<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-pcu/+/17617">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">BSSGP: fix: properly encode P-TMSI in RR Paging Request<br><br>The TMSI/P-TMSI IE in BSSGP PAGING-PS/CS comes without the MI type<br>header, that must be present in RR Paging Request. Prepend it.<br><br>TTCN-3 test case: I7fbec5b2c5c3943a7413417b623f55c135c152d7<br><br>Change-Id: I97fd5ffc15a4a58112d7c37c69b7ac42b0741a0e<br>---<br>M src/gprs_bssgp_pcu.cpp<br>1 file changed, 36 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/17/17617/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp</span><br><span>index efddc03..b8e746a 100644</span><br><span>--- a/src/gprs_bssgp_pcu.cpp</span><br><span>+++ b/src/gprs_bssgp_pcu.cpp</span><br><span>@@ -166,22 +166,46 @@</span><br><span>                       ms_class, egprs_ms_class, delay_csec, data, len);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Returns 0 on success, suggested BSSGP cause otherwise */</span><br><span style="color: hsl(120, 100%, 40%);">+static unsigned int get_paging_mi(const uint8_t **mi, uint8_t *mi_len,</span><br><span style="color: hsl(120, 100%, 40%);">+                                 const struct tlv_parsed *tp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     static uint8_t tmsi_buf[GSM48_TMSI_LEN];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Use TMSI (if present) or IMSI */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (TLVP_PRESENT(tp, BSSGP_IE_TMSI)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                /* Be safe against an evil SGSN - check the length */</span><br><span style="color: hsl(120, 100%, 40%);">+         if (TLVP_LEN(tp, BSSGP_IE_TMSI) != GSM23003_TMSI_NUM_BYTES) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 LOGP(DBSSGP, LOGL_NOTICE, "TMSI IE has odd length (!= 4)\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                       return BSSGP_CAUSE_COND_IE_ERR;</span><br><span style="color: hsl(120, 100%, 40%);">+               }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           /* NOTE: TMSI (unlike IMSI) IE comes without MI type header */</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy(tmsi_buf + 1, TLVP_VAL(tp, BSSGP_IE_TMSI), GSM23003_TMSI_NUM_BYTES);</span><br><span style="color: hsl(120, 100%, 40%);">+           tmsi_buf[0] = 0xf0 | GSM_MI_TYPE_TMSI;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+              *mi_len = GSM48_TMSI_LEN;</span><br><span style="color: hsl(120, 100%, 40%);">+             *mi = tmsi_buf;</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (TLVP_PRESENT(tp, BSSGP_IE_IMSI)) {</span><br><span style="color: hsl(120, 100%, 40%);">+         *mi_len = TLVP_LEN(tp, BSSGP_IE_IMSI);</span><br><span style="color: hsl(120, 100%, 40%);">+                *mi = TLVP_VAL(tp, BSSGP_IE_IMSI);</span><br><span style="color: hsl(120, 100%, 40%);">+    } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGP(DBSSGP, LOGL_ERROR, "Neither TMSI IE nor IMSI IE is present\n");</span><br><span style="color: hsl(120, 100%, 40%);">+               return BSSGP_CAUSE_MISSING_COND_IE;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int gprs_bssgp_pcu_rx_paging_cs(struct msgb *msg, struct tlv_parsed *tp)</span><br><span> {</span><br><span>       const uint8_t *mi;</span><br><span>   uint8_t mi_len;</span><br><span style="color: hsl(120, 100%, 40%);">+       int rc;</span><br><span>      uint8_t *chan_needed = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_CHAN_NEEDED);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-       if (TLVP_PRESENT(tp, BSSGP_IE_TMSI)) {</span><br><span style="color: hsl(0, 100%, 40%);">-          mi_len = TLVP_LEN(tp, BSSGP_IE_TMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-           mi = TLVP_VAL(tp, BSSGP_IE_TMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-       } else if (TLVP_PRESENT(tp, BSSGP_IE_IMSI)) { /* Use IMSI if TMSI not available: */</span><br><span style="color: hsl(0, 100%, 40%);">-             mi_len = TLVP_LEN(tp, BSSGP_IE_IMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-           mi = TLVP_VAL(tp, BSSGP_IE_IMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-       } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                LOGP(DBSSGP, LOGL_ERROR, "Neither TMSI IE nor IMSI IE is present\n");</span><br><span style="color: hsl(0, 100%, 40%);">-         return bssgp_tx_status(BSSGP_CAUSE_COND_IE_ERR, NULL, msg);</span><br><span style="color: hsl(0, 100%, 40%);">-     }</span><br><span style="color: hsl(120, 100%, 40%);">+     if ((rc = get_paging_mi(&mi, &mi_len, tp)) > 0)</span><br><span style="color: hsl(120, 100%, 40%);">+            return bssgp_tx_status((enum gprs_bssgp_cause) rc, NULL, msg);</span><br><span> </span><br><span>   return BTS::main_bts()->add_paging(chan_needed ? *chan_needed : 0, mi, mi_len);</span><br><span> }</span><br><span>@@ -212,13 +236,8 @@</span><br><span>               return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg);</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (TLVP_PRESENT(tp, BSSGP_IE_TMSI)) {</span><br><span style="color: hsl(0, 100%, 40%);">-          mi_len = TLVP_LEN(tp, BSSGP_IE_TMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-           mi = TLVP_VAL(tp, BSSGP_IE_TMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-       } else { /* Use IMSI if TMSI not available: */</span><br><span style="color: hsl(0, 100%, 40%);">-          mi_len = TLVP_LEN(tp, BSSGP_IE_IMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-           mi = TLVP_VAL(tp, BSSGP_IE_IMSI);</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(120, 100%, 40%);">+     if ((rc = get_paging_mi(&mi, &mi_len, tp)) > 0)</span><br><span style="color: hsl(120, 100%, 40%);">+            return bssgp_tx_status((enum gprs_bssgp_cause) rc, NULL, msg);</span><br><span> </span><br><span>   return gprs_rlcmac_paging_request(mi, mi_len, pgroup);</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-pcu/+/17617">change 17617</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/osmo-pcu/+/17617"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-pcu </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I97fd5ffc15a4a58112d7c37c69b7ac42b0741a0e </div>
<div style="display:none"> Gerrit-Change-Number: 17617 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>