blob: 8b9a00e160f66487d399af7c5e11f5dad05d5940 [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001#ifndef _GPRS_SGSN_H
2#define _GPRS_SGSN_H
3
Harald Welteeaa614c2010-05-02 11:26:34 +02004#include <stdint.h>
Harald Welted193cb32010-05-17 22:58:03 +02005#include <netinet/in.h>
Pau Espin Pedrol6ec5dc22019-08-28 16:52:56 +02006#include <inttypes.h>
Harald Welted193cb32010-05-17 22:58:03 +02007
Alexander Couzensf7198d72018-05-22 18:29:14 +02008#include <osmocom/core/fsm.h>
Holger Hans Peter Freyther26d0fe32012-01-06 17:29:06 +01009#include <osmocom/core/timer.h>
10
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010011#include <osmocom/gsm/gsm48.h>
Harald Welteeaa614c2010-05-02 11:26:34 +020012
Harald Welte496aee42010-06-30 19:59:55 +020013#include <osmocom/crypt/gprs_cipher.h>
Harald Welted3fa84d2016-04-20 17:50:17 +020014#include <osmocom/gsm/protocol/gsm_23_003.h>
Neels Hofmeyree6cfdc2017-07-13 02:03:50 +020015#include <osmocom/crypt/auth.h>
Jacob Erlbeckbd0cf112014-12-01 12:33:33 +010016
Pau Espin Pedrolc1cf4af2023-01-05 15:43:00 +010017#include <osmocom/sgsn/gprs_subscriber.h>
18
Harald Welte2720e732010-05-17 00:44:57 +020019#define GSM_EXTENSION_LENGTH 15
Jacob Erlbeck0e8add62014-12-17 14:03:35 +010020#define GSM_APN_LENGTH 102
Harald Welte2720e732010-05-17 00:44:57 +020021
Harald Welte807a5d82010-06-01 11:53:01 +020022struct gprs_llc_lle;
Holger Hans Peter Freythera2730302014-03-23 18:08:26 +010023struct ctrl_handle;
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010024struct gprs_subscr;
Pau Espin Pedrol5f4736a2023-01-04 21:30:28 +010025struct sgsn_ggsn_ctx;
Harald Welte807a5d82010-06-01 11:53:01 +020026
Jacob Erlbeck277b71e2015-02-02 18:03:05 +010027enum gsm48_gsm_cause;
28
Harald Weltec2e8cc42010-05-31 20:23:38 +020029enum gprs_mm_ctr {
Harald Welte8acd88f2010-05-18 10:57:45 +020030 GMM_CTR_PKTS_SIG_IN,
31 GMM_CTR_PKTS_SIG_OUT,
32 GMM_CTR_PKTS_UDATA_IN,
33 GMM_CTR_PKTS_UDATA_OUT,
34 GMM_CTR_BYTES_UDATA_IN,
35 GMM_CTR_BYTES_UDATA_OUT,
36 GMM_CTR_PDP_CTX_ACT,
37 GMM_CTR_SUSPEND,
38 GMM_CTR_PAGING_PS,
39 GMM_CTR_PAGING_CS,
40 GMM_CTR_RA_UPDATE,
41};
42
Harald Welteefbdee92010-06-10 00:20:12 +020043enum gprs_pdp_ctx {
44 PDP_CTR_PKTS_UDATA_IN,
45 PDP_CTR_PKTS_UDATA_OUT,
46 PDP_CTR_BYTES_UDATA_IN,
47 PDP_CTR_BYTES_UDATA_OUT,
48};
49
Harald Weltec2e8cc42010-05-31 20:23:38 +020050enum gprs_t3350_mode {
Jacob Erlbeck93eae8e2014-10-28 12:23:29 +010051 GMM_T3350_MODE_NONE,
Harald Weltec2e8cc42010-05-31 20:23:38 +020052 GMM_T3350_MODE_ATT,
53 GMM_T3350_MODE_RAU,
54 GMM_T3350_MODE_PTMSI_REALL,
55};
56
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +020057/* Authorization/ACL handling */
58enum sgsn_auth_state {
59 SGSN_AUTH_UNKNOWN,
Jacob Erlbeck4adb1362014-12-02 09:47:26 +010060 SGSN_AUTH_AUTHENTICATE,
Neels Hofmeyr058cd572017-02-24 06:24:45 +010061 SGSN_AUTH_UMTS_RESYNC,
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +020062 SGSN_AUTH_ACCEPTED,
63 SGSN_AUTH_REJECTED
64};
65
Harald Welte9b455bf2010-03-14 15:45:01 +080066#define MS_RADIO_ACCESS_CAPA
67
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080068enum sgsn_ggsn_lookup_state {
69 SGSN_GGSN_2DIGIT,
70 SGSN_GGSN_3DIGIT,
71};
72
73struct sgsn_ggsn_lookup {
74 int state;
75
76 struct sgsn_mm_ctx *mmctx;
77
78 /* APN string */
79 char apn_str[GSM_APN_LENGTH];
80
81 /* the original data */
82 struct msgb *orig_msg;
83 struct tlv_parsed tp;
84
85 /* for dealing with re-transmissions */
86 uint8_t nsapi;
87 uint8_t sapi;
88 uint8_t ti;
89};
90
Harald Weltef97ee042015-12-25 19:12:21 +010091enum sgsn_ran_type {
92 /* GPRS/EDGE via Gb */
93 MM_CTX_T_GERAN_Gb,
94 /* UMTS via Iu */
95 MM_CTX_T_UTRAN_Iu,
Pau Espin Pedrol05140b82019-08-13 18:38:24 +020096#if 0
97 /* GPRS/EDGE via Iu, not supported */
Harald Weltef97ee042015-12-25 19:12:21 +010098 MM_CTX_T_GERAN_Iu,
Pau Espin Pedrol05140b82019-08-13 18:38:24 +020099#endif
Harald Weltef97ee042015-12-25 19:12:21 +0100100};
Pau Espin Pedrolfd815bb2019-08-30 18:32:42 +0200101extern const struct value_string sgsn_ran_type_names[];
Harald Weltef97ee042015-12-25 19:12:21 +0100102
103struct service_info {
104 uint8_t type;
105 uint16_t pdp_status;
106};
107
Neels Hofmeyra7a39472017-07-05 15:19:52 +0200108struct ranap_ue_conn_ctx;
Harald Weltef97ee042015-12-25 19:12:21 +0100109
Harald Welte9b455bf2010-03-14 15:45:01 +0800110/* According to TS 03.60, Table 5: SGSN MM and PDP Contexts */
Harald Weltef533e132010-05-01 16:45:46 +0200111/* Extended by 3GPP TS 23.060, Table 6: SGSN MM and PDP Contexts */
Harald Welte9b455bf2010-03-14 15:45:01 +0800112struct sgsn_mm_ctx {
113 struct llist_head list;
114
Harald Weltef97ee042015-12-25 19:12:21 +0100115 enum sgsn_ran_type ran_type;
116
Harald Welted3fa84d2016-04-20 17:50:17 +0200117 char imsi[GSM23003_IMSI_MAX_DIGITS+1];
Pau Espin Pedrol31c46572019-09-02 16:45:27 +0200118 struct osmo_fsm_inst *gmm_fsm;
Harald Welteeaa614c2010-05-02 11:26:34 +0200119 uint32_t p_tmsi;
Harald Weltec2e8cc42010-05-31 20:23:38 +0200120 uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */
Harald Welteeaa614c2010-05-02 11:26:34 +0200121 uint32_t p_tmsi_sig;
Harald Welted3fa84d2016-04-20 17:50:17 +0200122 char imei[GSM23003_IMEISV_NUM_DIGITS+1];
Harald Weltef533e132010-05-01 16:45:46 +0200123 /* Opt: Software Version Numbber / TS 23.195 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800124 char msisdn[GSM_EXTENSION_LENGTH];
125 struct gprs_ra_id ra;
Harald Weltef97ee042015-12-25 19:12:21 +0100126 struct {
127 uint16_t cell_id; /* Gb only */
128 uint32_t cell_id_age; /* Gb only */
129 uint8_t radio_prio_sms;
130
131 /* Additional bits not present in the GSM TS */
132 uint16_t nsei;
133 uint16_t bvci;
134 struct gprs_llc_llme *llme;
135 uint32_t tlli;
136 uint32_t tlli_new;
Alexander Couzens39cbecd2017-02-03 22:16:05 +0100137
Pau Espin Pedrol0b722402019-08-29 19:59:07 +0200138 /* TS 23.060 6.1.1 Mobility Management States (A/Gb mode) */
Pau Espin Pedrol02514bc2019-08-30 16:14:22 +0200139 struct osmo_fsm_inst *mm_state_fsm;
Harald Weltef97ee042015-12-25 19:12:21 +0100140 } gb;
141 struct {
142 int new_key;
143 uint16_t sac; /* Iu: Service Area Code */
144 uint32_t sac_age; /* Iu: Service Area Code age */
145 /* CSG ID */
146 /* CSG Membership */
147 /* Access Mode */
148 /* Seelected CN Operator ID (TS 23.251) */
149 /* CSG Subscription Data */
150 /* LIPA Allowed */
151 /* Voice Support Match Indicator */
Neels Hofmeyra7a39472017-07-05 15:19:52 +0200152 struct ranap_ue_conn_ctx *ue_ctx;
Harald Weltef97ee042015-12-25 19:12:21 +0100153 struct service_info service;
Pau Espin Pedrol0b722402019-08-29 19:59:07 +0200154 /* TS 23.060 6.1.2 Mobility Management States (Iu mode) */
Pau Espin Pedrolccd12522019-08-30 17:06:36 +0200155 struct osmo_fsm_inst *mm_state_fsm;
Harald Weltef97ee042015-12-25 19:12:21 +0100156 } iu;
Alexander Couzensf7198d72018-05-22 18:29:14 +0200157 struct {
158 struct osmo_fsm_inst *fsm;
159
160 /* when a second attach req arrives while in this procedure,
161 * the fsm needs to compare it against old to decide what to do */
162 struct msgb *attach_req;
163 uint32_t id_type;
Alexander Couzens97390672018-09-18 18:16:53 +0200164 unsigned int auth_reattempt; /* tracking UMTS resync auth attempts */
Alexander Couzensf7198d72018-05-22 18:29:14 +0200165 } gmm_att_req;
Harald Welte9b455bf2010-03-14 15:45:01 +0800166 /* VLR number */
Harald Welteeaa614c2010-05-02 11:26:34 +0200167 uint32_t new_sgsn_addr;
Jacob Erlbeckbd0cf112014-12-01 12:33:33 +0100168 /* Authentication Triplet */
169 struct gsm_auth_tuple auth_triplet;
Harald Welte9b455bf2010-03-14 15:45:01 +0800170 /* Kc */
Harald Weltef533e132010-05-01 16:45:46 +0200171 /* Iu: CK, IK, KSI */
Harald Welte9b455bf2010-03-14 15:45:01 +0800172 /* CKSN */
173 enum gprs_ciph_algo ciph_algo;
Eric2f898262021-05-19 18:57:50 +0200174 uint8_t ue_cipher_mask;
Max4011e722016-07-05 15:19:12 +0200175 /* Auth & Ciphering Request reference from 3GPP TS 24.008 § 10.5.5.19: */
176 uint8_t ac_ref_nr_used;
Harald Weltef97ee042015-12-25 19:12:21 +0100177
Harald Welte9b455bf2010-03-14 15:45:01 +0800178 struct {
Harald Welteeaa614c2010-05-02 11:26:34 +0200179 uint8_t len;
Alexander Chemeris84402c02013-07-03 10:12:23 +0400180 uint8_t buf[50]; /* GSM 04.08 10.5.5.12a, extended in TS 24.008 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800181 } ms_radio_access_capa;
Harald Weltef97ee042015-12-25 19:12:21 +0100182 /* Supported Codecs (SRVCC) */
Harald Welte9b455bf2010-03-14 15:45:01 +0800183 struct {
Harald Welteeaa614c2010-05-02 11:26:34 +0200184 uint8_t len;
Alexander Chemeris84402c02013-07-03 10:12:23 +0400185 uint8_t buf[8]; /* GSM 04.08 10.5.5.12, extended in TS 24.008 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800186 } ms_network_capa;
Harald Weltef97ee042015-12-25 19:12:21 +0100187 /* UE Netowrk Capability (E-UTRAN) */
Harald Welteeaa614c2010-05-02 11:26:34 +0200188 uint16_t drx_parms;
Harald Weltef97ee042015-12-25 19:12:21 +0100189 /* Active Time value for PSM */
Harald Welte9b455bf2010-03-14 15:45:01 +0800190 int mnrg; /* MS reported to HLR? */
191 int ngaf; /* MS reported to MSC/VLR? */
192 int ppf; /* paging for GPRS + non-GPRS? */
Harald Weltef97ee042015-12-25 19:12:21 +0100193 /* Subscribed Charging Characteristics */
194 /* Trace Reference */
195 /* Trace Type */
196 /* Trigger ID */
197 /* OMC Identity */
Harald Welte9b455bf2010-03-14 15:45:01 +0800198 /* SMS Parameters */
199 int recovery;
Harald Weltef97ee042015-12-25 19:12:21 +0100200 /* Access Restriction */
201 /* GPRS CSI (CAMEL) */
202 /* MG-CSI (CAMEL) */
203 /* Subscribed UE-AMBR */
204 /* UE-AMBR */
205 /* APN Subscribed */
Harald Welte9b455bf2010-03-14 15:45:01 +0800206
207 struct llist_head pdp_list;
208
Harald Welte8acd88f2010-05-18 10:57:45 +0200209 struct rate_ctr_group *ctrg;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200210 struct osmo_timer_list timer;
Harald Weltec2e8cc42010-05-31 20:23:38 +0200211 unsigned int T; /* Txxxx number */
212 unsigned int num_T_exp; /* number of consecutive T expirations */
213
214 enum gprs_t3350_mode t3350_mode;
215 uint8_t t3370_id_type;
Jacob Erlbeck93eae8e2014-10-28 12:23:29 +0100216 uint8_t pending_req; /* the request's message type */
217 /* TODO: There isn't much semantic difference between t3350_mode
218 * (refers to the timer) and pending_req (refers to the procedure),
219 * where mm->T == 3350 => mm->t3350_mode == f(mm->pending_req). Check
220 * whether one of them can be dropped. */
Jacob Erlbeck0c06f982014-10-29 22:12:20 +0100221
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +0200222 enum sgsn_auth_state auth_state;
Neels Hofmeyraa4ed672018-04-22 19:29:41 +0200223 enum osmo_sub_auth_type sec_ctx;
Jacob Erlbeck02ab91e2014-11-12 09:53:45 +0100224
Holger Hans Peter Freyther8ee13e22015-05-18 10:00:03 +0200225 /* the string representation of the current hlr */
226 char hlr[GSM_EXTENSION_LENGTH];
227
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800228 /* the current GGSN look-up operation */
229 struct sgsn_ggsn_lookup *ggsn_lookup;
230
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100231 struct gprs_subscr *subscr;
Harald Welte9b455bf2010-03-14 15:45:01 +0800232};
233
Neels Hofmeyraa4ed672018-04-22 19:29:41 +0200234static inline bool sgsn_mm_ctx_is_authenticated(struct sgsn_mm_ctx *ctx)
235{
236 switch (ctx->sec_ctx) {
237 case OSMO_AUTH_TYPE_GSM:
238 case OSMO_AUTH_TYPE_UMTS:
239 return true;
240 default:
241 return false;
242 }
243}
244
Daniel Willmannb15ceec2014-09-03 15:57:49 +0200245#define LOGMMCTXP(level, mm, fmt, args...) \
Jacob Erlbeck5a38f642014-10-21 13:09:55 +0200246 LOGP(DMM, level, "MM(%s/%08x) " fmt, (mm) ? (mm)->imsi : "---", \
247 (mm) ? (mm)->p_tmsi : GSM_RESERVED_TMSI, ## args)
Daniel Willmannb15ceec2014-09-03 15:57:49 +0200248
Pau Espin Pedrol5b6c4b82019-08-14 16:08:15 +0200249#ifdef BUILD_IU
250#define LOGIUP(ue, level, fmt, args...) \
251 LOGP(DMM, level, "UE(0x%x){%s} " fmt, ue->conn_id, osmo_rai_name(&(ue)->ra_id), ## args)
252#else
253#define LOGIUP(ue, level, fmt, args...) \
254 LOGP(DMM, level, "UE(%p){NOTSUPPORTED} " fmt, ue, ## args)
255#endif
256
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +0100257#define LOGGBP(llme, category, level, fmt, args...) \
258 LOGP(category, level, "LLME(%08x/%08x){%s} " fmt, (llme)->old_tlli, \
Pau Espin Pedrol5b6c4b82019-08-14 16:08:15 +0200259 (llme)->tlli, get_value_string_or_null(gprs_llc_llme_state_names, (llme)->state), ## args);
260
261#define LOGGBIUP(llme, msg, level, fmt, args...) \
262 do { \
263 struct ranap_ue_conn_ctx * _ue; \
264 if (llme) { \
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +0100265 LOGGBP(llme, DMM, level, fmt, ## args); \
Pau Espin Pedrol5b6c4b82019-08-14 16:08:15 +0200266 } else if ((msg) && (_ue = MSG_IU_UE_CTX(msg))) { \
267 LOGIUP(_ue, level, fmt, ## args); \
268 } else { OSMO_ASSERT(0); } \
269 } while (0)
270
Harald Welte9b455bf2010-03-14 15:45:01 +0800271/* look-up a SGSN MM context based on TLLI + RAI */
Harald Welteeaa614c2010-05-02 11:26:34 +0200272struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
Harald Welte9b455bf2010-03-14 15:45:01 +0800273 const struct gprs_ra_id *raid);
Harald Welteeaa614c2010-05-02 11:26:34 +0200274struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi);
Harald Welte9b455bf2010-03-14 15:45:01 +0800275struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi);
Daniel Willmann6292c8d2016-05-21 17:35:57 +0200276struct sgsn_mm_ctx *sgsn_mm_ctx_by_ue_ctx(const void *uectx);
Harald Welte9b455bf2010-03-14 15:45:01 +0800277
Jacob Erlbeck5ac4aad2016-01-04 18:43:38 +0100278/* look-up by matching TLLI and P-TMSI (think twice before using this) */
279struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli,
280 const struct gprs_ra_id *raid);
281
Harald Welte9b455bf2010-03-14 15:45:01 +0800282/* Allocate a new SGSN MM context */
Alexander Couzens2b5fb8e2017-02-04 06:01:00 +0100283struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli,
Harald Welte9b455bf2010-03-14 15:45:01 +0800284 const struct gprs_ra_id *raid);
Daniel Willmann6292c8d2016-05-21 17:35:57 +0200285struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx);
286
Jacob Erlbecke671d252015-01-26 14:43:07 +0100287void sgsn_mm_ctx_cleanup_free(struct sgsn_mm_ctx *ctx);
Harald Welte9b455bf2010-03-14 15:45:01 +0800288
Jacob Erlbeck277b71e2015-02-02 18:03:05 +0100289struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
290 struct tlv_parsed *tp,
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800291 enum gsm48_gsm_cause *gsm_cause,
292 char *apn_str);
Harald Welted193cb32010-05-17 22:58:03 +0200293
294enum pdp_ctx_state {
295 PDP_STATE_NONE,
Harald Welte6abf94e2010-05-18 10:35:06 +0200296 PDP_STATE_CR_REQ,
297 PDP_STATE_CR_CONF,
Harald Weltea9b473a2010-12-24 21:13:26 +0100298
299 /* 04.08 / Figure 6.2 / 6.1.2.2 */
300 PDP_STATE_INACT_PEND,
301 PDP_STATE_INACTIVE = PDP_STATE_NONE,
Harald Welted193cb32010-05-17 22:58:03 +0200302};
303
304enum pdp_type {
305 PDP_TYPE_NONE,
Harald Welte6abf94e2010-05-18 10:35:06 +0200306 PDP_TYPE_ETSI_PPP,
307 PDP_TYPE_IANA_IPv4,
308 PDP_TYPE_IANA_IPv6,
Harald Welted193cb32010-05-17 22:58:03 +0200309};
310
311struct sgsn_pdp_ctx {
312 struct llist_head list; /* list_head for mmctx->pdp_list */
313 struct llist_head g_list; /* list_head for global list */
314 struct sgsn_mm_ctx *mm; /* back pointer to MM CTX */
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800315 int destroy_ggsn; /* destroy it on destruction */
Harald Welted193cb32010-05-17 22:58:03 +0200316 struct sgsn_ggsn_ctx *ggsn; /* which GGSN serves this PDP */
Pau Espin Pedrola98fead2018-07-09 14:39:47 +0200317 struct llist_head ggsn_list; /* list_head for ggsn->pdp_list */
Harald Welteefbdee92010-06-10 00:20:12 +0200318 struct rate_ctr_group *ctrg;
Harald Welted193cb32010-05-17 22:58:03 +0200319
320 //unsigned int id;
321 struct pdp_t *lib; /* pointer to libgtp PDP ctx */
322 enum pdp_ctx_state state;
323 enum pdp_type type;
324 uint32_t address;
325 char *apn_subscribed;
326 //char *apn_used;
Harald Welte6abf94e2010-05-18 10:35:06 +0200327 uint16_t nsapi; /* SNDCP */
328 uint16_t sapi; /* LLC */
Harald Welted193cb32010-05-17 22:58:03 +0200329 uint8_t ti; /* transaction identifier */
330 int vplmn_allowed;
331 uint32_t qos_profile_subscr;
332 //uint32_t qos_profile_req;
333 //uint32_t qos_profile_neg;
334 uint8_t radio_prio;
Harald Welted193cb32010-05-17 22:58:03 +0200335 //uint32_t charging_id;
Harald Weltea9b473a2010-12-24 21:13:26 +0100336
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200337 struct osmo_timer_list timer;
Harald Weltea9b473a2010-12-24 21:13:26 +0100338 unsigned int T; /* Txxxx number */
339 unsigned int num_T_exp; /* number of consecutive T expirations */
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200340
341 struct osmo_timer_list cdr_timer; /* CDR record wird timer */
342 struct timespec cdr_start; /* The start of the CDR */
343 uint64_t cdr_bytes_in;
344 uint64_t cdr_bytes_out;
Holger Hans Peter Freyther77ff1c42015-05-12 21:08:42 +0200345 uint32_t cdr_charging_id;
Harald Welted193cb32010-05-17 22:58:03 +0200346};
347
Daniel Willmannb15ceec2014-09-03 15:57:49 +0200348#define LOGPDPCTXP(level, pdp, fmt, args...) \
Jacob Erlbeck99985b52014-10-13 10:32:00 +0200349 LOGP(DGPRS, level, "PDP(%s/%u) " \
350 fmt, (pdp)->mm ? (pdp)->mm->imsi : "---", (pdp)->ti, ## args)
Harald Welted193cb32010-05-17 22:58:03 +0200351
Harald Welte96df6062010-06-03 06:37:26 +0200352/* look up PDP context by MM context and NSAPI */
Harald Welted193cb32010-05-17 22:58:03 +0200353struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm,
354 uint8_t nsapi);
Harald Welte96df6062010-06-03 06:37:26 +0200355/* look up PDP context by MM context and transaction ID */
Harald Welte77289c22010-05-18 14:32:29 +0200356struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm,
357 uint8_t tid);
Harald Welte96df6062010-06-03 06:37:26 +0200358
Harald Welted193cb32010-05-17 22:58:03 +0200359struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
Pau Espin Pedrola98fead2018-07-09 14:39:47 +0200360 struct sgsn_ggsn_ctx *ggsn,
Harald Welted193cb32010-05-17 22:58:03 +0200361 uint8_t nsapi);
Jacob Erlbeck99985b52014-10-13 10:32:00 +0200362void sgsn_pdp_ctx_terminate(struct sgsn_pdp_ctx *pdp);
Harald Welted193cb32010-05-17 22:58:03 +0200363void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp);
364
Harald Welted193cb32010-05-17 22:58:03 +0200365struct apn_ctx {
366 struct llist_head list;
Harald Welte77289c22010-05-18 14:32:29 +0200367 struct sgsn_ggsn_ctx *ggsn;
Harald Welted193cb32010-05-17 22:58:03 +0200368 char *name;
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100369 char *imsi_prefix;
Harald Welted193cb32010-05-17 22:58:03 +0200370 char *description;
371};
372
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100373struct apn_ctx *sgsn_apn_ctx_find_alloc(const char *name, const char *imsi_prefix);
374void sgsn_apn_ctx_free(struct apn_ctx *actx);
375struct apn_ctx *sgsn_apn_ctx_by_name(const char *name, const char *imsi_prefix);
376struct apn_ctx *sgsn_apn_ctx_match(const char *name, const char *imsi_prefix);
377
Harald Welted193cb32010-05-17 22:58:03 +0200378extern struct llist_head sgsn_mm_ctxts;
379extern struct llist_head sgsn_ggsn_ctxts;
380extern struct llist_head sgsn_apn_ctxts;
381extern struct llist_head sgsn_pdp_ctxts;
382
Harald Welte6463c072010-05-18 17:04:55 +0200383uint32_t sgsn_alloc_ptmsi(void);
Pau Espin Pedrol73b2bf32018-10-30 18:00:57 +0100384struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx);
385void sgsn_inst_init(struct sgsn_instance *sgsn);
Harald Welte6463c072010-05-18 17:04:55 +0200386
Keith6cee1a12021-09-29 21:00:04 +0200387char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len, bool return_ipv6);
Holger Hans Peter Freythera2730302014-03-23 18:08:26 +0100388
389/*
390 * ctrl interface related work
391 */
Holger Hans Peter Freythera2730302014-03-23 18:08:26 +0100392int sgsn_ctrl_cmds_install(void);
393
Holger Hans Peter Freyther1768a572014-04-04 12:40:34 +0200394/*
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +0200395 * Authorization/ACL handling
Holger Hans Peter Freyther1768a572014-04-04 12:40:34 +0200396 */
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200397struct imsi_acl_entry {
398 struct llist_head list;
Max85386dc2018-12-10 13:26:39 +0100399 char imsi[OSMO_IMSI_BUF_SIZE];
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200400};
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +0200401
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100402/* see GSM 09.02, 17.7.1, PDP-Context and GPRSSubscriptionData */
403/* see GSM 09.02, B.1, gprsSubscriptionData */
404struct sgsn_subscriber_pdp_data {
405 struct llist_head list;
406
407 unsigned int context_id;
408 uint16_t pdp_type;
409 char apn_str[GSM_APN_LENGTH];
Holger Hans Peter Freyther8cedded2015-04-23 11:33:35 -0400410 uint8_t qos_subscribed[20];
411 size_t qos_subscribed_len;
Holger Hans Peter Freyther5db68572017-07-09 13:18:17 +0200412 uint8_t pdp_charg[2];
413 bool has_pdp_charg;
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100414};
415
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100416#define SGSN_ERROR_CAUSE_NONE (-1)
417
Jacob Erlbeck42755782015-01-08 12:02:12 +0100418#define LOGGSUBSCRP(level, subscr, fmt, args...) \
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100419 LOGP(DGPRS, level, "SUBSCR(%s) " fmt, \
420 (subscr) ? (subscr)->imsi : "---", \
Jacob Erlbeck42755782015-01-08 12:02:12 +0100421 ## args)
422
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200423struct sgsn_config;
424struct sgsn_instance;
Jacob Erlbeckf951a012014-11-07 14:17:44 +0100425extern const struct value_string *sgsn_auth_state_names;
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200426
Max2e485762018-12-10 18:01:47 +0100427void sgsn_auth_init(struct sgsn_instance *sgsn);
Max40124c82018-12-10 18:17:21 +0100428struct imsi_acl_entry *sgsn_acl_lookup(const char *imsi, const struct sgsn_config *cfg);
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200429int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg);
430int sgsn_acl_del(const char *imsi, struct sgsn_config *cfg);
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +0200431/* Request authorization */
Jacob Erlbecka0b6efb2014-11-13 10:48:39 +0100432int sgsn_auth_request(struct sgsn_mm_ctx *mm);
433enum sgsn_auth_state sgsn_auth_state(struct sgsn_mm_ctx *mm);
434void sgsn_auth_update(struct sgsn_mm_ctx *mm);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100435struct gsm_auth_tuple *sgsn_auth_get_tuple(struct sgsn_mm_ctx *mmctx,
436 unsigned key_seq);
Jacob Erlbeck423f8bf2014-10-24 18:09:54 +0200437
438/* Called on subscriber data updates */
Jacob Erlbeck555b2e52015-01-26 13:52:42 +0100439void sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx);
Holger Hans Peter Freyther1768a572014-04-04 12:40:34 +0200440
Pau Espin Pedrolf37aedb2023-01-05 14:20:27 +0100441void sgsn_rate_ctr_init(void);
Alexander Couzens14314bd2016-07-05 09:52:52 +0200442
Harald Welte9b455bf2010-03-14 15:45:01 +0800443#endif /* _GPRS_SGSN_H */