Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | #ifndef _GPRS_SGSN_H |
| 2 | #define _GPRS_SGSN_H |
| 3 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 5 | #include <netinet/in.h> |
Pau Espin Pedrol | 6ec5dc2 | 2019-08-28 16:52:56 +0200 | [diff] [blame] | 6 | #include <inttypes.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 7 | |
Alexander Couzens | f7198d7 | 2018-05-22 18:29:14 +0200 | [diff] [blame] | 8 | #include <osmocom/core/fsm.h> |
Holger Hans Peter Freyther | 26d0fe3 | 2012-01-06 17:29:06 +0100 | [diff] [blame] | 9 | #include <osmocom/core/timer.h> |
| 10 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 11 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 12 | |
Harald Welte | 496aee4 | 2010-06-30 19:59:55 +0200 | [diff] [blame] | 13 | #include <osmocom/crypt/gprs_cipher.h> |
Harald Welte | d3fa84d | 2016-04-20 17:50:17 +0200 | [diff] [blame] | 14 | #include <osmocom/gsm/protocol/gsm_23_003.h> |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 15 | #include <osmocom/crypt/auth.h> |
Jacob Erlbeck | bd0cf11 | 2014-12-01 12:33:33 +0100 | [diff] [blame] | 16 | |
Pau Espin Pedrol | ffd6e37 | 2023-01-05 17:45:25 +0100 | [diff] [blame] | 17 | #include <osmocom/sgsn/apn.h> |
Pau Espin Pedrol | c1cf4af | 2023-01-05 15:43:00 +0100 | [diff] [blame] | 18 | #include <osmocom/sgsn/gprs_subscriber.h> |
| 19 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 20 | #define GSM_EXTENSION_LENGTH 15 |
| 21 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 22 | struct gprs_llc_lle; |
Holger Hans Peter Freyther | a273030 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 23 | struct ctrl_handle; |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 24 | struct gprs_subscr; |
Pau Espin Pedrol | 5f4736a | 2023-01-04 21:30:28 +0100 | [diff] [blame] | 25 | struct sgsn_ggsn_ctx; |
Pau Espin Pedrol | 05190c3 | 2023-01-05 20:13:13 +0100 | [diff] [blame^] | 26 | struct sgsn_pdp_ctx; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 27 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 28 | enum gsm48_gsm_cause; |
| 29 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 30 | enum gprs_mm_ctr { |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 31 | GMM_CTR_PKTS_SIG_IN, |
| 32 | GMM_CTR_PKTS_SIG_OUT, |
| 33 | GMM_CTR_PKTS_UDATA_IN, |
| 34 | GMM_CTR_PKTS_UDATA_OUT, |
| 35 | GMM_CTR_BYTES_UDATA_IN, |
| 36 | GMM_CTR_BYTES_UDATA_OUT, |
| 37 | GMM_CTR_PDP_CTX_ACT, |
| 38 | GMM_CTR_SUSPEND, |
| 39 | GMM_CTR_PAGING_PS, |
| 40 | GMM_CTR_PAGING_CS, |
| 41 | GMM_CTR_RA_UPDATE, |
| 42 | }; |
| 43 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 44 | enum gprs_t3350_mode { |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 45 | GMM_T3350_MODE_NONE, |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 46 | GMM_T3350_MODE_ATT, |
| 47 | GMM_T3350_MODE_RAU, |
| 48 | GMM_T3350_MODE_PTMSI_REALL, |
| 49 | }; |
| 50 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 51 | /* Authorization/ACL handling */ |
| 52 | enum sgsn_auth_state { |
| 53 | SGSN_AUTH_UNKNOWN, |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 54 | SGSN_AUTH_AUTHENTICATE, |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 55 | SGSN_AUTH_UMTS_RESYNC, |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 56 | SGSN_AUTH_ACCEPTED, |
| 57 | SGSN_AUTH_REJECTED |
| 58 | }; |
| 59 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 60 | #define MS_RADIO_ACCESS_CAPA |
| 61 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 62 | enum sgsn_ggsn_lookup_state { |
| 63 | SGSN_GGSN_2DIGIT, |
| 64 | SGSN_GGSN_3DIGIT, |
| 65 | }; |
| 66 | |
| 67 | struct sgsn_ggsn_lookup { |
| 68 | int state; |
| 69 | |
| 70 | struct sgsn_mm_ctx *mmctx; |
| 71 | |
| 72 | /* APN string */ |
| 73 | char apn_str[GSM_APN_LENGTH]; |
| 74 | |
| 75 | /* the original data */ |
| 76 | struct msgb *orig_msg; |
| 77 | struct tlv_parsed tp; |
| 78 | |
| 79 | /* for dealing with re-transmissions */ |
| 80 | uint8_t nsapi; |
| 81 | uint8_t sapi; |
| 82 | uint8_t ti; |
| 83 | }; |
| 84 | |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 85 | enum sgsn_ran_type { |
| 86 | /* GPRS/EDGE via Gb */ |
| 87 | MM_CTX_T_GERAN_Gb, |
| 88 | /* UMTS via Iu */ |
| 89 | MM_CTX_T_UTRAN_Iu, |
Pau Espin Pedrol | 05140b8 | 2019-08-13 18:38:24 +0200 | [diff] [blame] | 90 | #if 0 |
| 91 | /* GPRS/EDGE via Iu, not supported */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 92 | MM_CTX_T_GERAN_Iu, |
Pau Espin Pedrol | 05140b8 | 2019-08-13 18:38:24 +0200 | [diff] [blame] | 93 | #endif |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 94 | }; |
Pau Espin Pedrol | fd815bb | 2019-08-30 18:32:42 +0200 | [diff] [blame] | 95 | extern const struct value_string sgsn_ran_type_names[]; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 96 | |
| 97 | struct service_info { |
| 98 | uint8_t type; |
| 99 | uint16_t pdp_status; |
| 100 | }; |
| 101 | |
Neels Hofmeyr | a7a3947 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 102 | struct ranap_ue_conn_ctx; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 103 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 104 | /* According to TS 03.60, Table 5: SGSN MM and PDP Contexts */ |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 105 | /* Extended by 3GPP TS 23.060, Table 6: SGSN MM and PDP Contexts */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 106 | struct sgsn_mm_ctx { |
| 107 | struct llist_head list; |
| 108 | |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 109 | enum sgsn_ran_type ran_type; |
| 110 | |
Harald Welte | d3fa84d | 2016-04-20 17:50:17 +0200 | [diff] [blame] | 111 | char imsi[GSM23003_IMSI_MAX_DIGITS+1]; |
Pau Espin Pedrol | 31c4657 | 2019-09-02 16:45:27 +0200 | [diff] [blame] | 112 | struct osmo_fsm_inst *gmm_fsm; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 113 | uint32_t p_tmsi; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 114 | uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 115 | uint32_t p_tmsi_sig; |
Harald Welte | d3fa84d | 2016-04-20 17:50:17 +0200 | [diff] [blame] | 116 | char imei[GSM23003_IMEISV_NUM_DIGITS+1]; |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 117 | /* Opt: Software Version Numbber / TS 23.195 */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 118 | char msisdn[GSM_EXTENSION_LENGTH]; |
| 119 | struct gprs_ra_id ra; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 120 | struct { |
| 121 | uint16_t cell_id; /* Gb only */ |
| 122 | uint32_t cell_id_age; /* Gb only */ |
| 123 | uint8_t radio_prio_sms; |
| 124 | |
| 125 | /* Additional bits not present in the GSM TS */ |
| 126 | uint16_t nsei; |
| 127 | uint16_t bvci; |
| 128 | struct gprs_llc_llme *llme; |
| 129 | uint32_t tlli; |
| 130 | uint32_t tlli_new; |
Alexander Couzens | 39cbecd | 2017-02-03 22:16:05 +0100 | [diff] [blame] | 131 | |
Pau Espin Pedrol | 0b72240 | 2019-08-29 19:59:07 +0200 | [diff] [blame] | 132 | /* TS 23.060 6.1.1 Mobility Management States (A/Gb mode) */ |
Pau Espin Pedrol | 02514bc | 2019-08-30 16:14:22 +0200 | [diff] [blame] | 133 | struct osmo_fsm_inst *mm_state_fsm; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 134 | } gb; |
| 135 | struct { |
| 136 | int new_key; |
| 137 | uint16_t sac; /* Iu: Service Area Code */ |
| 138 | uint32_t sac_age; /* Iu: Service Area Code age */ |
| 139 | /* CSG ID */ |
| 140 | /* CSG Membership */ |
| 141 | /* Access Mode */ |
| 142 | /* Seelected CN Operator ID (TS 23.251) */ |
| 143 | /* CSG Subscription Data */ |
| 144 | /* LIPA Allowed */ |
| 145 | /* Voice Support Match Indicator */ |
Neels Hofmeyr | a7a3947 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 146 | struct ranap_ue_conn_ctx *ue_ctx; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 147 | struct service_info service; |
Pau Espin Pedrol | 0b72240 | 2019-08-29 19:59:07 +0200 | [diff] [blame] | 148 | /* TS 23.060 6.1.2 Mobility Management States (Iu mode) */ |
Pau Espin Pedrol | ccd1252 | 2019-08-30 17:06:36 +0200 | [diff] [blame] | 149 | struct osmo_fsm_inst *mm_state_fsm; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 150 | } iu; |
Alexander Couzens | f7198d7 | 2018-05-22 18:29:14 +0200 | [diff] [blame] | 151 | struct { |
| 152 | struct osmo_fsm_inst *fsm; |
| 153 | |
| 154 | /* when a second attach req arrives while in this procedure, |
| 155 | * the fsm needs to compare it against old to decide what to do */ |
| 156 | struct msgb *attach_req; |
| 157 | uint32_t id_type; |
Alexander Couzens | 9739067 | 2018-09-18 18:16:53 +0200 | [diff] [blame] | 158 | unsigned int auth_reattempt; /* tracking UMTS resync auth attempts */ |
Alexander Couzens | f7198d7 | 2018-05-22 18:29:14 +0200 | [diff] [blame] | 159 | } gmm_att_req; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 160 | /* VLR number */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 161 | uint32_t new_sgsn_addr; |
Jacob Erlbeck | bd0cf11 | 2014-12-01 12:33:33 +0100 | [diff] [blame] | 162 | /* Authentication Triplet */ |
| 163 | struct gsm_auth_tuple auth_triplet; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 164 | /* Kc */ |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 165 | /* Iu: CK, IK, KSI */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 166 | /* CKSN */ |
| 167 | enum gprs_ciph_algo ciph_algo; |
Eric | 2f89826 | 2021-05-19 18:57:50 +0200 | [diff] [blame] | 168 | uint8_t ue_cipher_mask; |
Max | 4011e72 | 2016-07-05 15:19:12 +0200 | [diff] [blame] | 169 | /* Auth & Ciphering Request reference from 3GPP TS 24.008 § 10.5.5.19: */ |
| 170 | uint8_t ac_ref_nr_used; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 171 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 172 | struct { |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 173 | uint8_t len; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 174 | uint8_t buf[50]; /* GSM 04.08 10.5.5.12a, extended in TS 24.008 */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 175 | } ms_radio_access_capa; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 176 | /* Supported Codecs (SRVCC) */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 177 | struct { |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 178 | uint8_t len; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 179 | uint8_t buf[8]; /* GSM 04.08 10.5.5.12, extended in TS 24.008 */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 180 | } ms_network_capa; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 181 | /* UE Netowrk Capability (E-UTRAN) */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 182 | uint16_t drx_parms; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 183 | /* Active Time value for PSM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 184 | int mnrg; /* MS reported to HLR? */ |
| 185 | int ngaf; /* MS reported to MSC/VLR? */ |
| 186 | int ppf; /* paging for GPRS + non-GPRS? */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 187 | /* Subscribed Charging Characteristics */ |
| 188 | /* Trace Reference */ |
| 189 | /* Trace Type */ |
| 190 | /* Trigger ID */ |
| 191 | /* OMC Identity */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 192 | /* SMS Parameters */ |
| 193 | int recovery; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 194 | /* Access Restriction */ |
| 195 | /* GPRS CSI (CAMEL) */ |
| 196 | /* MG-CSI (CAMEL) */ |
| 197 | /* Subscribed UE-AMBR */ |
| 198 | /* UE-AMBR */ |
| 199 | /* APN Subscribed */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 200 | |
| 201 | struct llist_head pdp_list; |
| 202 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 203 | struct rate_ctr_group *ctrg; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 204 | struct osmo_timer_list timer; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 205 | unsigned int T; /* Txxxx number */ |
| 206 | unsigned int num_T_exp; /* number of consecutive T expirations */ |
| 207 | |
| 208 | enum gprs_t3350_mode t3350_mode; |
| 209 | uint8_t t3370_id_type; |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 210 | uint8_t pending_req; /* the request's message type */ |
| 211 | /* TODO: There isn't much semantic difference between t3350_mode |
| 212 | * (refers to the timer) and pending_req (refers to the procedure), |
| 213 | * where mm->T == 3350 => mm->t3350_mode == f(mm->pending_req). Check |
| 214 | * whether one of them can be dropped. */ |
Jacob Erlbeck | 0c06f98 | 2014-10-29 22:12:20 +0100 | [diff] [blame] | 215 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 216 | enum sgsn_auth_state auth_state; |
Neels Hofmeyr | aa4ed67 | 2018-04-22 19:29:41 +0200 | [diff] [blame] | 217 | enum osmo_sub_auth_type sec_ctx; |
Jacob Erlbeck | 02ab91e | 2014-11-12 09:53:45 +0100 | [diff] [blame] | 218 | |
Holger Hans Peter Freyther | 8ee13e2 | 2015-05-18 10:00:03 +0200 | [diff] [blame] | 219 | /* the string representation of the current hlr */ |
| 220 | char hlr[GSM_EXTENSION_LENGTH]; |
| 221 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 222 | /* the current GGSN look-up operation */ |
| 223 | struct sgsn_ggsn_lookup *ggsn_lookup; |
| 224 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 225 | struct gprs_subscr *subscr; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 226 | }; |
| 227 | |
Neels Hofmeyr | aa4ed67 | 2018-04-22 19:29:41 +0200 | [diff] [blame] | 228 | static inline bool sgsn_mm_ctx_is_authenticated(struct sgsn_mm_ctx *ctx) |
| 229 | { |
| 230 | switch (ctx->sec_ctx) { |
| 231 | case OSMO_AUTH_TYPE_GSM: |
| 232 | case OSMO_AUTH_TYPE_UMTS: |
| 233 | return true; |
| 234 | default: |
| 235 | return false; |
| 236 | } |
| 237 | } |
| 238 | |
Daniel Willmann | b15ceec | 2014-09-03 15:57:49 +0200 | [diff] [blame] | 239 | #define LOGMMCTXP(level, mm, fmt, args...) \ |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 240 | LOGP(DMM, level, "MM(%s/%08x) " fmt, (mm) ? (mm)->imsi : "---", \ |
| 241 | (mm) ? (mm)->p_tmsi : GSM_RESERVED_TMSI, ## args) |
Daniel Willmann | b15ceec | 2014-09-03 15:57:49 +0200 | [diff] [blame] | 242 | |
Pau Espin Pedrol | 5b6c4b8 | 2019-08-14 16:08:15 +0200 | [diff] [blame] | 243 | #ifdef BUILD_IU |
| 244 | #define LOGIUP(ue, level, fmt, args...) \ |
| 245 | LOGP(DMM, level, "UE(0x%x){%s} " fmt, ue->conn_id, osmo_rai_name(&(ue)->ra_id), ## args) |
| 246 | #else |
| 247 | #define LOGIUP(ue, level, fmt, args...) \ |
| 248 | LOGP(DMM, level, "UE(%p){NOTSUPPORTED} " fmt, ue, ## args) |
| 249 | #endif |
| 250 | |
Pau Espin Pedrol | 029a70e | 2019-11-21 13:58:39 +0100 | [diff] [blame] | 251 | #define LOGGBP(llme, category, level, fmt, args...) \ |
| 252 | LOGP(category, level, "LLME(%08x/%08x){%s} " fmt, (llme)->old_tlli, \ |
Pau Espin Pedrol | 5b6c4b8 | 2019-08-14 16:08:15 +0200 | [diff] [blame] | 253 | (llme)->tlli, get_value_string_or_null(gprs_llc_llme_state_names, (llme)->state), ## args); |
| 254 | |
| 255 | #define LOGGBIUP(llme, msg, level, fmt, args...) \ |
| 256 | do { \ |
| 257 | struct ranap_ue_conn_ctx * _ue; \ |
| 258 | if (llme) { \ |
Pau Espin Pedrol | 029a70e | 2019-11-21 13:58:39 +0100 | [diff] [blame] | 259 | LOGGBP(llme, DMM, level, fmt, ## args); \ |
Pau Espin Pedrol | 5b6c4b8 | 2019-08-14 16:08:15 +0200 | [diff] [blame] | 260 | } else if ((msg) && (_ue = MSG_IU_UE_CTX(msg))) { \ |
| 261 | LOGIUP(_ue, level, fmt, ## args); \ |
| 262 | } else { OSMO_ASSERT(0); } \ |
| 263 | } while (0) |
| 264 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 265 | /* look-up a SGSN MM context based on TLLI + RAI */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 266 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 267 | const struct gprs_ra_id *raid); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 268 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 269 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi); |
Daniel Willmann | 6292c8d | 2016-05-21 17:35:57 +0200 | [diff] [blame] | 270 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_ue_ctx(const void *uectx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 271 | |
Jacob Erlbeck | 5ac4aad | 2016-01-04 18:43:38 +0100 | [diff] [blame] | 272 | /* look-up by matching TLLI and P-TMSI (think twice before using this) */ |
| 273 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli, |
| 274 | const struct gprs_ra_id *raid); |
| 275 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 276 | /* Allocate a new SGSN MM context */ |
Alexander Couzens | 2b5fb8e | 2017-02-04 06:01:00 +0100 | [diff] [blame] | 277 | struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 278 | const struct gprs_ra_id *raid); |
Daniel Willmann | 6292c8d | 2016-05-21 17:35:57 +0200 | [diff] [blame] | 279 | struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx); |
| 280 | |
Jacob Erlbeck | e671d25 | 2015-01-26 14:43:07 +0100 | [diff] [blame] | 281 | void sgsn_mm_ctx_cleanup_free(struct sgsn_mm_ctx *ctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 282 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 283 | struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx, |
| 284 | struct tlv_parsed *tp, |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 285 | enum gsm48_gsm_cause *gsm_cause, |
| 286 | char *apn_str); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 287 | |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 288 | /* look up PDP context by MM context and NSAPI */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 289 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm, |
| 290 | uint8_t nsapi); |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 291 | /* look up PDP context by MM context and transaction ID */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 292 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm, |
| 293 | uint8_t tid); |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 294 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 295 | extern struct llist_head sgsn_mm_ctxts; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 296 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 297 | uint32_t sgsn_alloc_ptmsi(void); |
| 298 | |
Holger Hans Peter Freyther | a273030 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 299 | /* |
| 300 | * ctrl interface related work |
| 301 | */ |
Holger Hans Peter Freyther | a273030 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 302 | int sgsn_ctrl_cmds_install(void); |
| 303 | |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 304 | /* |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 305 | * Authorization/ACL handling |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 306 | */ |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 307 | struct imsi_acl_entry { |
| 308 | struct llist_head list; |
Max | 85386dc | 2018-12-10 13:26:39 +0100 | [diff] [blame] | 309 | char imsi[OSMO_IMSI_BUF_SIZE]; |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 310 | }; |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 311 | |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 312 | #define SGSN_ERROR_CAUSE_NONE (-1) |
| 313 | |
Jacob Erlbeck | 4275578 | 2015-01-08 12:02:12 +0100 | [diff] [blame] | 314 | #define LOGGSUBSCRP(level, subscr, fmt, args...) \ |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 315 | LOGP(DGPRS, level, "SUBSCR(%s) " fmt, \ |
| 316 | (subscr) ? (subscr)->imsi : "---", \ |
Jacob Erlbeck | 4275578 | 2015-01-08 12:02:12 +0100 | [diff] [blame] | 317 | ## args) |
| 318 | |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 319 | struct sgsn_config; |
| 320 | struct sgsn_instance; |
Jacob Erlbeck | f951a01 | 2014-11-07 14:17:44 +0100 | [diff] [blame] | 321 | extern const struct value_string *sgsn_auth_state_names; |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 322 | |
Max | 2e48576 | 2018-12-10 18:01:47 +0100 | [diff] [blame] | 323 | void sgsn_auth_init(struct sgsn_instance *sgsn); |
Max | 40124c8 | 2018-12-10 18:17:21 +0100 | [diff] [blame] | 324 | struct imsi_acl_entry *sgsn_acl_lookup(const char *imsi, const struct sgsn_config *cfg); |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 325 | int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg); |
| 326 | int sgsn_acl_del(const char *imsi, struct sgsn_config *cfg); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 327 | /* Request authorization */ |
Jacob Erlbeck | a0b6efb | 2014-11-13 10:48:39 +0100 | [diff] [blame] | 328 | int sgsn_auth_request(struct sgsn_mm_ctx *mm); |
| 329 | enum sgsn_auth_state sgsn_auth_state(struct sgsn_mm_ctx *mm); |
| 330 | void sgsn_auth_update(struct sgsn_mm_ctx *mm); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 331 | struct gsm_auth_tuple *sgsn_auth_get_tuple(struct sgsn_mm_ctx *mmctx, |
| 332 | unsigned key_seq); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 333 | |
| 334 | /* Called on subscriber data updates */ |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 335 | void sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx); |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 336 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 337 | #endif /* _GPRS_SGSN_H */ |