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