pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-gprs/+/32572 )
Change subject: gmm: Switch state before announcing events to user
......................................................................
gmm: Switch state before announcing events to user
Update the state in the FSM before triggering paths implemented by the
user which may also again interact with the FSM. If the state is not
updated earlier, then the new interactions may encounter the FSM in an
unexpected state with regards to the event received.
Change-Id: I10eb23f6db5ff3b0b90f9066aa4fa44c8cb85170
---
M include/osmocom/gprs/gmm/gmm_ms_fsm.h
M src/gmm/gmm_ms_fsm.c
2 files changed, 49 insertions(+), 24 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-gprs refs/changes/72/32572/1
diff --git a/include/osmocom/gprs/gmm/gmm_ms_fsm.h
b/include/osmocom/gprs/gmm/gmm_ms_fsm.h
index 16bd022..516801e 100644
--- a/include/osmocom/gprs/gmm/gmm_ms_fsm.h
+++ b/include/osmocom/gprs/gmm/gmm_ms_fsm.h
@@ -42,28 +42,31 @@
GPRS_GMM_MS_EV_LOW_LVL_FAIL,
};
+/* Info about last initiated attach: */
+struct gprs_gmm_ms_fsm_attach_ctx {
+ enum osmo_gprs_gmm_attach_type type;
+ bool with_imsi;
+ bool explicit_att; /* true if by SMREG-ATTACH.req requested it */
+ bool implicit_att; /* true if GMMSM-ESTABLISH.req requested it */
+ /* Session Ids waiting for attach to happen during implicit_att: */
+ uint32_t sess_id[16];
+ uint8_t num_sess_id;
+ /* Retransmission of ATTACH REQUEST (T3310) */
+ uint8_t req_attempts;
+};
+
+/* Info about last initiated detach: */
+struct gprs_gmm_ms_fsm_detach_ctx {
+ enum osmo_gprs_gmm_detach_ms_type type;
+ enum osmo_gprs_gmm_detach_poweroff_type poweroff_type;
+};
+
struct gprs_gmm_ms_fsm_ctx {
struct osmo_fsm_inst *fi;
struct gprs_gmm_entity *gmme;
- /* Info about last initiated attach: */
- struct {
- enum osmo_gprs_gmm_attach_type type;
- bool with_imsi;
- bool explicit_att; /* true if by SMREG-ATTACH.req requested it */
- bool implicit_att; /* true if GMMSM-ESTABLISH.req requested it */
- /* Session Ids waiting for attach to happen during implicit_att: */
- uint32_t sess_id[16];
- uint8_t num_sess_id;
- /* Retransmission of ATTACH REQUEST (T3310) */
- uint8_t req_attempts;
- } attach;
-
- /* Info about last initiated detach: */
- struct {
- enum osmo_gprs_gmm_detach_ms_type type;
- enum osmo_gprs_gmm_detach_poweroff_type poweroff_type;
- } detach;
+ struct gprs_gmm_ms_fsm_attach_ctx attach;
+ struct gprs_gmm_ms_fsm_detach_ctx detach;
};
int gprs_gmm_ms_fsm_init(void);
diff --git a/src/gmm/gmm_ms_fsm.c b/src/gmm/gmm_ms_fsm.c
index 93dd397..85aa6bf 100644
--- a/src/gmm/gmm_ms_fsm.c
+++ b/src/gmm/gmm_ms_fsm.c
@@ -104,6 +104,7 @@
struct gprs_gmm_ms_fsm_ctx *ctx = (struct gprs_gmm_ms_fsm_ctx *)fi->priv;
uint8_t cause;
int rc;
+ struct gprs_gmm_ms_fsm_attach_ctx att;
switch (event) {
case GPRS_GMM_MS_EV_ATTACH_REQUESTED:
@@ -114,28 +115,36 @@
cause = *(uint8_t *)data;
/* fall-through */
case GPRS_GMM_MS_EV_LOW_LVL_FAIL:
+ /* Update state before announcing event to users. Moving to
+ * Deregistered reset attach ctx, hence do a tmp copy here: */
+ memcpy(&att, &ctx->attach, sizeof(att));
+ gmm_ms_fsm_state_chg(fi, GPRS_GMM_MS_ST_DEREGISTERED);
+
if (event == GPRS_GMM_MS_EV_LOW_LVL_FAIL)
cause = GMM_CAUSE_MAC_FAIL;
- if (ctx->attach.explicit_att) {
+
+ if (att.explicit_att) {
/* Submit GMMREG-ATTACH-REJ as per TS 24.007 Annex C.1 */
rc = gprs_gmm_submit_gmmreg_attach_cnf(ctx->gmme, false, cause);
if (rc < 0)
return;
}
- if (ctx->attach.implicit_att) {
+
+ if (att.implicit_att) {
/* Submit GMMSM-ESTABLISH-CNF as per TS 24.007 Annex C.3 */
unsigned int i;
- for (i = 0; i < ctx->attach.num_sess_id; i++) {
+ for (i = 0; i < att.num_sess_id; i++) {
rc = gprs_gmm_submit_gmmsm_establish_cnf(ctx->gmme,
- ctx->attach.sess_id[i],
+ att.sess_id[i],
false, cause);
if (rc < 0)
return;
}
}
- gmm_ms_fsm_state_chg(fi, GPRS_GMM_MS_ST_DEREGISTERED);
break;
case GPRS_GMM_MS_EV_ATTACH_ACCEPTED:
+ /* Update state before announcing event to users. */
+ gmm_ms_fsm_state_chg(fi, GPRS_GMM_MS_ST_REGISTERED);
if (ctx->attach.explicit_att) {
/* Submit GMMREG-ATTACH-CNF as per TS 24.007 Annex C.1 */
rc = gprs_gmm_submit_gmmreg_attach_cnf(ctx->gmme, true, 0);
@@ -151,7 +160,6 @@
return;
}
}
- gmm_ms_fsm_state_chg(fi, GPRS_GMM_MS_ST_REGISTERED);
break;
case GPRS_GMM_MS_EV_DETACH_REQUESTED:
gmm_ms_fsm_state_chg(fi, GPRS_GMM_MS_ST_DEREGISTERED);
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-gprs/+/32572
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-gprs
Gerrit-Branch: master
Gerrit-Change-Id: I10eb23f6db5ff3b0b90f9066aa4fa44c8cb85170
Gerrit-Change-Number: 32572
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange