diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2020-03-29 18:39:46 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2020-04-01 01:46:44 +0700 |
commit | c4744ac24c686d53d8075f45ecbcc64bb46dc9fe (patch) | |
tree | 3f325a63fe05e0095e985cc82641d8f49164b3b9 /src | |
parent | ae4d85d891c6fde179f16db7eed0b6e3fa468705 (diff) |
l1sap: fix gsmtap_ph_rach(): properly pack 8-bit and 11-bit RA
According to 3GPP TS 44.004, section 7.4a, two alternative RACH
block formats are specified: 8 bit (1 octet) and 11 bit. The
bit order is little-endian (right to left).
In L1SAP PH-RACH.ind structure (see ph_rach_ind_param) we use
a field of type uint16_t to store RA values regardles of the
block format. Thus when packing it to bytes, we cannot just
cast uint16_t* to uint8_t*, we need to do some bit shifting.
Change-Id: I0e91d825bb2e1897647dd5403c311d833a89ff2e
Diffstat (limited to 'src')
-rw-r--r-- | src/common/l1sap.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/common/l1sap.c b/src/common/l1sap.c index 673430de..99aa11bc 100644 --- a/src/common/l1sap.c +++ b/src/common/l1sap.c @@ -434,6 +434,7 @@ static int gsmtap_ph_rach(struct osmo_phsap_prim *l1sap, uint8_t *chan_type, uint8_t *tn, uint8_t *ss, uint32_t *fn, uint8_t **data, unsigned int *len) { uint8_t chan_nr = l1sap->u.rach_ind.chan_nr; + static uint8_t ra_buf[2]; *chan_type = GSMTAP_CHANNEL_RACH; *fn = l1sap->u.rach_ind.fn; @@ -454,8 +455,17 @@ static int gsmtap_ph_rach(struct osmo_phsap_prim *l1sap, uint8_t *chan_type, } } - *data = (uint8_t *)&l1sap->u.rach_ind.ra; - *len = (l1sap->u.rach_ind.is_11bit) ? 2 : 1; + if (l1sap->u.rach_ind.is_11bit) { + /* Pack as described in 3GPP TS 44.004, figure 7.4a.b */ + ra_buf[0] = (uint8_t) (l1sap->u.rach_ind.ra >> 3); + ra_buf[1] = (uint8_t) (l1sap->u.rach_ind.ra & 0x07); + *len = sizeof(ra_buf); + *data = ra_buf; + } else { + ra_buf[0] = (uint8_t) (l1sap->u.rach_ind.ra & 0xff); + *len = sizeof(ra_buf[0]); + *data = ra_buf; + } return 0; } |