Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <osmocom/core/linuxlist.h> |
| 5 | #include <osmocom/core/fsm.h> |
| 6 | #include <osmocom/core/logging.h> |
| 7 | #include <osmocom/gsm/protocol/gsm_23_003.h> |
| 8 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
| 9 | #include <osmocom/gsm/gsm23003.h> |
Neels Hofmeyr | cf30913 | 2017-12-14 03:57:31 +0100 | [diff] [blame] | 10 | #include <osmocom/gsm/gsm0808.h> |
Vadim Yanitskiy | 8a0e258 | 2018-06-14 03:54:33 +0700 | [diff] [blame] | 11 | #include <osmocom/gsm/gsup.h> |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 12 | #include <osmocom/gsm/ipa.h> |
Neels Hofmeyr | a8945ce | 2018-11-30 00:44:32 +0100 | [diff] [blame] | 13 | #include <osmocom/msc/ran_conn.h> |
Neels Hofmeyr | 7b61ffe | 2018-11-30 02:46:53 +0100 | [diff] [blame] | 14 | #include <osmocom/msc/msc_common.h> |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 15 | #include <osmocom/gsupclient/gsup_client.h> |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 16 | #include <osmocom/msc/vlr_sgs.h> |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 17 | |
Max | a263bb2 | 2017-12-27 13:23:44 +0100 | [diff] [blame] | 18 | #define LOGGSUPP(level, gsup, fmt, args...) \ |
| 19 | LOGP(DVLR, level, "GSUP(%s) " fmt, (gsup)->imsi, ## args) |
| 20 | |
| 21 | #define LOGVSUBP(level, vsub, fmt, args...) \ |
| 22 | LOGP(DVLR, level, "SUBSCR(%s) " fmt, vlr_subscr_name(vsub), ## args) |
| 23 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 24 | struct log_target; |
| 25 | |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 26 | #define VLR_SUBSCRIBER_NO_EXPIRATION 0 |
| 27 | #define VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL 60 /* in seconds */ |
| 28 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 29 | /* from 3s to 10s */ |
| 30 | #define GSM_29002_TIMER_S 10 |
| 31 | /* from 15s to 30s */ |
| 32 | #define GSM_29002_TIMER_M 30 |
| 33 | /* from 1min to 10min */ |
| 34 | #define GSM_29002_TIMER_ML (10*60) |
| 35 | /* from 28h to 38h */ |
| 36 | #define GSM_29002_TIMER_L (32*60*60) |
| 37 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 38 | /* VLR subscriber authentication state */ |
| 39 | enum vlr_subscr_auth_state { |
| 40 | /* subscriber needs to be autenticated */ |
| 41 | VLR_SUB_AS_NEEDS_AUTH, |
| 42 | /* waiting for AuthInfo from HLR/AUC */ |
| 43 | VLR_SUB_AS_NEEDS_AUTH_WAIT_AI, |
| 44 | /* waiting for response from subscriber */ |
| 45 | VLR_SUB_AS_WAIT_RESP, |
| 46 | /* successfully authenticated */ |
| 47 | VLR_SUB_AS_AUTHENTICATED, |
| 48 | /* subscriber needs re-sync */ |
| 49 | VLR_SUB_AS_NEEDS_RESYNC, |
| 50 | /* waiting for AuthInfo with ReSync */ |
| 51 | VLR_SUB_AS_NEEDS_AUTH_WAIT_SAI_RESYNC, |
| 52 | /* waiting for response from subscr, resync case */ |
| 53 | VLR_SUB_AS_WAIT_RESP_RESYNC, |
| 54 | /* waiting for IMSI from subscriber */ |
| 55 | VLR_SUB_AS_WAIT_ID_IMSI, |
| 56 | /* authentication has failed */ |
| 57 | VLR_SUB_AS_AUTH_FAILED, |
| 58 | }; |
| 59 | |
| 60 | enum vlr_lu_event { |
| 61 | VLR_ULA_E_UPDATE_LA, /* Initial trigger (LU from MS) */ |
| 62 | VLR_ULA_E_SEND_ID_ACK, /* Result of Send-ID from PVLR */ |
| 63 | VLR_ULA_E_SEND_ID_NACK, /* Result of Send-ID from PVLR */ |
| 64 | VLR_ULA_E_AUTH_RES, /* Result of auth procedure */ |
| 65 | VLR_ULA_E_CIPH_RES, /* Result of Ciphering Mode Command */ |
| 66 | VLR_ULA_E_ID_IMSI, /* IMSI recieved from MS */ |
| 67 | VLR_ULA_E_ID_IMEI, /* IMEI received from MS */ |
| 68 | VLR_ULA_E_ID_IMEISV, /* IMEISV received from MS */ |
Oliver Smith | 7d05309 | 2018-12-14 17:37:38 +0100 | [diff] [blame] | 69 | VLR_ULA_E_HLR_IMEI_ACK, /* Check_IMEI_VLR result from HLR */ |
| 70 | VLR_ULA_E_HLR_IMEI_NACK,/* Check_IMEI_VLR result from HLR */ |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 71 | VLR_ULA_E_HLR_LU_RES, /* HLR UpdateLocation result */ |
| 72 | VLR_ULA_E_UPD_HLR_COMPL,/* UpdatE_HLR_VLR result */ |
| 73 | VLR_ULA_E_LU_COMPL_SUCCESS,/* Location_Update_Completion_VLR result */ |
| 74 | VLR_ULA_E_LU_COMPL_FAILURE,/* Location_Update_Completion_VLR result */ |
| 75 | VLR_ULA_E_NEW_TMSI_ACK, /* TMSI Reallocation Complete */ |
| 76 | }; |
| 77 | |
| 78 | enum vlr_ciph_result_cause { |
| 79 | VLR_CIPH_REJECT, /* ? */ |
| 80 | VLR_CIPH_COMPL, |
| 81 | }; |
| 82 | |
Neels Hofmeyr | 8b6e536 | 2018-11-30 02:57:33 +0100 | [diff] [blame] | 83 | struct vlr_auth_tuple { |
| 84 | int use_count; |
| 85 | int key_seq; |
| 86 | struct osmo_auth_vector vec; |
| 87 | }; |
| 88 | #define VLR_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */ |
| 89 | |
| 90 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 91 | struct vlr_ciph_result { |
| 92 | enum vlr_ciph_result_cause cause; |
Neels Hofmeyr | fa10eda | 2018-03-13 01:22:01 +0100 | [diff] [blame] | 93 | char imeisv[GSM48_MI_SIZE]; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | enum vlr_subscr_security_context { |
| 97 | VLR_SEC_CTX_NONE, |
| 98 | VLR_SEC_CTX_GSM, |
| 99 | VLR_SEC_CTX_UMTS, |
| 100 | }; |
| 101 | |
| 102 | enum vlr_lu_type { |
| 103 | VLR_LU_TYPE_PERIODIC, |
| 104 | VLR_LU_TYPE_IMSI_ATTACH, |
| 105 | VLR_LU_TYPE_REGULAR, |
| 106 | }; |
| 107 | |
| 108 | #define OSMO_LBUF_DECL(name, xlen) \ |
| 109 | struct { \ |
| 110 | uint8_t buf[xlen]; \ |
| 111 | size_t len; \ |
| 112 | } name |
| 113 | |
| 114 | struct sgsn_mm_ctx; |
| 115 | struct vlr_instance; |
| 116 | |
Neels Hofmeyr | 7b61ffe | 2018-11-30 02:46:53 +0100 | [diff] [blame] | 117 | #define VLR_NAME_LENGTH 160 |
| 118 | #define VLR_MSISDN_LENGTH 15 |
| 119 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 120 | /* The VLR subscriber is the part of the GSM subscriber state in VLR (CS) or |
| 121 | * SGSN (PS), particularly while interacting with the HLR via GSUP */ |
| 122 | struct vlr_subscr { |
| 123 | struct llist_head list; |
| 124 | struct vlr_instance *vlr; |
| 125 | |
| 126 | /* TODO either populate from HLR or drop this completely? */ |
| 127 | long long unsigned int id; |
| 128 | |
| 129 | /* Data from HLR */ /* 3GPP TS 23.008 */ |
| 130 | /* Always use vlr_subscr_set_imsi() to write to imsi[] */ |
| 131 | char imsi[GSM23003_IMSI_MAX_DIGITS+1]; /* 2.1.1.1 */ |
Neels Hofmeyr | 7b61ffe | 2018-11-30 02:46:53 +0100 | [diff] [blame] | 132 | char msisdn[VLR_MSISDN_LENGTH+1]; /* 2.1.2 */ |
| 133 | char name[VLR_NAME_LENGTH+1]; /* proprietary */ |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 134 | OSMO_LBUF_DECL(hlr, 16); /* 2.4.7 */ |
| 135 | uint32_t periodic_lu_timer; /* 2.4.24 */ |
| 136 | uint32_t age_indicator; /* 2.17.1 */ |
| 137 | |
| 138 | /* Authentication Data */ |
Neels Hofmeyr | 8b6e536 | 2018-11-30 02:57:33 +0100 | [diff] [blame] | 139 | struct vlr_auth_tuple auth_tuples[5]; /* 2.3.1-2.3.4 */ |
| 140 | struct vlr_auth_tuple *last_tuple; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 141 | enum vlr_subscr_security_context sec_ctx; |
| 142 | |
| 143 | /* Data local to VLR is below */ |
| 144 | uint32_t tmsi; /* 2.1.4 */ |
| 145 | /* Newly allocated TMSI that was not yet acked by MS */ |
| 146 | uint32_t tmsi_new; |
| 147 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 148 | struct osmo_cell_global_id cgi; /* 2.4.16 */ |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 149 | |
| 150 | char imeisv[GSM23003_IMEISV_NUM_DIGITS+1]; /* 2.2.3 */ |
| 151 | char imei[GSM23003_IMEISV_NUM_DIGITS+1]; /* 2.1.9 */ |
| 152 | bool imsi_detached_flag; /* 2.7.1 */ |
| 153 | bool conf_by_radio_contact_ind; /* 2.7.4.1 */ |
| 154 | bool sub_dataconf_by_hlr_ind; /* 2.7.4.2 */ |
| 155 | bool loc_conf_in_hlr_ind; /* 2.7.4.3 */ |
| 156 | bool dormant_ind; /* 2.7.8 */ |
| 157 | bool cancel_loc_rx; /* 2.7.8A */ |
| 158 | bool ms_not_reachable_flag; /* 2.10.2 (MNRF) */ |
| 159 | bool la_allowed; |
| 160 | |
| 161 | int use_count; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 162 | |
| 163 | struct osmo_fsm_inst *lu_fsm; |
| 164 | struct osmo_fsm_inst *auth_fsm; |
| 165 | struct osmo_fsm_inst *proc_arq_fsm; |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 166 | struct osmo_fsm_inst *sgs_fsm; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 167 | |
| 168 | bool lu_complete; |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 169 | time_t expire_lu; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 170 | |
| 171 | void *msc_conn_ref; |
| 172 | |
| 173 | /* PS (SGSN) specific parts */ |
| 174 | struct { |
| 175 | struct llist_head pdp_list; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 176 | } ps; |
| 177 | /* CS (NITB/CSCN) specific parts */ |
| 178 | struct { |
| 179 | /* pending requests */ |
| 180 | bool is_paging; |
Neels Hofmeyr | 2ff5bcd | 2017-12-15 03:02:27 +0100 | [diff] [blame] | 181 | struct osmo_timer_list paging_response_timer; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 182 | /* list of struct subscr_request */ |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 183 | struct llist_head requests; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 184 | uint8_t lac; |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 185 | enum osmo_rat_type attached_via_ran; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 186 | } cs; |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 187 | /* SGs (MME) specific parts */ |
| 188 | struct { |
| 189 | struct vlr_sgs_cfg cfg; |
| 190 | char mme_name[SGS_MME_NAME_LEN + 1]; |
| 191 | struct osmo_location_area_id lai; |
| 192 | vlr_sgs_lu_response_cb_t response_cb; |
| 193 | vlr_sgs_lu_paging_cb_t paging_cb; |
| 194 | vlr_sgs_lu_mminfo_cb_t mminfo_cb; |
| 195 | enum sgsap_service_ind paging_serv_ind; |
| 196 | struct osmo_timer_list Ts5; |
| 197 | } sgs; |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 198 | |
| 199 | struct gsm_classmark classmark; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 200 | }; |
| 201 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 202 | enum vlr_ciph { |
| 203 | VLR_CIPH_NONE, /*< A5/0, no encryption */ |
| 204 | VLR_CIPH_A5_1, /*< A5/1, encryption */ |
| 205 | VLR_CIPH_A5_2, /*< A5/2, deprecated export-grade encryption */ |
| 206 | VLR_CIPH_A5_3, /*< A5/3, 'new secure' encryption */ |
| 207 | }; |
| 208 | |
Neels Hofmeyr | cf30913 | 2017-12-14 03:57:31 +0100 | [diff] [blame] | 209 | static inline uint8_t vlr_ciph_to_gsm0808_alg_id(enum vlr_ciph ciph) |
| 210 | { |
| 211 | switch (ciph) { |
| 212 | default: |
| 213 | case VLR_CIPH_NONE: |
| 214 | return GSM0808_ALG_ID_A5_0; |
| 215 | case VLR_CIPH_A5_1: |
| 216 | return GSM0808_ALG_ID_A5_1; |
| 217 | case VLR_CIPH_A5_2: |
| 218 | return GSM0808_ALG_ID_A5_2; |
| 219 | case VLR_CIPH_A5_3: |
| 220 | return GSM0808_ALG_ID_A5_3; |
| 221 | } |
| 222 | } |
| 223 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 224 | struct vlr_ops { |
| 225 | /* encode + transmit an AUTH REQ towards the MS. |
| 226 | * \param[in] at auth tuple providing rand, key_seq and autn. |
| 227 | * \param[in] send_autn True to send AUTN, for r99 UMTS auth. |
| 228 | */ |
Neels Hofmeyr | 8b6e536 | 2018-11-30 02:57:33 +0100 | [diff] [blame] | 229 | int (*tx_auth_req)(void *msc_conn_ref, struct vlr_auth_tuple *at, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 230 | bool send_autn); |
| 231 | /* encode + transmit an AUTH REJECT towards the MS */ |
| 232 | int (*tx_auth_rej)(void *msc_conn_ref); |
| 233 | |
| 234 | /* encode + transmit an IDENTITY REQUEST towards the MS */ |
| 235 | int (*tx_id_req)(void *msc_conn_ref, uint8_t mi_type); |
| 236 | |
| 237 | int (*tx_lu_acc)(void *msc_conn_ref, uint32_t send_tmsi); |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 238 | int (*tx_lu_rej)(void *msc_conn_ref, enum gsm48_reject_value cause); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 239 | int (*tx_cm_serv_acc)(void *msc_conn_ref); |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 240 | int (*tx_cm_serv_rej)(void *msc_conn_ref, enum gsm48_reject_value cause); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 241 | |
Harald Welte | 71c51df | 2017-12-23 18:51:48 +0100 | [diff] [blame] | 242 | int (*set_ciph_mode)(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 243 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 244 | /* UTRAN: send Common Id (when auth+ciph are complete) */ |
| 245 | int (*tx_common_id)(void *msc_conn_ref); |
| 246 | |
Stefan Sperling | 3a74128 | 2018-03-13 21:11:49 +0100 | [diff] [blame] | 247 | int (*tx_mm_info)(void *msc_conn_ref); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 248 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 249 | /* notify MSC/SGSN that the subscriber data in VLR has been updated */ |
| 250 | void (*subscr_update)(struct vlr_subscr *vsub); |
| 251 | /* notify MSC/SGSN that the given subscriber has been associated |
| 252 | * with this msc_conn_ref */ |
Neels Hofmeyr | 1035d90 | 2018-12-28 21:22:32 +0100 | [diff] [blame] | 253 | int (*subscr_assoc)(void *msc_conn_ref, struct vlr_subscr *vsub); |
Vadim Yanitskiy | 8a0e258 | 2018-06-14 03:54:33 +0700 | [diff] [blame] | 254 | |
| 255 | /* Forward a parsed GSUP message towards MSC message router */ |
| 256 | int (*forward_gsup_msg)(struct vlr_subscr *vsub, struct osmo_gsup_message *gsup_msg); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | enum vlr_timer { |
| 260 | VLR_T_3250, |
| 261 | VLR_T_3260, |
| 262 | VLR_T_3270, |
| 263 | _NUM_VLR_TIMERS |
| 264 | }; |
| 265 | |
| 266 | /* An instance of the VLR codebase */ |
| 267 | struct vlr_instance { |
| 268 | struct llist_head subscribers; |
| 269 | struct llist_head operations; |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 270 | struct osmo_gsup_client *gsup_client; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 271 | struct vlr_ops ops; |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 272 | struct osmo_timer_list lu_expire_timer; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 273 | struct { |
Neels Hofmeyr | 54a706c | 2017-07-18 15:39:27 +0200 | [diff] [blame] | 274 | bool retrieve_imeisv_early; |
| 275 | bool retrieve_imeisv_ciphered; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 276 | bool assign_tmsi; |
| 277 | bool check_imei_rqd; |
Neels Hofmeyr | 33f5341 | 2017-10-29 02:11:18 +0100 | [diff] [blame] | 278 | int auth_tuple_max_reuse_count; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 279 | bool auth_reuse_old_sets_on_error; |
| 280 | bool parq_retrieve_imsi; |
| 281 | bool is_ps; |
| 282 | uint32_t timer[_NUM_VLR_TIMERS]; |
| 283 | } cfg; |
| 284 | /* A free-form pointer for use by the caller */ |
| 285 | void *user_ctx; |
| 286 | }; |
| 287 | |
| 288 | extern const struct value_string vlr_ciph_names[]; |
| 289 | static inline const char *vlr_ciph_name(enum vlr_ciph val) |
| 290 | { |
| 291 | return get_value_string(vlr_ciph_names, val); |
| 292 | } |
| 293 | |
| 294 | /* Location Updating request */ |
| 295 | struct osmo_fsm_inst * |
| 296 | vlr_loc_update(struct osmo_fsm_inst *parent, |
| 297 | uint32_t parent_event_success, |
| 298 | uint32_t parent_event_failure, |
| 299 | void *parent_event_data, |
| 300 | struct vlr_instance *vlr, void *msc_conn_ref, |
| 301 | enum vlr_lu_type type, uint32_t tmsi, const char *imsi, |
| 302 | const struct osmo_location_area_id *old_lai, |
| 303 | const struct osmo_location_area_id *new_lai, |
| 304 | bool authentication_required, |
Harald Welte | 71c51df | 2017-12-23 18:51:48 +0100 | [diff] [blame] | 305 | bool ciphering_required, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 306 | bool is_r99, bool is_utran, |
| 307 | bool assign_tmsi); |
| 308 | |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 309 | void vlr_loc_update_cancel(struct osmo_fsm_inst *fi, |
| 310 | enum osmo_fsm_term_cause fsm_cause, |
| 311 | uint8_t gsm48_cause); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 312 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 313 | /* tell the VLR that the RAN connection is gone */ |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 314 | int vlr_subscr_disconnected(struct vlr_subscr *vsub); |
Max | dcc193d | 2017-12-27 19:34:15 +0100 | [diff] [blame] | 315 | bool vlr_subscr_expire(struct vlr_subscr *vsub); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 316 | int vlr_subscr_rx_id_resp(struct vlr_subscr *vsub, const uint8_t *mi, size_t mi_len); |
| 317 | int vlr_subscr_rx_auth_resp(struct vlr_subscr *vsub, bool is_r99, bool is_utran, |
| 318 | const uint8_t *res, uint8_t res_len); |
| 319 | int vlr_subscr_rx_auth_fail(struct vlr_subscr *vsub, const uint8_t *auts); |
Max | 770fbd2 | 2018-01-24 12:48:33 +0100 | [diff] [blame] | 320 | int vlr_subscr_tx_auth_fail_rep(const struct vlr_subscr *vsub) __attribute__((warn_unused_result)); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 321 | void vlr_subscr_rx_ciph_res(struct vlr_subscr *vsub, struct vlr_ciph_result *res); |
| 322 | int vlr_subscr_rx_tmsi_reall_compl(struct vlr_subscr *vsub); |
| 323 | int vlr_subscr_rx_imsi_detach(struct vlr_subscr *vsub); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 324 | |
| 325 | struct vlr_instance *vlr_alloc(void *ctx, const struct vlr_ops *ops); |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 326 | int vlr_start(struct ipaccess_unit *ipa_dev, struct vlr_instance *vlr, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 327 | const char *gsup_server_addr_str, uint16_t gsup_server_port); |
| 328 | |
| 329 | /* internal use only */ |
| 330 | |
Neels Hofmeyr | 1a5bcd5 | 2017-11-18 22:19:55 +0100 | [diff] [blame] | 331 | void sub_pres_vlr_fsm_start(struct osmo_fsm_inst **fsm, |
| 332 | struct osmo_fsm_inst *parent, |
| 333 | struct vlr_subscr *vsub, |
| 334 | uint32_t term_event); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 335 | struct osmo_fsm_inst * |
| 336 | upd_hlr_vlr_proc_start(struct osmo_fsm_inst *parent, |
| 337 | struct vlr_subscr *vsub, |
| 338 | uint32_t parent_event); |
| 339 | |
| 340 | struct osmo_fsm_inst * |
| 341 | lu_compl_vlr_proc_start(struct osmo_fsm_inst *parent, |
| 342 | struct vlr_subscr *vsub, |
| 343 | void *msc_conn_ref, |
| 344 | uint32_t parent_event_success, |
| 345 | uint32_t parent_event_failure); |
| 346 | |
| 347 | |
Oliver Smith | 5598aae | 2019-01-08 11:47:21 +0100 | [diff] [blame] | 348 | const char *vlr_subscr_name(const struct vlr_subscr *vsub); |
| 349 | const char *vlr_subscr_msisdn_or_name(const struct vlr_subscr *vsub); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 350 | |
| 351 | #define vlr_subscr_find_by_imsi(vlr, imsi) \ |
Neels Hofmeyr | c36e61e | 2018-08-20 12:41:36 +0200 | [diff] [blame] | 352 | _vlr_subscr_find_by_imsi(vlr, imsi, __FILE__, __LINE__) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 353 | #define vlr_subscr_find_or_create_by_imsi(vlr, imsi, created) \ |
| 354 | _vlr_subscr_find_or_create_by_imsi(vlr, imsi, created, \ |
Neels Hofmeyr | c36e61e | 2018-08-20 12:41:36 +0200 | [diff] [blame] | 355 | __FILE__, __LINE__) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 356 | |
| 357 | #define vlr_subscr_find_by_tmsi(vlr, tmsi) \ |
Neels Hofmeyr | c36e61e | 2018-08-20 12:41:36 +0200 | [diff] [blame] | 358 | _vlr_subscr_find_by_tmsi(vlr, tmsi, __FILE__, __LINE__) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 359 | #define vlr_subscr_find_or_create_by_tmsi(vlr, tmsi, created) \ |
| 360 | _vlr_subscr_find_or_create_by_tmsi(vlr, tmsi, created, \ |
Neels Hofmeyr | c36e61e | 2018-08-20 12:41:36 +0200 | [diff] [blame] | 361 | __FILE__, __LINE__) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 362 | |
| 363 | #define vlr_subscr_find_by_msisdn(vlr, msisdn) \ |
Neels Hofmeyr | c36e61e | 2018-08-20 12:41:36 +0200 | [diff] [blame] | 364 | _vlr_subscr_find_by_msisdn(vlr, msisdn, __FILE__, __LINE__) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 365 | |
| 366 | struct vlr_subscr *_vlr_subscr_find_by_imsi(struct vlr_instance *vlr, |
| 367 | const char *imsi, |
| 368 | const char *file, int line); |
| 369 | struct vlr_subscr *_vlr_subscr_find_or_create_by_imsi(struct vlr_instance *vlr, |
| 370 | const char *imsi, |
| 371 | bool *created, |
| 372 | const char *file, |
| 373 | int line); |
| 374 | |
| 375 | struct vlr_subscr *_vlr_subscr_find_by_tmsi(struct vlr_instance *vlr, |
| 376 | uint32_t tmsi, |
| 377 | const char *file, int line); |
| 378 | struct vlr_subscr *_vlr_subscr_find_or_create_by_tmsi(struct vlr_instance *vlr, |
| 379 | uint32_t tmsi, |
| 380 | bool *created, |
| 381 | const char *file, |
| 382 | int line); |
| 383 | |
| 384 | struct vlr_subscr *_vlr_subscr_find_by_msisdn(struct vlr_instance *vlr, |
| 385 | const char *msisdn, |
| 386 | const char *file, int line); |
| 387 | |
Neels Hofmeyr | c36e61e | 2018-08-20 12:41:36 +0200 | [diff] [blame] | 388 | #define vlr_subscr_get(sub) _vlr_subscr_get(sub, __FILE__, __LINE__) |
| 389 | #define vlr_subscr_put(sub) _vlr_subscr_put(sub, __FILE__, __LINE__) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 390 | struct vlr_subscr *_vlr_subscr_get(struct vlr_subscr *sub, const char *file, int line); |
| 391 | struct vlr_subscr *_vlr_subscr_put(struct vlr_subscr *sub, const char *file, int line); |
| 392 | |
| 393 | struct vlr_subscr *vlr_subscr_alloc(struct vlr_instance *vlr); |
| 394 | void vlr_subscr_free(struct vlr_subscr *vsub); |
| 395 | int vlr_subscr_alloc_tmsi(struct vlr_subscr *vsub); |
| 396 | |
| 397 | void vlr_subscr_set_imsi(struct vlr_subscr *vsub, const char *imsi); |
| 398 | void vlr_subscr_set_imei(struct vlr_subscr *vsub, const char *imei); |
| 399 | void vlr_subscr_set_imeisv(struct vlr_subscr *vsub, const char *imeisv); |
| 400 | void vlr_subscr_set_msisdn(struct vlr_subscr *vsub, const char *msisdn); |
| 401 | |
| 402 | bool vlr_subscr_matches_imsi(struct vlr_subscr *vsub, const char *imsi); |
| 403 | bool vlr_subscr_matches_tmsi(struct vlr_subscr *vsub, uint32_t tmsi); |
| 404 | bool vlr_subscr_matches_msisdn(struct vlr_subscr *vsub, const char *msisdn); |
| 405 | bool vlr_subscr_matches_imei(struct vlr_subscr *vsub, const char *imei); |
| 406 | |
| 407 | uint32_t vlr_timer(struct vlr_instance *vlr, uint32_t timer); |
| 408 | |
| 409 | int vlr_subscr_changed(struct vlr_subscr *vsub); |
Max | 770fbd2 | 2018-01-24 12:48:33 +0100 | [diff] [blame] | 410 | int vlr_subscr_purge(struct vlr_subscr *vsub) __attribute__((warn_unused_result)); |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 411 | void vlr_subscr_cancel_attach_fsm(struct vlr_subscr *vsub, |
| 412 | enum osmo_fsm_term_cause fsm_cause, |
| 413 | uint8_t gsm48_cause); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 414 | |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 415 | void vlr_subscr_enable_expire_lu(struct vlr_subscr *vsub); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 416 | |
| 417 | /* Process Acccess Request FSM */ |
| 418 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 419 | enum proc_arq_vlr_event { |
| 420 | PR_ARQ_E_START, |
| 421 | PR_ARQ_E_ID_IMSI, |
| 422 | PR_ARQ_E_AUTH_RES, |
| 423 | PR_ARQ_E_CIPH_RES, |
| 424 | PR_ARQ_E_UPD_LOC_RES, |
| 425 | PR_ARQ_E_TRACE_RES, |
| 426 | PR_ARQ_E_IMEI_RES, |
| 427 | PR_ARQ_E_PRES_RES, |
| 428 | PR_ARQ_E_TMSI_ACK, |
| 429 | }; |
| 430 | |
| 431 | enum vlr_parq_type { |
| 432 | VLR_PR_ARQ_T_INVALID = 0, /* to guard against unset vars */ |
| 433 | VLR_PR_ARQ_T_CM_SERV_REQ, |
| 434 | VLR_PR_ARQ_T_PAGING_RESP, |
| 435 | /* FIXME: differentiate between services of 24.008 10.5.3.3 */ |
| 436 | }; |
| 437 | |
| 438 | /* Process Access Request (CM SERV REQ / PAGING RESP) */ |
| 439 | void |
| 440 | vlr_proc_acc_req(struct osmo_fsm_inst *parent, |
| 441 | uint32_t parent_event_success, |
| 442 | uint32_t parent_event_failure, |
| 443 | void *parent_event_data, |
| 444 | struct vlr_instance *vlr, void *msc_conn_ref, |
| 445 | enum vlr_parq_type type, const uint8_t *mi_lv, |
| 446 | const struct osmo_location_area_id *lai, |
| 447 | bool authentication_required, |
Harald Welte | 71c51df | 2017-12-23 18:51:48 +0100 | [diff] [blame] | 448 | bool ciphering_required, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 449 | bool is_r99, bool is_utran); |
| 450 | |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 451 | void vlr_parq_cancel(struct osmo_fsm_inst *fi, |
| 452 | enum osmo_fsm_term_cause fsm_cause, |
| 453 | enum gsm48_reject_value gsm48_cause); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 454 | |
| 455 | void vlr_parq_fsm_init(void); |
| 456 | |
| 457 | int vlr_set_ciph_mode(struct vlr_instance *vlr, |
| 458 | struct osmo_fsm_inst *fi, |
| 459 | void *msc_conn_ref, |
Harald Welte | 71c51df | 2017-12-23 18:51:48 +0100 | [diff] [blame] | 460 | bool ciph_required, |
Neels Hofmeyr | 2ef2da5 | 2017-12-18 01:23:42 +0100 | [diff] [blame] | 461 | bool umts_aka, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 462 | bool retrieve_imeisv); |
| 463 | |
Neels Hofmeyr | e3d72d7 | 2017-12-18 02:06:44 +0100 | [diff] [blame] | 464 | bool vlr_use_umts_aka(struct osmo_auth_vector *vec, bool is_r99); |
| 465 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 466 | void log_set_filter_vlr_subscr(struct log_target *target, |
| 467 | struct vlr_subscr *vlr_subscr); |