blob: 1ea66330ec62ed1873d655bd6cc6453add269036 [file] [log] [blame]
Oliver Smith5375f782023-05-23 13:38:33 +02001/* Filter/overlay codec and CSD bearer service selections for voice calls/CSD,
2 * across MS, RAN and CN limitations
3 *
4 * (C) 2023 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
5 * All Rights Reserved
6 *
7 * Author: Oliver Smith
8 *
9 * SPDX-License-Identifier: AGPL-3.0+
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25#include <osmocom/msc/transaction_cc.h>
Oliver Smithc7c40c92023-05-23 17:43:40 +020026#include <osmocom/msc/codec_filter.h>
Oliver Smith10632132023-05-12 12:14:22 +020027#include <osmocom/msc/csd_filter.h>
Oliver Smith5375f782023-05-23 13:38:33 +020028
Oliver Smitha35abb72023-05-23 17:29:57 +020029void trans_cc_filter_init(struct gsm_trans *trans)
30{
31 trans->cc.codecs = (struct codec_filter){};
Oliver Smith10632132023-05-12 12:14:22 +020032 trans->cc.csd = (struct csd_filter){};
Oliver Smitha35abb72023-05-23 17:29:57 +020033}
34
Oliver Smithc7c40c92023-05-23 17:43:40 +020035void trans_cc_filter_set_ran(struct gsm_trans *trans, enum osmo_rat_type ran_type)
36{
37 codec_filter_set_ran(&trans->cc.codecs, ran_type);
Oliver Smith10632132023-05-12 12:14:22 +020038 csd_filter_set_ran(&trans->cc.csd, ran_type);
Oliver Smithc7c40c92023-05-23 17:43:40 +020039}
40
Oliver Smith1c7f1782023-05-23 17:58:26 +020041void trans_cc_filter_set_bss(struct gsm_trans *trans, struct msc_a *msc_a)
42{
43 codec_filter_set_bss(&trans->cc.codecs, &msc_a->cc.compl_l3_codec_list_bss_supported);
Oliver Smith10632132023-05-12 12:14:22 +020044
45 /* For CSD, there is no list of supported bearer services passed in
46 * Complete Layer 3. TODO: make it configurable? */
Oliver Smith1c7f1782023-05-23 17:58:26 +020047}
48
Oliver Smithceca8e62023-05-24 11:15:52 +020049void trans_cc_filter_run(struct gsm_trans *trans)
50{
Oliver Smith10632132023-05-12 12:14:22 +020051 switch (trans->bearer_cap.transfer) {
52 case GSM48_BCAP_ITCAP_SPEECH:
53 codec_filter_run(&trans->cc.codecs, &trans->cc.local, &trans->cc.remote);
54 LOG_TRANS(trans, LOGL_DEBUG, "codecs: %s\n",
55 codec_filter_to_str(&trans->cc.codecs, &trans->cc.local, &trans->cc.remote));
56 break;
Manawyrm1ed12ea2023-10-14 17:23:04 +020057 case GSM48_BCAP_ITCAP_3k1_AUDIO:
58 case GSM48_BCAP_ITCAP_FAX_G3:
Oliver Smith10632132023-05-12 12:14:22 +020059 case GSM48_BCAP_ITCAP_UNR_DIG_INF:
60 csd_filter_run(&trans->cc.csd, &trans->cc.local, &trans->cc.remote);
61 LOG_TRANS(trans, LOGL_DEBUG, "codec/BS: %s\n",
62 csd_filter_to_str(&trans->cc.csd, &trans->cc.local, &trans->cc.remote));
63 break;
64 default:
65 LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n",
66 trans->bearer_cap.transfer);
67 break;
68 }
Oliver Smithceca8e62023-05-24 11:15:52 +020069}
70
Oliver Smith5375f782023-05-23 13:38:33 +020071void trans_cc_filter_set_ms_from_bc(struct gsm_trans *trans, const struct gsm_mncc_bearer_cap *bcap)
72{
73 trans->cc.codecs.ms = (struct sdp_audio_codecs){0};
Oliver Smith10632132023-05-12 12:14:22 +020074 trans->cc.csd.ms = (struct csd_bs_list){0};
Oliver Smith5375f782023-05-23 13:38:33 +020075
76 if (!bcap)
77 return;
78
79 switch (bcap->transfer) {
80 case GSM48_BCAP_ITCAP_SPEECH:
81 sdp_audio_codecs_from_bearer_cap(&trans->cc.codecs.ms, bcap);
82 break;
Manawyrm1ed12ea2023-10-14 17:23:04 +020083 case GSM48_BCAP_ITCAP_3k1_AUDIO:
84 case GSM48_BCAP_ITCAP_FAX_G3:
Oliver Smith10632132023-05-12 12:14:22 +020085 case GSM48_BCAP_ITCAP_UNR_DIG_INF:
86 sdp_audio_codecs_set_csd(&trans->cc.codecs.ms);
87 csd_bs_list_from_bearer_cap(&trans->cc.csd.ms, bcap);
88 break;
Oliver Smith5375f782023-05-23 13:38:33 +020089 default:
90 LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n",
91 bcap->transfer);
92 break;
93 }
94}
Oliver Smith8a8ce712023-05-31 16:56:52 +020095
96void trans_cc_set_remote_from_bc(struct gsm_trans *trans, const struct gsm_mncc_bearer_cap *bcap)
97{
98 trans->cc.remote.audio_codecs = (struct sdp_audio_codecs){0};
Oliver Smith10632132023-05-12 12:14:22 +020099 trans->cc.remote.bearer_services = (struct csd_bs_list){0};
Oliver Smith8a8ce712023-05-31 16:56:52 +0200100
101 if (!bcap)
102 return;
103
104 switch (bcap->transfer) {
105 case GSM48_BCAP_ITCAP_SPEECH:
106 sdp_audio_codecs_from_bearer_cap(&trans->cc.remote.audio_codecs, bcap);
107 break;
Manawyrm1ed12ea2023-10-14 17:23:04 +0200108 case GSM48_BCAP_ITCAP_3k1_AUDIO:
109 case GSM48_BCAP_ITCAP_FAX_G3:
Oliver Smith10632132023-05-12 12:14:22 +0200110 case GSM48_BCAP_ITCAP_UNR_DIG_INF:
111 sdp_audio_codecs_set_csd(&trans->cc.remote.audio_codecs);
112 csd_bs_list_from_bearer_cap(&trans->cc.remote.bearer_services, bcap);
113 break;
Oliver Smith8a8ce712023-05-31 16:56:52 +0200114 default:
115 LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n",
116 bcap->transfer);
117 break;
118 }
119}