diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2021-04-22 04:43:04 +0200 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2021-04-24 08:47:56 +0000 |
commit | 8a993652810b52014d82129ec14e0c356eef720e (patch) | |
tree | b18b78a1f0ddd4e8ae9b3f4041bee37ad0414f00 /src/osmo-bts-trx/trx_if.c | |
parent | ac55dcb5d07242f77bd98052f90876fc00d57c04 (diff) |
osmo-bts-trx: generalize checking of TRXD header length
Diffstat (limited to 'src/osmo-bts-trx/trx_if.c')
-rw-r--r-- | src/osmo-bts-trx/trx_if.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c index 0beb941d..28b5f2e3 100644 --- a/src/osmo-bts-trx/trx_if.c +++ b/src/osmo-bts-trx/trx_if.c @@ -723,19 +723,17 @@ rsp_error: /* Uplink TRXDv1 header length: additional MTS + C/I */ #define TRX_UL_V1HDR_LEN (TRX_UL_V0HDR_LEN + 1 + 2) +/* Minimum Uplink TRXD header length for all PDU versions */ +static const uint8_t trx_data_rx_hdr_len[] = { + TRX_UL_V0HDR_LEN, /* TRXDv0 */ + TRX_UL_V1HDR_LEN, /* TRXDv1 */ +}; + /* TRXD header dissector for version 0 */ static int trx_data_handle_hdr_v0(struct trx_l1h *l1h, struct trx_ul_burst_ind *bi, const uint8_t *buf, size_t buf_len) { - /* Make sure we have enough data */ - if (buf_len < TRX_UL_V0HDR_LEN) { - LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, - "Short read on TRXD, missing version 0 header " - "(len=%zu vs expected %d)\n", buf_len, TRX_UL_V0HDR_LEN); - return -EIO; - } - bi->tn = buf[0] & 0b111; bi->fn = osmo_load32be(buf + 1); bi->rssi = -(int8_t)buf[5]; @@ -785,14 +783,6 @@ static int trx_data_handle_hdr_v1(struct trx_l1h *l1h, { int rc; - /* Make sure we have enough data */ - if (buf_len < TRX_UL_V1HDR_LEN) { - LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, - "Short read on TRXD, missing version 1 header " - "(len=%zu vs expected %d)\n", buf_len, TRX_UL_V1HDR_LEN); - return -EIO; - } - /* Parse v0 specific part */ rc = trx_data_handle_hdr_v0(l1h, bi, buf, buf_len); if (rc < 0) @@ -948,6 +938,14 @@ static int trx_data_read_cb(struct osmo_fd *ofd, unsigned int what) return -EIO; } + /* Make sure that we have enough bytes to parse the header */ + if (buf_len < trx_data_rx_hdr_len[pdu_ver]) { + 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]); + return -EINVAL; + } + /* Parse header depending on the PDU version */ switch (pdu_ver) { case 0: |