Vadim Yanitskiy has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/11395 )

Change subject: l1ctl_proto.h: use flexible array member for traffic messages
......................................................................

l1ctl_proto.h: use flexible array member for traffic messages

Unlike the DATA messages, traffic frames may have different length.
Instead of having fixed payload (i.e. TCH frame) length, let's
introduce a flexible array member. This would allow one to
calculate the frame length using the MSGB API.

Change-Id: I119fa36c84e95c3003d57c19e25f8146ed45c3c6
---
M include/l1ctl_proto.h
M src/host/layer23/src/common/l1ctl.c
M src/host/virt_phy/src/virt_prim_traffic.c
M src/target/firmware/layer1/prim_tch.c
4 files changed, 34 insertions(+), 21 deletions(-)

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



diff --git a/include/l1ctl_proto.h b/include/l1ctl_proto.h
index f1bff86..c6156f5 100644
--- a/include/l1ctl_proto.h
+++ b/include/l1ctl_proto.h
@@ -96,8 +96,6 @@
        L1CTL_MCS9,
 };

-#define TRAFFIC_DATA_LEN       40
-
 /*
  * NOTE: struct size. We do add manual padding out of the believe
  * that it will avoid some unaligned access.
@@ -162,7 +160,7 @@

 /* traffic from the network */
 struct l1ctl_traffic_ind {
-       uint8_t data[TRAFFIC_DATA_LEN];
+       uint8_t data[0];
 } __attribute__((packed));

 /*
@@ -346,7 +344,7 @@

 /* traffic data to network */
 struct l1ctl_traffic_req {
-       uint8_t data[TRAFFIC_DATA_LEN];
+       uint8_t data[0];
 } __attribute__((packed));

 struct l1ctl_tbf_cfg_req {
diff --git a/src/host/layer23/src/common/l1ctl.c 
b/src/host/layer23/src/common/l1ctl.c
index 96db52f..5d6d9c0 100644
--- a/src/host/layer23/src/common/l1ctl.c
+++ b/src/host/layer23/src/common/l1ctl.c
@@ -762,6 +762,8 @@
 {
        struct l1ctl_info_dl *dl;
        struct l1ctl_traffic_ind *ti;
+       size_t frame_len;
+       uint8_t *frame;

        if (msgb_l1len(msg) < sizeof(*dl)) {
                LOGP(DL1C, LOGL_ERROR, "TRAFFIC IND MSG too short "
@@ -771,10 +773,17 @@

        /* Header handling */
        dl = (struct l1ctl_info_dl *) msg->l1h;
-       msg->l2h = dl->payload;
-       ti = (struct l1ctl_traffic_ind *) msg->l2h;
+       ti = (struct l1ctl_traffic_ind *) dl->payload;
+       frame = (uint8_t *) ti->data;

-       DEBUGP(DL1C, "TRAFFIC IND (%s)\n", osmo_hexdump(ti->data, 33));
+       msg->l2h = dl->payload;
+       msg->l3h = frame;
+
+       /* Calculate the frame length */
+       frame_len = msgb_l3len(msg);
+
+       DEBUGP(DL1C, "TRAFFIC IND len=%zu (%s)\n", frame_len,
+               osmo_hexdump(frame, frame_len));

        /* distribute or drop */
        if (ms->l1_entity.l1_traffic_ind)
@@ -791,28 +800,28 @@
        struct l1ctl_hdr *l1h;
        struct l1ctl_info_ul *l1i_ul;
        struct l1ctl_traffic_req *tr;
+       size_t frame_len;
+       uint8_t *frame;

        /* Header handling */
        tr = (struct l1ctl_traffic_req *) msg->l2h;
+       frame = (uint8_t *) tr->data;
+       msg->l3h = frame;

-       DEBUGP(DL1C, "TRAFFIC REQ (%s)\n",
-               osmo_hexdump(msg->l2h, msgb_l2len(msg)));
+       /* Calculate the frame length */
+       frame_len = msgb_l3len(msg);

-       if (msgb_l2len(msg) != 33) {
-               LOGP(DL1C, LOGL_ERROR, "Traffic Request has incorrect length "
-                       "(%u != 33)\n", msgb_l2len(msg));
-               msgb_free(msg);
-               return -EINVAL;
-       }
+       DEBUGP(DL1C, "TRAFFIC REQ len=%zu (%s)\n", frame_len,
+               osmo_hexdump(frame, frame_len));

-       if ((tr->data[0] >> 4) != 0xd) {
+       if ((frame[0] >> 4) != 0xd) {
                LOGP(DL1C, LOGL_ERROR, "Traffic Request has incorrect magic "
-                       "(%u != 0xd)\n", tr->data[0] >> 4);
+                       "(%u != 0xd)\n", frame[0] >> 4);
                msgb_free(msg);
                return -EINVAL;
        }

-//     printf("TX %s\n", osmo_hexdump(tr->data, 33));
+//     printf("TX %s\n", osmo_hexdump(frame, frame_len));

        /* prepend uplink info header */
        l1i_ul = (struct l1ctl_info_ul *) msgb_push(msg, sizeof(*l1i_ul));
diff --git a/src/host/virt_phy/src/virt_prim_traffic.c 
b/src/host/virt_phy/src/virt_prim_traffic.c
index 4e58de6..5f6b273 100644
--- a/src/host/virt_phy/src/virt_prim_traffic.c
+++ b/src/host/virt_phy/src/virt_prim_traffic.c
@@ -84,6 +84,7 @@
        struct msgb *l1ctl_msg = NULL;
        struct l1ctl_traffic_ind * l1ti;
        struct l1ctl_info_dl * l1dl;
+       uint8_t *frame, frame_len;
        uint8_t rsl_chan_type, subchan, timeslot;
        l1ctl_msg = l1ctl_msgb_alloc(L1CTL_TRAFFIC_IND);
        l1dl = (struct l1ctl_info_dl *) msgb_put(l1ctl_msg, sizeof(*l1dl));
@@ -102,7 +103,10 @@

        /* TODO: traffic decoding and decryption */

-       memcpy(l1ti->data, msgb_data(msg), msgb_length(msg));
+       frame_len = msgb_length(msg);
+       frame = (uint8_t *) msgb_put(l1ctl_msg, frame_len);
+       memcpy(frame, msgb_data(msg), frame_len);
+
        DEBUGPMS(DL1P, ms, "Tx L1CTL_TRAFFIC_IND (chan_nr=0x%02x, 
link_id=0x%02x)\n", chan_nr, link_id);
        l1ctl_sap_tx_to_l23_inst(ms, l1ctl_msg);
 }
diff --git a/src/target/firmware/layer1/prim_tch.c 
b/src/target/firmware/layer1/prim_tch.c
index 2dadaaf..a8036d2 100644
--- a/src/target/firmware/layer1/prim_tch.c
+++ b/src/target/firmware/layer1/prim_tch.c
@@ -338,6 +338,7 @@
                                struct msgb *msg;
                                struct l1ctl_info_dl *dl;
                                struct l1ctl_traffic_ind *ti;
+                               uint8_t *payload;

                                /* Allocate msgb */
                                /* FIXME: we actually want all allocation out 
of L1S! */
@@ -349,15 +350,16 @@

                                dl = (struct l1ctl_info_dl *) msgb_put(msg, 
sizeof(*dl));
                                ti = (struct l1ctl_traffic_ind *) msgb_put(msg, 
sizeof(*ti));
+                               payload = (uint8_t *) msgb_put(msg, 33);

                                /* Copy actual data, skipping the information 
block [0,1,2] */
-                               dsp_memcpy_from_api(ti->data, &traffic_buf[3], 
33, 1);
+                               dsp_memcpy_from_api(payload, &traffic_buf[3], 
33, 1);

                                /**
                                 * Perform some bit conversations
                                 * FIXME: what about other (than FR) codecs?
                                 */
-                               tch_fr_bit_magic(ti, 1);
+                               tch_fr_bit_magic(payload, 1);

                                /* Give message to up layer */
                                l1_queue_for_l2(msg);

--
To view, visit https://gerrit.osmocom.org/11395
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: I119fa36c84e95c3003d57c19e25f8146ed45c3c6
Gerrit-Change-Number: 11395
Gerrit-PatchSet: 3
Gerrit-Owner: Vadim Yanitskiy <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Vadim Yanitskiy <[email protected]>

Reply via email to