summaryrefslogtreecommitdiffstats
path: root/include/osmocom
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2018-12-19 19:01:03 +0100
committerMax <msuraev@sysmocom.de>2018-12-20 09:52:15 +0000
commitbd6d5c10db634c752d25dee037179006d5f87cab (patch)
treefc8a22a4c312e10bab550908e88f38c0b270bb5d /include/osmocom
parente6f63f22c5ae54c4bf884d85c7ce304955ee9533 (diff)
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
Diffstat (limited to 'include/osmocom')
-rw-r--r--include/osmocom/gsm/tlv.h16
1 files changed, 16 insertions, 0 deletions
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