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