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 | c1cf4af | 2023-01-05 15:43:00 +0100 | [diff] [blame^] | 17 | #include <osmocom/sgsn/gprs_subscriber.h> |
| 18 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 19 | #define GSM_EXTENSION_LENGTH 15 |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 20 | #define GSM_APN_LENGTH 102 |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 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; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 26 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 27 | enum gsm48_gsm_cause; |
| 28 | |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 29 | enum gprs_mm_ctr { |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 30 | 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 Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 43 | enum 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 Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 50 | enum gprs_t3350_mode { |
Jacob Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 51 | GMM_T3350_MODE_NONE, |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 52 | GMM_T3350_MODE_ATT, |
| 53 | GMM_T3350_MODE_RAU, |
| 54 | GMM_T3350_MODE_PTMSI_REALL, |
| 55 | }; |
| 56 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 57 | /* Authorization/ACL handling */ |
| 58 | enum sgsn_auth_state { |
| 59 | SGSN_AUTH_UNKNOWN, |
Jacob Erlbeck | 4adb136 | 2014-12-02 09:47:26 +0100 | [diff] [blame] | 60 | SGSN_AUTH_AUTHENTICATE, |
Neels Hofmeyr | 058cd57 | 2017-02-24 06:24:45 +0100 | [diff] [blame] | 61 | SGSN_AUTH_UMTS_RESYNC, |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 62 | SGSN_AUTH_ACCEPTED, |
| 63 | SGSN_AUTH_REJECTED |
| 64 | }; |
| 65 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 66 | #define MS_RADIO_ACCESS_CAPA |
| 67 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 68 | enum sgsn_ggsn_lookup_state { |
| 69 | SGSN_GGSN_2DIGIT, |
| 70 | SGSN_GGSN_3DIGIT, |
| 71 | }; |
| 72 | |
| 73 | struct 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 Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 91 | enum 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 Pedrol | 05140b8 | 2019-08-13 18:38:24 +0200 | [diff] [blame] | 96 | #if 0 |
| 97 | /* GPRS/EDGE via Iu, not supported */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 98 | MM_CTX_T_GERAN_Iu, |
Pau Espin Pedrol | 05140b8 | 2019-08-13 18:38:24 +0200 | [diff] [blame] | 99 | #endif |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 100 | }; |
Pau Espin Pedrol | fd815bb | 2019-08-30 18:32:42 +0200 | [diff] [blame] | 101 | extern const struct value_string sgsn_ran_type_names[]; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 102 | |
| 103 | struct service_info { |
| 104 | uint8_t type; |
| 105 | uint16_t pdp_status; |
| 106 | }; |
| 107 | |
Neels Hofmeyr | a7a3947 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 108 | struct ranap_ue_conn_ctx; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 109 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 110 | /* According to TS 03.60, Table 5: SGSN MM and PDP Contexts */ |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 111 | /* 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] | 112 | struct sgsn_mm_ctx { |
| 113 | struct llist_head list; |
| 114 | |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 115 | enum sgsn_ran_type ran_type; |
| 116 | |
Harald Welte | d3fa84d | 2016-04-20 17:50:17 +0200 | [diff] [blame] | 117 | char imsi[GSM23003_IMSI_MAX_DIGITS+1]; |
Pau Espin Pedrol | 31c4657 | 2019-09-02 16:45:27 +0200 | [diff] [blame] | 118 | struct osmo_fsm_inst *gmm_fsm; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 119 | uint32_t p_tmsi; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 120 | uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 121 | uint32_t p_tmsi_sig; |
Harald Welte | d3fa84d | 2016-04-20 17:50:17 +0200 | [diff] [blame] | 122 | char imei[GSM23003_IMEISV_NUM_DIGITS+1]; |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 123 | /* Opt: Software Version Numbber / TS 23.195 */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 124 | char msisdn[GSM_EXTENSION_LENGTH]; |
| 125 | struct gprs_ra_id ra; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 126 | 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 Couzens | 39cbecd | 2017-02-03 22:16:05 +0100 | [diff] [blame] | 137 | |
Pau Espin Pedrol | 0b72240 | 2019-08-29 19:59:07 +0200 | [diff] [blame] | 138 | /* 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] | 139 | struct osmo_fsm_inst *mm_state_fsm; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 140 | } 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 Hofmeyr | a7a3947 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 152 | struct ranap_ue_conn_ctx *ue_ctx; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 153 | struct service_info service; |
Pau Espin Pedrol | 0b72240 | 2019-08-29 19:59:07 +0200 | [diff] [blame] | 154 | /* TS 23.060 6.1.2 Mobility Management States (Iu mode) */ |
Pau Espin Pedrol | ccd1252 | 2019-08-30 17:06:36 +0200 | [diff] [blame] | 155 | struct osmo_fsm_inst *mm_state_fsm; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 156 | } iu; |
Alexander Couzens | f7198d7 | 2018-05-22 18:29:14 +0200 | [diff] [blame] | 157 | 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 Couzens | 9739067 | 2018-09-18 18:16:53 +0200 | [diff] [blame] | 164 | unsigned int auth_reattempt; /* tracking UMTS resync auth attempts */ |
Alexander Couzens | f7198d7 | 2018-05-22 18:29:14 +0200 | [diff] [blame] | 165 | } gmm_att_req; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 166 | /* VLR number */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 167 | uint32_t new_sgsn_addr; |
Jacob Erlbeck | bd0cf11 | 2014-12-01 12:33:33 +0100 | [diff] [blame] | 168 | /* Authentication Triplet */ |
| 169 | struct gsm_auth_tuple auth_triplet; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 170 | /* Kc */ |
Harald Welte | f533e13 | 2010-05-01 16:45:46 +0200 | [diff] [blame] | 171 | /* Iu: CK, IK, KSI */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 172 | /* CKSN */ |
| 173 | enum gprs_ciph_algo ciph_algo; |
Eric | 2f89826 | 2021-05-19 18:57:50 +0200 | [diff] [blame] | 174 | uint8_t ue_cipher_mask; |
Max | 4011e72 | 2016-07-05 15:19:12 +0200 | [diff] [blame] | 175 | /* Auth & Ciphering Request reference from 3GPP TS 24.008 § 10.5.5.19: */ |
| 176 | uint8_t ac_ref_nr_used; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 177 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 178 | struct { |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 179 | uint8_t len; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 180 | 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] | 181 | } ms_radio_access_capa; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 182 | /* Supported Codecs (SRVCC) */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 183 | struct { |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 184 | uint8_t len; |
Alexander Chemeris | 84402c0 | 2013-07-03 10:12:23 +0400 | [diff] [blame] | 185 | 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] | 186 | } ms_network_capa; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 187 | /* UE Netowrk Capability (E-UTRAN) */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 188 | uint16_t drx_parms; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 189 | /* Active Time value for PSM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 190 | int mnrg; /* MS reported to HLR? */ |
| 191 | int ngaf; /* MS reported to MSC/VLR? */ |
| 192 | int ppf; /* paging for GPRS + non-GPRS? */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 193 | /* Subscribed Charging Characteristics */ |
| 194 | /* Trace Reference */ |
| 195 | /* Trace Type */ |
| 196 | /* Trigger ID */ |
| 197 | /* OMC Identity */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 198 | /* SMS Parameters */ |
| 199 | int recovery; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 200 | /* Access Restriction */ |
| 201 | /* GPRS CSI (CAMEL) */ |
| 202 | /* MG-CSI (CAMEL) */ |
| 203 | /* Subscribed UE-AMBR */ |
| 204 | /* UE-AMBR */ |
| 205 | /* APN Subscribed */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 206 | |
| 207 | struct llist_head pdp_list; |
| 208 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 209 | struct rate_ctr_group *ctrg; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 210 | struct osmo_timer_list timer; |
Harald Welte | c2e8cc4 | 2010-05-31 20:23:38 +0200 | [diff] [blame] | 211 | 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 Erlbeck | 93eae8e | 2014-10-28 12:23:29 +0100 | [diff] [blame] | 216 | 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 Erlbeck | 0c06f98 | 2014-10-29 22:12:20 +0100 | [diff] [blame] | 221 | |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 222 | enum sgsn_auth_state auth_state; |
Neels Hofmeyr | aa4ed67 | 2018-04-22 19:29:41 +0200 | [diff] [blame] | 223 | enum osmo_sub_auth_type sec_ctx; |
Jacob Erlbeck | 02ab91e | 2014-11-12 09:53:45 +0100 | [diff] [blame] | 224 | |
Holger Hans Peter Freyther | 8ee13e2 | 2015-05-18 10:00:03 +0200 | [diff] [blame] | 225 | /* the string representation of the current hlr */ |
| 226 | char hlr[GSM_EXTENSION_LENGTH]; |
| 227 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 228 | /* the current GGSN look-up operation */ |
| 229 | struct sgsn_ggsn_lookup *ggsn_lookup; |
| 230 | |
Neels Hofmeyr | 0e5d807 | 2017-01-10 00:49:56 +0100 | [diff] [blame] | 231 | struct gprs_subscr *subscr; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 232 | }; |
| 233 | |
Neels Hofmeyr | aa4ed67 | 2018-04-22 19:29:41 +0200 | [diff] [blame] | 234 | static 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 Willmann | b15ceec | 2014-09-03 15:57:49 +0200 | [diff] [blame] | 245 | #define LOGMMCTXP(level, mm, fmt, args...) \ |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 246 | LOGP(DMM, level, "MM(%s/%08x) " fmt, (mm) ? (mm)->imsi : "---", \ |
| 247 | (mm) ? (mm)->p_tmsi : GSM_RESERVED_TMSI, ## args) |
Daniel Willmann | b15ceec | 2014-09-03 15:57:49 +0200 | [diff] [blame] | 248 | |
Pau Espin Pedrol | 5b6c4b8 | 2019-08-14 16:08:15 +0200 | [diff] [blame] | 249 | #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 Pedrol | 029a70e | 2019-11-21 13:58:39 +0100 | [diff] [blame] | 257 | #define LOGGBP(llme, category, level, fmt, args...) \ |
| 258 | LOGP(category, level, "LLME(%08x/%08x){%s} " fmt, (llme)->old_tlli, \ |
Pau Espin Pedrol | 5b6c4b8 | 2019-08-14 16:08:15 +0200 | [diff] [blame] | 259 | (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 Pedrol | 029a70e | 2019-11-21 13:58:39 +0100 | [diff] [blame] | 265 | LOGGBP(llme, DMM, level, fmt, ## args); \ |
Pau Espin Pedrol | 5b6c4b8 | 2019-08-14 16:08:15 +0200 | [diff] [blame] | 266 | } 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 Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 271 | /* look-up a SGSN MM context based on TLLI + RAI */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 272 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 273 | const struct gprs_ra_id *raid); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 274 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 275 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi); |
Daniel Willmann | 6292c8d | 2016-05-21 17:35:57 +0200 | [diff] [blame] | 276 | 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] | 277 | |
Jacob Erlbeck | 5ac4aad | 2016-01-04 18:43:38 +0100 | [diff] [blame] | 278 | /* look-up by matching TLLI and P-TMSI (think twice before using this) */ |
| 279 | struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli, |
| 280 | const struct gprs_ra_id *raid); |
| 281 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 282 | /* Allocate a new SGSN MM context */ |
Alexander Couzens | 2b5fb8e | 2017-02-04 06:01:00 +0100 | [diff] [blame] | 283 | struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 284 | const struct gprs_ra_id *raid); |
Daniel Willmann | 6292c8d | 2016-05-21 17:35:57 +0200 | [diff] [blame] | 285 | struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx); |
| 286 | |
Jacob Erlbeck | e671d25 | 2015-01-26 14:43:07 +0100 | [diff] [blame] | 287 | void sgsn_mm_ctx_cleanup_free(struct sgsn_mm_ctx *ctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 288 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 289 | struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx, |
| 290 | struct tlv_parsed *tp, |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 291 | enum gsm48_gsm_cause *gsm_cause, |
| 292 | char *apn_str); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 293 | |
| 294 | enum pdp_ctx_state { |
| 295 | PDP_STATE_NONE, |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 296 | PDP_STATE_CR_REQ, |
| 297 | PDP_STATE_CR_CONF, |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 298 | |
| 299 | /* 04.08 / Figure 6.2 / 6.1.2.2 */ |
| 300 | PDP_STATE_INACT_PEND, |
| 301 | PDP_STATE_INACTIVE = PDP_STATE_NONE, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | enum pdp_type { |
| 305 | PDP_TYPE_NONE, |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 306 | PDP_TYPE_ETSI_PPP, |
| 307 | PDP_TYPE_IANA_IPv4, |
| 308 | PDP_TYPE_IANA_IPv6, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | struct 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 Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 315 | int destroy_ggsn; /* destroy it on destruction */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 316 | struct sgsn_ggsn_ctx *ggsn; /* which GGSN serves this PDP */ |
Pau Espin Pedrol | a98fead | 2018-07-09 14:39:47 +0200 | [diff] [blame] | 317 | struct llist_head ggsn_list; /* list_head for ggsn->pdp_list */ |
Harald Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 318 | struct rate_ctr_group *ctrg; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 319 | |
| 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 Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 327 | uint16_t nsapi; /* SNDCP */ |
| 328 | uint16_t sapi; /* LLC */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 329 | 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 Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 335 | //uint32_t charging_id; |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 336 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 337 | struct osmo_timer_list timer; |
Harald Welte | a9b473a | 2010-12-24 21:13:26 +0100 | [diff] [blame] | 338 | unsigned int T; /* Txxxx number */ |
| 339 | unsigned int num_T_exp; /* number of consecutive T expirations */ |
Holger Hans Peter Freyther | 4f5b823 | 2015-05-05 22:25:48 +0200 | [diff] [blame] | 340 | |
| 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 Freyther | 77ff1c4 | 2015-05-12 21:08:42 +0200 | [diff] [blame] | 345 | uint32_t cdr_charging_id; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 346 | }; |
| 347 | |
Daniel Willmann | b15ceec | 2014-09-03 15:57:49 +0200 | [diff] [blame] | 348 | #define LOGPDPCTXP(level, pdp, fmt, args...) \ |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 349 | LOGP(DGPRS, level, "PDP(%s/%u) " \ |
| 350 | fmt, (pdp)->mm ? (pdp)->mm->imsi : "---", (pdp)->ti, ## args) |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 351 | |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 352 | /* look up PDP context by MM context and NSAPI */ |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 353 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm, |
| 354 | uint8_t nsapi); |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 355 | /* look up PDP context by MM context and transaction ID */ |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 356 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm, |
| 357 | uint8_t tid); |
Harald Welte | 96df606 | 2010-06-03 06:37:26 +0200 | [diff] [blame] | 358 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 359 | struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm, |
Pau Espin Pedrol | a98fead | 2018-07-09 14:39:47 +0200 | [diff] [blame] | 360 | struct sgsn_ggsn_ctx *ggsn, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 361 | uint8_t nsapi); |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 362 | void sgsn_pdp_ctx_terminate(struct sgsn_pdp_ctx *pdp); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 363 | void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp); |
| 364 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 365 | struct apn_ctx { |
| 366 | struct llist_head list; |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 367 | struct sgsn_ggsn_ctx *ggsn; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 368 | char *name; |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 369 | char *imsi_prefix; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 370 | char *description; |
| 371 | }; |
| 372 | |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 373 | struct apn_ctx *sgsn_apn_ctx_find_alloc(const char *name, const char *imsi_prefix); |
| 374 | void sgsn_apn_ctx_free(struct apn_ctx *actx); |
| 375 | struct apn_ctx *sgsn_apn_ctx_by_name(const char *name, const char *imsi_prefix); |
| 376 | struct apn_ctx *sgsn_apn_ctx_match(const char *name, const char *imsi_prefix); |
| 377 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 378 | extern struct llist_head sgsn_mm_ctxts; |
| 379 | extern struct llist_head sgsn_ggsn_ctxts; |
| 380 | extern struct llist_head sgsn_apn_ctxts; |
| 381 | extern struct llist_head sgsn_pdp_ctxts; |
| 382 | |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 383 | uint32_t sgsn_alloc_ptmsi(void); |
Pau Espin Pedrol | 73b2bf3 | 2018-10-30 18:00:57 +0100 | [diff] [blame] | 384 | struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx); |
| 385 | void sgsn_inst_init(struct sgsn_instance *sgsn); |
Harald Welte | 6463c07 | 2010-05-18 17:04:55 +0200 | [diff] [blame] | 386 | |
Keith | 6cee1a1 | 2021-09-29 21:00:04 +0200 | [diff] [blame] | 387 | char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len, bool return_ipv6); |
Holger Hans Peter Freyther | a273030 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * ctrl interface related work |
| 391 | */ |
Holger Hans Peter Freyther | a273030 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 392 | int sgsn_ctrl_cmds_install(void); |
| 393 | |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 394 | /* |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 395 | * Authorization/ACL handling |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 396 | */ |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 397 | struct imsi_acl_entry { |
| 398 | struct llist_head list; |
Max | 85386dc | 2018-12-10 13:26:39 +0100 | [diff] [blame] | 399 | char imsi[OSMO_IMSI_BUF_SIZE]; |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 400 | }; |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 401 | |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 402 | /* see GSM 09.02, 17.7.1, PDP-Context and GPRSSubscriptionData */ |
| 403 | /* see GSM 09.02, B.1, gprsSubscriptionData */ |
| 404 | struct 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 Freyther | 8cedded | 2015-04-23 11:33:35 -0400 | [diff] [blame] | 410 | uint8_t qos_subscribed[20]; |
| 411 | size_t qos_subscribed_len; |
Holger Hans Peter Freyther | 5db6857 | 2017-07-09 13:18:17 +0200 | [diff] [blame] | 412 | uint8_t pdp_charg[2]; |
| 413 | bool has_pdp_charg; |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 414 | }; |
| 415 | |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 416 | #define SGSN_ERROR_CAUSE_NONE (-1) |
| 417 | |
Jacob Erlbeck | 4275578 | 2015-01-08 12:02:12 +0100 | [diff] [blame] | 418 | #define LOGGSUBSCRP(level, subscr, fmt, args...) \ |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 419 | LOGP(DGPRS, level, "SUBSCR(%s) " fmt, \ |
| 420 | (subscr) ? (subscr)->imsi : "---", \ |
Jacob Erlbeck | 4275578 | 2015-01-08 12:02:12 +0100 | [diff] [blame] | 421 | ## args) |
| 422 | |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 423 | struct sgsn_config; |
| 424 | struct sgsn_instance; |
Jacob Erlbeck | f951a01 | 2014-11-07 14:17:44 +0100 | [diff] [blame] | 425 | extern const struct value_string *sgsn_auth_state_names; |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 426 | |
Max | 2e48576 | 2018-12-10 18:01:47 +0100 | [diff] [blame] | 427 | void sgsn_auth_init(struct sgsn_instance *sgsn); |
Max | 40124c8 | 2018-12-10 18:17:21 +0100 | [diff] [blame] | 428 | 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] | 429 | int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg); |
| 430 | int sgsn_acl_del(const char *imsi, struct sgsn_config *cfg); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 431 | /* Request authorization */ |
Jacob Erlbeck | a0b6efb | 2014-11-13 10:48:39 +0100 | [diff] [blame] | 432 | int sgsn_auth_request(struct sgsn_mm_ctx *mm); |
| 433 | enum sgsn_auth_state sgsn_auth_state(struct sgsn_mm_ctx *mm); |
| 434 | void sgsn_auth_update(struct sgsn_mm_ctx *mm); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 435 | struct gsm_auth_tuple *sgsn_auth_get_tuple(struct sgsn_mm_ctx *mmctx, |
| 436 | unsigned key_seq); |
Jacob Erlbeck | 423f8bf | 2014-10-24 18:09:54 +0200 | [diff] [blame] | 437 | |
| 438 | /* Called on subscriber data updates */ |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 439 | void sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx); |
Holger Hans Peter Freyther | 1768a57 | 2014-04-04 12:40:34 +0200 | [diff] [blame] | 440 | |
Pau Espin Pedrol | f37aedb | 2023-01-05 14:20:27 +0100 | [diff] [blame] | 441 | void sgsn_rate_ctr_init(void); |
Alexander Couzens | 14314bd | 2016-07-05 09:52:52 +0200 | [diff] [blame] | 442 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 443 | #endif /* _GPRS_SGSN_H */ |