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
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;