Max has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/13354 )

Change subject: trxcon: use helper to add l1ctl_info_dl
......................................................................

trxcon: use helper to add l1ctl_info_dl

Use static helpers to add l1ctl_info_dl to msgb - this simplifies
l1ctl_* routines and reduce code duplication.

Change-Id: I0b5b81f1fcd2984136e553a93735ea5456d2b3df
---
M src/host/trxcon/l1ctl.c
1 file changed, 18 insertions(+), 24 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/host/trxcon/l1ctl.c b/src/host/trxcon/l1ctl.c
index eb14832..b37082e 100644
--- a/src/host/trxcon/l1ctl.c
+++ b/src/host/trxcon/l1ctl.c
@@ -138,13 +138,24 @@
        return l1ctl_link_send(l1l, msg);
 }

+static struct l1ctl_info_dl *put_dl_info_hdr(struct msgb *msg, struct 
l1ctl_info_dl *dl_info)
+{
+       size_t len = sizeof(struct l1ctl_info_dl);
+       struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msgb_put(msg, len);
+
+       if (dl_info) /* Copy DL info provided by handler */
+               memcpy(dl, dl_info, len);
+       else /* Init DL info header */
+               memset(dl, 0x00, len);
+
+       return dl;
+}
+
 int l1ctl_tx_fbsb_conf(struct l1ctl_link *l1l, uint8_t result,
        struct l1ctl_info_dl *dl_info, uint8_t bsic)
 {
        struct l1ctl_fbsb_conf *conf;
-       struct l1ctl_info_dl *dl;
        struct msgb *msg;
-       size_t len;

        msg = l1ctl_alloc_msg(L1CTL_FBSB_CONF);
        if (msg == NULL)
@@ -153,10 +164,7 @@
        LOGP(DL1C, LOGL_DEBUG, "Send FBSB Conf (result=%u, bsic=%u)\n",
                result, bsic);

-       /* Copy DL info provided by handler */
-       len = sizeof(struct l1ctl_info_dl);
-       dl = (struct l1ctl_info_dl *) msgb_put(msg, len);
-       memcpy(dl, dl_info, len);
+       put_dl_info_hdr(msg, dl_info);
        talloc_free(dl_info);

        /* Fill in FBSB payload: BSIC and sync result */
@@ -198,7 +206,6 @@
 int l1ctl_tx_dt_ind(struct l1ctl_link *l1l, struct l1ctl_info_dl *data,
        uint8_t *l2, size_t l2_len, bool traffic)
 {
-       struct l1ctl_info_dl *dl;
        struct msgb *msg;
        uint8_t *msg_l2;

@@ -207,9 +214,7 @@
        if (msg == NULL)
                return -ENOMEM;

-       /* Copy DL header */
-       dl = (struct l1ctl_info_dl *) msgb_put(msg, sizeof(*dl));
-       memcpy(dl, data, sizeof(*dl));
+       put_dl_info_hdr(msg, data);

        /* Copy the L2 payload if preset */
        if (l2 && l2_len > 0) {
@@ -225,16 +230,13 @@
 {
        struct l1ctl_info_dl *dl;
        struct msgb *msg;
-       size_t len;

        msg = l1ctl_alloc_msg(L1CTL_RACH_CONF);
        if (msg == NULL)
                return -ENOMEM;

-       len = sizeof(struct l1ctl_info_dl);
-       dl = (struct l1ctl_info_dl *) msgb_put(msg, len);
+       dl = put_dl_info_hdr(msg, NULL);

-       memset(dl, 0x00, len);
        dl->band_arfcn = htons(l1l->trx->band_arfcn);
        dl->frame_nr = htonl(fn);

@@ -248,9 +250,7 @@
 int l1ctl_tx_dt_conf(struct l1ctl_link *l1l,
        struct l1ctl_info_dl *data, bool traffic)
 {
-       struct l1ctl_info_dl *dl;
        struct msgb *msg;
-       size_t len;

        msg = l1ctl_alloc_msg(traffic ?
                L1CTL_TRAFFIC_CONF : L1CTL_DATA_CONF);
@@ -258,9 +258,7 @@
                return -ENOMEM;

        /* Copy DL frame header from source message */
-       len = sizeof(struct l1ctl_info_dl);
-       dl = (struct l1ctl_info_dl *) msgb_put(msg, len);
-       memcpy(dl, data, len);
+       put_dl_info_hdr(msg, data);

        return l1ctl_link_send(l1l, msg);
 }
@@ -292,7 +290,6 @@
        struct l1ctl_fbsb_conf *conf;
        struct l1ctl_info_dl *dl;
        struct msgb *msg;
-       size_t len;

        msg = l1ctl_alloc_msg(L1CTL_FBSB_CONF);
        if (msg == NULL)
@@ -300,10 +297,7 @@

        LOGP(DL1C, LOGL_DEBUG, "Send FBSB Conf (result=255, bsic=0)\n");

-       /* Compose DL info header */
-       len = sizeof(struct l1ctl_info_dl);
-       dl = (struct l1ctl_info_dl *) msgb_put(msg, len);
-       memset(dl, 0x00, len);
+       dl = put_dl_info_hdr(msg, NULL);

        /* Fill in current ARFCN */
        dl->band_arfcn = htons(l1l->trx->band_arfcn);

--
To view, visit https://gerrit.osmocom.org/13354
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I0b5b81f1fcd2984136e553a93735ea5456d2b3df
Gerrit-Change-Number: 13354
Gerrit-PatchSet: 2
Gerrit-Owner: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilira...@gmail.com>
Gerrit-Reviewer: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: osmith <osm...@sysmocom.de>

Reply via email to