From bd6d5c10db634c752d25dee037179006d5f87cab Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 19 Dec 2018 19:01:03 +0100 Subject: 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 --- include/osmocom/gsm/tlv.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index 4c392645..d0c95522 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -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 -- cgit v1.2.3