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: 559a6ee683
Change-Id: Id619459c17976b77cd2c7e4179123bb06807285c
This commit is contained in:
Pau Espin 2023-04-28 17:33:36 +02:00
parent e2217ee098
commit beb7c1741e
2 changed files with 13 additions and 7 deletions

View File

@ -225,7 +225,11 @@ int tlv_encode_ordered(struct msgb *msg, const struct tlv_definition *def, const
* \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 @@ int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val,
*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;

View File

@ -470,14 +470,12 @@ static void test_tlv_type_single_tv(void)
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)