laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-tetra/+/28850 )
Change subject: Improved parsing in macpdu_decode_resource ......................................................................
Improved parsing in macpdu_decode_resource
fill_bits and grant_position bits are now parsed and stored in the tetra_resrc_decoded struct A flag is_encrypted is set to to true if resource was not encrypted or if the calling function states that the frame has been decrypted successfully before passing it to tetra_resrc_decoded. Lastly, the channel_alloc element is only parsed if the frame is unencrypted.
Change-Id: I6c85c93b70a34e01fd1a96a863f0e113be6424d3 --- M src/tetra_mac_pdu.c M src/tetra_mac_pdu.h M src/tetra_upper_mac.c 3 files changed, 17 insertions(+), 11 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/src/tetra_mac_pdu.c b/src/tetra_mac_pdu.c index b395b7c..d114703 100644 --- a/src/tetra_mac_pdu.c +++ b/src/tetra_mac_pdu.c @@ -91,7 +91,7 @@ };
/* 21.5.2 */ -static int decode_chan_alloc(struct tetra_chan_alloc_decoded *cad, const uint8_t *bits) +static int macpdu_decode_chan_alloc(struct tetra_chan_alloc_decoded *cad, const uint8_t *bits) { const uint8_t *cur = bits;
@@ -182,12 +182,15 @@ return -EINVAL; }
-/* Section 21.4.3.1 MAC-RESOURCE */ -int macpdu_decode_resource(struct tetra_resrc_decoded *rsd, const uint8_t *bits) -{ - const uint8_t *cur = bits + 4;
+/* Section 21.4.3.1 MAC-RESOURCE */ +int macpdu_decode_resource(struct tetra_resrc_decoded *rsd, const uint8_t *bits, uint8_t is_decrypted) +{ + const uint8_t *cur = bits + 2; + rsd->fill_bits = bits_to_uint(cur, 1); cur += 1; + rsd->grant_position = bits_to_uint(cur, 1); cur += 1; rsd->encryption_mode = bits_to_uint(cur, 2); cur += 2; + rsd->is_encrypted = rsd->encryption_mode > 0 && !is_decrypted; rsd->rand_acc_flag = *cur++; rsd->macpdu_length = decode_length(bits_to_uint(cur, 6)); cur += 6; rsd->addr.type = bits_to_uint(cur, 3); cur += 3; @@ -239,10 +242,10 @@ #endif } rsd->chan_alloc_pres = *cur++; - /* FIXME: If encryption is enabled, Channel Allocation is encrypted !!! */ - if (rsd->chan_alloc_pres) - cur += decode_chan_alloc(&rsd->cad, cur); - /* FIXME: TM-SDU */ + + if (rsd->chan_alloc_pres && !rsd->is_encrypted) + // We can only determine length if the frame is unencrypted + cur += macpdu_decode_chan_alloc(&rsd->cad, cur);
return cur - bits; } diff --git a/src/tetra_mac_pdu.h b/src/tetra_mac_pdu.h index 051e47a..d243062 100644 --- a/src/tetra_mac_pdu.h +++ b/src/tetra_mac_pdu.h @@ -213,7 +213,10 @@ };
struct tetra_resrc_decoded { + uint8_t fill_bits; + uint8_t grant_position; uint8_t encryption_mode; + uint8_t is_encrypted; // Set to 0 if not encrypted or decrypted successfully uint8_t rand_acc_flag; int macpdu_length; struct tetra_addr addr; @@ -229,7 +232,7 @@ uint8_t chan_alloc_pres; struct tetra_chan_alloc_decoded cad; }; -int macpdu_decode_resource(struct tetra_resrc_decoded *rsd, const uint8_t *bits); +int macpdu_decode_resource(struct tetra_resrc_decoded *rsd, const uint8_t *bits, uint8_t is_decrypted);
const char *tetra_addr_dump(const struct tetra_addr *addr);
diff --git a/src/tetra_upper_mac.c b/src/tetra_upper_mac.c index a4c7e59..0e090cf 100644 --- a/src/tetra_upper_mac.c +++ b/src/tetra_upper_mac.c @@ -157,7 +157,7 @@ int tmpdu_offset;
memset(&rsd, 0, sizeof(rsd)); - tmpdu_offset = macpdu_decode_resource(&rsd, msg->l1h); + tmpdu_offset = macpdu_decode_resource(&rsd, msg->l1h, 0); msg->l2h = msg->l1h + tmpdu_offset;
printf("RESOURCE Encr=%u, Length=%d Addr=%s ",