<p>daniel has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/22874">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bssgp2_enc_status: Truncate STATUS to MTU if necessary<br><br>Related: OS#4889<br>Change-Id: Ic39d918c56399ceb0431299ce938e3bf276f678a<br>---<br>M include/osmocom/gprs/gprs_bssgp2.h<br>M src/gb/bssgp_bvc_fsm.c<br>M src/gb/gprs_bssgp2.c<br>3 files changed, 17 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/74/22874/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/gprs/gprs_bssgp2.h b/include/osmocom/gprs/gprs_bssgp2.h</span><br><span>index bf814cb..46186fa 100644</span><br><span>--- a/include/osmocom/gprs/gprs_bssgp2.h</span><br><span>+++ b/include/osmocom/gprs/gprs_bssgp2.h</span><br><span>@@ -59,7 +59,7 @@</span><br><span> struct msgb *bssgp2_enc_bvc_reset_ack(uint16_t bvci, const struct gprs_ra_id *ra_id, uint16_t cell_id,</span><br><span>                                const uint8_t *feat_bm, const uint8_t *ext_feat_bm);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg);</span><br><span style="color: hsl(120, 100%, 40%);">+struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg, uint16_t mtu);</span><br><span> </span><br><span> </span><br><span> int bssgp2_dec_fc_bvc(struct bssgp2_flow_ctrl *fc, const struct tlv_parsed *tp);</span><br><span>diff --git a/src/gb/bssgp_bvc_fsm.c b/src/gb/bssgp_bvc_fsm.c</span><br><span>index a1edf58..9ac4250 100644</span><br><span>--- a/src/gb/bssgp_bvc_fsm.c</span><br><span>+++ b/src/gb/bssgp_bvc_fsm.c</span><br><span>@@ -238,7 +238,7 @@</span><br><span>      if (cause == BSSGP_CAUSE_UNKNOWN_BVCI || cause == BSSGP_CAUSE_BVCI_BLOCKED)</span><br><span>          bvci = &bfp->bvci;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   tx = bssgp2_enc_status(cause, bvci, rx);</span><br><span style="color: hsl(120, 100%, 40%);">+      tx = bssgp2_enc_status(cause, bvci, rx, bfp->mtu);</span><br><span> </span><br><span>    if (msgb_bvci(rx) == 0)</span><br><span>              fi_tx_sig(fi, tx);</span><br><span>diff --git a/src/gb/gprs_bssgp2.c b/src/gb/gprs_bssgp2.c</span><br><span>index 0f519ad..1a7874c 100644</span><br><span>--- a/src/gb/gprs_bssgp2.c</span><br><span>+++ b/src/gb/gprs_bssgp2.c</span><br><span>@@ -217,8 +217,9 @@</span><br><span> /*! Encode BSSGP STATUS PDU as per TS 48.018 Section 10.4.14.</span><br><span>  *  \param[in] cause BSSGP Cause value</span><br><span>  *  \param[in] bvci optional BVCI - only encoded if non-NULL</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param[in] msg optional message buffer containing PDU in error - only encoded if non-NULL */</span><br><span style="color: hsl(0, 100%, 40%);">-struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] msg optional message buffer containing PDU in error - only encoded if non-NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] mtu Maximum size the NS layer accepts as payload */</span><br><span style="color: hsl(120, 100%, 40%);">+struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg, uint16_t mtu)</span><br><span> {</span><br><span>     struct msgb *msg = bssgp_msgb_alloc();</span><br><span>       struct bssgp_normal_hdr *bgph;</span><br><span>@@ -229,12 +230,22 @@</span><br><span>       bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));</span><br><span>     bgph->pdu_type = BSSGP_PDUT_STATUS;</span><br><span>       msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);</span><br><span style="color: hsl(120, 100%, 40%);">+    /* FIXME: Require/encode BVCI only if cause is BVCI unknown/blocked</span><br><span style="color: hsl(120, 100%, 40%);">+    * See 3GPP TS 48.018 Ch. 10.4.14 */</span><br><span>         if (bvci) {</span><br><span>          uint16_t _bvci = osmo_htons(*bvci);</span><br><span>          msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);</span><br><span>        }</span><br><span style="color: hsl(0, 100%, 40%);">-       if (orig_msg)</span><br><span style="color: hsl(0, 100%, 40%);">-           msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR, msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));</span><br><span style="color: hsl(120, 100%, 40%);">+   if (orig_msg) {</span><br><span style="color: hsl(120, 100%, 40%);">+               uint32_t orig_len, max_orig_len;</span><br><span style="color: hsl(120, 100%, 40%);">+              /* Calculate how big the reply would be: the BSSGP msg so far + size of the PDU IN ERROR including tvl */</span><br><span style="color: hsl(120, 100%, 40%);">+             max_orig_len = msgb_length(msg) + TVLV_GROSS_LEN(msgb_bssgp_len(orig_msg));</span><br><span style="color: hsl(120, 100%, 40%);">+           orig_len = msgb_bssgp_len(orig_msg);</span><br><span style="color: hsl(120, 100%, 40%);">+          /* Truncate the difference between max_orig_len and mtu */</span><br><span style="color: hsl(120, 100%, 40%);">+            if (max_orig_len > mtu)</span><br><span style="color: hsl(120, 100%, 40%);">+                    orig_len -= max_orig_len - mtu;</span><br><span style="color: hsl(120, 100%, 40%);">+               msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR, orig_len, msgb_bssgph(orig_msg));</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span> </span><br><span>        return msg;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/22874">change 22874</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/+/22874"/><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: Ic39d918c56399ceb0431299ce938e3bf276f678a </div>
<div style="display:none"> Gerrit-Change-Number: 22874 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: daniel <dwillmann@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>