diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2018-05-12 02:04:53 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2018-10-03 18:43:08 +0700 |
commit | 7b8da829c4956ea5d6e3bdd121e37ae9fdaf13f8 (patch) | |
tree | b146233f36943c80d7690ed0f24a7abe7d90d423 /src/host/layer23 | |
parent | 95dd61ba27a13d4c462a2c59401952bb6e084544 (diff) |
l1ctl_proto.h: use flexible array member to store a traffic frame
Unlike the LAPDm messages, traffic frames may have different
length. Instead of having a buffer with fixed length, let's
use flexible array member. This would allow one to calculate
a frame length using the MSGB API (i.e. msgb_l3len()).
Change-Id: I119fa36c84e95c3003d57c19e25f8146ed45c3c6
Diffstat (limited to 'src/host/layer23')
-rw-r--r-- | src/host/layer23/src/common/l1ctl.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/host/layer23/src/common/l1ctl.c b/src/host/layer23/src/common/l1ctl.c index eedfb938..4291d81b 100644 --- a/src/host/layer23/src/common/l1ctl.c +++ b/src/host/layer23/src/common/l1ctl.c @@ -775,13 +775,22 @@ static int rx_l1_traffic_ind(struct osmocom_ms *ms, struct msgb *msg) { struct l1ctl_info_dl *dl; struct l1ctl_traffic_ind *ti; + size_t frame_len; + uint8_t *frame; /* Header handling */ dl = (struct l1ctl_info_dl *) msg->l1h; + ti = (struct l1ctl_traffic_ind *) dl->payload; + frame = (uint8_t *) ti->data; + msg->l2h = dl->payload; - ti = (struct l1ctl_traffic_ind *) msg->l2h; + msg->l3h = frame; + + /* Calculate the frame length */ + frame_len = msgb_l3len(msg); - DEBUGP(DL1C, "TRAFFIC IND (%s)\n", osmo_hexdump(ti->data, 33)); + 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) { @@ -803,28 +812,35 @@ int l1ctl_tx_traffic_req(struct osmocom_ms *ms, struct msgb *msg, 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; + + /* Calculate the frame length */ + frame_len = msgb_l3len(msg); - DEBUGP(DL1C, "TRAFFIC REQ (%s)\n", - osmo_hexdump(msg->l2h, msgb_l2len(msg))); + DEBUGP(DL1C, "TRAFFIC REQ (len=%zu): %s\n", frame_len, + osmo_hexdump(frame, frame_len)); - if (msgb_l2len(msg) != 33) { + if (frame_len != 33) { LOGP(DL1C, LOGL_ERROR, "Traffic Request has incorrect length " - "(%u != 33)\n", msgb_l2len(msg)); + "(%u != 33)\n", frame_len); msgb_free(msg); return -EINVAL; } - 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)); |