Timur Davydov has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/42696?usp=email )
Change subject: trx: split TRXD parsing from socket callback ......................................................................
trx: split TRXD parsing from socket callback
Extract TRXD message parsing into trx_data_read() and reuse it from trx_data_read_cb()
This decouples parsing from socket I/O and allows reuse with alternative transports
No functional changes intended
Change-Id: I50ad8b6d2edfd91f2d569cd8badf5c036fbf87ed --- M src/osmo-bts-trx/trx_if.c M src/osmo-bts-trx/trx_if.h 2 files changed, 42 insertions(+), 18 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/96/42696/1
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c index 57da2f3..f2e568c 100644 --- a/src/osmo-bts-trx/trx_if.c +++ b/src/osmo-bts-trx/trx_if.c @@ -1022,23 +1022,19 @@ }
/* Parse TRXD message from transceiver, compose an UL burst indication. */ -static void trx_data_read_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg) +int trx_data_read(struct trx_l1h *l1h, const uint8_t *buf, size_t buf_len) { - struct trx_l1h *l1h = osmo_iofd_get_data(iofd); - const uint8_t *buf; struct trx_ul_burst_ind bi; - ssize_t hdr_len, buf_len; + int rc; + ssize_t hdr_len; uint8_t pdu_ver;
- if (OSMO_UNLIKELY(res <= 0)) { - char errbuf[256]; - strerror_r(errno, errbuf, sizeof(errbuf)); + /* We shall have at least one byte to parse the PDU version */ + if (OSMO_UNLIKELY(!buf || buf_len == 0)) { LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, - "recv() failed on TRXD with rc=%d (%s)\n", res, errbuf); - goto ret_msg_free; + "Rx empty TRXD PDU\n"); + return -EINVAL; } - buf = msgb_data(msg); - buf_len = msgb_length(msg);
/* Parse PDU version first */ pdu_ver = buf[0] >> 4; @@ -1048,7 +1044,7 @@ LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Rx TRXD PDU with unexpected version %u (expected %u)\n", pdu_ver, l1h->config.trxd_pdu_ver_use); - goto ret_msg_free; + return -EINVAL; }
/* We're about to parse the first PDU */ @@ -1064,7 +1060,7 @@ LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Rx malformed TRXDv%u PDU: len=%zd < expected %u\n", pdu_ver, buf_len, trx_data_rx_hdr_len[pdu_ver]); - goto ret_msg_free; + return -EINVAL; }
/* Parse header depending on the PDU version */ @@ -1085,13 +1081,13 @@
/* Header parsing error */ if (OSMO_UNLIKELY(hdr_len < 0)) - goto ret_msg_free; + return (int)hdr_len;
if (OSMO_UNLIKELY(bi.fn >= GSM_TDMA_HYPERFRAME)) { LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Rx malformed TRXDv%u PDU: illegal TDMA fn=%u\n", pdu_ver, bi.fn); - goto ret_msg_free; + return -EINVAL; }
/* We're done with the header now */ @@ -1099,11 +1095,12 @@ buf += hdr_len;
/* Calculate burst length and parse it (if present) */ - if (OSMO_UNLIKELY(trx_data_handle_burst(&bi, buf, buf_len) != 0)) { + rc = trx_data_handle_burst(&bi, buf, buf_len); + if (OSMO_UNLIKELY(rc != 0)) { LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Rx malformed TRXDv%u PDU: odd burst length=%zd\n", pdu_ver, buf_len); - goto ret_msg_free; + return rc; }
/* We're done with the burst bits now */ @@ -1124,7 +1121,31 @@ TRACE(OSMO_BTS_TRX_UL_DATA_DONE(l1h->phy_inst->trx->nr, bi.tn, bi.fn)); } while (bi.flags & TRX_BI_F_BATCH_IND);
-ret_msg_free: + return 0; +} + +/* TRXD socket read callback. + * Called when a TRXD datagram is received on the IOFD. + * If `res` <= 0 an error is logged; otherwise the payload is passed + * to `trx_data_read()` for parsing and routing. The message buffer + * is freed before returning. + */ +static void trx_data_read_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg) +{ + struct trx_l1h *l1h = osmo_iofd_get_data(iofd); + + if (OSMO_UNLIKELY(res <= 0)) { + char errbuf[256]; + strerror_r(errno, errbuf, sizeof(errbuf)); + LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, + "recv() failed on TRXD with rc=%d (%s)\n", res, errbuf); + } else { + const uint8_t *buf = msgb_data(msg); + const ssize_t buf_len = msgb_length(msg); + + trx_data_read(l1h, buf, buf_len); + } + msgb_free(msg); }
diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h index 44483b5..9fd5ca6 100644 --- a/src/osmo-bts-trx/trx_if.h +++ b/src/osmo-bts-trx/trx_if.h @@ -80,3 +80,6 @@ int trx_ctrl_cmd_cb(struct trx_l1h *l1h, int critical, void *cb, const char *cmd, const char *fmt, ...); #define trx_ctrl_cmd(l1h, critical, cmd, fmt, ...) trx_ctrl_cmd_cb(l1h, critical, NULL, cmd, fmt, ##__VA_ARGS__) + +/* Parse TRXD message from transceiver, compose an UL burst indication. */ +int trx_data_read(struct trx_l1h *l1h, const uint8_t *buf, size_t buf_len);