blob: bff5e67f94b7ff0eff3199d00c5079b9889ecbcf [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001/* Code to manage a subscriber's MSC-A role */
2/*
Vadim Yanitskiy999a5932023-05-18 17:22:26 +07003 * (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01004 * 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
24#include <osmocom/core/utils.h>
25#include <osmocom/core/tdef.h>
26#include <osmocom/core/rate_ctr.h>
27#include <osmocom/core/signal.h>
28
29#include <osmocom/msc/gsm_data.h>
30#include <osmocom/msc/msc_roles.h>
31#include <osmocom/msc/msub.h>
32#include <osmocom/msc/msc_a.h>
33#include <osmocom/msc/msc_t.h>
34#include <osmocom/msc/msc_i.h>
35#include <osmocom/msc/paging.h>
36#include <osmocom/msc/signal.h>
37#include <osmocom/msc/vlr.h>
38#include <osmocom/msc/transaction.h>
Oliver Smithceca8e62023-05-24 11:15:52 +020039#include <osmocom/msc/transaction_cc.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010040#include <osmocom/msc/ran_peer.h>
41#include <osmocom/msc/ran_msg_a.h>
42#include <osmocom/msc/ran_msg_iu.h>
43#include <osmocom/msc/sgs_iface.h>
44#include <osmocom/msc/gsm_04_08.h>
45#include <osmocom/msc/gsm_09_11.h>
46#include <osmocom/msc/gsm_04_14.h>
47#include <osmocom/msc/call_leg.h>
48#include <osmocom/msc/rtp_stream.h>
49#include <osmocom/msc/msc_ho.h>
Neels Hofmeyre276ae92022-01-13 21:38:35 +010050#include <osmocom/msc/codec_mapping.h>
Andreas Eversbergf7c6f142023-04-23 12:10:42 +020051#include <osmocom/msc/msc_vgcs.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010052
53#define MSC_A_USE_WAIT_CLEAR_COMPLETE "wait-Clear-Complete"
54
55static struct osmo_fsm msc_a_fsm;
56
57static const struct osmo_tdef_state_timeout msc_a_fsm_timeouts[32] = {
58 [MSC_A_ST_VALIDATE_L3] = { .T = -1 },
59 [MSC_A_ST_AUTH_CIPH] = { .keep_timer = true },
60 [MSC_A_ST_WAIT_CLASSMARK_UPDATE] = { .keep_timer = true },
61 [MSC_A_ST_AUTHENTICATED] = { .keep_timer = true },
62 [MSC_A_ST_RELEASING] = { .T = -2 },
63 [MSC_A_ST_RELEASED] = { .T = -2 },
64};
65
66/* Transition to a state, using the T timer defined in msc_a_fsm_timeouts.
67 * The actual timeout value is in turn obtained from network->T_defs.
68 * Assumes local variable fi exists. */
Neels Hofmeyr01653252019-09-03 02:06:22 +020069#define msc_a_state_chg_always(msc_a, state) \
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010070 osmo_tdef_fsm_inst_state_chg((msc_a)->c.fi, state, msc_a_fsm_timeouts, (msc_a)->c.ran->tdefs, 5)
71
Neels Hofmeyr01653252019-09-03 02:06:22 +020072/* Same as msc_a_state_chg_always() but ignore if the msc_a already is in the target state. */
73#define msc_a_state_chg(msc_a, STATE) do { \
74 if ((msc_a)->c.fi->state != STATE) \
75 msc_a_state_chg_always(msc_a, STATE); \
76 } while(0)
77
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010078struct gsm_network *msc_a_net(const struct msc_a *msc_a)
79{
80 return msub_net(msc_a->c.msub);
81}
82
83struct vlr_subscr *msc_a_vsub(const struct msc_a *msc_a)
84{
Neels Hofmeyr911e5972019-05-09 13:28:26 +020085 if (!msc_a)
86 return NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010087 return msub_vsub(msc_a->c.msub);
88}
89
90struct msc_i *msc_a_msc_i(const struct msc_a *msc_a)
91{
Neels Hofmeyr911e5972019-05-09 13:28:26 +020092 if (!msc_a)
93 return NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010094 return msub_msc_i(msc_a->c.msub);
95}
96
97struct msc_t *msc_a_msc_t(const struct msc_a *msc_a)
98{
Neels Hofmeyr911e5972019-05-09 13:28:26 +020099 if (!msc_a)
100 return NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100101 return msub_msc_t(msc_a->c.msub);
102}
103
104struct msc_a *msc_a_fi_priv(struct osmo_fsm_inst *fi)
105{
106 OSMO_ASSERT(fi);
107 OSMO_ASSERT(fi->fsm == &msc_a_fsm);
108 OSMO_ASSERT(fi->priv);
109 return fi->priv;
110}
111
Neels Hofmeyrd99a6072022-10-10 23:34:48 +0200112bool msc_a_is_ciphering_to_be_attempted(const struct msc_a *msc_a)
Alexander Couzens2c5e4612021-11-05 02:00:17 +0100113{
114 struct gsm_network *net = msc_a_net(msc_a);
115 bool is_utran = (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU);
116 if (is_utran)
117 return net->uea_encryption_mask > (1 << OSMO_UTRAN_UEA0);
118 else
119 return net->a5_encryption_mask > 0x1;
120}
121
Neels Hofmeyr2ea72642022-10-10 23:35:47 +0200122bool msc_a_is_ciphering_required(const struct msc_a *msc_a)
123{
124 struct gsm_network *net = msc_a_net(msc_a);
125 bool is_utran = (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU);
126 if (is_utran)
127 return net->uea_encryption_mask
128 && ((net->uea_encryption_mask & (1 << OSMO_UTRAN_UEA0)) == 0);
129 else
130 return net->a5_encryption_mask
131 && ((net->a5_encryption_mask & 0x1) == 0);
132}
133
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100134static void update_counters(struct osmo_fsm_inst *fi, bool conn_accepted)
135{
136 struct msc_a *msc_a = fi->priv;
137 struct gsm_network *net = msc_a_net(msc_a);
138 switch (msc_a->complete_layer3_type) {
139 case COMPLETE_LAYER3_LU:
Pau Espin Pedrol2e21a682021-06-04 16:45:44 +0200140 rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, conn_accepted ? MSC_CTR_LOC_UPDATE_COMPLETED : MSC_CTR_LOC_UPDATE_FAILED));
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100141 break;
142 case COMPLETE_LAYER3_CM_SERVICE_REQ:
Pau Espin Pedrol2e21a682021-06-04 16:45:44 +0200143 rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, conn_accepted ? MSC_CTR_CM_SERVICE_REQUEST_ACCEPTED : MSC_CTR_CM_SERVICE_REQUEST_REJECTED));
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100144 break;
145 case COMPLETE_LAYER3_PAGING_RESP:
Pau Espin Pedrol2e21a682021-06-04 16:45:44 +0200146 rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, conn_accepted ? MSC_CTR_PAGING_RESP_ACCEPTED : MSC_CTR_PAGING_RESP_REJECTED));
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100147 break;
Neels Hofmeyrae98b972021-07-27 03:46:49 +0200148 case COMPLETE_LAYER3_CM_RE_ESTABLISH_REQ:
149 rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs,
150 conn_accepted ? MSC_CTR_CM_RE_ESTABLISH_REQ_ACCEPTED
151 : MSC_CTR_CM_RE_ESTABLISH_REQ_REJECTED));
152 break;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100153 default:
154 break;
155 }
156}
157
Vadim Yanitskiy3e66ec52024-05-08 00:17:43 +0200158static void lu_delay_timer_cb(void *data)
159{
160 struct msc_a *msc_a = (struct msc_a *)data;
161 msc_a_put(msc_a, MSC_A_USE_LOCATION_UPDATING);
162}
163
164static void msc_a_put_lu_deferred(struct msc_a *msc_a)
165{
166 unsigned long Tval;
167
168 /* The idea behind timer X36 is to allow re-using the radio channel that was used for
169 * Location Updating to deliver MT SMS over GSUP. This is achieved by delaying
170 * release of a BSSAP/RANAP connection and thus delaying the release of the radio
171 * channel. The delay can be configured separately for GERAN and UTRAN. */
172 switch (msc_a->c.ran->type) {
173 case OSMO_RAT_GERAN_A:
174 Tval = osmo_tdef_get(msc_tdefs_geran, -36, OSMO_TDEF_MS, 0);
175 break;
176 case OSMO_RAT_UTRAN_IU:
177 Tval = osmo_tdef_get(msc_tdefs_utran, -36, OSMO_TDEF_MS, 0);
178 break;
179 default:
180 Tval = 0;
181 break;
182 }
183
184 if (Tval == 0) {
185 /* no delay, put LU token immediately */
186 msc_a_put(msc_a, MSC_A_USE_LOCATION_UPDATING);
187 return;
188 }
189
190 LOG_MSC_A(msc_a, LOGL_INFO, "Keeping LU token for +%lu ms\n", Tval);
191 osmo_timer_schedule(&msc_a->lu_delay_timer,
192 Tval / 1000, /* seconds */
193 Tval % 1000 * 1000); /* microseconds */
194}
195
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100196static void evaluate_acceptance_outcome(struct osmo_fsm_inst *fi, bool conn_accepted)
197{
198 struct msc_a *msc_a = fi->priv;
199 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
200
201 update_counters(fi, conn_accepted);
202
Neels Hofmeyr83cf10c2020-06-24 14:23:26 +0200203 if (conn_accepted) {
204 /* Record the Cell ID seen in Complete Layer 3 Information in the VLR, so that it also shows in vty
205 * 'show' output. */
206 vsub->cgi = msc_a->via_cell;
207 }
208
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100209 /* Trigger transactions that we paged for */
210 if (msc_a->complete_layer3_type == COMPLETE_LAYER3_PAGING_RESP) {
211 if (conn_accepted)
212 paging_response(msc_a);
213 else
214 paging_expired(vsub);
215 }
216
217 if (conn_accepted)
218 osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_ATTACHED, msc_a_vsub(msc_a));
219
220 if (msc_a->complete_layer3_type == COMPLETE_LAYER3_LU)
Vadim Yanitskiy3e66ec52024-05-08 00:17:43 +0200221 msc_a_put_lu_deferred(msc_a);
Neels Hofmeyrae98b972021-07-27 03:46:49 +0200222
Neels Hofmeyrc19f8fe2024-04-03 20:50:36 +0200223 if (conn_accepted && msc_a->complete_layer3_type == COMPLETE_LAYER3_CM_RE_ESTABLISH_REQ) {
Neels Hofmeyrae98b972021-07-27 03:46:49 +0200224 /* Trigger new Assignment to recommence the voice call. A little dance here because normally we verify
225 * that no CC trans is already active. */
226 struct gsm_trans *cc_trans = msc_a->cc.active_trans;
227 msc_a->cc.active_trans = NULL;
228 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, cc_trans);
229 msc_a_try_call_assignment(cc_trans);
230 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100231}
232
233bool msc_a_is_accepted(const struct msc_a *msc_a)
234{
235 if (!msc_a || !msc_a->c.fi)
236 return false;
237 return msc_a->c.fi->state == MSC_A_ST_AUTHENTICATED
238 || msc_a->c.fi->state == MSC_A_ST_COMMUNICATING;
239}
240
241bool msc_a_in_release(struct msc_a *msc_a)
242{
243 if (!msc_a)
244 return true;
245 if (msc_a->c.fi->state == MSC_A_ST_RELEASING)
246 return true;
247 if (msc_a->c.fi->state == MSC_A_ST_RELEASED)
248 return true;
249 return false;
250}
251
252static int msc_a_ran_dec(struct msc_a *msc_a, const struct an_apdu *an_apdu, enum msc_role from_role)
253{
254 int rc;
255 struct msc_a_ran_dec_data d = {
256 .from_role = from_role,
257 .an_apdu = an_apdu,
258 };
259 msc_a_get(msc_a, __func__);
260 rc = msc_role_ran_decode(msc_a->c.fi, an_apdu, msc_a_ran_decode_cb, &d);
261 msc_a_put(msc_a, __func__);
262 return rc;
263};
264
265static void msc_a_fsm_validate_l3(struct osmo_fsm_inst *fi, uint32_t event, void *data)
266{
267 struct msc_a *msc_a = fi->priv;
268 const struct an_apdu *an_apdu;
269
270 switch (event) {
271 case MSC_A_EV_FROM_I_COMPLETE_LAYER_3:
272 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
273 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
274 an_apdu = data;
275 msc_a_ran_dec(msc_a, an_apdu, MSC_ROLE_I);
276 return;
277
278 case MSC_A_EV_COMPLETE_LAYER_3_OK:
279 msc_a_state_chg(msc_a, MSC_A_ST_AUTH_CIPH);
280 return;
281
282 case MSC_A_EV_MO_CLOSE:
283 case MSC_A_EV_CN_CLOSE:
284 evaluate_acceptance_outcome(fi, false);
285 /* fall through */
286 case MSC_A_EV_UNUSED:
287 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
288 return;
289
290 default:
291 OSMO_ASSERT(false);
292 }
293}
294
295/* Figure out whether to first send a Classmark Request to the MS to figure out algorithm support. */
296static bool msc_a_need_classmark_for_ciphering(struct msc_a *msc_a)
297{
298 struct gsm_network *net = msc_a_net(msc_a);
299 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
300 int i = 0;
301 bool request_classmark = false;
302
303 /* Only on GERAN-A do we ever need Classmark Information for Ciphering. */
304 if (msc_a->c.ran->type != OSMO_RAT_GERAN_A)
305 return false;
306
307 for (i = 0; i < 8; i++) {
308 int supported;
309
310 /* A5/n permitted by osmo-msc.cfg? */
311 if (!(net->a5_encryption_mask & (1 << i)))
312 continue;
313
314 /* A5/n supported by MS? */
315 supported = osmo_gsm48_classmark_supports_a5(&vsub->classmark, i);
316 if (supported < 0) {
317 LOG_MSC_A(msc_a, LOGL_DEBUG, "For A5/%d, we still need Classmark %d\n", i, -supported);
318 request_classmark = true;
319 }
320 }
321
322 return request_classmark;
323}
324
325static int msc_a_ran_enc_ciphering(struct msc_a *msc_a, bool umts_aka, bool retrieve_imeisv);
326
327/* VLR callback for ops.set_ciph_mode() */
328int msc_a_vlr_set_cipher_mode(void *_msc_a, bool umts_aka, bool retrieve_imeisv)
329{
330 struct msc_a *msc_a = _msc_a;
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700331 struct vlr_subscr *vsub;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100332
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700333 if (!msc_a) {
334 LOGP(DMSC, LOGL_ERROR, "Insufficient info to start ciphering: "
335 "MSC-A role is NULL?!?\n");
336 return -EINVAL;
337 }
338
339 vsub = msc_a_vsub(msc_a);
340 if (!vsub || !vsub->last_tuple) {
341 LOG_MSC_A(msc_a, LOGL_ERROR, "Insufficient info to start ciphering: "
342 "vlr_subscr is NULL?!?\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100343 return -EINVAL;
344 }
345
346 if (msc_a_need_classmark_for_ciphering(msc_a)) {
347 int rc;
348 struct ran_msg msg = {
349 .msg_type = RAN_MSG_CLASSMARK_REQUEST,
350 };
351 rc = msc_a_ran_down(msc_a, MSC_ROLE_I, &msg);
352 if (rc) {
353 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot send Classmark Request\n");
354 return -EIO;
355 }
356
357 msc_a->state_before_classmark_update = msc_a->c.fi->state;
358 msc_a->action_on_classmark_update = (struct msc_a_action_on_classmark_update){
359 .type = MSC_A_CLASSMARK_UPDATE_THEN_CIPHERING,
360 .ciphering = {
361 .umts_aka = umts_aka,
362 .retrieve_imeisv = retrieve_imeisv,
363 },
364 };
365 msc_a_state_chg(msc_a, MSC_A_ST_WAIT_CLASSMARK_UPDATE);
366 return 0;
367 }
368
369 return msc_a_ran_enc_ciphering(msc_a, umts_aka, retrieve_imeisv);
370}
371
Neels Hofmeyr6ce2edc2021-06-09 22:26:11 +0200372static uint8_t filter_a5(uint8_t a5_mask, bool umts_aka)
373{
374 /* With GSM AKA: allow A5/0, 1, 3 = 0b00001011 = 0xb.
375 * UMTS aka: allow A5/0, 1, 3, 4 = 0b00011011 = 0x1b.
376 */
377 return a5_mask & (umts_aka ? 0x1b : 0x0b);
378}
379
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100380static int msc_a_ran_enc_ciphering(struct msc_a *msc_a, bool umts_aka, bool retrieve_imeisv)
381{
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700382 struct gsm_network *net;
383 struct vlr_subscr *vsub;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100384 struct ran_msg msg;
385
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700386 if (!msc_a) {
387 LOGP(DMSC, LOGL_ERROR, "Insufficient info to start ciphering: "
388 "MSC-A role is NULL?!?\n");
389 return -EINVAL;
390 }
391
392 net = msc_a_net(msc_a);
393 vsub = msc_a_vsub(msc_a);
394
395 if (!net || !vsub || !vsub->last_tuple) {
396 LOG_MSC_A(msc_a, LOGL_ERROR, "Insufficient info to start ciphering: "
397 "gsm_network and/or vlr_subscr is NULL?!?\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100398 return -EINVAL;
399 }
400
401 msg = (struct ran_msg){
402 .msg_type = RAN_MSG_CIPHER_MODE_COMMAND,
403 .cipher_mode_command = {
404 .vec = vsub->last_tuple ? &vsub->last_tuple->vec : NULL,
405 .classmark = &vsub->classmark,
406 .geran = {
407 .umts_aka = umts_aka,
408 .retrieve_imeisv = retrieve_imeisv,
Neels Hofmeyr6ce2edc2021-06-09 22:26:11 +0200409 .a5_encryption_mask = filter_a5(net->a5_encryption_mask, umts_aka),
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100410
411 /* for ran_a.c to store the GERAN key that is actually used */
412 .chosen_key = &msc_a->geran_encr,
413 },
Harald Welte274b70f2021-02-06 16:47:39 +0100414 .utran = {
Harald Welte505a94a2021-02-06 17:12:20 +0100415 .uea_encryption_mask = net->uea_encryption_mask,
416 },
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100417 },
418 };
419
420 if (msc_a_ran_down(msc_a, MSC_ROLE_I, &msg)) {
421 LOG_MSC_A(msc_a, LOGL_ERROR, "Sending Cipher Mode Command failed\n");
422 /* Returning error to the VLR ops.set_ciph_mode() will cancel the attach. Other callers need to take
423 * care of the return value. */
424 return -EINVAL;
425 }
426
427 if (msc_a->geran_encr.key_len)
Neels Hofmeyr73d093a2021-06-23 23:54:43 +0200428 LOG_MSC_A(msc_a, LOGL_DEBUG, "RAN encoding chose ciphering: A5/%d kc %s kc128 %s\n",
429 msc_a->geran_encr.alg_id - 1,
430 osmo_hexdump_nospc_c(OTC_SELECT, msc_a->geran_encr.key, msc_a->geran_encr.key_len),
431 msc_a->geran_encr.kc128_present ?
432 osmo_hexdump_nospc_c(OTC_SELECT, msc_a->geran_encr.kc128, sizeof(msc_a->geran_encr.kc128))
433 : "-");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100434 return 0;
435}
436
437static void msc_a_fsm_auth_ciph(struct osmo_fsm_inst *fi, uint32_t event, void *data)
438{
439 struct msc_a *msc_a = fi->priv;
440
441 /* If accepted, transition the state, all other cases mean failure. */
442 switch (event) {
443 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
444 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
445 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
446 return;
447
448 case MSC_A_EV_AUTHENTICATED:
449 msc_a_state_chg(msc_a, MSC_A_ST_AUTHENTICATED);
450 return;
451
452 case MSC_A_EV_UNUSED:
453 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
454 return;
455
456 case MSC_A_EV_MO_CLOSE:
457 case MSC_A_EV_CN_CLOSE:
458 evaluate_acceptance_outcome(fi, false);
459 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
460 return;
461
462
463 default:
464 OSMO_ASSERT(false);
465 }
466}
467
468static void msc_a_fsm_wait_classmark_update(struct osmo_fsm_inst *fi, uint32_t event, void *data)
469{
470 struct msc_a *msc_a = fi->priv;
471
472 switch (event) {
473 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
474 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
475 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
476 return;
477
478 case MSC_A_EV_CLASSMARK_UPDATE:
479 switch (msc_a->action_on_classmark_update.type) {
480 case MSC_A_CLASSMARK_UPDATE_THEN_CIPHERING:
481 msc_a_state_chg(msc_a, MSC_A_ST_AUTH_CIPH);
482 if (msc_a_ran_enc_ciphering(msc_a,
483 msc_a->action_on_classmark_update.ciphering.umts_aka,
484 msc_a->action_on_classmark_update.ciphering.retrieve_imeisv)) {
485 LOG_MSC_A(msc_a, LOGL_ERROR,
486 "After Classmark Update, still failed to send Cipher Mode Command\n");
487 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
488 }
489 return;
490
491 default:
492 LOG_MSC_A(msc_a, LOGL_ERROR, "Internal error: After Classmark Update, don't know what to do\n");
493 msc_a_state_chg(msc_a, msc_a->state_before_classmark_update);
494 return;
495 }
496
497 case MSC_A_EV_UNUSED:
498 /* Seems something detached / aborted in the middle of auth+ciph. */
499 evaluate_acceptance_outcome(fi, false);
500 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
501 return;
502
503 case MSC_A_EV_MO_CLOSE:
504 case MSC_A_EV_CN_CLOSE:
505 evaluate_acceptance_outcome(fi, false);
506 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
507 return;
508
509 default:
510 OSMO_ASSERT(false);
511 }
512}
513
514static bool msc_a_fsm_has_active_transactions(struct osmo_fsm_inst *fi)
515{
516 struct msc_a *msc_a = fi->priv;
517 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
518 struct gsm_trans *trans;
519
520 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_SILENT_CALL)) {
521 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: silent call still active\n", __func__);
522 return true;
523 }
524
525 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_CC)) {
526 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO CC request after a CM Service Request\n",
527 __func__);
528 return true;
529 }
Andreas Eversberg456c6f72023-04-23 11:54:16 +0200530 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_GCC)) {
531 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO GCC request after a CM Service Request\n",
532 __func__);
533 return true;
534 }
535 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_BCC)) {
536 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO BCC request after a CM Service Request\n",
537 __func__);
538 return true;
539 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100540 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_SMS)) {
541 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO SMS after a CM Service Request\n",
542 __func__);
543 return true;
544 }
545 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_SS)) {
546 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO SS after a CM Service Request\n",
547 __func__);
548 return true;
549 }
550
551 if (vsub && !llist_empty(&vsub->cs.requests)) {
552 struct paging_request *pr;
553 llist_for_each_entry(pr, &vsub->cs.requests, entry) {
554 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still active: %s\n", __func__, pr->label);
555 }
556 return true;
557 }
558
559 if ((trans = trans_has_conn(msc_a))) {
560 LOG_MSC_A(msc_a, LOGL_DEBUG, "connection still has active transaction: %s\n",
561 trans_type_name(trans->type));
562 return true;
563 }
564
565 return false;
566}
567
568static void msc_a_fsm_authenticated_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
569{
570 struct msc_a *msc_a = fi->priv;
571 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
572
573 /* Stop Location Update expiry for this subscriber. While the subscriber
574 * has an open connection the LU expiry timer must remain disabled.
575 * Otherwise we would kick the subscriber off the network when the timer
576 * expires e.g. during a long phone call.
577 * The LU expiry timer will restart once the connection is closed. */
578 if (vsub)
579 vsub->expire_lu = VLR_SUBSCRIBER_NO_EXPIRATION;
580
581 evaluate_acceptance_outcome(fi, true);
582}
583
584static void msc_a_fsm_authenticated(struct osmo_fsm_inst *fi, uint32_t event, void *data)
585{
586 struct msc_a *msc_a = fi->priv;
587
588 switch (event) {
589 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
590 case MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST:
591 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
592 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
593 return;
594
595 case MSC_A_EV_COMPLETE_LAYER_3_OK:
596 /* When Authentication is off, we may already be in the Accepted state when the code
597 * evaluates the Compl L3. Simply ignore. This just cosmetically mutes the error log
598 * about the useless event. */
599 return;
600
601 case MSC_A_EV_TRANSACTION_ACCEPTED:
602 msc_a_state_chg(msc_a, MSC_A_ST_COMMUNICATING);
603 return;
604
605 case MSC_A_EV_MO_CLOSE:
606 case MSC_A_EV_CN_CLOSE:
607 case MSC_A_EV_UNUSED:
608 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
609 return;
610
611 default:
612 OSMO_ASSERT(false);
613 }
614}
615
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +0100616static struct call_leg *msc_a_ensure_call_leg(struct msc_a *msc_a, struct gsm_trans *for_cc_trans)
617{
618 struct call_leg *cl = msc_a->cc.call_leg;
619 struct gsm_network *net = msc_a_net(msc_a);
620
621 /* Ensure that events about RTP endpoints coming from the msc_a->cc.call_leg know which gsm_trans to abort on
622 * error */
623 if (!msc_a->cc.active_trans)
624 msc_a->cc.active_trans = for_cc_trans;
625 if (msc_a->cc.active_trans != for_cc_trans) {
626 LOG_TRANS(for_cc_trans, LOGL_ERROR,
627 "Cannot create call leg, another trans is already active for this conn\n");
628 return NULL;
629 }
630
631 if (!cl) {
632 cl = msc_a->cc.call_leg = call_leg_alloc(msc_a->c.fi,
633 MSC_EV_CALL_LEG_TERM,
634 MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE,
635 MSC_EV_CALL_LEG_RTP_COMPLETE);
636 OSMO_ASSERT(cl);
637
638 if (net->use_osmux != OSMUX_USAGE_OFF) {
639 struct msc_i *msc_i = msc_a_msc_i(msc_a);
640 if (msc_i->c.remote_to) {
641 /* TODO: investigate what to do in this case */
642 LOG_MSC_A(msc_a, LOGL_ERROR, "Osmux not yet supported for inter-MSC");
643 } else {
644 cl->ran_peer_supports_osmux = msc_i->ran_conn->ran_peer->remote_supports_osmux;
645 }
646 }
647
648 }
649 return cl;
650}
651
652int msc_a_ensure_cn_local_rtp(struct msc_a *msc_a, struct gsm_trans *cc_trans)
653{
654 struct call_leg *cl;
655 struct rtp_stream *rtp_to_ran;
656
657 cl = msc_a_ensure_call_leg(msc_a, cc_trans);
658 if (!cl)
659 return -EINVAL;
660 rtp_to_ran = cl->rtp[RTP_TO_RAN];
661
662 if (call_leg_local_ip(cl, RTP_TO_CN)) {
663 /* Already has an RTP address and port towards the CN, continue right away. */
664 return osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE, cl->rtp[RTP_TO_CN]);
665 }
666
667 /* No CN RTP address available yet, ask the MGW to create one.
668 * Set a codec to be used: if Assignment on the RAN side is already done, take the same codec as the RTP_TO_RAN.
669 * If no RAN side RTP is established, try to guess a preliminary codec from SDP -- before Assignment, picking a
670 * codec from the SDP is more politeness/avoiding confusion than necessity. The actual codec to be used would be
671 * determined later. If no codec could be determined, pass none for the time being. */
Andreas Eversberg712b28e2023-06-21 11:17:26 +0200672 return call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->call_id, cc_trans,
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +0100673 rtp_to_ran->codecs_known ? &rtp_to_ran->codecs : NULL, NULL);
674}
675
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100676/* The MGW has given us a local IP address for the RAN side. Ready to start the Assignment of a voice channel. */
Neels Hofmeyrd767c732023-11-17 04:12:29 +0100677void msc_a_tx_assignment_cmd(struct msc_a *msc_a)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100678{
679 struct ran_msg msg;
680 struct gsm_trans *cc_trans = msc_a->cc.active_trans;
681 struct gsm0808_channel_type channel_type;
682
Neels Hofmeyr00a476b2019-11-28 02:46:05 +0100683 if (!cc_trans) {
684 LOG_MSC_A(msc_a, LOGL_ERROR, "No CC transaction active\n");
685 call_leg_release(msc_a->cc.call_leg);
686 return;
687 }
688
Oliver Smithceca8e62023-05-24 11:15:52 +0200689 trans_cc_filter_run(cc_trans);
690 LOG_TRANS(cc_trans, LOGL_DEBUG, "Sending Assignment Command\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100691
Oliver Smith10632132023-05-12 12:14:22 +0200692 switch (cc_trans->bearer_cap.transfer) {
693 case GSM48_BCAP_ITCAP_SPEECH:
694 if (!cc_trans->cc.local.audio_codecs.count) {
695 LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching codec: %s\n",
696 codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.local, &cc_trans->cc.remote));
697 call_leg_release(msc_a->cc.call_leg);
698 return;
699 }
700
701 /* Compose 48.008 Channel Type from the current set of codecs
702 * determined from both local and remote codec capabilities. */
703 if (sdp_audio_codecs_to_gsm0808_channel_type(&channel_type, &cc_trans->cc.local.audio_codecs)) {
704 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose Channel Type (Permitted Speech) from codecs: %s\n",
705 codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.local, &cc_trans->cc.remote));
706 trans_free(cc_trans);
707 return;
708 }
709 break;
Manawyrm1ed12ea2023-10-14 17:23:04 +0200710 case GSM48_BCAP_ITCAP_3k1_AUDIO:
711 case GSM48_BCAP_ITCAP_FAX_G3:
Oliver Smith10632132023-05-12 12:14:22 +0200712 case GSM48_BCAP_ITCAP_UNR_DIG_INF:
713 if (!cc_trans->cc.local.bearer_services.count) {
714 LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching bearer service: %s\n",
715 csd_filter_to_str(&cc_trans->cc.csd, &cc_trans->cc.local, &cc_trans->cc.remote));
716 call_leg_release(msc_a->cc.call_leg);
717 return;
718 }
719
720 /* Compose 48.008 Channel Type from the current set of bearer
721 * services determined from local and remote capabilities. */
722 if (csd_bs_list_to_gsm0808_channel_type(&channel_type, &cc_trans->cc.local.bearer_services)) {
723 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose channel type from: %s\n",
724 csd_filter_to_str(&cc_trans->cc.csd, &cc_trans->cc.local, &cc_trans->cc.remote));
725 return;
726 }
727 break;
728 default:
729 LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible for information transfer capability %d\n",
730 cc_trans->bearer_cap.transfer);
Neels Hofmeyr11a746a2023-01-26 15:00:06 +0100731 call_leg_release(msc_a->cc.call_leg);
732 return;
733 }
734
Oliver Smith10632132023-05-12 12:14:22 +0200735 /* The RAN side RTP address is known, so the voice/CSD Assignment can commence. */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100736 msg = (struct ran_msg){
737 .msg_type = RAN_MSG_ASSIGNMENT_COMMAND,
738 .assignment_command = {
739 .cn_rtp = &msc_a->cc.call_leg->rtp[RTP_TO_RAN]->local,
740 .channel_type = &channel_type,
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +0200741 .osmux_present = msc_a->cc.call_leg->rtp[RTP_TO_RAN]->use_osmux,
742 .osmux_cid = msc_a->cc.call_leg->rtp[RTP_TO_RAN]->local_osmux_cid,
Philipp Maierf34d9452020-06-05 15:49:35 +0200743 .call_id_present = true,
Andreas Eversberg712b28e2023-06-21 11:17:26 +0200744 .call_id = cc_trans->call_id,
Keith Whytea1a70be2021-05-16 02:59:52 +0200745 .lcls = cc_trans->cc.lcls,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100746 },
747 };
748 if (msc_a_ran_down(msc_a, MSC_ROLE_I, &msg)) {
749 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot send Assignment\n");
Neels Hofmeyrf439ff12019-10-05 04:19:36 +0200750 trans_free(cc_trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100751 return;
752 }
753}
754
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100755static struct gsm_trans *find_waiting_call(struct msc_a *msc_a)
756{
757 struct gsm_trans *trans;
758 struct gsm_network *net = msc_a_net(msc_a);
759
760 llist_for_each_entry(trans, &net->trans_list, entry) {
761 if (trans->msc_a != msc_a)
762 continue;
763 if (trans->type != TRANS_CC)
764 continue;
765 if (trans->msc_a->cc.active_trans == trans)
766 continue;
767 return trans;
768 }
769 return NULL;
770}
771
772static void msc_a_cleanup_rtp_streams(struct msc_a *msc_a, uint32_t event, void *data)
773{
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100774 switch (event) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100775
776 case MSC_EV_CALL_LEG_TERM:
777 msc_a->cc.call_leg = NULL;
778 if (msc_a->cc.mncc_forwarding_to_remote_ran)
779 msc_a->cc.mncc_forwarding_to_remote_ran->rtps = NULL;
780
Neels Hofmeyr265a4c72019-05-09 16:20:51 +0200781 if (msc_a->ho.new_cell.mncc_forwarding_to_remote_ran)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100782 msc_a->ho.new_cell.mncc_forwarding_to_remote_ran->rtps = NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100783 return;
784
785 case MSC_MNCC_EV_CALL_ENDED:
786 msc_a->cc.mncc_forwarding_to_remote_ran = NULL;
787 return;
788
789 default:
790 return;
791 }
792}
793
794static void msc_a_fsm_communicating(struct osmo_fsm_inst *fi, uint32_t event, void *data)
795{
796 struct msc_a *msc_a = fi->priv;
797 struct rtp_stream *rtps;
798 struct gsm_trans *waiting_trans;
799 struct an_apdu *an_apdu;
800
801 msc_a_cleanup_rtp_streams(msc_a, event, data);
802
803 switch (event) {
804 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
805 case MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST:
806 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
807 an_apdu = data;
808 msc_a_ran_dec(msc_a, an_apdu, MSC_ROLE_I);
809 return;
810
811 case MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE:
812 case MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE:
813 case MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST:
814 case MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST:
815 an_apdu = data;
816 msc_a_ran_dec(msc_a, an_apdu, MSC_ROLE_T);
817 return;
818
819 case MSC_A_EV_TRANSACTION_ACCEPTED:
820 /* no-op */
821 return;
822
823 case MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE:
824 rtps = data;
825 if (!rtps) {
826 LOG_MSC_A(msc_a, LOGL_ERROR, "Invalid data for %s\n", osmo_fsm_event_name(fi->fsm, event));
827 return;
828 }
Neels Hofmeyr00a476b2019-11-28 02:46:05 +0100829 if (!msc_a->cc.call_leg) {
830 LOG_MSC_A(msc_a, LOGL_ERROR, "No call leg active\n");
831 return;
832 }
Neels Hofmeyrcc918cb2019-11-28 02:16:34 +0100833 if (!osmo_sockaddr_str_is_nonzero(&rtps->local)) {
834 LOG_MSC_A(msc_a, LOGL_ERROR, "Invalid RTP address received from MGW: " OSMO_SOCKADDR_STR_FMT "\n",
835 OSMO_SOCKADDR_STR_FMT_ARGS(&rtps->local));
836 call_leg_release(msc_a->cc.call_leg);
837 return;
838 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100839 LOG_MSC_A(msc_a, LOGL_DEBUG,
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +0200840 "MGW endpoint's RTP address available for the CI %s: " OSMO_SOCKADDR_STR_FMT " (osmux=%s:%d)\n",
841 rtp_direction_name(rtps->dir), OSMO_SOCKADDR_STR_FMT_ARGS(&rtps->local),
842 rtps->use_osmux ? "yes" : "no", rtps->local_osmux_cid);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100843 switch (rtps->dir) {
844 case RTP_TO_RAN:
Neels Hofmeyrd767c732023-11-17 04:12:29 +0100845 msc_a_tx_assignment_cmd(msc_a);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100846 return;
847 case RTP_TO_CN:
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +0100848 cc_on_cn_local_rtp_port_known(rtps->for_trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100849 return;
850 default:
851 LOG_MSC_A(msc_a, LOGL_ERROR, "Invalid data for %s\n", osmo_fsm_event_name(fi->fsm, event));
852 return;
853 }
854
855 case MSC_EV_CALL_LEG_RTP_COMPLETE:
856 /* Nothing to do. */
857 return;
858
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100859 case MSC_MNCC_EV_CALL_ENDED:
860 /* Cleaned up above */
861 return;
862
863 case MSC_EV_CALL_LEG_TERM:
864 /* RTP streams cleaned up above */
865
866 msc_a_get(msc_a, __func__);
867 if (msc_a->cc.active_trans)
868 trans_free(msc_a->cc.active_trans);
869
870 /* If there is another call still waiting to be activated, this is the time when the mgcp_ctx is
871 * available again and the other call can start assigning. */
872 waiting_trans = find_waiting_call(msc_a);
873 if (waiting_trans) {
874 LOG_MSC_A(msc_a, LOGL_DEBUG, "(ti %02x) Call waiting: starting Assignment\n",
875 waiting_trans->transaction_id);
876 msc_a_try_call_assignment(waiting_trans);
877 }
878 msc_a_put(msc_a, __func__);
879 return;
880
881 case MSC_A_EV_HANDOVER_REQUIRED:
882 msc_ho_start(msc_a, (struct ran_handover_required*)data);
883 return;
884
Neels Hofmeyr0a437be2019-05-10 15:55:52 +0200885 case MSC_A_EV_HANDOVER_END:
886 /* Termination event of the msc_ho_fsm. No action needed, it's all done in the msc_ho_fsm cleanup. This
887 * event only exists because osmo_fsm_inst_alloc_child() requires a parent term event; and maybe
888 * interesting for logging. */
889 return;
890
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100891 case MSC_A_EV_MO_CLOSE:
892 case MSC_A_EV_CN_CLOSE:
893 case MSC_A_EV_UNUSED:
894 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
895 return;
896
897 default:
898 OSMO_ASSERT(false);
899 }
900}
901
902static int msc_a_fsm_timer_cb(struct osmo_fsm_inst *fi)
903{
904 struct msc_a *msc_a = fi->priv;
905 if (msc_a_in_release(msc_a)) {
906 LOG_MSC_A(msc_a, LOGL_ERROR, "Timeout while releasing, discarding right now\n");
907 msc_a_put_all(msc_a, MSC_A_USE_WAIT_CLEAR_COMPLETE);
908 msc_a_state_chg(msc_a, MSC_A_ST_RELEASED);
909 } else {
910 enum gsm48_reject_value cause = GSM48_REJECT_CONGESTION;
911 osmo_fsm_inst_dispatch(fi, MSC_A_EV_CN_CLOSE, &cause);
912 }
913 return 0;
914}
915
916static void msc_a_fsm_releasing_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
917{
918 struct msc_a *msc_a = fi->priv;
919 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
920 int i;
921 char buf[128];
922 const char * const use_counts_to_cancel[] = {
923 MSC_A_USE_LOCATION_UPDATING,
924 MSC_A_USE_CM_SERVICE_CC,
925 MSC_A_USE_CM_SERVICE_SMS,
926 MSC_A_USE_CM_SERVICE_SS,
Andreas Eversberg456c6f72023-04-23 11:54:16 +0200927 MSC_A_USE_CM_SERVICE_GCC,
928 MSC_A_USE_CM_SERVICE_BCC,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100929 MSC_A_USE_PAGING_RESPONSE,
930 };
931
932 LOG_MSC_A(msc_a, LOGL_DEBUG, "Releasing: msc_a use is %s\n",
933 osmo_use_count_name_buf(buf, sizeof(buf), &msc_a->use_count));
934
935 if (vsub) {
936 vlr_subscr_get(vsub, __func__);
937
938 /* Cancel all VLR FSMs, if any */
939 vlr_subscr_cancel_attach_fsm(vsub, OSMO_FSM_TERM_ERROR, GSM48_REJECT_CONGESTION);
940
941 /* The subscriber has no active connection anymore.
942 * Restart the periodic Location Update expiry timer for this subscriber. */
943 vlr_subscr_enable_expire_lu(vsub);
944 }
945
946 /* If we're closing in a middle of a trans, we need to clean up */
947 trans_conn_closed(msc_a);
948
949 call_leg_release(msc_a->cc.call_leg);
950
951 /* Cancel use counts for pending CM Service / Paging */
952 for (i = 0; i < ARRAY_SIZE(use_counts_to_cancel); i++) {
953 const char *use = use_counts_to_cancel[i];
954 int32_t count = osmo_use_count_by(&msc_a->use_count, use);
955 if (!count)
956 continue;
957 LOG_MSC_A(msc_a, LOGL_DEBUG, "Releasing: canceling still pending use: %s (%d)\n", use, count);
958 osmo_use_count_get_put(&msc_a->use_count, use, -count);
959 }
960
961 if (msc_a->c.ran->type == OSMO_RAT_EUTRAN_SGS) {
962 sgs_iface_tx_release(vsub);
963 /* In SGsAP there is no confirmation of a release. */
964 msc_a_state_chg(msc_a, MSC_A_ST_RELEASED);
965 } else {
966 struct ran_msg msg = {
967 .msg_type = RAN_MSG_CLEAR_COMMAND,
968 .clear_command = {
Neels Hofmeyrd9fe7112020-07-11 00:20:20 +0200969 /* "Call Control" is the only cause code listed in 3GPP TS 48.008 3.2.1.21 CLEAR COMMAND
970 * that qualifies for a normal release situation. (OS#4664) */
971 .gsm0808_cause = GSM0808_CAUSE_CALL_CONTROL,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100972 .csfb_ind = (vsub && vsub->sgs_fsm->state == SGS_UE_ST_ASSOCIATED),
973 },
974 };
975 msc_a_get(msc_a, MSC_A_USE_WAIT_CLEAR_COMPLETE);
976 msc_a_ran_down(msc_a, MSC_ROLE_I, &msg);
Philipp Maier47cf84d2019-08-15 14:56:54 +0200977
978 /* The connection is cleared. The MS will now go back to 4G,
979 Switch the RAN type back to SGS. */
980 if (vsub && vsub->sgs_fsm->state == SGS_UE_ST_ASSOCIATED)
981 vsub->cs.attached_via_ran = OSMO_RAT_EUTRAN_SGS;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100982 }
983
984 if (vsub)
985 vlr_subscr_put(vsub, __func__);
986}
987
988static void msc_a_fsm_releasing(struct osmo_fsm_inst *fi, uint32_t event, void *data)
989{
990 struct msc_a *msc_a = fi->priv;
991
992 msc_a_cleanup_rtp_streams(msc_a, event, data);
993
994 switch (event) {
995 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
996 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
997 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
998 return;
999
1000 case MSC_A_EV_MO_CLOSE:
1001 case MSC_A_EV_CN_CLOSE:
1002 case MSC_A_EV_UNUSED:
1003 /* Already releasing */
1004 return;
1005
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001006 case MSC_EV_CALL_LEG_TERM:
1007 case MSC_MNCC_EV_CALL_ENDED:
1008 /* RTP streams cleaned up above */
1009 return;
1010
Neels Hofmeyr0a437be2019-05-10 15:55:52 +02001011 case MSC_A_EV_HANDOVER_END:
1012 /* msc_ho_fsm does cleanup. */
1013 return;
1014
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001015 default:
1016 OSMO_ASSERT(false);
1017 }
1018}
1019
1020
1021static void msc_a_fsm_released_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
1022{
1023 struct msc_a *msc_a = msc_a_fi_priv(fi);
1024 char buf[128];
1025 LOG_MSC_A(msc_a, LOGL_DEBUG, "Released: msc_a use is %s\n",
1026 osmo_use_count_name_buf(buf, sizeof(buf), &msc_a->use_count));
1027 if (osmo_use_count_total(&msc_a->use_count) == 0)
1028 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, fi);
1029}
1030
1031static void msc_a_fsm_released(struct osmo_fsm_inst *fi, uint32_t event, void *data)
1032{
1033 if (event == MSC_A_EV_UNUSED)
1034 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, fi);
1035}
1036
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001037void msc_a_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
1038{
1039 struct msc_a *msc_a = msc_a_fi_priv(fi);
Neels Hofmeyr72ef7d82024-03-26 01:43:53 +01001040 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001041
1042 trans_conn_closed(msc_a);
1043
1044 if (msc_a_fsm_has_active_transactions(fi))
1045 LOG_MSC_A(msc_a, LOGL_ERROR, "Deallocating active transactions failed\n");
1046
1047 LOG_MSC_A_CAT(msc_a, DREF, LOGL_DEBUG, "max total use count was %d\n", msc_a->max_total_use_count);
Neels Hofmeyr72ef7d82024-03-26 01:43:53 +01001048
1049 /* Invalidate the active conn in VLR subscriber state, if any. */
1050 if (vsub && vsub->msc_conn_ref == msc_a)
1051 vsub->msc_conn_ref = NULL;
Vadim Yanitskiy3e66ec52024-05-08 00:17:43 +02001052
1053 osmo_timer_del(&msc_a->lu_delay_timer);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001054}
1055
1056const struct value_string msc_a_fsm_event_names[] = {
1057 OSMO_VALUE_STRING(MSC_REMOTE_EV_RX_GSUP),
1058 OSMO_VALUE_STRING(MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE),
1059 OSMO_VALUE_STRING(MSC_EV_CALL_LEG_RTP_COMPLETE),
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001060 OSMO_VALUE_STRING(MSC_EV_CALL_LEG_TERM),
1061 OSMO_VALUE_STRING(MSC_MNCC_EV_NEED_LOCAL_RTP),
1062 OSMO_VALUE_STRING(MSC_MNCC_EV_CALL_PROCEEDING),
1063 OSMO_VALUE_STRING(MSC_MNCC_EV_CALL_COMPLETE),
1064 OSMO_VALUE_STRING(MSC_MNCC_EV_CALL_ENDED),
1065 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_COMPLETE_LAYER_3),
1066 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST),
1067 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST),
1068 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST),
1069 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST),
1070 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE),
1071 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE),
1072 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST),
1073 OSMO_VALUE_STRING(MSC_A_EV_COMPLETE_LAYER_3_OK),
1074 OSMO_VALUE_STRING(MSC_A_EV_CLASSMARK_UPDATE),
1075 OSMO_VALUE_STRING(MSC_A_EV_AUTHENTICATED),
1076 OSMO_VALUE_STRING(MSC_A_EV_TRANSACTION_ACCEPTED),
1077 OSMO_VALUE_STRING(MSC_A_EV_CN_CLOSE),
1078 OSMO_VALUE_STRING(MSC_A_EV_MO_CLOSE),
1079 OSMO_VALUE_STRING(MSC_A_EV_UNUSED),
1080 OSMO_VALUE_STRING(MSC_A_EV_HANDOVER_REQUIRED),
1081 OSMO_VALUE_STRING(MSC_A_EV_HANDOVER_END),
1082 {}
1083};
1084
1085#define S(x) (1 << (x))
1086
1087static const struct osmo_fsm_state msc_a_fsm_states[] = {
1088 [MSC_A_ST_VALIDATE_L3] = {
1089 .name = OSMO_STRINGIFY(MSC_A_ST_VALIDATE_L3),
1090 .in_event_mask = 0
1091 | S(MSC_A_EV_FROM_I_COMPLETE_LAYER_3)
1092 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1093 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1094 | S(MSC_A_EV_COMPLETE_LAYER_3_OK)
1095 | S(MSC_A_EV_MO_CLOSE)
1096 | S(MSC_A_EV_CN_CLOSE)
1097 | S(MSC_A_EV_UNUSED)
1098 ,
1099 .out_state_mask = 0
1100 | S(MSC_A_ST_VALIDATE_L3)
1101 | S(MSC_A_ST_AUTH_CIPH)
1102 | S(MSC_A_ST_RELEASING)
1103 ,
1104 .action = msc_a_fsm_validate_l3,
1105 },
1106 [MSC_A_ST_AUTH_CIPH] = {
1107 .name = OSMO_STRINGIFY(MSC_A_ST_AUTH_CIPH),
1108 .in_event_mask = 0
1109 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1110 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1111 | S(MSC_A_EV_AUTHENTICATED)
1112 | S(MSC_A_EV_MO_CLOSE)
1113 | S(MSC_A_EV_CN_CLOSE)
1114 | S(MSC_A_EV_UNUSED)
1115 ,
1116 .out_state_mask = 0
1117 | S(MSC_A_ST_WAIT_CLASSMARK_UPDATE)
1118 | S(MSC_A_ST_AUTHENTICATED)
1119 | S(MSC_A_ST_RELEASING)
1120 ,
1121 .action = msc_a_fsm_auth_ciph,
1122 },
1123 [MSC_A_ST_WAIT_CLASSMARK_UPDATE] = {
1124 .name = OSMO_STRINGIFY(MSC_A_ST_WAIT_CLASSMARK_UPDATE),
1125 .in_event_mask = 0
1126 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1127 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1128 | S(MSC_A_EV_CLASSMARK_UPDATE)
1129 | S(MSC_A_EV_MO_CLOSE)
1130 | S(MSC_A_EV_CN_CLOSE)
1131 ,
1132 .out_state_mask = 0
1133 | S(MSC_A_ST_AUTH_CIPH)
1134 | S(MSC_A_ST_RELEASING)
1135 ,
1136 .action = msc_a_fsm_wait_classmark_update,
1137 },
1138 [MSC_A_ST_AUTHENTICATED] = {
1139 .name = OSMO_STRINGIFY(MSC_A_ST_AUTHENTICATED),
1140 /* allow everything to release for any odd behavior */
1141 .in_event_mask = 0
1142 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1143 | S(MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST)
1144 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1145 | S(MSC_A_EV_TRANSACTION_ACCEPTED)
1146 | S(MSC_A_EV_MO_CLOSE)
1147 | S(MSC_A_EV_CN_CLOSE)
1148 | S(MSC_A_EV_UNUSED)
1149 ,
1150 .out_state_mask = 0
1151 | S(MSC_A_ST_RELEASING)
1152 | S(MSC_A_ST_COMMUNICATING)
1153 ,
1154 .onenter = msc_a_fsm_authenticated_enter,
1155 .action = msc_a_fsm_authenticated,
1156 },
1157 [MSC_A_ST_COMMUNICATING] = {
1158 .name = OSMO_STRINGIFY(MSC_A_ST_COMMUNICATING),
1159 /* allow everything to release for any odd behavior */
1160 .in_event_mask = 0
1161 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1162 | S(MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST)
1163 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1164 | S(MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE)
1165 | S(MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE)
1166 | S(MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST)
1167 | S(MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST)
1168 | S(MSC_A_EV_TRANSACTION_ACCEPTED)
1169 | S(MSC_A_EV_MO_CLOSE)
1170 | S(MSC_A_EV_CN_CLOSE)
1171 | S(MSC_A_EV_UNUSED)
1172 | S(MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE)
1173 | S(MSC_EV_CALL_LEG_RTP_COMPLETE)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001174 | S(MSC_EV_CALL_LEG_TERM)
1175 | S(MSC_MNCC_EV_CALL_ENDED)
1176 | S(MSC_A_EV_HANDOVER_REQUIRED)
Neels Hofmeyr0a437be2019-05-10 15:55:52 +02001177 | S(MSC_A_EV_HANDOVER_END)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001178 ,
1179 .out_state_mask = 0
1180 | S(MSC_A_ST_RELEASING)
1181 ,
1182 .action = msc_a_fsm_communicating,
1183 },
1184 [MSC_A_ST_RELEASING] = {
1185 .name = OSMO_STRINGIFY(MSC_A_ST_RELEASING),
1186 .in_event_mask = 0
1187 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1188 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1189 | S(MSC_A_EV_UNUSED)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001190 | S(MSC_EV_CALL_LEG_TERM)
1191 | S(MSC_MNCC_EV_CALL_ENDED)
Neels Hofmeyr0a437be2019-05-10 15:55:52 +02001192 | S(MSC_A_EV_HANDOVER_END)
Pau Espin Pedrole53ecde2021-07-12 13:37:24 +02001193 | S(MSC_A_EV_CN_CLOSE)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001194 ,
1195 .out_state_mask = 0
1196 | S(MSC_A_ST_RELEASED)
1197 ,
1198 .onenter = msc_a_fsm_releasing_onenter,
1199 .action = msc_a_fsm_releasing,
1200 },
1201 [MSC_A_ST_RELEASED] = {
1202 .name = OSMO_STRINGIFY(MSC_A_ST_RELEASED),
1203 .in_event_mask = 0
1204 | S(MSC_A_EV_UNUSED)
1205 ,
1206 .onenter = msc_a_fsm_released_onenter,
1207 .action = msc_a_fsm_released,
1208 },
1209};
1210
1211static struct osmo_fsm msc_a_fsm = {
1212 .name = "msc_a",
1213 .states = msc_a_fsm_states,
1214 .num_states = ARRAY_SIZE(msc_a_fsm_states),
1215 .log_subsys = DMSC,
1216 .event_names = msc_a_fsm_event_names,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001217 .timer_cb = msc_a_fsm_timer_cb,
1218 .cleanup = msc_a_fsm_cleanup,
1219};
1220
1221static __attribute__((constructor)) void msc_a_fsm_init()
1222{
1223 OSMO_ASSERT(osmo_fsm_register(&msc_a_fsm) == 0);
1224}
1225
1226static int msc_a_use_cb(struct osmo_use_count_entry *e, int32_t old_use_count, const char *file, int line)
1227{
1228 struct msc_a *msc_a = e->use_count->talloc_object;
1229 char buf[128];
1230 int32_t total;
1231 int level;
1232
1233 if (!e->use)
1234 return -EINVAL;
1235
1236 total = osmo_use_count_total(&msc_a->use_count);
1237
1238 if (total == 0
1239 || (total == 1 && old_use_count == 0 && e->count == 1))
1240 level = LOGL_INFO;
1241 else
1242 level = LOGL_DEBUG;
1243
1244 LOG_MSC_A_CAT_SRC(msc_a, DREF, level, file, line, "%s %s: now used by %s\n",
1245 (e->count - old_use_count) > 0? "+" : "-", e->use,
1246 osmo_use_count_name_buf(buf, sizeof(buf), &msc_a->use_count));
1247
1248 if (e->count < 0)
1249 return -ERANGE;
1250
1251 msc_a->max_total_use_count = OSMO_MAX(msc_a->max_total_use_count, total);
1252
1253 if (total == 0)
1254 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_UNUSED, NULL);
1255 return 0;
1256}
1257
1258struct msc_a *msc_a_alloc(struct msub *msub, struct ran_infra *ran)
1259{
1260 struct msc_a *msc_a = msub_role_alloc(msub, MSC_ROLE_A, &msc_a_fsm, struct msc_a, ran);
1261 msc_a->use_count = (struct osmo_use_count){
1262 .talloc_object = msc_a,
1263 .use_cb = msc_a_use_cb,
1264 };
1265 osmo_use_count_make_static_entries(&msc_a->use_count, msc_a->use_count_buf, ARRAY_SIZE(msc_a->use_count_buf));
1266 /* Start timeout for first state */
Neels Hofmeyr01653252019-09-03 02:06:22 +02001267 msc_a_state_chg_always(msc_a, MSC_A_ST_VALIDATE_L3);
Vadim Yanitskiy3e66ec52024-05-08 00:17:43 +02001268 osmo_timer_setup(&msc_a->lu_delay_timer, &lu_delay_timer_cb, msc_a);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001269 return msc_a;
1270}
1271
1272bool msc_a_is_establishing_auth_ciph(const struct msc_a *msc_a)
1273{
1274 if (!msc_a || !msc_a->c.fi)
1275 return false;
1276 return msc_a->c.fi->state == MSC_A_ST_AUTH_CIPH;
1277}
1278
1279const struct value_string complete_layer3_type_names[] = {
1280 { COMPLETE_LAYER3_NONE, "NONE" },
1281 { COMPLETE_LAYER3_LU, "LU" },
1282 { COMPLETE_LAYER3_CM_SERVICE_REQ, "CM_SERVICE_REQ" },
1283 { COMPLETE_LAYER3_PAGING_RESP, "PAGING_RESP" },
Neels Hofmeyrae98b972021-07-27 03:46:49 +02001284 { COMPLETE_LAYER3_CM_RE_ESTABLISH_REQ, "CM_RE_ESTABLISH_REQ" },
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001285 { 0, NULL }
1286};
1287
1288#define _msc_a_update_id(MSC_A, FMT, ARGS ...) \
1289 do { \
1290 if (osmo_fsm_inst_update_id_f(msc_a->c.fi, FMT ":%s:%s", \
1291 ## ARGS, \
1292 msub_ran_conn_name(msc_a->c.msub), \
1293 complete_layer3_type_name(msc_a->complete_layer3_type)) \
1294 == 0) { \
1295 struct vlr_subscr *_vsub = msc_a_vsub(MSC_A); \
1296 if (_vsub) { \
1297 if (_vsub->lu_fsm) \
1298 osmo_fsm_inst_update_id(_vsub->lu_fsm, (MSC_A)->c.fi->id); \
1299 if (_vsub->auth_fsm) \
1300 osmo_fsm_inst_update_id(_vsub->auth_fsm, (MSC_A)->c.fi->id); \
1301 if (_vsub->proc_arq_fsm) \
1302 osmo_fsm_inst_update_id(_vsub->proc_arq_fsm, (MSC_A)->c.fi->id); \
1303 } \
1304 LOG_MSC_A(MSC_A, LOGL_DEBUG, "Updated ID\n"); \
1305 } \
1306 /* otherwise osmo_fsm_inst_update_id_f() will log an error. */ \
1307 } while (0)
1308
1309
1310/* Compose an ID almost like gsm48_mi_to_string(), but print the MI type along, and print a TMSI as hex. */
Neels Hofmeyr46d526a2020-05-29 03:27:50 +02001311void msc_a_update_id_from_mi(struct msc_a *msc_a, const struct osmo_mobile_identity *mi)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001312{
Neels Hofmeyr46d526a2020-05-29 03:27:50 +02001313 _msc_a_update_id(msc_a, "%s", osmo_mobile_identity_to_str_c(OTC_SELECT, mi));
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001314}
1315
1316/* Update msc_a->fi id string from current msc_a->vsub and msc_a->complete_layer3_type. */
1317void msc_a_update_id(struct msc_a *msc_a)
1318{
1319 _msc_a_update_id(msc_a, "%s", vlr_subscr_name(msc_a_vsub(msc_a)));
1320}
1321
1322/* Iterate all msc_a instances that are relevant for this subscriber, and update FSM ID strings for all of the FSM
1323 * instances. */
1324void msc_a_update_id_for_vsub(struct vlr_subscr *for_vsub)
1325{
1326 struct msub *msub;
1327 llist_for_each_entry(msub, &msub_list, entry) {
1328 struct vlr_subscr *vsub = msub_vsub(msub);
1329 if (vsub != for_vsub)
1330 continue;
1331 msc_a_update_id(msub_msc_a(msub));
1332 }
1333}
1334
1335static bool msg_is_initially_permitted(const struct gsm48_hdr *hdr)
1336{
1337 uint8_t pdisc = gsm48_hdr_pdisc(hdr);
1338 uint8_t msg_type = gsm48_hdr_msg_type(hdr);
1339
1340 switch (pdisc) {
1341 case GSM48_PDISC_MM:
1342 switch (msg_type) {
1343 case GSM48_MT_MM_LOC_UPD_REQUEST:
1344 case GSM48_MT_MM_CM_SERV_REQ:
1345 case GSM48_MT_MM_CM_REEST_REQ:
1346 case GSM48_MT_MM_AUTH_RESP:
1347 case GSM48_MT_MM_AUTH_FAIL:
1348 case GSM48_MT_MM_ID_RESP:
1349 case GSM48_MT_MM_TMSI_REALL_COMPL:
1350 case GSM48_MT_MM_IMSI_DETACH_IND:
1351 return true;
1352 default:
1353 break;
1354 }
1355 break;
1356 case GSM48_PDISC_RR:
1357 switch (msg_type) {
1358 /* GSM48_MT_RR_CIPH_M_COMPL is actually handled in bssmap_rx_ciph_compl() and gets redirected in the
1359 * BSSAP layer to ran_conn_cipher_mode_compl() (before this here is reached) */
1360 case GSM48_MT_RR_PAG_RESP:
1361 case GSM48_MT_RR_CIPH_M_COMPL:
1362 return true;
1363 default:
1364 break;
1365 }
1366 break;
1367 default:
1368 break;
1369 }
1370
1371 return false;
1372}
1373
1374/* Main entry point for GSM 04.08/44.008 Layer 3 data (e.g. from the BSC). */
1375int msc_a_up_l3(struct msc_a *msc_a, struct msgb *msg)
1376{
1377 struct gsm48_hdr *gh;
1378 uint8_t pdisc;
1379 int rc;
1380 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
1381 int is_r99;
1382
1383 OSMO_ASSERT(msg->l3h);
1384 OSMO_ASSERT(msg);
1385
1386 gh = msgb_l3(msg);
1387 pdisc = gsm48_hdr_pdisc(gh);
1388
1389 LOG_MSC_A_CAT(msc_a, DRLL, LOGL_DEBUG, "Dispatching 04.08 message: %s %s\n",
1390 gsm48_pdisc_name(pdisc), gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1391
1392 /* To evaluate the 3GPP TS 24.007 Duplicate Detection, we need Classmark information on whether the MS is R99
1393 * capable. If the subscriber is already actively connected, the Classmark information is stored with the
1394 * vlr_subscr. Otherwise, this *must* be a Complete Layer 3 with Classmark info. */
1395 if (vsub)
1396 is_r99 = osmo_gsm48_classmark_is_r99(&vsub->classmark) ? 1 : 0;
1397 else
1398 is_r99 = compl_l3_msg_is_r99(msg);
1399
1400 if (is_r99 < 0) {
1401 LOG_MSC_A(msc_a, LOGL_ERROR,
1402 "No Classmark Information, dropping non-Complete-Layer3 message: %s\n",
1403 gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1404 return -EACCES;
1405 }
1406
1407 if (is_r99 >= 0
1408 && ran_dec_dtap_undup_is_duplicate(msc_a->c.fi, msc_a->n_sd_next, is_r99 ? true : false, msg)) {
1409 LOG_MSC_A(msc_a, LOGL_DEBUG, "Dropping duplicate message"
1410 " (3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection)\n");
1411 return 0;
1412 }
1413
1414 if (!msc_a_is_accepted(msc_a)
1415 && !msg_is_initially_permitted(gh)) {
1416 LOG_MSC_A(msc_a, LOGL_ERROR,
1417 "Message not permitted for initial conn: %s\n",
1418 gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1419 return -EACCES;
1420 }
1421
1422 if (vsub && vsub->cs.attached_via_ran != msc_a->c.ran->type) {
1423 LOG_MSC_A(msc_a, LOGL_ERROR,
1424 "Illegal situation: RAN type mismatch:"
1425 " attached via %s, received message via %s\n",
1426 osmo_rat_type_name(vsub->cs.attached_via_ran),
1427 osmo_rat_type_name(msc_a->c.ran->type));
1428 return -EACCES;
1429 }
1430
1431#if 0
1432 if (silent_call_reroute(conn, msg))
1433 return silent_call_rx(conn, msg);
1434#endif
1435
1436 switch (pdisc) {
Andreas Eversberg23b53e52023-06-21 13:30:58 +02001437 case GSM48_PDISC_GROUP_CC:
1438 case GSM48_PDISC_BCAST_CC:
1439 rc = gsm44068_rcv_bcc_gcc(msc_a, NULL, msg);
1440 break;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001441 case GSM48_PDISC_CC:
1442 rc = gsm0408_rcv_cc(msc_a, msg);
1443 break;
1444 case GSM48_PDISC_MM:
1445 rc = gsm0408_rcv_mm(msc_a, msg);
1446 break;
1447 case GSM48_PDISC_RR:
1448 rc = gsm0408_rcv_rr(msc_a, msg);
1449 break;
1450 case GSM48_PDISC_SMS:
1451 rc = gsm0411_rcv_sms(msc_a, msg);
1452 break;
1453 case GSM48_PDISC_MM_GPRS:
1454 case GSM48_PDISC_SM_GPRS:
1455 LOG_MSC_A_CAT(msc_a, DRLL, LOGL_NOTICE, "Unimplemented "
1456 "GSM 04.08 discriminator 0x%02x\n", pdisc);
1457 rc = -ENOTSUP;
1458 break;
1459 case GSM48_PDISC_NC_SS:
1460 rc = gsm0911_rcv_nc_ss(msc_a, msg);
1461 break;
1462 case GSM48_PDISC_TEST:
1463 rc = gsm0414_rcv_test(msc_a, msg);
1464 break;
1465 default:
1466 LOG_MSC_A_CAT(msc_a, DRLL, LOGL_NOTICE, "Unknown "
1467 "GSM 04.08 discriminator 0x%02x\n", pdisc);
1468 rc = -EINVAL;
1469 break;
1470 }
1471
1472 return rc;
1473}
1474
1475static void msc_a_up_call_assignment_complete(struct msc_a *msc_a, const struct ran_msg *ac)
1476{
Andreas Eversberg23b53e52023-06-21 13:30:58 +02001477 struct gsm_trans *cc_trans = msc_a->cc.active_trans, *gcc_trans;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001478 struct rtp_stream *rtps_to_ran = msc_a->cc.call_leg ? msc_a->cc.call_leg->rtp[RTP_TO_RAN] : NULL;
Neels Hofmeyrcec51b32023-03-01 03:47:45 +01001479 const struct gsm0808_speech_codec *codec_if_known = ac->assignment_complete.codec_present ?
1480 &ac->assignment_complete.codec : NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001481
Andreas Eversberg23b53e52023-06-21 13:30:58 +02001482 /* For a voice group call, handling is performed by VGCS FSM */
1483 gcc_trans = trans_find_by_type(msc_a, TRANS_GCC);
1484 if (gcc_trans) {
1485 vgcs_vbs_caller_assign_cpl(gcc_trans);
1486 return;
1487 }
1488 gcc_trans = trans_find_by_type(msc_a, TRANS_BCC);
1489 if (gcc_trans) {
1490 vgcs_vbs_caller_assign_cpl(gcc_trans);
1491 return;
1492 }
1493
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001494 if (!rtps_to_ran) {
1495 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx Assignment Complete, but no RTP stream is set up\n");
1496 return;
1497 }
1498 if (!cc_trans) {
Neels Hofmeyr550506a2022-01-13 23:31:57 +01001499 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx Assignment Complete, but no CC transaction is active\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001500 return;
1501 }
1502
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +02001503 if (rtps_to_ran->use_osmux != ac->assignment_complete.osmux_present) {
1504 LOG_MSC_A_CAT(msc_a, DCC, LOGL_ERROR, "Osmux usage ass request and complete don't match: %d vs %d\n",
1505 rtps_to_ran->use_osmux, ac->assignment_complete.osmux_present);
1506 call_leg_release(msc_a->cc.call_leg);
1507 return;
1508 }
1509
Neels Hofmeyr62bfa372022-10-31 18:51:07 +01001510 if (codec_if_known) {
Neels Hofmeyr1a07bcd2024-01-19 06:37:57 +01001511 const struct codec_mapping *codec_assigned;
1512
Neels Hofmeyrbd8ac512024-01-19 06:38:11 +01001513 /* Check for unexpected codec with CSD */
Vadim Yanitskiyb0300112024-02-06 16:58:28 +07001514 switch (cc_trans->bearer_cap.transfer) {
1515 case GSM48_BCAP_ITCAP_FAX_G3:
1516 case GSM48_BCAP_ITCAP_3k1_AUDIO:
1517 case GSM48_BCAP_ITCAP_UNR_DIG_INF:
1518 if (codec_if_known->type == GSM0808_SCT_CSD)
1519 break; /* we're good */
Neels Hofmeyrbd8ac512024-01-19 06:38:11 +01001520 LOG_TRANS(cc_trans, LOGL_ERROR, "Unexpected codec in Assignment Complete for CSD: %s\n",
1521 gsm0808_speech_codec_type_name(codec_if_known->type));
1522 call_leg_release(msc_a->cc.call_leg);
1523 return;
Vadim Yanitskiyb0300112024-02-06 16:58:28 +07001524 default:
1525 break;
Neels Hofmeyrbd8ac512024-01-19 06:38:11 +01001526 }
1527
Neels Hofmeyr388d7c92023-03-22 19:03:15 +01001528 /* For 2G:
1529 * - The Assignment Complete has returned a specific codec (e.g. FR3 for AMR FR).
1530 * - Set this codec at the MGW endpoint facing the RAN.
1531 * - Also set this codec at the MGW endpoint facing the CN -- we require an exact match on both call
1532 * legs.
1533 * - TODO: be aware of transcoding that the MGW is capable of, e.g. AMR octet-aligned to AMR
1534 * bandwidth-efficient...
1535 *
1536 * For 3G:
1537 * - ran_infra->force_mgw_codecs_to_ran sets VND.3GPP.IUFP as single codec at the MGW towards RAN.
1538 * - ran_msg_iu.c always returns FR3 (AMR FR) for the assigned codec. Set that at the MGW towards CN.
1539 * - So the MGW decapsulates IuUP <-> AMR
1540 */
Neels Hofmeyr1a07bcd2024-01-19 06:37:57 +01001541 codec_assigned = codec_mapping_by_gsm0808_speech_codec_type(codec_if_known->type);
Neels Hofmeyr388d7c92023-03-22 19:03:15 +01001542 /* TODO: use codec_mapping_by_gsm0808_speech_codec() to also match on codec_if_known->cfg */
Neels Hofmeyr1a07bcd2024-01-19 06:37:57 +01001543 if (!codec_assigned) {
Neels Hofmeyr388d7c92023-03-22 19:03:15 +01001544 LOG_TRANS(cc_trans, LOGL_ERROR, "Unknown codec in Assignment Complete: %s\n",
1545 gsm0808_speech_codec_type_name(codec_if_known->type));
1546 call_leg_release(msc_a->cc.call_leg);
1547 return;
Neels Hofmeyr62bfa372022-10-31 18:51:07 +01001548 }
1549
Neels Hofmeyrcec51b32023-03-01 03:47:45 +01001550 /* Update RAN-side endpoint CI from Assignment result -- unless it is forced by the ran_infra, in which
1551 * case it remains unchanged as passed to the earlier call of call_leg_ensure_ci(). */
1552 if (msc_a->c.ran->force_mgw_codecs_to_ran.count == 0)
Neels Hofmeyr1a07bcd2024-01-19 06:37:57 +01001553 rtp_stream_set_one_codec(rtps_to_ran, &codec_assigned->sdp);
Neels Hofmeyr62bfa372022-10-31 18:51:07 +01001554
1555 /* Update codec filter with Assignment result, for the CN side */
Neels Hofmeyr1a07bcd2024-01-19 06:37:57 +01001556 cc_trans->cc.codecs.assignment = codec_assigned->sdp;
Neels Hofmeyr62bfa372022-10-31 18:51:07 +01001557 } else {
1558 /* No codec passed in Assignment Complete, set 'codecs.assignment' to none. */
1559 cc_trans->cc.codecs.assignment = (struct sdp_audio_codec){};
1560 LOG_TRANS(cc_trans, LOGL_INFO, "Assignment Complete without voice codec\n");
1561 }
1562
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001563 rtp_stream_set_remote_addr(rtps_to_ran, &ac->assignment_complete.remote_rtp);
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +02001564 if (rtps_to_ran->use_osmux)
1565 rtp_stream_set_remote_osmux_cid(rtps_to_ran,
1566 ac->assignment_complete.osmux_cid);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001567 rtp_stream_commit(rtps_to_ran);
1568
Neels Hofmeyr2d57d6e2022-01-13 21:39:58 +01001569 /* Remember the Codec List (BSS Supported) */
1570 if (ac->assignment_complete.codec_list_bss_supported)
1571 codec_filter_set_bss(&cc_trans->cc.codecs, ac->assignment_complete.codec_list_bss_supported);
1572
Oliver Smithceca8e62023-05-24 11:15:52 +02001573 trans_cc_filter_run(cc_trans);
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01001574 LOG_TRANS(cc_trans, LOGL_INFO, "Assignment Complete: RAN: %s, CN: %s\n",
1575 sdp_audio_codecs_to_str(&rtps_to_ran->codecs),
Oliver Smithc63c3a02023-05-24 10:48:07 +02001576 sdp_audio_codecs_to_str(&cc_trans->cc.local.audio_codecs));
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01001577
1578 if (cc_on_assignment_done(cc_trans)) {
1579 /* If an error occurred, it was logged in cc_assignment_done() */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001580 call_leg_release(msc_a->cc.call_leg);
1581 return;
1582 }
1583}
1584
1585static void msc_a_up_call_assignment_failure(struct msc_a *msc_a, const struct ran_msg *af)
1586{
1587 struct gsm_trans *trans;
1588
1589 /* For a normal voice call, there will be an rtp_stream FSM. */
1590 if (msc_a->cc.call_leg && msc_a->cc.call_leg->rtp[RTP_TO_RAN]) {
1591 LOG_MSC_A(msc_a, LOGL_ERROR, "Assignment Failure, releasing call\n");
1592 rtp_stream_release(msc_a->cc.call_leg->rtp[RTP_TO_RAN]);
1593 return;
1594 }
1595
Andreas Eversberg23b53e52023-06-21 13:30:58 +02001596 /* For a voice group call, release is performed by VGCS FSM */
1597 trans = trans_find_by_type(msc_a, TRANS_GCC);
1598 if (trans) {
1599 vgcs_vbs_caller_assign_fail(trans);
1600 return;
1601 }
1602 trans = trans_find_by_type(msc_a, TRANS_BCC);
1603 if (trans) {
1604 vgcs_vbs_caller_assign_fail(trans);
1605 return;
1606 }
1607
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001608 /* Otherwise, a silent call might be active */
1609 trans = trans_find_by_type(msc_a, TRANS_SILENT_CALL);
1610 if (trans) {
1611 LOG_MSC_A(msc_a, LOGL_ERROR, "Assignment Failure, releasing silent call\n");
1612 trans_free(trans);
1613 return;
1614 }
1615
1616 /* Neither a voice call nor silent call assignment. Assume the worst and detach. */
1617 msc_a_release_cn(msc_a);
1618}
1619
1620static void msc_a_up_classmark_update(struct msc_a *msc_a, const struct osmo_gsm48_classmark *classmark,
1621 struct osmo_gsm48_classmark *dst)
1622{
1623 if (!dst) {
1624 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
1625
1626 if (!vsub)
1627 dst = &msc_a->temporary_classmark;
1628 else
1629 dst = &vsub->classmark;
1630 }
1631
Martin Hauke3f07dac2019-11-14 17:49:08 +01001632 LOG_MSC_A(msc_a, LOGL_DEBUG, "A5 capabilities received from Classmark Update: %s\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001633 osmo_gsm48_classmark_a5_name(classmark));
1634 osmo_gsm48_classmark_update(dst, classmark);
1635
1636 /* bump subscr conn FSM in case it is waiting for a Classmark Update */
1637 if (msc_a->c.fi->state == MSC_A_ST_WAIT_CLASSMARK_UPDATE)
1638 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_CLASSMARK_UPDATE, NULL);
1639}
1640
1641static void msc_a_up_sapi_n_reject(struct msc_a *msc_a, const struct ran_msg *msg)
1642{
1643 int sapi = msg->sapi_n_reject.dlci & 0x7;
1644 if (sapi == UM_SAPI_SMS)
1645 gsm411_sapi_n_reject(msc_a);
1646}
1647
1648static int msc_a_up_ho(struct msc_a *msc_a, const struct msc_a_ran_dec_data *d, uint32_t ho_fi_event)
1649{
1650 if (!msc_a->ho.fi) {
1651 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx Handover message, but no Handover ongoing: %s\n", d->ran_dec->msg_name);
1652 return -EINVAL;
1653 }
1654 return osmo_fsm_inst_dispatch(msc_a->ho.fi, ho_fi_event, (void*)d);
1655}
1656
1657int msc_a_ran_dec_from_msc_i(struct msc_a *msc_a, struct msc_a_ran_dec_data *d)
1658{
1659 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
Alexander Couzens2aaff752021-10-19 17:09:11 +02001660 struct gsm_network *net = msc_a_net(msc_a);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001661 const struct ran_msg *msg = d->ran_dec;
1662 int rc = -99;
1663
1664 switch (msg->msg_type) {
1665
1666 case RAN_MSG_COMPL_L3:
Neels Hofmeyr68f50da2020-06-24 14:22:52 +02001667 /* In case the cell_id from Complete Layer 3 Information lacks a PLMN, write the configured PLMN code
1668 * into msc_a->via_cell. Then overwrite with those bits obtained from Complete Layer 3 Information. */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001669 msc_a->via_cell = (struct osmo_cell_global_id){
1670 .lai.plmn = msc_a_net(msc_a)->plmn,
1671 };
1672 gsm0808_cell_id_to_cgi(&msc_a->via_cell, msg->compl_l3.cell_id);
Neels Hofmeyrede90832022-01-13 18:13:15 +01001673
Neels Hofmeyre276ae92022-01-13 21:38:35 +01001674 /* If a codec list was sent along in the RAN_MSG_COMPL_L3, remember it for any upcoming codec
1675 * resolution. */
1676 if (msg->compl_l3.codec_list_bss_supported) {
1677 msc_a->cc.compl_l3_codec_list_bss_supported = *msg->compl_l3.codec_list_bss_supported;
1678 if (log_check_level(msc_a->c.ran->log_subsys, LOGL_DEBUG)) {
1679 struct sdp_audio_codecs ac = {};
1680 sdp_audio_codecs_from_speech_codec_list(&ac, &msc_a->cc.compl_l3_codec_list_bss_supported);
1681 LOG_MSC_A(msc_a, LOGL_DEBUG, "Complete Layer 3: Codec List (BSS Supported): %s\n",
1682 sdp_audio_codecs_to_str(&ac));
1683 }
1684 }
1685
Neels Hofmeyrede90832022-01-13 18:13:15 +01001686 /* Submit the Complete Layer 3 Information DTAP */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001687 rc = msc_a_up_l3(msc_a, msg->compl_l3.msg);
1688 if (!rc) {
1689 struct ran_conn *conn = msub_ran_conn(msc_a->c.msub);
1690 if (conn)
1691 ran_peer_cells_seen_add(conn->ran_peer, msg->compl_l3.cell_id);
1692 }
1693 break;
1694
1695 case RAN_MSG_DTAP:
1696 rc = msc_a_up_l3(msc_a, msg->dtap);
1697 break;
1698
1699 case RAN_MSG_CLEAR_REQUEST:
1700 rc = osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_MO_CLOSE, NULL);
1701 break;
1702
1703 case RAN_MSG_CLEAR_COMPLETE:
1704 switch (msc_a->c.fi->state) {
1705 case MSC_A_ST_RELEASING:
1706 msc_a_put_all(msc_a, MSC_A_USE_WAIT_CLEAR_COMPLETE);
1707 msc_a_state_chg(msc_a, MSC_A_ST_RELEASED);
1708 break;
1709 case MSC_A_ST_RELEASED:
1710 break;
1711 default:
1712 LOG_MSC_A(msc_a, LOGL_ERROR, "Received Clear Complete event, but did not send Clear Command\n");
1713 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
1714 break;
1715 }
1716 rc = 0;
1717 break;
1718
1719 case RAN_MSG_CLASSMARK_UPDATE:
1720 msc_a_up_classmark_update(msc_a, msg->classmark_update.classmark, NULL);
1721 rc = 0;
1722 break;
1723
1724 case RAN_MSG_CIPHER_MODE_COMPLETE:
1725 /* Remember what Ciphering was negotiated (e.g. for Handover) */
1726 if (msg->cipher_mode_complete.alg_id) {
1727 msc_a->geran_encr.alg_id = msg->cipher_mode_complete.alg_id;
1728 LOG_MSC_A(msc_a, LOGL_DEBUG, "Cipher Mode Complete: chosen encryption algorithm: A5/%u\n",
1729 msc_a->geran_encr.alg_id - 1);
Alexander Couzens2aaff752021-10-19 17:09:11 +02001730 }
1731
1732 if (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU) {
1733 int16_t utran_encryption;
1734
1735 /* utran: ensure chosen ciphering mode is allowed
1736 * If the IE is missing (utran_encryption == -1), parse it as no encryption */
1737 utran_encryption = msg->cipher_mode_complete.utran_encryption;
1738 if (utran_encryption == -1)
1739 utran_encryption = 0;
1740 if ((net->uea_encryption_mask & (1 << utran_encryption)) == 0) {
1741 /* cipher disallowed */
1742 LOG_MSC_A(msc_a, LOGL_ERROR, "Cipher Mode Complete: RNC chosen forbidden ciphering UEA%d\n",
1743 msg->cipher_mode_complete.utran_encryption);
1744 vlr_subscr_rx_ciph_res(vsub, VLR_CIPH_REJECT);
1745 rc = 0;
1746 break;
1747 }
1748 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001749 vlr_subscr_rx_ciph_res(vsub, VLR_CIPH_COMPL);
1750 rc = 0;
Neels Hofmeyre9a39112019-08-29 00:10:49 +02001751
1752 /* Evaluate enclosed L3 message, typically Identity Response (IMEISV) */
1753 if (msg->cipher_mode_complete.l3_msg) {
1754 unsigned char *data = (unsigned char*)(msg->cipher_mode_complete.l3_msg->val);
1755 uint16_t len = msg->cipher_mode_complete.l3_msg->len;
1756 struct msgb *dtap = msgb_alloc(len, "DTAP from Cipher Mode Complete");
1757 unsigned char *pos = msgb_put(dtap, len);
1758 memcpy(pos, data, len);
1759 dtap->l3h = pos;
1760 rc = msc_a_up_l3(msc_a, dtap);
1761 msgb_free(dtap);
1762 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001763 break;
1764
1765 case RAN_MSG_CIPHER_MODE_REJECT:
1766 vlr_subscr_rx_ciph_res(vsub, VLR_CIPH_REJECT);
1767 rc = 0;
1768 break;
1769
1770 case RAN_MSG_ASSIGNMENT_COMPLETE:
1771 msc_a_up_call_assignment_complete(msc_a, msg);
1772 rc = 0;
1773 break;
1774
1775 case RAN_MSG_ASSIGNMENT_FAILURE:
1776 msc_a_up_call_assignment_failure(msc_a, msg);
1777 rc = 0;
1778 break;
1779
1780 case RAN_MSG_SAPI_N_REJECT:
1781 msc_a_up_sapi_n_reject(msc_a, msg);
1782 rc = 0;
1783 break;
1784
1785 case RAN_MSG_HANDOVER_PERFORMED:
1786 /* The BSS lets us know that a handover happened within the BSS, which doesn't concern us. */
1787 LOG_MSC_A(msc_a, LOGL_ERROR, "'Handover Performed' handling not implemented\n");
1788 break;
1789
1790 case RAN_MSG_HANDOVER_REQUIRED:
1791 /* The BSS lets us know that it wants to handover to a different cell */
1792 rc = osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_HANDOVER_REQUIRED, (void*)&msg->handover_required);
1793 break;
1794
1795 case RAN_MSG_HANDOVER_FAILURE:
1796 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_FAILURE);
1797 break;
1798
Keith Whytea1a70be2021-05-16 02:59:52 +02001799 case RAN_MSG_LCLS_STATUS:
1800 /* The BSS sends us LCLS_STATUS. We do nothing for now, but it is not an error. */
1801 LOG_MSC_A(msc_a, LOGL_DEBUG, "LCLS_STATUS (%s) received from MSC-I\n",
1802 gsm0808_lcls_status_name(msg->lcls_status.status));
1803 rc = 0;
1804 break;
1805
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001806 default:
1807 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from MSC-I not implemented: %s\n", ran_msg_type_name(msg->msg_type));
1808 rc = -ENOTSUP;
1809 break;
1810 }
1811 return rc;
1812}
1813
Andreas Eversbergf7c6f142023-04-23 12:10:42 +02001814static int msc_a_rx_vgcs_bss_decoded(struct osmo_fsm_inst *caller_fi, void *caller_data, const struct ran_msg *msg)
1815{
1816 struct vgcs_bss *bss = caller_data;
1817 struct msc_a *msc_a = (bss->trans) ? bss->trans->msc_a : NULL;
1818 int rc = 0;
1819
1820 switch (msg->msg_type) {
1821 case RAN_MSG_VGCS_VBS_SETUP_ACK:
1822 /* The BSS accepts VGCS/VBS and sends us supported features. */
1823 vgcs_vbs_setup_ack(bss, msg);
1824 break;
1825 case RAN_MSG_VGCS_VBS_SETUP_REFUSE:
1826 /* The BSS refuses VGCS/VBS. */
1827 vgcs_vbs_setup_refuse(bss, msg);
1828 break;
1829 case RAN_MSG_UPLINK_REQUEST:
1830 /* A mobile station requests the uplink on a VGCS channel. */
1831 vgcs_uplink_request(bss, msg);
1832 break;
1833 case RAN_MSG_UPLINK_REQUEST_CNF:
1834 /* The uplink on a VGCS channel has been established. */
1835 vgcs_uplink_request_cnf(bss, msg);
1836 break;
1837 case RAN_MSG_UPLINK_APPLICATION_DATA:
1838 /* Application data received on the uplink of a VGCS channel. */
1839 vgcs_app_data(bss, msg);
1840 break;
1841 case RAN_MSG_DTAP:
1842 /* BSS confirms the release of the channel. */
1843 vgcs_bss_dtap(bss, msg);
1844 break;
1845 case RAN_MSG_UPLINK_RELEASE_IND:
1846 /* A mobile station releases the uplink on a VGCS channel. */
1847 vgcs_uplink_release_ind(bss, msg);
1848 break;
1849 case RAN_MSG_CLEAR_REQUEST:
1850 /* BSS indicated that the channel has been released. */
1851 vgcs_vbs_clear_req(bss, msg);
1852 break;
1853 case RAN_MSG_CLEAR_COMPLETE:
1854 /* BSS confirms the release of the channel. */
1855 vgcs_vbs_clear_cpl(bss, msg);
1856 break;
1857 default:
1858 LOG_MSC_A(msc_a, LOGL_ERROR, "VGCS message from BSS not implemented: %s\n",
1859 ran_msg_type_name(msg->msg_type));
1860 rc = -ENOTSUP;
1861 break;
1862 }
1863 return rc;
1864}
1865
1866int msc_a_rx_vgcs_bss(struct vgcs_bss *bss, struct ran_conn *from_conn, struct msgb *msg)
1867{
1868 struct ran_dec ran_dec;
1869
1870 /* Feed through the decoding mechanism ran_msg. The decoded message arrives in msc_a_rx_vgcs_decoded() */
1871 ran_dec = (struct ran_dec) {
1872 .caller_data = bss,
1873 .decode_cb = msc_a_rx_vgcs_bss_decoded,
1874 };
1875 struct ran_peer *ran_peer = from_conn->ran_peer;
1876 struct ran_infra *ran = ran_peer->sri->ran;
1877 if (!ran->ran_dec_l2) {
1878 LOGP(DMSC, LOGL_ERROR, "No ran_dec_l2() defined for RAN type %s\n",
1879 osmo_rat_type_name(ran->type));
1880 return -ENOTSUP;
1881 }
1882 return ran->ran_dec_l2(&ran_dec, msg);
1883}
1884
1885static int msc_a_rx_vgcs_cell_decoded(struct osmo_fsm_inst *caller_fi, void *caller_data, const struct ran_msg *msg)
1886{
1887 struct vgcs_bss_cell *cell = caller_data;
1888 struct msc_a *msc_a = (cell->bss && cell->bss->trans) ? cell->bss->trans->msc_a : NULL;
1889 int rc = 0;
1890
1891 switch (msg->msg_type) {
1892 case RAN_MSG_VGCS_VBS_ASSIGN_RES:
1893 /* The BSS accepts VGCS/VBS channel assignment. */
1894 vgcs_vbs_assign_result(cell, msg);
1895 break;
1896 case RAN_MSG_VGCS_VBS_ASSIGN_FAIL:
1897 /* The BSS refuses VGCS/VBS channel assignment. */
1898 vgcs_vbs_assign_fail(cell, msg);
1899 break;
1900 case RAN_MSG_VGCS_VBS_QUEUING_IND:
1901 /* The BSS needs more time for VGCS/VBS channel assignment. */
1902 vgcs_vbs_queuing_ind(cell);
1903 break;
1904 case RAN_MSG_VGCS_VBS_ASSIGN_STATUS:
1905 /* The BSS gives cell status about VGCS/VBS channel. */
1906 vgcs_vbs_assign_status(cell, msg);
1907 break;
1908 case RAN_MSG_CLEAR_REQUEST:
1909 /* BSS indicated that the channel has been released. */
1910 vgcs_vbs_clear_req_channel(cell, msg);
1911 break;
1912 case RAN_MSG_CLEAR_COMPLETE:
1913 /* BSS confirms the release of the channel. */
1914 vgcs_vbs_clear_cpl_channel(cell, msg);
1915 break;
1916 default:
1917 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from BSS leg not implemented: %s\n",
1918 ran_msg_type_name(msg->msg_type));
1919 rc = -ENOTSUP;
1920 break;
1921 }
1922 return rc;
1923}
1924
1925int msc_a_rx_vgcs_cell(struct vgcs_bss_cell *cell, struct ran_conn *from_conn, struct msgb *msg)
1926{
1927 struct ran_dec ran_dec;
1928
1929 /* Feed through the decoding mechanism ran_msg. The decoded message arrives in msc_a_rx_vgcs_decoded() */
1930 ran_dec = (struct ran_dec) {
1931 .caller_data = cell,
1932 .decode_cb = msc_a_rx_vgcs_cell_decoded,
1933 };
1934 struct ran_peer *ran_peer = from_conn->ran_peer;
1935 struct ran_infra *ran = ran_peer->sri->ran;
1936 if (!ran->ran_dec_l2) {
1937 LOGP(DMSC, LOGL_ERROR, "No ran_dec_l2() defined for RAN type %s\n",
1938 osmo_rat_type_name(ran->type));
1939 return -ENOTSUP;
1940 }
1941 return ran->ran_dec_l2(&ran_dec, msg);
1942}
1943
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001944static int msc_a_ran_dec_from_msc_t(struct msc_a *msc_a, struct msc_a_ran_dec_data *d)
1945{
1946 struct msc_t *msc_t = msc_a_msc_t(msc_a);
1947 int rc = -99;
1948
1949 if (!msc_t) {
1950 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx message from MSC-T role, but I have no active MSC-T role.\n");
1951 return -EINVAL;
1952 }
1953
1954 OSMO_ASSERT(d->ran_dec);
1955
1956 switch (d->ran_dec->msg_type) {
1957
1958 case RAN_MSG_CLEAR_REQUEST:
1959 rc = osmo_fsm_inst_dispatch(msc_t->c.fi, MSC_T_EV_MO_CLOSE, NULL);
1960 break;
1961
1962 case RAN_MSG_CLEAR_COMPLETE:
1963 rc = osmo_fsm_inst_dispatch(msc_t->c.fi, MSC_T_EV_CLEAR_COMPLETE, NULL);
1964 break;
1965
1966 case RAN_MSG_CLASSMARK_UPDATE:
1967 msc_a_up_classmark_update(msc_a, d->ran_dec->classmark_update.classmark, &msc_t->classmark);
1968 rc = 0;
1969 break;
1970
1971 case RAN_MSG_HANDOVER_REQUEST_ACK:
1972 /* new BSS accepts Handover */
1973 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_REQUEST_ACK);
1974 break;
1975
1976 case RAN_MSG_HANDOVER_DETECT:
1977 /* new BSS signals the MS is DETECTed on the new lchan */
1978 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_DETECT);
1979 break;
1980
1981 case RAN_MSG_HANDOVER_COMPLETE:
1982 /* new BSS signals the MS has fully moved to the new lchan */
1983 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_COMPLETE);
1984 break;
1985
1986 case RAN_MSG_HANDOVER_FAILURE:
1987 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_FAILURE);
1988 break;
1989
1990 default:
1991 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from MSC-T not implemented: %s\n",
1992 ran_msg_type_name(d->ran_dec->msg_type));
1993 rc = -ENOTSUP;
1994 break;
1995 }
1996 return rc;
1997}
1998
1999int msc_a_ran_decode_cb(struct osmo_fsm_inst *msc_a_fi, void *data, const struct ran_msg *msg)
2000{
2001 struct msc_a *msc_a = msc_a_fi_priv(msc_a_fi);
2002 struct msc_a_ran_dec_data *d = data;
2003 int rc = -99;
2004
2005 d->ran_dec = msg;
2006
2007 switch (d->from_role) {
2008 case MSC_ROLE_I:
2009 LOG_MSC_A(msc_a, LOGL_DEBUG, "RAN decode: %s\n", msg->msg_name ? : ran_msg_type_name(msg->msg_type));
2010 rc = msc_a_ran_dec_from_msc_i(msc_a, d);
2011 break;
2012
2013 case MSC_ROLE_T:
2014 LOG_MSC_A(msc_a, LOGL_DEBUG, "RAN decode from MSC-T: %s\n",
2015 msg->msg_name ? : ran_msg_type_name(msg->msg_type));
2016 rc = msc_a_ran_dec_from_msc_t(msc_a, d);
2017 break;
2018
2019 default:
2020 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from invalid role %s: %s\n", msc_role_name(d->from_role),
2021 ran_msg_type_name(msg->msg_type));
2022 return -ENOTSUP;
2023 }
2024
2025 if (rc)
2026 LOG_MSC_A(msc_a, LOGL_ERROR, "RAN decode error (rc=%d) for %s from %s\n", rc, ran_msg_type_name(msg->msg_type),
2027 msc_role_name(d->from_role));
2028 return rc;
2029}
2030
2031/* Your typical DTAP via FORWARD_ACCESS_SIGNALLING_REQUEST */
2032int _msc_a_ran_down(struct msc_a *msc_a, enum msc_role to_role, const struct ran_msg *ran_msg,
2033 const char *file, int line)
2034{
2035 return _msc_a_msg_down(msc_a, to_role, msub_role_to_role_event(msc_a->c.msub, MSC_ROLE_A, to_role),
2036 ran_msg, file, line);
2037}
2038
2039/* To transmit more complex events than just FORWARD_ACCESS_SIGNALLING_REQUEST, e.g. an
2040 * MSC_T_EV_FROM_A_PREPARE_HANDOVER_REQUEST */
2041int _msc_a_msg_down(struct msc_a *msc_a, enum msc_role to_role, uint32_t to_role_event,
2042 const struct ran_msg *ran_msg,
2043 const char *file, int line)
2044{
2045 struct an_apdu an_apdu = {
2046 .an_proto = msc_a->c.ran->an_proto,
2047 .msg = msc_role_ran_encode(msc_a->c.fi, ran_msg),
2048 };
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002049 if (!an_apdu.msg)
2050 return -EIO;
Vadim Yanitskiyc44342b2021-12-07 18:32:35 +03002051 return _msub_role_dispatch(msc_a->c.msub, to_role, to_role_event, &an_apdu, file, line);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002052}
2053
2054int msc_a_tx_dtap_to_i(struct msc_a *msc_a, struct msgb *dtap)
2055{
2056 struct ran_msg ran_msg;
Neels Hofmeyrc192c0b2019-10-07 21:41:18 +02002057 struct gsm48_hdr *gh = msgb_l3(dtap) ? : dtap->data;
2058 uint8_t pdisc = gsm48_hdr_pdisc(gh);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002059
Neels Hofmeyr2e8f8812019-08-21 16:56:41 +02002060 if (!msc_a) {
Neels Hofmeyr2e8f8812019-08-21 16:56:41 +02002061 LOGP(DMSC, LOGL_ERROR, "Attempt to send DTAP to NULL MSC-A, dropping message: %s %s\n",
2062 gsm48_pdisc_name(pdisc), gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
2063 msgb_free(dtap);
2064 return -EIO;
2065 }
2066
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002067 if (msc_a->c.ran->type == OSMO_RAT_EUTRAN_SGS) {
2068 /* The SGs connection to the MME always is at the MSC-A. */
2069 return sgs_iface_tx_dtap_ud(msc_a, dtap);
2070 }
2071
Neels Hofmeyrc192c0b2019-10-07 21:41:18 +02002072 LOG_MSC_A(msc_a, LOGL_DEBUG, "Sending DTAP: %s %s\n",
2073 gsm48_pdisc_name(pdisc), gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
2074
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002075 ran_msg = (struct ran_msg){
2076 .msg_type = RAN_MSG_DTAP,
2077 .dtap = dtap,
2078 };
2079 return msc_a_ran_down(msc_a, MSC_ROLE_I, &ran_msg);
2080}
2081
2082struct msc_a *msc_a_for_vsub(const struct vlr_subscr *vsub, bool valid_conn_only)
2083{
2084 struct msc_a *msc_a = msub_msc_a(msub_for_vsub(vsub));
2085 if (valid_conn_only && !msc_a_is_accepted(msc_a))
2086 return NULL;
2087 return msc_a;
2088}
2089
2090int msc_tx_common_id(struct msc_a *msc_a, enum msc_role to_role)
2091{
2092 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
Vadim Yanitskiy435f67f2021-06-06 15:47:49 +02002093 if (vsub == NULL)
2094 return -ENODEV;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002095 struct ran_msg msg = {
2096 .msg_type = RAN_MSG_COMMON_ID,
2097 .common_id = {
2098 .imsi = vsub->imsi,
Pau Espin Pedrol67106702021-04-27 18:20:15 +02002099 .last_eutran_plmn_present = vsub->sgs.last_eutran_plmn_present,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002100 },
2101 };
Pau Espin Pedrol67106702021-04-27 18:20:15 +02002102 if (vsub->sgs.last_eutran_plmn_present) {
2103 memcpy(&msg.common_id.last_eutran_plmn, &vsub->sgs.last_eutran_plmn,
2104 sizeof(vsub->sgs.last_eutran_plmn));
2105 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002106
2107 return msc_a_ran_down(msc_a, to_role, &msg);
2108}
2109
2110static int msc_a_start_assignment(struct msc_a *msc_a, struct gsm_trans *cc_trans)
2111{
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01002112 struct call_leg *cl;
2113 bool cn_rtp_available;
2114 bool ran_rtp_available;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002115
2116 OSMO_ASSERT(!msc_a->cc.active_trans);
2117 msc_a->cc.active_trans = cc_trans;
2118
Neels Hofmeyr62bfa372022-10-31 18:51:07 +01002119 cc_trans->cc.codecs.assignment = (struct sdp_audio_codec){};
2120
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002121 OSMO_ASSERT(cc_trans && cc_trans->type == TRANS_CC);
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01002122 cl = msc_a_ensure_call_leg(msc_a, cc_trans);
2123 if (!cl)
2124 return -EINVAL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002125
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01002126 /* See if we can set a preliminary codec. If not, pass none for the time being. */
Oliver Smithceca8e62023-05-24 11:15:52 +02002127 trans_cc_filter_run(cc_trans);
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01002128
2129 cn_rtp_available = call_leg_local_ip(cl, RTP_TO_CN);
2130 ran_rtp_available = call_leg_local_ip(cl, RTP_TO_RAN);
2131
2132 /* Set up RTP ports for both RAN and CN side. Even though we ask for both at the same time, the
2133 * osmo_mgcpc_ep_fsm automagically waits for the first CRCX to complete before firing the second CRCX. The one
2134 * issued first here will also be the first CRCX sent to the MGW. Usually both still need to be set up. */
2135 if (!cn_rtp_available)
Andreas Eversberg712b28e2023-06-21 11:17:26 +02002136 call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->call_id, cc_trans,
Oliver Smithc63c3a02023-05-24 10:48:07 +02002137 &cc_trans->cc.local.audio_codecs, NULL);
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01002138 if (!ran_rtp_available) {
2139 struct sdp_audio_codecs *codecs;
2140 if (msc_a->c.ran->force_mgw_codecs_to_ran.count)
2141 codecs = &msc_a->c.ran->force_mgw_codecs_to_ran;
2142 else
Oliver Smithc63c3a02023-05-24 10:48:07 +02002143 codecs = &cc_trans->cc.local.audio_codecs;
Andreas Eversberg712b28e2023-06-21 11:17:26 +02002144 return call_leg_ensure_ci(cl, RTP_TO_RAN, cc_trans->call_id, cc_trans, codecs, NULL);
Neels Hofmeyrbd5f8e92022-01-13 23:18:02 +01002145 }
2146
2147 /* Should these already be set up, immediately continue by retriggering the events signalling that the RTP
2148 * ports are available. The ordering is: first CN, then RAN. */
2149 if (cn_rtp_available && ran_rtp_available)
2150 return osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE, cl->rtp[RTP_TO_RAN]);
2151 else if (cn_rtp_available)
2152 return osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE, cl->rtp[RTP_TO_CN]);
2153 /* Otherwise wait for MGCP response and continue from there. */
2154 return 0;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002155}
2156
2157int msc_a_try_call_assignment(struct gsm_trans *cc_trans)
2158{
2159 struct msc_a *msc_a = cc_trans->msc_a;
2160 OSMO_ASSERT(cc_trans->type == TRANS_CC);
2161
2162 if (msc_a->cc.active_trans == cc_trans) {
Neels Hofmeyrb4ef5e72019-08-30 01:11:12 +02002163 LOG_MSC_A(msc_a, LOGL_DEBUG, "Assignment for this trans already started earlier\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002164 return 0;
2165 }
2166
2167 if (msc_a->cc.active_trans) {
2168 LOG_MSC_A(msc_a, LOGL_INFO, "Another call is already ongoing, not assigning yet\n");
2169 return 0;
2170 }
2171
2172 LOG_MSC_A(msc_a, LOGL_DEBUG, "Starting call assignment\n");
2173 return msc_a_start_assignment(msc_a, cc_trans);
2174}
2175
Neels Hofmeyr5d53c602022-04-24 23:37:07 +02002176/* Map CM Service type to use token.
2177 * Given a CM Service type, return a matching token intended for osmo_use_count.
2178 * For unknown service type, return NULL.
2179 */
Andreas Eversbergcd8bd452023-07-11 14:16:24 +02002180const char *msc_a_cm_service_type_to_use(struct msc_a *msc_a, enum osmo_cm_service_type cm_service_type)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002181{
Andreas Eversbergcd8bd452023-07-11 14:16:24 +02002182 struct gsm_network *net = msc_a_net(msc_a);
2183
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002184 switch (cm_service_type) {
2185 case GSM48_CMSERV_MO_CALL_PACKET:
2186 case GSM48_CMSERV_EMERGENCY:
2187 return MSC_A_USE_CM_SERVICE_CC;
2188
2189 case GSM48_CMSERV_SMS:
2190 return MSC_A_USE_CM_SERVICE_SMS;
2191
2192 case GSM48_CMSERV_SUP_SERV:
2193 return MSC_A_USE_CM_SERVICE_SS;
2194
Andreas Eversberg456c6f72023-04-23 11:54:16 +02002195 case GSM48_CMSERV_VGCS:
Andreas Eversbergcd8bd452023-07-11 14:16:24 +02002196 if (net->asci.enable)
2197 return MSC_A_USE_CM_SERVICE_GCC;
2198 else
2199 return NULL;
Andreas Eversberg456c6f72023-04-23 11:54:16 +02002200
2201 case GSM48_CMSERV_VBS:
Andreas Eversbergcd8bd452023-07-11 14:16:24 +02002202 if (net->asci.enable)
2203 return MSC_A_USE_CM_SERVICE_BCC;
2204 else
2205 return NULL;
Andreas Eversberg456c6f72023-04-23 11:54:16 +02002206
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002207 default:
2208 return NULL;
2209 }
2210}
2211
2212void msc_a_release_cn(struct msc_a *msc_a)
2213{
2214 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_CN_CLOSE, NULL);
2215}
2216
2217void msc_a_release_mo(struct msc_a *msc_a, enum gsm48_gsm_cause gsm_cause)
2218{
2219 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_MO_CLOSE, NULL);
2220}