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
This commit is contained in:
wbokslag 2022-07-29 16:24:29 +02:00
parent 6dfb41681c
commit a5bc24792b
3 changed files with 17 additions and 11 deletions

View File

@ -91,7 +91,7 @@ static const uint8_t addr_len_by_type[] = {
};
/* 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 @@ static int decode_length(unsigned int length_ind)
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 @@ int macpdu_decode_resource(struct tetra_resrc_decoded *rsd, const uint8_t *bits)
#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;
}

View File

@ -213,7 +213,10 @@ struct tetra_addr {
};
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 @@ struct tetra_resrc_decoded {
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);

View File

@ -157,7 +157,7 @@ static void rx_resrc(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms
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 ",