From dec201a6069d2625da6c10c088976d1c9d691376 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 8 Dec 2020 20:32:12 +0100 Subject: 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 --- include/osmocom/gsm/tlv.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index d34b7dab..fe057f4b 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -278,6 +279,20 @@ static inline uint8_t *msgb_tvlv_put(struct msgb *msg, uint8_t tag, uint16_t len 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) -- cgit v1.2.3