Introduce FSM mm_state_gb_fsm

Implement TS 23.060 6.1.1 Mobility Management States (A/Gb mode) using
osmocom FSM and drop old implementation.
Most of the logic on each state is still kept in gprs_gmm.c, will be
inserted into the FSM later.

Change-Id: I04004423e993107374d5a3549b8a93ac169251dd
diff --git a/include/osmocom/sgsn/Makefile.am b/include/osmocom/sgsn/Makefile.am
index b91c9f1..d6ee445 100644
--- a/include/osmocom/sgsn/Makefile.am
+++ b/include/osmocom/sgsn/Makefile.am
@@ -7,6 +7,7 @@
 	gprs_gb_parse.h \
 	gprs_gmm.h \
 	gprs_gmm_attach.h \
+	gprs_mm_state_gb_fsm.h \
 	gprs_llc.h \
 	gprs_llc_xid.h \
 	gprs_ranap.h \
diff --git a/include/osmocom/sgsn/gprs_gmm.h b/include/osmocom/sgsn/gprs_gmm.h
index 6c72cda..2fa12e5 100644
--- a/include/osmocom/sgsn/gprs_gmm.h
+++ b/include/osmocom/sgsn/gprs_gmm.h
@@ -50,8 +50,6 @@
 void pdp_ctx_detach_mm_ctx(struct sgsn_pdp_ctx *pdp);
 
 void mmctx_set_pmm_state(struct sgsn_mm_ctx *ctx, enum gprs_mm_state_iu state);
-void mmctx_state_timer_start(struct sgsn_mm_ctx *mm, unsigned int T);
-void mmctx_set_mm_state(struct sgsn_mm_ctx *ctx, enum gprs_mm_state_gb state);
 
 void msgid2mmctx(struct sgsn_mm_ctx *mm, const struct msgb *msg);
 #endif /* _GPRS_GMM_H */
diff --git a/include/osmocom/sgsn/gprs_mm_state_gb_fsm.h b/include/osmocom/sgsn/gprs_mm_state_gb_fsm.h
new file mode 100644
index 0000000..e69e1e1
--- /dev/null
+++ b/include/osmocom/sgsn/gprs_mm_state_gb_fsm.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <osmocom/core/fsm.h>
+
+struct sgsn_mm_ctx;
+
+
+/* TS 23.060 6.1.1 Mobility Management States (A/Gb mode) */
+enum mm_state_gb_fsm_states {
+	ST_MM_IDLE,
+	ST_MM_READY,
+	ST_MM_STANDBY
+};
+
+enum mm_state_gb_fsm_events {
+	E_MM_GPRS_ATTACH,
+	/* E_GPRS_DETACH, TODO: not used */
+	E_MM_PDU_RECEPTION,
+	E_MM_IMPLICIT_DETACH, /* = E_MM_CANCEL_LOCATION */
+	E_MM_READY_TIMER_EXPIRY,
+	/* E_FORCE_TO_STANDBY, TODO: not used */
+	/* E_ABNSORMAL_RLC_CONDITION, TODO: not used */
+	E_MM_RA_UPDATE,
+};
+
+extern struct osmo_fsm mm_state_gb_fsm;
diff --git a/include/osmocom/sgsn/gprs_sgsn.h b/include/osmocom/sgsn/gprs_sgsn.h
index f64e07b..382019c 100644
--- a/include/osmocom/sgsn/gprs_sgsn.h
+++ b/include/osmocom/sgsn/gprs_sgsn.h
@@ -32,12 +32,6 @@
 	GMM_DEREGISTERED_INIT,		/* 4.1.3.3.1.4 */
 };
 
-/* TS 23.060 6.1.1 Mobility Management States (A/Gb mode) */
-enum gprs_mm_state_gb {
-	MM_IDLE,
-	MM_READY,
-	MM_STANDBY
-};
 /* TS 23.060 6.1.2 Mobility Management States (Iu mode) */
 enum gprs_mm_state_iu {
 	PMM_DETACHED,
@@ -161,10 +155,7 @@
 		uint32_t		tlli_new;
 
 		/* TS 23.060 6.1.1 Mobility Management States (A/Gb mode) */
-		enum gprs_mm_state_gb	mm_state;
-		/* timer for mm state. state=READY: T3314 (aka TS 23.060 "READY timer") */
-		struct osmo_timer_list  state_timer;
-		unsigned int		state_T;	/* Txxxx number but only used for mm_state */
+		struct osmo_fsm_inst	*mm_state_fsm;
 	} gb;
 	struct {
 		int			new_key;