pespin submitted this change.

View Change


Approvals: Jenkins Builder: Verified daniel: Looks good to me, but someone else must approve pespin: Looks good to me, approved
Fix 'Fix parsing of TLV_TYPE_SINGLE_TV'

A commit was merged recently attempting to fix decoding of
TLV_TYPE_SINGLE_TV. It did mostly a good job, but missed updating the
o_tag pointer used to fill in the structures.
This commit fixes that specific part missing.

Fixes: 559a6ee68359dab691a483573982e6f8c6439ae2
Change-Id: Id619459c17976b77cd2c7e4179123bb06807285c
---
M src/gsm/tlv_parser.c
M tests/tlv/tlv_test.c
2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/gsm/tlv_parser.c b/src/gsm/tlv_parser.c
index e47b94f..8dd460d 100644
--- a/src/gsm/tlv_parser.c
+++ b/src/gsm/tlv_parser.c
@@ -225,7 +225,11 @@
* \param[in] def structure defining the valid TLV tags / configurations
* \param[in] buf the input data buffer to be parsed
* \param[in] buf_len length of the input data buffer
- * \returns number of bytes consumed by the TLV entry / IE parsed; negative in case of error
+ * \returns number of bytes consumed by the TLV entry / IE parsed; negative in case of error.
+ *
+ * In IEs of type TLV_TYPE_SINGLE_TV, the data pointer \ref o_val will point to the
+ * byte shared by both the Tag and te Value, hence the tag is to be trimmed
+ * by the caller.
*/
int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val,
const struct tlv_definition *def,
@@ -241,9 +245,13 @@
*o_tag = tag;

/* single octet TV IE */
- if (def->def[tag >> 4].type == TLV_TYPE_SINGLE_TV
+ if (def->def[tag >> 4].type == TLV_TYPE_SINGLE_TV) {
+ *o_tag = tag >> 4;
+ *o_val = buf;
+ *o_len = 1;
+ return 1;
+ } else if ((tag > 0x0f) && (def->def[tag & 0xf0].type == TLV_TYPE_SINGLE_TV)) {
/* backward compat for old IEs with half-octet tag defined as 0xN0: */
- || ((tag > 0x0f) && (def->def[tag & 0xf0].type == TLV_TYPE_SINGLE_TV))) {
*o_tag = tag & 0xf0;
*o_val = buf;
*o_len = 1;
diff --git a/tests/tlv/tlv_test.c b/tests/tlv/tlv_test.c
index aaa86a3..8e8bd60 100644
--- a/tests/tlv/tlv_test.c
+++ b/tests/tlv/tlv_test.c
@@ -470,14 +470,12 @@

rc = tlv_parse(&tp, &att_tlvdef, buf, sizeof(buf), 0, 0);
OSMO_ASSERT(rc == 1);
- OSMO_ASSERT(!TLVP_PRESENT(&tp, SAMPLE_SINGLE_TV_IE)); //FIXME!
+ OSMO_ASSERT(TLVP_PRESENT(&tp, SAMPLE_SINGLE_TV_IE));
val = TLVP_VAL(&tp, SAMPLE_SINGLE_TV_IE);
- OSMO_ASSERT(!val); //FIXME!
-#if 0
+ OSMO_ASSERT(val);
OSMO_ASSERT(val == &buf[0]);
OSMO_ASSERT(*val == buf[0]);
OSMO_ASSERT((*val & 0x0f) == exp_val);
-#endif
}

int main(int argc, char **argv)

To view, visit change 32549. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id619459c17976b77cd2c7e4179123bb06807285c
Gerrit-Change-Number: 32549
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr@sysmocom.de>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-CC: laforge <laforge@osmocom.org>
Gerrit-MessageType: merged