Change in libosmocore[master]: tlv.h: Add msgb_tvlv_put_{16,32}be()

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/.

laforge gerrit-no-reply at lists.osmocom.org
Wed Dec 9 09:46:04 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/21609 )

Change subject: tlv.h: Add msgb_tvlv_put_{16,32}be()
......................................................................

tlv.h: Add msgb_tvlv_put_{16,32}be()

Those routines are very useful when puzzling together BSSGP messages
with 16-bit and 32bit sized IEs.

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

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved
  fixeria: Looks good to me, approved



diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h
index d34b7da..fe057f4 100644
--- a/include/osmocom/gsm/tlv.h
+++ b/include/osmocom/gsm/tlv.h
@@ -4,6 +4,7 @@
 #include <string.h>
 
 #include <osmocom/core/msgb.h>
+#include <osmocom/core/byteswap.h>
 #include <osmocom/core/bit16gen.h>
 #include <osmocom/core/bit32gen.h>
 
@@ -278,6 +279,20 @@
 	return tvlv_put(buf, tag, len, val);
 }
 
+/*! put (append) a TvLV field containing a big-endian 16bit value to msgb. */
+static inline uint8_t *msgb_tvlv_put_16be(struct msgb *msg, uint8_t tag, uint16_t val)
+{
+	uint16_t val_be = osmo_htons(val);
+	return msgb_tvlv_put(msg, tag, 2, (const uint8_t *)&val_be);
+}
+
+/*! put (append) a TvLV field containing a big-endian 16bit value to msgb. */
+static inline uint8_t *msgb_tvlv_put_32be(struct msgb *msg, uint8_t tag, uint32_t val)
+{
+	uint32_t val_be = osmo_htonl(val);
+	return msgb_tvlv_put(msg, tag, 4, (const uint8_t *)&val_be);
+}
+
 /*! put (append) a vTvLV field to \ref msgb */
 static inline uint8_t *msgb_vtvlv_gan_put(struct msgb *msg, uint16_t tag,
 					  uint16_t len, const uint8_t *val)

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/21609
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I033f9a708c9d7ffad91336178231dc66233e1693
Gerrit-Change-Number: 21609
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201209/e21e4d50/attachment.htm>


More information about the gerrit-log mailing list