<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/11642">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">WIP: SGs Interface initial code<br><br>- LU works<br>- ISMI detach and EPS detach work (but presumably not as it should)<br>- Paging works so far that if the MSC has to page it may send a paging<br>  request via SGs<br><br>Change-Id: I73359925fc1ca72b33a1466e6ac41307f2f0b11d<br>Related: OS#3615<br>---<br>M include/osmocom/msc/Makefile.am<br>M include/osmocom/msc/debug.h<br>M include/osmocom/msc/gsm_data.h<br>M include/osmocom/msc/gsm_subscriber.h<br>A include/osmocom/msc/sgs_iface.h<br>A include/osmocom/msc/sgs_vty.h<br>M include/osmocom/msc/vlr.h<br>A include/osmocom/msc/vlr_sgs.h<br>M include/osmocom/msc/vty.h<br>M src/libmsc/Makefile.am<br>M src/libmsc/gsm_04_08_cc.c<br>M src/libmsc/gsm_04_11.c<br>M src/libmsc/gsm_09_11.c<br>M src/libmsc/gsm_subscriber.c<br>M src/libmsc/msc_vty.c<br>A src/libmsc/sgs_iface.c<br>A src/libmsc/sgs_vty.c<br>M src/libmsc/silent_call.c<br>M src/libvlr/Makefile.am<br>M src/libvlr/vlr.c<br>M src/libvlr/vlr_lu_fsm.c<br>A src/libvlr/vlr_sgs.c<br>A src/libvlr/vlr_sgs_fsm.c<br>A src/libvlr/vlr_sgs_fsm.h<br>M src/osmo-msc/Makefile.am<br>M src/osmo-msc/msc_main.c<br>M tests/msc_vlr/msc_vlr_test_authen_reuse.c<br>M tests/msc_vlr/msc_vlr_test_call.c<br>M tests/msc_vlr/msc_vlr_test_gsm_authen.c<br>M tests/msc_vlr/msc_vlr_test_gsm_ciph.c<br>M tests/msc_vlr/msc_vlr_test_hlr_reject.c<br>M tests/msc_vlr/msc_vlr_test_hlr_timeout.c<br>M tests/msc_vlr/msc_vlr_test_ms_timeout.c<br>M tests/msc_vlr/msc_vlr_test_no_authen.c<br>M tests/msc_vlr/msc_vlr_test_reject_concurrency.c<br>M tests/msc_vlr/msc_vlr_test_rest.c<br>M tests/msc_vlr/msc_vlr_test_ss.c<br>M tests/msc_vlr/msc_vlr_test_umts_authen.c<br>M tests/sms_queue/sms_queue_test.c<br>39 files changed, 2,060 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/42/11642/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/msc/Makefile.am b/include/osmocom/msc/Makefile.am</span><br><span>index ebc946a..35e8c5e 100644</span><br><span>--- a/include/osmocom/msc/Makefile.am</span><br><span>+++ b/include/osmocom/msc/Makefile.am</span><br><span>@@ -24,11 +24,14 @@</span><br><span>     a_reset.h \</span><br><span>  osmo_msc.h \</span><br><span>         rrlp.h \</span><br><span style="color: hsl(120, 100%, 40%);">+      sgs_iface.h \</span><br><span style="color: hsl(120, 100%, 40%);">+ sgs_vty.h \</span><br><span>  signal.h \</span><br><span>   silent_call.h \</span><br><span>      smpp.h \</span><br><span>     sms_queue.h \</span><br><span>        transaction.h \</span><br><span>      vlr.h \</span><br><span style="color: hsl(120, 100%, 40%);">+       vlr_sgs.h \</span><br><span>  vty.h \</span><br><span>      $(NULL)</span><br><span>diff --git a/include/osmocom/msc/debug.h b/include/osmocom/msc/debug.h</span><br><span>index 717cf74..28ba482 100644</span><br><span>--- a/include/osmocom/msc/debug.h</span><br><span>+++ b/include/osmocom/msc/debug.h</span><br><span>@@ -21,5 +21,6 @@</span><br><span>         DVLR,</span><br><span>        DIUCS,</span><br><span>       DBSSAP,</span><br><span style="color: hsl(120, 100%, 40%);">+       DSGS,</span><br><span>        Debug_LastEntry,</span><br><span> };</span><br><span>diff --git a/include/osmocom/msc/gsm_data.h b/include/osmocom/msc/gsm_data.h</span><br><span>index 085248c..94b5474 100644</span><br><span>--- a/include/osmocom/msc/gsm_data.h</span><br><span>+++ b/include/osmocom/msc/gsm_data.h</span><br><span>@@ -55,6 +55,7 @@</span><br><span>        RAN_UNKNOWN,</span><br><span>        RAN_GERAN_A,   /* 2G / A-interface */</span><br><span>        RAN_UTRAN_IU,  /* 3G / Iu-interface (IuCS or IuPS) */</span><br><span style="color: hsl(120, 100%, 40%);">+       RAN_UTRAN_SGS,   /* 4G / SGs-interface (csfb) */</span><br><span> };</span><br><span> </span><br><span> extern const struct value_string ran_type_names[];</span><br><span>@@ -124,7 +125,7 @@</span><br><span>        /* back pointers */</span><br><span>  struct gsm_network *network;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        /* connected via 2G or 3G? */</span><br><span style="color: hsl(120, 100%, 40%);">+ /* connected via 2G, 3G or 4G csfb via SGs */</span><br><span>        enum ran_type via_ran;</span><br><span> </span><br><span>   uint16_t lac;</span><br><span>diff --git a/include/osmocom/msc/gsm_subscriber.h b/include/osmocom/msc/gsm_subscriber.h</span><br><span>index 01d9c58..762c8e6 100644</span><br><span>--- a/include/osmocom/msc/gsm_subscriber.h</span><br><span>+++ b/include/osmocom/msc/gsm_subscriber.h</span><br><span>@@ -5,6 +5,7 @@</span><br><span> </span><br><span> #include <osmocom/core/linuxlist.h></span><br><span> #include <osmocom/gsm/protocol/gsm_23_003.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/protocol/gsm_29_118.h></span><br><span> </span><br><span> #include <osmocom/msc/gsm_data.h></span><br><span> </span><br><span>@@ -54,8 +55,8 @@</span><br><span>  */</span><br><span> struct subscr_request *subscr_request_conn(struct vlr_subscr *vsub,</span><br><span>                                            gsm_cbfn *cbfn, void *param,</span><br><span style="color: hsl(0, 100%, 40%);">-                                    const char *label);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+                                           const char *label,</span><br><span style="color: hsl(120, 100%, 40%);">+                                    enum sgsap_service_ind serv_ind);</span><br><span> void subscr_remove_request(struct subscr_request *req);</span><br><span> int subscr_rx_paging_response(struct msgb *msg,</span><br><span>                         struct gsm_subscriber_connection *conn);</span><br><span>diff --git a/include/osmocom/msc/sgs_iface.h b/include/osmocom/msc/sgs_iface.h</span><br><span>new file mode 100644</span><br><span>index 0000000..ea2bd62</span><br><span>--- /dev/null</span><br><span>+++ b/include/osmocom/msc/sgs_iface.h</span><br><span>@@ -0,0 +1,103 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/protocol/gsm_23_003.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/protocol/gsm_29_118.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum {</span><br><span style="color: hsl(120, 100%, 40%);">+     SGS_STATE_TS5, /* Started when sending the SGsAP-PAGING-REQUEST */</span><br><span style="color: hsl(120, 100%, 40%);">+    SGS_STATE_TS6_2, /* TMSI reallocation, 5.2.3.5 */</span><br><span style="color: hsl(120, 100%, 40%);">+     SGS_STATE_TS7, /* Started when SGsAP-ALERT-REQUEST is sent 5.3.2.1 */</span><br><span style="color: hsl(120, 100%, 40%);">+ SGS_STATE_TS11, /* Reset ack timeout */</span><br><span style="color: hsl(120, 100%, 40%);">+       SGS_STATE_TS14, /* Started when SGsAP-SERVICE-REQUEST is received 5.15.1 */</span><br><span style="color: hsl(120, 100%, 40%);">+   SGS_STATE_TS15, /* Started when SGsAP-MO-CSFB-INDICATION is received 5.16.3 (UE fallback) */</span><br><span style="color: hsl(120, 100%, 40%);">+  _NUM_SGS_STATE_TIMERS</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%);">+enum {</span><br><span style="color: hsl(120, 100%, 40%);">+   SGS_STATE_NS7, /* Alert request retransmit */</span><br><span style="color: hsl(120, 100%, 40%);">+ SGS_STATE_NS11, /* Reset repeat */</span><br><span style="color: hsl(120, 100%, 40%);">+    _NUM_SGS_STATE_COUNTERS</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%);">+static const unsigned int sgs_state_timer_defaults[_NUM_SGS_STATE_TIMERS] = {</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_STATE_TS5] = SGS_TS5_DEFAULT,</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_STATE_TS6_2] = SGS_TS6_2_DEFAULT,</span><br><span style="color: hsl(120, 100%, 40%);">+        [SGS_STATE_TS7] = SGS_TS7_DEFAULT,</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_STATE_TS11] = SGS_TS11_DEFAULT,</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_STATE_TS14] = SGS_TS14_DEFAULT,</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_STATE_TS15] = SGS_TS15_DEFAULT,</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%);">+static const unsigned int sgs_state_counter_defaults[_NUM_SGS_STATE_COUNTERS] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ [SGS_STATE_NS7] = SGS_NS7_DEFAULT,</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_STATE_NS11] = SGS_NS11_DEFAULT,</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%);">+/* global SGs state */</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_state {</span><br><span style="color: hsl(120, 100%, 40%);">+        /* list of MMEs (sgs_mme_ctx) */</span><br><span style="color: hsl(120, 100%, 40%);">+      struct llist_head mme_list;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* list of SCTP client connections */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct llist_head conn_list;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* SCTP server for inbound SGs connections */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct osmo_stream_srv_link *srv_link;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      struct {</span><br><span style="color: hsl(120, 100%, 40%);">+              char *local_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+             uint16_t local_port;</span><br><span style="color: hsl(120, 100%, 40%);">+          /* user-configured VLR name (FQDN) */</span><br><span style="color: hsl(120, 100%, 40%);">+         char *vlr_name;</span><br><span style="color: hsl(120, 100%, 40%);">+               /* timers on VLR side */</span><br><span style="color: hsl(120, 100%, 40%);">+              unsigned int timer[_NUM_SGS_STATE_TIMERS];</span><br><span style="color: hsl(120, 100%, 40%);">+            /* countrs on VLR side */</span><br><span style="color: hsl(120, 100%, 40%);">+             unsigned int counter[_NUM_SGS_STATE_COUNTERS];</span><br><span style="color: hsl(120, 100%, 40%);">+        } cfg;</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%);">+struct sgs_connection {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* global list of SGs connections */</span><br><span style="color: hsl(120, 100%, 40%);">+  struct llist_head list;</span><br><span style="color: hsl(120, 100%, 40%);">+       /* back-pointer */</span><br><span style="color: hsl(120, 100%, 40%);">+    struct sgs_state *sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* Socket name from osmo_sock_get_name() */</span><br><span style="color: hsl(120, 100%, 40%);">+   char *sockname;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* MME for this connection, if any.  This field is NULL until we</span><br><span style="color: hsl(120, 100%, 40%);">+       * receive the first "MME name" IE from the MME, which could be part</span><br><span style="color: hsl(120, 100%, 40%);">+         * of the RESET procedure, but also just a normal LU request. */</span><br><span style="color: hsl(120, 100%, 40%);">+      struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* represents the SCTP connection we accept()ed from this MME */</span><br><span style="color: hsl(120, 100%, 40%);">+      struct osmo_stream_srv *srv;</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%);">+struct sgs_mme_ctx {</span><br><span style="color: hsl(120, 100%, 40%);">+      /* global list of MME contexts */</span><br><span style="color: hsl(120, 100%, 40%);">+     struct llist_head list;</span><br><span style="color: hsl(120, 100%, 40%);">+       /* back-pointer */</span><br><span style="color: hsl(120, 100%, 40%);">+    struct sgs_state *sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* MME name as string representation */</span><br><span style="color: hsl(120, 100%, 40%);">+       char fqdn[GSM23003_MME_DOMAIN_LEN + 1];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* current connection for this MME, if any. Can be NULL if the SCTP</span><br><span style="color: hsl(120, 100%, 40%);">+    * connection to the MME was lost and hasn't been re-established yet */</span><br><span style="color: hsl(120, 100%, 40%);">+   struct sgs_connection *conn;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* FSM for the "VLR reset" procedure" */</span><br><span style="color: hsl(120, 100%, 40%);">+       struct osmo_fsm_inst *fi;</span><br><span style="color: hsl(120, 100%, 40%);">+     unsigned int ns11_remaining;</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%);">+extern struct sgs_state *g_sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_state *sgs_init(void *ctx, struct gsm_network *network);</span><br><span style="color: hsl(120, 100%, 40%);">+int sgs_open(struct sgs_state *sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+int sgs_iface_tx_paging(struct vlr_subscr *vsub, enum sgsap_service_ind serv_ind);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+extern const char *sgs_state_timer_names[_NUM_SGS_STATE_TIMERS];</span><br><span style="color: hsl(120, 100%, 40%);">+extern const char *sgs_state_counter_names[_NUM_SGS_STATE_COUNTERS];</span><br><span>diff --git a/include/osmocom/msc/sgs_vty.h b/include/osmocom/msc/sgs_vty.h</span><br><span>new file mode 100644</span><br><span>index 0000000..75a0f24</span><br><span>--- /dev/null</span><br><span>+++ b/include/osmocom/msc/sgs_vty.h</span><br><span>@@ -0,0 +1,3 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_vty_init(void);</span><br><span>diff --git a/include/osmocom/msc/vlr.h b/include/osmocom/msc/vlr.h</span><br><span>index d52713c..d103be6 100644</span><br><span>--- a/include/osmocom/msc/vlr.h</span><br><span>+++ b/include/osmocom/msc/vlr.h</span><br><span>@@ -102,6 +102,13 @@</span><br><span> </span><br><span> struct sgsn_mm_ctx;</span><br><span> struct vlr_instance;</span><br><span style="color: hsl(120, 100%, 40%);">+struct vlr_subscr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_lu_response {</span><br><span style="color: hsl(120, 100%, 40%);">+      bool accepted;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct vlr_subscr *vsub;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+typedef void (*vlr_sgs_lu_response_cb_t) (struct sgs_lu_response * response);</span><br><span> </span><br><span> /* The VLR subscriber is the part of the GSM subscriber state in VLR (CS) or</span><br><span>  * SGSN (PS), particularly while interacting with the HLR via GSUP */</span><br><span>@@ -151,6 +158,7 @@</span><br><span>       struct osmo_fsm_inst *lu_fsm;</span><br><span>        struct osmo_fsm_inst *auth_fsm;</span><br><span>      struct osmo_fsm_inst *proc_arq_fsm;</span><br><span style="color: hsl(120, 100%, 40%);">+   struct osmo_fsm_inst *sgs_fsm;</span><br><span> </span><br><span>   bool lu_complete;</span><br><span>    time_t expire_lu;</span><br><span>@@ -174,6 +182,13 @@</span><br><span>             uint8_t lac;</span><br><span>                 enum ran_type attached_via_ran;</span><br><span>      } cs;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* SGs (MME) specific parts */</span><br><span style="color: hsl(120, 100%, 40%);">+        struct {</span><br><span style="color: hsl(120, 100%, 40%);">+              /* FIXME: probably use cs.lac for instead of introducing another lai here? */</span><br><span style="color: hsl(120, 100%, 40%);">+         struct osmo_location_area_id lai;</span><br><span style="color: hsl(120, 100%, 40%);">+             vlr_sgs_lu_response_cb_t response_cb;</span><br><span style="color: hsl(120, 100%, 40%);">+         char mme_name[55 + 1];</span><br><span style="color: hsl(120, 100%, 40%);">+        } sgs;</span><br><span> </span><br><span>   struct gsm_classmark classmark;</span><br><span> };</span><br><span>diff --git a/include/osmocom/msc/vlr_sgs.h b/include/osmocom/msc/vlr_sgs.h</span><br><span>new file mode 100644</span><br><span>index 0000000..d177516</span><br><span>--- /dev/null</span><br><span>+++ b/include/osmocom/msc/vlr_sgs.h</span><br><span>@@ -0,0 +1,15 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum sgs_ue_fsm_state {</span><br><span style="color: hsl(120, 100%, 40%);">+  SGS_UE_ST_NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+       SGS_UE_ST_ASSOCIATED,</span><br><span style="color: hsl(120, 100%, 40%);">+ SGS_UE_ST_LA_UPD_PRES,</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%);">+void vlr_sgs_reset(struct vlr_instance *vlr);</span><br><span style="color: hsl(120, 100%, 40%);">+int vlr_sgs_loc_update(struct vlr_instance *vlr,</span><br><span style="color: hsl(120, 100%, 40%);">+                vlr_sgs_lu_response_cb_t response_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+                 char *mme_name, enum vlr_lu_type type, const char *imsi, struct osmo_location_area_id *new_lai);</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_loc_update_acc_sent(struct vlr_subscr *vlr_subscr);</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_loc_update_rej_sent(struct vlr_subscr *vlr_subscr);</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_detach(struct vlr_instance *vlr, const char *imsi, bool eps);</span><br><span>diff --git a/include/osmocom/msc/vty.h b/include/osmocom/msc/vty.h</span><br><span>index 6a55df7..2a3b18b 100644</span><br><span>--- a/include/osmocom/msc/vty.h</span><br><span>+++ b/include/osmocom/msc/vty.h</span><br><span>@@ -23,6 +23,7 @@</span><br><span>         SMPP_NODE,</span><br><span>   SMPP_ESME_NODE,</span><br><span>      HLR_NODE,</span><br><span style="color: hsl(120, 100%, 40%);">+     CFG_SGS_NODE,</span><br><span> };</span><br><span> </span><br><span> int bsc_vty_init_extra(void);</span><br><span>diff --git a/src/libmsc/Makefile.am b/src/libmsc/Makefile.am</span><br><span>index 90bbbf8..2cf34cf 100644</span><br><span>--- a/src/libmsc/Makefile.am</span><br><span>+++ b/src/libmsc/Makefile.am</span><br><span>@@ -51,6 +51,8 @@</span><br><span>    osmo_msc.c \</span><br><span>         ctrl_commands.c \</span><br><span>    subscr_conn.c \</span><br><span style="color: hsl(120, 100%, 40%);">+       sgs_iface.c \</span><br><span style="color: hsl(120, 100%, 40%);">+ sgs_vty.c \</span><br><span>  $(NULL)</span><br><span> if BUILD_IU</span><br><span> libmsc_a_SOURCES += \</span><br><span>diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c</span><br><span>index f9888d7..54320d2 100644</span><br><span>--- a/src/libmsc/gsm_04_08_cc.c</span><br><span>+++ b/src/libmsc/gsm_04_08_cc.c</span><br><span>@@ -1995,7 +1995,8 @@</span><br><span>                                                     vsub,</span><br><span>                                                        setup_trig_pag_evt,</span><br><span>                                                  trans,</span><br><span style="color: hsl(0, 100%, 40%);">-                                                  "MNCC: establish call");</span><br><span style="color: hsl(120, 100%, 40%);">+                                                    "MNCC: establish call",</span><br><span style="color: hsl(120, 100%, 40%);">+                                                     SGSAP_SERV_IND_CS_CALL);</span><br><span>                     if (!trans->paging_request) {</span><br><span>                             LOGP(DCC, LOGL_ERROR, "Failed to allocate paging token.\n");</span><br><span>                               vlr_subscr_put(vsub);</span><br><span>diff --git a/src/libmsc/gsm_04_11.c b/src/libmsc/gsm_04_11.c</span><br><span>index 8d9169b..cb37db6 100644</span><br><span>--- a/src/libmsc/gsm_04_11.c</span><br><span>+++ b/src/libmsc/gsm_04_11.c</span><br><span>@@ -1132,7 +1132,8 @@</span><br><span>   /* if not, we have to start paging */</span><br><span>        LOGP(DLSMS, LOGL_DEBUG, "Sending SMS: no connection open, start paging %s\n",</span><br><span>           vlr_subscr_name(vsub));</span><br><span style="color: hsl(0, 100%, 40%);">-    res = subscr_request_conn(vsub, paging_cb_send_sms, sms, "send SMS");</span><br><span style="color: hsl(120, 100%, 40%);">+       res = subscr_request_conn(vsub, paging_cb_send_sms, sms, "send SMS",</span><br><span style="color: hsl(120, 100%, 40%);">+                                  SGSAP_SERV_IND_SMS);</span><br><span>       if (!res) {</span><br><span>          send_signal(S_SMS_UNKNOWN_ERROR, NULL, sms, GSM_PAGING_BUSY);</span><br><span>                sms_free(sms);</span><br><span>diff --git a/src/libmsc/gsm_09_11.c b/src/libmsc/gsm_09_11.c</span><br><span>index b863ce8..9adf5b7 100644</span><br><span>--- a/src/libmsc/gsm_09_11.c</span><br><span>+++ b/src/libmsc/gsm_09_11.c</span><br><span>@@ -347,7 +347,10 @@</span><br><span> </span><br><span>       /* Trigger Paging Request */</span><br><span>         trans->paging_request = subscr_request_conn(vsub,</span><br><span style="color: hsl(0, 100%, 40%);">-            &handle_paging_event, trans, "GSM 09.11 SS/USSD");</span><br><span style="color: hsl(120, 100%, 40%);">+                                                  &handle_paging_event,</span><br><span style="color: hsl(120, 100%, 40%);">+                                             trans,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                "GSM 09.11 SS/USSD",</span><br><span style="color: hsl(120, 100%, 40%);">+                                                SGSAP_SERV_IND_SMS);</span><br><span>     if (!trans->paging_request) {</span><br><span>             LOGP(DMM, LOGL_ERROR, "Failed to allocate paging token\n");</span><br><span>                trans_free(trans);</span><br><span>diff --git a/src/libmsc/gsm_subscriber.c b/src/libmsc/gsm_subscriber.c</span><br><span>index fb61209..0645fa9 100644</span><br><span>--- a/src/libmsc/gsm_subscriber.c</span><br><span>+++ b/src/libmsc/gsm_subscriber.c</span><br><span>@@ -49,6 +49,7 @@</span><br><span> #include <osmocom/msc/osmo_msc.h></span><br><span> #include <osmocom/msc/msc_ifaces.h></span><br><span> #include <osmocom/msc/a_iface.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/sgs_iface.h></span><br><span> </span><br><span> void subscr_paging_cancel(struct vlr_subscr *vsub, enum gsm_paging_event event)</span><br><span> {</span><br><span>@@ -110,7 +111,7 @@</span><br><span>        return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-int msc_paging_request(struct vlr_subscr *vsub)</span><br><span style="color: hsl(120, 100%, 40%);">+static int msc_paging_request(struct vlr_subscr *vsub, enum sgsap_service_ind serv_ind)</span><br><span> {</span><br><span>      /* The subscriber was last seen in subscr->lac. Find out which</span><br><span>     * BSCs/RNCs are responsible and send them a paging request via open</span><br><span>@@ -123,6 +124,8 @@</span><br><span>                                   vsub->tmsi == GSM_RESERVED_TMSI?</span><br><span>                                  NULL : &vsub->tmsi,</span><br><span>                                   vsub->lac);</span><br><span style="color: hsl(120, 100%, 40%);">+        case RAN_UTRAN_SGS:</span><br><span style="color: hsl(120, 100%, 40%);">+           return sgs_iface_tx_paging(vsub, serv_ind);</span><br><span>  default:</span><br><span>             break;</span><br><span>       }</span><br><span>@@ -143,10 +146,13 @@</span><br><span>  * \param cbfn  function to call when the conn is established.</span><br><span>  * \param param  caller defined param to pass to cbfn().</span><br><span>  * \param label  human readable label of the request kind used for logging.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param label  human readable label of the request kind used for logging.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param serv_ind  sgsap service indicator (in case SGs interface is used to page)</span><br><span>  */</span><br><span> struct subscr_request *subscr_request_conn(struct vlr_subscr *vsub,</span><br><span>                                          gsm_cbfn *cbfn, void *param,</span><br><span style="color: hsl(0, 100%, 40%);">-                                    const char *label)</span><br><span style="color: hsl(120, 100%, 40%);">+                                    const char *label,</span><br><span style="color: hsl(120, 100%, 40%);">+                                    enum sgsap_service_ind serv_ind)</span><br><span> {</span><br><span>     int rc;</span><br><span>      struct subscr_request *request;</span><br><span>@@ -156,7 +162,7 @@</span><br><span>        if (!vsub->cs.is_paging) {</span><br><span>                LOGP(DMM, LOGL_DEBUG, "Subscriber %s not paged yet, start paging.\n",</span><br><span>                   vlr_subscr_name(vsub));</span><br><span style="color: hsl(0, 100%, 40%);">-            rc = msc_paging_request(vsub);</span><br><span style="color: hsl(120, 100%, 40%);">+                rc = msc_paging_request(vsub, serv_ind);</span><br><span>             if (rc <= 0) {</span><br><span>                    LOGP(DMM, LOGL_ERROR, "Subscriber %s paging failed: %d\n",</span><br><span>                              vlr_subscr_name(vsub), rc);</span><br><span>diff --git a/src/libmsc/msc_vty.c b/src/libmsc/msc_vty.c</span><br><span>index a16cec8..4683695 100644</span><br><span>--- a/src/libmsc/msc_vty.c</span><br><span>+++ b/src/libmsc/msc_vty.c</span><br><span>@@ -54,6 +54,7 @@</span><br><span> #include <osmocom/msc/signal.h></span><br><span> #include <osmocom/msc/mncc_int.h></span><br><span> #include <osmocom/msc/rrlp.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr_sgs.h></span><br><span> </span><br><span> static struct gsm_network *gsmnet = NULL;</span><br><span> </span><br><span>@@ -608,6 +609,17 @@</span><br><span>             reqs += 1;</span><br><span>   vty_out(vty, "    Paging: %s paging for %d requests%s",</span><br><span>            vsub->cs.is_paging ? "is" : "not", reqs, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* SGs related */</span><br><span style="color: hsl(120, 100%, 40%);">+     vty_out(vty, "    SGs-state: %s%s",</span><br><span style="color: hsl(120, 100%, 40%);">+         osmo_fsm_state_name(vsub->sgs_fsm->fsm, vsub->sgs_fsm->state),</span><br><span style="color: hsl(120, 100%, 40%);">+            VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (vsub->sgs.mme_name && strlen(vsub->sgs.mme_name))</span><br><span style="color: hsl(120, 100%, 40%);">+           vty_out(vty, "    SGs-MME: %s%s", vsub->sgs.mme_name,</span><br><span style="color: hsl(120, 100%, 40%);">+                    VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ else</span><br><span style="color: hsl(120, 100%, 40%);">+          vty_out(vty, "    SGs-MME: (none)%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      vty_out(vty, "    Use count: %u%s", vsub->use_count, VTY_NEWLINE);</span><br><span> </span><br><span>  /* Connection */</span><br><span>@@ -1035,7 +1047,7 @@</span><br><span>             return CMD_WARNING;</span><br><span>  }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   req = subscr_request_conn(vsub, NULL, NULL, "manual Paging from VTY");</span><br><span style="color: hsl(120, 100%, 40%);">+      req = subscr_request_conn(vsub, NULL, NULL, "manual Paging from VTY", SGSAP_SERV_IND_CS_CALL);</span><br><span>     if (req)</span><br><span>             vty_out(vty, "%% paging subscriber%s", VTY_NEWLINE);</span><br><span>       else</span><br><span>@@ -1401,6 +1413,8 @@</span><br><span>         return CMD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+extern void sgs_vty_init(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void msc_vty_init(struct gsm_network *msc_network)</span><br><span> {</span><br><span>   OSMO_ASSERT(gsmnet == NULL);</span><br><span>@@ -1440,6 +1454,7 @@</span><br><span> #ifdef BUILD_IU</span><br><span>      ranap_iu_vty_init(MSC_NODE, &msc_network->iu.rab_assign_addr_enc);</span><br><span> #endif</span><br><span style="color: hsl(120, 100%, 40%);">+   sgs_vty_init();</span><br><span>      osmo_fsm_vty_add_cmds();</span><br><span> </span><br><span>         osmo_signal_register_handler(SS_SCALL, scall_cbfn, NULL);</span><br><span>diff --git a/src/libmsc/sgs_iface.c b/src/libmsc/sgs_iface.c</span><br><span>new file mode 100644</span><br><span>index 0000000..69597be</span><br><span>--- /dev/null</span><br><span>+++ b/src/libmsc/sgs_iface.c</span><br><span>@@ -0,0 +1,976 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* SGs Interface according to 3GPP TS 23.272 + TS 29.118 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C 2018 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU Affero General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/msgb.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/socket.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/select.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/gsm48.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/gsm23003.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/netif/stream.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr_sgs.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/debug.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/sgs_iface.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define S(x) (1 << (x))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_fsm sgs_vlr_reset_fsm;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* See also comment in a_iface.c */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct gsm_network *gsm_network = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_state *g_sgs;</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%);">+ * SGs state per MME connection</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%);">+struct sgs_state;</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_connection;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+const char *sgs_state_timer_names[_NUM_SGS_STATE_TIMERS] = {</span><br><span style="color: hsl(120, 100%, 40%);">+   [SGS_STATE_TS5] = "Ts5",</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_STATE_TS6_2] = "Ts6-2",</span><br><span style="color: hsl(120, 100%, 40%);">+        [SGS_STATE_TS7] = "Ts7",</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_STATE_TS11] = "Ts11",</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_STATE_TS14] = "Ts14",</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_STATE_TS15] = "Ts15",</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%);">+const char *sgs_state_counter_names[_NUM_SGS_STATE_COUNTERS] = {</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_STATE_NS7] = "Ns7",</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_STATE_NS11] = "Ns11",</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%);">+#define LOGSGC(sgc, lvl, fmt, args...) \</span><br><span style="color: hsl(120, 100%, 40%);">+  LOGP(DSGS, lvl, "%s: " fmt, (sgc)->sockname, ## args)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define LOGMME(mme, lvl, fmt, args...) \</span><br><span style="color: hsl(120, 100%, 40%);">+        LOGP(DSGS, lvl, "%s: " fmt, (mme)->fqdn ? (mme)->fqdn : (mme)->conn->sockname, ## args)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum sgs_vlr_reset_fsm_state {</span><br><span style="color: hsl(120, 100%, 40%);">+       SGS_VLRR_ST_NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+     SGS_VLRR_ST_WAIT_ACK,</span><br><span style="color: hsl(120, 100%, 40%);">+ SGS_VLRR_ST_COMPLETE,</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%);">+enum sgs_vlr_reset_fsm_event {</span><br><span style="color: hsl(120, 100%, 40%);">+   SGS_VLRR_E_START_RESET,</span><br><span style="color: hsl(120, 100%, 40%);">+       SGS_VLRR_E_RX_RESET_ACK,</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%);">+/***********************************************************************</span><br><span style="color: hsl(120, 100%, 40%);">+ * SGsAP transmit functions</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%);">+#include <osmocom/gsm/apn.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct msgb *sgs_msgb_alloc(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* by far sufficient for the maximum size message of 298 bytes</span><br><span style="color: hsl(120, 100%, 40%);">+         * (9+7+5+3+10+253+10+1) SGsAP-UP-UD */</span><br><span style="color: hsl(120, 100%, 40%);">+       return msgb_alloc_headroom(1024, 128, "SGsAP");</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%);">+/*! Encode VLR/MME name from string and append to SGsAP msg */</span><br><span style="color: hsl(120, 100%, 40%);">+static void msgb_sgsap_name_put(struct msgb *msg, enum sgsap_iei iei, const char *name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t buf[APN_MAXLEN];</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t len;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* encoding is like DNS names, which is like APN fields */</span><br><span style="color: hsl(120, 100%, 40%);">+    memset(buf, 0, sizeof(buf));</span><br><span style="color: hsl(120, 100%, 40%);">+  len = osmo_apn_from_str(buf, sizeof(buf), name);</span><br><span style="color: hsl(120, 100%, 40%);">+      if (iei == SGSAP_IE_MME_NAME)</span><br><span style="color: hsl(120, 100%, 40%);">+         len = 55;</span><br><span style="color: hsl(120, 100%, 40%);">+     msgb_tlv_put(msg, iei, len, buf);</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%);">+/*! Encode IMSI from string representation and append to SGSaAP msg */</span><br><span style="color: hsl(120, 100%, 40%);">+static void msgb_sgsap_imsi_put(struct msgb *msg, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        uint8_t buf[16];</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t len;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* encoding is just like TS 04.08 */</span><br><span style="color: hsl(120, 100%, 40%);">+  len = gsm48_generate_mid_from_imsi(buf, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+        /* skip first two bytes (tag+length) so we can use msgb_tlv_put */</span><br><span style="color: hsl(120, 100%, 40%);">+    msgb_tlv_put(msg, SGSAP_IE_IMSI, len - 2, buf + 2);</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%);">+/*! Encode IMSI from string representation and append to SGSaAP msg */</span><br><span style="color: hsl(120, 100%, 40%);">+static void msgb_sgsap_imsi_push(struct msgb *msg, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     uint8_t buf[16];</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t len;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* encoding is just like TS 04.08 */</span><br><span style="color: hsl(120, 100%, 40%);">+  len = gsm48_generate_mid_from_imsi(buf, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+        /* skip first two bytes (tag+length) so we can use msgb_tlv_put */</span><br><span style="color: hsl(120, 100%, 40%);">+    msgb_tlv_push(msg, SGSAP_IE_IMSI, len - 2, buf + 2);</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%);">+static void sgs_tx(struct sgs_connection *sgc, enum sgsap_msg_type msg_type, struct msgb *msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t *cur = msgb_push(msg, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+     *cur = msg_type;</span><br><span style="color: hsl(120, 100%, 40%);">+      msgb_sctp_ppid(msg) = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+      if (!sgc) {</span><br><span style="color: hsl(120, 100%, 40%);">+           LOGSGC(sgc, LOGL_NOTICE, "Cannot transmit %s: connection dead. Discarding\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                      sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+                msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_stream_srv_send(sgc->srv, msg);</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 simple SGsAP message (only IE: IMSI) */</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_tx_simple(struct sgs_connection *sgc, enum sgsap_msg_type msgt, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       sgs_tx(sgc, msgt, msg);</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%);">+/* 8.3 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_alert_req(struct sgs_connection *sgc, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       sgs_tx_simple(sgc, SGSAP_MSGT_ALERT_REQ, imsi);</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%);">+/* 8.4 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_dl_ud(struct sgs_connection *sgc, const char *imsi, struct msgb *msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ msgb_sgsap_imsi_push(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+      sgs_tx(sgc, SGSAP_MSGT_DL_UD, msg);</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%);">+/* 8.5 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_eps_det_ack(struct sgs_connection *sgc, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ sgs_tx_simple(sgc, SGSAP_MSGT_EPS_DET_ACK, imsi);</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%);">+/* 8.7 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_imsi_det_ack(struct sgs_connection *sgc, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  sgs_tx_simple(sgc, SGSAP_MSGT_IMSI_DET_ACK, imsi);</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%);">+/*! 8.9 SGsAP-LOCATION-UPDATE-ACCEPT.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] sgc SGs Connection.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] imsi IMSI of the subscriber.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] lai Location Area Identity (optional, may be NULL).</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] new_id value part of new Mobile Identity (optional, may be NULL).</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] new_id_len length of \a new_id in octets. */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_lu_ack(struct sgs_connection *sgc, const char *imsi,</span><br><span style="color: hsl(120, 100%, 40%);">+             const struct osmo_location_area_id *lai, const uint8_t *new_id, unsigned int new_id_len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (lai) {</span><br><span style="color: hsl(120, 100%, 40%);">+            struct gsm48_loc_area_id lai_enc;</span><br><span style="color: hsl(120, 100%, 40%);">+             gsm48_generate_lai2(&lai_enc, lai);</span><br><span style="color: hsl(120, 100%, 40%);">+               msgb_tlv_put(msg, SGSAP_IE_LAI, 5, (uint8_t *) & lai_enc);</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (new_id && new_id_len)</span><br><span style="color: hsl(120, 100%, 40%);">+             msgb_tlv_put(msg, SGSAP_IE_MOBILE_ID, new_id_len, new_id);</span><br><span style="color: hsl(120, 100%, 40%);">+    sgs_tx(sgc, SGSAP_MSGT_LOC_UPD_ACK, msg);</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%);">+/* 8.10 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_lu_rej(struct sgs_connection *sgc, const char *imsi, uint8_t rej_cause,</span><br><span style="color: hsl(120, 100%, 40%);">+                  const struct osmo_location_area_id *lai)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       msgb_tlv_put(msg, SGSAP_IE_REJECT_CAUSE, 1, &rej_cause);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (lai) {</span><br><span style="color: hsl(120, 100%, 40%);">+            struct gsm48_loc_area_id lai_enc;</span><br><span style="color: hsl(120, 100%, 40%);">+             gsm48_generate_lai2(&lai_enc, lai);</span><br><span style="color: hsl(120, 100%, 40%);">+               msgb_tlv_put(msg, SGSAP_IE_LAI, 5, (uint8_t *) & lai_enc);</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     sgs_tx(sgc, SGSAP_MSGT_LOC_UPD_REJ, msg);</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%);">+/* 8.12 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_mm_info_req(struct sgs_connection *sgc, const char *imsi, const uint8_t *mm_info, uint8_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       msgb_tlv_put(msg, SGSAP_IE_MM_INFO, len, mm_info);</span><br><span style="color: hsl(120, 100%, 40%);">+    sgs_tx(sgc, SGSAP_MSGT_MM_INFO_REQ, msg);</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%);">+/* 8.14 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_paging_req(struct sgs_connection *sgc, const char *imsi, const char *vlr_name, uint8_t serv_ind)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       msgb_sgsap_name_put(msg, SGSAP_IE_VLR_NAME, vlr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+        msgb_tlv_put(msg, SGSAP_IE_SERVICE_INDICATOR, 1, &serv_ind);</span><br><span style="color: hsl(120, 100%, 40%);">+      sgs_tx(sgc, SGSAP_MSGT_PAGING_REQ, msg);</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%);">+/* 8.15 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_reset_ack_vlr(struct sgs_connection *sgc, const char *vlr_name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_name_put(msg, SGSAP_IE_VLR_NAME, vlr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+        sgs_tx(sgc, SGSAP_MSGT_RESET_ACK, msg);</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%);">+/* 8.16 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_reset_ind_vlr(struct sgs_connection *sgc, const char *vlr_name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_name_put(msg, SGSAP_IE_VLR_NAME, vlr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+        sgs_tx(sgc, SGSAP_MSGT_RESET_IND, msg);</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%);">+/* 8.18 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_status(struct sgs_connection *sgc, enum sgsap_sgs_cause cause, const char *imsi, const struct msgb *err_msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t c8 = cause;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ msgb_tlv_put(msg, SGSAP_IE_SGS_CAUSE, 1, &c8);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+             msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (err_msg)</span><br><span style="color: hsl(120, 100%, 40%);">+          msgb_tlv_put(msg, SGSAP_IE_ERR_MSG, msgb_l2len(msg), msgb_l2(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+   sgs_tx(sgc, SGSAP_MSGT_STATUS, msg);</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%);">+/* same as above, but get IMSI from tlv_parsed */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_status_tp(struct sgs_connection *sgc, enum sgsap_sgs_cause cause,</span><br><span style="color: hsl(120, 100%, 40%);">+                 const struct tlv_parsed *tp, const struct msgb *err_msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t c8 = cause;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ msgb_tlv_put(msg, SGSAP_IE_SGS_CAUSE, 1, &c8);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (tp && TLVP_PRESENT(tp, SGSAP_IE_IMSI)) {</span><br><span style="color: hsl(120, 100%, 40%);">+          msgb_tlv_put(msg, SGSAP_IE_IMSI, TLVP_LEN(tp, SGSAP_IE_IMSI), TLVP_VAL(tp, SGSAP_IE_IMSI));</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (err_msg)</span><br><span style="color: hsl(120, 100%, 40%);">+          msgb_tlv_put(msg, SGSAP_IE_ERR_MSG, msgb_l2len(msg), msgb_l2(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+   sgs_tx(sgc, SGSAP_MSGT_STATUS, msg);</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%);">+/* 8.23 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_release_req(struct sgs_connection *sgc, const char *imsi, const uint8_t *sgs_cause)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_sgsap_imsi_put(msg, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (sgs_cause)</span><br><span style="color: hsl(120, 100%, 40%);">+                msgb_tlv_put(msg, SGSAP_IE_SGS_CAUSE, 1, sgs_cause);</span><br><span style="color: hsl(120, 100%, 40%);">+  sgs_tx(sgc, SGSAP_MSGT_RELEASE_REQ, msg);</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%);">+/* 8.24 */</span><br><span style="color: hsl(120, 100%, 40%);">+void sgs_tx_service_abort_req(struct sgs_connection *sgc, const char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    sgs_tx_simple(sgc, SGSAP_MSGT_SERVICE_ABORT_REQ, imsi);</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%);">+/***********************************************************************</span><br><span style="color: hsl(120, 100%, 40%);">+ * SGs utility functions</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%);">+struct sgs_state *sgs_state_alloc(void *ctx)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct sgs_state *sgs = talloc_zero(ctx, struct sgs_state);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ INIT_LLIST_HEAD(&sgs->mme_list);</span><br><span style="color: hsl(120, 100%, 40%);">+       INIT_LLIST_HEAD(&sgs->conn_list);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    memcpy(sgs->cfg.timer, sgs_state_timer_defaults, sizeof(sgs->cfg.timer));</span><br><span style="color: hsl(120, 100%, 40%);">+       memcpy(sgs->cfg.counter, sgs_state_counter_defaults, sizeof(sgs->cfg.counter));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       sgs->cfg.vlr_name = talloc_strdup(sgs, "mmec02.mmegi0002.mme.epc.mnc070.mcc901.3gppnetwork.org");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      return sgs;</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%);">+struct sgs_mme_ctx *sgs_mme_by_fqdn(struct sgs_state *sgs, const char *mme_fqdn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    llist_for_each_entry(mme, &sgs->mme_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+              if (!strcasecmp(mme_fqdn, mme->fqdn))</span><br><span style="color: hsl(120, 100%, 40%);">+                      return mme;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+     return NULL;</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%);">+static struct sgs_mme_ctx *sgs_mme_alloc(struct sgs_state *sgs, const char *mme_fqdn, const struct osmo_gummei *gummei)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_ASSERT(sgs_mme_by_fqdn(sgs, mme_fqdn) == NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        mme = talloc_zero(sgs, struct sgs_mme_ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!mme)</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  mme->sgs = sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_STRLCPY_ARRAY(mme->fqdn, mme_fqdn);</span><br><span style="color: hsl(120, 100%, 40%);">+   mme->fi = osmo_fsm_inst_alloc(&sgs_vlr_reset_fsm, mme, mme, LOGL_INFO, osmo_gummei_name(gummei));</span><br><span style="color: hsl(120, 100%, 40%);">+      if (!mme->fi) {</span><br><span style="color: hsl(120, 100%, 40%);">+            talloc_free(mme);</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     llist_add_tail(&mme->list, &sgs->mme_list);</span><br><span style="color: hsl(120, 100%, 40%);">+     return mme;</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%);">+/* Decode and verify MME name */</span><br><span style="color: hsl(120, 100%, 40%);">+static int decode_mme_name(char *mme_name, const struct tlv_parsed *tp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        const uint8_t *mme_name_enc = TLVP_VAL_MINLEN(tp, SGSAP_IE_MME_NAME, 55);</span><br><span style="color: hsl(120, 100%, 40%);">+     struct osmo_gummei gummei;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!mme_name_enc)</span><br><span style="color: hsl(120, 100%, 40%);">+            return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* decode the MME name from DNS labels to string */</span><br><span style="color: hsl(120, 100%, 40%);">+   osmo_apn_to_str(mme_name, TLVP_VAL(tp, SGSAP_IE_MME_NAME), TLVP_LEN(tp, SGSAP_IE_MME_NAME));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* try to parse the MME name into a GUMMEI as a test for the format */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (osmo_parse_mme_domain(&gummei, mme_name) < 0)</span><br><span style="color: hsl(120, 100%, 40%);">+              return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</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%);">+/* A MME FQDN was received (e.g. RESET-IND/RESET-ACK/LU-REQ) */</span><br><span style="color: hsl(120, 100%, 40%);">+static int sgs_mme_fqdn_received(struct sgs_connection *sgc, const char *mme_fqdn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct osmo_gummei gummei;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* caller must pass in a valid FQDN string syntax */</span><br><span style="color: hsl(120, 100%, 40%);">+  OSMO_ASSERT(osmo_parse_mme_domain(&gummei, mme_fqdn) == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!sgc->mme) {</span><br><span style="color: hsl(120, 100%, 40%);">+           /* attempt to find MME with given name */</span><br><span style="color: hsl(120, 100%, 40%);">+             mme = sgs_mme_by_fqdn(sgc->sgs, mme_fqdn);</span><br><span style="color: hsl(120, 100%, 40%);">+         if (!mme)</span><br><span style="color: hsl(120, 100%, 40%);">+                     mme = sgs_mme_alloc(sgc->sgs, mme_fqdn, &gummei);</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(mme);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           if (mme->conn) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   /* The MME context has another connection !?! */</span><br><span style="color: hsl(120, 100%, 40%);">+                      LOGSGC(sgc, LOGL_ERROR, "Rx MME name %s, but that MME already has other "</span><br><span style="color: hsl(120, 100%, 40%);">+                          "SCTP connection?!?\n", mme_fqdn);</span><br><span style="color: hsl(120, 100%, 40%);">+                   return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+            } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                      /* associate the two */</span><br><span style="color: hsl(120, 100%, 40%);">+                       mme->conn = sgc;</span><br><span style="color: hsl(120, 100%, 40%);">+                   sgc->mme = mme;</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span style="color: hsl(120, 100%, 40%);">+     } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              mme = sgc->mme;</span><br><span style="color: hsl(120, 100%, 40%);">+            if (strcasecmp(mme->fqdn, mme_fqdn) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        LOGMME(mme, LOGL_ERROR, "Rx MME name \"%s\" in packet from MME \"%s\" ?!?\n", mme_fqdn,</span><br><span style="color: hsl(120, 100%, 40%);">+                        mme->fqdn);</span><br><span style="color: hsl(120, 100%, 40%);">+                 return -2;</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%);">+     return 0;</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%);">+/* Safely get the mme-name for an sgs-connection */</span><br><span style="color: hsl(120, 100%, 40%);">+static char *sgs_mme_fqdn_get(struct sgs_connection *sgc)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!sgc)</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!sgc->mme)</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  if (strlen(sgc->mme->fqdn) <= 0)</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  return sgc->mme->fqdn;</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%);">+/* Find an sgs_mme_ctx for a given vlr subscriber, also check result */</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_mme_ctx *sgs_mme_ctx_by_vsub(struct vlr_subscr *vsub, uint8_t msg_type)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Find SGS connection by MME name */</span><br><span style="color: hsl(120, 100%, 40%);">+ mme = sgs_mme_by_fqdn(g_sgs, vsub->sgs.mme_name);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!mme) {</span><br><span style="color: hsl(120, 100%, 40%);">+           LOGP(DSGS, LOGL_ERROR, "(sub %s) Tx %s can not find suitable MME!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                    vlr_subscr_msisdn_or_name(vsub), sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+         return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!mme->conn) {</span><br><span style="color: hsl(120, 100%, 40%);">+          LOGP(DSGS, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                     "(sub %s) Tx %s suitable MME found, but no SGS connection present!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+              vlr_subscr_msisdn_or_name(vsub), sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+         return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!mme->sgs) {</span><br><span style="color: hsl(120, 100%, 40%);">+           LOGP(DSGS, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                     "(sub %s) Tx %s suitable MME found, but no SGS state present!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                   vlr_subscr_msisdn_or_name(vsub), sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+         return NULL;</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%);">+   return mme;</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%);">+/***********************************************************************</span><br><span style="color: hsl(120, 100%, 40%);">+ * SGs incoming messages from the MME</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%);">+static void sgs_rx_status(struct sgs_connection *sgc, struct msgb *msg, struct tlv_parsed *tp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     uint8_t cause;</span><br><span style="color: hsl(120, 100%, 40%);">+        const uint8_t *cause_ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+     const uint8_t *err_msg;</span><br><span style="color: hsl(120, 100%, 40%);">+       char imsi[32];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      cause_ptr = TLVP_VAL_MINLEN(tp, SGSAP_IE_SGS_CAUSE, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (cause_ptr)</span><br><span style="color: hsl(120, 100%, 40%);">+                cause = *cause_ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (TLVP_PRESENT(tp, SGSAP_IE_IMSI)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                gsm48_mi_to_string(imsi, sizeof(imsi), TLVP_VAL(tp, SGSAP_IE_IMSI), TLVP_LEN(tp, SGSAP_IE_IMSI));</span><br><span style="color: hsl(120, 100%, 40%);">+     } else</span><br><span style="color: hsl(120, 100%, 40%);">+                OSMO_STRLCPY_ARRAY(imsi, "<none>");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (TLVP_PRESENT(tp, SGSAP_IE_ERR_MSG))</span><br><span style="color: hsl(120, 100%, 40%);">+               err_msg = TLVP_VAL(tp, SGSAP_IE_ERR_MSG);</span><br><span style="color: hsl(120, 100%, 40%);">+     else</span><br><span style="color: hsl(120, 100%, 40%);">+          err_msg = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     LOGSGC(sgc, LOGL_NOTICE, "Rx STATUS cause=%s, IMSI=%s, orig_msg=%s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+             sgsap_sgs_cause_name(cause), imsi, err_msg ? osmo_hexdump(err_msg, TLVP_LEN(tp, SGSAP_IE_ERR_MSG)) : "");</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%);">+static void sgs_rx_reset_ind(struct sgs_connection *sgc, struct msgb *msg, const struct tlv_parsed *tp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+/* Perform a reset of the SGS FSM of all subscribers that are present in the VLR */</span><br><span style="color: hsl(120, 100%, 40%);">+      vlr_sgs_reset(gsm_network->vlr);</span><br><span style="color: hsl(120, 100%, 40%);">+   sgs_tx_reset_ack_vlr(sgc, sgc->sgs->cfg.vlr_name);</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%);">+static void sgs_rx_reset_ack(struct sgs_connection *sgc, struct msgb *msg, const struct tlv_parsed *tp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     /* dispatch event to VLR reset FSM for this MME */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (sgc->mme && sgc->mme->fi)</span><br><span style="color: hsl(120, 100%, 40%);">+                osmo_fsm_inst_dispatch(sgc->mme->fi, SGS_VLRR_E_RX_RESET_ACK, msg);</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%);">+static void sgs_rx_log_upd_resp_cb(struct sgs_lu_response *response)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct vlr_subscr *vsub = response->vsub;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t new_id[2 + GSM48_TMSI_LEN];</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t *new_id_ptr = new_id;</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int new_id_len = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t resp_msg_type;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      if (response->accepted)</span><br><span style="color: hsl(120, 100%, 40%);">+            resp_msg_type = SGSAP_MSGT_LOC_UPD_ACK;</span><br><span style="color: hsl(120, 100%, 40%);">+       else</span><br><span style="color: hsl(120, 100%, 40%);">+          resp_msg_type = SGSAP_MSGT_LOC_UPD_REJ;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     mme = sgs_mme_ctx_by_vsub(vsub, resp_msg_type);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!mme)</span><br><span style="color: hsl(120, 100%, 40%);">+             return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (response->accepted) {</span><br><span style="color: hsl(120, 100%, 40%);">+          if (vsub->tmsi != GSM_RESERVED_TMSI) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     new_id_len = gsm48_generate_mid_from_tmsi(new_id, vsub->tmsi);</span><br><span style="color: hsl(120, 100%, 40%);">+                     new_id_ptr = new_id + 2;</span><br><span style="color: hsl(120, 100%, 40%);">+                      new_id_len -= 2;</span><br><span style="color: hsl(120, 100%, 40%);">+              }</span><br><span style="color: hsl(120, 100%, 40%);">+             sgs_tx_lu_ack(mme->conn, vsub->imsi, &vsub->sgs.lai, new_id_ptr, new_id_len);</span><br><span style="color: hsl(120, 100%, 40%);">+            vlr_sgs_loc_update_acc_sent(vsub);</span><br><span style="color: hsl(120, 100%, 40%);">+    } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              sgs_tx_lu_rej(mme->conn, vsub->imsi, SGSAP_SGS_CAUSE_IMSI_UNKNOWN, &vsub->sgs.lai);</span><br><span style="color: hsl(120, 100%, 40%);">+              vlr_sgs_loc_update_rej_sent(vsub);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_rx_loc_upd_req(struct sgs_connection *sgc, struct msgb *msg, const struct tlv_parsed *tp, char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      const uint8_t *lu_type_ie;</span><br><span style="color: hsl(120, 100%, 40%);">+    enum vlr_lu_type type;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct osmo_location_area_id new_lai;</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct gsm48_loc_area_id *gsm48_lai;</span><br><span style="color: hsl(120, 100%, 40%);">+    int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+       char *mme_name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Determine MME-Name */</span><br><span style="color: hsl(120, 100%, 40%);">+      mme_name = sgs_mme_fqdn_get(sgc);</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!mme_name) {</span><br><span style="color: hsl(120, 100%, 40%);">+              sgs_tx_lu_rej(sgc, imsi, SGSAP_SGS_CAUSE_IMSI_UNKNOWN, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+         return;</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%);">+   /* Parse LU-Type */</span><br><span style="color: hsl(120, 100%, 40%);">+   lu_type_ie = TLVP_VAL_MINLEN(tp, SGSAP_IE_EPS_LU_TYPE, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!lu_type_ie) {</span><br><span style="color: hsl(120, 100%, 40%);">+            LOGSGC(sgc, LOGL_ERROR, "Rx SGsAP-LOCATION-UPDATE-REQ with no/invalid LU type!\n");</span><br><span style="color: hsl(120, 100%, 40%);">+         sgs_tx_status_tp(sgc, SGSAP_SGS_CAUSE_MISSING_MAND_IE, tp, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (lu_type_ie[0] == 0x01)</span><br><span style="color: hsl(120, 100%, 40%);">+            type = VLR_LU_TYPE_IMSI_ATTACH;</span><br><span style="color: hsl(120, 100%, 40%);">+       else</span><br><span style="color: hsl(120, 100%, 40%);">+          type = VLR_LU_TYPE_REGULAR;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Parse LAI of the new location */</span><br><span style="color: hsl(120, 100%, 40%);">+   gsm48_lai = (struct gsm48_loc_area_id *)TLVP_VAL_MINLEN(tp, SGSAP_IE_LAI, 5);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!gsm48_lai) {</span><br><span style="color: hsl(120, 100%, 40%);">+             LOGSGC(sgc, LOGL_ERROR, "Rx SGsAP-LOCATION-UPDATE-REQ with no/invalid NEW LAI type!\n");</span><br><span style="color: hsl(120, 100%, 40%);">+            sgs_tx_status_tp(sgc, SGSAP_SGS_CAUSE_MISSING_MAND_IE, tp, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+     gsm48_decode_lai2(gsm48_lai, &new_lai);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Perform actual location update */</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = vlr_sgs_loc_update(gsm_network->vlr, sgs_rx_log_upd_resp_cb, mme_name, type, imsi, &new_lai);</span><br><span style="color: hsl(120, 100%, 40%);">+     if (rc != 0)</span><br><span style="color: hsl(120, 100%, 40%);">+          sgs_tx_lu_rej(sgc, imsi, SGSAP_SGS_CAUSE_IMSI_UNKNOWN, NULL);</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%);">+static void sgs_rx_imsi_det_ind(struct sgs_connection *sgc, struct msgb *msg, const struct tlv_parsed *tp, char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ vlr_sgs_detach(gsm_network->vlr, imsi, false);</span><br><span style="color: hsl(120, 100%, 40%);">+     sgs_tx_imsi_det_ack(sgc, imsi);</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%);">+static void sgs_rx_eps_det_ind(struct sgs_connection *sgc, struct msgb *msg, const struct tlv_parsed *tp, char *imsi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        vlr_sgs_detach(gsm_network->vlr, imsi, true);</span><br><span style="color: hsl(120, 100%, 40%);">+      sgs_tx_eps_det_ack(sgc, imsi);</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%);">+/* Page a subscriber via SGs-interface */</span><br><span style="color: hsl(120, 100%, 40%);">+int sgs_iface_tx_paging(struct vlr_subscr *vsub, enum sgsap_service_ind serv_ind)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_mme_ctx *mme;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    mme = sgs_mme_ctx_by_vsub(vsub, SGSAP_MSGT_PAGING_REQ);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!mme)</span><br><span style="color: hsl(120, 100%, 40%);">+             return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     sgs_tx_paging_req(mme->conn, vsub->imsi, mme->sgs->cfg.vlr_name, serv_ind);</span><br><span style="color: hsl(120, 100%, 40%);">+       return 0;</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%);">+int sgs_rx(struct sgs_connection *sgc, struct msgb *msg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t msg_type = msg->l2h[0];</span><br><span style="color: hsl(120, 100%, 40%);">+    struct tlv_parsed tp;</span><br><span style="color: hsl(120, 100%, 40%);">+ int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+       char imsi[GSM48_MI_SIZE];</span><br><span style="color: hsl(120, 100%, 40%);">+     char mme_name[55 + 1];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* When the receiving entity receives a message that is too short to contain a complete</span><br><span style="color: hsl(120, 100%, 40%);">+        * message type information element, the receiving entity shall ignore that message. */</span><br><span style="color: hsl(120, 100%, 40%);">+       if (msgb_l2len(msg) < 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+         sgs_tx_status(sgc, SGSAP_SGS_CAUSE_MISSING_MAND_IE, NULL, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return 0;</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%);">+   /* Parse TLV elements */</span><br><span style="color: hsl(120, 100%, 40%);">+      rc = tlv_parse(&tp, &sgsap_ie_tlvdef, msgb_l2(msg) + 1, msgb_l2len(msg) - 1, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGSGC(sgc, LOGL_NOTICE, "SGsAP Message %s parsing error\n", sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+                sgs_tx_status(sgc, SGSAP_SGS_CAUSE_SEMANT_INCORR_MSG, NULL, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+             msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return 0;</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%);">+   /* Most of the messages contain an IMSI as mandatory IE, parse it right here */</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!TLVP_PRESENT(&tp, SGSAP_IE_IMSI) &&</span><br><span style="color: hsl(120, 100%, 40%);">+      msg_type != SGSAP_MSGT_STATUS && msg_type != SGSAP_MSGT_RESET_IND && msg_type != SGSAP_MSGT_RESET_ACK) {</span><br><span style="color: hsl(120, 100%, 40%);">+          /* reject the message; all but the three above have mandatory IMSI */</span><br><span style="color: hsl(120, 100%, 40%);">+         LOGSGC(sgc, LOGL_NOTICE, "SGsAP Message %s without IMSI, dropping\n", sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+               sgs_tx_status(sgc, SGSAP_SGS_CAUSE_MISSING_MAND_IE, NULL, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     memset(imsi, 0, sizeof(imsi));</span><br><span style="color: hsl(120, 100%, 40%);">+        if (TLVP_PRESENT(&tp, SGSAP_IE_IMSI)) {</span><br><span style="color: hsl(120, 100%, 40%);">+           gsm48_mi_to_string(imsi, sizeof(imsi), TLVP_VAL(&tp, SGSAP_IE_IMSI), TLVP_LEN(&tp, SGSAP_IE_IMSI));</span><br><span style="color: hsl(120, 100%, 40%);">+           /* FIXME: Is there a well defined minimum length (MCC=3 + MNC=2 + MSIN=1 => 6?) */</span><br><span style="color: hsl(120, 100%, 40%);">+         if (strlen(imsi) <= 6) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   LOGSGC(sgc, LOGL_NOTICE, "SGsAP Message %s with short IMSI, dropping\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                           sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+                        sgs_tx_status(sgc, SGSAP_SGS_CAUSE_INVALID_MAND_IE, NULL, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                       msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                       return 0;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Some messages contain an MME-NAME as mandatore IE, parse it right here. The</span><br><span style="color: hsl(120, 100%, 40%);">+         * MME-NAME is als immediately registered with the sgc, so it will be implicitly</span><br><span style="color: hsl(120, 100%, 40%);">+       * known to all functions that have access to the sgc context. */</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!TLVP_PRESENT(&tp, SGSAP_IE_MME_NAME)</span><br><span style="color: hsl(120, 100%, 40%);">+     && (msg_type == SGSAP_MSGT_RESET_IND || msg_type == SGSAP_MSGT_RESET_ACK</span><br><span style="color: hsl(120, 100%, 40%);">+          || msg_type == SGSAP_MSGT_LOC_UPD_REQ || msg_type == SGSAP_MSGT_IMSI_DET_IND</span><br><span style="color: hsl(120, 100%, 40%);">+          || msg_type == SGSAP_MSGT_EPS_DET_IND)) {</span><br><span style="color: hsl(120, 100%, 40%);">+             LOGSGC(sgc, LOGL_NOTICE, "SGsAP Message %s without MME-Name, dropping\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                  sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+                sgs_tx_status(sgc, SGSAP_SGS_CAUSE_MISSING_MAND_IE, NULL, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     memset(mme_name, 0, sizeof(mme_name));</span><br><span style="color: hsl(120, 100%, 40%);">+        if (TLVP_PRESENT(&tp, SGSAP_IE_MME_NAME)) {</span><br><span style="color: hsl(120, 100%, 40%);">+               if (decode_mme_name(mme_name, &tp) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        LOGSGC(sgc, LOGL_NOTICE, "SGsAP Message %s with invalid MME-Name, dropping\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                             sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+                        sgs_tx_status_tp(sgc, SGSAP_SGS_CAUSE_INVALID_MAND_IE, &tp, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                 msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                       return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+             }</span><br><span style="color: hsl(120, 100%, 40%);">+             /* Regsister/check mme_name with sgc */</span><br><span style="color: hsl(120, 100%, 40%);">+               if (sgs_mme_fqdn_received(sgc, mme_name) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    sgs_tx_status_tp(sgc, SGSAP_SGS_CAUSE_MSG_INCOMP_STATE, &tp, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                        LOGSGC(sgc, LOGL_NOTICE, "SGsAP Message %s with invalid MME-Name, dropping\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                             sgsap_msg_type_name(msg_type));</span><br><span style="color: hsl(120, 100%, 40%);">+                        msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                       return 0;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* dispatch msg to various handler functions.  msgb ownership remains here! */</span><br><span style="color: hsl(120, 100%, 40%);">+        switch (msg_type) {</span><br><span style="color: hsl(120, 100%, 40%);">+   case SGSAP_MSGT_STATUS:</span><br><span style="color: hsl(120, 100%, 40%);">+               sgs_rx_status(sgc, msg, &tp);</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_RESET_IND:</span><br><span style="color: hsl(120, 100%, 40%);">+            sgs_rx_reset_ind(sgc, msg, &tp);</span><br><span style="color: hsl(120, 100%, 40%);">+          break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_RESET_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+            sgs_rx_reset_ack(sgc, msg, &tp);</span><br><span style="color: hsl(120, 100%, 40%);">+          break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_LOC_UPD_REQ:</span><br><span style="color: hsl(120, 100%, 40%);">+          sgs_rx_loc_upd_req(sgc, msg, &tp, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+          break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_IMSI_DET_IND:</span><br><span style="color: hsl(120, 100%, 40%);">+         sgs_rx_imsi_det_ind(sgc, msg, &tp, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_EPS_DET_IND:</span><br><span style="color: hsl(120, 100%, 40%);">+          sgs_rx_eps_det_ind(sgc, msg, &tp, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+          break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_TMSI_REALL_CMPL:</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGSAP_MSGT_ALERT_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+    case SGSAP_MSGT_ALERT_REJ:</span><br><span style="color: hsl(120, 100%, 40%);">+    case SGSAP_MSGT_PAGING_REJ:</span><br><span style="color: hsl(120, 100%, 40%);">+   case SGSAP_MSGT_UE_ACT_IND:</span><br><span style="color: hsl(120, 100%, 40%);">+   case SGSAP_MSGT_UE_UNREACHABLE:</span><br><span style="color: hsl(120, 100%, 40%);">+       case SGSAP_MSGT_UL_UD:</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGSAP_MSGT_SERVICE_REQ:</span><br><span style="color: hsl(120, 100%, 40%);">+  case SGSAP_MSGT_MO_CSFB_IND:</span><br><span style="color: hsl(120, 100%, 40%);">+          LOGSGC(sgc, LOGL_NOTICE, "Rx unmplemented SGsAP %s: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                 sgsap_msg_type_name(msg_type), msgb_hexdump(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+             sgs_tx_status_tp(sgc, SGSAP_SGS_CAUSE_MSG_UNKNOWN, &tp, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGSGC(sgc, LOGL_NOTICE, "Rx unknown SGsAP message type 0x%02x: %s\n", msg_type, msgb_hexdump(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+                sgs_tx_status_tp(sgc, SGSAP_SGS_CAUSE_MSG_UNKNOWN, &tp, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+       return 0;</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%);">+/***********************************************************************</span><br><span style="color: hsl(120, 100%, 40%);">+ * SGs connection "VLR Reset Procedure" FSM</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%);">+static const struct value_string sgs_vlr_reset_fsm_event_names[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+    {SGS_VLRR_E_START_RESET, "START-RESET"},</span><br><span style="color: hsl(120, 100%, 40%);">+    {SGS_VLRR_E_RX_RESET_ACK, "RX-RESET-ACK"},</span><br><span style="color: hsl(120, 100%, 40%);">+  {0, NULL}</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%);">+static void sgs_vlr_reset_fsm_null(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_VLRR_E_RX_RESET_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_vlr_reset_fsm_wait_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_VLRR_E_RX_RESET_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+         osmo_fsm_inst_state_chg(fi, SGS_VLRR_ST_COMPLETE, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_vlr_reset_fsm_complete(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_VLRR_E_RX_RESET_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_vlr_reset_fsm_allstate(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct sgs_mme_ctx *mme = (struct sgs_mme_ctx *)fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_connection *sgc = mme->conn;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct sgs_state *sgs = mme->sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_VLRR_E_START_RESET:</span><br><span style="color: hsl(120, 100%, 40%);">+          osmo_fsm_inst_state_chg(fi, SGS_VLRR_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+          mme->ns11_remaining = sgs->cfg.counter[SGS_STATE_NS11];</span><br><span style="color: hsl(120, 100%, 40%);">+         /* send a reset message and enter WAIT_ACK state */</span><br><span style="color: hsl(120, 100%, 40%);">+           sgs_tx_reset_ind_vlr(sgc, sgs->cfg.vlr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+              osmo_fsm_inst_state_chg(fi, SGS_VLRR_ST_WAIT_ACK, sgs->cfg.timer[SGS_STATE_TS11], 11);</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int sgs_vlr_reset_fsm_timer_cb(struct osmo_fsm_inst *fi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    struct sgs_mme_ctx *mme = (struct sgs_mme_ctx *)fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_connection *sgc = mme->conn;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct sgs_state *sgs = mme->sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        switch (fi->T) {</span><br><span style="color: hsl(120, 100%, 40%);">+   case 11:</span><br><span style="color: hsl(120, 100%, 40%);">+              if (mme->ns11_remaining >= 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 sgs_tx_reset_ind_vlr(sgc, sgc->sgs->cfg.vlr_name);</span><br><span style="color: hsl(120, 100%, 40%);">+                      osmo_fsm_inst_state_chg(fi, SGS_VLRR_ST_WAIT_ACK, sgs->cfg.timer[SGS_STATE_TS11], 11);</span><br><span style="color: hsl(120, 100%, 40%);">+                     mme->ns11_remaining--;</span><br><span style="color: hsl(120, 100%, 40%);">+             } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                      LOGMME(mme, LOGL_ERROR, "Ts11 expired more than Ns11 times, giving up\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                  osmo_fsm_inst_state_chg(fi, SGS_VLRR_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+          }</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</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%);">+static const struct osmo_fsm_state sgs_vlr_reset_fsm_states[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+     [SGS_VLRR_ST_NULL] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                              /* We haven't even tried yet to send a RESET */</span><br><span style="color: hsl(120, 100%, 40%);">+                           .name = "NULL",</span><br><span style="color: hsl(120, 100%, 40%);">+                             .action = sgs_vlr_reset_fsm_null,</span><br><span style="color: hsl(120, 100%, 40%);">+                             .in_event_mask = S(SGS_VLRR_E_RX_RESET_ACK),</span><br><span style="color: hsl(120, 100%, 40%);">+                          .out_state_mask = S(SGS_VLRR_ST_NULL) | S(SGS_VLRR_ST_WAIT_ACK),</span><br><span style="color: hsl(120, 100%, 40%);">+                              },</span><br><span style="color: hsl(120, 100%, 40%);">+      [SGS_VLRR_ST_WAIT_ACK] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                              /* We're waiting for a SGsAP_RESET_ACK */</span><br><span style="color: hsl(120, 100%, 40%);">+                                 .name = "WAIT-ACK",</span><br><span style="color: hsl(120, 100%, 40%);">+                                 .action = sgs_vlr_reset_fsm_wait_ack,</span><br><span style="color: hsl(120, 100%, 40%);">+                                 .in_event_mask = S(SGS_VLRR_E_RX_RESET_ACK),</span><br><span style="color: hsl(120, 100%, 40%);">+                                  .out_state_mask = S(SGS_VLRR_ST_NULL) |</span><br><span style="color: hsl(120, 100%, 40%);">+                               S(SGS_VLRR_ST_COMPLETE) | S(SGS_VLRR_ST_WAIT_ACK),</span><br><span style="color: hsl(120, 100%, 40%);">+                            },</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_VLRR_ST_COMPLETE] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                              /* Reset procedure to this MME has been completed */</span><br><span style="color: hsl(120, 100%, 40%);">+                                  .name = "COMPLETE",</span><br><span style="color: hsl(120, 100%, 40%);">+                                 .action = sgs_vlr_reset_fsm_complete,</span><br><span style="color: hsl(120, 100%, 40%);">+                                 .in_event_mask = S(SGS_VLRR_E_RX_RESET_ACK),</span><br><span style="color: hsl(120, 100%, 40%);">+                                  .out_state_mask = S(SGS_VLRR_ST_NULL) | S(SGS_VLRR_ST_COMPLETE),</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_fsm sgs_vlr_reset_fsm = {</span><br><span style="color: hsl(120, 100%, 40%);">+      .name = "SGs-VLR-RESET",</span><br><span style="color: hsl(120, 100%, 40%);">+    .states = sgs_vlr_reset_fsm_states,</span><br><span style="color: hsl(120, 100%, 40%);">+   .allstate_event_mask = S(SGS_VLRR_E_START_RESET),</span><br><span style="color: hsl(120, 100%, 40%);">+     .allstate_action = sgs_vlr_reset_fsm_allstate,</span><br><span style="color: hsl(120, 100%, 40%);">+        .timer_cb = sgs_vlr_reset_fsm_timer_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+       .log_subsys = DSGS,</span><br><span style="color: hsl(120, 100%, 40%);">+   .event_names = sgs_vlr_reset_fsm_event_names,</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%);">+/***********************************************************************</span><br><span style="color: hsl(120, 100%, 40%);">+ * SGs connection server</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%);">+#include <netinet/sctp.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int sgs_conn_readable_cb(struct osmo_stream_srv *conn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_connection *sgc = osmo_stream_srv_get_data(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+  struct msgb *msg = sgs_msgb_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sctp_sndrcvinfo sinfo;</span><br><span style="color: hsl(120, 100%, 40%);">+ int flags = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+        int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* we cannot use osmo_stream_srv_recv() here, as we might get some out-of-band info from</span><br><span style="color: hsl(120, 100%, 40%);">+       * SCTP.  FIXME: add something like osmo_stream_srv_recv_sctp() to libosmo-netif and use</span><br><span style="color: hsl(120, 100%, 40%);">+       * it here as well as in libosmo-sigtran */</span><br><span style="color: hsl(120, 100%, 40%);">+   rc = sctp_recvmsg(ofd->fd, msgb_data(msg), msgb_tailroom(msg), NULL, NULL, &sinfo, &flags);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              osmo_stream_srv_destroy(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+                goto out;</span><br><span style="color: hsl(120, 100%, 40%);">+     } else if (rc == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+         osmo_stream_srv_destroy(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+                goto out;</span><br><span style="color: hsl(120, 100%, 40%);">+     } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              msgb_put(msg, rc);</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%);">+   if (flags & MSG_NOTIFICATION) {</span><br><span style="color: hsl(120, 100%, 40%);">+           union sctp_notification *notif = (union sctp_notification *)msgb_data(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+         switch (notif->sn_header.sn_type) {</span><br><span style="color: hsl(120, 100%, 40%);">+                case SCTP_SHUTDOWN_EVENT:</span><br><span style="color: hsl(120, 100%, 40%);">+                     osmo_stream_srv_destroy(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+                        break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case SCTP_ASSOC_CHANGE:</span><br><span style="color: hsl(120, 100%, 40%);">+                       /* do we have to notify the SGs code about this? */</span><br><span style="color: hsl(120, 100%, 40%);">+                   break;</span><br><span style="color: hsl(120, 100%, 40%);">+                default:</span><br><span style="color: hsl(120, 100%, 40%);">+                      break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             rc = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+               goto out;</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%);">+   /* set l2 header, as that's what we use in SGs code */</span><br><span style="color: hsl(120, 100%, 40%);">+    msg->l2h = msgb_data(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       if (msgb_sctp_ppid(msg) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               LOGSGC(sgc, LOGL_NOTICE, "Ignoring SCTP PPID %ld (spec violation)\n", msgb_sctp_ppid(msg));</span><br><span style="color: hsl(120, 100%, 40%);">+         msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     /* handle message */</span><br><span style="color: hsl(120, 100%, 40%);">+  sgs_rx(sgc, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+out:</span><br><span style="color: hsl(120, 100%, 40%);">+       msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+       return rc;</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%);">+static int sgs_conn_closed_cb(struct osmo_stream_srv *conn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct sgs_connection *sgc = osmo_stream_srv_get_data(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        LOGSGC(sgc, LOGL_NOTICE, "Connection lost\n");</span><br><span style="color: hsl(120, 100%, 40%);">+      if (sgc->mme) {</span><br><span style="color: hsl(120, 100%, 40%);">+            /* unlink ourselves from the MME context */</span><br><span style="color: hsl(120, 100%, 40%);">+           if (sgc->mme->conn == sgc)</span><br><span style="color: hsl(120, 100%, 40%);">+                      sgc->mme->conn = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     llist_del(&sgc->list);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</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%);">+/* call-back when new connection is accept() ed on SGs */</span><br><span style="color: hsl(120, 100%, 40%);">+static int sgs_accept_cb(struct osmo_stream_srv_link *link, int fd)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct sgs_state *sgs = osmo_stream_srv_link_get_data(link);</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_connection *sgc = talloc_zero(link, struct sgs_connection);</span><br><span style="color: hsl(120, 100%, 40%);">+        OSMO_ASSERT(sgc);</span><br><span style="color: hsl(120, 100%, 40%);">+     sgc->sgs = sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+    sgc->sockname = osmo_sock_get_name(sgc, fd);</span><br><span style="color: hsl(120, 100%, 40%);">+       sgc->srv = osmo_stream_srv_create(sgc, link, fd, sgs_conn_readable_cb, sgs_conn_closed_cb, sgc);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!sgc->srv) {</span><br><span style="color: hsl(120, 100%, 40%);">+           talloc_free(sgc);</span><br><span style="color: hsl(120, 100%, 40%);">+             return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+     LOGSGC(sgc, LOGL_INFO, "Accepted new SGs connection\n");</span><br><span style="color: hsl(120, 100%, 40%);">+    llist_add_tail(&sgc->list, &sgs->conn_list);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  return 0;</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%);">+/* global init function */</span><br><span style="color: hsl(120, 100%, 40%);">+struct sgs_state *sgs_init(void *ctx, struct gsm_network *network)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct sgs_state *sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct osmo_stream_srv_link *link;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  gsm_network = network;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      sgs = sgs_state_alloc(ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+   OSMO_ASSERT(sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* We currently only support one SGs instance */</span><br><span style="color: hsl(120, 100%, 40%);">+      OSMO_ASSERT(!g_sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+  g_sgs = sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        osmo_fsm_register(&sgs_vlr_reset_fsm);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  sgs->srv_link = link = osmo_stream_srv_link_create(ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+   OSMO_ASSERT(sgs->srv_link);</span><br><span style="color: hsl(120, 100%, 40%);">+        osmo_stream_srv_link_set_nodelay(link, true);</span><br><span style="color: hsl(120, 100%, 40%);">+ //osmo_stream_srv_link_set_addr(link, local_ip);</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_stream_srv_link_set_port(link, 29118);</span><br><span style="color: hsl(120, 100%, 40%);">+   osmo_stream_srv_link_set_proto(link, IPPROTO_SCTP);</span><br><span style="color: hsl(120, 100%, 40%);">+   osmo_stream_srv_link_set_data(link, sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_stream_srv_link_set_accept_cb(link, sgs_accept_cb);</span><br><span style="color: hsl(120, 100%, 40%);">+      sgs_open(sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      return sgs;</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%);">+int sgs_open(struct sgs_state *sgs)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+       struct osmo_fd *ofd = osmo_stream_srv_link_get_ofd(sgs->srv_link);</span><br><span style="color: hsl(120, 100%, 40%);">+ char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = osmo_stream_srv_link_open(sgs->srv_link);</span><br><span style="color: hsl(120, 100%, 40%);">+     if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGP(DSGS, LOGL_ERROR, "SGs socket cannot be opened: %s\n", strerror(errno));</span><br><span style="color: hsl(120, 100%, 40%);">+               return rc;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+     name = osmo_sock_get_name(sgs, ofd->fd);</span><br><span style="color: hsl(120, 100%, 40%);">+   LOGP(DSGS, LOGL_NOTICE, "SGs socket bound to %s\n", name);</span><br><span style="color: hsl(120, 100%, 40%);">+  talloc_free(name);</span><br><span style="color: hsl(120, 100%, 40%);">+    return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/libmsc/sgs_vty.c b/src/libmsc/sgs_vty.c</span><br><span>new file mode 100644</span><br><span>index 0000000..6a0b1ad</span><br><span>--- /dev/null</span><br><span>+++ b/src/libmsc/sgs_vty.c</span><br><span>@@ -0,0 +1,176 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* SGs Interface according to 3GPP TS 23.272 + TS 29.118 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C 2018 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU Affero General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <errno.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vty.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/netif/stream.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/sgs_iface.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/debug.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/tlv.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct cmd_node cfg_sgs_node = {</span><br><span style="color: hsl(120, 100%, 40%);">+     CFG_SGS_NODE,</span><br><span style="color: hsl(120, 100%, 40%);">+ "%s(config-sgs)# ",</span><br><span style="color: hsl(120, 100%, 40%);">+ 1</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%);">+DEFUN(cfg_sgs, cfg_sgs_cmd, "sgs", "Configure the SGs interface\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   vty->index = g_sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+        vty->node = CFG_SGS_NODE;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        return CMD_SUCCESS;</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%);">+DEFUN(cfg_sgs_local_ip, cfg_sgs_local_ip_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+      "local-ip A.B.C.D", "Set the Local IP Address of the SGs interface\n" "Local IP Address of the SGs interface\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct sgs_state *sgs = vty->index;</span><br><span style="color: hsl(120, 100%, 40%);">+        int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_stream_srv_link_set_addr(sgs->srv_link, argv[0]);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   rc = sgs_open(sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              vty_out(vty, "%% SGs socket cannot be opened: %s%s", strerror(errno), VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+         return CMD_WARNING;</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%);">+   return CMD_SUCCESS;</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%);">+DEFUN(cfg_sgs_local_port, cfg_sgs_local_port_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+      "local-port <0-65535>", "Set the local SCTP port of the SGs interface\n" "Local SCTP port of the SGs interface\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_state *sgs = vty->index;</span><br><span style="color: hsl(120, 100%, 40%);">+        int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_stream_srv_link_set_port(sgs->srv_link, atoi(argv[0]));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = sgs_open(sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              vty_out(vty, "%% SGs socket cannot be opened: %s%s", strerror(errno), VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+         return CMD_WARNING;</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%);">+   return CMD_SUCCESS;</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%);">+DEFUN(cfg_sgs_vlr_name, cfg_sgs_vlr_name_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+      "vlr-name FQDN", "Set the SGs VLR Name as per TS 29.118 9.4.22\n" "Fully-Qualified Domain Name of this VLR\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct sgs_state *sgs = vty->index;</span><br><span style="color: hsl(120, 100%, 40%);">+        osmo_talloc_replace_string(sgs, &sgs->cfg.vlr_name, argv[0]);</span><br><span style="color: hsl(120, 100%, 40%);">+  return CMD_SUCCESS;</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%);">+DEFUN(cfg_sgs_timer, cfg_sgs_timer_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+      "timer (Ts5|TS6-2|Ts7|Ts11|Ts14|Ts15) <1-120>",</span><br><span style="color: hsl(120, 100%, 40%);">+      "Configure SGs Timer\n"</span><br><span style="color: hsl(120, 100%, 40%);">+      "Paging procedure guard timer\n"</span><br><span style="color: hsl(120, 100%, 40%);">+      "TMSI reallocation guard timer\n"</span><br><span style="color: hsl(120, 100%, 40%);">+      "Non-EPS alert procedure guard timer\n"</span><br><span style="color: hsl(120, 100%, 40%);">+      "VLR reset guard timer\n"</span><br><span style="color: hsl(120, 100%, 40%);">+      "UE fallback prcoedure timer\n" "MO UE fallback procedure guard timer\n" "Time in seconds\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct sgs_state *sgs = vty->index;</span><br><span style="color: hsl(120, 100%, 40%);">+        unsigned int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     for (i = 0; i < ARRAY_SIZE(sgs->cfg.timer); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+              if (!strcmp(argv[0], sgs_state_timer_names[i])) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     sgs->cfg.timer[i] = atoi(argv[1]);</span><br><span style="color: hsl(120, 100%, 40%);">+                 return CMD_SUCCESS;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return CMD_WARNING;</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%);">+DEFUN(cfg_sgs_counter, cfg_sgs_counter_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+      "counter (Ns7|Ns11) <0-255>",</span><br><span style="color: hsl(120, 100%, 40%);">+      "Configure SGs Counter\n" "Non-EPS alert request retry counter\n" "VLR reset retry counter\n" "Counter value\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sgs_state *sgs = vty->index;</span><br><span style="color: hsl(120, 100%, 40%);">+        unsigned int i = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_SIZE(sgs->cfg.counter); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (!strcmp(argv[0], sgs_state_counter_names[i])) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   sgs->cfg.counter[i] = atoi(argv[1]);</span><br><span style="color: hsl(120, 100%, 40%);">+                       return CMD_SUCCESS;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return CMD_WARNING;</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%);">+DEFUN(show_sgs_conn, show_sgs_conn_cmd, "show sgs-connections", SHOW_STR "Show SGs interface connections / MMEs\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct sgs_connection *sgc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ llist_for_each_entry(sgc, &g_sgs->conn_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+           vty_out(vty, " %s %s%s", sgc->sockname, sgc->mme ? sgc->mme->fqdn : "", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+     return CMD_SUCCESS;</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%);">+static int config_write_sgs(struct vty *vty)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct sgs_state *sgs = g_sgs;</span><br><span style="color: hsl(120, 100%, 40%);">+        unsigned int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     vty_out(vty, "sgs%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (sgs->cfg.local_port != 29118)</span><br><span style="color: hsl(120, 100%, 40%);">+          vty_out(vty, " local-port %u%s", sgs->cfg.local_port, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+      if (sgs->cfg.local_addr)</span><br><span style="color: hsl(120, 100%, 40%);">+           vty_out(vty, " local-ip %s%s", sgs->cfg.local_addr, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (sgs->cfg.vlr_name)</span><br><span style="color: hsl(120, 100%, 40%);">+             vty_out(vty, " vlr-name %s%s", sgs->cfg.vlr_name, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        for (i = 0; i < ARRAY_SIZE(sgs->cfg.timer); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+              if (sgs->cfg.timer[i] == sgs_state_timer_defaults[i])</span><br><span style="color: hsl(120, 100%, 40%);">+                      continue;</span><br><span style="color: hsl(120, 100%, 40%);">+             vty_out(vty, " timer %s %u%s", sgs_state_timer_names[i], sgs->cfg.timer[i], VTY_NEWLINE);</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%);">+   for (i = 0; i < ARRAY_SIZE(sgs->cfg.counter); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (sgs->cfg.timer[i] == sgs_state_counter_defaults[i])</span><br><span style="color: hsl(120, 100%, 40%);">+                    continue;</span><br><span style="color: hsl(120, 100%, 40%);">+             vty_out(vty, " counter %s %u%s", sgs_state_counter_names[i], sgs->cfg.counter[i], VTY_NEWLINE);</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%);">+   return 1;</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%);">+void sgs_vty_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    /* configuration commands / nodes */</span><br><span style="color: hsl(120, 100%, 40%);">+  install_element(CONFIG_NODE, &cfg_sgs_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+       install_node(&cfg_sgs_node, config_write_sgs);</span><br><span style="color: hsl(120, 100%, 40%);">+    install_element(CFG_SGS_NODE, &cfg_sgs_local_ip_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+     install_element(CFG_SGS_NODE, &cfg_sgs_local_port_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+   install_element(CFG_SGS_NODE, &cfg_sgs_timer_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+        install_element(CFG_SGS_NODE, &cfg_sgs_counter_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+      install_element(CFG_SGS_NODE, &cfg_sgs_vlr_name_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   install_element_ve(&show_sgs_conn_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/libmsc/silent_call.c b/src/libmsc/silent_call.c</span><br><span>index 9888894..a173a0f 100644</span><br><span>--- a/src/libmsc/silent_call.c</span><br><span>+++ b/src/libmsc/silent_call.c</span><br><span>@@ -129,7 +129,8 @@</span><br><span>     * This doesn't apply to the situation after MSCSPLIT with an</span><br><span>     * A-interface. */</span><br><span>   req = subscr_request_conn(vsub, paging_cb_silent, data,</span><br><span style="color: hsl(0, 100%, 40%);">-                           "establish silent call");</span><br><span style="color: hsl(120, 100%, 40%);">+                           "establish silent call",</span><br><span style="color: hsl(120, 100%, 40%);">+                            SGSAP_SERV_IND_CS_CALL);</span><br><span>   if (!req)</span><br><span>            return -ENODEV;</span><br><span>      return 0;</span><br><span>diff --git a/src/libvlr/Makefile.am b/src/libvlr/Makefile.am</span><br><span>index dcae1c7..790943c 100644</span><br><span>--- a/src/libvlr/Makefile.am</span><br><span>+++ b/src/libvlr/Makefile.am</span><br><span>@@ -16,6 +16,7 @@</span><br><span>   vlr_auth_fsm.h \</span><br><span>     vlr_core.h \</span><br><span>         vlr_lu_fsm.h \</span><br><span style="color: hsl(120, 100%, 40%);">+        vlr_sgs_fsm.h \</span><br><span>      $(NULL)</span><br><span> </span><br><span> noinst_LIBRARIES = libvlr.a</span><br><span>@@ -25,4 +26,6 @@</span><br><span>       vlr_access_req_fsm.c \</span><br><span>       vlr_auth_fsm.c \</span><br><span>     vlr_lu_fsm.c \</span><br><span style="color: hsl(120, 100%, 40%);">+        vlr_sgs.c \</span><br><span style="color: hsl(120, 100%, 40%);">+   vlr_sgs_fsm.c \</span><br><span>      $(NULL)</span><br><span>diff --git a/src/libvlr/vlr.c b/src/libvlr/vlr.c</span><br><span>index f7572f2..920c332 100644</span><br><span>--- a/src/libvlr/vlr.c</span><br><span>+++ b/src/libvlr/vlr.c</span><br><span>@@ -30,6 +30,7 @@</span><br><span> #include <osmocom/msc/gsm_subscriber.h></span><br><span> #include <osmocom/gsupclient/gsup_client.h></span><br><span> #include <osmocom/msc/vlr.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr_sgs.h></span><br><span> #include <osmocom/msc/debug.h></span><br><span> </span><br><span> #include <netinet/in.h></span><br><span>@@ -41,6 +42,7 @@</span><br><span> #include "vlr_auth_fsm.h"</span><br><span> #include "vlr_lu_fsm.h"</span><br><span> #include "vlr_access_req_fsm.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "vlr_sgs_fsm.h"</span><br><span> </span><br><span> #define SGSN_SUBSCR_MAX_RETRIES 3</span><br><span> #define SGSN_SUBSCR_RETRY_INTERVAL 10</span><br><span>@@ -247,6 +249,11 @@</span><br><span>  INIT_LLIST_HEAD(&vsub->cs.requests);</span><br><span>  INIT_LLIST_HEAD(&vsub->ps.pdp_list);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+       /* Create an SGs FSM, which is needed to control CSFB,</span><br><span style="color: hsl(120, 100%, 40%);">+         * in cases where CSFB/SGs is not in use, this FSM will</span><br><span style="color: hsl(120, 100%, 40%);">+        * just do nothing. (see also: sgs_iface.c) */</span><br><span style="color: hsl(120, 100%, 40%);">+        vlr_sgs_fsm_create(vsub);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  llist_add_tail(&vsub->list, &vlr->subscribers);</span><br><span>        return vsub;</span><br><span> }</span><br><span>@@ -292,6 +299,10 @@</span><br><span> {</span><br><span>        llist_del(&vsub->list);</span><br><span>       DEBUGP(DREF, "freeing VLR subscr %s\n", vlr_subscr_name(vsub));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Remove SGs FSM (see also: sgs_iface.c) */</span><br><span style="color: hsl(120, 100%, 40%);">+  vlr_sgs_fsm_remove(vsub);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  talloc_free(vsub);</span><br><span> }</span><br><span> </span><br><span>@@ -816,7 +827,13 @@</span><br><span> static int vlr_subscr_handle_lu_res(struct vlr_subscr *vsub,</span><br><span>                               const struct osmo_gsup_message *gsup)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-  if (!vsub->lu_fsm) {</span><br><span style="color: hsl(120, 100%, 40%);">+       struct sgs_lu_response sgs_lu_response;</span><br><span style="color: hsl(120, 100%, 40%);">+       bool sgs_lu_in_progress = false;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (vsub->sgs_fsm->state == SGS_UE_ST_LA_UPD_PRES)</span><br><span style="color: hsl(120, 100%, 40%);">+              sgs_lu_in_progress = true;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!vsub->lu_fsm && !sgs_lu_in_progress) {</span><br><span>               LOGVSUBP(LOGL_ERROR, vsub, "Rx GSUP LU Result "</span><br><span>                     "without LU in progress\n");</span><br><span>              return -ENODEV;</span><br><span>@@ -827,7 +844,12 @@</span><br><span>        * nested INSERT SUBSCRIBER DATA transaction */</span><br><span>      vlr_subscr_gsup_insert_data(vsub, gsup);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_HLR_LU_RES, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (sgs_lu_in_progress) {</span><br><span style="color: hsl(120, 100%, 40%);">+             sgs_lu_response.accepted = true;</span><br><span style="color: hsl(120, 100%, 40%);">+              sgs_lu_response.vsub = vsub;</span><br><span style="color: hsl(120, 100%, 40%);">+          vsub->sgs.response_cb(&sgs_lu_response);</span><br><span style="color: hsl(120, 100%, 40%);">+       } else</span><br><span style="color: hsl(120, 100%, 40%);">+                osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_HLR_LU_RES, NULL);</span><br><span> </span><br><span>     return 0;</span><br><span> }</span><br><span>@@ -836,7 +858,13 @@</span><br><span> static int vlr_subscr_handle_lu_err(struct vlr_subscr *vsub,</span><br><span>                                    const struct osmo_gsup_message *gsup)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-  if (!vsub->lu_fsm) {</span><br><span style="color: hsl(120, 100%, 40%);">+       struct sgs_lu_response sgs_lu_response;</span><br><span style="color: hsl(120, 100%, 40%);">+       bool sgs_lu_in_progress = false;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (vsub->sgs_fsm->state == SGS_UE_ST_LA_UPD_PRES)</span><br><span style="color: hsl(120, 100%, 40%);">+              sgs_lu_in_progress = true;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!vsub->lu_fsm && !sgs_lu_in_progress) {</span><br><span>               LOGVSUBP(LOGL_ERROR, vsub, "Rx GSUP LU Error "</span><br><span>                      "without LU in progress\n");</span><br><span>              return -ENODEV;</span><br><span>@@ -845,9 +873,13 @@</span><br><span>       LOGVSUBP(LOGL_DEBUG, vsub, "UpdateLocation failed; gmm_cause: %s\n",</span><br><span>                get_value_string(gsm48_gmm_cause_names, gsup->cause));</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_HLR_LU_RES,</span><br><span style="color: hsl(0, 100%, 40%);">-                           (void *)&gsup->cause);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ if (sgs_lu_in_progress) {</span><br><span style="color: hsl(120, 100%, 40%);">+             sgs_lu_response.accepted = false;</span><br><span style="color: hsl(120, 100%, 40%);">+             sgs_lu_response.vsub = vsub;</span><br><span style="color: hsl(120, 100%, 40%);">+          vsub->sgs.response_cb(&sgs_lu_response);</span><br><span style="color: hsl(120, 100%, 40%);">+       } else</span><br><span style="color: hsl(120, 100%, 40%);">+                osmo_fsm_inst_dispatch(vsub->lu_fsm, VLR_ULA_E_HLR_LU_RES,</span><br><span style="color: hsl(120, 100%, 40%);">+                                 (void *)&gsup->cause);</span><br><span>        return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -1157,6 +1189,9 @@</span><br><span>   vsub->imsi_detached_flag = true;</span><br><span>  vsub->expire_lu = VLR_SUBSCRIBER_NO_EXPIRATION;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        /* Inform the UE-SGs FSM that the subscriber has been detached */</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_DETACH_IND_FROM_UE, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>    /* balancing the get from vlr_lu_compl_fsm_success() */</span><br><span>      vlr_subscr_expire(vsub);</span><br><span> </span><br><span>@@ -1206,6 +1241,8 @@</span><br><span>         vlr_lu_fsm_init();</span><br><span>   /* vlr_access_request_fsm.c */</span><br><span>       vlr_parq_fsm_init();</span><br><span style="color: hsl(120, 100%, 40%);">+  /* vlr_sgs_fsm.c */</span><br><span style="color: hsl(120, 100%, 40%);">+   vlr_sgs_fsm_init();</span><br><span> </span><br><span>      return vlr;</span><br><span> }</span><br><span>diff --git a/src/libvlr/vlr_lu_fsm.c b/src/libvlr/vlr_lu_fsm.c</span><br><span>index 717db42..10cb656 100644</span><br><span>--- a/src/libvlr/vlr_lu_fsm.c</span><br><span>+++ b/src/libvlr/vlr_lu_fsm.c</span><br><span>@@ -27,6 +27,7 @@</span><br><span> #include "vlr_core.h"</span><br><span> #include "vlr_auth_fsm.h"</span><br><span> #include "vlr_lu_fsm.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "vlr_sgs_fsm.h"</span><br><span> </span><br><span> #define S(x)    (1 << (x))</span><br><span> </span><br><span>@@ -1045,6 +1046,11 @@</span><br><span> </span><br><span>    OSMO_ASSERT(lfp->vsub);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        /* At this point we know for which subscriber the location update is,</span><br><span style="color: hsl(120, 100%, 40%);">+  * we now must inform SGs-UE FSM that we received a location update</span><br><span style="color: hsl(120, 100%, 40%);">+    * via A, IU or Gs interface. */</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fsm_inst_dispatch(lfp->vsub->sgs_fsm, SGS_UE_E_RX_LU_FROM_A_IU_GS, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       /* See 3GPP TS 23.012, procedure Retrieve_IMEISV_If_Required */</span><br><span>      if ((!vlr->cfg.retrieve_imeisv_early)</span><br><span>         || (lfp->type == VLR_LU_TYPE_PERIODIC && lfp->vsub->imeisv[0])) {</span><br><span>diff --git a/src/libvlr/vlr_sgs.c b/src/libvlr/vlr_sgs.c</span><br><span>new file mode 100644</span><br><span>index 0000000..d8c3a36</span><br><span>--- /dev/null</span><br><span>+++ b/src/libvlr/vlr_sgs.c</span><br><span>@@ -0,0 +1,124 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2018 by sysmocom s.f.m.c. GmbH</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Author: Harald Welte, Philipp Maier</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU Affero General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/debug.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr_sgs.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include "vlr_sgs_fsm.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Reset all SGs-Associations back to zero.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] vlr VLR instace. */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_reset(struct vlr_instance *vlr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct vlr_subscr *vsub;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_ASSERT(vlr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   LOGP(DVLR, LOGL_INFO, "dropping all SGs associations.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        llist_for_each_entry(vsub, &vlr->subscribers, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+          osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_RESET_FROM_MME, NULL);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Perform an SGs location update.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] vlr VLR instace.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] response_cb calback function that is called when LU is done.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] mme_name fqdn of the requesting MME (mme-name).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] type location update type (normal or IMSI attach).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] imsi mobile identity (IMSI).</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] new_lai identifier of the new location area.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns 0 in case of success, -EINVAL in case of error. */</span><br><span style="color: hsl(120, 100%, 40%);">+int vlr_sgs_loc_update(struct vlr_instance *vlr,</span><br><span style="color: hsl(120, 100%, 40%);">+                   vlr_sgs_lu_response_cb_t response_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+                 char *mme_name, enum vlr_lu_type type, const char *imsi, struct osmo_location_area_id *new_lai)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct vlr_subscr *vsub = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+       vsub = vlr_subscr_find_or_create_by_imsi(vlr, imsi, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  OSMO_ASSERT(response_cb);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!vsub) {</span><br><span style="color: hsl(120, 100%, 40%);">+          LOGP(DSGS, LOGL_ERROR, "VLR subscriber allocation failed\n");</span><br><span style="color: hsl(120, 100%, 40%);">+               return -EINVAL;</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%);">+   vsub->sgs.response_cb = response_cb;</span><br><span style="color: hsl(120, 100%, 40%);">+       vlr_subscr_set_imsi(vsub, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_strlcpy(vsub->sgs.mme_name, mme_name, sizeof(vsub->sgs.mme_name));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_LU_FROM_MME, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* FIXME: put type parameter to the right place! */</span><br><span style="color: hsl(120, 100%, 40%);">+   printf("==============================TYPE %x\n", type);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* FIXME: see note for struct member in vlr.h */</span><br><span style="color: hsl(120, 100%, 40%);">+      memcpy(&vsub->sgs.lai, new_lai, sizeof(vsub->sgs.lai));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</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%);">+/*! Notify that the SGs Location Update accept message has been sent to MME.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] vlr_subscr VLR subscriber. */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_loc_update_acc_sent(struct vlr_subscr *vlr_subscr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        osmo_fsm_inst_dispatch(vlr_subscr->sgs_fsm, SGS_UE_E_TX_LU_ACCEPT, NULL);</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%);">+/*! Notify that the SGs Location Update reject message has been sent to MME.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] vlr_subscr VLR subscriber. */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_loc_update_rej_sent(struct vlr_subscr *vlr_subscr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_fsm_inst_dispatch(vlr_subscr->sgs_fsm, SGS_UE_E_TX_LU_REJECT, NULL);</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%);">+/*! Perform an SGs ISMI/EPS detach */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_detach(struct vlr_instance *vlr, const char *imsi, bool eps)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct vlr_subscr *vsub;</span><br><span style="color: hsl(120, 100%, 40%);">+      vsub = vlr_subscr_find_by_imsi(vlr, imsi);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!vsub) {</span><br><span style="color: hsl(120, 100%, 40%);">+          /* Subscriber never existed or got already (implicitly) detached. */</span><br><span style="color: hsl(120, 100%, 40%);">+          return;</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%);">+   /* FIXME: What about the eps parameter? How is EPS Detach different</span><br><span style="color: hsl(120, 100%, 40%);">+    * from IMSI Detach? */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     vsub->imsi_detached_flag = true;</span><br><span style="color: hsl(120, 100%, 40%);">+   vsub->expire_lu = VLR_SUBSCRIBER_NO_EXPIRATION;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* Inform the UE-SGs FSM that the subscriber has been detached */</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_fsm_inst_dispatch(vsub->sgs_fsm, SGS_UE_E_RX_DETACH_IND_FROM_MME, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* balancing the get from vlr_lu_compl_fsm_success() */</span><br><span style="color: hsl(120, 100%, 40%);">+       vlr_subscr_expire(vsub);</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%);">+/*! Check if the has an SGs association.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns true if a an SGs association is present, otherwise false */</span><br><span style="color: hsl(120, 100%, 40%);">+bool vlr_sgs_assoc(struct vlr_subscr * vlr_subscr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       if (vlr_subscr->sgs_fsm->state == SGS_UE_ST_ASSOCIATED)</span><br><span style="color: hsl(120, 100%, 40%);">+         return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  return false;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/libvlr/vlr_sgs_fsm.c b/src/libvlr/vlr_sgs_fsm.c</span><br><span>new file mode 100644</span><br><span>index 0000000..ebfc1ba</span><br><span>--- /dev/null</span><br><span>+++ b/src/libvlr/vlr_sgs_fsm.c</span><br><span>@@ -0,0 +1,236 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2018 by sysmocom s.f.m.c. GmbH</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Author: Harald Welte, Philipp Maier</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU Affero General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/debug.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/vlr_sgs.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "vlr_sgs_fsm.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "vlr_core.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define S(x) (1 << (x))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct value_string sgs_ue_fsm_event_names[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+        {SGS_UE_E_VLR_FAILURE, "VLR_FAILURE"},</span><br><span style="color: hsl(120, 100%, 40%);">+      {SGS_UE_E_RX_RESET_FROM_MME, "RX_RESET_FROM_MME"},</span><br><span style="color: hsl(120, 100%, 40%);">+  {SGS_UE_E_RX_DETACH_IND_FROM_MME, "RX_DETACH_IND_FROM_MME"},</span><br><span style="color: hsl(120, 100%, 40%);">+        {SGS_UE_E_RX_DETACH_IND_FROM_UE, "RX_DETACH_IND_FROM_UE"},    /* vlr.c */</span><br><span style="color: hsl(120, 100%, 40%);">+   {SGS_UE_E_RX_LU_FROM_A_IU_GS, "RX_LU_FROM_A_Iu_Gs"},  /* vlr_lu_fsm.c */</span><br><span style="color: hsl(120, 100%, 40%);">+    {SGS_UE_E_RX_PAGING_FAILURE, "RX_PAGING_FAILURE"},</span><br><span style="color: hsl(120, 100%, 40%);">+  {SGS_UE_E_RX_ALERT_FAILURE, "RX_ALERT_FAILURE"},</span><br><span style="color: hsl(120, 100%, 40%);">+    {SGS_UE_E_RX_LU_FROM_MME, "RX_LU_FROM_MME"},</span><br><span style="color: hsl(120, 100%, 40%);">+        {SGS_UE_E_TX_LU_REJECT, "TX_LU_REJECT"},</span><br><span style="color: hsl(120, 100%, 40%);">+    {SGS_UE_E_TX_LU_ACCEPT, "TX_LU_ACCEPT"},</span><br><span style="color: hsl(120, 100%, 40%);">+    {SGS_UE_E_TX_PAGING, "TX_PAGING"},</span><br><span style="color: hsl(120, 100%, 40%);">+  {SGS_UE_E_RX_SGSAP_UE_UNRECHABLE, "RX_SGSAP_UE_UNREACH"},</span><br><span style="color: hsl(120, 100%, 40%);">+   {SGS_UE_E_RX_TMSI_REALLOC, "RX_TMSI_REALLOC"},</span><br><span style="color: hsl(120, 100%, 40%);">+      {0, NULL}</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%);">+/* Figure 4.2.2.1 SGs-NULL */</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_ue_fsm_null(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct vlr_subscr *vsub = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+        int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_RX_LU_FROM_MME:</span><br><span style="color: hsl(120, 100%, 40%);">+         osmo_fsm_inst_state_chg(fi, SGS_UE_ST_LA_UPD_PRES, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+             rc = vlr_subscr_req_lu(vsub, vsub->vlr->cfg.is_ps);</span><br><span style="color: hsl(120, 100%, 40%);">+             if (rc != 0)</span><br><span style="color: hsl(120, 100%, 40%);">+                  LOGPFSML(fi, LOGL_ERROR, "(sub %s) HLR LU request failed\n", vlr_subscr_msisdn_or_name(vsub));</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_TX_PAGING:</span><br><span style="color: hsl(120, 100%, 40%);">+              /* do nothing */</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_RX_PAGING_FAILURE:</span><br><span style="color: hsl(120, 100%, 40%);">+              /* do nothing */</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Figure 4.2.2.1 SGs-LA-UPDATE-PRESENT */</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_ue_fsm_lau_present(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct vlr_subscr *vsub = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_TX_LU_ACCEPT:</span><br><span style="color: hsl(120, 100%, 40%);">+           vsub->cs.attached_via_ran = RAN_UTRAN_SGS;</span><br><span style="color: hsl(120, 100%, 40%);">+         osmo_fsm_inst_state_chg(fi, SGS_UE_ST_ASSOCIATED, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+              vsub->conf_by_radio_contact_ind = true;</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_TX_LU_REJECT:</span><br><span style="color: hsl(120, 100%, 40%);">+   case SGS_UE_E_RX_PAGING_FAILURE:</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_RX_ALERT_FAILURE:</span><br><span style="color: hsl(120, 100%, 40%);">+               /* FIXME: Not sure if we really must reset this, it will</span><br><span style="color: hsl(120, 100%, 40%);">+               * be overwritten anyway when RAN changes to 2G or 3G? */</span><br><span style="color: hsl(120, 100%, 40%);">+             if (vsub->cs.attached_via_ran == RAN_UTRAN_SGS)</span><br><span style="color: hsl(120, 100%, 40%);">+                    vsub->cs.attached_via_ran = RAN_UNKNOWN;</span><br><span style="color: hsl(120, 100%, 40%);">+           osmo_fsm_inst_state_chg(fi, SGS_UE_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_TX_PAGING:</span><br><span style="color: hsl(120, 100%, 40%);">+              /* do nothing */</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Figure 4.2.2.1 SGs-ASSOCIATED */</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_ue_fsm_associated(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct vlr_subscr *vsub = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+        int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_TX_PAGING:</span><br><span style="color: hsl(120, 100%, 40%);">+              /* do nothing */</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_RX_TMSI_REALLOC:</span><br><span style="color: hsl(120, 100%, 40%);">+                /* do nothing */</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_RX_SGSAP_UE_UNRECHABLE:</span><br><span style="color: hsl(120, 100%, 40%);">+         /* do nothing */</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_RX_PAGING_FAILURE:</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_RX_ALERT_FAILURE:</span><br><span style="color: hsl(120, 100%, 40%);">+               /* FIXME: Not sure if we really must reset this, it will</span><br><span style="color: hsl(120, 100%, 40%);">+               * be overwritten anyway when RAN changes to 2G or 3G? */</span><br><span style="color: hsl(120, 100%, 40%);">+             if (vsub->cs.attached_via_ran == RAN_UTRAN_SGS)</span><br><span style="color: hsl(120, 100%, 40%);">+                    vsub->cs.attached_via_ran = RAN_UNKNOWN;</span><br><span style="color: hsl(120, 100%, 40%);">+           osmo_fsm_inst_state_chg(fi, SGS_UE_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case SGS_UE_E_RX_LU_FROM_MME:</span><br><span style="color: hsl(120, 100%, 40%);">+         osmo_fsm_inst_state_chg(fi, SGS_UE_ST_LA_UPD_PRES, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+             rc = vlr_subscr_req_lu(vsub, vsub->vlr->cfg.is_ps);</span><br><span style="color: hsl(120, 100%, 40%);">+             if (rc != 0)</span><br><span style="color: hsl(120, 100%, 40%);">+                  LOGPFSML(fi, LOGL_ERROR, "(sub %s) HLR LU request failed\n", vlr_subscr_msisdn_or_name(vsub));</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Figure 4.2.2.1 From any of the three states (at the VLR) */</span><br><span style="color: hsl(120, 100%, 40%);">+static void sgs_ue_fsm_allstate(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct vlr_subscr *vsub = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fsm_inst_update_id(fi, vlr_subscr_msisdn_or_name(vsub));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       switch (event) {</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_VLR_FAILURE:</span><br><span style="color: hsl(120, 100%, 40%);">+    case SGS_UE_E_RX_RESET_FROM_MME:</span><br><span style="color: hsl(120, 100%, 40%);">+      case SGS_UE_E_RX_DETACH_IND_FROM_MME:</span><br><span style="color: hsl(120, 100%, 40%);">+ case SGS_UE_E_RX_DETACH_IND_FROM_UE:</span><br><span style="color: hsl(120, 100%, 40%);">+  case SGS_UE_E_RX_LU_FROM_A_IU_GS:</span><br><span style="color: hsl(120, 100%, 40%);">+             osmo_fsm_inst_state_chg(fi, SGS_UE_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(0);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int sgs_ue_fsm_timer_cb(struct osmo_fsm_inst *fi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</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%);">+static const struct osmo_fsm_state sgs_ue_fsm_states[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+    [SGS_UE_ST_NULL] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                      .name = "SGs-NULL",</span><br><span style="color: hsl(120, 100%, 40%);">+                         .action = sgs_ue_fsm_null,</span><br><span style="color: hsl(120, 100%, 40%);">+                            .in_event_mask = S(SGS_UE_E_RX_LU_FROM_MME) |</span><br><span style="color: hsl(120, 100%, 40%);">+                         S(SGS_UE_E_TX_PAGING) | S(SGS_UE_E_RX_PAGING_FAILURE),</span><br><span style="color: hsl(120, 100%, 40%);">+                        .out_state_mask = S(SGS_UE_ST_NULL) | S(SGS_UE_ST_LA_UPD_PRES),</span><br><span style="color: hsl(120, 100%, 40%);">+                       },</span><br><span style="color: hsl(120, 100%, 40%);">+        [SGS_UE_ST_ASSOCIATED] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                              .name = "SGs-ASSOCIATED",</span><br><span style="color: hsl(120, 100%, 40%);">+                           .action = sgs_ue_fsm_associated,</span><br><span style="color: hsl(120, 100%, 40%);">+                              .in_event_mask = S(SGS_UE_E_TX_PAGING) |</span><br><span style="color: hsl(120, 100%, 40%);">+                              S(SGS_UE_E_RX_TMSI_REALLOC) |</span><br><span style="color: hsl(120, 100%, 40%);">+                                 S(SGS_UE_E_RX_SGSAP_UE_UNRECHABLE) |</span><br><span style="color: hsl(120, 100%, 40%);">+                                  S(SGS_UE_E_RX_PAGING_FAILURE) |</span><br><span style="color: hsl(120, 100%, 40%);">+                               S(SGS_UE_E_RX_ALERT_FAILURE) | S(SGS_UE_E_RX_LU_FROM_MME),</span><br><span style="color: hsl(120, 100%, 40%);">+                            .out_state_mask = S(SGS_UE_ST_NULL) |</span><br><span style="color: hsl(120, 100%, 40%);">+                                 S(SGS_UE_ST_ASSOCIATED) | S(SGS_UE_ST_LA_UPD_PRES),</span><br><span style="color: hsl(120, 100%, 40%);">+                           },</span><br><span style="color: hsl(120, 100%, 40%);">+  [SGS_UE_ST_LA_UPD_PRES] = {</span><br><span style="color: hsl(120, 100%, 40%);">+                              .name = "SGs-LA-UPDATE-PRESENT",</span><br><span style="color: hsl(120, 100%, 40%);">+                            .action = sgs_ue_fsm_lau_present,</span><br><span style="color: hsl(120, 100%, 40%);">+                             .in_event_mask = S(SGS_UE_E_TX_LU_ACCEPT) |</span><br><span style="color: hsl(120, 100%, 40%);">+                                   S(SGS_UE_E_TX_LU_REJECT) |</span><br><span style="color: hsl(120, 100%, 40%);">+                            S(SGS_UE_E_TX_PAGING) | S(SGS_UE_E_RX_PAGING_FAILURE) | S(SGS_UE_E_RX_ALERT_FAILURE),</span><br><span style="color: hsl(120, 100%, 40%);">+                                 .out_state_mask = S(SGS_UE_ST_NULL) |</span><br><span style="color: hsl(120, 100%, 40%);">+                                 S(SGS_UE_ST_ASSOCIATED) | S(SGS_UE_ST_LA_UPD_PRES),</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_fsm sgs_ue_fsm = {</span><br><span style="color: hsl(120, 100%, 40%);">+    .name = "SGs-UE",</span><br><span style="color: hsl(120, 100%, 40%);">+   .states = sgs_ue_fsm_states,</span><br><span style="color: hsl(120, 100%, 40%);">+  .num_states = ARRAY_SIZE(sgs_ue_fsm_states),</span><br><span style="color: hsl(120, 100%, 40%);">+  .allstate_event_mask = S(SGS_UE_E_RX_RESET_FROM_MME) |</span><br><span style="color: hsl(120, 100%, 40%);">+            S(SGS_UE_E_VLR_FAILURE) |</span><br><span style="color: hsl(120, 100%, 40%);">+     S(SGS_UE_E_RX_DETACH_IND_FROM_MME) | S(SGS_UE_E_RX_DETACH_IND_FROM_UE) | S(SGS_UE_E_RX_LU_FROM_A_IU_GS),</span><br><span style="color: hsl(120, 100%, 40%);">+  .allstate_action = sgs_ue_fsm_allstate,</span><br><span style="color: hsl(120, 100%, 40%);">+       .timer_cb = sgs_ue_fsm_timer_cb,</span><br><span style="color: hsl(120, 100%, 40%);">+      .log_subsys = DSGS,</span><br><span style="color: hsl(120, 100%, 40%);">+   .event_names = sgs_ue_fsm_event_names,</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%);">+/*! Initalize/Register SGs FSM in osmo-fsm subsystem */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_fsm_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (osmo_fsm_find_by_name(sgs_ue_fsm.name) != &sgs_ue_fsm)</span><br><span style="color: hsl(120, 100%, 40%);">+                osmo_fsm_register(&sgs_ue_fsm);</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%);">+/*! Crate SGs FSM in struct vlr_subscr.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] vsub VLR subscriber for which the SGs FSM should be created. */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_fsm_create(struct vlr_subscr *vsub)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        /* An SGSs FSM must not be created twice! */</span><br><span style="color: hsl(120, 100%, 40%);">+  OSMO_ASSERT(!vsub->sgs_fsm);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     vsub->sgs_fsm = osmo_fsm_inst_alloc(&sgs_ue_fsm, vsub, vsub, LOGL_INFO, vlr_subscr_msisdn_or_name(vsub));</span><br><span style="color: hsl(120, 100%, 40%);">+      OSMO_ASSERT(vsub->sgs_fsm);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fsm_inst_state_chg(vsub->sgs_fsm, SGS_UE_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+//      DEBUGP(DSGS, "(sub %s) SGs FSM created\n", vlr_subscr_msisdn_or_name(vsub));</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%);">+/*! Remove SGs FSM from struct vlr_subscr.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] vsub VLR subscriber from which the SGs FSM should be removed. */</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_fsm_remove(struct vlr_subscr *vsub)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     /* An SGSs FSM must exist! */</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(vsub->sgs_fsm);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fsm_inst_state_chg(vsub->sgs_fsm, SGS_UE_ST_NULL, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fsm_inst_term(vsub->sgs_fsm, OSMO_FSM_TERM_REGULAR, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+    vsub->sgs_fsm = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/libvlr/vlr_sgs_fsm.h b/src/libvlr/vlr_sgs_fsm.h</span><br><span>new file mode 100644</span><br><span>index 0000000..2233ceb</span><br><span>--- /dev/null</span><br><span>+++ b/src/libvlr/vlr_sgs_fsm.h</span><br><span>@@ -0,0 +1,41 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2018 by sysmocom s.f.m.c. GmbH</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Author: Harald Welte, Philipp Maier</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU Affero General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum sgs_ue_fsm_event {</span><br><span style="color: hsl(120, 100%, 40%);">+    SGS_UE_E_VLR_FAILURE,</span><br><span style="color: hsl(120, 100%, 40%);">+ SGS_UE_E_RX_RESET_FROM_MME,</span><br><span style="color: hsl(120, 100%, 40%);">+   SGS_UE_E_RX_DETACH_IND_FROM_MME,</span><br><span style="color: hsl(120, 100%, 40%);">+      SGS_UE_E_RX_DETACH_IND_FROM_UE,</span><br><span style="color: hsl(120, 100%, 40%);">+       SGS_UE_E_RX_LU_FROM_A_IU_GS,</span><br><span style="color: hsl(120, 100%, 40%);">+  SGS_UE_E_RX_PAGING_FAILURE,</span><br><span style="color: hsl(120, 100%, 40%);">+   SGS_UE_E_RX_ALERT_FAILURE,</span><br><span style="color: hsl(120, 100%, 40%);">+    SGS_UE_E_RX_LU_FROM_MME,</span><br><span style="color: hsl(120, 100%, 40%);">+      SGS_UE_E_TX_LU_REJECT,</span><br><span style="color: hsl(120, 100%, 40%);">+        SGS_UE_E_TX_LU_ACCEPT,</span><br><span style="color: hsl(120, 100%, 40%);">+        SGS_UE_E_TX_PAGING,</span><br><span style="color: hsl(120, 100%, 40%);">+   SGS_UE_E_RX_SGSAP_UE_UNRECHABLE,</span><br><span style="color: hsl(120, 100%, 40%);">+      SGS_UE_E_RX_TMSI_REALLOC,</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%);">+void vlr_sgs_fsm_init(void);</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_fsm_create(struct vlr_subscr *vsub);</span><br><span style="color: hsl(120, 100%, 40%);">+void vlr_sgs_fsm_remove(struct vlr_subscr *vsub);</span><br><span>diff --git a/src/osmo-msc/Makefile.am b/src/osmo-msc/Makefile.am</span><br><span>index bcc4ada..abe9ad3 100644</span><br><span>--- a/src/osmo-msc/Makefile.am</span><br><span>+++ b/src/osmo-msc/Makefile.am</span><br><span>@@ -12,6 +12,7 @@</span><br><span>         $(LIBOSMOVTY_CFLAGS) \</span><br><span>       $(LIBOSMOCTRL_CFLAGS) \</span><br><span>      $(LIBOSMOABIS_CFLAGS) \</span><br><span style="color: hsl(120, 100%, 40%);">+       $(LIBOSMONETIF_CFLAGS) \</span><br><span>     $(LIBSMPP34_CFLAGS) \</span><br><span>        $(LIBOSMORANAP_CFLAGS) \</span><br><span>     $(LIBASN1C_CFLAGS) \</span><br><span>@@ -40,11 +41,13 @@</span><br><span>   $(LIBOSMOCORE_LIBS) \</span><br><span>        $(LIBOSMOCTRL_LIBS) \</span><br><span>        $(LIBOSMOABIS_LIBS) \</span><br><span style="color: hsl(120, 100%, 40%);">+ $(LIBOSMONETIF_LIBS) \</span><br><span>       $(LIBSMPP34_LIBS) \</span><br><span>  $(LIBOSMOSIGTRAN_LIBS) \</span><br><span>     $(LIBOSMOMGCPCLIENT_LIBS) \</span><br><span>  $(LIBOSMOGSUPCLIENT_LIBS) \</span><br><span>  -ldbi \</span><br><span style="color: hsl(120, 100%, 40%);">+       -lsctp \</span><br><span>     $(NULL)</span><br><span> if BUILD_IU</span><br><span> osmo_msc_LDADD += \</span><br><span>diff --git a/src/osmo-msc/msc_main.c b/src/osmo-msc/msc_main.c</span><br><span>index 53d27d3..f5bec7d 100644</span><br><span>--- a/src/osmo-msc/msc_main.c</span><br><span>+++ b/src/osmo-msc/msc_main.c</span><br><span>@@ -61,6 +61,7 @@</span><br><span> #include <osmocom/msc/smpp.h></span><br><span> #include <osmocom/sigtran/osmo_ss7.h></span><br><span> #include <osmocom/mgcp_client/mgcp_client.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/msc/sgs_iface.h></span><br><span> </span><br><span> #ifdef BUILD_IU</span><br><span> #include <osmocom/ranap/iu_client.h></span><br><span>@@ -493,6 +494,12 @@</span><br><span>                 .description = "BSSAP Protocol (A Interface)",</span><br><span>             .enabled = 1, .loglevel = LOGL_NOTICE,</span><br><span>       },</span><br><span style="color: hsl(120, 100%, 40%);">+    [DSGS] = {</span><br><span style="color: hsl(120, 100%, 40%);">+            .name = "DSGS",</span><br><span style="color: hsl(120, 100%, 40%);">+             .description = "SGs Interface (SGsAP)",</span><br><span style="color: hsl(120, 100%, 40%);">+             .enabled = 1, .loglevel = LOGL_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+        },</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> </span><br><span> };</span><br><span> </span><br><span>@@ -570,6 +577,7 @@</span><br><span>     if (smpp_openbsc_alloc_init(tall_msc_ctx) < 0)</span><br><span>            return -1;</span><br><span> #endif</span><br><span style="color: hsl(120, 100%, 40%);">+  sgs_init(tall_msc_ctx, msc_network);</span><br><span> </span><br><span>     rc = vty_read_config_file(msc_cmdline_config.config_file, NULL);</span><br><span>     if (rc < 0) {</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_authen_reuse.c b/tests/msc_vlr/msc_vlr_test_authen_reuse.c</span><br><span>index 6591557..cf5d67a 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_authen_reuse.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_authen_reuse.c</span><br><span>@@ -320,3 +320,23 @@</span><br><span>     test_no_auth_reuse_utran,</span><br><span>    NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_call.c b/tests/msc_vlr/msc_vlr_test_call.c</span><br><span>index 5819e51..486aa30 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_call.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_call.c</span><br><span>@@ -588,3 +588,23 @@</span><br><span>      test_call_mo_to_unknown_timeout,</span><br><span>     NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_gsm_authen.c b/tests/msc_vlr/msc_vlr_test_gsm_authen.c</span><br><span>index 8129781..fd5dd10 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_gsm_authen.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_gsm_authen.c</span><br><span>@@ -1003,3 +1003,23 @@</span><br><span>    test_wrong_sres_length,</span><br><span>      NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_gsm_ciph.c b/tests/msc_vlr/msc_vlr_test_gsm_ciph.c</span><br><span>index 8f256b1..b1ea4d0 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_gsm_ciph.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_gsm_ciph.c</span><br><span>@@ -1512,3 +1512,23 @@</span><br><span>    test_cm_service_needs_classmark_update,</span><br><span>      NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_hlr_reject.c b/tests/msc_vlr/msc_vlr_test_hlr_reject.c</span><br><span>index 13bed42..51c7d03 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_hlr_reject.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_hlr_reject.c</span><br><span>@@ -456,3 +456,23 @@</span><br><span>      test_hlr_no_insert_data,</span><br><span>     NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_hlr_timeout.c b/tests/msc_vlr/msc_vlr_test_hlr_timeout.c</span><br><span>index a237695..ae5f154 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_hlr_timeout.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_hlr_timeout.c</span><br><span>@@ -118,3 +118,23 @@</span><br><span>  test_hlr_timeout_lu_upd_loc_result,</span><br><span>  NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_ms_timeout.c b/tests/msc_vlr/msc_vlr_test_ms_timeout.c</span><br><span>index a4851b3..7ea2e79 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_ms_timeout.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_ms_timeout.c</span><br><span>@@ -368,3 +368,23 @@</span><br><span>      test_classmark_update_timeout,</span><br><span>       NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_no_authen.c b/tests/msc_vlr/msc_vlr_test_no_authen.c</span><br><span>index b34ddd7..c3e3cd1 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_no_authen.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_no_authen.c</span><br><span>@@ -983,3 +983,23 @@</span><br><span>  test_no_authen_subscr_expire,</span><br><span>        NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_reject_concurrency.c b/tests/msc_vlr/msc_vlr_test_reject_concurrency.c</span><br><span>index d206571..4af6571 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_reject_concurrency.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_reject_concurrency.c</span><br><span>@@ -404,3 +404,23 @@</span><br><span>      test_reject_paging_resp_during_paging_resp,</span><br><span>  NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_rest.c b/tests/msc_vlr/msc_vlr_test_rest.c</span><br><span>index 247e7ae..7af526f 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_rest.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_rest.c</span><br><span>@@ -203,3 +203,24 @@</span><br><span>      test_lu_unknown_tmsi,</span><br><span>        NULL</span><br><span> };</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%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                             int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_ss.c b/tests/msc_vlr/msc_vlr_test_ss.c</span><br><span>index 34aa634..ab43002 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_ss.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_ss.c</span><br><span>@@ -213,3 +213,23 @@</span><br><span>      test_ss_ussd_no_geran, /* Network-originated */</span><br><span>      NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/msc_vlr/msc_vlr_test_umts_authen.c b/tests/msc_vlr/msc_vlr_test_umts_authen.c</span><br><span>index 62e280e..ffd209a 100644</span><br><span>--- a/tests/msc_vlr/msc_vlr_test_umts_authen.c</span><br><span>+++ b/tests/msc_vlr/msc_vlr_test_umts_authen.c</span><br><span>@@ -880,3 +880,23 @@</span><br><span>  test_umts_authen_only_sres_utran,</span><br><span>    NULL</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                               int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span>diff --git a/tests/sms_queue/sms_queue_test.c b/tests/sms_queue/sms_queue_test.c</span><br><span>index 6ce0b88..5f87c17 100644</span><br><span>--- a/tests/sms_queue/sms_queue_test.c</span><br><span>+++ b/tests/sms_queue/sms_queue_test.c</span><br><span>@@ -236,3 +236,23 @@</span><br><span> </span><br><span>      return 0;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link,</span><br><span style="color: hsl(120, 100%, 40%);">+                                           int fd, int (*cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                              int (*closed_cb)(struct osmo_stream_srv *conn),</span><br><span style="color: hsl(120, 100%, 40%);">+                                               void *data) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto) {}</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay) {}</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)</span><br><span style="color: hsl(120, 100%, 40%);">+                                   (struct osmo_stream_srv_link *link, int fd)) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { return 0; }</span><br><span style="color: hsl(120, 100%, 40%);">+void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return NULL; }</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) {}</span><br><span style="color: hsl(120, 100%, 40%);">+int sctp_recvmsg(int sd, void *msg, size_t len, void *from, void *fromlen, void *info, int *msg_flags) { return 0; }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/11642">change 11642</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/11642"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-msc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I73359925fc1ca72b33a1466e6ac41307f2f0b11d </div>
<div style="display:none"> Gerrit-Change-Number: 11642 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>