aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/gsm
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2012-11-06 12:02:59 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-12-18 23:47:45 +0100
commit0167596c2bf19102eac8a69f5066eedbae72a167 (patch)
tree6a235c73c53b50de3c50416048bf1b39cc220cd0 /include/osmocom/gsm
parent31659f72cba5f354b79448991bb7d4ca1d608f83 (diff)
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.
Diffstat (limited to 'include/osmocom/gsm')
-rw-r--r--include/osmocom/gsm/tlv.h24
1 files changed, 24 insertions, 0 deletions
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 */