From 0167596c2bf19102eac8a69f5066eedbae72a167 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Tue, 6 Nov 2012 12:02:59 +0100 Subject: 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. --- include/osmocom/gsm/tlv.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include/osmocom/gsm') diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index 9c0319d9..a70b0f9c 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -410,6 +410,30 @@ void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src) #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 */ -- cgit v1.2.3