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

Change subject: tlv.h: add msgb_tvl_put() to add a TvLV without the value part
......................................................................

tlv.h: add msgb_tvl_put() to add a TvLV without the value part

So far, we have msgb_tl_put(), which allows putting the TL header of a TLV,
without the value part. Add the same for a variable-size length TvLV: put a TvL
header of a TvLV without the value part.

In a subsequent patch, osmo_mobile_identity will be introduced, which will
allow writing the encoded MI directly to the end of a msgb. For BSSGP_IE_IMSI,
which is a TvLV, it would hence be simplest to write only the TvL first.

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

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h
index bb0e8fc..254c21b 100644
--- a/include/osmocom/gsm/tlv.h
+++ b/include/osmocom/gsm/tlv.h
@@ -111,6 +111,14 @@
        return buf + len;
 }

+/*! put (append) a TL field (a TLV field but omitting the value part). */
+static inline uint8_t *tl_put(uint8_t *buf, uint8_t tag, uint8_t len)
+{
+       *buf++ = tag;
+       *buf++ = len;
+       return buf;
+}
+
 /*! put (append) a TLV16 field */
 static inline uint8_t *tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,
                                const uint16_t *val)
@@ -132,6 +140,15 @@
        return buf + len*2;
 }

+/*! put (append) a TL16 field. */
+static inline uint8_t *tl16_put(uint8_t *buf, uint8_t tag, uint16_t len)
+{
+       *buf++ = tag;
+       *buf++ = len >> 8;
+       *buf++ = len & 0xff;
+       return buf;
+}
+
 /*! put (append) a TL16V field */
 static inline uint8_t *t16lv_put(uint8_t *buf, uint16_t tag, uint8_t len,
                                const uint8_t *val)
@@ -158,6 +175,23 @@
        return ret;
 }

+/*! put (append) a TvL field (a TvLV with variable-size length, where the 
value part's length is already known, but will
+ * be put() later).
+ * \returns pointer to the value's start position.
+ */
+static inline uint8_t *tvl_put(uint8_t *buf, uint8_t tag, uint16_t len)
+{
+       uint8_t *ret;
+
+       if (len <= TVLV_MAX_ONEBYTE) {
+               ret = tl_put(buf, tag, len);
+               buf[1] |= 0x80;
+       } else
+               ret = tl16_put(buf, tag, len);
+
+       return ret;
+}
+
 /*! put (append) a variable-length tag or variable-length length * */
 static inline uint8_t *vt_gan_put(uint8_t *buf, uint16_t tag)
 {
@@ -215,6 +249,17 @@
        return t16lv_put(buf, tag, len, val);
 }

+/*! put (append) a TvL field to \ref msgb, i.e. a TvLV with variable-size 
length, where the value's length is already
+ * known, but will be put() later. The value section is not yet reserved, only 
tag and variable-length are put in the
+ * msgb.
+ * \returns pointer to the value's start position and end of the msgb.
+ */
+static inline uint8_t *msgb_tvl_put(struct msgb *msg, uint8_t tag, uint16_t 
len)
+{
+       uint8_t *buf = msgb_put(msg, TVLV_GROSS_LEN(len));
+       return tvl_put(buf, tag, len);
+}
+
 /*! put (append) a TvLV field to \ref msgb */
 static inline uint8_t *msgb_tvlv_put(struct msgb *msg, uint8_t tag, uint16_t 
len,
                                      const uint8_t *val)

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I02cca5182fe42e40b63680a2fd470f03bcc11076
Gerrit-Change-Number: 18634
Gerrit-PatchSet: 6
Gerrit-Owner: neels <nhofm...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to