[PATCH] libosmocore[master]: tlv: Add tlvp_val{16, 32}be() to get TLV values in unaligned ...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon May 15 11:14:19 UTC 2017


Review at  https://gerrit.osmocom.org/2625

tlv: Add tlvp_val{16,32}be() to get TLV values in unaligned host byte order

Change-Id: I3749e1e4974742bc8c32722e0e998775b5394829
---
M include/osmocom/gsm/tlv.h
1 file changed, 23 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/25/2625/1

diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h
index 701fe68..8caddae 100644
--- a/include/osmocom/gsm/tlv.h
+++ b/include/osmocom/gsm/tlv.h
@@ -4,6 +4,8 @@
 #include <string.h>
 
 #include <osmocom/core/msgb.h>
+#include <osmocom/core/bit16gen.h>
+#include <osmocom/core/bit32gen.h>
 
 /*! \defgroup tlv GSM L3 compatible TLV parser
  *  @{
@@ -436,6 +438,27 @@
 	return res;
 }
 
+/*! \brief Retrieve (possibly unaligned) TLV element and convert to host byte order
+ *  \param[in] tp pointer to \ref tlv_parsed
+ *  \param[in] pos element to return
+ *  \returns aligned 16 bit value in host byte order
+ */
+static inline uint16_t tlvp_val16be(const struct tlv_parsed *tp, int pos)
+{
+	return osmo_load16be(TLVP_VAL(tp, pos));
+}
+
+/*! \brief Retrieve (possibly unaligned) TLV element and convert to host byte order
+ *  \param[in] tp pointer to \ref tlv_parsed
+ *  \param[in] pos element to return
+ *  \returns aligned 32 bit value in host byte order
+ */
+static inline uint32_t tlvp_val32be(const struct tlv_parsed *tp, int pos)
+{
+	return osmo_load32be(TLVP_VAL(tp, pos));
+}
+
+
 struct tlv_parsed *osmo_tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx);
 int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src);
 int osmo_shift_v_fixed(uint8_t **data, size_t *data_len,

-- 
To view, visit https://gerrit.osmocom.org/2625
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3749e1e4974742bc8c32722e0e998775b5394829
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list