pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-sgsn/+/15186


Change subject: gprs_gmm.c: Call mmctx_set_(p)mm_state only on related ran_type
......................................................................

gprs_gmm.c: Call mmctx_set_(p)mm_state only on related ran_type

For new readers it's very confusing why PMM states and MM states are in
the same enum, but handled with different functions, and sometimes
called one right after the other with different enums. Calling them when
on a different ran_type makes the function early return, so let's better
conditionally call the function to make it clear in the flow when the
function is expected to do something.

Change-Id: I65ad9e180177bc9fc7c4a037cd85cfe33b161f73
---
M src/gprs/gprs_gmm.c
1 file changed, 34 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/86/15186/1

diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 61c5908..1e586c2 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -138,9 +138,6 @@

 static void mmctx_set_pmm_state(struct sgsn_mm_ctx *ctx, enum gprs_pmm_state 
state)
 {
-       if (ctx->ran_type != MM_CTX_T_UTRAN_Iu)
-               return;
-
        if (ctx->pmm_state == state)
                return;

@@ -164,9 +161,6 @@

 static void mmctx_set_mm_state(struct sgsn_mm_ctx *ctx, enum gprs_pmm_state 
state)
 {
-       if (ctx->ran_type != MM_CTX_T_GERAN_Gb)
-               return;
-
        if (ctx->pmm_state == state)
                return;

@@ -206,7 +200,7 @@
                else
                        LOGMMCTXP(LOGL_INFO, mm, "IU release for UE conn 
0x%x\n",
                                  ctx->conn_id);
-               if (mm && mm->pmm_state == PMM_CONNECTED)
+               if (mm && mm->ran_type == MM_CTX_T_UTRAN_Iu && mm->pmm_state == 
PMM_CONNECTED)
                        mmctx_set_pmm_state(mm, PMM_IDLE);
                rc = 0;
                break;
@@ -326,8 +320,17 @@

        /* Mark MM state as deregistered */
        ctx->gmm_state = GMM_DEREGISTERED;
-       mmctx_set_pmm_state(ctx, PMM_DETACHED);
-       mmctx_set_mm_state(ctx, MM_IDLE);
+
+       switch(ctx->ran_type) {
+       case MM_CTX_T_UTRAN_Iu:
+               mmctx_set_pmm_state(ctx, PMM_DETACHED);
+               break;
+       case MM_CTX_T_GERAN_Gb:
+               mmctx_set_mm_state(ctx, MM_IDLE);
+               break;
+       case MM_CTX_T_GERAN_Iu:
+               break;
+       }

        sgsn_mm_ctx_cleanup_free(ctx);
 }
@@ -1092,7 +1095,8 @@
 #ifdef BUILD_IU
        case GSM48_MT_GMM_SERVICE_REQ:
                ctx->pending_req = 0;
-               mmctx_set_pmm_state(ctx, PMM_CONNECTED);
+               if (ctx->ran_type == MM_CTX_T_UTRAN_Iu)
+                       mmctx_set_pmm_state(ctx, PMM_CONNECTED);
                rc = gsm48_tx_gmm_service_ack(ctx);

                if (ctx->iu.service.type != GPRS_SERVICE_T_SIGNALLING)
@@ -2073,16 +2077,22 @@
                mmctx->t3350_mode = GMM_T3350_MODE_NONE;
                mmctx->p_tmsi_old = 0;
                mmctx->pending_req = 0;
-               if (mmctx->ran_type == MM_CTX_T_GERAN_Gb) {
+               mmctx->gmm_state = GMM_REGISTERED_NORMAL;
+               switch(mmctx->ran_type) {
+               case MM_CTX_T_UTRAN_Iu:
+                       mmctx_set_pmm_state(mmctx, PMM_CONNECTED);
+                       break;
+               case MM_CTX_T_GERAN_Gb:
                        /* Unassign the old TLLI */
                        mmctx->gb.tlli = mmctx->gb.tlli_new;
                        gprs_llme_copy_key(mmctx, mmctx->gb.llme);
                        gprs_llgmm_assign(mmctx->gb.llme, TLLI_UNASSIGNED,
                                          mmctx->gb.tlli_new);
+                       mmctx_set_mm_state(mmctx, MM_READY);
+                       break;
+               case MM_CTX_T_GERAN_Iu:
+                       break;
                }
-               mmctx->gmm_state = GMM_REGISTERED_NORMAL;
-               mmctx_set_pmm_state(mmctx, PMM_CONNECTED);
-               mmctx_set_mm_state(mmctx, MM_READY);
                rc = 0;

                osmo_fsm_inst_dispatch(mmctx->gmm_att_req.fsm, 
E_ATTACH_COMPLETE_RECV, 0);
@@ -2099,15 +2109,21 @@
                mmctx->t3350_mode = GMM_T3350_MODE_NONE;
                mmctx->p_tmsi_old = 0;
                mmctx->pending_req = 0;
-               if (mmctx->ran_type == MM_CTX_T_GERAN_Gb) {
+               mmctx->gmm_state = GMM_REGISTERED_NORMAL;
+               switch(mmctx->ran_type) {
+               case MM_CTX_T_UTRAN_Iu:
+                       mmctx_set_pmm_state(mmctx, PMM_CONNECTED);
+                       break;
+               case MM_CTX_T_GERAN_Gb:
                        /* Unassign the old TLLI */
                        mmctx->gb.tlli = mmctx->gb.tlli_new;
                        gprs_llgmm_assign(mmctx->gb.llme, TLLI_UNASSIGNED,
                                          mmctx->gb.tlli_new);
+                       mmctx_set_mm_state(mmctx, MM_READY);
+                       break;
+               case MM_CTX_T_GERAN_Iu:
+                       break;
                }
-               mmctx->gmm_state = GMM_REGISTERED_NORMAL;
-               mmctx_set_pmm_state(mmctx, PMM_CONNECTED);
-               mmctx_set_mm_state(mmctx, MM_READY);
                rc = 0;
 
                memset(&sig_data, 0, sizeof(sig_data));

--
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/15186
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: I65ad9e180177bc9fc7c4a037cd85cfe33b161f73
Gerrit-Change-Number: 15186
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to