blob: 4e63e299f80ed3e5f0cb2d014b929acc2f075f94 [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
175 /* TODO: Identity := IMSI */
176 if (0 /* TODO: TMSI reallocation at access: vlr->cfg.alloc_tmsi_arq */) {
177 vlr_subscr_alloc_tmsi(vsub);
178 /* TODO: forward TMSI to MS, wait for TMSI
179 * REALLOC COMPLETE */
180 /* TODO: Freeze old TMSI */
181 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_TMSI_ACK, 0, 0);
182 return;
183 }
184
185 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_PASSED);
186}
187
188static void _proc_arq_vlr_post_trace(struct osmo_fsm_inst *fi)
189{
190 struct proc_arq_priv *par = fi->priv;
191 struct vlr_subscr *vsub = par->vsub;
192 struct vlr_instance *vlr = vsub->vlr;
193
194 LOGPFSM(fi, "%s()\n", __func__);
195
196 /* Node 3 */
197 if (0 /* IMEI check required */) {
198 /* Chck_IMEI_VLR */
199 vlr->ops.tx_id_req(par->msc_conn_ref, GSM_MI_TYPE_IMEI);
200 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_CHECK_IMEI,
201 vlr_timer(vlr, 3270), 3270);
202 } else
203 _proc_arq_vlr_post_imei(fi);
204}
205
206/* After Subscriber_Present_VLR */
207static void _proc_arq_vlr_post_pres(struct osmo_fsm_inst *fi)
208{
209 LOGPFSM(fi, "%s()\n", __func__);
210 if (0 /* TODO: tracing required */) {
211 /* TODO: Trace_Subscriber_Activity_VLR */
212 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_TRACE_SUB, 0, 0);
213 }
214 _proc_arq_vlr_post_trace(fi);
215}
216
217/* After Update_Location_Child_VLR */
218static void _proc_arq_vlr_node2_post_vlr(struct osmo_fsm_inst *fi)
219{
220 struct proc_arq_priv *par = fi->priv;
221 struct vlr_subscr *vsub = par->vsub;
222
223 LOGPFSM(fi, "%s()\n", __func__);
224
225 if (!vsub->sub_dataconf_by_hlr_ind) {
226 /* Set User Error: Unidentified Subscriber */
227 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
228 return;
229 }
230 if (0 /* roaming not allowed in LA */) {
231 /* Set User Error: Roaming not allowed in this LA */
232 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ROAMING_NOTALLOWED);
233 return;
234 }
235 vsub->imsi_detached_flag = false;
236 if (vsub->ms_not_reachable_flag) {
237 /* Start Subscriber_Present_VLR */
238 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_SUB_PRES, 0, 0);
239 par->sub_pres_vlr_fsm = sub_pres_vlr_fsm_start(fi, vsub,
240 PR_ARQ_E_PRES_RES);
241 return;
242 }
243 _proc_arq_vlr_post_pres(fi);
244}
245
246static void _proc_arq_vlr_node2_post_ciph(struct osmo_fsm_inst *fi)
247{
248 struct proc_arq_priv *par = fi->priv;
249 struct vlr_subscr *vsub = par->vsub;
250
251 LOGPFSM(fi, "%s()\n", __func__);
252
253 vsub->conf_by_radio_contact_ind = true;
254 if (vsub->loc_conf_in_hlr_ind == false) {
255 /* start Update_Location_Child_VLR. WE use
256 * Update_HLR_VLR instead, the differences appear
257 * insignificant for now. */
258 par->ul_child_fsm = upd_hlr_vlr_proc_start(fi, vsub,
259 PR_ARQ_E_UPD_LOC_RES);
260 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_UPD_LOC_CHILD, 0, 0);
261 return;
262 }
263 _proc_arq_vlr_node2_post_vlr(fi);
264}
265
266static bool is_ciph_required(struct proc_arq_priv *par)
267{
268 return par->ciphering_required != VLR_CIPH_NONE;
269}
270
271static void _proc_arq_vlr_node2(struct osmo_fsm_inst *fi)
272{
273 struct proc_arq_priv *par = fi->priv;
274 struct vlr_subscr *vsub = par->vsub;
275
276 LOGPFSM(fi, "%s()\n", __func__);
277
278 if (!is_ciph_required(par)) {
279 _proc_arq_vlr_node2_post_ciph(fi);
280 return;
281 }
282
283 if (vlr_set_ciph_mode(vsub->vlr, fi, par->msc_conn_ref,
284 par->ciphering_required,
285 vsub->vlr->cfg.retrieve_imeisv)) {
286 LOGPFSML(fi, LOGL_ERROR,
287 "Failed to send Ciphering Mode Command\n");
288 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_SYSTEM_FAILURE);
289 return;
290 }
291
292 par->implicitly_accepted_parq_by_ciphering_cmd = true;
293 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_CIPH, 0, 0);
294}
295
296static bool is_auth_required(struct proc_arq_priv *par)
297{
298 /* The cases where the authentication procedure should be used
299 * are defined in 3GPP TS 33.102 */
300 /* For now we use a default value passed in to vlr_lu_fsm(). */
301 return par->authentication_required
302 || (par->ciphering_required != VLR_CIPH_NONE);
303}
304
305/* after the IMSI is known */
306static void proc_arq_vlr_fn_post_imsi(struct osmo_fsm_inst *fi)
307{
308 struct proc_arq_priv *par = fi->priv;
309 struct vlr_subscr *vsub = par->vsub;
310
311 LOGPFSM(fi, "%s()\n", __func__);
312
313 OSMO_ASSERT(vsub);
314
315 /* TODO: Identity IMEI -> System Failure */
316 if (is_auth_required(par)) {
317 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_AUTH,
318 0, 0);
319 vsub->auth_fsm = auth_fsm_start(vsub, fi->log_level, fi,
320 PR_ARQ_E_AUTH_RES,
321 par->is_r99,
322 par->is_utran);
323 } else {
324 _proc_arq_vlr_node2(fi);
325 }
326}
327
328static void proc_arq_vlr_fn_init(struct osmo_fsm_inst *fi,
329 uint32_t event, void *data)
330{
331 struct proc_arq_priv *par = fi->priv;
332 struct vlr_instance *vlr = par->vlr;
333 struct vlr_subscr *vsub = NULL;
334
335 OSMO_ASSERT(event == PR_ARQ_E_START);
336
337 /* Obtain_Identity_VLR */
338 if (!par->by_tmsi) {
339 /* IMSI was included */
340 vsub = vlr_subscr_find_by_imsi(par->vlr, par->imsi);
341 } else {
342 /* TMSI was included */
343 vsub = vlr_subscr_find_by_tmsi(par->vlr, par->tmsi);
344 }
345 if (vsub) {
346 if (vsub->proc_arq_fsm && fi != vsub->proc_arq_fsm) {
347 LOGPFSML(fi, LOGL_ERROR,
348 "Another proc_arq_fsm is already"
349 " associated with subscr %s,"
350 " terminating the other FSM.\n",
351 vlr_subscr_name(vsub));
352 proc_arq_fsm_done(vsub->proc_arq_fsm,
353 VLR_PR_ARQ_RES_SYSTEM_FAILURE);
354 }
355 vsub->proc_arq_fsm = fi;
356 assoc_par_with_subscr(fi, vsub);
357 proc_arq_vlr_fn_post_imsi(fi);
358 vlr_subscr_put(vsub);
359 return;
360 }
361 /* No VSUB could be resolved. What now? */
362
363 if (!par->by_tmsi) {
364 /* We couldn't find a subscriber even by IMSI,
365 * Set User Error: Unidentified Subscriber */
366 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
367 return;
368 } else {
369 /* TMSI was included, are we permitted to use it? */
370 if (vlr->cfg.parq_retrieve_imsi) {
371 /* Obtain_IMSI_VLR */
372 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_OBTAIN_IMSI,
373 vlr_timer(vlr, 3270), 3270);
374 return;
375 } else {
376 /* Set User Error: Unidentified Subscriber */
377 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
378 return;
379 }
380 }
381}
382
383/* ID REQ(IMSI) has returned */
384static void proc_arq_vlr_fn_w_obt_imsi(struct osmo_fsm_inst *fi,
385 uint32_t event, void *data)
386{
387 struct proc_arq_priv *par = fi->priv;
388 struct vlr_instance *vlr = par->vlr;
389 struct vlr_subscr *vsub;
390
391 OSMO_ASSERT(event == PR_ARQ_E_ID_IMSI);
392
393 vsub = vlr_subscr_find_by_imsi(vlr, par->imsi);
394 if (!vsub) {
395 /* Set User Error: Unidentified Subscriber */
396 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
397 return;
398 }
399 assoc_par_with_subscr(fi, vsub);
400 proc_arq_vlr_fn_post_imsi(fi);
401 vlr_subscr_put(vsub);
402}
403
404/* Authenticate_VLR has completed */
405static void proc_arq_vlr_fn_w_auth(struct osmo_fsm_inst *fi,
406 uint32_t event, void *data)
407{
408 enum vlr_auth_fsm_result res;
409 enum vlr_proc_arq_result ret;
410
411 OSMO_ASSERT(event == PR_ARQ_E_AUTH_RES);
412
413 res = data ? *(enum vlr_auth_fsm_result*)data : -1;
414 LOGPFSM(fi, "got %s\n", vlr_auth_fsm_result_name(res));
415
416 switch (res) {
417 case VLR_AUTH_RES_PASSED:
418 /* Node 2 */
419 _proc_arq_vlr_node2(fi);
420 return;
421 case VLR_AUTH_RES_ABORTED:
422 /* Error */
423 ret = VLR_PR_ARQ_RES_UNKNOWN_ERROR;
424 break;
425 case VLR_AUTH_RES_UNKNOWN_SUBSCR:
426 /* Set User Error: Unidentified Subscriber */
427 ret = VLR_PR_ARQ_RES_UNIDENT_SUBSCR;
428 break;
429 case VLR_AUTH_RES_AUTH_FAILED:
430 /* Set User Error: Illegal Subscriber */
431 ret = VLR_PR_ARQ_RES_ILLEGAL_SUBSCR;
432 break;
433 case VLR_AUTH_RES_PROC_ERR:
434 /* Set User Error: System failure */
435 ret = VLR_PR_ARQ_RES_SYSTEM_FAILURE;
436 break;
437 default:
438 LOGPFSML(fi, LOGL_ERROR, "Unexpected vlr_auth_fsm_result value: %d (data=%p)\n", res, data);
439 ret = VLR_PR_ARQ_RES_UNKNOWN_ERROR;
440 break;
441 }
442
443 /* send process_access_req response to caller, enter error state */
444 proc_arq_fsm_done(fi, ret);
445}
446
447static void proc_arq_vlr_fn_w_ciph(struct osmo_fsm_inst *fi,
448 uint32_t event, void *data)
449{
450 struct proc_arq_priv *par = fi->priv;
451 struct vlr_subscr *vsub = par->vsub;
452 struct vlr_ciph_result res = { .cause = VLR_CIPH_REJECT };
453
454 OSMO_ASSERT(event == PR_ARQ_E_CIPH_RES);
455
456 if (!data)
457 LOGPFSML(fi, LOGL_ERROR, "invalid ciphering result: NULL\n");
458 else
459 res = *(struct vlr_ciph_result*)data;
460
461 switch (res.cause) {
462 case VLR_CIPH_COMPL:
463 break;
464 case VLR_CIPH_REJECT:
465 LOGPFSM(fi, "ciphering rejected\n");
466 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR);
467 return;
468 default:
469 LOGPFSML(fi, LOGL_ERROR, "invalid ciphering result: %d\n",
470 res.cause);
471 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR);
472 return;
473 }
474
475
476 if (res.imeisv) {
477 LOGPFSM(fi, "got IMEISV: %s\n", res.imeisv);
478 vlr_subscr_set_imeisv(vsub, res.imeisv);
479 }
480 _proc_arq_vlr_node2_post_ciph(fi);
481}
482
483/* Update_Location_Child_VLR has completed */
484static void proc_arq_vlr_fn_w_upd_loc(struct osmo_fsm_inst *fi,
485 uint32_t event, void *data)
486{
487 OSMO_ASSERT(event == PR_ARQ_E_UPD_LOC_RES);
488
489 _proc_arq_vlr_node2_post_vlr(fi);
490}
491
492/* Subscriber_Present_VLR has completed */
493static void proc_arq_vlr_fn_w_pres(struct osmo_fsm_inst *fi,
494 uint32_t event, void *data)
495{
496 OSMO_ASSERT(event == PR_ARQ_E_PRES_RES);
497
498 _proc_arq_vlr_post_pres(fi);
499}
500
501static void proc_arq_vlr_fn_w_trace(struct osmo_fsm_inst *fi,
502 uint32_t event, void *data)
503{
504 OSMO_ASSERT(event == PR_ARQ_E_TRACE_RES);
505
506 _proc_arq_vlr_post_trace(fi);
507}
508
509/* we have received the ID RESPONSE (IMEI) */
510static void proc_arq_vlr_fn_w_imei(struct osmo_fsm_inst *fi,
511 uint32_t event, void *data)
512{
513 OSMO_ASSERT(event == PR_ARQ_E_IMEI_RES);
514
515 _proc_arq_vlr_post_imei(fi);
516}
517
518/* MSC tells us that MS has acknowleded TMSI re-allocation */
519static void proc_arq_vlr_fn_w_tmsi(struct osmo_fsm_inst *fi,
520 uint32_t event, void *data)
521{
522 OSMO_ASSERT(event == PR_ARQ_E_TMSI_ACK);
523
524 /* FIXME: check confirmation? unfreeze? */
525 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_PASSED);
526}
527
528static const struct osmo_fsm_state proc_arq_vlr_states[] = {
529 [PR_ARQ_S_INIT] = {
530 .name = OSMO_STRINGIFY(PR_ARQ_S_INIT),
531 .in_event_mask = S(PR_ARQ_E_START),
532 .out_state_mask = S(PR_ARQ_S_DONE) |
533 S(PR_ARQ_S_WAIT_OBTAIN_IMSI) |
534 S(PR_ARQ_S_WAIT_AUTH) |
535 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
536 S(PR_ARQ_S_WAIT_SUB_PRES) |
537 S(PR_ARQ_S_WAIT_TRACE_SUB) |
538 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
539 S(PR_ARQ_S_WAIT_TMSI_ACK),
540 .action = proc_arq_vlr_fn_init,
541 },
542 [PR_ARQ_S_WAIT_OBTAIN_IMSI] = {
543 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_OBTAIN_IMSI),
544 .in_event_mask = S(PR_ARQ_E_ID_IMSI),
545 .out_state_mask = S(PR_ARQ_S_DONE) |
546 S(PR_ARQ_S_WAIT_AUTH) |
547 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
548 S(PR_ARQ_S_WAIT_SUB_PRES) |
549 S(PR_ARQ_S_WAIT_TRACE_SUB) |
550 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
551 S(PR_ARQ_S_WAIT_TMSI_ACK),
552 .action = proc_arq_vlr_fn_w_obt_imsi,
553 },
554 [PR_ARQ_S_WAIT_AUTH] = {
555 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_AUTH),
556 .in_event_mask = S(PR_ARQ_E_AUTH_RES),
557 .out_state_mask = S(PR_ARQ_S_DONE) |
558 S(PR_ARQ_S_WAIT_CIPH) |
559 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
560 S(PR_ARQ_S_WAIT_SUB_PRES) |
561 S(PR_ARQ_S_WAIT_TRACE_SUB) |
562 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
563 S(PR_ARQ_S_WAIT_TMSI_ACK),
564 .action = proc_arq_vlr_fn_w_auth,
565 },
566 [PR_ARQ_S_WAIT_CIPH] = {
567 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_CIPH),
568 .in_event_mask = S(PR_ARQ_E_CIPH_RES),
569 .out_state_mask = S(PR_ARQ_S_DONE) |
570 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
571 S(PR_ARQ_S_WAIT_SUB_PRES) |
572 S(PR_ARQ_S_WAIT_TRACE_SUB) |
573 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
574 S(PR_ARQ_S_WAIT_TMSI_ACK),
575 .action = proc_arq_vlr_fn_w_ciph,
576 },
577 [PR_ARQ_S_WAIT_UPD_LOC_CHILD] = {
578 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_UPD_LOC_CHILD),
579 .in_event_mask = S(PR_ARQ_E_UPD_LOC_RES),
580 .out_state_mask = S(PR_ARQ_S_DONE) |
581 S(PR_ARQ_S_WAIT_SUB_PRES) |
582 S(PR_ARQ_S_WAIT_TRACE_SUB) |
583 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
584 S(PR_ARQ_S_WAIT_TMSI_ACK),
585 .action = proc_arq_vlr_fn_w_upd_loc,
586 },
587 [PR_ARQ_S_WAIT_SUB_PRES] = {
588 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_SUB_PRES),
589 .in_event_mask = S(PR_ARQ_E_PRES_RES),
590 .out_state_mask = S(PR_ARQ_S_DONE) |
591 S(PR_ARQ_S_WAIT_TRACE_SUB) |
592 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
593 S(PR_ARQ_S_WAIT_TMSI_ACK),
594 .action = proc_arq_vlr_fn_w_pres,
595 },
596 [PR_ARQ_S_WAIT_TRACE_SUB] = {
597 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_TRACE_SUB),
598 .in_event_mask = S(PR_ARQ_E_TRACE_RES),
599 .out_state_mask = S(PR_ARQ_S_DONE) |
600 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
601 S(PR_ARQ_S_WAIT_TMSI_ACK),
602 .action = proc_arq_vlr_fn_w_trace,
603 },
604 [PR_ARQ_S_WAIT_CHECK_IMEI] = {
605 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_CHECK_IMEI),
606 .in_event_mask = S(PR_ARQ_E_IMEI_RES),
607 .out_state_mask = S(PR_ARQ_S_DONE) |
608 S(PR_ARQ_S_WAIT_TMSI_ACK),
609 .action = proc_arq_vlr_fn_w_imei,
610 },
611 [PR_ARQ_S_WAIT_TMSI_ACK] = {
612 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_TMSI_ACK),
613 .in_event_mask = S(PR_ARQ_E_TMSI_ACK),
614 .out_state_mask = S(PR_ARQ_S_DONE),
615 .action = proc_arq_vlr_fn_w_tmsi,
616 },
617 [PR_ARQ_S_DONE] = {
618 .name = OSMO_STRINGIFY(PR_ARQ_S_DONE),
619 .onenter = proc_arq_vlr_dispatch_result,
620 },
621};
622
623static struct osmo_fsm proc_arq_vlr_fsm = {
624 .name = "Process_Access_Request_VLR",
625 .states = proc_arq_vlr_states,
626 .num_states = ARRAY_SIZE(proc_arq_vlr_states),
627 .allstate_event_mask = 0,
628 .allstate_action = NULL,
629 .log_subsys = DVLR,
630 .event_names = proc_arq_vlr_event_names,
631 .cleanup = proc_arq_vlr_cleanup,
632};
633
634void
635vlr_proc_acc_req(struct osmo_fsm_inst *parent,
636 uint32_t parent_event_success,
637 uint32_t parent_event_failure,
638 void *parent_event_data,
639 struct vlr_instance *vlr, void *msc_conn_ref,
640 enum vlr_parq_type type, const uint8_t *mi_lv,
641 const struct osmo_location_area_id *lai,
642 bool authentication_required,
643 enum vlr_ciph ciphering_required,
644 bool is_r99, bool is_utran)
645{
646 struct osmo_fsm_inst *fi;
647 struct proc_arq_priv *par;
648 char mi_string[GSM48_MI_SIZE];
649 uint8_t mi_type;
650
651 fi = osmo_fsm_inst_alloc_child(&proc_arq_vlr_fsm, parent,
652 parent_event_failure);
653 if (!fi)
654 return;
655
656 par = talloc_zero(fi, struct proc_arq_priv);
657 fi->priv = par;
658 par->vlr = vlr;
659 par->msc_conn_ref = msc_conn_ref;
660 par->type = type;
661 par->lai = *lai;
662 par->parent_event_success = parent_event_success;
663 par->parent_event_failure = parent_event_failure;
664 par->parent_event_data = parent_event_data;
665 par->authentication_required = authentication_required;
666 par->ciphering_required = ciphering_required;
667 par->is_r99 = is_r99;
668 par->is_utran = is_utran;
669
670 LOGPFSM(fi, "rev=%s net=%s%s%s\n",
671 is_r99 ? "R99" : "GSM",
672 is_utran ? "UTRAN" : "GERAN",
673 (authentication_required || ciphering_required)?
674 " Auth" : " (no Auth)",
675 (authentication_required || ciphering_required)?
676 (ciphering_required? "+Ciph" : " (no Ciph)")
677 : "");
678
679 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi_lv+1, mi_lv[0]);
680 mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
681 switch (mi_type) {
682 case GSM_MI_TYPE_IMSI:
683 strncpy(par->imsi, mi_string, sizeof(par->imsi)-1);
684 par->imsi[sizeof(par->imsi)-1] = '\0';
685 par->by_tmsi = false;
686 break;
687 case GSM_MI_TYPE_TMSI:
688 par->by_tmsi = true;
689 par->tmsi = osmo_load32be(mi_lv+2);
690 break;
691 case GSM_MI_TYPE_IMEI:
692 /* TODO: IMEI (emergency call) */
693 default:
694 /* FIXME: directly send reject? */
695 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
696 return;
697 }
698
699 osmo_fsm_inst_dispatch(fi, PR_ARQ_E_START, NULL);
700}
701
702/* Gracefully terminate an FSM created by vlr_proc_acc_req() in case of
703 * external timeout (i.e. from MSC). */
704void vlr_parq_conn_timeout(struct osmo_fsm_inst *fi)
705{
706 if (!fi || fi->state == PR_ARQ_S_DONE)
707 return;
708 LOGPFSM(fi, "Connection timed out\n");
709 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_TIMEOUT);
710}
711
712
713#if 0
714/***********************************************************************
715 * Update_Location_Child_VLR, TS 29.002 Chapter 25.4.4
716 ***********************************************************************/
717
718enum upd_loc_child_vlr_state {
719 ULC_S_IDLE,
720 ULC_S_WAIT_HLR_RESP,
721 ULC_S_DONE,
722};
723
724enum upd_loc_child_vlr_event {
725 ULC_E_START,
726};
727
728static const struct value_string upd_loc_child_vlr_event_names[] = {
729 { ULC_E_START, "START" },
730 { 0, NULL }
731};
732
733static void upd_loc_child_f_idle(struct osmo_fsm_inst *fi, uint32_t event,
734 void *data)
735{
736 OSMO_ASSERT(event == ULC_E_START);
737
738 /* send update location */
739}
740
741static void upd_loc_child_f_w_hlr(struct osmo_fsm_inst *fi, uint32_t event,
742 void *data)
743{
744}
745
746static const struct osmo_fsm_state upd_loc_child_vlr_states[] = {
747 [ULC_S_IDLE] = {
748 .in_event_mask = ,
749 .out_state_mask = S(ULC_S_WAIT_HLR_RESP) |
750 S(ULC_S_DONE),
751 .name = "IDLE",
752 .action = upd_loc_child_f_idle,
753 },
754 [ULC_S_WAIT_HLR_RESP] = {
755 .in_event_mask = ,
756 .out_state_mask = S(ULC_S_DONE),
757 .name = "WAIT-HLR-RESP",
758 .action = upd_loc_child_f_w_hlr,
759 },
760 [ULC_S_DONE] = {
761 .name = "DONE",
762 },
763};
764
765static struct osmo_fsm upd_loc_child_vlr_fsm = {
766 .name = "Update_Location_Child_VLR",
767 .states = upd_loc_child_vlr_states,
768 .num_states = ARRAY_SIZE(upd_loc_child_vlr_states),
769 .log_subsys = DVLR,
770 .event_names = upd_loc_child_vlr_event_names,
771};
772#endif
773
774void vlr_parq_fsm_init(void)
775{
776 //osmo_fsm_register(&upd_loc_child_vlr_fsm);
777 osmo_fsm_register(&proc_arq_vlr_fsm);
778}