<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-sgsn/+/15158">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gprs_gmm: Introduce macros to access msgb's associated IU UE ctx<br><br>Change-Id: I4d1d47af332d4557e8a3a70c1055bcc172166016<br>---<br>M src/gprs/gprs_gmm.c<br>1 file changed, 20 insertions(+), 22 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/58/15158/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c</span><br><span>index 3465a52..c93ddf4 100644</span><br><span>--- a/src/gprs/gprs_gmm.c</span><br><span>+++ b/src/gprs/gprs_gmm.c</span><br><span>@@ -116,6 +116,12 @@</span><br><span>      { 0, NULL }</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* On RANAP, Returns pointer to he associated ranap_ue_conn_ctx in msg, filled</span><br><span style="color: hsl(120, 100%, 40%);">+ * in by osmo-iuh's iu_recv_cb().</span><br><span style="color: hsl(120, 100%, 40%);">+ * On Gb, returns NULL */</span><br><span style="color: hsl(120, 100%, 40%);">+#define MSG_IU_UE_CTX(msg) ((struct ranap_ue_conn_ctx *)(msg)->dst)</span><br><span style="color: hsl(120, 100%, 40%);">+#define MSG_IU_UE_CTX_SET(msg, val) (msg)->dst = (val)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx);</span><br><span> </span><br><span> static void mmctx_change_gtpu_endpoints_to_sgsn(struct sgsn_mm_ctx *mm_ctx)</span><br><span>@@ -271,10 +277,7 @@</span><br><span>   }</span><br><span> </span><br><span> #ifdef BUILD_IU</span><br><span style="color: hsl(0, 100%, 40%);">-        /* In Iu mode, msg->dst contains the ranap_ue_conn_ctx pointer, in Gb mode</span><br><span style="color: hsl(0, 100%, 40%);">-    * dst is empty. */</span><br><span style="color: hsl(0, 100%, 40%);">-     /* FIXME: have a more explicit indicator for Iu messages */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (msg->dst)</span><br><span style="color: hsl(120, 100%, 40%);">+      if (MSG_IU_UE_CTX(msg))</span><br><span>              return ranap_iu_tx(msg, GPRS_SAPI_GMM);</span><br><span> #endif</span><br><span> </span><br><span>@@ -289,7 +292,7 @@</span><br><span>  msgb_tlli(msg) = msgb_tlli(old);</span><br><span>     msgb_bvci(msg) = msgb_bvci(old);</span><br><span>     msgb_nsei(msg) = msgb_nsei(old);</span><br><span style="color: hsl(0, 100%, 40%);">-        msg->dst = old->dst;</span><br><span style="color: hsl(120, 100%, 40%);">+    MSG_IU_UE_CTX_SET(msg, MSG_IU_UE_CTX(old));</span><br><span> }</span><br><span> </span><br><span> /* Store BVCI/NSEI in MM context */</span><br><span>@@ -298,7 +301,7 @@</span><br><span>    mm->gb.bvci = msgb_bvci(msg);</span><br><span>     mm->gb.nsei = msgb_nsei(msg);</span><br><span>     /* In case a Iu connection is reconnected we need to update the ue ctx */</span><br><span style="color: hsl(0, 100%, 40%);">-       mm->iu.ue_ctx = msg->dst;</span><br><span style="color: hsl(120, 100%, 40%);">+       mm->iu.ue_ctx = MSG_IU_UE_CTX(msg);</span><br><span>       if (mm->ran_type == MM_CTX_T_UTRAN_Iu</span><br><span>         && mm->iu.ue_ctx) {</span><br><span> #ifdef BUILD_IU</span><br><span>@@ -314,7 +317,7 @@</span><br><span>  msgb_tlli(msg) = mm->gb.tlli;</span><br><span>     msgb_bvci(msg) = mm->gb.bvci;</span><br><span>     msgb_nsei(msg) = mm->gb.nsei;</span><br><span style="color: hsl(0, 100%, 40%);">-        msg->dst = mm->iu.ue_ctx;</span><br><span style="color: hsl(120, 100%, 40%);">+       MSG_IU_UE_CTX_SET(msg, mm->iu.ue_ctx);</span><br><span> }</span><br><span> </span><br><span> static void mm_ctx_cleanup_free(struct sgsn_mm_ctx *ctx, const char *log_text)</span><br><span>@@ -1290,15 +1293,12 @@</span><br><span>        * with a foreign TLLI (P-TMSI that was allocated to the MS before),</span><br><span>          * or with random TLLI. */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  /* In Iu mode, msg->dst contains the ranap_ue_conn_ctx pointer, in Gb mode</span><br><span style="color: hsl(0, 100%, 40%);">-    * dst is empty. */</span><br><span style="color: hsl(0, 100%, 40%);">-     /* FIXME: have a more explicit indicator for Iu messages */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (!msg->dst) {</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!MSG_IU_UE_CTX(msg)) {</span><br><span>           /* Gb mode */</span><br><span>                cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg));</span><br><span>       } else {</span><br><span> #ifdef BUILD_IU</span><br><span style="color: hsl(0, 100%, 40%);">-             ra_id = ((struct ranap_ue_conn_ctx*)msg->dst)->ra_id;</span><br><span style="color: hsl(120, 100%, 40%);">+           ra_id = MSG_IU_UE_CTX(msg)->ra_id;</span><br><span> #else</span><br><span>               LOGMMCTXP(LOGL_ERROR, ctx, "Cannot handle Iu Attach Request, built without Iu support\n");</span><br><span>                 return -ENOTSUP;</span><br><span>@@ -1354,8 +1354,8 @@</span><br><span>             if (!ctx)</span><br><span>                    ctx = sgsn_mm_ctx_by_imsi(mi_string);</span><br><span>                if (!ctx) {</span><br><span style="color: hsl(0, 100%, 40%);">-                     if (msg->dst)</span><br><span style="color: hsl(0, 100%, 40%);">-                                ctx = sgsn_mm_ctx_alloc_iu(msg->dst);</span><br><span style="color: hsl(120, 100%, 40%);">+                      if (MSG_IU_UE_CTX(msg))</span><br><span style="color: hsl(120, 100%, 40%);">+                               ctx = sgsn_mm_ctx_alloc_iu(MSG_IU_UE_CTX(msg));</span><br><span>                      else</span><br><span>                                 ctx = sgsn_mm_ctx_alloc_gb(0, &ra_id);</span><br><span>                   if (!ctx) {</span><br><span>@@ -1379,8 +1379,8 @@</span><br><span>          if (!ctx) {</span><br><span>                  /* Allocate a context as most of our code expects one.</span><br><span>                        * Context will not have an IMSI ultil ID RESP is received */</span><br><span style="color: hsl(0, 100%, 40%);">-                   if (msg->dst)</span><br><span style="color: hsl(0, 100%, 40%);">-                                ctx = sgsn_mm_ctx_alloc_iu(msg->dst);</span><br><span style="color: hsl(120, 100%, 40%);">+                      if (MSG_IU_UE_CTX(msg))</span><br><span style="color: hsl(120, 100%, 40%);">+                               ctx = sgsn_mm_ctx_alloc_iu(MSG_IU_UE_CTX(msg));</span><br><span>                      else</span><br><span>                                 ctx = sgsn_mm_ctx_alloc_gb(msgb_tlli(msg), &ra_id);</span><br><span>                      if (!ctx) {</span><br><span>@@ -1697,10 +1697,8 @@</span><br><span>                  * is an optimization to avoid the RA reject (impl detached)</span><br><span>                  * below, which will cause a new attach cycle. */</span><br><span>            /* Look-up the MM context based on old RA-ID and TLLI */</span><br><span style="color: hsl(0, 100%, 40%);">-                /* In Iu mode, msg->dst contains the ranap_ue_conn_ctx pointer, in Gb</span><br><span style="color: hsl(0, 100%, 40%);">-                 * mode dst is empty. */</span><br><span style="color: hsl(0, 100%, 40%);">-                /* FIXME: have a more explicit indicator for Iu messages */</span><br><span style="color: hsl(0, 100%, 40%);">-             if (!msg->dst) {</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!MSG_IU_UE_CTX(msg)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* Gb */</span><br><span>                     mmctx = sgsn_mm_ctx_by_tlli_and_ptmsi(msgb_tlli(msg), &old_ra_id);</span><br><span>               } else if (TLVP_PRESENT(&tp, GSM48_IE_GMM_ALLOC_PTMSI)) {</span><br><span> #ifdef BUILD_IU</span><br><span>@@ -1847,7 +1845,7 @@</span><br><span>     LOGMMCTXP(LOGL_INFO, ctx, "-> GMM SERVICE REQUEST ");</span><br><span> </span><br><span>       /* This message is only valid in Iu mode */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (!msg->dst) {</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!MSG_IU_UE_CTX(msg)) {</span><br><span>           LOGPC(DMM, LOGL_INFO, "Invalid if not in Iu mode\n");</span><br><span>              return -1;</span><br><span>   }</span><br><span>@@ -2904,7 +2902,7 @@</span><br><span>    struct sgsn_mm_ctx *mmctx;</span><br><span>   int rc = -EINVAL;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   mmctx = sgsn_mm_ctx_by_ue_ctx(msg->dst);</span><br><span style="color: hsl(120, 100%, 40%);">+   mmctx = sgsn_mm_ctx_by_ue_ctx(MSG_IU_UE_CTX(msg));</span><br><span>   if (mmctx) {</span><br><span>                 rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]);</span><br><span>              if (ra_id)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-sgsn/+/15158">change 15158</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-sgsn/+/15158"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-sgsn </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I4d1d47af332d4557e8a3a70c1055bcc172166016 </div>
<div style="display:none"> Gerrit-Change-Number: 15158 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>