blob: 28ecfc244e97884649baea7d163d8f7f0e14df64 [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001/* Code to manage a subscriber's MSC-A role */
2/*
3 * (C) 2019 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de>
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
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>
39#include <osmocom/msc/ran_peer.h>
40#include <osmocom/msc/ran_msg_a.h>
41#include <osmocom/msc/ran_msg_iu.h>
42#include <osmocom/msc/sgs_iface.h>
43#include <osmocom/msc/gsm_04_08.h>
44#include <osmocom/msc/gsm_09_11.h>
45#include <osmocom/msc/gsm_04_14.h>
46#include <osmocom/msc/call_leg.h>
47#include <osmocom/msc/rtp_stream.h>
48#include <osmocom/msc/msc_ho.h>
Neels Hofmeyr7c6c9ae2022-01-13 21:38:35 +010049#include <osmocom/msc/codec_sdp_cc_t9n.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010050
51#define MSC_A_USE_WAIT_CLEAR_COMPLETE "wait-Clear-Complete"
52
53static struct osmo_fsm msc_a_fsm;
54
55static const struct osmo_tdef_state_timeout msc_a_fsm_timeouts[32] = {
56 [MSC_A_ST_VALIDATE_L3] = { .T = -1 },
57 [MSC_A_ST_AUTH_CIPH] = { .keep_timer = true },
58 [MSC_A_ST_WAIT_CLASSMARK_UPDATE] = { .keep_timer = true },
59 [MSC_A_ST_AUTHENTICATED] = { .keep_timer = true },
60 [MSC_A_ST_RELEASING] = { .T = -2 },
61 [MSC_A_ST_RELEASED] = { .T = -2 },
62};
63
64/* Transition to a state, using the T timer defined in msc_a_fsm_timeouts.
65 * The actual timeout value is in turn obtained from network->T_defs.
66 * Assumes local variable fi exists. */
Neels Hofmeyr01653252019-09-03 02:06:22 +020067#define msc_a_state_chg_always(msc_a, state) \
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010068 osmo_tdef_fsm_inst_state_chg((msc_a)->c.fi, state, msc_a_fsm_timeouts, (msc_a)->c.ran->tdefs, 5)
69
Neels Hofmeyr01653252019-09-03 02:06:22 +020070/* Same as msc_a_state_chg_always() but ignore if the msc_a already is in the target state. */
71#define msc_a_state_chg(msc_a, STATE) do { \
72 if ((msc_a)->c.fi->state != STATE) \
73 msc_a_state_chg_always(msc_a, STATE); \
74 } while(0)
75
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010076struct gsm_network *msc_a_net(const struct msc_a *msc_a)
77{
78 return msub_net(msc_a->c.msub);
79}
80
81struct vlr_subscr *msc_a_vsub(const struct msc_a *msc_a)
82{
Neels Hofmeyr911e5972019-05-09 13:28:26 +020083 if (!msc_a)
84 return NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010085 return msub_vsub(msc_a->c.msub);
86}
87
88struct msc_i *msc_a_msc_i(const struct msc_a *msc_a)
89{
Neels Hofmeyr911e5972019-05-09 13:28:26 +020090 if (!msc_a)
91 return NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010092 return msub_msc_i(msc_a->c.msub);
93}
94
95struct msc_t *msc_a_msc_t(const struct msc_a *msc_a)
96{
Neels Hofmeyr911e5972019-05-09 13:28:26 +020097 if (!msc_a)
98 return NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010099 return msub_msc_t(msc_a->c.msub);
100}
101
102struct msc_a *msc_a_fi_priv(struct osmo_fsm_inst *fi)
103{
104 OSMO_ASSERT(fi);
105 OSMO_ASSERT(fi->fsm == &msc_a_fsm);
106 OSMO_ASSERT(fi->priv);
107 return fi->priv;
108}
109
Neels Hofmeyr0d2aab72022-10-10 23:34:48 +0200110bool msc_a_try_ciphering(const struct msc_a *msc_a)
Alexander Couzens2c5e4612021-11-05 02:00:17 +0100111{
112 struct gsm_network *net = msc_a_net(msc_a);
113 bool is_utran = (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU);
114 if (is_utran)
115 return net->uea_encryption_mask > (1 << OSMO_UTRAN_UEA0);
116 else
117 return net->a5_encryption_mask > 0x1;
118}
119
Neels Hofmeyr7bb31ca2022-10-10 23:35:47 +0200120bool msc_a_require_ciphering(const struct msc_a *msc_a)
121{
122 struct gsm_network *net = msc_a_net(msc_a);
123 bool is_utran = (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU);
124 if (is_utran)
125 return net->uea_encryption_mask
126 && ((net->uea_encryption_mask & (1 << OSMO_UTRAN_UEA0)) == 0);
127 else
128 return net->a5_encryption_mask
129 && ((net->a5_encryption_mask & 0x1) == 0);
130}
131
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100132static void update_counters(struct osmo_fsm_inst *fi, bool conn_accepted)
133{
134 struct msc_a *msc_a = fi->priv;
135 struct gsm_network *net = msc_a_net(msc_a);
136 switch (msc_a->complete_layer3_type) {
137 case COMPLETE_LAYER3_LU:
Pau Espin Pedrol2e21a682021-06-04 16:45:44 +0200138 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 +0100139 break;
140 case COMPLETE_LAYER3_CM_SERVICE_REQ:
Pau Espin Pedrol2e21a682021-06-04 16:45:44 +0200141 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 +0100142 break;
143 case COMPLETE_LAYER3_PAGING_RESP:
Pau Espin Pedrol2e21a682021-06-04 16:45:44 +0200144 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 +0100145 break;
Neels Hofmeyrae98b972021-07-27 03:46:49 +0200146 case COMPLETE_LAYER3_CM_RE_ESTABLISH_REQ:
147 rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs,
148 conn_accepted ? MSC_CTR_CM_RE_ESTABLISH_REQ_ACCEPTED
149 : MSC_CTR_CM_RE_ESTABLISH_REQ_REJECTED));
150 break;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100151 default:
152 break;
153 }
154}
155
156static void evaluate_acceptance_outcome(struct osmo_fsm_inst *fi, bool conn_accepted)
157{
158 struct msc_a *msc_a = fi->priv;
159 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
160
161 update_counters(fi, conn_accepted);
162
Neels Hofmeyr83cf10c2020-06-24 14:23:26 +0200163 if (conn_accepted) {
164 /* Record the Cell ID seen in Complete Layer 3 Information in the VLR, so that it also shows in vty
165 * 'show' output. */
166 vsub->cgi = msc_a->via_cell;
167 }
168
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100169 /* Trigger transactions that we paged for */
170 if (msc_a->complete_layer3_type == COMPLETE_LAYER3_PAGING_RESP) {
171 if (conn_accepted)
172 paging_response(msc_a);
173 else
174 paging_expired(vsub);
175 }
176
177 if (conn_accepted)
178 osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_ATTACHED, msc_a_vsub(msc_a));
179
180 if (msc_a->complete_layer3_type == COMPLETE_LAYER3_LU)
181 msc_a_put(msc_a, MSC_A_USE_LOCATION_UPDATING);
Neels Hofmeyrae98b972021-07-27 03:46:49 +0200182
183 if (msc_a->complete_layer3_type == COMPLETE_LAYER3_CM_RE_ESTABLISH_REQ) {
184 /* Trigger new Assignment to recommence the voice call. A little dance here because normally we verify
185 * that no CC trans is already active. */
186 struct gsm_trans *cc_trans = msc_a->cc.active_trans;
187 msc_a->cc.active_trans = NULL;
188 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, cc_trans);
189 msc_a_try_call_assignment(cc_trans);
190 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100191}
192
193bool msc_a_is_accepted(const struct msc_a *msc_a)
194{
195 if (!msc_a || !msc_a->c.fi)
196 return false;
197 return msc_a->c.fi->state == MSC_A_ST_AUTHENTICATED
198 || msc_a->c.fi->state == MSC_A_ST_COMMUNICATING;
199}
200
201bool msc_a_in_release(struct msc_a *msc_a)
202{
203 if (!msc_a)
204 return true;
205 if (msc_a->c.fi->state == MSC_A_ST_RELEASING)
206 return true;
207 if (msc_a->c.fi->state == MSC_A_ST_RELEASED)
208 return true;
209 return false;
210}
211
212static int msc_a_ran_dec(struct msc_a *msc_a, const struct an_apdu *an_apdu, enum msc_role from_role)
213{
214 int rc;
215 struct msc_a_ran_dec_data d = {
216 .from_role = from_role,
217 .an_apdu = an_apdu,
218 };
219 msc_a_get(msc_a, __func__);
220 rc = msc_role_ran_decode(msc_a->c.fi, an_apdu, msc_a_ran_decode_cb, &d);
221 msc_a_put(msc_a, __func__);
222 return rc;
223};
224
225static void msc_a_fsm_validate_l3(struct osmo_fsm_inst *fi, uint32_t event, void *data)
226{
227 struct msc_a *msc_a = fi->priv;
228 const struct an_apdu *an_apdu;
229
230 switch (event) {
231 case MSC_A_EV_FROM_I_COMPLETE_LAYER_3:
232 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
233 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
234 an_apdu = data;
235 msc_a_ran_dec(msc_a, an_apdu, MSC_ROLE_I);
236 return;
237
238 case MSC_A_EV_COMPLETE_LAYER_3_OK:
239 msc_a_state_chg(msc_a, MSC_A_ST_AUTH_CIPH);
240 return;
241
242 case MSC_A_EV_MO_CLOSE:
243 case MSC_A_EV_CN_CLOSE:
244 evaluate_acceptance_outcome(fi, false);
245 /* fall through */
246 case MSC_A_EV_UNUSED:
247 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
248 return;
249
250 default:
251 OSMO_ASSERT(false);
252 }
253}
254
255/* Figure out whether to first send a Classmark Request to the MS to figure out algorithm support. */
256static bool msc_a_need_classmark_for_ciphering(struct msc_a *msc_a)
257{
258 struct gsm_network *net = msc_a_net(msc_a);
259 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
260 int i = 0;
261 bool request_classmark = false;
262
263 /* Only on GERAN-A do we ever need Classmark Information for Ciphering. */
264 if (msc_a->c.ran->type != OSMO_RAT_GERAN_A)
265 return false;
266
267 for (i = 0; i < 8; i++) {
268 int supported;
269
270 /* A5/n permitted by osmo-msc.cfg? */
271 if (!(net->a5_encryption_mask & (1 << i)))
272 continue;
273
274 /* A5/n supported by MS? */
275 supported = osmo_gsm48_classmark_supports_a5(&vsub->classmark, i);
276 if (supported < 0) {
277 LOG_MSC_A(msc_a, LOGL_DEBUG, "For A5/%d, we still need Classmark %d\n", i, -supported);
278 request_classmark = true;
279 }
280 }
281
282 return request_classmark;
283}
284
285static int msc_a_ran_enc_ciphering(struct msc_a *msc_a, bool umts_aka, bool retrieve_imeisv);
286
287/* VLR callback for ops.set_ciph_mode() */
288int msc_a_vlr_set_cipher_mode(void *_msc_a, bool umts_aka, bool retrieve_imeisv)
289{
290 struct msc_a *msc_a = _msc_a;
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700291 struct vlr_subscr *vsub;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100292
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700293 if (!msc_a) {
294 LOGP(DMSC, LOGL_ERROR, "Insufficient info to start ciphering: "
295 "MSC-A role is NULL?!?\n");
296 return -EINVAL;
297 }
298
299 vsub = msc_a_vsub(msc_a);
300 if (!vsub || !vsub->last_tuple) {
301 LOG_MSC_A(msc_a, LOGL_ERROR, "Insufficient info to start ciphering: "
302 "vlr_subscr is NULL?!?\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100303 return -EINVAL;
304 }
305
306 if (msc_a_need_classmark_for_ciphering(msc_a)) {
307 int rc;
308 struct ran_msg msg = {
309 .msg_type = RAN_MSG_CLASSMARK_REQUEST,
310 };
311 rc = msc_a_ran_down(msc_a, MSC_ROLE_I, &msg);
312 if (rc) {
313 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot send Classmark Request\n");
314 return -EIO;
315 }
316
317 msc_a->state_before_classmark_update = msc_a->c.fi->state;
318 msc_a->action_on_classmark_update = (struct msc_a_action_on_classmark_update){
319 .type = MSC_A_CLASSMARK_UPDATE_THEN_CIPHERING,
320 .ciphering = {
321 .umts_aka = umts_aka,
322 .retrieve_imeisv = retrieve_imeisv,
323 },
324 };
325 msc_a_state_chg(msc_a, MSC_A_ST_WAIT_CLASSMARK_UPDATE);
326 return 0;
327 }
328
329 return msc_a_ran_enc_ciphering(msc_a, umts_aka, retrieve_imeisv);
330}
331
Neels Hofmeyr6ce2edc2021-06-09 22:26:11 +0200332static uint8_t filter_a5(uint8_t a5_mask, bool umts_aka)
333{
334 /* With GSM AKA: allow A5/0, 1, 3 = 0b00001011 = 0xb.
335 * UMTS aka: allow A5/0, 1, 3, 4 = 0b00011011 = 0x1b.
336 */
337 return a5_mask & (umts_aka ? 0x1b : 0x0b);
338}
339
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100340static int msc_a_ran_enc_ciphering(struct msc_a *msc_a, bool umts_aka, bool retrieve_imeisv)
341{
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700342 struct gsm_network *net;
343 struct vlr_subscr *vsub;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100344 struct ran_msg msg;
345
Vadim Yanitskiy4dd477f2019-05-11 03:00:30 +0700346 if (!msc_a) {
347 LOGP(DMSC, LOGL_ERROR, "Insufficient info to start ciphering: "
348 "MSC-A role is NULL?!?\n");
349 return -EINVAL;
350 }
351
352 net = msc_a_net(msc_a);
353 vsub = msc_a_vsub(msc_a);
354
355 if (!net || !vsub || !vsub->last_tuple) {
356 LOG_MSC_A(msc_a, LOGL_ERROR, "Insufficient info to start ciphering: "
357 "gsm_network and/or vlr_subscr is NULL?!?\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100358 return -EINVAL;
359 }
360
361 msg = (struct ran_msg){
362 .msg_type = RAN_MSG_CIPHER_MODE_COMMAND,
363 .cipher_mode_command = {
364 .vec = vsub->last_tuple ? &vsub->last_tuple->vec : NULL,
365 .classmark = &vsub->classmark,
366 .geran = {
367 .umts_aka = umts_aka,
368 .retrieve_imeisv = retrieve_imeisv,
Neels Hofmeyr6ce2edc2021-06-09 22:26:11 +0200369 .a5_encryption_mask = filter_a5(net->a5_encryption_mask, umts_aka),
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100370
371 /* for ran_a.c to store the GERAN key that is actually used */
372 .chosen_key = &msc_a->geran_encr,
373 },
Harald Welte274b70f2021-02-06 16:47:39 +0100374 .utran = {
Harald Welte505a94a2021-02-06 17:12:20 +0100375 .uea_encryption_mask = net->uea_encryption_mask,
376 },
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100377 },
378 };
379
380 if (msc_a_ran_down(msc_a, MSC_ROLE_I, &msg)) {
381 LOG_MSC_A(msc_a, LOGL_ERROR, "Sending Cipher Mode Command failed\n");
382 /* Returning error to the VLR ops.set_ciph_mode() will cancel the attach. Other callers need to take
383 * care of the return value. */
384 return -EINVAL;
385 }
386
387 if (msc_a->geran_encr.key_len)
Neels Hofmeyr73d093a2021-06-23 23:54:43 +0200388 LOG_MSC_A(msc_a, LOGL_DEBUG, "RAN encoding chose ciphering: A5/%d kc %s kc128 %s\n",
389 msc_a->geran_encr.alg_id - 1,
390 osmo_hexdump_nospc_c(OTC_SELECT, msc_a->geran_encr.key, msc_a->geran_encr.key_len),
391 msc_a->geran_encr.kc128_present ?
392 osmo_hexdump_nospc_c(OTC_SELECT, msc_a->geran_encr.kc128, sizeof(msc_a->geran_encr.kc128))
393 : "-");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100394 return 0;
395}
396
397static void msc_a_fsm_auth_ciph(struct osmo_fsm_inst *fi, uint32_t event, void *data)
398{
399 struct msc_a *msc_a = fi->priv;
400
401 /* If accepted, transition the state, all other cases mean failure. */
402 switch (event) {
403 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
404 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
405 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
406 return;
407
408 case MSC_A_EV_AUTHENTICATED:
409 msc_a_state_chg(msc_a, MSC_A_ST_AUTHENTICATED);
410 return;
411
412 case MSC_A_EV_UNUSED:
413 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
414 return;
415
416 case MSC_A_EV_MO_CLOSE:
417 case MSC_A_EV_CN_CLOSE:
418 evaluate_acceptance_outcome(fi, false);
419 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
420 return;
421
422
423 default:
424 OSMO_ASSERT(false);
425 }
426}
427
428static void msc_a_fsm_wait_classmark_update(struct osmo_fsm_inst *fi, uint32_t event, void *data)
429{
430 struct msc_a *msc_a = fi->priv;
431
432 switch (event) {
433 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
434 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
435 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
436 return;
437
438 case MSC_A_EV_CLASSMARK_UPDATE:
439 switch (msc_a->action_on_classmark_update.type) {
440 case MSC_A_CLASSMARK_UPDATE_THEN_CIPHERING:
441 msc_a_state_chg(msc_a, MSC_A_ST_AUTH_CIPH);
442 if (msc_a_ran_enc_ciphering(msc_a,
443 msc_a->action_on_classmark_update.ciphering.umts_aka,
444 msc_a->action_on_classmark_update.ciphering.retrieve_imeisv)) {
445 LOG_MSC_A(msc_a, LOGL_ERROR,
446 "After Classmark Update, still failed to send Cipher Mode Command\n");
447 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
448 }
449 return;
450
451 default:
452 LOG_MSC_A(msc_a, LOGL_ERROR, "Internal error: After Classmark Update, don't know what to do\n");
453 msc_a_state_chg(msc_a, msc_a->state_before_classmark_update);
454 return;
455 }
456
457 case MSC_A_EV_UNUSED:
458 /* Seems something detached / aborted in the middle of auth+ciph. */
459 evaluate_acceptance_outcome(fi, false);
460 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
461 return;
462
463 case MSC_A_EV_MO_CLOSE:
464 case MSC_A_EV_CN_CLOSE:
465 evaluate_acceptance_outcome(fi, false);
466 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
467 return;
468
469 default:
470 OSMO_ASSERT(false);
471 }
472}
473
474static bool msc_a_fsm_has_active_transactions(struct osmo_fsm_inst *fi)
475{
476 struct msc_a *msc_a = fi->priv;
477 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
478 struct gsm_trans *trans;
479
480 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_SILENT_CALL)) {
481 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: silent call still active\n", __func__);
482 return true;
483 }
484
485 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_CC)) {
486 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO CC request after a CM Service Request\n",
487 __func__);
488 return true;
489 }
490 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_SMS)) {
491 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO SMS after a CM Service Request\n",
492 __func__);
493 return true;
494 }
495 if (osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_SS)) {
496 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still awaiting MO SS after a CM Service Request\n",
497 __func__);
498 return true;
499 }
500
501 if (vsub && !llist_empty(&vsub->cs.requests)) {
502 struct paging_request *pr;
503 llist_for_each_entry(pr, &vsub->cs.requests, entry) {
504 LOG_MSC_A(msc_a, LOGL_DEBUG, "%s: still active: %s\n", __func__, pr->label);
505 }
506 return true;
507 }
508
509 if ((trans = trans_has_conn(msc_a))) {
510 LOG_MSC_A(msc_a, LOGL_DEBUG, "connection still has active transaction: %s\n",
511 trans_type_name(trans->type));
512 return true;
513 }
514
515 return false;
516}
517
518static void msc_a_fsm_authenticated_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
519{
520 struct msc_a *msc_a = fi->priv;
521 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
522
523 /* Stop Location Update expiry for this subscriber. While the subscriber
524 * has an open connection the LU expiry timer must remain disabled.
525 * Otherwise we would kick the subscriber off the network when the timer
526 * expires e.g. during a long phone call.
527 * The LU expiry timer will restart once the connection is closed. */
528 if (vsub)
529 vsub->expire_lu = VLR_SUBSCRIBER_NO_EXPIRATION;
530
531 evaluate_acceptance_outcome(fi, true);
532}
533
534static void msc_a_fsm_authenticated(struct osmo_fsm_inst *fi, uint32_t event, void *data)
535{
536 struct msc_a *msc_a = fi->priv;
537
538 switch (event) {
539 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
540 case MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST:
541 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
542 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
543 return;
544
545 case MSC_A_EV_COMPLETE_LAYER_3_OK:
546 /* When Authentication is off, we may already be in the Accepted state when the code
547 * evaluates the Compl L3. Simply ignore. This just cosmetically mutes the error log
548 * about the useless event. */
549 return;
550
551 case MSC_A_EV_TRANSACTION_ACCEPTED:
552 msc_a_state_chg(msc_a, MSC_A_ST_COMMUNICATING);
553 return;
554
555 case MSC_A_EV_MO_CLOSE:
556 case MSC_A_EV_CN_CLOSE:
557 case MSC_A_EV_UNUSED:
558 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
559 return;
560
561 default:
562 OSMO_ASSERT(false);
563 }
564}
565
566/* The MGW has given us a local IP address for the RAN side. Ready to start the Assignment of a voice channel. */
567static void msc_a_call_leg_ran_local_addr_available(struct msc_a *msc_a)
568{
569 struct ran_msg msg;
570 struct gsm_trans *cc_trans = msc_a->cc.active_trans;
571 struct gsm0808_channel_type channel_type;
572
Neels Hofmeyr00a476b2019-11-28 02:46:05 +0100573 if (!cc_trans) {
574 LOG_MSC_A(msc_a, LOGL_ERROR, "No CC transaction active\n");
575 call_leg_release(msc_a->cc.call_leg);
576 return;
577 }
578
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100579 /* Once a CI is known, we could also CRCX the CN side of the MGW endpoint, but it makes sense to wait for the
580 * codec to be determined by the Assignment Complete message, first. */
581
582 if (mncc_bearer_cap_to_channel_type(&channel_type, &cc_trans->bearer_cap)) {
583 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose Channel Type from bearer capabilities\n");
Neels Hofmeyrf439ff12019-10-05 04:19:36 +0200584 trans_free(cc_trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100585 return;
586 }
587
588 /* The RAN side RTP address is known, so the voice Assignment can commence. */
589 msg = (struct ran_msg){
590 .msg_type = RAN_MSG_ASSIGNMENT_COMMAND,
591 .assignment_command = {
592 .cn_rtp = &msc_a->cc.call_leg->rtp[RTP_TO_RAN]->local,
593 .channel_type = &channel_type,
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +0200594 .osmux_present = msc_a->cc.call_leg->rtp[RTP_TO_RAN]->use_osmux,
595 .osmux_cid = msc_a->cc.call_leg->rtp[RTP_TO_RAN]->local_osmux_cid,
Philipp Maierf34d9452020-06-05 15:49:35 +0200596 .call_id_present = true,
597 .call_id = cc_trans->callref,
Keith Whytea1a70be2021-05-16 02:59:52 +0200598 .lcls = cc_trans->cc.lcls,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100599 },
600 };
601 if (msc_a_ran_down(msc_a, MSC_ROLE_I, &msg)) {
602 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot send Assignment\n");
Neels Hofmeyrf439ff12019-10-05 04:19:36 +0200603 trans_free(cc_trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100604 return;
605 }
606}
607
608static void msc_a_call_leg_cn_local_addr_available(struct msc_a *msc_a, struct gsm_trans *cc_trans)
609{
610 if (gsm48_tch_rtp_create(cc_trans)) {
611 LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot inform MNCC of RTP address\n");
Neels Hofmeyrf439ff12019-10-05 04:19:36 +0200612 trans_free(cc_trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100613 return;
614 }
615}
616
617static struct gsm_trans *find_waiting_call(struct msc_a *msc_a)
618{
619 struct gsm_trans *trans;
620 struct gsm_network *net = msc_a_net(msc_a);
621
622 llist_for_each_entry(trans, &net->trans_list, entry) {
623 if (trans->msc_a != msc_a)
624 continue;
625 if (trans->type != TRANS_CC)
626 continue;
627 if (trans->msc_a->cc.active_trans == trans)
628 continue;
629 return trans;
630 }
631 return NULL;
632}
633
634static void msc_a_cleanup_rtp_streams(struct msc_a *msc_a, uint32_t event, void *data)
635{
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100636 switch (event) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100637
638 case MSC_EV_CALL_LEG_TERM:
639 msc_a->cc.call_leg = NULL;
640 if (msc_a->cc.mncc_forwarding_to_remote_ran)
641 msc_a->cc.mncc_forwarding_to_remote_ran->rtps = NULL;
642
Neels Hofmeyr265a4c72019-05-09 16:20:51 +0200643 if (msc_a->ho.new_cell.mncc_forwarding_to_remote_ran)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100644 msc_a->ho.new_cell.mncc_forwarding_to_remote_ran->rtps = NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100645 return;
646
647 case MSC_MNCC_EV_CALL_ENDED:
648 msc_a->cc.mncc_forwarding_to_remote_ran = NULL;
649 return;
650
651 default:
652 return;
653 }
654}
655
656static void msc_a_fsm_communicating(struct osmo_fsm_inst *fi, uint32_t event, void *data)
657{
658 struct msc_a *msc_a = fi->priv;
659 struct rtp_stream *rtps;
660 struct gsm_trans *waiting_trans;
661 struct an_apdu *an_apdu;
662
663 msc_a_cleanup_rtp_streams(msc_a, event, data);
664
665 switch (event) {
666 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
667 case MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST:
668 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
669 an_apdu = data;
670 msc_a_ran_dec(msc_a, an_apdu, MSC_ROLE_I);
671 return;
672
673 case MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE:
674 case MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE:
675 case MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST:
676 case MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST:
677 an_apdu = data;
678 msc_a_ran_dec(msc_a, an_apdu, MSC_ROLE_T);
679 return;
680
681 case MSC_A_EV_TRANSACTION_ACCEPTED:
682 /* no-op */
683 return;
684
685 case MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE:
686 rtps = data;
687 if (!rtps) {
688 LOG_MSC_A(msc_a, LOGL_ERROR, "Invalid data for %s\n", osmo_fsm_event_name(fi->fsm, event));
689 return;
690 }
Neels Hofmeyr00a476b2019-11-28 02:46:05 +0100691 if (!msc_a->cc.call_leg) {
692 LOG_MSC_A(msc_a, LOGL_ERROR, "No call leg active\n");
693 return;
694 }
Neels Hofmeyrcc918cb2019-11-28 02:16:34 +0100695 if (!osmo_sockaddr_str_is_nonzero(&rtps->local)) {
696 LOG_MSC_A(msc_a, LOGL_ERROR, "Invalid RTP address received from MGW: " OSMO_SOCKADDR_STR_FMT "\n",
697 OSMO_SOCKADDR_STR_FMT_ARGS(&rtps->local));
698 call_leg_release(msc_a->cc.call_leg);
699 return;
700 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100701 LOG_MSC_A(msc_a, LOGL_DEBUG,
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +0200702 "MGW endpoint's RTP address available for the CI %s: " OSMO_SOCKADDR_STR_FMT " (osmux=%s:%d)\n",
703 rtp_direction_name(rtps->dir), OSMO_SOCKADDR_STR_FMT_ARGS(&rtps->local),
704 rtps->use_osmux ? "yes" : "no", rtps->local_osmux_cid);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100705 switch (rtps->dir) {
706 case RTP_TO_RAN:
707 msc_a_call_leg_ran_local_addr_available(msc_a);
708 return;
709 case RTP_TO_CN:
710 msc_a_call_leg_cn_local_addr_available(msc_a, rtps->for_trans);
711 return;
712 default:
713 LOG_MSC_A(msc_a, LOGL_ERROR, "Invalid data for %s\n", osmo_fsm_event_name(fi->fsm, event));
714 return;
715 }
716
717 case MSC_EV_CALL_LEG_RTP_COMPLETE:
718 /* Nothing to do. */
719 return;
720
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100721 case MSC_MNCC_EV_CALL_ENDED:
722 /* Cleaned up above */
723 return;
724
725 case MSC_EV_CALL_LEG_TERM:
726 /* RTP streams cleaned up above */
727
728 msc_a_get(msc_a, __func__);
729 if (msc_a->cc.active_trans)
730 trans_free(msc_a->cc.active_trans);
731
732 /* If there is another call still waiting to be activated, this is the time when the mgcp_ctx is
733 * available again and the other call can start assigning. */
734 waiting_trans = find_waiting_call(msc_a);
735 if (waiting_trans) {
736 LOG_MSC_A(msc_a, LOGL_DEBUG, "(ti %02x) Call waiting: starting Assignment\n",
737 waiting_trans->transaction_id);
738 msc_a_try_call_assignment(waiting_trans);
739 }
740 msc_a_put(msc_a, __func__);
741 return;
742
743 case MSC_A_EV_HANDOVER_REQUIRED:
744 msc_ho_start(msc_a, (struct ran_handover_required*)data);
745 return;
746
Neels Hofmeyr0a437be2019-05-10 15:55:52 +0200747 case MSC_A_EV_HANDOVER_END:
748 /* Termination event of the msc_ho_fsm. No action needed, it's all done in the msc_ho_fsm cleanup. This
749 * event only exists because osmo_fsm_inst_alloc_child() requires a parent term event; and maybe
750 * interesting for logging. */
751 return;
752
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100753 case MSC_A_EV_MO_CLOSE:
754 case MSC_A_EV_CN_CLOSE:
755 case MSC_A_EV_UNUSED:
756 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
757 return;
758
759 default:
760 OSMO_ASSERT(false);
761 }
762}
763
764static int msc_a_fsm_timer_cb(struct osmo_fsm_inst *fi)
765{
766 struct msc_a *msc_a = fi->priv;
767 if (msc_a_in_release(msc_a)) {
768 LOG_MSC_A(msc_a, LOGL_ERROR, "Timeout while releasing, discarding right now\n");
769 msc_a_put_all(msc_a, MSC_A_USE_WAIT_CLEAR_COMPLETE);
770 msc_a_state_chg(msc_a, MSC_A_ST_RELEASED);
771 } else {
772 enum gsm48_reject_value cause = GSM48_REJECT_CONGESTION;
773 osmo_fsm_inst_dispatch(fi, MSC_A_EV_CN_CLOSE, &cause);
774 }
775 return 0;
776}
777
778static void msc_a_fsm_releasing_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
779{
780 struct msc_a *msc_a = fi->priv;
781 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
782 int i;
783 char buf[128];
784 const char * const use_counts_to_cancel[] = {
785 MSC_A_USE_LOCATION_UPDATING,
786 MSC_A_USE_CM_SERVICE_CC,
787 MSC_A_USE_CM_SERVICE_SMS,
788 MSC_A_USE_CM_SERVICE_SS,
789 MSC_A_USE_PAGING_RESPONSE,
790 };
791
792 LOG_MSC_A(msc_a, LOGL_DEBUG, "Releasing: msc_a use is %s\n",
793 osmo_use_count_name_buf(buf, sizeof(buf), &msc_a->use_count));
794
795 if (vsub) {
796 vlr_subscr_get(vsub, __func__);
797
798 /* Cancel all VLR FSMs, if any */
799 vlr_subscr_cancel_attach_fsm(vsub, OSMO_FSM_TERM_ERROR, GSM48_REJECT_CONGESTION);
800
801 /* The subscriber has no active connection anymore.
802 * Restart the periodic Location Update expiry timer for this subscriber. */
803 vlr_subscr_enable_expire_lu(vsub);
804 }
805
806 /* If we're closing in a middle of a trans, we need to clean up */
807 trans_conn_closed(msc_a);
808
809 call_leg_release(msc_a->cc.call_leg);
810
811 /* Cancel use counts for pending CM Service / Paging */
812 for (i = 0; i < ARRAY_SIZE(use_counts_to_cancel); i++) {
813 const char *use = use_counts_to_cancel[i];
814 int32_t count = osmo_use_count_by(&msc_a->use_count, use);
815 if (!count)
816 continue;
817 LOG_MSC_A(msc_a, LOGL_DEBUG, "Releasing: canceling still pending use: %s (%d)\n", use, count);
818 osmo_use_count_get_put(&msc_a->use_count, use, -count);
819 }
820
821 if (msc_a->c.ran->type == OSMO_RAT_EUTRAN_SGS) {
822 sgs_iface_tx_release(vsub);
823 /* In SGsAP there is no confirmation of a release. */
824 msc_a_state_chg(msc_a, MSC_A_ST_RELEASED);
825 } else {
826 struct ran_msg msg = {
827 .msg_type = RAN_MSG_CLEAR_COMMAND,
828 .clear_command = {
Neels Hofmeyrd9fe7112020-07-11 00:20:20 +0200829 /* "Call Control" is the only cause code listed in 3GPP TS 48.008 3.2.1.21 CLEAR COMMAND
830 * that qualifies for a normal release situation. (OS#4664) */
831 .gsm0808_cause = GSM0808_CAUSE_CALL_CONTROL,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100832 .csfb_ind = (vsub && vsub->sgs_fsm->state == SGS_UE_ST_ASSOCIATED),
833 },
834 };
835 msc_a_get(msc_a, MSC_A_USE_WAIT_CLEAR_COMPLETE);
836 msc_a_ran_down(msc_a, MSC_ROLE_I, &msg);
Philipp Maier47cf84d2019-08-15 14:56:54 +0200837
838 /* The connection is cleared. The MS will now go back to 4G,
839 Switch the RAN type back to SGS. */
840 if (vsub && vsub->sgs_fsm->state == SGS_UE_ST_ASSOCIATED)
841 vsub->cs.attached_via_ran = OSMO_RAT_EUTRAN_SGS;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100842 }
843
844 if (vsub)
845 vlr_subscr_put(vsub, __func__);
846}
847
848static void msc_a_fsm_releasing(struct osmo_fsm_inst *fi, uint32_t event, void *data)
849{
850 struct msc_a *msc_a = fi->priv;
851
852 msc_a_cleanup_rtp_streams(msc_a, event, data);
853
854 switch (event) {
855 case MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST:
856 case MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST:
857 msc_a_ran_dec(msc_a, data, MSC_ROLE_I);
858 return;
859
860 case MSC_A_EV_MO_CLOSE:
861 case MSC_A_EV_CN_CLOSE:
862 case MSC_A_EV_UNUSED:
863 /* Already releasing */
864 return;
865
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100866 case MSC_EV_CALL_LEG_TERM:
867 case MSC_MNCC_EV_CALL_ENDED:
868 /* RTP streams cleaned up above */
869 return;
870
Neels Hofmeyr0a437be2019-05-10 15:55:52 +0200871 case MSC_A_EV_HANDOVER_END:
872 /* msc_ho_fsm does cleanup. */
873 return;
874
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100875 default:
876 OSMO_ASSERT(false);
877 }
878}
879
880
881static void msc_a_fsm_released_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
882{
883 struct msc_a *msc_a = msc_a_fi_priv(fi);
884 char buf[128];
885 LOG_MSC_A(msc_a, LOGL_DEBUG, "Released: msc_a use is %s\n",
886 osmo_use_count_name_buf(buf, sizeof(buf), &msc_a->use_count));
887 if (osmo_use_count_total(&msc_a->use_count) == 0)
888 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, fi);
889}
890
891static void msc_a_fsm_released(struct osmo_fsm_inst *fi, uint32_t event, void *data)
892{
893 if (event == MSC_A_EV_UNUSED)
894 osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, fi);
895}
896
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100897void msc_a_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
898{
899 struct msc_a *msc_a = msc_a_fi_priv(fi);
900
901 trans_conn_closed(msc_a);
902
903 if (msc_a_fsm_has_active_transactions(fi))
904 LOG_MSC_A(msc_a, LOGL_ERROR, "Deallocating active transactions failed\n");
905
906 LOG_MSC_A_CAT(msc_a, DREF, LOGL_DEBUG, "max total use count was %d\n", msc_a->max_total_use_count);
907}
908
909const struct value_string msc_a_fsm_event_names[] = {
910 OSMO_VALUE_STRING(MSC_REMOTE_EV_RX_GSUP),
911 OSMO_VALUE_STRING(MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE),
912 OSMO_VALUE_STRING(MSC_EV_CALL_LEG_RTP_COMPLETE),
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100913 OSMO_VALUE_STRING(MSC_EV_CALL_LEG_TERM),
914 OSMO_VALUE_STRING(MSC_MNCC_EV_NEED_LOCAL_RTP),
915 OSMO_VALUE_STRING(MSC_MNCC_EV_CALL_PROCEEDING),
916 OSMO_VALUE_STRING(MSC_MNCC_EV_CALL_COMPLETE),
917 OSMO_VALUE_STRING(MSC_MNCC_EV_CALL_ENDED),
918 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_COMPLETE_LAYER_3),
919 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST),
920 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST),
921 OSMO_VALUE_STRING(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST),
922 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST),
923 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE),
924 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE),
925 OSMO_VALUE_STRING(MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST),
926 OSMO_VALUE_STRING(MSC_A_EV_COMPLETE_LAYER_3_OK),
927 OSMO_VALUE_STRING(MSC_A_EV_CLASSMARK_UPDATE),
928 OSMO_VALUE_STRING(MSC_A_EV_AUTHENTICATED),
929 OSMO_VALUE_STRING(MSC_A_EV_TRANSACTION_ACCEPTED),
930 OSMO_VALUE_STRING(MSC_A_EV_CN_CLOSE),
931 OSMO_VALUE_STRING(MSC_A_EV_MO_CLOSE),
932 OSMO_VALUE_STRING(MSC_A_EV_UNUSED),
933 OSMO_VALUE_STRING(MSC_A_EV_HANDOVER_REQUIRED),
934 OSMO_VALUE_STRING(MSC_A_EV_HANDOVER_END),
935 {}
936};
937
938#define S(x) (1 << (x))
939
940static const struct osmo_fsm_state msc_a_fsm_states[] = {
941 [MSC_A_ST_VALIDATE_L3] = {
942 .name = OSMO_STRINGIFY(MSC_A_ST_VALIDATE_L3),
943 .in_event_mask = 0
944 | S(MSC_A_EV_FROM_I_COMPLETE_LAYER_3)
945 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
946 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
947 | S(MSC_A_EV_COMPLETE_LAYER_3_OK)
948 | S(MSC_A_EV_MO_CLOSE)
949 | S(MSC_A_EV_CN_CLOSE)
950 | S(MSC_A_EV_UNUSED)
951 ,
952 .out_state_mask = 0
953 | S(MSC_A_ST_VALIDATE_L3)
954 | S(MSC_A_ST_AUTH_CIPH)
955 | S(MSC_A_ST_RELEASING)
956 ,
957 .action = msc_a_fsm_validate_l3,
958 },
959 [MSC_A_ST_AUTH_CIPH] = {
960 .name = OSMO_STRINGIFY(MSC_A_ST_AUTH_CIPH),
961 .in_event_mask = 0
962 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
963 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
964 | S(MSC_A_EV_AUTHENTICATED)
965 | S(MSC_A_EV_MO_CLOSE)
966 | S(MSC_A_EV_CN_CLOSE)
967 | S(MSC_A_EV_UNUSED)
968 ,
969 .out_state_mask = 0
970 | S(MSC_A_ST_WAIT_CLASSMARK_UPDATE)
971 | S(MSC_A_ST_AUTHENTICATED)
972 | S(MSC_A_ST_RELEASING)
973 ,
974 .action = msc_a_fsm_auth_ciph,
975 },
976 [MSC_A_ST_WAIT_CLASSMARK_UPDATE] = {
977 .name = OSMO_STRINGIFY(MSC_A_ST_WAIT_CLASSMARK_UPDATE),
978 .in_event_mask = 0
979 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
980 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
981 | S(MSC_A_EV_CLASSMARK_UPDATE)
982 | S(MSC_A_EV_MO_CLOSE)
983 | S(MSC_A_EV_CN_CLOSE)
984 ,
985 .out_state_mask = 0
986 | S(MSC_A_ST_AUTH_CIPH)
987 | S(MSC_A_ST_RELEASING)
988 ,
989 .action = msc_a_fsm_wait_classmark_update,
990 },
991 [MSC_A_ST_AUTHENTICATED] = {
992 .name = OSMO_STRINGIFY(MSC_A_ST_AUTHENTICATED),
993 /* allow everything to release for any odd behavior */
994 .in_event_mask = 0
995 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
996 | S(MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST)
997 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
998 | S(MSC_A_EV_TRANSACTION_ACCEPTED)
999 | S(MSC_A_EV_MO_CLOSE)
1000 | S(MSC_A_EV_CN_CLOSE)
1001 | S(MSC_A_EV_UNUSED)
1002 ,
1003 .out_state_mask = 0
1004 | S(MSC_A_ST_RELEASING)
1005 | S(MSC_A_ST_COMMUNICATING)
1006 ,
1007 .onenter = msc_a_fsm_authenticated_enter,
1008 .action = msc_a_fsm_authenticated,
1009 },
1010 [MSC_A_ST_COMMUNICATING] = {
1011 .name = OSMO_STRINGIFY(MSC_A_ST_COMMUNICATING),
1012 /* allow everything to release for any odd behavior */
1013 .in_event_mask = 0
1014 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1015 | S(MSC_A_EV_FROM_I_PREPARE_SUBSEQUENT_HANDOVER_REQUEST)
1016 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1017 | S(MSC_A_EV_FROM_T_PREPARE_HANDOVER_RESPONSE)
1018 | S(MSC_A_EV_FROM_T_PREPARE_HANDOVER_FAILURE)
1019 | S(MSC_A_EV_FROM_T_PROCESS_ACCESS_SIGNALLING_REQUEST)
1020 | S(MSC_A_EV_FROM_T_SEND_END_SIGNAL_REQUEST)
1021 | S(MSC_A_EV_TRANSACTION_ACCEPTED)
1022 | S(MSC_A_EV_MO_CLOSE)
1023 | S(MSC_A_EV_CN_CLOSE)
1024 | S(MSC_A_EV_UNUSED)
1025 | S(MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE)
1026 | S(MSC_EV_CALL_LEG_RTP_COMPLETE)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001027 | S(MSC_EV_CALL_LEG_TERM)
1028 | S(MSC_MNCC_EV_CALL_ENDED)
1029 | S(MSC_A_EV_HANDOVER_REQUIRED)
Neels Hofmeyr0a437be2019-05-10 15:55:52 +02001030 | S(MSC_A_EV_HANDOVER_END)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001031 ,
1032 .out_state_mask = 0
1033 | S(MSC_A_ST_RELEASING)
1034 ,
1035 .action = msc_a_fsm_communicating,
1036 },
1037 [MSC_A_ST_RELEASING] = {
1038 .name = OSMO_STRINGIFY(MSC_A_ST_RELEASING),
1039 .in_event_mask = 0
1040 | S(MSC_A_EV_FROM_I_PROCESS_ACCESS_SIGNALLING_REQUEST)
1041 | S(MSC_A_EV_FROM_I_SEND_END_SIGNAL_REQUEST)
1042 | S(MSC_A_EV_UNUSED)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001043 | S(MSC_EV_CALL_LEG_TERM)
1044 | S(MSC_MNCC_EV_CALL_ENDED)
Neels Hofmeyr0a437be2019-05-10 15:55:52 +02001045 | S(MSC_A_EV_HANDOVER_END)
Pau Espin Pedrole53ecde2021-07-12 13:37:24 +02001046 | S(MSC_A_EV_CN_CLOSE)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001047 ,
1048 .out_state_mask = 0
1049 | S(MSC_A_ST_RELEASED)
1050 ,
1051 .onenter = msc_a_fsm_releasing_onenter,
1052 .action = msc_a_fsm_releasing,
1053 },
1054 [MSC_A_ST_RELEASED] = {
1055 .name = OSMO_STRINGIFY(MSC_A_ST_RELEASED),
1056 .in_event_mask = 0
1057 | S(MSC_A_EV_UNUSED)
1058 ,
1059 .onenter = msc_a_fsm_released_onenter,
1060 .action = msc_a_fsm_released,
1061 },
1062};
1063
1064static struct osmo_fsm msc_a_fsm = {
1065 .name = "msc_a",
1066 .states = msc_a_fsm_states,
1067 .num_states = ARRAY_SIZE(msc_a_fsm_states),
1068 .log_subsys = DMSC,
1069 .event_names = msc_a_fsm_event_names,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001070 .timer_cb = msc_a_fsm_timer_cb,
1071 .cleanup = msc_a_fsm_cleanup,
1072};
1073
1074static __attribute__((constructor)) void msc_a_fsm_init()
1075{
1076 OSMO_ASSERT(osmo_fsm_register(&msc_a_fsm) == 0);
1077}
1078
1079static int msc_a_use_cb(struct osmo_use_count_entry *e, int32_t old_use_count, const char *file, int line)
1080{
1081 struct msc_a *msc_a = e->use_count->talloc_object;
1082 char buf[128];
1083 int32_t total;
1084 int level;
1085
1086 if (!e->use)
1087 return -EINVAL;
1088
1089 total = osmo_use_count_total(&msc_a->use_count);
1090
1091 if (total == 0
1092 || (total == 1 && old_use_count == 0 && e->count == 1))
1093 level = LOGL_INFO;
1094 else
1095 level = LOGL_DEBUG;
1096
1097 LOG_MSC_A_CAT_SRC(msc_a, DREF, level, file, line, "%s %s: now used by %s\n",
1098 (e->count - old_use_count) > 0? "+" : "-", e->use,
1099 osmo_use_count_name_buf(buf, sizeof(buf), &msc_a->use_count));
1100
1101 if (e->count < 0)
1102 return -ERANGE;
1103
1104 msc_a->max_total_use_count = OSMO_MAX(msc_a->max_total_use_count, total);
1105
1106 if (total == 0)
1107 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_UNUSED, NULL);
1108 return 0;
1109}
1110
1111struct msc_a *msc_a_alloc(struct msub *msub, struct ran_infra *ran)
1112{
1113 struct msc_a *msc_a = msub_role_alloc(msub, MSC_ROLE_A, &msc_a_fsm, struct msc_a, ran);
1114 msc_a->use_count = (struct osmo_use_count){
1115 .talloc_object = msc_a,
1116 .use_cb = msc_a_use_cb,
1117 };
1118 osmo_use_count_make_static_entries(&msc_a->use_count, msc_a->use_count_buf, ARRAY_SIZE(msc_a->use_count_buf));
1119 /* Start timeout for first state */
Neels Hofmeyr01653252019-09-03 02:06:22 +02001120 msc_a_state_chg_always(msc_a, MSC_A_ST_VALIDATE_L3);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001121 return msc_a;
1122}
1123
1124bool msc_a_is_establishing_auth_ciph(const struct msc_a *msc_a)
1125{
1126 if (!msc_a || !msc_a->c.fi)
1127 return false;
1128 return msc_a->c.fi->state == MSC_A_ST_AUTH_CIPH;
1129}
1130
1131const struct value_string complete_layer3_type_names[] = {
1132 { COMPLETE_LAYER3_NONE, "NONE" },
1133 { COMPLETE_LAYER3_LU, "LU" },
1134 { COMPLETE_LAYER3_CM_SERVICE_REQ, "CM_SERVICE_REQ" },
1135 { COMPLETE_LAYER3_PAGING_RESP, "PAGING_RESP" },
Neels Hofmeyrae98b972021-07-27 03:46:49 +02001136 { COMPLETE_LAYER3_CM_RE_ESTABLISH_REQ, "CM_RE_ESTABLISH_REQ" },
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001137 { 0, NULL }
1138};
1139
1140#define _msc_a_update_id(MSC_A, FMT, ARGS ...) \
1141 do { \
1142 if (osmo_fsm_inst_update_id_f(msc_a->c.fi, FMT ":%s:%s", \
1143 ## ARGS, \
1144 msub_ran_conn_name(msc_a->c.msub), \
1145 complete_layer3_type_name(msc_a->complete_layer3_type)) \
1146 == 0) { \
1147 struct vlr_subscr *_vsub = msc_a_vsub(MSC_A); \
1148 if (_vsub) { \
1149 if (_vsub->lu_fsm) \
1150 osmo_fsm_inst_update_id(_vsub->lu_fsm, (MSC_A)->c.fi->id); \
1151 if (_vsub->auth_fsm) \
1152 osmo_fsm_inst_update_id(_vsub->auth_fsm, (MSC_A)->c.fi->id); \
1153 if (_vsub->proc_arq_fsm) \
1154 osmo_fsm_inst_update_id(_vsub->proc_arq_fsm, (MSC_A)->c.fi->id); \
1155 } \
1156 LOG_MSC_A(MSC_A, LOGL_DEBUG, "Updated ID\n"); \
1157 } \
1158 /* otherwise osmo_fsm_inst_update_id_f() will log an error. */ \
1159 } while (0)
1160
1161
1162/* 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 +02001163void msc_a_update_id_from_mi(struct msc_a *msc_a, const struct osmo_mobile_identity *mi)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001164{
Neels Hofmeyr46d526a2020-05-29 03:27:50 +02001165 _msc_a_update_id(msc_a, "%s", osmo_mobile_identity_to_str_c(OTC_SELECT, mi));
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001166}
1167
1168/* Update msc_a->fi id string from current msc_a->vsub and msc_a->complete_layer3_type. */
1169void msc_a_update_id(struct msc_a *msc_a)
1170{
1171 _msc_a_update_id(msc_a, "%s", vlr_subscr_name(msc_a_vsub(msc_a)));
1172}
1173
1174/* Iterate all msc_a instances that are relevant for this subscriber, and update FSM ID strings for all of the FSM
1175 * instances. */
1176void msc_a_update_id_for_vsub(struct vlr_subscr *for_vsub)
1177{
1178 struct msub *msub;
1179 llist_for_each_entry(msub, &msub_list, entry) {
1180 struct vlr_subscr *vsub = msub_vsub(msub);
1181 if (vsub != for_vsub)
1182 continue;
1183 msc_a_update_id(msub_msc_a(msub));
1184 }
1185}
1186
1187static bool msg_is_initially_permitted(const struct gsm48_hdr *hdr)
1188{
1189 uint8_t pdisc = gsm48_hdr_pdisc(hdr);
1190 uint8_t msg_type = gsm48_hdr_msg_type(hdr);
1191
1192 switch (pdisc) {
1193 case GSM48_PDISC_MM:
1194 switch (msg_type) {
1195 case GSM48_MT_MM_LOC_UPD_REQUEST:
1196 case GSM48_MT_MM_CM_SERV_REQ:
1197 case GSM48_MT_MM_CM_REEST_REQ:
1198 case GSM48_MT_MM_AUTH_RESP:
1199 case GSM48_MT_MM_AUTH_FAIL:
1200 case GSM48_MT_MM_ID_RESP:
1201 case GSM48_MT_MM_TMSI_REALL_COMPL:
1202 case GSM48_MT_MM_IMSI_DETACH_IND:
1203 return true;
1204 default:
1205 break;
1206 }
1207 break;
1208 case GSM48_PDISC_RR:
1209 switch (msg_type) {
1210 /* GSM48_MT_RR_CIPH_M_COMPL is actually handled in bssmap_rx_ciph_compl() and gets redirected in the
1211 * BSSAP layer to ran_conn_cipher_mode_compl() (before this here is reached) */
1212 case GSM48_MT_RR_PAG_RESP:
1213 case GSM48_MT_RR_CIPH_M_COMPL:
1214 return true;
1215 default:
1216 break;
1217 }
1218 break;
1219 default:
1220 break;
1221 }
1222
1223 return false;
1224}
1225
1226/* Main entry point for GSM 04.08/44.008 Layer 3 data (e.g. from the BSC). */
1227int msc_a_up_l3(struct msc_a *msc_a, struct msgb *msg)
1228{
1229 struct gsm48_hdr *gh;
1230 uint8_t pdisc;
1231 int rc;
1232 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
1233 int is_r99;
1234
1235 OSMO_ASSERT(msg->l3h);
1236 OSMO_ASSERT(msg);
1237
1238 gh = msgb_l3(msg);
1239 pdisc = gsm48_hdr_pdisc(gh);
1240
1241 LOG_MSC_A_CAT(msc_a, DRLL, LOGL_DEBUG, "Dispatching 04.08 message: %s %s\n",
1242 gsm48_pdisc_name(pdisc), gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1243
1244 /* To evaluate the 3GPP TS 24.007 Duplicate Detection, we need Classmark information on whether the MS is R99
1245 * capable. If the subscriber is already actively connected, the Classmark information is stored with the
1246 * vlr_subscr. Otherwise, this *must* be a Complete Layer 3 with Classmark info. */
1247 if (vsub)
1248 is_r99 = osmo_gsm48_classmark_is_r99(&vsub->classmark) ? 1 : 0;
1249 else
1250 is_r99 = compl_l3_msg_is_r99(msg);
1251
1252 if (is_r99 < 0) {
1253 LOG_MSC_A(msc_a, LOGL_ERROR,
1254 "No Classmark Information, dropping non-Complete-Layer3 message: %s\n",
1255 gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1256 return -EACCES;
1257 }
1258
1259 if (is_r99 >= 0
1260 && ran_dec_dtap_undup_is_duplicate(msc_a->c.fi, msc_a->n_sd_next, is_r99 ? true : false, msg)) {
1261 LOG_MSC_A(msc_a, LOGL_DEBUG, "Dropping duplicate message"
1262 " (3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection)\n");
1263 return 0;
1264 }
1265
1266 if (!msc_a_is_accepted(msc_a)
1267 && !msg_is_initially_permitted(gh)) {
1268 LOG_MSC_A(msc_a, LOGL_ERROR,
1269 "Message not permitted for initial conn: %s\n",
1270 gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1271 return -EACCES;
1272 }
1273
1274 if (vsub && vsub->cs.attached_via_ran != msc_a->c.ran->type) {
1275 LOG_MSC_A(msc_a, LOGL_ERROR,
1276 "Illegal situation: RAN type mismatch:"
1277 " attached via %s, received message via %s\n",
1278 osmo_rat_type_name(vsub->cs.attached_via_ran),
1279 osmo_rat_type_name(msc_a->c.ran->type));
1280 return -EACCES;
1281 }
1282
1283#if 0
1284 if (silent_call_reroute(conn, msg))
1285 return silent_call_rx(conn, msg);
1286#endif
1287
1288 switch (pdisc) {
1289 case GSM48_PDISC_CC:
1290 rc = gsm0408_rcv_cc(msc_a, msg);
1291 break;
1292 case GSM48_PDISC_MM:
1293 rc = gsm0408_rcv_mm(msc_a, msg);
1294 break;
1295 case GSM48_PDISC_RR:
1296 rc = gsm0408_rcv_rr(msc_a, msg);
1297 break;
1298 case GSM48_PDISC_SMS:
1299 rc = gsm0411_rcv_sms(msc_a, msg);
1300 break;
1301 case GSM48_PDISC_MM_GPRS:
1302 case GSM48_PDISC_SM_GPRS:
1303 LOG_MSC_A_CAT(msc_a, DRLL, LOGL_NOTICE, "Unimplemented "
1304 "GSM 04.08 discriminator 0x%02x\n", pdisc);
1305 rc = -ENOTSUP;
1306 break;
1307 case GSM48_PDISC_NC_SS:
1308 rc = gsm0911_rcv_nc_ss(msc_a, msg);
1309 break;
1310 case GSM48_PDISC_TEST:
1311 rc = gsm0414_rcv_test(msc_a, msg);
1312 break;
1313 default:
1314 LOG_MSC_A_CAT(msc_a, DRLL, LOGL_NOTICE, "Unknown "
1315 "GSM 04.08 discriminator 0x%02x\n", pdisc);
1316 rc = -EINVAL;
1317 break;
1318 }
1319
1320 return rc;
1321}
1322
1323static void msc_a_up_call_assignment_complete(struct msc_a *msc_a, const struct ran_msg *ac)
1324{
1325 struct gsm_trans *cc_trans = msc_a->cc.active_trans;
1326 struct rtp_stream *rtps_to_ran = msc_a->cc.call_leg ? msc_a->cc.call_leg->rtp[RTP_TO_RAN] : NULL;
Pau Espin Pedrol9de384a2022-01-07 16:27:04 +01001327 const enum mgcp_codecs *codec_if_known = ac->assignment_complete.codec_present ?
1328 &ac->assignment_complete.codec : NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001329
1330 if (!rtps_to_ran) {
1331 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx Assignment Complete, but no RTP stream is set up\n");
1332 return;
1333 }
1334 if (!cc_trans) {
Neels Hofmeyr550506a2022-01-13 23:31:57 +01001335 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx Assignment Complete, but no CC transaction is active\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001336 return;
1337 }
1338
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +02001339 if (rtps_to_ran->use_osmux != ac->assignment_complete.osmux_present) {
1340 LOG_MSC_A_CAT(msc_a, DCC, LOGL_ERROR, "Osmux usage ass request and complete don't match: %d vs %d\n",
1341 rtps_to_ran->use_osmux, ac->assignment_complete.osmux_present);
1342 call_leg_release(msc_a->cc.call_leg);
1343 return;
1344 }
1345
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001346 /* Update RAN-side endpoint CI: */
Pau Espin Pedrol9de384a2022-01-07 16:27:04 +01001347 if (codec_if_known)
1348 rtp_stream_set_codec(rtps_to_ran, *codec_if_known);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001349 rtp_stream_set_remote_addr(rtps_to_ran, &ac->assignment_complete.remote_rtp);
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +02001350 if (rtps_to_ran->use_osmux)
1351 rtp_stream_set_remote_osmux_cid(rtps_to_ran,
1352 ac->assignment_complete.osmux_cid);
1353
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001354 rtp_stream_commit(rtps_to_ran);
1355
1356 /* Setup CN side endpoint CI:
1357 * Now that
1358 * - the first CI has been created and a definitive endpoint name is assigned to the call_leg's MGW
1359 * endpoint,
1360 * - the Assignment has chosen a speech codec
1361 * go on to create the CN side RTP stream's CI. */
1362 if (call_leg_ensure_ci(msc_a->cc.call_leg, RTP_TO_CN, cc_trans->callref, cc_trans,
Pau Espin Pedrol9de384a2022-01-07 16:27:04 +01001363 codec_if_known, NULL)) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001364 LOG_MSC_A_CAT(msc_a, DCC, LOGL_ERROR, "Error creating MGW CI towards CN\n");
1365 call_leg_release(msc_a->cc.call_leg);
1366 return;
1367 }
1368}
1369
1370static void msc_a_up_call_assignment_failure(struct msc_a *msc_a, const struct ran_msg *af)
1371{
1372 struct gsm_trans *trans;
1373
1374 /* For a normal voice call, there will be an rtp_stream FSM. */
1375 if (msc_a->cc.call_leg && msc_a->cc.call_leg->rtp[RTP_TO_RAN]) {
1376 LOG_MSC_A(msc_a, LOGL_ERROR, "Assignment Failure, releasing call\n");
1377 rtp_stream_release(msc_a->cc.call_leg->rtp[RTP_TO_RAN]);
1378 return;
1379 }
1380
1381 /* Otherwise, a silent call might be active */
1382 trans = trans_find_by_type(msc_a, TRANS_SILENT_CALL);
1383 if (trans) {
1384 LOG_MSC_A(msc_a, LOGL_ERROR, "Assignment Failure, releasing silent call\n");
1385 trans_free(trans);
1386 return;
1387 }
1388
1389 /* Neither a voice call nor silent call assignment. Assume the worst and detach. */
1390 msc_a_release_cn(msc_a);
1391}
1392
1393static void msc_a_up_classmark_update(struct msc_a *msc_a, const struct osmo_gsm48_classmark *classmark,
1394 struct osmo_gsm48_classmark *dst)
1395{
1396 if (!dst) {
1397 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
1398
1399 if (!vsub)
1400 dst = &msc_a->temporary_classmark;
1401 else
1402 dst = &vsub->classmark;
1403 }
1404
Martin Hauke3f07dac2019-11-14 17:49:08 +01001405 LOG_MSC_A(msc_a, LOGL_DEBUG, "A5 capabilities received from Classmark Update: %s\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001406 osmo_gsm48_classmark_a5_name(classmark));
1407 osmo_gsm48_classmark_update(dst, classmark);
1408
1409 /* bump subscr conn FSM in case it is waiting for a Classmark Update */
1410 if (msc_a->c.fi->state == MSC_A_ST_WAIT_CLASSMARK_UPDATE)
1411 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_CLASSMARK_UPDATE, NULL);
1412}
1413
1414static void msc_a_up_sapi_n_reject(struct msc_a *msc_a, const struct ran_msg *msg)
1415{
1416 int sapi = msg->sapi_n_reject.dlci & 0x7;
1417 if (sapi == UM_SAPI_SMS)
1418 gsm411_sapi_n_reject(msc_a);
1419}
1420
1421static int msc_a_up_ho(struct msc_a *msc_a, const struct msc_a_ran_dec_data *d, uint32_t ho_fi_event)
1422{
1423 if (!msc_a->ho.fi) {
1424 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx Handover message, but no Handover ongoing: %s\n", d->ran_dec->msg_name);
1425 return -EINVAL;
1426 }
1427 return osmo_fsm_inst_dispatch(msc_a->ho.fi, ho_fi_event, (void*)d);
1428}
1429
1430int msc_a_ran_dec_from_msc_i(struct msc_a *msc_a, struct msc_a_ran_dec_data *d)
1431{
1432 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
Alexander Couzens2aaff752021-10-19 17:09:11 +02001433 struct gsm_network *net = msc_a_net(msc_a);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001434 const struct ran_msg *msg = d->ran_dec;
1435 int rc = -99;
1436
1437 switch (msg->msg_type) {
1438
1439 case RAN_MSG_COMPL_L3:
Neels Hofmeyr68f50da2020-06-24 14:22:52 +02001440 /* In case the cell_id from Complete Layer 3 Information lacks a PLMN, write the configured PLMN code
1441 * into msc_a->via_cell. Then overwrite with those bits obtained from Complete Layer 3 Information. */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001442 msc_a->via_cell = (struct osmo_cell_global_id){
1443 .lai.plmn = msc_a_net(msc_a)->plmn,
1444 };
1445 gsm0808_cell_id_to_cgi(&msc_a->via_cell, msg->compl_l3.cell_id);
Neels Hofmeyr7c6c9ae2022-01-13 21:38:35 +01001446 /* If a codec list was sent along in the RAN_MSG_COMPL_L3, remember it for any upcoming codec
1447 * resolution. */
1448 if (msg->compl_l3.codec_list_bss_supported) {
1449 msc_a->cc.compl_l3_codec_list_bss_supported = *msg->compl_l3.codec_list_bss_supported;
1450 if (log_check_level(msc_a->c.ran->log_subsys, LOGL_DEBUG)) {
1451 struct sdp_audio_codecs ac = {};
1452 sdp_audio_codecs_from_speech_codec_list(&ac, &msc_a->cc.compl_l3_codec_list_bss_supported);
1453 LOG_MSC_A(msc_a, LOGL_DEBUG, "Complete Layer 3: Codec List (BSS Supported): %s\n",
1454 sdp_audio_codecs_to_str(&ac));
1455 }
1456 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001457 rc = msc_a_up_l3(msc_a, msg->compl_l3.msg);
1458 if (!rc) {
1459 struct ran_conn *conn = msub_ran_conn(msc_a->c.msub);
1460 if (conn)
1461 ran_peer_cells_seen_add(conn->ran_peer, msg->compl_l3.cell_id);
1462 }
1463 break;
1464
1465 case RAN_MSG_DTAP:
1466 rc = msc_a_up_l3(msc_a, msg->dtap);
1467 break;
1468
1469 case RAN_MSG_CLEAR_REQUEST:
1470 rc = osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_MO_CLOSE, NULL);
1471 break;
1472
1473 case RAN_MSG_CLEAR_COMPLETE:
1474 switch (msc_a->c.fi->state) {
1475 case MSC_A_ST_RELEASING:
1476 msc_a_put_all(msc_a, MSC_A_USE_WAIT_CLEAR_COMPLETE);
1477 msc_a_state_chg(msc_a, MSC_A_ST_RELEASED);
1478 break;
1479 case MSC_A_ST_RELEASED:
1480 break;
1481 default:
1482 LOG_MSC_A(msc_a, LOGL_ERROR, "Received Clear Complete event, but did not send Clear Command\n");
1483 msc_a_state_chg(msc_a, MSC_A_ST_RELEASING);
1484 break;
1485 }
1486 rc = 0;
1487 break;
1488
1489 case RAN_MSG_CLASSMARK_UPDATE:
1490 msc_a_up_classmark_update(msc_a, msg->classmark_update.classmark, NULL);
1491 rc = 0;
1492 break;
1493
1494 case RAN_MSG_CIPHER_MODE_COMPLETE:
1495 /* Remember what Ciphering was negotiated (e.g. for Handover) */
1496 if (msg->cipher_mode_complete.alg_id) {
1497 msc_a->geran_encr.alg_id = msg->cipher_mode_complete.alg_id;
1498 LOG_MSC_A(msc_a, LOGL_DEBUG, "Cipher Mode Complete: chosen encryption algorithm: A5/%u\n",
1499 msc_a->geran_encr.alg_id - 1);
Alexander Couzens2aaff752021-10-19 17:09:11 +02001500 }
1501
1502 if (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU) {
1503 int16_t utran_encryption;
1504
1505 /* utran: ensure chosen ciphering mode is allowed
1506 * If the IE is missing (utran_encryption == -1), parse it as no encryption */
1507 utran_encryption = msg->cipher_mode_complete.utran_encryption;
1508 if (utran_encryption == -1)
1509 utran_encryption = 0;
1510 if ((net->uea_encryption_mask & (1 << utran_encryption)) == 0) {
1511 /* cipher disallowed */
1512 LOG_MSC_A(msc_a, LOGL_ERROR, "Cipher Mode Complete: RNC chosen forbidden ciphering UEA%d\n",
1513 msg->cipher_mode_complete.utran_encryption);
1514 vlr_subscr_rx_ciph_res(vsub, VLR_CIPH_REJECT);
1515 rc = 0;
1516 break;
1517 }
1518 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001519 vlr_subscr_rx_ciph_res(vsub, VLR_CIPH_COMPL);
1520 rc = 0;
Neels Hofmeyre9a39112019-08-29 00:10:49 +02001521
1522 /* Evaluate enclosed L3 message, typically Identity Response (IMEISV) */
1523 if (msg->cipher_mode_complete.l3_msg) {
1524 unsigned char *data = (unsigned char*)(msg->cipher_mode_complete.l3_msg->val);
1525 uint16_t len = msg->cipher_mode_complete.l3_msg->len;
1526 struct msgb *dtap = msgb_alloc(len, "DTAP from Cipher Mode Complete");
1527 unsigned char *pos = msgb_put(dtap, len);
1528 memcpy(pos, data, len);
1529 dtap->l3h = pos;
1530 rc = msc_a_up_l3(msc_a, dtap);
1531 msgb_free(dtap);
1532 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001533 break;
1534
1535 case RAN_MSG_CIPHER_MODE_REJECT:
1536 vlr_subscr_rx_ciph_res(vsub, VLR_CIPH_REJECT);
1537 rc = 0;
1538 break;
1539
1540 case RAN_MSG_ASSIGNMENT_COMPLETE:
1541 msc_a_up_call_assignment_complete(msc_a, msg);
1542 rc = 0;
1543 break;
1544
1545 case RAN_MSG_ASSIGNMENT_FAILURE:
1546 msc_a_up_call_assignment_failure(msc_a, msg);
1547 rc = 0;
1548 break;
1549
1550 case RAN_MSG_SAPI_N_REJECT:
1551 msc_a_up_sapi_n_reject(msc_a, msg);
1552 rc = 0;
1553 break;
1554
1555 case RAN_MSG_HANDOVER_PERFORMED:
1556 /* The BSS lets us know that a handover happened within the BSS, which doesn't concern us. */
1557 LOG_MSC_A(msc_a, LOGL_ERROR, "'Handover Performed' handling not implemented\n");
1558 break;
1559
1560 case RAN_MSG_HANDOVER_REQUIRED:
1561 /* The BSS lets us know that it wants to handover to a different cell */
1562 rc = osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_HANDOVER_REQUIRED, (void*)&msg->handover_required);
1563 break;
1564
1565 case RAN_MSG_HANDOVER_FAILURE:
1566 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_FAILURE);
1567 break;
1568
Keith Whytea1a70be2021-05-16 02:59:52 +02001569 case RAN_MSG_LCLS_STATUS:
1570 /* The BSS sends us LCLS_STATUS. We do nothing for now, but it is not an error. */
1571 LOG_MSC_A(msc_a, LOGL_DEBUG, "LCLS_STATUS (%s) received from MSC-I\n",
1572 gsm0808_lcls_status_name(msg->lcls_status.status));
1573 rc = 0;
1574 break;
1575
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001576 default:
1577 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from MSC-I not implemented: %s\n", ran_msg_type_name(msg->msg_type));
1578 rc = -ENOTSUP;
1579 break;
1580 }
1581 return rc;
1582}
1583
1584static int msc_a_ran_dec_from_msc_t(struct msc_a *msc_a, struct msc_a_ran_dec_data *d)
1585{
1586 struct msc_t *msc_t = msc_a_msc_t(msc_a);
1587 int rc = -99;
1588
1589 if (!msc_t) {
1590 LOG_MSC_A(msc_a, LOGL_ERROR, "Rx message from MSC-T role, but I have no active MSC-T role.\n");
1591 return -EINVAL;
1592 }
1593
1594 OSMO_ASSERT(d->ran_dec);
1595
1596 switch (d->ran_dec->msg_type) {
1597
1598 case RAN_MSG_CLEAR_REQUEST:
1599 rc = osmo_fsm_inst_dispatch(msc_t->c.fi, MSC_T_EV_MO_CLOSE, NULL);
1600 break;
1601
1602 case RAN_MSG_CLEAR_COMPLETE:
1603 rc = osmo_fsm_inst_dispatch(msc_t->c.fi, MSC_T_EV_CLEAR_COMPLETE, NULL);
1604 break;
1605
1606 case RAN_MSG_CLASSMARK_UPDATE:
1607 msc_a_up_classmark_update(msc_a, d->ran_dec->classmark_update.classmark, &msc_t->classmark);
1608 rc = 0;
1609 break;
1610
1611 case RAN_MSG_HANDOVER_REQUEST_ACK:
1612 /* new BSS accepts Handover */
1613 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_REQUEST_ACK);
1614 break;
1615
1616 case RAN_MSG_HANDOVER_DETECT:
1617 /* new BSS signals the MS is DETECTed on the new lchan */
1618 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_DETECT);
1619 break;
1620
1621 case RAN_MSG_HANDOVER_COMPLETE:
1622 /* new BSS signals the MS has fully moved to the new lchan */
1623 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_COMPLETE);
1624 break;
1625
1626 case RAN_MSG_HANDOVER_FAILURE:
1627 rc = msc_a_up_ho(msc_a, d, MSC_HO_EV_RX_FAILURE);
1628 break;
1629
1630 default:
1631 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from MSC-T not implemented: %s\n",
1632 ran_msg_type_name(d->ran_dec->msg_type));
1633 rc = -ENOTSUP;
1634 break;
1635 }
1636 return rc;
1637}
1638
1639int msc_a_ran_decode_cb(struct osmo_fsm_inst *msc_a_fi, void *data, const struct ran_msg *msg)
1640{
1641 struct msc_a *msc_a = msc_a_fi_priv(msc_a_fi);
1642 struct msc_a_ran_dec_data *d = data;
1643 int rc = -99;
1644
1645 d->ran_dec = msg;
1646
1647 switch (d->from_role) {
1648 case MSC_ROLE_I:
1649 LOG_MSC_A(msc_a, LOGL_DEBUG, "RAN decode: %s\n", msg->msg_name ? : ran_msg_type_name(msg->msg_type));
1650 rc = msc_a_ran_dec_from_msc_i(msc_a, d);
1651 break;
1652
1653 case MSC_ROLE_T:
1654 LOG_MSC_A(msc_a, LOGL_DEBUG, "RAN decode from MSC-T: %s\n",
1655 msg->msg_name ? : ran_msg_type_name(msg->msg_type));
1656 rc = msc_a_ran_dec_from_msc_t(msc_a, d);
1657 break;
1658
1659 default:
1660 LOG_MSC_A(msc_a, LOGL_ERROR, "Message from invalid role %s: %s\n", msc_role_name(d->from_role),
1661 ran_msg_type_name(msg->msg_type));
1662 return -ENOTSUP;
1663 }
1664
1665 if (rc)
1666 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),
1667 msc_role_name(d->from_role));
1668 return rc;
1669}
1670
1671/* Your typical DTAP via FORWARD_ACCESS_SIGNALLING_REQUEST */
1672int _msc_a_ran_down(struct msc_a *msc_a, enum msc_role to_role, const struct ran_msg *ran_msg,
1673 const char *file, int line)
1674{
1675 return _msc_a_msg_down(msc_a, to_role, msub_role_to_role_event(msc_a->c.msub, MSC_ROLE_A, to_role),
1676 ran_msg, file, line);
1677}
1678
1679/* To transmit more complex events than just FORWARD_ACCESS_SIGNALLING_REQUEST, e.g. an
1680 * MSC_T_EV_FROM_A_PREPARE_HANDOVER_REQUEST */
1681int _msc_a_msg_down(struct msc_a *msc_a, enum msc_role to_role, uint32_t to_role_event,
1682 const struct ran_msg *ran_msg,
1683 const char *file, int line)
1684{
1685 struct an_apdu an_apdu = {
1686 .an_proto = msc_a->c.ran->an_proto,
1687 .msg = msc_role_ran_encode(msc_a->c.fi, ran_msg),
1688 };
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001689 if (!an_apdu.msg)
1690 return -EIO;
Vadim Yanitskiyc44342b2021-12-07 18:32:35 +03001691 return _msub_role_dispatch(msc_a->c.msub, to_role, to_role_event, &an_apdu, file, line);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001692}
1693
1694int msc_a_tx_dtap_to_i(struct msc_a *msc_a, struct msgb *dtap)
1695{
1696 struct ran_msg ran_msg;
Neels Hofmeyrc192c0b2019-10-07 21:41:18 +02001697 struct gsm48_hdr *gh = msgb_l3(dtap) ? : dtap->data;
1698 uint8_t pdisc = gsm48_hdr_pdisc(gh);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001699
Neels Hofmeyr2e8f8812019-08-21 16:56:41 +02001700 if (!msc_a) {
Neels Hofmeyr2e8f8812019-08-21 16:56:41 +02001701 LOGP(DMSC, LOGL_ERROR, "Attempt to send DTAP to NULL MSC-A, dropping message: %s %s\n",
1702 gsm48_pdisc_name(pdisc), gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1703 msgb_free(dtap);
1704 return -EIO;
1705 }
1706
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001707 if (msc_a->c.ran->type == OSMO_RAT_EUTRAN_SGS) {
1708 /* The SGs connection to the MME always is at the MSC-A. */
1709 return sgs_iface_tx_dtap_ud(msc_a, dtap);
1710 }
1711
Neels Hofmeyrc192c0b2019-10-07 21:41:18 +02001712 LOG_MSC_A(msc_a, LOGL_DEBUG, "Sending DTAP: %s %s\n",
1713 gsm48_pdisc_name(pdisc), gsm48_pdisc_msgtype_name(pdisc, gsm48_hdr_msg_type(gh)));
1714
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001715 ran_msg = (struct ran_msg){
1716 .msg_type = RAN_MSG_DTAP,
1717 .dtap = dtap,
1718 };
1719 return msc_a_ran_down(msc_a, MSC_ROLE_I, &ran_msg);
1720}
1721
1722struct msc_a *msc_a_for_vsub(const struct vlr_subscr *vsub, bool valid_conn_only)
1723{
1724 struct msc_a *msc_a = msub_msc_a(msub_for_vsub(vsub));
1725 if (valid_conn_only && !msc_a_is_accepted(msc_a))
1726 return NULL;
1727 return msc_a;
1728}
1729
1730int msc_tx_common_id(struct msc_a *msc_a, enum msc_role to_role)
1731{
1732 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
Vadim Yanitskiy435f67f2021-06-06 15:47:49 +02001733 if (vsub == NULL)
1734 return -ENODEV;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001735 struct ran_msg msg = {
1736 .msg_type = RAN_MSG_COMMON_ID,
1737 .common_id = {
1738 .imsi = vsub->imsi,
Pau Espin Pedrol67106702021-04-27 18:20:15 +02001739 .last_eutran_plmn_present = vsub->sgs.last_eutran_plmn_present,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001740 },
1741 };
Pau Espin Pedrol67106702021-04-27 18:20:15 +02001742 if (vsub->sgs.last_eutran_plmn_present) {
1743 memcpy(&msg.common_id.last_eutran_plmn, &vsub->sgs.last_eutran_plmn,
1744 sizeof(vsub->sgs.last_eutran_plmn));
1745 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001746
1747 return msc_a_ran_down(msc_a, to_role, &msg);
1748}
1749
1750static int msc_a_start_assignment(struct msc_a *msc_a, struct gsm_trans *cc_trans)
1751{
1752 struct call_leg *cl = msc_a->cc.call_leg;
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +02001753 struct msc_i *msc_i = msc_a_msc_i(msc_a);
1754 struct gsm_network *net = msc_a_net(msc_a);
Pau Espin Pedrol3a02d292022-01-05 13:56:16 +01001755 enum mgcp_codecs codec, *codec_ptr;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001756
1757 OSMO_ASSERT(!msc_a->cc.active_trans);
1758 msc_a->cc.active_trans = cc_trans;
1759
1760 OSMO_ASSERT(cc_trans && cc_trans->type == TRANS_CC);
1761
1762 if (!cl) {
1763 cl = msc_a->cc.call_leg = call_leg_alloc(msc_a->c.fi,
1764 MSC_EV_CALL_LEG_TERM,
1765 MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE,
Neels Hofmeyr265a4c72019-05-09 16:20:51 +02001766 MSC_EV_CALL_LEG_RTP_COMPLETE);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001767 OSMO_ASSERT(cl);
1768
Martin Hauke3f07dac2019-11-14 17:49:08 +01001769 /* HACK: We put the connection in loopback mode at the beginning to
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001770 * trick the hNodeB into doing the IuUP negotiation with itself.
1771 * This is a hack we need because osmo-mgw does not support IuUP yet, see OS#2459. */
1772 if (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU)
1773 cl->crcx_conn_mode[RTP_TO_RAN] = MGCP_CONN_LOOPBACK;
1774 }
1775
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +02001776 if (net->use_osmux != OSMUX_USAGE_OFF) {
1777 msc_i = msc_a_msc_i(msc_a);
1778 if (msc_i->c.remote_to) {
1779 /* TODO: investigate what to do in this case */
1780 LOG_MSC_A(msc_a, LOGL_ERROR, "Osmux not yet supported for inter-MSC");
1781 } else {
1782 cl->ran_peer_supports_osmux = msc_i->ran_conn->ran_peer->remote_supports_osmux;
1783 }
1784 }
1785
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001786 /* This will lead to either MSC_EV_CALL_LEG_LOCAL_ADDR_AVAILABLE or MSC_EV_CALL_LEG_TERM.
1787 * If the local address is already known, then immediately trigger. */
1788 if (call_leg_local_ip(cl, RTP_TO_RAN))
1789 return osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE, cl->rtp[RTP_TO_RAN]);
Pau Espin Pedrol3a02d292022-01-05 13:56:16 +01001790
1791 if (msc_a->c.ran->type == OSMO_RAT_UTRAN_IU) {
1792 codec = CODEC_IUFP;
1793 codec_ptr = &codec;
1794 } else {
1795 codec_ptr = NULL;
1796 }
1797 return call_leg_ensure_ci(msc_a->cc.call_leg, RTP_TO_RAN, cc_trans->callref, cc_trans, codec_ptr, NULL);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001798}
1799
1800int msc_a_try_call_assignment(struct gsm_trans *cc_trans)
1801{
1802 struct msc_a *msc_a = cc_trans->msc_a;
1803 OSMO_ASSERT(cc_trans->type == TRANS_CC);
1804
1805 if (msc_a->cc.active_trans == cc_trans) {
Neels Hofmeyrb4ef5e72019-08-30 01:11:12 +02001806 LOG_MSC_A(msc_a, LOGL_DEBUG, "Assignment for this trans already started earlier\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001807 return 0;
1808 }
1809
1810 if (msc_a->cc.active_trans) {
1811 LOG_MSC_A(msc_a, LOGL_INFO, "Another call is already ongoing, not assigning yet\n");
1812 return 0;
1813 }
1814
1815 LOG_MSC_A(msc_a, LOGL_DEBUG, "Starting call assignment\n");
1816 return msc_a_start_assignment(msc_a, cc_trans);
1817}
1818
Neels Hofmeyr5d53c602022-04-24 23:37:07 +02001819/* Map CM Service type to use token.
1820 * Given a CM Service type, return a matching token intended for osmo_use_count.
1821 * For unknown service type, return NULL.
1822 */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001823const char *msc_a_cm_service_type_to_use(enum osmo_cm_service_type cm_service_type)
1824{
1825 switch (cm_service_type) {
1826 case GSM48_CMSERV_MO_CALL_PACKET:
1827 case GSM48_CMSERV_EMERGENCY:
1828 return MSC_A_USE_CM_SERVICE_CC;
1829
1830 case GSM48_CMSERV_SMS:
1831 return MSC_A_USE_CM_SERVICE_SMS;
1832
1833 case GSM48_CMSERV_SUP_SERV:
1834 return MSC_A_USE_CM_SERVICE_SS;
1835
1836 default:
1837 return NULL;
1838 }
1839}
1840
1841void msc_a_release_cn(struct msc_a *msc_a)
1842{
1843 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_CN_CLOSE, NULL);
1844}
1845
1846void msc_a_release_mo(struct msc_a *msc_a, enum gsm48_gsm_cause gsm_cause)
1847{
1848 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_MO_CLOSE, NULL);
1849}