wbokslag has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-tetra/+/34000 )
Change subject: Fixups and clarifying comments for msgb tail modifications
......................................................................
Fixups and clarifying comments for msgb tail modifications
Added fixups for msgb len field whenever the tail is modified
Also, added some clarifying comments
Change-Id: Ia725edbeafe26bd2ea9b5a1810d0b26bc79d84db
---
M src/lower_mac/tetra_lower_mac.c
M src/tetra_llc.c
M src/tetra_upper_mac.c
3 files changed, 30 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-tetra refs/changes/00/34000/1
diff --git a/src/lower_mac/tetra_lower_mac.c b/src/lower_mac/tetra_lower_mac.c
index 21998f7..f8e7810 100644
--- a/src/lower_mac/tetra_lower_mac.c
+++ b/src/lower_mac/tetra_lower_mac.c
@@ -325,23 +325,26 @@
int pdu_bits = 0;
uint32_t offset = 0;
- uint8_t *orig_head = msg->head;
- uint8_t *orig_tail = msg->tail;
+ uint8_t *orig_head = msg->head; /* The true start of the timeslot */
+ uint8_t *orig_tail = msg->tail; /* The true end of the timeslot */
while (offset < tbp->type1_bits - 16) {
/* send Rx time along with the TMV-UNITDATA.ind primitive */
memcpy(&tup->tdma_time, &tcd->time, sizeof(tup->tdma_time));
+
+ /* Parse MAC element in timeslot (just one, possibly more later in the loop) */
pdu_bits = upper_mac_prim_recv(&ttp->oph, tms);
- if (pdu_bits < 0) {
- /* -1 is returned when pdu fills slot or length could not be determined */
+ /* Check if we are done (-1 returned) */
+ if (pdu_bits < 0)
break;
- }
- /* Increment head and l1h ptrs and reset tail to end of msg (may be altered by removing
FCS) */
+ /* Not done */
+ /* Increment head and l1h ptrs */
+ /* Reset tail to end of msg (may be altered by removing FCS) */
offset += pdu_bits;
- msg->head = orig_head + offset;
- msg->tail = orig_tail;
- msg->len = msg->tail - msg->head;
+ msg->head = orig_head + offset; /* New head is old head plus parsed len from prev
msg */
+ msg->tail = orig_tail; /* Restore original tail */
+ msg->len = msg->tail - msg->head; /* Fixup len */
msg->l1h = msg->head;
msg->l2h = 0;
msg->l3h = 0;
diff --git a/src/tetra_llc.c b/src/tetra_llc.c
index b8a378d..cdbfea0 100644
--- a/src/tetra_llc.c
+++ b/src/tetra_llc.c
@@ -122,6 +122,7 @@
tetra_llc_pdu_parse(&lpp, msg->l2h, len);
msg->l3h = lpp.tl_sdu;
msg->tail = msg->l3h + lpp.tl_sdu_len; // Strips off FCS (if present)
+ msg->len = msg->tail - msg->head;
printf("TM-SDU(%s)", tetra_get_llc_pdut_dec_name(lpp.pdu_type));
if (lpp.have_fcs) {
diff --git a/src/tetra_upper_mac.c b/src/tetra_upper_mac.c
index 94a58ce..3b2092b 100644
--- a/src/tetra_upper_mac.c
+++ b/src/tetra_upper_mac.c
@@ -175,12 +175,14 @@
} else {
pdu_bits = rsd.macpdu_length * 8; /* Length given */
msg->tail = msg->head + pdu_bits;
+ msg->len = msg->tail - msg->head;
}
/* Strip fill bits */
if (rsd.fill_bits) {
int num_fill_bits = get_num_fill_bits(msg->l1h, msgb_l1len(msg));
msg->tail -= num_fill_bits;
+ msg->len = msg->tail - msg->head;
}
/* Decrypt buffer if encrypted and key available */
@@ -301,6 +303,7 @@
if (fillbits_present) {
int num_fill_bits = get_num_fill_bits(msg->l1h, msgb_l1len(msg));
msg->tail -= num_fill_bits;
+ msg->len = msg->tail - msg->head;
}
/* Decrypt (if required) */
@@ -349,9 +352,11 @@
/* Determine msg len, strip fill bits if any */
msg->tail = msg->head + length_indicator * 8;
+ msg->len = msg->tail - msg->head;
if (fillbits_present) {
num_fill_bits = get_num_fill_bits(msg->l1h, msgb_l1len(msg));
msg->tail -= num_fill_bits;
+ msg->len = msg->tail - msg->head;
}
/* Decrypt (if required) */
--
To view, visit
https://gerrit.osmocom.org/c/osmo-tetra/+/34000
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-tetra
Gerrit-Branch: master
Gerrit-Change-Id: Ia725edbeafe26bd2ea9b5a1810d0b26bc79d84db
Gerrit-Change-Number: 34000
Gerrit-PatchSet: 1
Gerrit-Owner: wbokslag <w.bokslag(a)midnightblue.nl>
Gerrit-MessageType: newchange