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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gprs_bssgp: add support for SGSN oriented RESET<br><br>To support SGSN oriented RESET introduce a role flag to<br>track what's running the gprs_bssgp (local side).<br><br>Related: OS#3879<br>Change-Id: Ibcbaffa94cbdc4296a8a7c372304ac11d50d9559<br>---<br>M include/osmocom/gprs/gprs_bssgp.h<br>M src/gb/gprs_bssgp.c<br>2 files changed, 59 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h</span><br><span>index e55fa52..09f640d 100644</span><br><span>--- a/include/osmocom/gprs/gprs_bssgp.h</span><br><span>+++ b/include/osmocom/gprs/gprs_bssgp.h</span><br><span>@@ -125,6 +125,8 @@</span><br><span>     /*! default bucket leak rate of per-MS bucket in octests/s */</span><br><span>        uint32_t r_default_ms;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    /*! BSS or SGSN. This defines the local state. */</span><br><span style="color: hsl(120, 100%, 40%);">+     bool is_sgsn;</span><br><span>        /* we might want to add this as a shortcut later, avoiding the NSVC</span><br><span>   * lookup for every packet, similar to a routing cache */</span><br><span>    //struct gprs_nsvc *nsvc;</span><br><span>diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c</span><br><span>index 926b0ef..c91abd6 100644</span><br><span>--- a/src/gb/gprs_bssgp.c</span><br><span>+++ b/src/gb/gprs_bssgp.c</span><br><span>@@ -93,28 +93,40 @@</span><br><span>     return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! Transmit a BVC-RESET message with a given nsei and bvci (Chapter 10.4.12)</span><br><span style="color: hsl(120, 100%, 40%);">+/* Transmit a BVC-RESET or BVC-RESET-ACK with a given nsei and bvci (Chapter 10.4.12)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] pdu Either BSSGP_PDUT_BVC_RESET or BSSGP_PDUT_BVC_RESET_ACK</span><br><span>  *  \param[in] nsei The NSEI to transmit over</span><br><span>  *  \param[in] bvci BVCI of the BVC to reset</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param[in] cause The cause of the reset</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] cause The cause of the reset only valid for BSSGP_PDUT_BVC_RESET.</span><br><span>  *  \param[in] ra_id Pointer to the ra_id to include. If NULL no cell information will be included</span><br><span>  *  \param[in] cell_id The cell_id to include (if ra_id is not NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  returns >= 0 on success, on error < 0.</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-int bssgp_tx_bvc_reset_nsei_bvci(uint16_t nsei, uint16_t bvci, enum gprs_bssgp_cause cause, const struct gprs_ra_id *ra_id, uint16_t cell_id)</span><br><span style="color: hsl(120, 100%, 40%);">+static int tx_bvc_reset_nsei_bvci(enum bssgp_pdu_type pdu, uint16_t nsei, uint16_t bvci,</span><br><span style="color: hsl(120, 100%, 40%);">+                               enum gprs_bssgp_cause cause, const struct gprs_ra_id *ra_id, uint16_t cell_id)</span><br><span> {</span><br><span>        struct msgb *msg = bssgp_msgb_alloc();</span><br><span>       struct bssgp_normal_hdr *bgph =</span><br><span>              (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));</span><br><span>    uint16_t _bvci = osmo_htons(bvci);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        OSMO_ASSERT(pdu == BSSGP_PDUT_BVC_RESET || pdu == BSSGP_PDUT_BVC_RESET_ACK);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       msgb_nsei(msg) = nsei;</span><br><span>       msgb_bvci(msg) = 0; /* Signalling */</span><br><span style="color: hsl(0, 100%, 40%);">-    bgph->pdu_type = BSSGP_PDUT_BVC_RESET;</span><br><span style="color: hsl(0, 100%, 40%);">-       LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-RESET "</span><br><span style="color: hsl(0, 100%, 40%);">-            "CAUSE=%s\n", bvci, bssgp_cause_str(cause));</span><br><span style="color: hsl(120, 100%, 40%);">+        bgph->pdu_type = pdu;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> </span><br><span>       msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);</span><br><span style="color: hsl(0, 100%, 40%);">-   msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, (uint8_t *) &cause);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      if (pdu == BSSGP_PDUT_BVC_RESET) {</span><br><span style="color: hsl(120, 100%, 40%);">+            msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, (uint8_t *) &cause);</span><br><span style="color: hsl(120, 100%, 40%);">+                LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-RESET "</span><br><span style="color: hsl(120, 100%, 40%);">+                  "CAUSE=%s\n", bvci, bssgp_cause_str(cause));</span><br><span style="color: hsl(120, 100%, 40%);">+        } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-RESET-ACK\n", bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  if (ra_id) {</span><br><span>                 uint8_t bssgp_cid[8];</span><br><span>                bssgp_create_cell_id(bssgp_cid, ra_id, cell_id);</span><br><span>@@ -126,6 +138,31 @@</span><br><span>      return bssgp_ns_send(bssgp_ns_send_data, msg);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Transmit a BVC-RESET message with a given nsei and bvci (Chapter 10.4.12)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] nsei The NSEI to transmit over</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] bvci BVCI of the BVC to reset</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] cause The cause of the reset</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] ra_id Pointer to the ra_id to include. If NULL no cell information will be included</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] cell_id The cell_id to include (if ra_id is not NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  returns >= 0 on success, on error < 0.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int bssgp_tx_bvc_reset_nsei_bvci(uint16_t nsei, uint16_t bvci, enum gprs_bssgp_cause cause, const struct gprs_ra_id *ra_id, uint16_t cell_id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   return tx_bvc_reset_nsei_bvci(BSSGP_PDUT_BVC_RESET, nsei, bvci, cause, ra_id, cell_id);</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%);">+/*! Transmit a BVC-RESET-ACK message with a given nsei and bvci (Chapter 10.4.12)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] nsei The NSEI to transmit over</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] bvci BVCI of the BVC to reset</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] ra_id Pointer to the ra_id to include. If NULL no cell information will be included</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] cell_id The cell_id to include (if ra_id is not NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+ *  returns >= 0 on success, on error < 0.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int bssgp_tx_bvc_reset_ack_nsei_bvci(uint16_t nsei, uint16_t bvci, const struct gprs_ra_id *ra_id, uint16_t cell_id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        return tx_bvc_reset_nsei_bvci(BSSGP_PDUT_BVC_RESET_ACK, nsei, bvci, 0, ra_id, cell_id);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Initiate reset procedure for all PTP BVC on a given NSEI.</span><br><span>  *</span><br><span>  *  This function initiates reset procedure for all PTP BVC with a given cause.</span><br><span>@@ -178,6 +215,7 @@</span><br><span>                 return NULL;</span><br><span>         ctx->bvci = bvci;</span><br><span>         ctx->nsei = nsei;</span><br><span style="color: hsl(120, 100%, 40%);">+  ctx->is_sgsn = true;</span><br><span>      /* FIXME: BVCI is not unique, only BVCI+NSEI ?!? */</span><br><span>  ctx->ctrg = rate_ctr_group_alloc(ctx, &bssgp_ctrg_desc, bvci);</span><br><span>        if (!ctx->ctrg)</span><br><span>@@ -350,7 +388,7 @@</span><br><span> </span><br><span>         /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS</span><br><span>          * informs us about its RAC + Cell ID, so we can create a mapping */</span><br><span style="color: hsl(0, 100%, 40%);">-    if (bvci != 0 && bvci != 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (bctx->is_sgsn && bvci != 0 && bvci != 1) {</span><br><span>            if (!TLVP_PRES_LEN(tp, BSSGP_IE_CELL_ID, 8)) {</span><br><span>                       LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESET "</span><br><span>                                "missing mandatory IE\n", bvci);</span><br><span>@@ -363,6 +401,13 @@</span><br><span>                 osmo_rai_name(&bctx->ra_id), bctx->cell_id, bvci);</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Acknowledge the RESET to the BTS */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (bvci == 0 || bvci == 1 || bctx->is_sgsn)</span><br><span style="color: hsl(120, 100%, 40%);">+               bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK,</span><br><span style="color: hsl(120, 100%, 40%);">+                                     nsei, bvci, ns_bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+    else</span><br><span style="color: hsl(120, 100%, 40%);">+          bssgp_tx_bvc_reset_ack_nsei_bvci(nsei, bvci, &bctx->ra_id, bctx->cell_id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       /* Send NM_BVC_RESET.ind to NM */</span><br><span>    memset(&nmp, 0, sizeof(nmp));</span><br><span>    nmp.nsei = nsei;</span><br><span>@@ -372,10 +417,6 @@</span><br><span>      osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_RESET,</span><br><span>                        PRIM_OP_INDICATION, msg);</span><br><span>    bssgp_prim_cb(&nmp.oph, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-      /* Acknowledge the RESET to the BTS */</span><br><span style="color: hsl(0, 100%, 40%);">-  bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK,</span><br><span style="color: hsl(0, 100%, 40%);">-                       nsei, bvci, ns_bvci);</span><br><span>   return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -972,6 +1013,9 @@</span><br><span>    case BSSGP_PDUT_STATUS:</span><br><span>              /* This is already handled in bssgp_rcvmsg() */</span><br><span>              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case BSSGP_PDUT_BVC_RESET:</span><br><span style="color: hsl(120, 100%, 40%);">+            rc = bssgp_rx_bvc_reset(msg, tp, bctx->bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span>       case BSSGP_PDUT_DOWNLOAD_BSS_PFC:</span><br><span>    case BSSGP_PDUT_CREATE_BSS_PFC_ACK:</span><br><span>  case BSSGP_PDUT_CREATE_BSS_PFC_NACK:</span><br><span>@@ -1060,7 +1104,7 @@</span><br><span>                 LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx BVC-RESET-ACK\n", bvci);</span><br><span>               break;</span><br><span>       case BSSGP_PDUT_BVC_RESET:</span><br><span style="color: hsl(0, 100%, 40%);">-              /* BSS tells us that BVC init is required */</span><br><span style="color: hsl(120, 100%, 40%);">+          /* SGSN or BSS tells us that BVC init is required */</span><br><span>                 if (!TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2) ||</span><br><span>              !TLVP_PRES_LEN(tp, BSSGP_IE_CAUSE, 1)) {</span><br><span>                         LOGP(DLBSSGP, LOGL_ERROR, "BSSGP Rx BVC-RESET "</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/22945">change 22945</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/+/22945"/><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: Ibcbaffa94cbdc4296a8a7c372304ac11d50d9559 </div>
<div style="display:none"> Gerrit-Change-Number: 22945 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: lynxis lazus <lynxis@fe80.eu> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: daniel <dwillmann@sysmocom.de> </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>