aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-01-09 12:29:27 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2023-01-11 12:58:15 +0100
commit58101ea587f725bd79c089b1596a77bffbb152d8 (patch)
tree30f94aaad2e72d445a8fcb96ada8b0dc3df1ea17
parent6aad14c3faf562e9d5172097dcf6ccd4095684f8 (diff)
Split gprs_sgsn.{c,h} -> {auth,mmctx,sgsn}.{c,h}
Some level of split already existed, like sgsn_auth.c, but headers were entangled together. Let's clearly separate application centric code (sgsn.c/h), auth related code (auth.c/h) and mmctx related code (mmctx.c/h). Change-Id: I048a082851c1275c959649942904205b02acce2a
-rw-r--r--include/osmocom/sgsn/Makefile.am3
-rw-r--r--include/osmocom/sgsn/auth.h39
-rw-r--r--include/osmocom/sgsn/gprs_gmm.h8
-rw-r--r--include/osmocom/sgsn/gprs_gmm_fsm.h4
-rw-r--r--include/osmocom/sgsn/gprs_llc.h8
-rw-r--r--include/osmocom/sgsn/gprs_ranap.h4
-rw-r--r--include/osmocom/sgsn/gprs_sm.h5
-rw-r--r--include/osmocom/sgsn/gprs_sndcp.h3
-rw-r--r--include/osmocom/sgsn/mmctx.h (renamed from include/osmocom/sgsn/gprs_sgsn.h)42
-rw-r--r--include/osmocom/sgsn/sgsn.h4
-rw-r--r--src/gprs/gprs_llc_parse.c2
-rw-r--r--src/sgsn/Makefile.am3
-rw-r--r--src/sgsn/gprs_bssgp.c1
-rw-r--r--src/sgsn/gprs_gmm.c2
-rw-r--r--src/sgsn/gprs_gmm_attach.c1
-rw-r--r--src/sgsn/gprs_llc.c2
-rw-r--r--src/sgsn/gprs_mm_state_gb_fsm.c1
-rw-r--r--src/sgsn/gprs_mm_state_iu_fsm.c1
-rw-r--r--src/sgsn/gprs_ns.c1
-rw-r--r--src/sgsn/gprs_ranap.c1
-rw-r--r--src/sgsn/gprs_sm.c1
-rw-r--r--src/sgsn/gprs_sndcp.c1
-rw-r--r--src/sgsn/gprs_subscriber.c2
-rw-r--r--src/sgsn/mmctx.c (renamed from src/sgsn/gprs_sgsn.c)160
-rw-r--r--src/sgsn/pdpctx.c2
-rw-r--r--src/sgsn/sgsn.c214
-rw-r--r--src/sgsn/sgsn_auth.c2
-rw-r--r--src/sgsn/sgsn_cdr.c1
-rw-r--r--src/sgsn/sgsn_ctrl.c2
-rw-r--r--src/sgsn/sgsn_libgtp.c2
-rw-r--r--src/sgsn/sgsn_vty.c2
-rw-r--r--tests/sgsn/Makefile.am3
-rw-r--r--tests/sgsn/gprs_gb_parse.c2
33 files changed, 311 insertions, 218 deletions
diff --git a/include/osmocom/sgsn/Makefile.am b/include/osmocom/sgsn/Makefile.am
index 017954dac..aa6cd0f0f 100644
--- a/include/osmocom/sgsn/Makefile.am
+++ b/include/osmocom/sgsn/Makefile.am
@@ -1,5 +1,6 @@
noinst_HEADERS = \
apn.h \
+ auth.h \
common.h \
crc24.h \
debug.h \
@@ -13,7 +14,6 @@ noinst_HEADERS = \
gprs_llc.h \
gprs_llc_xid.h \
gprs_ranap.h \
- gprs_sgsn.h \
gprs_sm.h \
gprs_sndcp_comp.h \
gprs_sndcp_dcomp.h \
@@ -25,6 +25,7 @@ noinst_HEADERS = \
gtp.h \
gtp_ggsn.h \
gtp_mme.h \
+ mmctx.h \
pdpctx.h \
sgsn.h \
sgsn_rim.h \
diff --git a/include/osmocom/sgsn/auth.h b/include/osmocom/sgsn/auth.h
new file mode 100644
index 000000000..a46fb16bb
--- /dev/null
+++ b/include/osmocom/sgsn/auth.h
@@ -0,0 +1,39 @@
+/* MS authorization and subscriber data handling */
+#pragma once
+
+#include <osmocom/core/linuxlist.h>
+
+struct sgsn_config;
+struct sgsn_instance;
+struct sgsn_mm_ctx;
+struct gsm_auth_tuple;
+
+/* Authorization/ACL handling */
+enum sgsn_auth_state {
+ SGSN_AUTH_UNKNOWN,
+ SGSN_AUTH_AUTHENTICATE,
+ SGSN_AUTH_UMTS_RESYNC,
+ SGSN_AUTH_ACCEPTED,
+ SGSN_AUTH_REJECTED
+};
+
+extern const struct value_string *sgsn_auth_state_names;
+
+void sgsn_auth_init(struct sgsn_instance *sgsn);
+/* Request authorization */
+enum sgsn_auth_state sgsn_auth_state(struct sgsn_mm_ctx *mm);
+int sgsn_auth_request(struct sgsn_mm_ctx *mm);
+void sgsn_auth_update(struct sgsn_mm_ctx *mm);
+struct gsm_auth_tuple *sgsn_auth_get_tuple(struct sgsn_mm_ctx *mmctx,
+ unsigned key_seq);
+
+/*
+ * Authorization/ACL handling
+ */
+struct imsi_acl_entry {
+ struct llist_head list;
+ char imsi[OSMO_IMSI_BUF_SIZE];
+};
+struct imsi_acl_entry *sgsn_acl_lookup(const char *imsi, const struct sgsn_config *cfg);
+int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg);
+int sgsn_acl_del(const char *imsi, struct sgsn_config *cfg);
diff --git a/include/osmocom/sgsn/gprs_gmm.h b/include/osmocom/sgsn/gprs_gmm.h
index 0d04280bf..71dd1fa7f 100644
--- a/include/osmocom/sgsn/gprs_gmm.h
+++ b/include/osmocom/sgsn/gprs_gmm.h
@@ -1,10 +1,14 @@
#ifndef _GPRS_GMM_H
#define _GPRS_GMM_H
+#include <stdbool.h>
+
#include <osmocom/core/msgb.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/gsm/gsm48.h>
+#include <osmocom/crypt/auth.h>
-#include <stdbool.h>
+struct sgsn_mm_ctx;
+struct gprs_llc_llme;
int gsm48_tx_gmm_auth_ciph_req(struct sgsn_mm_ctx *mm,
const struct osmo_auth_vector *vec,
diff --git a/include/osmocom/sgsn/gprs_gmm_fsm.h b/include/osmocom/sgsn/gprs_gmm_fsm.h
index f10851e5c..2f0e81a09 100644
--- a/include/osmocom/sgsn/gprs_gmm_fsm.h
+++ b/include/osmocom/sgsn/gprs_gmm_fsm.h
@@ -1,8 +1,10 @@
#pragma once
#include <osmocom/core/fsm.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
+
+struct gprs_llc_llme;
/* 3GPP TS 24.008 ยง 4.1.3.3 GMM mobility management states on the network side */
enum gmm_fsm_states {
diff --git a/include/osmocom/sgsn/gprs_llc.h b/include/osmocom/sgsn/gprs_llc.h
index 32b16b0d0..6f0e4922f 100644
--- a/include/osmocom/sgsn/gprs_llc.h
+++ b/include/osmocom/sgsn/gprs_llc.h
@@ -2,9 +2,15 @@
#include <stdint.h>
#include <stdbool.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/crypt/gprs_cipher.h>
+
#include <osmocom/sgsn/gprs_llc_xid.h>
+struct sgsn_mm_ctx;
+
/* Section 4.7 LLC Layer Structure */
enum gprs_llc_sapi {
GPRS_SAPI_GMM = 1,
diff --git a/include/osmocom/sgsn/gprs_ranap.h b/include/osmocom/sgsn/gprs_ranap.h
index 62fdf6f2d..68f9115d7 100644
--- a/include/osmocom/sgsn/gprs_ranap.h
+++ b/include/osmocom/sgsn/gprs_ranap.h
@@ -1,13 +1,15 @@
#pragma once
#include <osmocom/core/msgb.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
#ifdef BUILD_IU
#include <osmocom/ranap/ranap_ies_defs.h>
#include <osmocom/ranap/ranap_msg_factory.h>
#include <osmocom/ranap/iu_client.h>
+struct sgsn_mm_ctx;
+struct sgsn_pdp_ctx;
+
void activate_pdp_rabs(struct sgsn_mm_ctx *ctx);
int sgsn_ranap_iu_event(struct ranap_ue_conn_ctx *ctx, enum ranap_iu_event_type type, void *data);
int iu_rab_act_ps(uint8_t rab_id, struct sgsn_pdp_ctx *pdp);
diff --git a/include/osmocom/sgsn/gprs_sm.h b/include/osmocom/sgsn/gprs_sm.h
index 55c95b89d..78bb2d8c3 100644
--- a/include/osmocom/sgsn/gprs_sm.h
+++ b/include/osmocom/sgsn/gprs_sm.h
@@ -1,7 +1,10 @@
#pragma once
#include <osmocom/core/msgb.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+
+struct sgsn_mm_ctx;
+struct sgsn_pdp_ctx;
+struct gprs_llc_llme;
int gsm48_tx_gsm_deact_pdp_req(struct sgsn_pdp_ctx *pdp, uint8_t sm_cause, bool teardown);
int gsm48_tx_gsm_act_pdp_rej(struct sgsn_mm_ctx *mm, uint8_t tid,
diff --git a/include/osmocom/sgsn/gprs_sndcp.h b/include/osmocom/sgsn/gprs_sndcp.h
index b4a0af8d3..30ea05308 100644
--- a/include/osmocom/sgsn/gprs_sndcp.h
+++ b/include/osmocom/sgsn/gprs_sndcp.h
@@ -3,6 +3,9 @@
#include <stdint.h>
#include <osmocom/core/linuxlist.h>
+#include <osmocom/gsm/gsm48.h>
+
+struct gprs_llc_lle;
/* A fragment queue header, maintaining list of fragments for one N-PDU */
struct defrag_state {
diff --git a/include/osmocom/sgsn/gprs_sgsn.h b/include/osmocom/sgsn/mmctx.h
index c9e301d91..dd781244c 100644
--- a/include/osmocom/sgsn/gprs_sgsn.h
+++ b/include/osmocom/sgsn/mmctx.h
@@ -1,5 +1,4 @@
-#ifndef _GPRS_SGSN_H
-#define _GPRS_SGSN_H
+#pragma once
#include <stdint.h>
#include <netinet/in.h>
@@ -15,6 +14,7 @@
#include <osmocom/crypt/auth.h>
#include <osmocom/sgsn/apn.h>
+#include <osmocom/sgsn/auth.h>
#include <osmocom/sgsn/gprs_subscriber.h>
#define GSM_EXTENSION_LENGTH 15
@@ -48,17 +48,6 @@ enum gprs_t3350_mode {
GMM_T3350_MODE_PTMSI_REALL,
};
-/* Authorization/ACL handling */
-enum sgsn_auth_state {
- SGSN_AUTH_UNKNOWN,
- SGSN_AUTH_AUTHENTICATE,
- SGSN_AUTH_UMTS_RESYNC,
- SGSN_AUTH_ACCEPTED,
- SGSN_AUTH_REJECTED
-};
-
-#define MS_RADIO_ACCESS_CAPA
-
enum sgsn_ggsn_lookup_state {
SGSN_GGSN_2DIGIT,
SGSN_GGSN_3DIGIT,
@@ -296,32 +285,5 @@ extern struct llist_head sgsn_mm_ctxts;
uint32_t sgsn_alloc_ptmsi(void);
-/*
- * Authorization/ACL handling
- */
-struct imsi_acl_entry {
- struct llist_head list;
- char imsi[OSMO_IMSI_BUF_SIZE];
-};
-
-#define SGSN_ERROR_CAUSE_NONE (-1)
-
-struct sgsn_config;
-struct sgsn_instance;
-extern const struct value_string *sgsn_auth_state_names;
-
-void sgsn_auth_init(struct sgsn_instance *sgsn);
-struct imsi_acl_entry *sgsn_acl_lookup(const char *imsi, const struct sgsn_config *cfg);
-int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg);
-int sgsn_acl_del(const char *imsi, struct sgsn_config *cfg);
-/* Request authorization */
-int sgsn_auth_request(struct sgsn_mm_ctx *mm);
-enum sgsn_auth_state sgsn_auth_state(struct sgsn_mm_ctx *mm);
-void sgsn_auth_update(struct sgsn_mm_ctx *mm);
-struct gsm_auth_tuple *sgsn_auth_get_tuple(struct sgsn_mm_ctx *mmctx,
- unsigned key_seq);
-
/* Called on subscriber data updates */
void sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx);
-
-#endif /* _GPRS_SGSN_H */
diff --git a/include/osmocom/sgsn/sgsn.h b/include/osmocom/sgsn/sgsn.h
index aadb8a75a..0963863c7 100644
--- a/include/osmocom/sgsn/sgsn.h
+++ b/include/osmocom/sgsn/sgsn.h
@@ -8,7 +8,7 @@
#include <osmocom/gprs/gprs_ns2.h>
#include <osmocom/gprs/gprs_bssgp.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/auth.h>
#include <osmocom/sgsn/gtp_mme.h>
#include <osmocom/gsm/oap_client.h>
#include <osmocom/gsupclient/gsup_client.h>
@@ -25,6 +25,8 @@
struct hostent;
+#define SGSN_ERROR_CAUSE_NONE (-1)
+
enum sgsn_auth_policy {
SGSN_AUTH_POLICY_OPEN,
SGSN_AUTH_POLICY_CLOSED,
diff --git a/src/gprs/gprs_llc_parse.c b/src/gprs/gprs_llc_parse.c
index e400e25a2..d099cdaf3 100644
--- a/src/gprs/gprs_llc_parse.c
+++ b/src/gprs/gprs_llc_parse.c
@@ -29,7 +29,7 @@
#include <osmocom/gprs/gprs_bssgp.h>
#include <osmocom/sgsn/debug.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_llc.h>
#include <osmocom/sgsn/crc24.h>
diff --git a/src/sgsn/Makefile.am b/src/sgsn/Makefile.am
index 75f96082b..93b9fa058 100644
--- a/src/sgsn/Makefile.am
+++ b/src/sgsn/Makefile.am
@@ -47,7 +47,6 @@ osmo_sgsn_SOURCES = \
gprs_gmm_fsm.c \
gprs_mm_state_gb_fsm.c \
gprs_ns.c \
- gprs_sgsn.c \
gprs_sm.c \
gprs_sndcp.c \
gprs_sndcp_comp.c \
@@ -57,11 +56,13 @@ osmo_sgsn_SOURCES = \
gprs_sndcp_xid.c \
gtp_ggsn.c \
gtp_mme.c \
+ sgsn.c \
sgsn_main.c \
sgsn_vty.c \
sgsn_libgtp.c \
gprs_llc.c \
gprs_llc_vty.c \
+ mmctx.c \
pdpctx.c \
sgsn_ctrl.c \
sgsn_auth.c \
diff --git a/src/sgsn/gprs_bssgp.c b/src/sgsn/gprs_bssgp.c
index d6bd25f9d..5db751cce 100644
--- a/src/sgsn/gprs_bssgp.c
+++ b/src/sgsn/gprs_bssgp.c
@@ -29,6 +29,7 @@
#include <osmocom/sgsn/gprs_llc.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/sgsn_rim.h>
+#include <osmocom/sgsn/mmctx.h>
/* call-back function for the BSSGP protocol */
int sgsn_bssgp_rx_prim(struct osmo_prim_hdr *oph)
diff --git a/src/sgsn/gprs_gmm.c b/src/sgsn/gprs_gmm.c
index 2f15c92d0..5bf66c3a7 100644
--- a/src/sgsn/gprs_gmm.c
+++ b/src/sgsn/gprs_gmm.c
@@ -48,7 +48,7 @@
#include <osmocom/sgsn/debug.h>
#include <osmocom/sgsn/gprs_llc.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_utils.h>
#include <osmocom/sgsn/gprs_subscriber.h>
diff --git a/src/sgsn/gprs_gmm_attach.c b/src/sgsn/gprs_gmm_attach.c
index 59417dfaa..708ea8f23 100644
--- a/src/sgsn/gprs_gmm_attach.c
+++ b/src/sgsn/gprs_gmm_attach.c
@@ -6,6 +6,7 @@
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/sgsn/debug.h>
#include <osmocom/sgsn/gprs_gmm.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/sgsn.h>
#define X(s) (1 << (s))
diff --git a/src/sgsn/gprs_llc.c b/src/sgsn/gprs_llc.c
index 302e01861..6f563851f 100644
--- a/src/sgsn/gprs_llc.c
+++ b/src/sgsn/gprs_llc.c
@@ -33,7 +33,7 @@
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/sgsn/debug.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_llc.h>
#include <osmocom/sgsn/crc24.h>
diff --git a/src/sgsn/gprs_mm_state_gb_fsm.c b/src/sgsn/gprs_mm_state_gb_fsm.c
index 6e812d31d..5a007e972 100644
--- a/src/sgsn/gprs_mm_state_gb_fsm.c
+++ b/src/sgsn/gprs_mm_state_gb_fsm.c
@@ -27,6 +27,7 @@
#include <osmocom/sgsn/debug.h>
#include <osmocom/sgsn/sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#define X(s) (1 << (s))
diff --git a/src/sgsn/gprs_mm_state_iu_fsm.c b/src/sgsn/gprs_mm_state_iu_fsm.c
index 597507c7d..5ac009765 100644
--- a/src/sgsn/gprs_mm_state_iu_fsm.c
+++ b/src/sgsn/gprs_mm_state_iu_fsm.c
@@ -31,6 +31,7 @@
#include <osmocom/sgsn/gprs_ranap.h>
#include <osmocom/sgsn/gtp.h>
#include <osmocom/sgsn/pdpctx.h>
+#include <osmocom/sgsn/mmctx.h>
#define X(s) (1 << (s))
diff --git a/src/sgsn/gprs_ns.c b/src/sgsn/gprs_ns.c
index e2ff931af..eb447facd 100644
--- a/src/sgsn/gprs_ns.c
+++ b/src/sgsn/gprs_ns.c
@@ -31,7 +31,6 @@
#include "config.h"
-#include <osmocom/sgsn/gprs_sgsn.h>
#include <osmocom/sgsn/debug.h>
void gprs_ns_prim_status_cb(struct osmo_gprs_ns2_prim *nsp)
diff --git a/src/sgsn/gprs_ranap.c b/src/sgsn/gprs_ranap.c
index d3d958d74..5e0d8edc6 100644
--- a/src/sgsn/gprs_ranap.c
+++ b/src/sgsn/gprs_ranap.c
@@ -40,6 +40,7 @@
#include <osmocom/sgsn/gtp_ggsn.h>
#include <osmocom/sgsn/gtp.h>
#include <osmocom/sgsn/pdpctx.h>
+#include <osmocom/sgsn/mmctx.h>
/* Send RAB activation requests for all PDP contexts */
void activate_pdp_rabs(struct sgsn_mm_ctx *ctx)
diff --git a/src/sgsn/gprs_sm.c b/src/sgsn/gprs_sm.c
index 3a5ba3b99..1194f31a7 100644
--- a/src/sgsn/gprs_sm.c
+++ b/src/sgsn/gprs_sm.c
@@ -44,6 +44,7 @@
#include <osmocom/sgsn/gprs_ranap.h>
#include <osmocom/sgsn/gtp.h>
#include <osmocom/sgsn/pdpctx.h>
+#include <osmocom/sgsn/mmctx.h>
/* 3GPP TS 04.08 sec 6.1.3.4.3(.a) "Abnormal cases" */
#define T339X_MAX_RETRANS 4
diff --git a/src/sgsn/gprs_sndcp.c b/src/sgsn/gprs_sndcp.c
index 6707c2863..36e808f3b 100644
--- a/src/sgsn/gprs_sndcp.c
+++ b/src/sgsn/gprs_sndcp.c
@@ -42,6 +42,7 @@
#include <osmocom/sgsn/gprs_sndcp_dcomp.h>
#include <osmocom/sgsn/gprs_sndcp_comp.h>
#include <osmocom/sgsn/gprs_gmm.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gtp.h>
#define DEBUG_IP_PACKETS 0 /* 0=Disabled, 1=Enabled */
diff --git a/src/sgsn/gprs_subscriber.c b/src/sgsn/gprs_subscriber.c
index 416e6a408..460450c1e 100644
--- a/src/sgsn/gprs_subscriber.c
+++ b/src/sgsn/gprs_subscriber.c
@@ -30,7 +30,7 @@
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/sgsn/sgsn.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_utils.h>
diff --git a/src/sgsn/gprs_sgsn.c b/src/sgsn/mmctx.c
index 55e1cb205..c40db219e 100644
--- a/src/sgsn/gprs_sgsn.c
+++ b/src/sgsn/mmctx.c
@@ -1,4 +1,4 @@
-/* GPRS SGSN functionality */
+/* Mobility Management context */
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
*
@@ -38,7 +38,7 @@
#include <osmocom/sgsn/gprs_subscriber.h>
#include <osmocom/sgsn/debug.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/sgsn.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_sm.h>
@@ -60,10 +60,6 @@
#include "../../config.h"
-#define GPRS_LLME_CHECK_TICK 30
-
-extern struct osmo_tdef sgsn_T_defs[];
-
LLIST_HEAD(sgsn_mm_ctxts);
const struct value_string sgsn_ran_type_names[] = {
@@ -97,40 +93,6 @@ static const struct rate_ctr_group_desc mmctx_ctrg_desc = {
.class_id = OSMO_STATS_CLASS_SUBSCRIBER,
};
-static const struct rate_ctr_desc sgsn_ctr_description[] = {
- { "llc:dl_bytes", "Count sent LLC bytes before giving it to the bssgp layer" },
- { "llc:ul_bytes", "Count successful received LLC bytes (encrypt & fcs correct)" },
- { "llc:dl_packets", "Count successful sent LLC packets before giving it to the bssgp layer" },
- { "llc:ul_packets", "Count successful received LLC packets (encrypt & fcs correct)" },
- { "gprs:attach_requested", "Received attach requests" },
- { "gprs:attach_accepted", "Sent attach accepts" },
- { "gprs:attach_rejected", "Sent attach rejects" },
- { "gprs:detach_requested", "Received detach requests" },
- { "gprs:detach_acked", "Sent detach acks" },
- { "gprs:routing_area_requested", "Received routing area requests" },
- { "gprs:routing_area_requested", "Sent routing area acks" },
- { "gprs:routing_area_requested", "Sent routing area rejects" },
- { "pdp:activate_requested", "Received activate requests" },
- { "pdp:activate_rejected", "Sent activate rejects" },
- { "pdp:activate_accepted", "Sent activate accepts" },
- { "pdp:request_activated", "unused" },
- { "pdp:request_activate_rejected", "unused" },
- { "pdp:modify_requested", "unused" },
- { "pdp:modify_accepted", "unused" },
- { "pdp:dl_deactivate_requested", "Sent deactivate requests" },
- { "pdp:dl_deactivate_accepted", "Sent deactivate accepted" },
- { "pdp:ul_deactivate_requested", "Received deactivate requests" },
- { "pdp:ul_deactivate_accepted", "Received deactivate accepts" },
-};
-
-static const struct rate_ctr_group_desc sgsn_ctrg_desc = {
- "sgsn",
- "SGSN Overall Statistics",
- OSMO_STATS_CLASS_GLOBAL,
- ARRAY_SIZE(sgsn_ctr_description),
- sgsn_ctr_description,
-};
-
/* look-up an SGSN MM context based on Iu UE context (struct ue_conn_ctx)*/
struct sgsn_mm_ctx *sgsn_mm_ctx_by_ue_ctx(const void *uectx)
{
@@ -622,121 +584,3 @@ struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
return ggsn;
}
-
-static void sgsn_llme_cleanup_free(struct gprs_llc_llme *llme)
-{
- struct sgsn_mm_ctx *mmctx = NULL;
-
- llist_for_each_entry(mmctx, &sgsn_mm_ctxts, list) {
- if (llme == mmctx->gb.llme) {
- gsm0408_gprs_access_cancelled(mmctx, SGSN_ERROR_CAUSE_NONE);
- return;
- }
- }
-
- /* No MM context found */
- LOGP(DGPRS, LOGL_INFO, "Deleting orphaned LLME, TLLI 0x%08x\n",
- llme->tlli);
- gprs_llgmm_unassign(llme);
-}
-
-static void sgsn_llme_check_cb(void *data_)
-{
- struct gprs_llc_llme *llme, *llme_tmp;
- struct timespec now_tp;
- time_t now, age;
- time_t max_age = gprs_max_time_to_idle();
-
- int rc;
-
- rc = osmo_clock_gettime(CLOCK_MONOTONIC, &now_tp);
- OSMO_ASSERT(rc >= 0);
- now = now_tp.tv_sec;
-
- LOGP(DGPRS, LOGL_DEBUG,
- "Checking for inactive LLMEs, time = %u\n", (unsigned)now);
-
- llist_for_each_entry_safe(llme, llme_tmp, &gprs_llc_llmes, list) {
- if (llme->age_timestamp == GPRS_LLME_RESET_AGE)
- llme->age_timestamp = now;
-
- age = now - llme->age_timestamp;
-
- if (age > max_age || age < 0) {
- LOGP(DGPRS, LOGL_INFO,
- "Inactivity timeout for TLLI 0x%08x, age %d\n",
- llme->tlli, (int)age);
- sgsn_llme_cleanup_free(llme);
- }
- }
-
- osmo_timer_schedule(&sgsn->llme_timer, GPRS_LLME_CHECK_TICK, 0);
-}
-
-static int sgsn_instance_talloc_destructor(struct sgsn_instance *sgi)
-{
- sgsn_cdr_release(sgi);
- osmo_timer_del(&sgi->llme_timer);
- rate_ctr_group_free(sgi->rate_ctrs);
- return 0;
-}
-
-struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx)
-{
- struct sgsn_instance *inst;
- inst = talloc_zero(talloc_ctx, struct sgsn_instance);
-
- talloc_set_destructor(inst, sgsn_instance_talloc_destructor);
-
- inst->cfg.gtp_statedir = talloc_strdup(inst, "./");
- inst->cfg.auth_policy = SGSN_AUTH_POLICY_CLOSED;
- inst->cfg.require_authentication = true; /* only applies if auth_policy is REMOTE */
- inst->cfg.gsup_server_port = OSMO_GSUP_PORT;
-
- inst->cfg.T_defs = sgsn_T_defs;
- osmo_tdefs_reset(inst->cfg.T_defs);
- inst->cfg.T_defs_gtp = gtp_T_defs;
- osmo_tdefs_reset(inst->cfg.T_defs_gtp);
-
- inst->rate_ctrs = rate_ctr_group_alloc(inst, &sgsn_ctrg_desc, 0);
- OSMO_ASSERT(inst->rate_ctrs);
-
- INIT_LLIST_HEAD(&inst->apn_list);
- INIT_LLIST_HEAD(&inst->ggsn_list);
- INIT_LLIST_HEAD(&inst->mme_list);
- INIT_LLIST_HEAD(&inst->pdp_list);
-
- osmo_timer_setup(&inst->llme_timer, sgsn_llme_check_cb, NULL);
- osmo_timer_schedule(&inst->llme_timer, GPRS_LLME_CHECK_TICK, 0);
- /* These are mostly setting up stuff not related to VTY cfg, so they can be set up here: */
- sgsn_auth_init(inst);
- sgsn_cdr_init(inst);
- return inst;
-}
-
-/* To be called after VTY config parsing: */
-int sgsn_inst_init(struct sgsn_instance *sgsn)
-{
- int rc;
-
- /* start control interface after reading config for
- * ctrl_vty_get_bind_addr() */
- sgsn->ctrlh = ctrl_interface_setup(NULL, OSMO_CTRL_PORT_SGSN, NULL);
- if (!sgsn->ctrlh) {
- LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
- return -EIO;
- }
-
- rc = sgsn_ctrl_cmds_install();
- if (rc != 0) {
- LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
- return -EFAULT;
- }
-
- rc = gprs_subscr_init(sgsn);
- if (rc < 0) {
- LOGP(DGPRS, LOGL_FATAL, "Cannot set up SGSN\n");
- return rc;
- }
- return 0;
-}
diff --git a/src/sgsn/pdpctx.c b/src/sgsn/pdpctx.c
index 77146fc76..70fba208e 100644
--- a/src/sgsn/pdpctx.c
+++ b/src/sgsn/pdpctx.c
@@ -28,7 +28,7 @@
#include <osmocom/core/stats.h>
#include <osmocom/sgsn/pdpctx.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/sgsn.h>
#include <osmocom/sgsn/debug.h>
#include <osmocom/sgsn/signal.h>
diff --git a/src/sgsn/sgsn.c b/src/sgsn/sgsn.c
new file mode 100644
index 000000000..f394db8b7
--- /dev/null
+++ b/src/sgsn/sgsn.c
@@ -0,0 +1,214 @@
+/* SGSN instance */
+
+/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdint.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/timer.h>
+#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/stats.h>
+#include <osmocom/core/backtrace.h>
+#include <osmocom/ctrl/control_if.h>
+#include <osmocom/ctrl/ports.h>
+#include <osmocom/gprs/gprs_ns2.h>
+#include <osmocom/gprs/gprs_bssgp.h>
+#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
+#include <osmocom/gsm/apn.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/gsup.h>
+
+#include <osmocom/sgsn/gprs_subscriber.h>
+#include <osmocom/sgsn/debug.h>
+#include <osmocom/sgsn/sgsn.h>
+#include <osmocom/sgsn/gprs_gmm.h>
+#include <osmocom/sgsn/gprs_sm.h>
+#include <osmocom/sgsn/gprs_utils.h>
+#include <osmocom/sgsn/signal.h>
+#include <osmocom/sgsn/gprs_gmm_attach.h>
+#include <osmocom/sgsn/gprs_mm_state_gb_fsm.h>
+#include <osmocom/sgsn/gprs_mm_state_iu_fsm.h>
+#include <osmocom/sgsn/gprs_gmm_fsm.h>
+#include <osmocom/sgsn/gprs_llc.h>
+#include <osmocom/sgsn/gprs_sndcp.h>
+#include <osmocom/sgsn/gtp_ggsn.h>
+#include <osmocom/sgsn/gtp.h>
+#include <osmocom/sgsn/pdpctx.h>
+
+#include <pdp.h>
+
+#include <time.h>
+
+#define GPRS_LLME_CHECK_TICK 30
+
+extern struct osmo_tdef sgsn_T_defs[];
+
+static const struct rate_ctr_desc sgsn_ctr_description[] = {
+ { "llc:dl_bytes", "Count sent LLC bytes before giving it to the bssgp layer" },
+ { "llc:ul_bytes", "Count successful received LLC bytes (encrypt & fcs correct)" },
+ { "llc:dl_packets", "Count successful sent LLC packets before giving it to the bssgp layer" },
+ { "llc:ul_packets", "Count successful received LLC packets (encrypt & fcs correct)" },
+ { "gprs:attach_requested", "Received attach requests" },
+ { "gprs:attach_accepted", "Sent attach accepts" },
+ { "gprs:attach_rejected", "Sent attach rejects" },
+ { "gprs:detach_requested", "Received detach requests" },
+ { "gprs:detach_acked", "Sent detach acks" },
+ { "gprs:routing_area_requested", "Received routing area requests" },
+ { "gprs:routing_area_requested", "Sent routing area acks" },
+ { "gprs:routing_area_requested", "Sent routing area rejects" },
+ { "pdp:activate_requested", "Received activate requests" },
+ { "pdp:activate_rejected", "Sent activate rejects" },
+ { "pdp:activate_accepted", "Sent activate accepts" },
+ { "pdp:request_activated", "unused" },
+ { "pdp:request_activate_rejected", "unused" },
+ { "pdp:modify_requested", "unused" },
+ { "pdp:modify_accepted", "unused" },
+ { "pdp:dl_deactivate_requested", "Sent deactivate requests" },
+ { "pdp:dl_deactivate_accepted", "Sent deactivate accepted" },
+ { "pdp:ul_deactivate_requested", "Received deactivate requests" },
+ { "pdp:ul_deactivate_accepted", "Received deactivate accepts" },
+};
+
+static const struct rate_ctr_group_desc sgsn_ctrg_desc = {
+ "sgsn",
+ "SGSN Overall Statistics",
+ OSMO_STATS_CLASS_GLOBAL,
+ ARRAY_SIZE(sgsn_ctr_description),
+ sgsn_ctr_description,
+};
+
+static void sgsn_llme_cleanup_free(struct gprs_llc_llme *llme)
+{
+ struct sgsn_mm_ctx *mmctx = NULL;
+
+ llist_for_each_entry(mmctx, &sgsn_mm_ctxts, list) {
+ if (llme == mmctx->gb.llme) {
+ gsm0408_gprs_access_cancelled(mmctx, SGSN_ERROR_CAUSE_NONE);
+ return;
+ }
+ }
+
+ /* No MM context found */
+ LOGP(DGPRS, LOGL_INFO, "Deleting orphaned LLME, TLLI 0x%08x\n",
+ llme->tlli);
+ gprs_llgmm_unassign(llme);
+}
+
+static void sgsn_llme_check_cb(void *data_)
+{
+ struct gprs_llc_llme *llme, *llme_tmp;
+ struct timespec now_tp;
+ time_t now, age;
+ time_t max_age = gprs_max_time_to_idle();
+
+ int rc;
+
+ rc = osmo_clock_gettime(CLOCK_MONOTONIC, &now_tp);
+ OSMO_ASSERT(rc >= 0);
+ now = now_tp.tv_sec;
+
+ LOGP(DGPRS, LOGL_DEBUG,
+ "Checking for inactive LLMEs, time = %u\n", (unsigned)now);
+
+ llist_for_each_entry_safe(llme, llme_tmp, &gprs_llc_llmes, list) {
+ if (llme->age_timestamp == GPRS_LLME_RESET_AGE)
+ llme->age_timestamp = now;
+
+ age = now - llme->age_timestamp;
+
+ if (age > max_age || age < 0) {
+ LOGP(DGPRS, LOGL_INFO,
+ "Inactivity timeout for TLLI 0x%08x, age %d\n",
+ llme->tlli, (int)age);
+ sgsn_llme_cleanup_free(llme);
+ }
+ }
+
+ osmo_timer_schedule(&sgsn->llme_timer, GPRS_LLME_CHECK_TICK, 0);
+}
+
+static int sgsn_instance_talloc_destructor(struct sgsn_instance *sgi)
+{
+ sgsn_cdr_release(sgi);
+ osmo_timer_del(&sgi->llme_timer);
+ rate_ctr_group_free(sgi->rate_ctrs);
+ return 0;
+}
+
+struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx)
+{
+ struct sgsn_instance *inst;
+ inst = talloc_zero(talloc_ctx, struct sgsn_instance);
+
+ talloc_set_destructor(inst, sgsn_instance_talloc_destructor);
+
+ inst->cfg.gtp_statedir = talloc_strdup(inst, "./");
+ inst->cfg.auth_policy = SGSN_AUTH_POLICY_CLOSED;
+ inst->cfg.require_authentication = true; /* only applies if auth_policy is REMOTE */
+ inst->cfg.gsup_server_port = OSMO_GSUP_PORT;
+
+ inst->cfg.T_defs = sgsn_T_defs;
+ osmo_tdefs_reset(inst->cfg.T_defs);
+ inst->cfg.T_defs_gtp = gtp_T_defs;
+ osmo_tdefs_reset(inst->cfg.T_defs_gtp);
+
+ inst->rate_ctrs = rate_ctr_group_alloc(inst, &sgsn_ctrg_desc, 0);
+ OSMO_ASSERT(inst->rate_ctrs);
+
+ INIT_LLIST_HEAD(&inst->apn_list);
+ INIT_LLIST_HEAD(&inst->ggsn_list);
+ INIT_LLIST_HEAD(&inst->mme_list);
+ INIT_LLIST_HEAD(&inst->pdp_list);
+
+ osmo_timer_setup(&inst->llme_timer, sgsn_llme_check_cb, NULL);
+ osmo_timer_schedule(&inst->llme_timer, GPRS_LLME_CHECK_TICK, 0);
+ /* These are mostly setting up stuff not related to VTY cfg, so they can be set up here: */
+ sgsn_auth_init(inst);
+ sgsn_cdr_init(inst);
+ return inst;
+}
+
+/* To be called after VTY config parsing: */
+int sgsn_inst_init(struct sgsn_instance *sgsn)
+{
+ int rc;
+
+ /* start control interface after reading config for
+ * ctrl_vty_get_bind_addr() */
+ sgsn->ctrlh = ctrl_interface_setup(NULL, OSMO_CTRL_PORT_SGSN, NULL);
+ if (!sgsn->ctrlh) {
+ LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
+ return -EIO;
+ }
+
+ rc = sgsn_ctrl_cmds_install();
+ if (rc != 0) {
+ LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
+ return -EFAULT;
+ }
+
+ rc = gprs_subscr_init(sgsn);
+ if (rc < 0) {
+ LOGP(DGPRS, LOGL_FATAL, "Cannot set up SGSN\n");
+ return rc;
+ }
+ return 0;
+}
diff --git a/src/sgsn/sgsn_auth.c b/src/sgsn/sgsn_auth.c
index b8d803590..cbff6f8ba 100644
--- a/src/sgsn/sgsn_auth.c
+++ b/src/sgsn/sgsn_auth.c
@@ -22,7 +22,7 @@
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/core/utils.h>
#include <osmocom/sgsn/sgsn.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_subscriber.h>
#include <osmocom/sgsn/debug.h>
diff --git a/src/sgsn/sgsn_cdr.c b/src/sgsn/sgsn_cdr.c
index db326448c..1536c135a 100644
--- a/src/sgsn/sgsn_cdr.c
+++ b/src/sgsn/sgsn_cdr.c
@@ -29,6 +29,7 @@
#include <osmocom/sgsn/vty.h>
#include <osmocom/sgsn/gtp_ggsn.h>
#include <osmocom/sgsn/pdpctx.h>
+#include <osmocom/sgsn/mmctx.h>
#include <gtp.h>
#include <pdp.h>
diff --git a/src/sgsn/sgsn_ctrl.c b/src/sgsn/sgsn_ctrl.c
index 8961f3725..15c15ceb7 100644
--- a/src/sgsn/sgsn_ctrl.c
+++ b/src/sgsn/sgsn_ctrl.c
@@ -21,7 +21,7 @@
#include <osmocom/ctrl/control_if.h>
#include <osmocom/ctrl/control_cmd.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/pdpctx.h>
#include <osmocom/sgsn/sgsn.h>
#include <osmocom/sgsn/debug.h>
diff --git a/src/sgsn/sgsn_libgtp.c b/src/sgsn/sgsn_libgtp.c
index e2d567028..7c08e6fce 100644
--- a/src/sgsn/sgsn_libgtp.c
+++ b/src/sgsn/sgsn_libgtp.c
@@ -47,7 +47,7 @@
#include <osmocom/sgsn/sgsn.h>
#include <osmocom/sgsn/gprs_ns.h>
#include <osmocom/sgsn/gprs_llc.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_sm.h>
#include <osmocom/sgsn/gprs_subscriber.h>
diff --git a/src/sgsn/sgsn_vty.c b/src/sgsn/sgsn_vty.c
index fa62561e6..4a1d085e3 100644
--- a/src/sgsn/sgsn_vty.c
+++ b/src/sgsn/sgsn_vty.c
@@ -38,7 +38,7 @@
#include <osmocom/sgsn/gprs_ns.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_bssgp.h>
-#include <osmocom/sgsn/gprs_sgsn.h>
+#include <osmocom/sgsn/mmctx.h>
#include <osmocom/sgsn/gtp_ggsn.h>
#include <osmocom/sgsn/gtp_mme.h>
#include <osmocom/sgsn/vty.h>
diff --git a/tests/sgsn/Makefile.am b/tests/sgsn/Makefile.am
index 8df1395ce..d22a8d91f 100644
--- a/tests/sgsn/Makefile.am
+++ b/tests/sgsn/Makefile.am
@@ -57,10 +57,11 @@ sgsn_test_LDADD = \
$(top_builddir)/src/sgsn/gprs_gmm.o \
$(top_builddir)/src/sgsn/gprs_gmm_fsm.o \
$(top_builddir)/src/sgsn/gprs_mm_state_gb_fsm.o \
- $(top_builddir)/src/sgsn/gprs_sgsn.o \
$(top_builddir)/src/sgsn/gtp_ggsn.o \
$(top_builddir)/src/sgsn/gtp_mme.o \
+ $(top_builddir)/src/sgsn/mmctx.o \
$(top_builddir)/src/sgsn/pdpctx.o \
+ $(top_builddir)/src/sgsn/sgsn.o \
$(top_builddir)/src/sgsn/sgsn_cdr.o \
$(top_builddir)/src/sgsn/sgsn_ctrl.o \
$(top_builddir)/src/sgsn/sgsn_vty.o \
diff --git a/tests/sgsn/gprs_gb_parse.c b/tests/sgsn/gprs_gb_parse.c
index 3338911db..670839f73 100644
--- a/tests/sgsn/gprs_gb_parse.c
+++ b/tests/sgsn/gprs_gb_parse.c
@@ -18,6 +18,8 @@
*
*/
+#include <arpa/inet.h>
+
#include <osmocom/gsm/gsm48.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>