blob: 15f84b7e33b797975117ec150de3b102e745b488 [file] [log] [blame]
Harald Welteb8b85a12016-06-17 00:06:42 +02001/* Osmocom Visitor Location Register (VLR): Access Request FSMs */
2
3/* (C) 2016 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <osmocom/core/fsm.h>
23#include <osmocom/gsm/gsup.h>
24#include <openbsc/vlr.h>
25#include <openbsc/debug.h>
26
27#include "vlr_core.h"
28#include "vlr_auth_fsm.h"
29#include "vlr_lu_fsm.h"
30#include "vlr_access_req_fsm.h"
31
32#define S(x) (1 << (x))
33
34/***********************************************************************
35 * Process_Access_Request_VLR, TS 29.002 Chapter 25.4.2
36 ***********************************************************************/
37
38const struct value_string vlr_proc_arq_result_names[] = {
39 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_NONE),
40 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_SYSTEM_FAILURE),
41 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_ILLEGAL_SUBSCR),
42 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_UNIDENT_SUBSCR),
43 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_ROAMING_NOTALLOWED),
44 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_ILLEGAL_EQUIP),
45 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_UNKNOWN_ERROR),
46 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_TIMEOUT),
47 OSMO_VALUE_STRING(VLR_PR_ARQ_RES_PASSED),
48 { 0, NULL }
49};
50
51static const struct value_string proc_arq_vlr_event_names[] = {
52 OSMO_VALUE_STRING(PR_ARQ_E_START),
53 OSMO_VALUE_STRING(PR_ARQ_E_ID_IMSI),
54 OSMO_VALUE_STRING(PR_ARQ_E_AUTH_RES),
55 OSMO_VALUE_STRING(PR_ARQ_E_CIPH_RES),
56 OSMO_VALUE_STRING(PR_ARQ_E_UPD_LOC_RES),
57 OSMO_VALUE_STRING(PR_ARQ_E_TRACE_RES),
58 OSMO_VALUE_STRING(PR_ARQ_E_IMEI_RES),
59 OSMO_VALUE_STRING(PR_ARQ_E_PRES_RES),
60 OSMO_VALUE_STRING(PR_ARQ_E_TMSI_ACK),
61 { 0, NULL }
62};
63
64struct proc_arq_priv {
65 struct vlr_instance *vlr;
66 struct vlr_subscr *vsub;
67 void *msc_conn_ref;
68 struct osmo_fsm_inst *ul_child_fsm;
69 struct osmo_fsm_inst *sub_pres_vlr_fsm;
70 uint32_t parent_event_success;
71 uint32_t parent_event_failure;
72 void *parent_event_data;
73
74 enum vlr_parq_type type;
75 enum vlr_proc_arq_result result;
76 bool by_tmsi;
77 char imsi[16];
78 uint32_t tmsi;
79 struct osmo_location_area_id lai;
80 bool authentication_required;
81 enum vlr_ciph ciphering_required;
82 bool is_r99;
83 bool is_utran;
84 bool implicitly_accepted_parq_by_ciphering_cmd;
85};
86
87static void assoc_par_with_subscr(struct osmo_fsm_inst *fi, struct vlr_subscr *vsub)
88{
89 struct proc_arq_priv *par = fi->priv;
90 struct vlr_instance *vlr = par->vlr;
91
92 vsub->msc_conn_ref = par->msc_conn_ref;
93 par->vsub = vsub;
94 /* Tell MSC to associate this subscriber with the given
95 * connection */
96 vlr->ops.subscr_assoc(par->msc_conn_ref, par->vsub);
97}
98
99#define proc_arq_fsm_done(fi, res) _proc_arq_fsm_done(fi, res, __FILE__, __LINE__)
100static void _proc_arq_fsm_done(struct osmo_fsm_inst *fi,
101 enum vlr_proc_arq_result res,
102 const char *file, int line)
103{
104 struct proc_arq_priv *par = fi->priv;
105 LOGPFSMSRC(fi, file, line, "proc_arq_fsm_done(%s)\n",
106 vlr_proc_arq_result_name(res));
107 par->result = res;
108 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_DONE, 0, 0);
109}
110
111static void proc_arq_vlr_dispatch_result(struct osmo_fsm_inst *fi,
112 uint32_t prev_state)
113{
114 struct proc_arq_priv *par = fi->priv;
115 bool success;
116 int rc;
117 LOGPFSM(fi, "Process Access Request result: %s\n",
118 vlr_proc_arq_result_name(par->result));
119
120 success = (par->result == VLR_PR_ARQ_RES_PASSED);
121
122 /* It would be logical to first dispatch the success event to the
123 * parent FSM, but that could start actions that send messages to the
124 * MS. Rather send the CM Service Accept message first and then signal
125 * success. Since messages are handled synchronously, the success event
126 * will be processed before we handle new incoming data from the MS. */
127
128 if (par->type == VLR_PR_ARQ_T_CM_SERV_REQ) {
129 if (success
130 && !par->implicitly_accepted_parq_by_ciphering_cmd) {
131 rc = par->vlr->ops.tx_cm_serv_acc(par->msc_conn_ref);
132 if (rc) {
133 LOGPFSML(fi, LOGL_ERROR,
134 "Failed to send CM Service Accept\n");
135 success = false;
136 }
137 }
138 if (!success) {
139 rc = par->vlr->ops.tx_cm_serv_rej(par->msc_conn_ref,
140 par->result);
141 if (rc)
142 LOGPFSML(fi, LOGL_ERROR,
143 "Failed to send CM Service Reject\n");
144 }
145 }
146
147 /* For VLR_PR_ARQ_T_PAGING_RESP, there is nothing to send. The conn_fsm
148 * will start handling pending paging transactions. */
149
150 if (!fi->proc.parent) {
151 LOGPFSML(fi, LOGL_ERROR, "No parent FSM");
152 return;
153 }
154 osmo_fsm_inst_dispatch(fi->proc.parent,
155 success ? par->parent_event_success
156 : par->parent_event_failure,
157 par->parent_event_data);
158}
159
160void proc_arq_vlr_cleanup(struct osmo_fsm_inst *fi,
161 enum osmo_fsm_term_cause cause)
162{
163 struct proc_arq_priv *par = fi->priv;
164 if (par->vsub && par->vsub->proc_arq_fsm == fi)
165 par->vsub->proc_arq_fsm = NULL;
166}
167
168static void _proc_arq_vlr_post_imei(struct osmo_fsm_inst *fi)
169{
170 struct proc_arq_priv *par = fi->priv;
171 struct vlr_subscr *vsub = par->vsub;
172
173 LOGPFSM(fi, "%s()\n", __func__);
174
Neels Hofmeyref9126c2017-07-18 15:38:39 +0200175 /* See 3GPP TS 29.002 Proc_Acc_Req_VLR3. */
Harald Welteb8b85a12016-06-17 00:06:42 +0200176 /* TODO: Identity := IMSI */
177 if (0 /* TODO: TMSI reallocation at access: vlr->cfg.alloc_tmsi_arq */) {
178 vlr_subscr_alloc_tmsi(vsub);
179 /* TODO: forward TMSI to MS, wait for TMSI
180 * REALLOC COMPLETE */
181 /* TODO: Freeze old TMSI */
182 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_TMSI_ACK, 0, 0);
183 return;
184 }
185
186 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_PASSED);
187}
188
189static void _proc_arq_vlr_post_trace(struct osmo_fsm_inst *fi)
190{
191 struct proc_arq_priv *par = fi->priv;
192 struct vlr_subscr *vsub = par->vsub;
193 struct vlr_instance *vlr = vsub->vlr;
194
195 LOGPFSM(fi, "%s()\n", __func__);
196
197 /* Node 3 */
Neels Hofmeyref9126c2017-07-18 15:38:39 +0200198 /* See 3GPP TS 29.002 Proc_Acc_Req_VLR3. */
Harald Welteb8b85a12016-06-17 00:06:42 +0200199 if (0 /* IMEI check required */) {
200 /* Chck_IMEI_VLR */
201 vlr->ops.tx_id_req(par->msc_conn_ref, GSM_MI_TYPE_IMEI);
202 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_CHECK_IMEI,
203 vlr_timer(vlr, 3270), 3270);
204 } else
205 _proc_arq_vlr_post_imei(fi);
206}
207
208/* After Subscriber_Present_VLR */
209static void _proc_arq_vlr_post_pres(struct osmo_fsm_inst *fi)
210{
211 LOGPFSM(fi, "%s()\n", __func__);
Neels Hofmeyref9126c2017-07-18 15:38:39 +0200212 /* See 3GPP TS 29.002 Proc_Acc_Req_VLR3. */
Harald Welteb8b85a12016-06-17 00:06:42 +0200213 if (0 /* TODO: tracing required */) {
214 /* TODO: Trace_Subscriber_Activity_VLR */
215 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_TRACE_SUB, 0, 0);
216 }
217 _proc_arq_vlr_post_trace(fi);
218}
219
220/* After Update_Location_Child_VLR */
221static void _proc_arq_vlr_node2_post_vlr(struct osmo_fsm_inst *fi)
222{
223 struct proc_arq_priv *par = fi->priv;
224 struct vlr_subscr *vsub = par->vsub;
225
226 LOGPFSM(fi, "%s()\n", __func__);
227
228 if (!vsub->sub_dataconf_by_hlr_ind) {
229 /* Set User Error: Unidentified Subscriber */
230 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
231 return;
232 }
Neels Hofmeyref9126c2017-07-18 15:38:39 +0200233 /* We don't feature location area specific blocking (yet). */
Harald Welteb8b85a12016-06-17 00:06:42 +0200234 if (0 /* roaming not allowed in LA */) {
235 /* Set User Error: Roaming not allowed in this LA */
236 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ROAMING_NOTALLOWED);
237 return;
238 }
239 vsub->imsi_detached_flag = false;
240 if (vsub->ms_not_reachable_flag) {
241 /* Start Subscriber_Present_VLR */
242 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_SUB_PRES, 0, 0);
243 par->sub_pres_vlr_fsm = sub_pres_vlr_fsm_start(fi, vsub,
244 PR_ARQ_E_PRES_RES);
245 return;
246 }
247 _proc_arq_vlr_post_pres(fi);
248}
249
250static void _proc_arq_vlr_node2_post_ciph(struct osmo_fsm_inst *fi)
251{
252 struct proc_arq_priv *par = fi->priv;
253 struct vlr_subscr *vsub = par->vsub;
254
255 LOGPFSM(fi, "%s()\n", __func__);
256
257 vsub->conf_by_radio_contact_ind = true;
258 if (vsub->loc_conf_in_hlr_ind == false) {
259 /* start Update_Location_Child_VLR. WE use
260 * Update_HLR_VLR instead, the differences appear
261 * insignificant for now. */
262 par->ul_child_fsm = upd_hlr_vlr_proc_start(fi, vsub,
263 PR_ARQ_E_UPD_LOC_RES);
264 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_UPD_LOC_CHILD, 0, 0);
265 return;
266 }
267 _proc_arq_vlr_node2_post_vlr(fi);
268}
269
270static bool is_ciph_required(struct proc_arq_priv *par)
271{
272 return par->ciphering_required != VLR_CIPH_NONE;
273}
274
275static void _proc_arq_vlr_node2(struct osmo_fsm_inst *fi)
276{
277 struct proc_arq_priv *par = fi->priv;
278 struct vlr_subscr *vsub = par->vsub;
279
280 LOGPFSM(fi, "%s()\n", __func__);
281
282 if (!is_ciph_required(par)) {
283 _proc_arq_vlr_node2_post_ciph(fi);
284 return;
285 }
286
287 if (vlr_set_ciph_mode(vsub->vlr, fi, par->msc_conn_ref,
288 par->ciphering_required,
289 vsub->vlr->cfg.retrieve_imeisv)) {
290 LOGPFSML(fi, LOGL_ERROR,
291 "Failed to send Ciphering Mode Command\n");
292 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_SYSTEM_FAILURE);
293 return;
294 }
295
296 par->implicitly_accepted_parq_by_ciphering_cmd = true;
297 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_CIPH, 0, 0);
298}
299
300static bool is_auth_required(struct proc_arq_priv *par)
301{
302 /* The cases where the authentication procedure should be used
303 * are defined in 3GPP TS 33.102 */
304 /* For now we use a default value passed in to vlr_lu_fsm(). */
305 return par->authentication_required
306 || (par->ciphering_required != VLR_CIPH_NONE);
307}
308
309/* after the IMSI is known */
310static void proc_arq_vlr_fn_post_imsi(struct osmo_fsm_inst *fi)
311{
312 struct proc_arq_priv *par = fi->priv;
313 struct vlr_subscr *vsub = par->vsub;
314
315 LOGPFSM(fi, "%s()\n", __func__);
316
317 OSMO_ASSERT(vsub);
318
319 /* TODO: Identity IMEI -> System Failure */
320 if (is_auth_required(par)) {
321 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_AUTH,
322 0, 0);
323 vsub->auth_fsm = auth_fsm_start(vsub, fi->log_level, fi,
324 PR_ARQ_E_AUTH_RES,
325 par->is_r99,
326 par->is_utran);
327 } else {
328 _proc_arq_vlr_node2(fi);
329 }
330}
331
332static void proc_arq_vlr_fn_init(struct osmo_fsm_inst *fi,
333 uint32_t event, void *data)
334{
335 struct proc_arq_priv *par = fi->priv;
336 struct vlr_instance *vlr = par->vlr;
337 struct vlr_subscr *vsub = NULL;
338
339 OSMO_ASSERT(event == PR_ARQ_E_START);
340
341 /* Obtain_Identity_VLR */
342 if (!par->by_tmsi) {
343 /* IMSI was included */
344 vsub = vlr_subscr_find_by_imsi(par->vlr, par->imsi);
345 } else {
346 /* TMSI was included */
347 vsub = vlr_subscr_find_by_tmsi(par->vlr, par->tmsi);
348 }
349 if (vsub) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200350 log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200351 if (vsub->proc_arq_fsm && fi != vsub->proc_arq_fsm) {
352 LOGPFSML(fi, LOGL_ERROR,
353 "Another proc_arq_fsm is already"
354 " associated with subscr %s,"
355 " terminating the other FSM.\n",
356 vlr_subscr_name(vsub));
357 proc_arq_fsm_done(vsub->proc_arq_fsm,
358 VLR_PR_ARQ_RES_SYSTEM_FAILURE);
359 }
360 vsub->proc_arq_fsm = fi;
361 assoc_par_with_subscr(fi, vsub);
362 proc_arq_vlr_fn_post_imsi(fi);
363 vlr_subscr_put(vsub);
364 return;
365 }
366 /* No VSUB could be resolved. What now? */
367
368 if (!par->by_tmsi) {
369 /* We couldn't find a subscriber even by IMSI,
370 * Set User Error: Unidentified Subscriber */
371 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
372 return;
373 } else {
374 /* TMSI was included, are we permitted to use it? */
375 if (vlr->cfg.parq_retrieve_imsi) {
376 /* Obtain_IMSI_VLR */
377 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_OBTAIN_IMSI,
378 vlr_timer(vlr, 3270), 3270);
379 return;
380 } else {
381 /* Set User Error: Unidentified Subscriber */
382 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
383 return;
384 }
385 }
386}
387
388/* ID REQ(IMSI) has returned */
389static void proc_arq_vlr_fn_w_obt_imsi(struct osmo_fsm_inst *fi,
390 uint32_t event, void *data)
391{
392 struct proc_arq_priv *par = fi->priv;
393 struct vlr_instance *vlr = par->vlr;
394 struct vlr_subscr *vsub;
395
396 OSMO_ASSERT(event == PR_ARQ_E_ID_IMSI);
397
398 vsub = vlr_subscr_find_by_imsi(vlr, par->imsi);
399 if (!vsub) {
400 /* Set User Error: Unidentified Subscriber */
401 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
402 return;
403 }
404 assoc_par_with_subscr(fi, vsub);
405 proc_arq_vlr_fn_post_imsi(fi);
406 vlr_subscr_put(vsub);
407}
408
409/* Authenticate_VLR has completed */
410static void proc_arq_vlr_fn_w_auth(struct osmo_fsm_inst *fi,
411 uint32_t event, void *data)
412{
413 enum vlr_auth_fsm_result res;
414 enum vlr_proc_arq_result ret;
415
416 OSMO_ASSERT(event == PR_ARQ_E_AUTH_RES);
417
418 res = data ? *(enum vlr_auth_fsm_result*)data : -1;
419 LOGPFSM(fi, "got %s\n", vlr_auth_fsm_result_name(res));
420
421 switch (res) {
422 case VLR_AUTH_RES_PASSED:
423 /* Node 2 */
424 _proc_arq_vlr_node2(fi);
425 return;
426 case VLR_AUTH_RES_ABORTED:
427 /* Error */
428 ret = VLR_PR_ARQ_RES_UNKNOWN_ERROR;
429 break;
430 case VLR_AUTH_RES_UNKNOWN_SUBSCR:
431 /* Set User Error: Unidentified Subscriber */
432 ret = VLR_PR_ARQ_RES_UNIDENT_SUBSCR;
433 break;
434 case VLR_AUTH_RES_AUTH_FAILED:
435 /* Set User Error: Illegal Subscriber */
436 ret = VLR_PR_ARQ_RES_ILLEGAL_SUBSCR;
437 break;
438 case VLR_AUTH_RES_PROC_ERR:
439 /* Set User Error: System failure */
440 ret = VLR_PR_ARQ_RES_SYSTEM_FAILURE;
441 break;
442 default:
443 LOGPFSML(fi, LOGL_ERROR, "Unexpected vlr_auth_fsm_result value: %d (data=%p)\n", res, data);
444 ret = VLR_PR_ARQ_RES_UNKNOWN_ERROR;
445 break;
446 }
447
448 /* send process_access_req response to caller, enter error state */
449 proc_arq_fsm_done(fi, ret);
450}
451
452static void proc_arq_vlr_fn_w_ciph(struct osmo_fsm_inst *fi,
453 uint32_t event, void *data)
454{
455 struct proc_arq_priv *par = fi->priv;
456 struct vlr_subscr *vsub = par->vsub;
457 struct vlr_ciph_result res = { .cause = VLR_CIPH_REJECT };
458
459 OSMO_ASSERT(event == PR_ARQ_E_CIPH_RES);
460
461 if (!data)
462 LOGPFSML(fi, LOGL_ERROR, "invalid ciphering result: NULL\n");
463 else
464 res = *(struct vlr_ciph_result*)data;
465
466 switch (res.cause) {
467 case VLR_CIPH_COMPL:
468 break;
469 case VLR_CIPH_REJECT:
470 LOGPFSM(fi, "ciphering rejected\n");
471 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR);
472 return;
473 default:
474 LOGPFSML(fi, LOGL_ERROR, "invalid ciphering result: %d\n",
475 res.cause);
476 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR);
477 return;
478 }
479
480
481 if (res.imeisv) {
482 LOGPFSM(fi, "got IMEISV: %s\n", res.imeisv);
483 vlr_subscr_set_imeisv(vsub, res.imeisv);
484 }
485 _proc_arq_vlr_node2_post_ciph(fi);
486}
487
488/* Update_Location_Child_VLR has completed */
489static void proc_arq_vlr_fn_w_upd_loc(struct osmo_fsm_inst *fi,
490 uint32_t event, void *data)
491{
492 OSMO_ASSERT(event == PR_ARQ_E_UPD_LOC_RES);
493
494 _proc_arq_vlr_node2_post_vlr(fi);
495}
496
497/* Subscriber_Present_VLR has completed */
498static void proc_arq_vlr_fn_w_pres(struct osmo_fsm_inst *fi,
499 uint32_t event, void *data)
500{
501 OSMO_ASSERT(event == PR_ARQ_E_PRES_RES);
502
503 _proc_arq_vlr_post_pres(fi);
504}
505
506static void proc_arq_vlr_fn_w_trace(struct osmo_fsm_inst *fi,
507 uint32_t event, void *data)
508{
509 OSMO_ASSERT(event == PR_ARQ_E_TRACE_RES);
510
511 _proc_arq_vlr_post_trace(fi);
512}
513
514/* we have received the ID RESPONSE (IMEI) */
515static void proc_arq_vlr_fn_w_imei(struct osmo_fsm_inst *fi,
516 uint32_t event, void *data)
517{
518 OSMO_ASSERT(event == PR_ARQ_E_IMEI_RES);
519
520 _proc_arq_vlr_post_imei(fi);
521}
522
523/* MSC tells us that MS has acknowleded TMSI re-allocation */
524static void proc_arq_vlr_fn_w_tmsi(struct osmo_fsm_inst *fi,
525 uint32_t event, void *data)
526{
527 OSMO_ASSERT(event == PR_ARQ_E_TMSI_ACK);
528
529 /* FIXME: check confirmation? unfreeze? */
530 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_PASSED);
531}
532
533static const struct osmo_fsm_state proc_arq_vlr_states[] = {
534 [PR_ARQ_S_INIT] = {
535 .name = OSMO_STRINGIFY(PR_ARQ_S_INIT),
536 .in_event_mask = S(PR_ARQ_E_START),
537 .out_state_mask = S(PR_ARQ_S_DONE) |
538 S(PR_ARQ_S_WAIT_OBTAIN_IMSI) |
539 S(PR_ARQ_S_WAIT_AUTH) |
540 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
541 S(PR_ARQ_S_WAIT_SUB_PRES) |
542 S(PR_ARQ_S_WAIT_TRACE_SUB) |
543 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
544 S(PR_ARQ_S_WAIT_TMSI_ACK),
545 .action = proc_arq_vlr_fn_init,
546 },
547 [PR_ARQ_S_WAIT_OBTAIN_IMSI] = {
548 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_OBTAIN_IMSI),
549 .in_event_mask = S(PR_ARQ_E_ID_IMSI),
550 .out_state_mask = S(PR_ARQ_S_DONE) |
551 S(PR_ARQ_S_WAIT_AUTH) |
552 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
553 S(PR_ARQ_S_WAIT_SUB_PRES) |
554 S(PR_ARQ_S_WAIT_TRACE_SUB) |
555 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
556 S(PR_ARQ_S_WAIT_TMSI_ACK),
557 .action = proc_arq_vlr_fn_w_obt_imsi,
558 },
559 [PR_ARQ_S_WAIT_AUTH] = {
560 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_AUTH),
561 .in_event_mask = S(PR_ARQ_E_AUTH_RES),
562 .out_state_mask = S(PR_ARQ_S_DONE) |
563 S(PR_ARQ_S_WAIT_CIPH) |
564 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
565 S(PR_ARQ_S_WAIT_SUB_PRES) |
566 S(PR_ARQ_S_WAIT_TRACE_SUB) |
567 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
568 S(PR_ARQ_S_WAIT_TMSI_ACK),
569 .action = proc_arq_vlr_fn_w_auth,
570 },
571 [PR_ARQ_S_WAIT_CIPH] = {
572 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_CIPH),
573 .in_event_mask = S(PR_ARQ_E_CIPH_RES),
574 .out_state_mask = S(PR_ARQ_S_DONE) |
575 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
576 S(PR_ARQ_S_WAIT_SUB_PRES) |
577 S(PR_ARQ_S_WAIT_TRACE_SUB) |
578 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
579 S(PR_ARQ_S_WAIT_TMSI_ACK),
580 .action = proc_arq_vlr_fn_w_ciph,
581 },
582 [PR_ARQ_S_WAIT_UPD_LOC_CHILD] = {
583 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_UPD_LOC_CHILD),
584 .in_event_mask = S(PR_ARQ_E_UPD_LOC_RES),
585 .out_state_mask = S(PR_ARQ_S_DONE) |
586 S(PR_ARQ_S_WAIT_SUB_PRES) |
587 S(PR_ARQ_S_WAIT_TRACE_SUB) |
588 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
589 S(PR_ARQ_S_WAIT_TMSI_ACK),
590 .action = proc_arq_vlr_fn_w_upd_loc,
591 },
592 [PR_ARQ_S_WAIT_SUB_PRES] = {
593 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_SUB_PRES),
594 .in_event_mask = S(PR_ARQ_E_PRES_RES),
595 .out_state_mask = S(PR_ARQ_S_DONE) |
596 S(PR_ARQ_S_WAIT_TRACE_SUB) |
597 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
598 S(PR_ARQ_S_WAIT_TMSI_ACK),
599 .action = proc_arq_vlr_fn_w_pres,
600 },
601 [PR_ARQ_S_WAIT_TRACE_SUB] = {
602 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_TRACE_SUB),
603 .in_event_mask = S(PR_ARQ_E_TRACE_RES),
604 .out_state_mask = S(PR_ARQ_S_DONE) |
605 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
606 S(PR_ARQ_S_WAIT_TMSI_ACK),
607 .action = proc_arq_vlr_fn_w_trace,
608 },
609 [PR_ARQ_S_WAIT_CHECK_IMEI] = {
610 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_CHECK_IMEI),
611 .in_event_mask = S(PR_ARQ_E_IMEI_RES),
612 .out_state_mask = S(PR_ARQ_S_DONE) |
613 S(PR_ARQ_S_WAIT_TMSI_ACK),
614 .action = proc_arq_vlr_fn_w_imei,
615 },
616 [PR_ARQ_S_WAIT_TMSI_ACK] = {
617 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_TMSI_ACK),
618 .in_event_mask = S(PR_ARQ_E_TMSI_ACK),
619 .out_state_mask = S(PR_ARQ_S_DONE),
620 .action = proc_arq_vlr_fn_w_tmsi,
621 },
622 [PR_ARQ_S_DONE] = {
623 .name = OSMO_STRINGIFY(PR_ARQ_S_DONE),
624 .onenter = proc_arq_vlr_dispatch_result,
625 },
626};
627
628static struct osmo_fsm proc_arq_vlr_fsm = {
629 .name = "Process_Access_Request_VLR",
630 .states = proc_arq_vlr_states,
631 .num_states = ARRAY_SIZE(proc_arq_vlr_states),
632 .allstate_event_mask = 0,
633 .allstate_action = NULL,
634 .log_subsys = DVLR,
635 .event_names = proc_arq_vlr_event_names,
636 .cleanup = proc_arq_vlr_cleanup,
637};
638
639void
640vlr_proc_acc_req(struct osmo_fsm_inst *parent,
641 uint32_t parent_event_success,
642 uint32_t parent_event_failure,
643 void *parent_event_data,
644 struct vlr_instance *vlr, void *msc_conn_ref,
645 enum vlr_parq_type type, const uint8_t *mi_lv,
646 const struct osmo_location_area_id *lai,
647 bool authentication_required,
648 enum vlr_ciph ciphering_required,
649 bool is_r99, bool is_utran)
650{
651 struct osmo_fsm_inst *fi;
652 struct proc_arq_priv *par;
653 char mi_string[GSM48_MI_SIZE];
654 uint8_t mi_type;
655
656 fi = osmo_fsm_inst_alloc_child(&proc_arq_vlr_fsm, parent,
657 parent_event_failure);
658 if (!fi)
659 return;
660
661 par = talloc_zero(fi, struct proc_arq_priv);
662 fi->priv = par;
663 par->vlr = vlr;
664 par->msc_conn_ref = msc_conn_ref;
665 par->type = type;
666 par->lai = *lai;
667 par->parent_event_success = parent_event_success;
668 par->parent_event_failure = parent_event_failure;
669 par->parent_event_data = parent_event_data;
670 par->authentication_required = authentication_required;
671 par->ciphering_required = ciphering_required;
672 par->is_r99 = is_r99;
673 par->is_utran = is_utran;
674
675 LOGPFSM(fi, "rev=%s net=%s%s%s\n",
676 is_r99 ? "R99" : "GSM",
677 is_utran ? "UTRAN" : "GERAN",
678 (authentication_required || ciphering_required)?
679 " Auth" : " (no Auth)",
680 (authentication_required || ciphering_required)?
681 (ciphering_required? "+Ciph" : " (no Ciph)")
682 : "");
683
684 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi_lv+1, mi_lv[0]);
685 mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
686 switch (mi_type) {
687 case GSM_MI_TYPE_IMSI:
688 strncpy(par->imsi, mi_string, sizeof(par->imsi)-1);
689 par->imsi[sizeof(par->imsi)-1] = '\0';
690 par->by_tmsi = false;
691 break;
692 case GSM_MI_TYPE_TMSI:
693 par->by_tmsi = true;
694 par->tmsi = osmo_load32be(mi_lv+2);
695 break;
696 case GSM_MI_TYPE_IMEI:
697 /* TODO: IMEI (emergency call) */
698 default:
699 /* FIXME: directly send reject? */
700 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
701 return;
702 }
703
704 osmo_fsm_inst_dispatch(fi, PR_ARQ_E_START, NULL);
705}
706
707/* Gracefully terminate an FSM created by vlr_proc_acc_req() in case of
708 * external timeout (i.e. from MSC). */
709void vlr_parq_conn_timeout(struct osmo_fsm_inst *fi)
710{
711 if (!fi || fi->state == PR_ARQ_S_DONE)
712 return;
713 LOGPFSM(fi, "Connection timed out\n");
714 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_TIMEOUT);
715}
716
717
718#if 0
719/***********************************************************************
720 * Update_Location_Child_VLR, TS 29.002 Chapter 25.4.4
721 ***********************************************************************/
722
723enum upd_loc_child_vlr_state {
724 ULC_S_IDLE,
725 ULC_S_WAIT_HLR_RESP,
726 ULC_S_DONE,
727};
728
729enum upd_loc_child_vlr_event {
730 ULC_E_START,
731};
732
733static const struct value_string upd_loc_child_vlr_event_names[] = {
734 { ULC_E_START, "START" },
735 { 0, NULL }
736};
737
738static void upd_loc_child_f_idle(struct osmo_fsm_inst *fi, uint32_t event,
739 void *data)
740{
741 OSMO_ASSERT(event == ULC_E_START);
742
743 /* send update location */
744}
745
746static void upd_loc_child_f_w_hlr(struct osmo_fsm_inst *fi, uint32_t event,
747 void *data)
748{
749}
750
751static const struct osmo_fsm_state upd_loc_child_vlr_states[] = {
752 [ULC_S_IDLE] = {
753 .in_event_mask = ,
754 .out_state_mask = S(ULC_S_WAIT_HLR_RESP) |
755 S(ULC_S_DONE),
756 .name = "IDLE",
757 .action = upd_loc_child_f_idle,
758 },
759 [ULC_S_WAIT_HLR_RESP] = {
760 .in_event_mask = ,
761 .out_state_mask = S(ULC_S_DONE),
762 .name = "WAIT-HLR-RESP",
763 .action = upd_loc_child_f_w_hlr,
764 },
765 [ULC_S_DONE] = {
766 .name = "DONE",
767 },
768};
769
770static struct osmo_fsm upd_loc_child_vlr_fsm = {
771 .name = "Update_Location_Child_VLR",
772 .states = upd_loc_child_vlr_states,
773 .num_states = ARRAY_SIZE(upd_loc_child_vlr_states),
774 .log_subsys = DVLR,
775 .event_names = upd_loc_child_vlr_event_names,
776};
777#endif
778
779void vlr_parq_fsm_init(void)
780{
781 //osmo_fsm_register(&upd_loc_child_vlr_fsm);
782 osmo_fsm_register(&proc_arq_vlr_fsm);
783}