Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 1 | /* 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 Smith | c7c40c9 | 2023-05-23 17:43:40 +0200 | [diff] [blame] | 26 | #include <osmocom/msc/codec_filter.h> |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 27 | #include <osmocom/msc/csd_filter.h> |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 28 | |
Oliver Smith | a35abb7 | 2023-05-23 17:29:57 +0200 | [diff] [blame] | 29 | void trans_cc_filter_init(struct gsm_trans *trans) |
| 30 | { |
| 31 | trans->cc.codecs = (struct codec_filter){}; |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 32 | trans->cc.csd = (struct csd_filter){}; |
Oliver Smith | a35abb7 | 2023-05-23 17:29:57 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Oliver Smith | c7c40c9 | 2023-05-23 17:43:40 +0200 | [diff] [blame] | 35 | void 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 Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 38 | csd_filter_set_ran(&trans->cc.csd, ran_type); |
Oliver Smith | c7c40c9 | 2023-05-23 17:43:40 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Oliver Smith | 1c7f178 | 2023-05-23 17:58:26 +0200 | [diff] [blame] | 41 | void 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 Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 44 | |
| 45 | /* For CSD, there is no list of supported bearer services passed in |
| 46 | * Complete Layer 3. TODO: make it configurable? */ |
Oliver Smith | 1c7f178 | 2023-05-23 17:58:26 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 49 | void trans_cc_filter_run(struct gsm_trans *trans) |
| 50 | { |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 51 | 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; |
| 57 | case GSM48_BCAP_ITCAP_UNR_DIG_INF: |
| 58 | csd_filter_run(&trans->cc.csd, &trans->cc.local, &trans->cc.remote); |
| 59 | LOG_TRANS(trans, LOGL_DEBUG, "codec/BS: %s\n", |
| 60 | csd_filter_to_str(&trans->cc.csd, &trans->cc.local, &trans->cc.remote)); |
| 61 | break; |
| 62 | default: |
| 63 | LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n", |
| 64 | trans->bearer_cap.transfer); |
| 65 | break; |
| 66 | } |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 69 | void trans_cc_filter_set_ms_from_bc(struct gsm_trans *trans, const struct gsm_mncc_bearer_cap *bcap) |
| 70 | { |
| 71 | trans->cc.codecs.ms = (struct sdp_audio_codecs){0}; |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 72 | trans->cc.csd.ms = (struct csd_bs_list){0}; |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 73 | |
| 74 | if (!bcap) |
| 75 | return; |
| 76 | |
| 77 | switch (bcap->transfer) { |
| 78 | case GSM48_BCAP_ITCAP_SPEECH: |
| 79 | sdp_audio_codecs_from_bearer_cap(&trans->cc.codecs.ms, bcap); |
| 80 | break; |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 81 | case GSM48_BCAP_ITCAP_UNR_DIG_INF: |
| 82 | sdp_audio_codecs_set_csd(&trans->cc.codecs.ms); |
| 83 | csd_bs_list_from_bearer_cap(&trans->cc.csd.ms, bcap); |
| 84 | break; |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 85 | default: |
| 86 | LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n", |
| 87 | bcap->transfer); |
| 88 | break; |
| 89 | } |
| 90 | } |
Oliver Smith | 8a8ce71 | 2023-05-31 16:56:52 +0200 | [diff] [blame] | 91 | |
| 92 | void trans_cc_set_remote_from_bc(struct gsm_trans *trans, const struct gsm_mncc_bearer_cap *bcap) |
| 93 | { |
| 94 | trans->cc.remote.audio_codecs = (struct sdp_audio_codecs){0}; |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 95 | trans->cc.remote.bearer_services = (struct csd_bs_list){0}; |
Oliver Smith | 8a8ce71 | 2023-05-31 16:56:52 +0200 | [diff] [blame] | 96 | |
| 97 | if (!bcap) |
| 98 | return; |
| 99 | |
| 100 | switch (bcap->transfer) { |
| 101 | case GSM48_BCAP_ITCAP_SPEECH: |
| 102 | sdp_audio_codecs_from_bearer_cap(&trans->cc.remote.audio_codecs, bcap); |
| 103 | break; |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 104 | case GSM48_BCAP_ITCAP_UNR_DIG_INF: |
| 105 | sdp_audio_codecs_set_csd(&trans->cc.remote.audio_codecs); |
| 106 | csd_bs_list_from_bearer_cap(&trans->cc.remote.bearer_services, bcap); |
| 107 | break; |
Oliver Smith | 8a8ce71 | 2023-05-31 16:56:52 +0200 | [diff] [blame] | 108 | default: |
| 109 | LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n", |
| 110 | bcap->transfer); |
| 111 | break; |
| 112 | } |
| 113 | } |