Add tlvp_val16_unal() / tlvp_val32_unal() to align 16 and 32 bit values
This is required for CPUs < armv6, to access 16 and 32 values at right
memory locations.
diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h
index 9c0319d..a70b0f9 100644
--- a/include/osmocom/gsm/tlv.h
+++ b/include/osmocom/gsm/tlv.h
@@ -410,6 +410,30 @@
#define TLVP_LEN(x, y) (x)->lv[y].len
#define TLVP_VAL(x, y) (x)->lv[y].val
+/*! \brief 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
+ * \returns aligned 16 bit value
+ */
+static inline uint16_t tlvp_val16_unal(const struct tlv_parsed *tp, int pos)
+{
+ uint16_t res;
+ memcpy(&res, TLVP_VAL(tp, pos), sizeof(res));
+ return res;
+}
+
+/*! \brief Align given TLV element with 32 bit value to an address that is a multiple of 4
+ * \param[in] tp pointer to \ref tlv_parsed
+ * \param[in] pos element to return
+ * \returns aligned 32 bit value
+ */
+static inline uint32_t tlvp_val32_unal(const struct tlv_parsed *tp, int pos)
+{
+ uint32_t res;
+ memcpy(&res, TLVP_VAL(tp, pos), sizeof(res));
+ return res;
+}
+
/*! @} */
#endif /* _TLV_H */