From 99abe5768c306e0da4c19bc9ff03674e4f01d91e Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Nov 2022 22:18:01 +0300 Subject: [PATCH] LAPD: move tx_hist code into static function Related: OS#4074 Change-Id: Ibf3b08c8d874416796b94ba3a672a02d614313b1 --- src/gsm/lapd_core.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/gsm/lapd_core.c b/src/gsm/lapd_core.c index 9a4f56b96..658540a15 100644 --- a/src/gsm/lapd_core.c +++ b/src/gsm/lapd_core.c @@ -1738,6 +1738,15 @@ static int lapd_udata_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) return dl->send_ph_data_req(&nctx, msg); } +static void msg_to_tx_hist(struct lapd_datalink *dl, const struct msgb *msg, int more) +{ + dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST"); + dl->tx_hist[0].more = more; + msgb_put(dl->tx_hist[0].msg, msg->len); + if (msg->len) + memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len); +} + /* request link establishment */ static int lapd_est_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) { @@ -1776,11 +1785,8 @@ static int lapd_est_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) nctx.more = 0; /* Transmit-buffer carries exactly one segment */ - dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST"); - msgb_put(dl->tx_hist[0].msg, msg->len); - if (msg->len) - memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len); - dl->tx_hist[0].more = 0; + msg_to_tx_hist(dl, msg, 0); + /* set Vs to 0, because it is used as index when resending SABM */ dl->v_send = 0; @@ -1913,11 +1919,8 @@ static int lapd_send_i(struct lapd_msg_ctx *lctx, int line) memcpy(msg->l3h, dl->send_buffer->l3h + dl->send_out, length); /* store in tx_hist */ - dl->tx_hist[h].msg = lapd_msgb_alloc(msg->len, "HIST"); - msgb_put(dl->tx_hist[h].msg, msg->len); - if (length) - memcpy(dl->tx_hist[h].msg->data, msg->l3h, msg->len); - dl->tx_hist[h].more = nctx.more; + msg_to_tx_hist(dl, msg, nctx.more); + /* Add length to track how much is already in the tx buffer */ dl->send_out += length; } else { @@ -2038,11 +2041,8 @@ static int lapd_res_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) nctx.length = 0; nctx.more = 0; - dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST"); - msgb_put(dl->tx_hist[0].msg, msg->len); - if (msg->len) - memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len); - dl->tx_hist[0].more = 0; + msg_to_tx_hist(dl, msg, 0); + /* set Vs to 0, because it is used as index when resending SABM */ dl->v_send = 0; @@ -2102,11 +2102,8 @@ static int lapd_rel_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) nctx.length = 0; nctx.more = 0; - dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST"); - msgb_put(dl->tx_hist[0].msg, msg->len); - if (msg->len) - memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len); - dl->tx_hist[0].more = 0; + msg_to_tx_hist(dl, msg, 0); + /* set Vs to 0, because it is used as index when resending DISC */ dl->v_send = 0;