diff options
author | Harald Welte <laforge@osmocom.org> | 2020-12-08 20:32:12 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2020-12-08 21:37:45 +0100 |
commit | dec201a6069d2625da6c10c088976d1c9d691376 (patch) | |
tree | 307c5fb31377ba2c4577b3dd3b922b983c985e2f /include/osmocom/gsm/tlv.h | |
parent | a6f896232ea70dcbe6b65bbe2e3be59f611b16c1 (diff) |
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
Diffstat (limited to 'include/osmocom/gsm/tlv.h')
-rw-r--r-- | include/osmocom/gsm/tlv.h | 15 |
1 files changed, 15 insertions, 0 deletions
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 <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 @@ 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) |