blob: 279e3d49ace36e83408ba2f7faf0d52cf94f7adf [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) {
Harald Welte2483f1b2016-06-19 18:06:02 +0200346 log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
Harald Welteb8b85a12016-06-17 00:06:42 +0200347 if (vsub->proc_arq_fsm && fi != vsub->proc_arq_fsm) {
348 LOGPFSML(fi, LOGL_ERROR,
349 "Another proc_arq_fsm is already"
350 " associated with subscr %s,"
351 " terminating the other FSM.\n",
352 vlr_subscr_name(vsub));
353 proc_arq_fsm_done(vsub->proc_arq_fsm,
354 VLR_PR_ARQ_RES_SYSTEM_FAILURE);
355 }
356 vsub->proc_arq_fsm = fi;
357 assoc_par_with_subscr(fi, vsub);
358 proc_arq_vlr_fn_post_imsi(fi);
359 vlr_subscr_put(vsub);
360 return;
361 }
362 /* No VSUB could be resolved. What now? */
363
364 if (!par->by_tmsi) {
365 /* We couldn't find a subscriber even by IMSI,
366 * Set User Error: Unidentified Subscriber */
367 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
368 return;
369 } else {
370 /* TMSI was included, are we permitted to use it? */
371 if (vlr->cfg.parq_retrieve_imsi) {
372 /* Obtain_IMSI_VLR */
373 osmo_fsm_inst_state_chg(fi, PR_ARQ_S_WAIT_OBTAIN_IMSI,
374 vlr_timer(vlr, 3270), 3270);
375 return;
376 } else {
377 /* Set User Error: Unidentified Subscriber */
378 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
379 return;
380 }
381 }
382}
383
384/* ID REQ(IMSI) has returned */
385static void proc_arq_vlr_fn_w_obt_imsi(struct osmo_fsm_inst *fi,
386 uint32_t event, void *data)
387{
388 struct proc_arq_priv *par = fi->priv;
389 struct vlr_instance *vlr = par->vlr;
390 struct vlr_subscr *vsub;
391
392 OSMO_ASSERT(event == PR_ARQ_E_ID_IMSI);
393
394 vsub = vlr_subscr_find_by_imsi(vlr, par->imsi);
395 if (!vsub) {
396 /* Set User Error: Unidentified Subscriber */
397 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
398 return;
399 }
400 assoc_par_with_subscr(fi, vsub);
401 proc_arq_vlr_fn_post_imsi(fi);
402 vlr_subscr_put(vsub);
403}
404
405/* Authenticate_VLR has completed */
406static void proc_arq_vlr_fn_w_auth(struct osmo_fsm_inst *fi,
407 uint32_t event, void *data)
408{
409 enum vlr_auth_fsm_result res;
410 enum vlr_proc_arq_result ret;
411
412 OSMO_ASSERT(event == PR_ARQ_E_AUTH_RES);
413
414 res = data ? *(enum vlr_auth_fsm_result*)data : -1;
415 LOGPFSM(fi, "got %s\n", vlr_auth_fsm_result_name(res));
416
417 switch (res) {
418 case VLR_AUTH_RES_PASSED:
419 /* Node 2 */
420 _proc_arq_vlr_node2(fi);
421 return;
422 case VLR_AUTH_RES_ABORTED:
423 /* Error */
424 ret = VLR_PR_ARQ_RES_UNKNOWN_ERROR;
425 break;
426 case VLR_AUTH_RES_UNKNOWN_SUBSCR:
427 /* Set User Error: Unidentified Subscriber */
428 ret = VLR_PR_ARQ_RES_UNIDENT_SUBSCR;
429 break;
430 case VLR_AUTH_RES_AUTH_FAILED:
431 /* Set User Error: Illegal Subscriber */
432 ret = VLR_PR_ARQ_RES_ILLEGAL_SUBSCR;
433 break;
434 case VLR_AUTH_RES_PROC_ERR:
435 /* Set User Error: System failure */
436 ret = VLR_PR_ARQ_RES_SYSTEM_FAILURE;
437 break;
438 default:
439 LOGPFSML(fi, LOGL_ERROR, "Unexpected vlr_auth_fsm_result value: %d (data=%p)\n", res, data);
440 ret = VLR_PR_ARQ_RES_UNKNOWN_ERROR;
441 break;
442 }
443
444 /* send process_access_req response to caller, enter error state */
445 proc_arq_fsm_done(fi, ret);
446}
447
448static void proc_arq_vlr_fn_w_ciph(struct osmo_fsm_inst *fi,
449 uint32_t event, void *data)
450{
451 struct proc_arq_priv *par = fi->priv;
452 struct vlr_subscr *vsub = par->vsub;
453 struct vlr_ciph_result res = { .cause = VLR_CIPH_REJECT };
454
455 OSMO_ASSERT(event == PR_ARQ_E_CIPH_RES);
456
457 if (!data)
458 LOGPFSML(fi, LOGL_ERROR, "invalid ciphering result: NULL\n");
459 else
460 res = *(struct vlr_ciph_result*)data;
461
462 switch (res.cause) {
463 case VLR_CIPH_COMPL:
464 break;
465 case VLR_CIPH_REJECT:
466 LOGPFSM(fi, "ciphering rejected\n");
467 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR);
468 return;
469 default:
470 LOGPFSML(fi, LOGL_ERROR, "invalid ciphering result: %d\n",
471 res.cause);
472 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_ILLEGAL_SUBSCR);
473 return;
474 }
475
476
477 if (res.imeisv) {
478 LOGPFSM(fi, "got IMEISV: %s\n", res.imeisv);
479 vlr_subscr_set_imeisv(vsub, res.imeisv);
480 }
481 _proc_arq_vlr_node2_post_ciph(fi);
482}
483
484/* Update_Location_Child_VLR has completed */
485static void proc_arq_vlr_fn_w_upd_loc(struct osmo_fsm_inst *fi,
486 uint32_t event, void *data)
487{
488 OSMO_ASSERT(event == PR_ARQ_E_UPD_LOC_RES);
489
490 _proc_arq_vlr_node2_post_vlr(fi);
491}
492
493/* Subscriber_Present_VLR has completed */
494static void proc_arq_vlr_fn_w_pres(struct osmo_fsm_inst *fi,
495 uint32_t event, void *data)
496{
497 OSMO_ASSERT(event == PR_ARQ_E_PRES_RES);
498
499 _proc_arq_vlr_post_pres(fi);
500}
501
502static void proc_arq_vlr_fn_w_trace(struct osmo_fsm_inst *fi,
503 uint32_t event, void *data)
504{
505 OSMO_ASSERT(event == PR_ARQ_E_TRACE_RES);
506
507 _proc_arq_vlr_post_trace(fi);
508}
509
510/* we have received the ID RESPONSE (IMEI) */
511static void proc_arq_vlr_fn_w_imei(struct osmo_fsm_inst *fi,
512 uint32_t event, void *data)
513{
514 OSMO_ASSERT(event == PR_ARQ_E_IMEI_RES);
515
516 _proc_arq_vlr_post_imei(fi);
517}
518
519/* MSC tells us that MS has acknowleded TMSI re-allocation */
520static void proc_arq_vlr_fn_w_tmsi(struct osmo_fsm_inst *fi,
521 uint32_t event, void *data)
522{
523 OSMO_ASSERT(event == PR_ARQ_E_TMSI_ACK);
524
525 /* FIXME: check confirmation? unfreeze? */
526 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_PASSED);
527}
528
529static const struct osmo_fsm_state proc_arq_vlr_states[] = {
530 [PR_ARQ_S_INIT] = {
531 .name = OSMO_STRINGIFY(PR_ARQ_S_INIT),
532 .in_event_mask = S(PR_ARQ_E_START),
533 .out_state_mask = S(PR_ARQ_S_DONE) |
534 S(PR_ARQ_S_WAIT_OBTAIN_IMSI) |
535 S(PR_ARQ_S_WAIT_AUTH) |
536 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
537 S(PR_ARQ_S_WAIT_SUB_PRES) |
538 S(PR_ARQ_S_WAIT_TRACE_SUB) |
539 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
540 S(PR_ARQ_S_WAIT_TMSI_ACK),
541 .action = proc_arq_vlr_fn_init,
542 },
543 [PR_ARQ_S_WAIT_OBTAIN_IMSI] = {
544 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_OBTAIN_IMSI),
545 .in_event_mask = S(PR_ARQ_E_ID_IMSI),
546 .out_state_mask = S(PR_ARQ_S_DONE) |
547 S(PR_ARQ_S_WAIT_AUTH) |
548 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
549 S(PR_ARQ_S_WAIT_SUB_PRES) |
550 S(PR_ARQ_S_WAIT_TRACE_SUB) |
551 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
552 S(PR_ARQ_S_WAIT_TMSI_ACK),
553 .action = proc_arq_vlr_fn_w_obt_imsi,
554 },
555 [PR_ARQ_S_WAIT_AUTH] = {
556 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_AUTH),
557 .in_event_mask = S(PR_ARQ_E_AUTH_RES),
558 .out_state_mask = S(PR_ARQ_S_DONE) |
559 S(PR_ARQ_S_WAIT_CIPH) |
560 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
561 S(PR_ARQ_S_WAIT_SUB_PRES) |
562 S(PR_ARQ_S_WAIT_TRACE_SUB) |
563 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
564 S(PR_ARQ_S_WAIT_TMSI_ACK),
565 .action = proc_arq_vlr_fn_w_auth,
566 },
567 [PR_ARQ_S_WAIT_CIPH] = {
568 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_CIPH),
569 .in_event_mask = S(PR_ARQ_E_CIPH_RES),
570 .out_state_mask = S(PR_ARQ_S_DONE) |
571 S(PR_ARQ_S_WAIT_UPD_LOC_CHILD) |
572 S(PR_ARQ_S_WAIT_SUB_PRES) |
573 S(PR_ARQ_S_WAIT_TRACE_SUB) |
574 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
575 S(PR_ARQ_S_WAIT_TMSI_ACK),
576 .action = proc_arq_vlr_fn_w_ciph,
577 },
578 [PR_ARQ_S_WAIT_UPD_LOC_CHILD] = {
579 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_UPD_LOC_CHILD),
580 .in_event_mask = S(PR_ARQ_E_UPD_LOC_RES),
581 .out_state_mask = S(PR_ARQ_S_DONE) |
582 S(PR_ARQ_S_WAIT_SUB_PRES) |
583 S(PR_ARQ_S_WAIT_TRACE_SUB) |
584 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
585 S(PR_ARQ_S_WAIT_TMSI_ACK),
586 .action = proc_arq_vlr_fn_w_upd_loc,
587 },
588 [PR_ARQ_S_WAIT_SUB_PRES] = {
589 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_SUB_PRES),
590 .in_event_mask = S(PR_ARQ_E_PRES_RES),
591 .out_state_mask = S(PR_ARQ_S_DONE) |
592 S(PR_ARQ_S_WAIT_TRACE_SUB) |
593 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
594 S(PR_ARQ_S_WAIT_TMSI_ACK),
595 .action = proc_arq_vlr_fn_w_pres,
596 },
597 [PR_ARQ_S_WAIT_TRACE_SUB] = {
598 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_TRACE_SUB),
599 .in_event_mask = S(PR_ARQ_E_TRACE_RES),
600 .out_state_mask = S(PR_ARQ_S_DONE) |
601 S(PR_ARQ_S_WAIT_CHECK_IMEI) |
602 S(PR_ARQ_S_WAIT_TMSI_ACK),
603 .action = proc_arq_vlr_fn_w_trace,
604 },
605 [PR_ARQ_S_WAIT_CHECK_IMEI] = {
606 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_CHECK_IMEI),
607 .in_event_mask = S(PR_ARQ_E_IMEI_RES),
608 .out_state_mask = S(PR_ARQ_S_DONE) |
609 S(PR_ARQ_S_WAIT_TMSI_ACK),
610 .action = proc_arq_vlr_fn_w_imei,
611 },
612 [PR_ARQ_S_WAIT_TMSI_ACK] = {
613 .name = OSMO_STRINGIFY(PR_ARQ_S_WAIT_TMSI_ACK),
614 .in_event_mask = S(PR_ARQ_E_TMSI_ACK),
615 .out_state_mask = S(PR_ARQ_S_DONE),
616 .action = proc_arq_vlr_fn_w_tmsi,
617 },
618 [PR_ARQ_S_DONE] = {
619 .name = OSMO_STRINGIFY(PR_ARQ_S_DONE),
620 .onenter = proc_arq_vlr_dispatch_result,
621 },
622};
623
624static struct osmo_fsm proc_arq_vlr_fsm = {
625 .name = "Process_Access_Request_VLR",
626 .states = proc_arq_vlr_states,
627 .num_states = ARRAY_SIZE(proc_arq_vlr_states),
628 .allstate_event_mask = 0,
629 .allstate_action = NULL,
630 .log_subsys = DVLR,
631 .event_names = proc_arq_vlr_event_names,
632 .cleanup = proc_arq_vlr_cleanup,
633};
634
635void
636vlr_proc_acc_req(struct osmo_fsm_inst *parent,
637 uint32_t parent_event_success,
638 uint32_t parent_event_failure,
639 void *parent_event_data,
640 struct vlr_instance *vlr, void *msc_conn_ref,
641 enum vlr_parq_type type, const uint8_t *mi_lv,
642 const struct osmo_location_area_id *lai,
643 bool authentication_required,
644 enum vlr_ciph ciphering_required,
645 bool is_r99, bool is_utran)
646{
647 struct osmo_fsm_inst *fi;
648 struct proc_arq_priv *par;
649 char mi_string[GSM48_MI_SIZE];
650 uint8_t mi_type;
651
652 fi = osmo_fsm_inst_alloc_child(&proc_arq_vlr_fsm, parent,
653 parent_event_failure);
654 if (!fi)
655 return;
656
657 par = talloc_zero(fi, struct proc_arq_priv);
658 fi->priv = par;
659 par->vlr = vlr;
660 par->msc_conn_ref = msc_conn_ref;
661 par->type = type;
662 par->lai = *lai;
663 par->parent_event_success = parent_event_success;
664 par->parent_event_failure = parent_event_failure;
665 par->parent_event_data = parent_event_data;
666 par->authentication_required = authentication_required;
667 par->ciphering_required = ciphering_required;
668 par->is_r99 = is_r99;
669 par->is_utran = is_utran;
670
671 LOGPFSM(fi, "rev=%s net=%s%s%s\n",
672 is_r99 ? "R99" : "GSM",
673 is_utran ? "UTRAN" : "GERAN",
674 (authentication_required || ciphering_required)?
675 " Auth" : " (no Auth)",
676 (authentication_required || ciphering_required)?
677 (ciphering_required? "+Ciph" : " (no Ciph)")
678 : "");
679
680 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi_lv+1, mi_lv[0]);
681 mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
682 switch (mi_type) {
683 case GSM_MI_TYPE_IMSI:
684 strncpy(par->imsi, mi_string, sizeof(par->imsi)-1);
685 par->imsi[sizeof(par->imsi)-1] = '\0';
686 par->by_tmsi = false;
687 break;
688 case GSM_MI_TYPE_TMSI:
689 par->by_tmsi = true;
690 par->tmsi = osmo_load32be(mi_lv+2);
691 break;
692 case GSM_MI_TYPE_IMEI:
693 /* TODO: IMEI (emergency call) */
694 default:
695 /* FIXME: directly send reject? */
696 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_UNIDENT_SUBSCR);
697 return;
698 }
699
700 osmo_fsm_inst_dispatch(fi, PR_ARQ_E_START, NULL);
701}
702
703/* Gracefully terminate an FSM created by vlr_proc_acc_req() in case of
704 * external timeout (i.e. from MSC). */
705void vlr_parq_conn_timeout(struct osmo_fsm_inst *fi)
706{
707 if (!fi || fi->state == PR_ARQ_S_DONE)
708 return;
709 LOGPFSM(fi, "Connection timed out\n");
710 proc_arq_fsm_done(fi, VLR_PR_ARQ_RES_TIMEOUT);
711}
712
713
714#if 0
715/***********************************************************************
716 * Update_Location_Child_VLR, TS 29.002 Chapter 25.4.4
717 ***********************************************************************/
718
719enum upd_loc_child_vlr_state {
720 ULC_S_IDLE,
721 ULC_S_WAIT_HLR_RESP,
722 ULC_S_DONE,
723};
724
725enum upd_loc_child_vlr_event {
726 ULC_E_START,
727};
728
729static const struct value_string upd_loc_child_vlr_event_names[] = {
730 { ULC_E_START, "START" },
731 { 0, NULL }
732};
733
734static void upd_loc_child_f_idle(struct osmo_fsm_inst *fi, uint32_t event,
735 void *data)
736{
737 OSMO_ASSERT(event == ULC_E_START);
738
739 /* send update location */
740}
741
742static void upd_loc_child_f_w_hlr(struct osmo_fsm_inst *fi, uint32_t event,
743 void *data)
744{
745}
746
747static const struct osmo_fsm_state upd_loc_child_vlr_states[] = {
748 [ULC_S_IDLE] = {
749 .in_event_mask = ,
750 .out_state_mask = S(ULC_S_WAIT_HLR_RESP) |
751 S(ULC_S_DONE),
752 .name = "IDLE",
753 .action = upd_loc_child_f_idle,
754 },
755 [ULC_S_WAIT_HLR_RESP] = {
756 .in_event_mask = ,
757 .out_state_mask = S(ULC_S_DONE),
758 .name = "WAIT-HLR-RESP",
759 .action = upd_loc_child_f_w_hlr,
760 },
761 [ULC_S_DONE] = {
762 .name = "DONE",
763 },
764};
765
766static struct osmo_fsm upd_loc_child_vlr_fsm = {
767 .name = "Update_Location_Child_VLR",
768 .states = upd_loc_child_vlr_states,
769 .num_states = ARRAY_SIZE(upd_loc_child_vlr_states),
770 .log_subsys = DVLR,
771 .event_names = upd_loc_child_vlr_event_names,
772};
773#endif
774
775void vlr_parq_fsm_init(void)
776{
777 //osmo_fsm_register(&upd_loc_child_vlr_fsm);
778 osmo_fsm_register(&proc_arq_vlr_fsm);
779}