TLV: add convenience function for 1-byte values

Similar to existing 16 and 32 bit value helpers but simpler because we
don't have to worry about alingment and endianness.

Change-Id: Ic0a148bd04b8860e321f509fdcd913f688c8e920
This commit is contained in:
Max 2018-12-19 19:01:03 +01:00
parent e6f63f22c5
commit bd6d5c10db
1 changed files with 16 additions and 0 deletions

View File

@ -495,6 +495,22 @@ void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src)
(TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
/*! Obtain 1-byte TLV element.
* \param[in] tp pointer to \ref tlv_parsed
* \param[in] tag the Tag to look for
* \param[in] default_val default value to use if tag not available
* \returns the 1st byte of value with a given tag or default_val if tag was not found
*/
static inline uint8_t tlvp_val8(const struct tlv_parsed *tp, uint8_t tag, uint8_t default_val)
{
const uint8_t *res = TLVP_VAL_MINLEN(tp, tag, 1);
if (res)
return res[0];
return default_val;
}
/*! Align given TLV element with 16 bit value to an even address
* \param[in] tp pointer to \ref tlv_parsed
* \param[in] pos element to return