Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1 | /* MSC-A role: main subscriber management */ |
| 2 | /* |
Vadim Yanitskiy | 999a593 | 2023-05-18 17:22:26 +0700 | [diff] [blame] | 3 | * (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
| 6 | * SPDX-License-Identifier: AGPL-3.0+ |
| 7 | * |
| 8 | * Author: Neels Hofmeyr |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Affero General Public License as published by |
| 12 | * the Free Software Foundation; either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Affero General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Affero General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | #pragma once |
| 24 | |
| 25 | #include <osmocom/core/use_count.h> |
| 26 | #include <osmocom/core/tdef.h> |
| 27 | |
| 28 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 29 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
| 30 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
| 31 | #include <osmocom/gsm/gsm23003.h> |
| 32 | |
| 33 | #include <osmocom/msc/msc_roles.h> |
| 34 | #include <osmocom/msc/ran_msg.h> |
| 35 | #include <osmocom/msc/msc_common.h> |
| 36 | #include <osmocom/msc/msc_ho.h> |
| 37 | #include <osmocom/msc/neighbor_ident.h> |
| 38 | |
| 39 | struct ran_infra; |
Andreas Eversberg | 6c8db1d | 2023-04-23 12:00:16 +0200 | [diff] [blame] | 40 | struct vgcs_bss; |
| 41 | struct vgcs_bss_cell; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 42 | |
| 43 | #define MSC_A_USE_LOCATION_UPDATING "lu" |
| 44 | #define MSC_A_USE_CM_SERVICE_CC "cm_service_cc" |
Andreas Eversberg | 456c6f7 | 2023-04-23 11:54:16 +0200 | [diff] [blame] | 45 | #define MSC_A_USE_CM_SERVICE_GCC "cm_service_gcc" |
| 46 | #define MSC_A_USE_CM_SERVICE_BCC "cm_service_bcc" |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 47 | #define MSC_A_USE_CM_SERVICE_SMS "cm_service_sms" |
| 48 | #define MSC_A_USE_CM_SERVICE_SS "cm_service_ss" |
| 49 | #define MSC_A_USE_PAGING_RESPONSE "paging-response" |
Andreas Eversberg | 456c6f7 | 2023-04-23 11:54:16 +0200 | [diff] [blame] | 50 | #define MSC_A_USE_GCC "gcc" |
| 51 | #define MSC_A_USE_BCC "bcc" |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 52 | #define MSC_A_USE_CC "cc" |
| 53 | #define MSC_A_USE_SMS "sms" |
Vadim Yanitskiy | 643270f | 2019-05-12 05:38:41 +0700 | [diff] [blame] | 54 | #define MSC_A_USE_SMS_MMTS "sms_mmts" |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 55 | #define MSC_A_USE_NC_SS "nc_ss" |
| 56 | #define MSC_A_USE_SILENT_CALL "silent_call" |
| 57 | |
| 58 | /* These are macros to use the source file:line information from the caller in a trivial way */ |
| 59 | #define msc_a_get(msc_a, use) \ |
| 60 | OSMO_ASSERT(osmo_use_count_get_put(&msc_a->use_count, use, 1) == 0) |
| 61 | #define msc_a_put(msc_a, use) \ |
| 62 | OSMO_ASSERT(osmo_use_count_get_put(&msc_a->use_count, use, -1) == 0) |
| 63 | #define msc_a_put_all(msc_a, use) do { \ |
| 64 | int32_t has_count = osmo_use_count_by(&msc_a->use_count, use); \ |
| 65 | if (has_count) \ |
| 66 | OSMO_ASSERT(osmo_use_count_get_put(&msc_a->use_count, use, -has_count) == 0); \ |
| 67 | } while(0) |
| 68 | |
| 69 | |
| 70 | enum msc_a_action_on_classmark_update_type { |
| 71 | MSC_A_CLASSMARK_UPDATE_NOT_EXPECTED = 0, |
| 72 | MSC_A_CLASSMARK_UPDATE_THEN_CIPHERING, |
| 73 | }; |
| 74 | |
| 75 | /* A Classmark Update might be required for various tasks. At the time of writing, the only use case is to determine A5 |
| 76 | * capabilities for choosing a ciphering algorithm. This structure anticipates other Classmark Update use cases to be |
| 77 | * added in the future. */ |
| 78 | struct msc_a_action_on_classmark_update { |
| 79 | enum msc_a_action_on_classmark_update_type type; |
| 80 | union { |
| 81 | /* State required to resume Ciphering after the Classmark Request / Classmark Update is complete. */ |
| 82 | struct { |
| 83 | bool umts_aka; |
| 84 | bool retrieve_imeisv; |
| 85 | } ciphering; |
| 86 | |
| 87 | /* Add more use cases here... */ |
| 88 | }; |
| 89 | }; |
| 90 | |
| 91 | struct msc_a { |
| 92 | /* struct msc_role_common must remain at start */ |
| 93 | struct msc_role_common c; |
| 94 | enum complete_layer3_type complete_layer3_type; |
| 95 | struct osmo_cell_global_id via_cell; |
| 96 | |
| 97 | /* Temporary storage for Classmark Information for times when a connection has no VLR subscriber |
| 98 | * associated yet. It will get copied to the VLR subscriber upon msc_vlr_subscr_assoc(). */ |
| 99 | struct osmo_gsm48_classmark temporary_classmark; |
| 100 | |
| 101 | /* See handling of E_MSC_A_CLASSMARK_UPDATE */ |
| 102 | struct msc_a_action_on_classmark_update action_on_classmark_update; |
| 103 | uint32_t state_before_classmark_update; |
| 104 | |
| 105 | /* After Ciphering Mode Complete on GERAN, this reflects the chosen ciphering algorithm and key */ |
| 106 | struct geran_encr geran_encr; |
| 107 | |
Vadim Yanitskiy | a79aac0 | 2019-12-28 01:19:19 +0100 | [diff] [blame] | 108 | /* Type of MI requested in MM Identity Request */ |
| 109 | uint8_t mm_id_req_type; |
| 110 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 111 | /* N(SD) expected in the received frame, per flow (TS 24.007 11.2.3.2.3.2.2) */ |
| 112 | uint8_t n_sd_next[4]; |
| 113 | |
| 114 | /* Call control and MSC-A side of RTP switching. Without inter-MSC handover involved, this manages all of the |
| 115 | * MGW and RTP switching; after an inter-MSC handover, the RAN-side of this is redirected via another MNCC |
| 116 | * connection to the Handover MSISDN, and a remote MSC-I role takes over RTP switching to the remote BSS. |
| 117 | * |
| 118 | * Without / before inter-MSC HO: |
| 119 | * |
| 120 | * BSS [MSC-I MSC-A] MNCC to PBX |
| 121 | * <--RTP---------> <--RTP--> |
| 122 | * |
| 123 | * After inter-MSC HO: |
| 124 | * |
| 125 | * BSS [MSC-I MSC-A] MNCC to PBX MSC-I BSS-B |
| 126 | * /--> <--RTP--> |
| 127 | * \-------RTP--> (ISUP) <--RTP--> <--RTP--> |
| 128 | */ |
| 129 | struct { |
Neels Hofmeyr | e276ae9 | 2022-01-13 21:38:35 +0100 | [diff] [blame] | 130 | /* Codec List (BSS Supported) as received during Complete Layer 3 Information */ |
| 131 | struct gsm0808_speech_codec_list compl_l3_codec_list_bss_supported; |
| 132 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 133 | /* All of the RTP stream handling */ |
| 134 | struct call_leg *call_leg; |
| 135 | struct mncc_call *mncc_forwarding_to_remote_ran; |
| 136 | |
| 137 | /* There may be up to 7 incoming calls for this subscriber. This is the currently serviced voice call, |
| 138 | * as in, the other person the subscriber is currently talking to. */ |
| 139 | struct gsm_trans *active_trans; |
| 140 | } cc; |
| 141 | |
| 142 | struct msc_ho_state ho; |
| 143 | |
| 144 | struct osmo_use_count use_count; |
| 145 | struct osmo_use_count_entry use_count_buf[8]; |
| 146 | int32_t max_total_use_count; |
| 147 | }; |
| 148 | |
| 149 | osmo_static_assert(offsetof(struct msc_a, c) == 0, msc_role_common_first_member_of_msc_a); |
| 150 | |
| 151 | struct msc_a_ran_dec_data { |
| 152 | enum msc_role from_role; |
| 153 | const struct an_apdu *an_apdu; |
| 154 | const struct ran_msg *ran_dec; |
| 155 | }; |
| 156 | |
| 157 | #define LOG_MSC_A(MSC_A, LEVEL, FMT, ARGS ...) \ |
| 158 | LOG_MSC_A_CAT(MSC_A, (MSC_A) ? (MSC_A)->c.ran->log_subsys : DMSC, LEVEL, FMT, ## ARGS) |
| 159 | #define LOG_MSC_A_CAT(MSC_A, SUBSYS, LEVEL, FMT, ARGS ...) \ |
| 160 | LOGPFSMSL((MSC_A) ? (MSC_A)->c.fi : NULL, SUBSYS, LEVEL, FMT, ## ARGS) |
| 161 | #define LOG_MSC_A_CAT_SRC(MSC_A, SUBSYS, LEVEL, SRCFILE, LINE, FMT, ARGS ...) \ |
| 162 | LOGPFSMSLSRC((MSC_A) ? (MSC_A)->c.fi : NULL, SUBSYS, LEVEL, SRCFILE, LINE, FMT, ## ARGS) |
| 163 | |
| 164 | enum msc_a_states { |
| 165 | MSC_A_ST_VALIDATE_L3, |
| 166 | MSC_A_ST_AUTH_CIPH, |
| 167 | MSC_A_ST_WAIT_CLASSMARK_UPDATE, |
| 168 | MSC_A_ST_AUTHENTICATED, |
| 169 | MSC_A_ST_COMMUNICATING, |
| 170 | MSC_A_ST_RELEASING, |
| 171 | MSC_A_ST_RELEASED, |
| 172 | }; |
| 173 | |
| 174 | struct msc_a *msc_a_alloc(struct msub *msub, struct ran_infra *ran); |
| 175 | |
| 176 | int msc_a_classmark_request_then_cipher_mode_cmd(struct msc_a *msc_a, bool umts_aka, bool retrieve_imeisv); |
| 177 | |
| 178 | bool msc_a_is_establishing_auth_ciph(const struct msc_a *msc_a); |
| 179 | bool msc_a_is_accepted(const struct msc_a *msc_a); |
| 180 | bool msc_a_in_release(struct msc_a *msc_a); |
| 181 | |
| 182 | struct gsm_network *msc_a_net(const struct msc_a *msc_a); |
| 183 | struct vlr_subscr *msc_a_vsub(const struct msc_a *msc_a); |
| 184 | struct msc_i *msc_a_msc_i(const struct msc_a *msc_a); |
| 185 | struct msc_t *msc_a_msc_t(const struct msc_a *msc_a); |
| 186 | |
| 187 | struct msc_a *msc_a_for_vsub(const struct vlr_subscr *vsub, bool valid_conn_only); |
| 188 | |
| 189 | void msc_a_pending_cm_service_req_add(struct msc_a *msc_a, enum osmo_cm_service_type type); |
| 190 | unsigned int msc_a_pending_cm_service_req_count(struct msc_a *msc_a, enum osmo_cm_service_type type); |
| 191 | void msc_a_pending_cm_service_req_del(struct msc_a *msc_a, enum osmo_cm_service_type type); |
Neels Hofmeyr | d99a607 | 2022-10-10 23:34:48 +0200 | [diff] [blame] | 192 | bool msc_a_is_ciphering_to_be_attempted(const struct msc_a *msc_a); |
Neels Hofmeyr | 2ea7264 | 2022-10-10 23:35:47 +0200 | [diff] [blame] | 193 | bool msc_a_is_ciphering_required(const struct msc_a *msc_a); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 194 | |
| 195 | #define msc_a_ran_down(A,B,C) \ |
| 196 | _msc_a_ran_down(A,B,C, __FILE__, __LINE__) |
| 197 | int _msc_a_ran_down(struct msc_a *msc_a, enum msc_role to_role, const struct ran_msg *ran_enc_msg, |
| 198 | const char *file, int line); |
| 199 | #define msc_a_msg_down(A,B,C,D) \ |
| 200 | _msc_a_msg_down(A,B,C,D, __FILE__, __LINE__) |
| 201 | int _msc_a_msg_down(struct msc_a *msc_a, enum msc_role to_role, uint32_t to_role_event, |
| 202 | const struct ran_msg *ran_enc_msg, |
| 203 | const char *file, int line); |
| 204 | |
| 205 | int msc_a_tx_dtap_to_i(struct msc_a *msc_a, struct msgb *dtap); |
| 206 | int msc_a_tx_common_id(struct msc_a *msc_a); |
| 207 | int msc_a_tx_mm_serv_ack(struct msc_a *msc_a); |
| 208 | int msc_a_tx_mm_serv_rej(struct msc_a *msc_a, enum gsm48_reject_value value); |
| 209 | |
| 210 | int msc_a_up_l3(struct msc_a *msc_a, struct msgb *msg); |
| 211 | |
| 212 | void msc_a_up_ciph_res(struct msc_a *msc_a, bool success, const char *imeisv); |
| 213 | |
| 214 | bool msc_a_is_accepted(const struct msc_a *msc_a); |
| 215 | bool msc_a_is_establishing_auth_ciph(const struct msc_a *msc_a); |
| 216 | |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 217 | int msc_a_ensure_cn_local_rtp(struct msc_a *msc_a, struct gsm_trans *cc_trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 218 | int msc_a_try_call_assignment(struct gsm_trans *cc_trans); |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 219 | void msc_a_tx_assignment_cmd(struct msc_a *msc_a); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 220 | |
Andreas Eversberg | cd8bd45 | 2023-07-11 14:16:24 +0200 | [diff] [blame] | 221 | const char *msc_a_cm_service_type_to_use(struct msc_a *msc_a, enum osmo_cm_service_type cm_service_type); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 222 | |
| 223 | void msc_a_release_cn(struct msc_a *msc_a); |
| 224 | void msc_a_release_mo(struct msc_a *msc_a, enum gsm48_gsm_cause gsm_cause); |
| 225 | |
Andreas Eversberg | 6c8db1d | 2023-04-23 12:00:16 +0200 | [diff] [blame] | 226 | int msc_a_rx_vgcs_bss(struct vgcs_bss *bss, struct ran_conn *from_conn, struct msgb *msg); |
| 227 | int msc_a_rx_vgcs_cell(struct vgcs_bss_cell *cell, struct ran_conn *from_conn, struct msgb *msg); |
| 228 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 229 | int msc_a_ran_decode_cb(struct osmo_fsm_inst *msc_a_fi, void *data, const struct ran_msg *msg); |
| 230 | |
| 231 | int msc_a_vlr_set_cipher_mode(void *_msc_a, bool umts_aka, bool retrieve_imeisv); |
| 232 | |
| 233 | struct msgb *msc_a_ran_encode(struct msc_a *msc_a, const struct ran_msg *ran_enc_msg); |
| 234 | |
| 235 | void msc_a_update_id(struct msc_a *msc_a); |