blob: b1c0d5ddeac8d6a4badb37b472c56d66f7126a14 [file] [log] [blame]
Harald Welteb8b85a12016-06-17 00:06:42 +02001#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>
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01007#include <osmocom/core/use_count.h>
Harald Welteb8b85a12016-06-17 00:06:42 +02008#include <osmocom/gsm/protocol/gsm_23_003.h>
9#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
10#include <osmocom/gsm/gsm23003.h>
Neels Hofmeyrcf309132017-12-14 03:57:31 +010011#include <osmocom/gsm/gsm0808.h>
Vadim Yanitskiy8a0e2582018-06-14 03:54:33 +070012#include <osmocom/gsm/gsup.h>
Stefan Sperlingafa030d2018-12-06 12:06:59 +010013#include <osmocom/gsm/ipa.h>
Neels Hofmeyra8945ce2018-11-30 00:44:32 +010014#include <osmocom/msc/ran_conn.h>
Neels Hofmeyr7b61ffe2018-11-30 02:46:53 +010015#include <osmocom/msc/msc_common.h>
Harald Welte1ea6baf2018-07-31 19:40:52 +020016#include <osmocom/gsupclient/gsup_client.h>
Harald Welte0df904d2018-12-03 11:00:04 +010017#include <osmocom/msc/vlr_sgs.h>
Harald Welteb8b85a12016-06-17 00:06:42 +020018
Maxa263bb22017-12-27 13:23:44 +010019#define LOGGSUPP(level, gsup, fmt, args...) \
20 LOGP(DVLR, level, "GSUP(%s) " fmt, (gsup)->imsi, ## args)
21
22#define LOGVSUBP(level, vsub, fmt, args...) \
23 LOGP(DVLR, level, "SUBSCR(%s) " fmt, vlr_subscr_name(vsub), ## args)
24
Harald Welte2483f1b2016-06-19 18:06:02 +020025struct log_target;
26
Stefan Sperlingdefc3c82018-05-15 14:48:04 +020027#define VLR_SUBSCRIBER_NO_EXPIRATION 0
28#define VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL 60 /* in seconds */
29
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +010030#define VSUB_USE_ATTACHED "attached"
31
Harald Welteb8b85a12016-06-17 00:06:42 +020032/* from 3s to 10s */
33#define GSM_29002_TIMER_S 10
34/* from 15s to 30s */
35#define GSM_29002_TIMER_M 30
36/* from 1min to 10min */
37#define GSM_29002_TIMER_ML (10*60)
38/* from 28h to 38h */
39#define GSM_29002_TIMER_L (32*60*60)
40
Harald Welteb8b85a12016-06-17 00:06:42 +020041/* VLR subscriber authentication state */
42enum vlr_subscr_auth_state {
43 /* subscriber needs to be autenticated */
44 VLR_SUB_AS_NEEDS_AUTH,
45 /* waiting for AuthInfo from HLR/AUC */
46 VLR_SUB_AS_NEEDS_AUTH_WAIT_AI,
47 /* waiting for response from subscriber */
48 VLR_SUB_AS_WAIT_RESP,
49 /* successfully authenticated */
50 VLR_SUB_AS_AUTHENTICATED,
51 /* subscriber needs re-sync */
52 VLR_SUB_AS_NEEDS_RESYNC,
53 /* waiting for AuthInfo with ReSync */
54 VLR_SUB_AS_NEEDS_AUTH_WAIT_SAI_RESYNC,
55 /* waiting for response from subscr, resync case */
56 VLR_SUB_AS_WAIT_RESP_RESYNC,
57 /* waiting for IMSI from subscriber */
58 VLR_SUB_AS_WAIT_ID_IMSI,
59 /* authentication has failed */
60 VLR_SUB_AS_AUTH_FAILED,
61};
62
63enum vlr_lu_event {
64 VLR_ULA_E_UPDATE_LA, /* Initial trigger (LU from MS) */
65 VLR_ULA_E_SEND_ID_ACK, /* Result of Send-ID from PVLR */
66 VLR_ULA_E_SEND_ID_NACK, /* Result of Send-ID from PVLR */
67 VLR_ULA_E_AUTH_RES, /* Result of auth procedure */
68 VLR_ULA_E_CIPH_RES, /* Result of Ciphering Mode Command */
69 VLR_ULA_E_ID_IMSI, /* IMSI recieved from MS */
70 VLR_ULA_E_ID_IMEI, /* IMEI received from MS */
71 VLR_ULA_E_ID_IMEISV, /* IMEISV received from MS */
Oliver Smith7d053092018-12-14 17:37:38 +010072 VLR_ULA_E_HLR_IMEI_ACK, /* Check_IMEI_VLR result from HLR */
73 VLR_ULA_E_HLR_IMEI_NACK,/* Check_IMEI_VLR result from HLR */
Harald Welteb8b85a12016-06-17 00:06:42 +020074 VLR_ULA_E_HLR_LU_RES, /* HLR UpdateLocation result */
75 VLR_ULA_E_UPD_HLR_COMPL,/* UpdatE_HLR_VLR result */
76 VLR_ULA_E_LU_COMPL_SUCCESS,/* Location_Update_Completion_VLR result */
77 VLR_ULA_E_LU_COMPL_FAILURE,/* Location_Update_Completion_VLR result */
78 VLR_ULA_E_NEW_TMSI_ACK, /* TMSI Reallocation Complete */
79};
80
81enum vlr_ciph_result_cause {
82 VLR_CIPH_REJECT, /* ? */
83 VLR_CIPH_COMPL,
84};
85
Neels Hofmeyr8b6e5362018-11-30 02:57:33 +010086struct vlr_auth_tuple {
87 int use_count;
88 int key_seq;
89 struct osmo_auth_vector vec;
90};
91#define VLR_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
92
93
Harald Welteb8b85a12016-06-17 00:06:42 +020094enum vlr_subscr_security_context {
95 VLR_SEC_CTX_NONE,
96 VLR_SEC_CTX_GSM,
97 VLR_SEC_CTX_UMTS,
98};
99
100enum vlr_lu_type {
101 VLR_LU_TYPE_PERIODIC,
102 VLR_LU_TYPE_IMSI_ATTACH,
103 VLR_LU_TYPE_REGULAR,
104};
105
106#define OSMO_LBUF_DECL(name, xlen) \
107 struct { \
108 uint8_t buf[xlen]; \
109 size_t len; \
110 } name
111
112struct sgsn_mm_ctx;
113struct vlr_instance;
114
Neels Hofmeyr7b61ffe2018-11-30 02:46:53 +0100115#define VLR_NAME_LENGTH 160
116#define VLR_MSISDN_LENGTH 15
117
Harald Welteb8b85a12016-06-17 00:06:42 +0200118/* The VLR subscriber is the part of the GSM subscriber state in VLR (CS) or
119 * SGSN (PS), particularly while interacting with the HLR via GSUP */
120struct vlr_subscr {
121 struct llist_head list;
122 struct vlr_instance *vlr;
123
124 /* TODO either populate from HLR or drop this completely? */
125 long long unsigned int id;
126
127 /* Data from HLR */ /* 3GPP TS 23.008 */
128 /* Always use vlr_subscr_set_imsi() to write to imsi[] */
129 char imsi[GSM23003_IMSI_MAX_DIGITS+1]; /* 2.1.1.1 */
Neels Hofmeyr7b61ffe2018-11-30 02:46:53 +0100130 char msisdn[VLR_MSISDN_LENGTH+1]; /* 2.1.2 */
131 char name[VLR_NAME_LENGTH+1]; /* proprietary */
Harald Welteb8b85a12016-06-17 00:06:42 +0200132 OSMO_LBUF_DECL(hlr, 16); /* 2.4.7 */
133 uint32_t periodic_lu_timer; /* 2.4.24 */
134 uint32_t age_indicator; /* 2.17.1 */
135
136 /* Authentication Data */
Neels Hofmeyr8b6e5362018-11-30 02:57:33 +0100137 struct vlr_auth_tuple auth_tuples[5]; /* 2.3.1-2.3.4 */
138 struct vlr_auth_tuple *last_tuple;
Harald Welteb8b85a12016-06-17 00:06:42 +0200139 enum vlr_subscr_security_context sec_ctx;
140
141 /* Data local to VLR is below */
142 uint32_t tmsi; /* 2.1.4 */
143 /* Newly allocated TMSI that was not yet acked by MS */
144 uint32_t tmsi_new;
145
Harald Welteb8b85a12016-06-17 00:06:42 +0200146 struct osmo_cell_global_id cgi; /* 2.4.16 */
Harald Welteb8b85a12016-06-17 00:06:42 +0200147
148 char imeisv[GSM23003_IMEISV_NUM_DIGITS+1]; /* 2.2.3 */
Oliver Smithd1037052019-05-02 13:39:26 +0200149 char imei[GSM23003_IMEI_NUM_DIGITS_NO_CHK+1]; /* 2.1.9 */
Harald Welteb8b85a12016-06-17 00:06:42 +0200150 bool imsi_detached_flag; /* 2.7.1 */
151 bool conf_by_radio_contact_ind; /* 2.7.4.1 */
152 bool sub_dataconf_by_hlr_ind; /* 2.7.4.2 */
153 bool loc_conf_in_hlr_ind; /* 2.7.4.3 */
154 bool dormant_ind; /* 2.7.8 */
155 bool cancel_loc_rx; /* 2.7.8A */
156 bool ms_not_reachable_flag; /* 2.10.2 (MNRF) */
157 bool la_allowed;
158
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100159 struct osmo_use_count use_count;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100160 struct osmo_use_count_entry use_count_buf[8];
161 int32_t max_total_use_count;
Harald Welteb8b85a12016-06-17 00:06:42 +0200162
163 struct osmo_fsm_inst *lu_fsm;
164 struct osmo_fsm_inst *auth_fsm;
165 struct osmo_fsm_inst *proc_arq_fsm;
Harald Welte0df904d2018-12-03 11:00:04 +0100166 struct osmo_fsm_inst *sgs_fsm;
Harald Welteb8b85a12016-06-17 00:06:42 +0200167
168 bool lu_complete;
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200169 time_t expire_lu;
Harald Welteb8b85a12016-06-17 00:06:42 +0200170
171 void *msc_conn_ref;
172
173 /* PS (SGSN) specific parts */
174 struct {
175 struct llist_head pdp_list;
Harald Welteb8b85a12016-06-17 00:06:42 +0200176 } ps;
177 /* CS (NITB/CSCN) specific parts */
178 struct {
179 /* pending requests */
180 bool is_paging;
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100181 struct osmo_timer_list paging_response_timer;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200182 /* list of struct subscr_request */
Harald Welteb8b85a12016-06-17 00:06:42 +0200183 struct llist_head requests;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200184 uint8_t lac;
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100185 enum osmo_rat_type attached_via_ran;
Harald Welteb8b85a12016-06-17 00:06:42 +0200186 } cs;
Harald Welte0df904d2018-12-03 11:00:04 +0100187 /* 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 Hofmeyr986fe7e2018-09-13 03:05:52 +0200198
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100199 struct osmo_gsm48_classmark classmark;
Harald Welteb8b85a12016-06-17 00:06:42 +0200200};
201
Harald Welteb8b85a12016-06-17 00:06:42 +0200202enum vlr_ciph {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100203 VLR_CIPH_NONE = 0, /*< A5/0, no encryption */
204 VLR_CIPH_A5_1 = 1, /*< A5/1, encryption */
205 VLR_CIPH_A5_2 = 2, /*< A5/2, deprecated export-grade encryption */
206 VLR_CIPH_A5_3 = 3, /*< A5/3, 'new secure' encryption */
Harald Welteb8b85a12016-06-17 00:06:42 +0200207};
208
Neels Hofmeyrcf309132017-12-14 03:57:31 +0100209static inline uint8_t vlr_ciph_to_gsm0808_alg_id(enum vlr_ciph ciph)
210{
211 switch (ciph) {
Neels Hofmeyrcf309132017-12-14 03:57:31 +0100212 case VLR_CIPH_NONE:
213 return GSM0808_ALG_ID_A5_0;
214 case VLR_CIPH_A5_1:
215 return GSM0808_ALG_ID_A5_1;
216 case VLR_CIPH_A5_2:
217 return GSM0808_ALG_ID_A5_2;
218 case VLR_CIPH_A5_3:
219 return GSM0808_ALG_ID_A5_3;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100220 default:
221 return GSM0808_ALG_ID_A5_7;
Neels Hofmeyrcf309132017-12-14 03:57:31 +0100222 }
223}
224
Harald Welteb8b85a12016-06-17 00:06:42 +0200225struct vlr_ops {
226 /* encode + transmit an AUTH REQ towards the MS.
227 * \param[in] at auth tuple providing rand, key_seq and autn.
228 * \param[in] send_autn True to send AUTN, for r99 UMTS auth.
229 */
Neels Hofmeyr8b6e5362018-11-30 02:57:33 +0100230 int (*tx_auth_req)(void *msc_conn_ref, struct vlr_auth_tuple *at,
Harald Welteb8b85a12016-06-17 00:06:42 +0200231 bool send_autn);
232 /* encode + transmit an AUTH REJECT towards the MS */
233 int (*tx_auth_rej)(void *msc_conn_ref);
234
235 /* encode + transmit an IDENTITY REQUEST towards the MS */
236 int (*tx_id_req)(void *msc_conn_ref, uint8_t mi_type);
237
238 int (*tx_lu_acc)(void *msc_conn_ref, uint32_t send_tmsi);
Neels Hofmeyr15809592018-04-06 02:57:51 +0200239 int (*tx_lu_rej)(void *msc_conn_ref, enum gsm48_reject_value cause);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100240 int (*tx_cm_serv_acc)(void *msc_conn_ref, enum osmo_cm_service_type cm_service_type);
241 int (*tx_cm_serv_rej)(void *msc_conn_ref, enum osmo_cm_service_type cm_service_type,
242 enum gsm48_reject_value cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200243
Harald Welte71c51df2017-12-23 18:51:48 +0100244 int (*set_ciph_mode)(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv);
Harald Welteb8b85a12016-06-17 00:06:42 +0200245
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200246 int (*tx_common_id)(void *msc_conn_ref);
247
Stefan Sperling3a741282018-03-13 21:11:49 +0100248 int (*tx_mm_info)(void *msc_conn_ref);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200249
Harald Welteb8b85a12016-06-17 00:06:42 +0200250 /* notify MSC/SGSN that the subscriber data in VLR has been updated */
251 void (*subscr_update)(struct vlr_subscr *vsub);
252 /* notify MSC/SGSN that the given subscriber has been associated
253 * with this msc_conn_ref */
Neels Hofmeyr1035d902018-12-28 21:22:32 +0100254 int (*subscr_assoc)(void *msc_conn_ref, struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200255};
256
257enum vlr_timer {
258 VLR_T_3250,
259 VLR_T_3260,
260 VLR_T_3270,
261 _NUM_VLR_TIMERS
262};
263
264/* An instance of the VLR codebase */
265struct vlr_instance {
266 struct llist_head subscribers;
267 struct llist_head operations;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100268 struct gsup_client_mux *gcm;
Harald Welteb8b85a12016-06-17 00:06:42 +0200269 struct vlr_ops ops;
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200270 struct osmo_timer_list lu_expire_timer;
Harald Welteb8b85a12016-06-17 00:06:42 +0200271 struct {
Neels Hofmeyr54a706c2017-07-18 15:39:27 +0200272 bool retrieve_imeisv_early;
273 bool retrieve_imeisv_ciphered;
Harald Welteb8b85a12016-06-17 00:06:42 +0200274 bool assign_tmsi;
275 bool check_imei_rqd;
Neels Hofmeyr33f53412017-10-29 02:11:18 +0100276 int auth_tuple_max_reuse_count;
Harald Welteb8b85a12016-06-17 00:06:42 +0200277 bool auth_reuse_old_sets_on_error;
278 bool parq_retrieve_imsi;
279 bool is_ps;
280 uint32_t timer[_NUM_VLR_TIMERS];
281 } cfg;
282 /* A free-form pointer for use by the caller */
283 void *user_ctx;
284};
285
286extern const struct value_string vlr_ciph_names[];
287static inline const char *vlr_ciph_name(enum vlr_ciph val)
288{
289 return get_value_string(vlr_ciph_names, val);
290}
291
292/* Location Updating request */
293struct osmo_fsm_inst *
294vlr_loc_update(struct osmo_fsm_inst *parent,
295 uint32_t parent_event_success,
296 uint32_t parent_event_failure,
297 void *parent_event_data,
298 struct vlr_instance *vlr, void *msc_conn_ref,
299 enum vlr_lu_type type, uint32_t tmsi, const char *imsi,
300 const struct osmo_location_area_id *old_lai,
301 const struct osmo_location_area_id *new_lai,
302 bool authentication_required,
Harald Welte71c51df2017-12-23 18:51:48 +0100303 bool ciphering_required,
Sylvain Munautda9f37e2019-03-14 11:02:36 +0100304 uint8_t key_seq,
Harald Welteb8b85a12016-06-17 00:06:42 +0200305 bool is_r99, bool is_utran,
306 bool assign_tmsi);
307
Neels Hofmeyr15809592018-04-06 02:57:51 +0200308void vlr_loc_update_cancel(struct osmo_fsm_inst *fi,
309 enum osmo_fsm_term_cause fsm_cause,
310 uint8_t gsm48_cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200311
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100312/* tell the VLR that the RAN connection is gone */
Harald Welteb8b85a12016-06-17 00:06:42 +0200313int vlr_subscr_disconnected(struct vlr_subscr *vsub);
Maxdcc193d2017-12-27 19:34:15 +0100314bool vlr_subscr_expire(struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200315int vlr_subscr_rx_id_resp(struct vlr_subscr *vsub, const uint8_t *mi, size_t mi_len);
316int vlr_subscr_rx_auth_resp(struct vlr_subscr *vsub, bool is_r99, bool is_utran,
317 const uint8_t *res, uint8_t res_len);
318int vlr_subscr_rx_auth_fail(struct vlr_subscr *vsub, const uint8_t *auts);
Max770fbd22018-01-24 12:48:33 +0100319int vlr_subscr_tx_auth_fail_rep(const struct vlr_subscr *vsub) __attribute__((warn_unused_result));
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100320void vlr_subscr_rx_ciph_res(struct vlr_subscr *vsub, enum vlr_ciph_result_cause result);
Harald Welteb8b85a12016-06-17 00:06:42 +0200321int vlr_subscr_rx_tmsi_reall_compl(struct vlr_subscr *vsub);
322int vlr_subscr_rx_imsi_detach(struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200323
324struct vlr_instance *vlr_alloc(void *ctx, const struct vlr_ops *ops);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100325int vlr_start(struct vlr_instance *vlr, struct gsup_client_mux *gcm);
326int vlr_gsup_rx(struct gsup_client_mux *gcm, void *data, const struct osmo_gsup_message *gsup_msg);
Harald Welteb8b85a12016-06-17 00:06:42 +0200327
328/* internal use only */
329
Neels Hofmeyr1a5bcd52017-11-18 22:19:55 +0100330void sub_pres_vlr_fsm_start(struct osmo_fsm_inst **fsm,
331 struct osmo_fsm_inst *parent,
332 struct vlr_subscr *vsub,
333 uint32_t term_event);
Harald Welteb8b85a12016-06-17 00:06:42 +0200334struct osmo_fsm_inst *
335upd_hlr_vlr_proc_start(struct osmo_fsm_inst *parent,
336 struct vlr_subscr *vsub,
337 uint32_t parent_event);
338
339struct osmo_fsm_inst *
340lu_compl_vlr_proc_start(struct osmo_fsm_inst *parent,
341 struct vlr_subscr *vsub,
342 void *msc_conn_ref,
343 uint32_t parent_event_success,
344 uint32_t parent_event_failure);
345
346
Oliver Smith5598aae2019-01-08 11:47:21 +0100347const char *vlr_subscr_name(const struct vlr_subscr *vsub);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100348const char *vlr_subscr_short_name(const struct vlr_subscr *vsub, unsigned int maxlen);
Oliver Smith5598aae2019-01-08 11:47:21 +0100349const char *vlr_subscr_msisdn_or_name(const struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200350
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100351#define vlr_subscr_find_by_imsi(vlr, imsi, USE) \
352 _vlr_subscr_find_by_imsi(vlr, imsi, USE, __FILE__, __LINE__)
353#define vlr_subscr_find_or_create_by_imsi(vlr, imsi, USE, created) \
354 _vlr_subscr_find_or_create_by_imsi(vlr, imsi, USE, created, \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200355 __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200356
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100357#define vlr_subscr_find_by_tmsi(vlr, tmsi, USE) \
358 _vlr_subscr_find_by_tmsi(vlr, tmsi, USE, __FILE__, __LINE__)
359#define vlr_subscr_find_or_create_by_tmsi(vlr, tmsi, USE, created) \
360 _vlr_subscr_find_or_create_by_tmsi(vlr, tmsi, USE, created, \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200361 __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200362
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100363#define vlr_subscr_find_by_msisdn(vlr, msisdn, USE) \
364 _vlr_subscr_find_by_msisdn(vlr, msisdn, USE, __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200365
366struct vlr_subscr *_vlr_subscr_find_by_imsi(struct vlr_instance *vlr,
367 const char *imsi,
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100368 const char *use,
Harald Welteb8b85a12016-06-17 00:06:42 +0200369 const char *file, int line);
370struct vlr_subscr *_vlr_subscr_find_or_create_by_imsi(struct vlr_instance *vlr,
371 const char *imsi,
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100372 const char *use,
Harald Welteb8b85a12016-06-17 00:06:42 +0200373 bool *created,
374 const char *file,
375 int line);
376
377struct vlr_subscr *_vlr_subscr_find_by_tmsi(struct vlr_instance *vlr,
378 uint32_t tmsi,
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100379 const char *use,
Harald Welteb8b85a12016-06-17 00:06:42 +0200380 const char *file, int line);
381struct vlr_subscr *_vlr_subscr_find_or_create_by_tmsi(struct vlr_instance *vlr,
382 uint32_t tmsi,
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100383 const char *use,
Harald Welteb8b85a12016-06-17 00:06:42 +0200384 bool *created,
385 const char *file,
386 int line);
387
388struct vlr_subscr *_vlr_subscr_find_by_msisdn(struct vlr_instance *vlr,
389 const char *msisdn,
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100390 const char *use,
Harald Welteb8b85a12016-06-17 00:06:42 +0200391 const char *file, int line);
392
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100393#define vlr_subscr_get(VSUB, USE) vlr_subscr_get_src(VSUB, USE, __FILE__, __LINE__)
394#define vlr_subscr_put(VSUB, USE) vlr_subscr_put_src(VSUB, USE, __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200395
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100396#define vlr_subscr_get_src(VSUB, USE, SRCFILE, SRCLINE) \
Neels Hofmeyr08aae212019-04-23 15:09:04 +0200397 OSMO_ASSERT((VSUB) && _osmo_use_count_get_put(&(VSUB)->use_count, USE, 1, SRCFILE, SRCLINE) == 0)
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100398#define vlr_subscr_put_src(VSUB, USE, SRCFILE, SRCLINE) \
Neels Hofmeyr08aae212019-04-23 15:09:04 +0200399 OSMO_ASSERT((VSUB) && _osmo_use_count_get_put(&(VSUB)->use_count, USE, -1, SRCFILE, SRCLINE) == 0)
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100400
Harald Welteb8b85a12016-06-17 00:06:42 +0200401void vlr_subscr_free(struct vlr_subscr *vsub);
402int vlr_subscr_alloc_tmsi(struct vlr_subscr *vsub);
403
404void vlr_subscr_set_imsi(struct vlr_subscr *vsub, const char *imsi);
405void vlr_subscr_set_imei(struct vlr_subscr *vsub, const char *imei);
406void vlr_subscr_set_imeisv(struct vlr_subscr *vsub, const char *imeisv);
407void vlr_subscr_set_msisdn(struct vlr_subscr *vsub, const char *msisdn);
408
409bool vlr_subscr_matches_imsi(struct vlr_subscr *vsub, const char *imsi);
410bool vlr_subscr_matches_tmsi(struct vlr_subscr *vsub, uint32_t tmsi);
411bool vlr_subscr_matches_msisdn(struct vlr_subscr *vsub, const char *msisdn);
412bool vlr_subscr_matches_imei(struct vlr_subscr *vsub, const char *imei);
413
414uint32_t vlr_timer(struct vlr_instance *vlr, uint32_t timer);
415
416int vlr_subscr_changed(struct vlr_subscr *vsub);
Max770fbd22018-01-24 12:48:33 +0100417int vlr_subscr_purge(struct vlr_subscr *vsub) __attribute__((warn_unused_result));
Neels Hofmeyr15809592018-04-06 02:57:51 +0200418void vlr_subscr_cancel_attach_fsm(struct vlr_subscr *vsub,
419 enum osmo_fsm_term_cause fsm_cause,
420 uint8_t gsm48_cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200421
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200422void vlr_subscr_enable_expire_lu(struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200423
424/* Process Acccess Request FSM */
425
Harald Welteb8b85a12016-06-17 00:06:42 +0200426enum proc_arq_vlr_event {
427 PR_ARQ_E_START,
428 PR_ARQ_E_ID_IMSI,
429 PR_ARQ_E_AUTH_RES,
430 PR_ARQ_E_CIPH_RES,
431 PR_ARQ_E_UPD_LOC_RES,
432 PR_ARQ_E_TRACE_RES,
433 PR_ARQ_E_IMEI_RES,
434 PR_ARQ_E_PRES_RES,
435 PR_ARQ_E_TMSI_ACK,
436};
437
438enum vlr_parq_type {
439 VLR_PR_ARQ_T_INVALID = 0, /* to guard against unset vars */
440 VLR_PR_ARQ_T_CM_SERV_REQ,
441 VLR_PR_ARQ_T_PAGING_RESP,
442 /* FIXME: differentiate between services of 24.008 10.5.3.3 */
443};
444
445/* Process Access Request (CM SERV REQ / PAGING RESP) */
446void
447vlr_proc_acc_req(struct osmo_fsm_inst *parent,
448 uint32_t parent_event_success,
449 uint32_t parent_event_failure,
450 void *parent_event_data,
451 struct vlr_instance *vlr, void *msc_conn_ref,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100452 enum vlr_parq_type type, enum osmo_cm_service_type cm_service_type,
453 const uint8_t *mi_lv,
Harald Welteb8b85a12016-06-17 00:06:42 +0200454 const struct osmo_location_area_id *lai,
455 bool authentication_required,
Harald Welte71c51df2017-12-23 18:51:48 +0100456 bool ciphering_required,
Sylvain Munautda9f37e2019-03-14 11:02:36 +0100457 uint8_t key_seq,
Harald Welteb8b85a12016-06-17 00:06:42 +0200458 bool is_r99, bool is_utran);
459
Neels Hofmeyr15809592018-04-06 02:57:51 +0200460void vlr_parq_cancel(struct osmo_fsm_inst *fi,
461 enum osmo_fsm_term_cause fsm_cause,
462 enum gsm48_reject_value gsm48_cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200463
464void vlr_parq_fsm_init(void);
465
466int vlr_set_ciph_mode(struct vlr_instance *vlr,
467 struct osmo_fsm_inst *fi,
468 void *msc_conn_ref,
Harald Welte71c51df2017-12-23 18:51:48 +0100469 bool ciph_required,
Neels Hofmeyr2ef2da52017-12-18 01:23:42 +0100470 bool umts_aka,
Harald Welteb8b85a12016-06-17 00:06:42 +0200471 bool retrieve_imeisv);
472
Neels Hofmeyre3d72d72017-12-18 02:06:44 +0100473bool vlr_use_umts_aka(struct osmo_auth_vector *vec, bool is_r99);
474
Harald Welteb8b85a12016-06-17 00:06:42 +0200475void log_set_filter_vlr_subscr(struct log_target *target,
476 struct vlr_subscr *vlr_subscr);