summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-03-09 06:34:04 +0700
committerHarald Welte <laforge@gnumonks.org>2018-03-11 10:05:48 +0000
commit2136891b7bbdfbd62f28f63c8a16711d9562ec1c (patch)
treec3c07e1c856d2e506895c4388e375c38b60a2464
parenta92fd3388cd7eac69e18938832be688c9a425613 (diff)
trxcon: clarify L1CTL message length field
Each L1CTL message gets its own length pushed in front before sending. This isn't specified in the 'l1ctl_proto.h', but assumed in the code. Let's clarify this. Change-Id: I118d00613aeaf5ff0bad1188fa5f7450d4ca8122
-rw-r--r--src/host/trxcon/l1ctl.c8
-rw-r--r--src/host/trxcon/l1ctl_link.c8
-rw-r--r--src/host/trxcon/l1ctl_link.h8
3 files changed, 19 insertions, 5 deletions
diff --git a/src/host/trxcon/l1ctl.c b/src/host/trxcon/l1ctl.c
index 58b8a4ff..f138b88c 100644
--- a/src/host/trxcon/l1ctl.c
+++ b/src/host/trxcon/l1ctl.c
@@ -49,8 +49,14 @@
static struct msgb *l1ctl_alloc_msg(uint8_t msg_type)
{
struct l1ctl_hdr *l1h;
- struct msgb *msg = msgb_alloc_headroom(256, 4, "l1ctl_tx_msg");
+ struct msgb *msg;
+ /**
+ * Each L1CTL message gets its own length pushed in front
+ * before sending. This is why we need this small headroom.
+ */
+ msg = msgb_alloc_headroom(L1CTL_LENGTH + L1CTL_MSG_LEN_FIELD,
+ L1CTL_MSG_LEN_FIELD, "l1ctl_tx_msg");
if (!msg) {
LOGP(DL1C, LOGL_ERROR, "Failed to allocate memory\n");
return NULL;
diff --git a/src/host/trxcon/l1ctl_link.c b/src/host/trxcon/l1ctl_link.c
index a7277ea5..0fa3efe5 100644
--- a/src/host/trxcon/l1ctl_link.c
+++ b/src/host/trxcon/l1ctl_link.c
@@ -84,8 +84,8 @@ static int l1ctl_link_read_cb(struct osmo_fd *bfd)
}
/* Attempt to read from socket */
- rc = read(bfd->fd, &len, sizeof(len));
- if (rc < sizeof(len)) {
+ rc = read(bfd->fd, &len, L1CTL_MSG_LEN_FIELD);
+ if (rc < L1CTL_MSG_LEN_FIELD) {
LOGP(DL1D, LOGL_NOTICE, "L1CTL has lost connection\n");
msgb_free(msg);
if (rc >= 0)
@@ -198,8 +198,8 @@ int l1ctl_link_send(struct l1ctl_link *l1l, struct msgb *msg)
LOGP(DL1D, LOGL_INFO, "Message L1 header != Message Data\n");
/* Prepend 16-bit length before sending */
- len = (uint16_t *) msgb_push(msg, sizeof(*len));
- *len = htons(msg->len - sizeof(*len));
+ len = (uint16_t *) msgb_push(msg, L1CTL_MSG_LEN_FIELD);
+ *len = htons(msg->len - L1CTL_MSG_LEN_FIELD);
if (osmo_wqueue_enqueue(&l1l->wq, msg) != 0) {
LOGP(DL1D, LOGL_ERROR, "Failed to enqueue msg!\n");
diff --git a/src/host/trxcon/l1ctl_link.h b/src/host/trxcon/l1ctl_link.h
index f9d91f14..01103dcc 100644
--- a/src/host/trxcon/l1ctl_link.h
+++ b/src/host/trxcon/l1ctl_link.h
@@ -1,5 +1,7 @@
#pragma once
+#include <stdint.h>
+
#include <osmocom/core/write_queue.h>
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
@@ -9,6 +11,12 @@
#define L1CTL_LENGTH 256
#define L1CTL_HEADROOM 32
+/**
+ * Each L1CTL message gets its own length pushed
+ * as two bytes in front before sending.
+ */
+#define L1CTL_MSG_LEN_FIELD 2
+
/* Forward declaration to avoid mutual include */
struct trx_instance;