<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/18634">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">tlv.h: add msgb_tvl_put() to add a TvLV without the value part<br><br>So far, we have msgb_tl_put(), which allows putting the TL header of a TLV,<br>without the value part. Add the same for a variable-size length TvLV: put a TvL<br>header of a TvLV without the value part.<br><br>In a subsequent patch, osmo_mobile_identity will be introduced, which will<br>allow writing the encoded MI directly to the end of a msgb. For BSSGP_IE_IMSI,<br>which is a TvLV, it would hence be simplest to write only the TvL first.<br><br>Change-Id: I02cca5182fe42e40b63680a2fd470f03bcc11076<br>---<br>M include/osmocom/gsm/tlv.h<br>1 file changed, 45 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h</span><br><span>index bb0e8fc..254c21b 100644</span><br><span>--- a/include/osmocom/gsm/tlv.h</span><br><span>+++ b/include/osmocom/gsm/tlv.h</span><br><span>@@ -111,6 +111,14 @@</span><br><span>        return buf + len;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! put (append) a TL field (a TLV field but omitting the value part). */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline uint8_t *tl_put(uint8_t *buf, uint8_t tag, uint8_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       *buf++ = tag;</span><br><span style="color: hsl(120, 100%, 40%);">+ *buf++ = len;</span><br><span style="color: hsl(120, 100%, 40%);">+ return buf;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! put (append) a TLV16 field */</span><br><span> static inline uint8_t *tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,</span><br><span>                            const uint16_t *val)</span><br><span>@@ -132,6 +140,15 @@</span><br><span>  return buf + len*2;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! put (append) a TL16 field. */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline uint8_t *tl16_put(uint8_t *buf, uint8_t tag, uint16_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  *buf++ = tag;</span><br><span style="color: hsl(120, 100%, 40%);">+ *buf++ = len >> 8;</span><br><span style="color: hsl(120, 100%, 40%);">+      *buf++ = len & 0xff;</span><br><span style="color: hsl(120, 100%, 40%);">+      return buf;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! put (append) a TL16V field */</span><br><span> static inline uint8_t *t16lv_put(uint8_t *buf, uint16_t tag, uint8_t len,</span><br><span>                           const uint8_t *val)</span><br><span>@@ -158,6 +175,23 @@</span><br><span>   return ret;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! put (append) a TvL field (a TvLV with variable-size length, where the value part's length is already known, but will</span><br><span style="color: hsl(120, 100%, 40%);">+ * be put() later).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns pointer to the value's start position.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline uint8_t *tvl_put(uint8_t *buf, uint8_t tag, uint16_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t *ret;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       if (len <= TVLV_MAX_ONEBYTE) {</span><br><span style="color: hsl(120, 100%, 40%);">+             ret = tl_put(buf, tag, len);</span><br><span style="color: hsl(120, 100%, 40%);">+          buf[1] |= 0x80;</span><br><span style="color: hsl(120, 100%, 40%);">+       } else</span><br><span style="color: hsl(120, 100%, 40%);">+                ret = tl16_put(buf, tag, len);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      return ret;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! put (append) a variable-length tag or variable-length length * */</span><br><span> static inline uint8_t *vt_gan_put(uint8_t *buf, uint16_t tag)</span><br><span> {</span><br><span>@@ -215,6 +249,17 @@</span><br><span>       return t16lv_put(buf, tag, len, val);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! put (append) a TvL field to \ref msgb, i.e. a TvLV with variable-size length, where the value's length is already</span><br><span style="color: hsl(120, 100%, 40%);">+ * known, but will be put() later. The value section is not yet reserved, only tag and variable-length are put in the</span><br><span style="color: hsl(120, 100%, 40%);">+ * msgb.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns pointer to the value's start position and end of the msgb.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline uint8_t *msgb_tvl_put(struct msgb *msg, uint8_t tag, uint16_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t *buf = msgb_put(msg, TVLV_GROSS_LEN(len));</span><br><span style="color: hsl(120, 100%, 40%);">+    return tvl_put(buf, tag, len);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! put (append) a TvLV field to \ref msgb */</span><br><span> static inline uint8_t *msgb_tvlv_put(struct msgb *msg, uint8_t tag, uint16_t len,</span><br><span>                                  const uint8_t *val)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/18634">change 18634</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/18634"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I02cca5182fe42e40b63680a2fd470f03bcc11076 </div>
<div style="display:none"> Gerrit-Change-Number: 18634 </div>
<div style="display:none"> Gerrit-PatchSet: 6 </div>
<div style="display:none"> Gerrit-Owner: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>