blob: 83c8e1bf6bf218ea4069f48d30e3d7993bcdc1d2 [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>
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 Hofmeyrcf309132017-12-14 03:57:31 +010010#include <osmocom/gsm/gsm0808.h>
Vadim Yanitskiy8a0e2582018-06-14 03:54:33 +070011#include <osmocom/gsm/gsup.h>
Stefan Sperlingafa030d2018-12-06 12:06:59 +010012#include <osmocom/gsm/ipa.h>
Neels Hofmeyra8945ce2018-11-30 00:44:32 +010013#include <osmocom/msc/ran_conn.h>
Neels Hofmeyr7b61ffe2018-11-30 02:46:53 +010014#include <osmocom/msc/msc_common.h>
Harald Welte1ea6baf2018-07-31 19:40:52 +020015#include <osmocom/gsupclient/gsup_client.h>
Harald Welteb8b85a12016-06-17 00:06:42 +020016
Maxa263bb22017-12-27 13:23:44 +010017#define LOGGSUPP(level, gsup, fmt, args...) \
18 LOGP(DVLR, level, "GSUP(%s) " fmt, (gsup)->imsi, ## args)
19
20#define LOGVSUBP(level, vsub, fmt, args...) \
21 LOGP(DVLR, level, "SUBSCR(%s) " fmt, vlr_subscr_name(vsub), ## args)
22
Harald Welte2483f1b2016-06-19 18:06:02 +020023struct log_target;
24
Stefan Sperlingdefc3c82018-05-15 14:48:04 +020025#define VLR_SUBSCRIBER_NO_EXPIRATION 0
26#define VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL 60 /* in seconds */
27
Harald Welteb8b85a12016-06-17 00:06:42 +020028/* from 3s to 10s */
29#define GSM_29002_TIMER_S 10
30/* from 15s to 30s */
31#define GSM_29002_TIMER_M 30
32/* from 1min to 10min */
33#define GSM_29002_TIMER_ML (10*60)
34/* from 28h to 38h */
35#define GSM_29002_TIMER_L (32*60*60)
36
Harald Welteb8b85a12016-06-17 00:06:42 +020037/* VLR subscriber authentication state */
38enum vlr_subscr_auth_state {
39 /* subscriber needs to be autenticated */
40 VLR_SUB_AS_NEEDS_AUTH,
41 /* waiting for AuthInfo from HLR/AUC */
42 VLR_SUB_AS_NEEDS_AUTH_WAIT_AI,
43 /* waiting for response from subscriber */
44 VLR_SUB_AS_WAIT_RESP,
45 /* successfully authenticated */
46 VLR_SUB_AS_AUTHENTICATED,
47 /* subscriber needs re-sync */
48 VLR_SUB_AS_NEEDS_RESYNC,
49 /* waiting for AuthInfo with ReSync */
50 VLR_SUB_AS_NEEDS_AUTH_WAIT_SAI_RESYNC,
51 /* waiting for response from subscr, resync case */
52 VLR_SUB_AS_WAIT_RESP_RESYNC,
53 /* waiting for IMSI from subscriber */
54 VLR_SUB_AS_WAIT_ID_IMSI,
55 /* authentication has failed */
56 VLR_SUB_AS_AUTH_FAILED,
57};
58
59enum vlr_lu_event {
60 VLR_ULA_E_UPDATE_LA, /* Initial trigger (LU from MS) */
61 VLR_ULA_E_SEND_ID_ACK, /* Result of Send-ID from PVLR */
62 VLR_ULA_E_SEND_ID_NACK, /* Result of Send-ID from PVLR */
63 VLR_ULA_E_AUTH_RES, /* Result of auth procedure */
64 VLR_ULA_E_CIPH_RES, /* Result of Ciphering Mode Command */
65 VLR_ULA_E_ID_IMSI, /* IMSI recieved from MS */
66 VLR_ULA_E_ID_IMEI, /* IMEI received from MS */
67 VLR_ULA_E_ID_IMEISV, /* IMEISV received from MS */
Oliver Smith7d053092018-12-14 17:37:38 +010068 VLR_ULA_E_HLR_IMEI_ACK, /* Check_IMEI_VLR result from HLR */
69 VLR_ULA_E_HLR_IMEI_NACK,/* Check_IMEI_VLR result from HLR */
Harald Welteb8b85a12016-06-17 00:06:42 +020070 VLR_ULA_E_HLR_LU_RES, /* HLR UpdateLocation result */
71 VLR_ULA_E_UPD_HLR_COMPL,/* UpdatE_HLR_VLR result */
72 VLR_ULA_E_LU_COMPL_SUCCESS,/* Location_Update_Completion_VLR result */
73 VLR_ULA_E_LU_COMPL_FAILURE,/* Location_Update_Completion_VLR result */
74 VLR_ULA_E_NEW_TMSI_ACK, /* TMSI Reallocation Complete */
75};
76
77enum vlr_ciph_result_cause {
78 VLR_CIPH_REJECT, /* ? */
79 VLR_CIPH_COMPL,
80};
81
Neels Hofmeyr8b6e5362018-11-30 02:57:33 +010082struct vlr_auth_tuple {
83 int use_count;
84 int key_seq;
85 struct osmo_auth_vector vec;
86};
87#define VLR_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
88
89
Harald Welteb8b85a12016-06-17 00:06:42 +020090struct vlr_ciph_result {
91 enum vlr_ciph_result_cause cause;
Neels Hofmeyrfa10eda2018-03-13 01:22:01 +010092 char imeisv[GSM48_MI_SIZE];
Harald Welteb8b85a12016-06-17 00:06:42 +020093};
94
95enum vlr_subscr_security_context {
96 VLR_SEC_CTX_NONE,
97 VLR_SEC_CTX_GSM,
98 VLR_SEC_CTX_UMTS,
99};
100
101enum vlr_lu_type {
102 VLR_LU_TYPE_PERIODIC,
103 VLR_LU_TYPE_IMSI_ATTACH,
104 VLR_LU_TYPE_REGULAR,
105};
106
107#define OSMO_LBUF_DECL(name, xlen) \
108 struct { \
109 uint8_t buf[xlen]; \
110 size_t len; \
111 } name
112
113struct sgsn_mm_ctx;
114struct vlr_instance;
115
Neels Hofmeyr7b61ffe2018-11-30 02:46:53 +0100116#define VLR_NAME_LENGTH 160
117#define VLR_MSISDN_LENGTH 15
118
Harald Welteb8b85a12016-06-17 00:06:42 +0200119/* The VLR subscriber is the part of the GSM subscriber state in VLR (CS) or
120 * SGSN (PS), particularly while interacting with the HLR via GSUP */
121struct vlr_subscr {
122 struct llist_head list;
123 struct vlr_instance *vlr;
124
125 /* TODO either populate from HLR or drop this completely? */
126 long long unsigned int id;
127
128 /* Data from HLR */ /* 3GPP TS 23.008 */
129 /* Always use vlr_subscr_set_imsi() to write to imsi[] */
130 char imsi[GSM23003_IMSI_MAX_DIGITS+1]; /* 2.1.1.1 */
Neels Hofmeyr7b61ffe2018-11-30 02:46:53 +0100131 char msisdn[VLR_MSISDN_LENGTH+1]; /* 2.1.2 */
132 char name[VLR_NAME_LENGTH+1]; /* proprietary */
Harald Welteb8b85a12016-06-17 00:06:42 +0200133 OSMO_LBUF_DECL(hlr, 16); /* 2.4.7 */
134 uint32_t periodic_lu_timer; /* 2.4.24 */
135 uint32_t age_indicator; /* 2.17.1 */
136
137 /* Authentication Data */
Neels Hofmeyr8b6e5362018-11-30 02:57:33 +0100138 struct vlr_auth_tuple auth_tuples[5]; /* 2.3.1-2.3.4 */
139 struct vlr_auth_tuple *last_tuple;
Harald Welteb8b85a12016-06-17 00:06:42 +0200140 enum vlr_subscr_security_context sec_ctx;
141
142 /* Data local to VLR is below */
143 uint32_t tmsi; /* 2.1.4 */
144 /* Newly allocated TMSI that was not yet acked by MS */
145 uint32_t tmsi_new;
146
Harald Welteb8b85a12016-06-17 00:06:42 +0200147 struct osmo_cell_global_id cgi; /* 2.4.16 */
Harald Welteb8b85a12016-06-17 00:06:42 +0200148
149 char imeisv[GSM23003_IMEISV_NUM_DIGITS+1]; /* 2.2.3 */
150 char imei[GSM23003_IMEISV_NUM_DIGITS+1]; /* 2.1.9 */
151 bool imsi_detached_flag; /* 2.7.1 */
152 bool conf_by_radio_contact_ind; /* 2.7.4.1 */
153 bool sub_dataconf_by_hlr_ind; /* 2.7.4.2 */
154 bool loc_conf_in_hlr_ind; /* 2.7.4.3 */
155 bool dormant_ind; /* 2.7.8 */
156 bool cancel_loc_rx; /* 2.7.8A */
157 bool ms_not_reachable_flag; /* 2.10.2 (MNRF) */
158 bool la_allowed;
159
160 int use_count;
Harald Welteb8b85a12016-06-17 00:06:42 +0200161
162 struct osmo_fsm_inst *lu_fsm;
163 struct osmo_fsm_inst *auth_fsm;
164 struct osmo_fsm_inst *proc_arq_fsm;
165
166 bool lu_complete;
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200167 time_t expire_lu;
Harald Welteb8b85a12016-06-17 00:06:42 +0200168
169 void *msc_conn_ref;
170
171 /* PS (SGSN) specific parts */
172 struct {
173 struct llist_head pdp_list;
Harald Welteb8b85a12016-06-17 00:06:42 +0200174 } ps;
175 /* CS (NITB/CSCN) specific parts */
176 struct {
177 /* pending requests */
178 bool is_paging;
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100179 struct osmo_timer_list paging_response_timer;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200180 /* list of struct subscr_request */
Harald Welteb8b85a12016-06-17 00:06:42 +0200181 struct llist_head requests;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200182 uint8_t lac;
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100183 enum osmo_rat_type attached_via_ran;
Harald Welteb8b85a12016-06-17 00:06:42 +0200184 } cs;
Neels Hofmeyr986fe7e2018-09-13 03:05:52 +0200185
186 struct gsm_classmark classmark;
Harald Welteb8b85a12016-06-17 00:06:42 +0200187};
188
Harald Welteb8b85a12016-06-17 00:06:42 +0200189enum vlr_ciph {
190 VLR_CIPH_NONE, /*< A5/0, no encryption */
191 VLR_CIPH_A5_1, /*< A5/1, encryption */
192 VLR_CIPH_A5_2, /*< A5/2, deprecated export-grade encryption */
193 VLR_CIPH_A5_3, /*< A5/3, 'new secure' encryption */
194};
195
Neels Hofmeyrcf309132017-12-14 03:57:31 +0100196static inline uint8_t vlr_ciph_to_gsm0808_alg_id(enum vlr_ciph ciph)
197{
198 switch (ciph) {
199 default:
200 case VLR_CIPH_NONE:
201 return GSM0808_ALG_ID_A5_0;
202 case VLR_CIPH_A5_1:
203 return GSM0808_ALG_ID_A5_1;
204 case VLR_CIPH_A5_2:
205 return GSM0808_ALG_ID_A5_2;
206 case VLR_CIPH_A5_3:
207 return GSM0808_ALG_ID_A5_3;
208 }
209}
210
Harald Welteb8b85a12016-06-17 00:06:42 +0200211struct vlr_ops {
212 /* encode + transmit an AUTH REQ towards the MS.
213 * \param[in] at auth tuple providing rand, key_seq and autn.
214 * \param[in] send_autn True to send AUTN, for r99 UMTS auth.
215 */
Neels Hofmeyr8b6e5362018-11-30 02:57:33 +0100216 int (*tx_auth_req)(void *msc_conn_ref, struct vlr_auth_tuple *at,
Harald Welteb8b85a12016-06-17 00:06:42 +0200217 bool send_autn);
218 /* encode + transmit an AUTH REJECT towards the MS */
219 int (*tx_auth_rej)(void *msc_conn_ref);
220
221 /* encode + transmit an IDENTITY REQUEST towards the MS */
222 int (*tx_id_req)(void *msc_conn_ref, uint8_t mi_type);
223
224 int (*tx_lu_acc)(void *msc_conn_ref, uint32_t send_tmsi);
Neels Hofmeyr15809592018-04-06 02:57:51 +0200225 int (*tx_lu_rej)(void *msc_conn_ref, enum gsm48_reject_value cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200226 int (*tx_cm_serv_acc)(void *msc_conn_ref);
Neels Hofmeyr15809592018-04-06 02:57:51 +0200227 int (*tx_cm_serv_rej)(void *msc_conn_ref, enum gsm48_reject_value cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200228
Harald Welte71c51df2017-12-23 18:51:48 +0100229 int (*set_ciph_mode)(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv);
Harald Welteb8b85a12016-06-17 00:06:42 +0200230
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200231 /* UTRAN: send Common Id (when auth+ciph are complete) */
232 int (*tx_common_id)(void *msc_conn_ref);
233
Stefan Sperling3a741282018-03-13 21:11:49 +0100234 int (*tx_mm_info)(void *msc_conn_ref);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200235
Harald Welteb8b85a12016-06-17 00:06:42 +0200236 /* notify MSC/SGSN that the subscriber data in VLR has been updated */
237 void (*subscr_update)(struct vlr_subscr *vsub);
238 /* notify MSC/SGSN that the given subscriber has been associated
239 * with this msc_conn_ref */
Neels Hofmeyr1035d902018-12-28 21:22:32 +0100240 int (*subscr_assoc)(void *msc_conn_ref, struct vlr_subscr *vsub);
Vadim Yanitskiy8a0e2582018-06-14 03:54:33 +0700241
242 /* Forward a parsed GSUP message towards MSC message router */
243 int (*forward_gsup_msg)(struct vlr_subscr *vsub, struct osmo_gsup_message *gsup_msg);
Harald Welteb8b85a12016-06-17 00:06:42 +0200244};
245
246enum vlr_timer {
247 VLR_T_3250,
248 VLR_T_3260,
249 VLR_T_3270,
250 _NUM_VLR_TIMERS
251};
252
253/* An instance of the VLR codebase */
254struct vlr_instance {
255 struct llist_head subscribers;
256 struct llist_head operations;
Harald Welte1ea6baf2018-07-31 19:40:52 +0200257 struct osmo_gsup_client *gsup_client;
Harald Welteb8b85a12016-06-17 00:06:42 +0200258 struct vlr_ops ops;
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200259 struct osmo_timer_list lu_expire_timer;
Harald Welteb8b85a12016-06-17 00:06:42 +0200260 struct {
Neels Hofmeyr54a706c2017-07-18 15:39:27 +0200261 bool retrieve_imeisv_early;
262 bool retrieve_imeisv_ciphered;
Harald Welteb8b85a12016-06-17 00:06:42 +0200263 bool assign_tmsi;
264 bool check_imei_rqd;
Neels Hofmeyr33f53412017-10-29 02:11:18 +0100265 int auth_tuple_max_reuse_count;
Harald Welteb8b85a12016-06-17 00:06:42 +0200266 bool auth_reuse_old_sets_on_error;
267 bool parq_retrieve_imsi;
268 bool is_ps;
269 uint32_t timer[_NUM_VLR_TIMERS];
270 } cfg;
271 /* A free-form pointer for use by the caller */
272 void *user_ctx;
273};
274
275extern const struct value_string vlr_ciph_names[];
276static inline const char *vlr_ciph_name(enum vlr_ciph val)
277{
278 return get_value_string(vlr_ciph_names, val);
279}
280
281/* Location Updating request */
282struct osmo_fsm_inst *
283vlr_loc_update(struct osmo_fsm_inst *parent,
284 uint32_t parent_event_success,
285 uint32_t parent_event_failure,
286 void *parent_event_data,
287 struct vlr_instance *vlr, void *msc_conn_ref,
288 enum vlr_lu_type type, uint32_t tmsi, const char *imsi,
289 const struct osmo_location_area_id *old_lai,
290 const struct osmo_location_area_id *new_lai,
291 bool authentication_required,
Harald Welte71c51df2017-12-23 18:51:48 +0100292 bool ciphering_required,
Harald Welteb8b85a12016-06-17 00:06:42 +0200293 bool is_r99, bool is_utran,
294 bool assign_tmsi);
295
Neels Hofmeyr15809592018-04-06 02:57:51 +0200296void vlr_loc_update_cancel(struct osmo_fsm_inst *fi,
297 enum osmo_fsm_term_cause fsm_cause,
298 uint8_t gsm48_cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200299
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100300/* tell the VLR that the RAN connection is gone */
Harald Welteb8b85a12016-06-17 00:06:42 +0200301int vlr_subscr_disconnected(struct vlr_subscr *vsub);
Maxdcc193d2017-12-27 19:34:15 +0100302bool vlr_subscr_expire(struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200303int vlr_subscr_rx_id_resp(struct vlr_subscr *vsub, const uint8_t *mi, size_t mi_len);
304int vlr_subscr_rx_auth_resp(struct vlr_subscr *vsub, bool is_r99, bool is_utran,
305 const uint8_t *res, uint8_t res_len);
306int vlr_subscr_rx_auth_fail(struct vlr_subscr *vsub, const uint8_t *auts);
Max770fbd22018-01-24 12:48:33 +0100307int vlr_subscr_tx_auth_fail_rep(const struct vlr_subscr *vsub) __attribute__((warn_unused_result));
Harald Welteb8b85a12016-06-17 00:06:42 +0200308void vlr_subscr_rx_ciph_res(struct vlr_subscr *vsub, struct vlr_ciph_result *res);
309int vlr_subscr_rx_tmsi_reall_compl(struct vlr_subscr *vsub);
310int vlr_subscr_rx_imsi_detach(struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200311
312struct vlr_instance *vlr_alloc(void *ctx, const struct vlr_ops *ops);
Stefan Sperlingafa030d2018-12-06 12:06:59 +0100313int vlr_start(struct ipaccess_unit *ipa_dev, struct vlr_instance *vlr,
Harald Welteb8b85a12016-06-17 00:06:42 +0200314 const char *gsup_server_addr_str, uint16_t gsup_server_port);
315
316/* internal use only */
317
Neels Hofmeyr1a5bcd52017-11-18 22:19:55 +0100318void sub_pres_vlr_fsm_start(struct osmo_fsm_inst **fsm,
319 struct osmo_fsm_inst *parent,
320 struct vlr_subscr *vsub,
321 uint32_t term_event);
Harald Welteb8b85a12016-06-17 00:06:42 +0200322struct osmo_fsm_inst *
323upd_hlr_vlr_proc_start(struct osmo_fsm_inst *parent,
324 struct vlr_subscr *vsub,
325 uint32_t parent_event);
326
327struct osmo_fsm_inst *
328lu_compl_vlr_proc_start(struct osmo_fsm_inst *parent,
329 struct vlr_subscr *vsub,
330 void *msc_conn_ref,
331 uint32_t parent_event_success,
332 uint32_t parent_event_failure);
333
334
Oliver Smith5598aae2019-01-08 11:47:21 +0100335const char *vlr_subscr_name(const struct vlr_subscr *vsub);
336const char *vlr_subscr_msisdn_or_name(const struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200337
338#define vlr_subscr_find_by_imsi(vlr, imsi) \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200339 _vlr_subscr_find_by_imsi(vlr, imsi, __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200340#define vlr_subscr_find_or_create_by_imsi(vlr, imsi, created) \
341 _vlr_subscr_find_or_create_by_imsi(vlr, imsi, created, \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200342 __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200343
344#define vlr_subscr_find_by_tmsi(vlr, tmsi) \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200345 _vlr_subscr_find_by_tmsi(vlr, tmsi, __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200346#define vlr_subscr_find_or_create_by_tmsi(vlr, tmsi, created) \
347 _vlr_subscr_find_or_create_by_tmsi(vlr, tmsi, created, \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200348 __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200349
350#define vlr_subscr_find_by_msisdn(vlr, msisdn) \
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200351 _vlr_subscr_find_by_msisdn(vlr, msisdn, __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200352
353struct vlr_subscr *_vlr_subscr_find_by_imsi(struct vlr_instance *vlr,
354 const char *imsi,
355 const char *file, int line);
356struct vlr_subscr *_vlr_subscr_find_or_create_by_imsi(struct vlr_instance *vlr,
357 const char *imsi,
358 bool *created,
359 const char *file,
360 int line);
361
362struct vlr_subscr *_vlr_subscr_find_by_tmsi(struct vlr_instance *vlr,
363 uint32_t tmsi,
364 const char *file, int line);
365struct vlr_subscr *_vlr_subscr_find_or_create_by_tmsi(struct vlr_instance *vlr,
366 uint32_t tmsi,
367 bool *created,
368 const char *file,
369 int line);
370
371struct vlr_subscr *_vlr_subscr_find_by_msisdn(struct vlr_instance *vlr,
372 const char *msisdn,
373 const char *file, int line);
374
Neels Hofmeyrc36e61e2018-08-20 12:41:36 +0200375#define vlr_subscr_get(sub) _vlr_subscr_get(sub, __FILE__, __LINE__)
376#define vlr_subscr_put(sub) _vlr_subscr_put(sub, __FILE__, __LINE__)
Harald Welteb8b85a12016-06-17 00:06:42 +0200377struct vlr_subscr *_vlr_subscr_get(struct vlr_subscr *sub, const char *file, int line);
378struct vlr_subscr *_vlr_subscr_put(struct vlr_subscr *sub, const char *file, int line);
379
380struct vlr_subscr *vlr_subscr_alloc(struct vlr_instance *vlr);
381void vlr_subscr_free(struct vlr_subscr *vsub);
382int vlr_subscr_alloc_tmsi(struct vlr_subscr *vsub);
383
384void vlr_subscr_set_imsi(struct vlr_subscr *vsub, const char *imsi);
385void vlr_subscr_set_imei(struct vlr_subscr *vsub, const char *imei);
386void vlr_subscr_set_imeisv(struct vlr_subscr *vsub, const char *imeisv);
387void vlr_subscr_set_msisdn(struct vlr_subscr *vsub, const char *msisdn);
388
389bool vlr_subscr_matches_imsi(struct vlr_subscr *vsub, const char *imsi);
390bool vlr_subscr_matches_tmsi(struct vlr_subscr *vsub, uint32_t tmsi);
391bool vlr_subscr_matches_msisdn(struct vlr_subscr *vsub, const char *msisdn);
392bool vlr_subscr_matches_imei(struct vlr_subscr *vsub, const char *imei);
393
394uint32_t vlr_timer(struct vlr_instance *vlr, uint32_t timer);
395
396int vlr_subscr_changed(struct vlr_subscr *vsub);
Max770fbd22018-01-24 12:48:33 +0100397int vlr_subscr_purge(struct vlr_subscr *vsub) __attribute__((warn_unused_result));
Neels Hofmeyr15809592018-04-06 02:57:51 +0200398void vlr_subscr_cancel_attach_fsm(struct vlr_subscr *vsub,
399 enum osmo_fsm_term_cause fsm_cause,
400 uint8_t gsm48_cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200401
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200402void vlr_subscr_enable_expire_lu(struct vlr_subscr *vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200403
404/* Process Acccess Request FSM */
405
Harald Welteb8b85a12016-06-17 00:06:42 +0200406enum proc_arq_vlr_event {
407 PR_ARQ_E_START,
408 PR_ARQ_E_ID_IMSI,
409 PR_ARQ_E_AUTH_RES,
410 PR_ARQ_E_CIPH_RES,
411 PR_ARQ_E_UPD_LOC_RES,
412 PR_ARQ_E_TRACE_RES,
413 PR_ARQ_E_IMEI_RES,
414 PR_ARQ_E_PRES_RES,
415 PR_ARQ_E_TMSI_ACK,
416};
417
418enum vlr_parq_type {
419 VLR_PR_ARQ_T_INVALID = 0, /* to guard against unset vars */
420 VLR_PR_ARQ_T_CM_SERV_REQ,
421 VLR_PR_ARQ_T_PAGING_RESP,
422 /* FIXME: differentiate between services of 24.008 10.5.3.3 */
423};
424
425/* Process Access Request (CM SERV REQ / PAGING RESP) */
426void
427vlr_proc_acc_req(struct osmo_fsm_inst *parent,
428 uint32_t parent_event_success,
429 uint32_t parent_event_failure,
430 void *parent_event_data,
431 struct vlr_instance *vlr, void *msc_conn_ref,
432 enum vlr_parq_type type, const uint8_t *mi_lv,
433 const struct osmo_location_area_id *lai,
434 bool authentication_required,
Harald Welte71c51df2017-12-23 18:51:48 +0100435 bool ciphering_required,
Harald Welteb8b85a12016-06-17 00:06:42 +0200436 bool is_r99, bool is_utran);
437
Neels Hofmeyr15809592018-04-06 02:57:51 +0200438void vlr_parq_cancel(struct osmo_fsm_inst *fi,
439 enum osmo_fsm_term_cause fsm_cause,
440 enum gsm48_reject_value gsm48_cause);
Harald Welteb8b85a12016-06-17 00:06:42 +0200441
442void vlr_parq_fsm_init(void);
443
444int vlr_set_ciph_mode(struct vlr_instance *vlr,
445 struct osmo_fsm_inst *fi,
446 void *msc_conn_ref,
Harald Welte71c51df2017-12-23 18:51:48 +0100447 bool ciph_required,
Neels Hofmeyr2ef2da52017-12-18 01:23:42 +0100448 bool umts_aka,
Harald Welteb8b85a12016-06-17 00:06:42 +0200449 bool retrieve_imeisv);
450
Neels Hofmeyre3d72d72017-12-18 02:06:44 +0100451bool vlr_use_umts_aka(struct osmo_auth_vector *vec, bool is_r99);
452
Harald Welteb8b85a12016-06-17 00:06:42 +0200453void log_set_filter_vlr_subscr(struct log_target *target,
454 struct vlr_subscr *vlr_subscr);