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