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
This commit is contained in:
Vadim Yanitskiy 2018-05-12 02:04:53 +07:00
parent d350e9f30c
commit 219ed20cb5
4 changed files with 34 additions and 21 deletions

View File

@ -96,8 +96,6 @@ enum l1ctl_coding_scheme {
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 @@ struct l1ctl_data_ind {
/* traffic from the network */
struct l1ctl_traffic_ind {
uint8_t data[TRAFFIC_DATA_LEN];
uint8_t data[0];
} __attribute__((packed));
/*
@ -346,7 +344,7 @@ struct l1ctl_neigh_pm_ind {
/* 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 {

View File

@ -762,6 +762,8 @@ 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;
if (msgb_l1len(msg) < sizeof(*dl)) {
LOGP(DL1C, LOGL_ERROR, "TRAFFIC IND MSG too short "
@ -771,10 +773,17 @@ static int rx_l1_traffic_ind(struct osmocom_ms *ms, struct msgb *msg)
/* 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 @@ 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;
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));

View File

@ -84,6 +84,7 @@ void l1ctl_tx_traffic_ind(struct l1_model_ms *ms, struct msgb *msg, uint16_t arf
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 @@ void l1ctl_tx_traffic_ind(struct l1_model_ms *ms, struct msgb *msg, uint16_t arf
/* 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);
}

View File

@ -338,6 +338,7 @@ static int l1s_tch_resp(__unused uint8_t p1, __unused uint8_t p2, uint16_t p3)
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 @@ static int l1s_tch_resp(__unused uint8_t p1, __unused uint8_t p2, uint16_t p3)
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);