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