Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 Call Control */ |
| 2 | |
| 3 | /* (C) 2008-2016 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2008-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <errno.h> |
| 28 | #include <time.h> |
| 29 | #include <netinet/in.h> |
| 30 | #include <regex.h> |
| 31 | #include <sys/types.h> |
| 32 | |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 33 | #include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h> |
| 34 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 35 | #include <osmocom/msc/db.h> |
| 36 | #include <osmocom/msc/debug.h> |
| 37 | #include <osmocom/msc/gsm_data.h> |
| 38 | #include <osmocom/msc/gsm_subscriber.h> |
| 39 | #include <osmocom/msc/gsm_04_11.h> |
| 40 | #include <osmocom/msc/gsm_04_08.h> |
| 41 | #include <osmocom/msc/gsm_04_80.h> |
| 42 | #include <osmocom/msc/gsm_04_14.h> |
| 43 | #include <osmocom/msc/gsm_09_11.h> |
| 44 | #include <osmocom/msc/signal.h> |
| 45 | #include <osmocom/msc/transaction.h> |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 46 | #include <osmocom/msc/transaction_cc.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 47 | #include <osmocom/msc/silent_call.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 48 | #include <osmocom/msc/mncc_int.h> |
| 49 | #include <osmocom/abis/e1_input.h> |
| 50 | #include <osmocom/core/bitvec.h> |
Alexander Couzens | eff28ab | 2024-09-12 00:55:25 +0200 | [diff] [blame^] | 51 | #include <osmocom/vlr/vlr.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 52 | #include <osmocom/msc/msub.h> |
| 53 | #include <osmocom/msc/msc_a.h> |
| 54 | #include <osmocom/msc/paging.h> |
| 55 | #include <osmocom/msc/call_leg.h> |
| 56 | #include <osmocom/msc/rtp_stream.h> |
| 57 | #include <osmocom/msc/mncc_call.h> |
| 58 | #include <osmocom/msc/msc_t.h> |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 59 | #include <osmocom/msc/sdp_msg.h> |
Neels Hofmeyr | a001a70 | 2022-10-31 17:57:30 +0100 | [diff] [blame] | 60 | #include <osmocom/msc/codec_mapping.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 61 | |
| 62 | #include <osmocom/gsm/gsm48.h> |
| 63 | #include <osmocom/gsm/gsm0480.h> |
| 64 | #include <osmocom/gsm/gsm_utils.h> |
| 65 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 66 | #include <osmocom/core/msgb.h> |
| 67 | #include <osmocom/core/talloc.h> |
| 68 | #include <osmocom/core/utils.h> |
| 69 | #include <osmocom/core/byteswap.h> |
| 70 | #include <osmocom/gsm/tlv.h> |
| 71 | #include <osmocom/crypt/auth.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 72 | |
| 73 | #include <assert.h> |
| 74 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 75 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg); |
| 76 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 77 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 78 | |
| 79 | static int trans_tx_gsm48(struct gsm_trans *trans, struct msgb *msg) |
| 80 | { |
| 81 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 82 | gh->proto_discr = GSM48_PDISC_CC | (trans->transaction_id << 4); |
| 83 | OMSC_LINKID_CB(msg) = trans->dlci; |
| 84 | |
| 85 | return msc_a_tx_dtap_to_i(trans->msc_a, msg); |
| 86 | } |
| 87 | |
| 88 | uint32_t msc_cc_next_outgoing_callref() { |
| 89 | static uint32_t last_callref = 0x80000000; |
| 90 | last_callref++; |
| 91 | if (last_callref < 0x80000001) |
| 92 | last_callref = 0x80000001; |
| 93 | return last_callref; |
| 94 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 95 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 96 | static void gsm48_cc_guard_timeout(void *arg) |
| 97 | { |
| 98 | struct gsm_trans *trans = arg; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 99 | LOG_TRANS(trans, LOGL_DEBUG, "guard timeout expired\n"); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 100 | trans_free(trans); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | static void gsm48_stop_guard_timer(struct gsm_trans *trans) |
| 105 | { |
| 106 | if (osmo_timer_pending(&trans->cc.timer_guard)) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 107 | LOG_TRANS(trans, LOGL_DEBUG, "stopping pending guard timer\n"); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 108 | osmo_timer_del(&trans->cc.timer_guard); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static void gsm48_start_guard_timer(struct gsm_trans *trans) |
| 113 | { |
| 114 | /* NOTE: The purpose of this timer is to prevent the cc state machine |
| 115 | * from hanging in cases where mncc, gsm48 or both become unresponsive |
| 116 | * for some reason. The timer is started initially with the setup from |
| 117 | * the gsm48 side and then re-started with every incoming mncc message. |
| 118 | * Once the mncc state reaches its active state the timer is stopped. |
| 119 | * So if the cc state machine does not show any activity for an |
| 120 | * extended amount of time during call setup or teardown the guard |
| 121 | * timer will time out and hard-clear the connection. */ |
| 122 | if (osmo_timer_pending(&trans->cc.timer_guard)) |
| 123 | gsm48_stop_guard_timer(trans); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 124 | LOG_TRANS(trans, LOGL_DEBUG, "starting guard timer with %d seconds\n", trans->net->mncc_guard_timeout); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 125 | osmo_timer_setup(&trans->cc.timer_guard, gsm48_cc_guard_timeout, trans); |
| 126 | osmo_timer_schedule(&trans->cc.timer_guard, |
| 127 | trans->net->mncc_guard_timeout, 0); |
| 128 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 129 | |
| 130 | /* Call Control */ |
| 131 | |
Neels Hofmeyr | e80f556 | 2023-06-28 02:21:15 +0200 | [diff] [blame] | 132 | static void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 133 | { |
| 134 | net->mncc_recv(net, msg); |
| 135 | } |
| 136 | |
| 137 | int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message) |
| 138 | { |
| 139 | struct gsm48_hdr *gh; |
| 140 | struct msgb *ss_notify; |
| 141 | |
| 142 | ss_notify = gsm0480_create_notifySS(message); |
| 143 | if (!ss_notify) |
| 144 | return -1; |
| 145 | |
| 146 | gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0); |
| 147 | uint8_t *data = msgb_push(ss_notify, 1); |
| 148 | data[0] = ss_notify->len - 1; |
| 149 | gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh)); |
| 150 | gh->msg_type = GSM48_MT_CC_FACILITY; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 151 | return trans_tx_gsm48(trans, ss_notify); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* FIXME: this count_statistics is a state machine behaviour. we should convert |
| 155 | * the complete call control into a state machine. Afterwards we can move this |
| 156 | * code into state transitions. |
| 157 | */ |
| 158 | static void count_statistics(struct gsm_trans *trans, int new_state) |
| 159 | { |
| 160 | int old_state = trans->cc.state; |
| 161 | struct rate_ctr_group *msc = trans->net->msc_ctrs; |
| 162 | |
| 163 | if (old_state == new_state) |
| 164 | return; |
| 165 | |
| 166 | /* state incoming */ |
| 167 | switch (new_state) { |
| 168 | case GSM_CSTATE_ACTIVE: |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 169 | osmo_stat_item_inc(osmo_stat_item_group_get_item(trans->net->statg, MSC_STAT_ACTIVE_CALLS), |
| 170 | 1); |
| 171 | rate_ctr_inc(rate_ctr_group_get_ctr(msc, MSC_CTR_CALL_ACTIVE)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 172 | break; |
| 173 | } |
| 174 | |
| 175 | /* state outgoing */ |
| 176 | switch (old_state) { |
| 177 | case GSM_CSTATE_ACTIVE: |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 178 | osmo_stat_item_dec(osmo_stat_item_group_get_item(trans->net->statg, MSC_STAT_ACTIVE_CALLS), |
| 179 | 1); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 180 | if (new_state == GSM_CSTATE_DISCONNECT_REQ || |
| 181 | new_state == GSM_CSTATE_DISCONNECT_IND) |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 182 | rate_ctr_inc(rate_ctr_group_get_ctr(msc, MSC_CTR_CALL_COMPLETE)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 183 | else |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 184 | rate_ctr_inc(rate_ctr_group_get_ctr(msc, MSC_CTR_CALL_INCOMPLETE)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 185 | break; |
| 186 | } |
| 187 | } |
| 188 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 189 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 190 | { |
| 191 | if (state > 31 || state < 0) |
| 192 | return; |
| 193 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 194 | LOG_TRANS(trans, LOGL_DEBUG, "new state %s -> %s\n", |
| 195 | gsm48_cc_state_name(trans->cc.state), |
| 196 | gsm48_cc_state_name(state)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 197 | |
| 198 | count_statistics(trans, state); |
| 199 | trans->cc.state = state; |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 200 | |
| 201 | /* Stop the guard timer when a call reaches the active state */ |
| 202 | if (state == GSM_CSTATE_ACTIVE) |
| 203 | gsm48_stop_guard_timer(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
| 207 | { |
| 208 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STATUS"); |
| 209 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 210 | uint8_t *cause, *call_state; |
| 211 | |
| 212 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 213 | |
| 214 | cause = msgb_put(msg, 3); |
| 215 | cause[0] = 2; |
| 216 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 217 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 218 | |
| 219 | call_state = msgb_put(msg, 1); |
| 220 | call_state[0] = 0xc0 | 0x00; |
| 221 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 222 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 226 | { |
| 227 | if (osmo_timer_pending(&trans->cc.timer)) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 228 | LOG_TRANS(trans, LOGL_DEBUG, "stopping pending timer T%x\n", trans->cc.Tcurrent); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 229 | osmo_timer_del(&trans->cc.timer); |
| 230 | trans->cc.Tcurrent = 0; |
| 231 | } |
| 232 | } |
| 233 | |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 234 | /* Log the MNCC tx and rx events. |
| 235 | * Depending on msg_type, also log whether RTP information is passed on. |
| 236 | * (This is particularly interesting for the doc/sequence_charts/msc_log_to_ladder.py) |
| 237 | */ |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 238 | #define log_mncc_rx_tx(ARGS...) _log_mncc_rx_tx(__FILE__, __LINE__, ##ARGS) |
| 239 | static void _log_mncc_rx_tx(const char *file, int line, |
| 240 | struct gsm_trans *trans, const char *rx_tx, const union mncc_msg *mncc) |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 241 | { |
| 242 | const char *sdp = NULL; |
| 243 | struct sdp_msg sdp_msg = {}; |
| 244 | struct osmo_sockaddr addr = {}; |
| 245 | |
| 246 | if (!log_check_level(DMNCC, LOGL_DEBUG)) |
| 247 | return; |
| 248 | |
| 249 | switch (mncc->msg_type) { |
| 250 | case MNCC_RTP_CREATE: |
| 251 | case MNCC_RTP_CONNECT: |
| 252 | addr = (struct osmo_sockaddr){ .u.sas = mncc->rtp.addr }; |
| 253 | sdp = mncc->rtp.sdp; |
| 254 | break; |
| 255 | |
| 256 | case MNCC_SETUP_IND: |
| 257 | case MNCC_SETUP_REQ: |
| 258 | case MNCC_SETUP_COMPL_IND: |
| 259 | case MNCC_SETUP_COMPL_REQ: |
| 260 | case MNCC_SETUP_RSP: |
| 261 | case MNCC_SETUP_CNF: |
| 262 | case MNCC_CALL_CONF_IND: |
| 263 | case MNCC_CALL_PROC_REQ: |
| 264 | case MNCC_ALERT_IND: |
| 265 | case MNCC_ALERT_REQ: |
| 266 | sdp = mncc->signal.sdp; |
| 267 | break; |
| 268 | |
| 269 | default: |
| 270 | break; |
| 271 | } |
| 272 | |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 273 | if (sdp && sdp[0]) { |
| 274 | int rc = sdp_msg_from_sdp_str(&sdp_msg, sdp); |
| 275 | if (rc != 0) { |
| 276 | LOG_TRANS_CAT_SRC(trans, DMNCC, LOGL_ERROR, file, line, "%s %s: invalid SDP message (trying anyway)\n", |
| 277 | rx_tx, |
| 278 | get_mncc_name(mncc->msg_type)); |
| 279 | LOG_TRANS_CAT_SRC(trans, DMNCC, LOGL_DEBUG, file, line, "erratic SDP: %s\n", |
| 280 | osmo_quote_cstr_c(OTC_SELECT, sdp, -1)); |
| 281 | return; |
| 282 | } |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 283 | LOG_TRANS_CAT_SRC(trans, DMNCC, LOGL_DEBUG, file, line, "%s %s (RTP=%s)\n", |
| 284 | rx_tx, |
| 285 | get_mncc_name(mncc->msg_type), |
| 286 | sdp_msg_to_str(&sdp_msg)); |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 287 | return; |
| 288 | } |
| 289 | |
| 290 | if (osmo_sockaddr_is_any(&addr) == 0) { |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 291 | LOG_TRANS_CAT_SRC(trans, DMNCC, LOGL_DEBUG, file, line, "%s %s (RTP=%s)\n", |
| 292 | rx_tx, |
| 293 | get_mncc_name(mncc->msg_type), |
| 294 | osmo_sockaddr_to_str_c(OTC_SELECT, &addr)); |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 295 | return; |
| 296 | } |
| 297 | |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 298 | LOG_TRANS_CAT_SRC(trans, DMNCC, LOGL_DEBUG, file, line, "%s %s\n", rx_tx, get_mncc_name(mncc->msg_type)); |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Neels Hofmeyr | 1c06507 | 2022-08-07 02:43:15 +0200 | [diff] [blame] | 301 | #define mncc_recvmsg(ARGS...) _mncc_recvmsg(__FILE__, __LINE__, ##ARGS) |
| 302 | static int _mncc_recvmsg(const char *file, int line, |
| 303 | struct gsm_network *net, struct gsm_trans *trans, int msg_type, struct gsm_mncc *mncc) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 304 | { |
| 305 | struct msgb *msg; |
| 306 | unsigned char *data; |
| 307 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 308 | mncc->msg_type = msg_type; |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 309 | log_mncc_rx_tx(trans, "tx", (union mncc_msg *)mncc); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 310 | |
| 311 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
| 312 | if (!msg) |
| 313 | return -ENOMEM; |
| 314 | |
| 315 | data = msgb_put(msg, sizeof(struct gsm_mncc)); |
| 316 | memcpy(data, mncc, sizeof(struct gsm_mncc)); |
| 317 | |
| 318 | cc_tx_to_mncc(net, msg); |
Neels Hofmeyr | cf90bdb | 2019-10-01 19:47:26 +0200 | [diff] [blame] | 319 | /* trans may be NULL when sending an MNCC error reply upon an invalid MNCC request */ |
| 320 | if (trans) |
| 321 | trans->cc.mncc_initiated = true; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, |
| 327 | uint32_t callref, int location, int value) |
| 328 | { |
| 329 | struct gsm_mncc rel; |
| 330 | |
| 331 | memset(&rel, 0, sizeof(rel)); |
| 332 | rel.callref = callref; |
| 333 | mncc_set_cause(&rel, location, value); |
| 334 | if (trans && trans->cc.state == GSM_CSTATE_RELEASE_REQ) |
| 335 | return mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 336 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 337 | } |
| 338 | |
| 339 | /* Call Control Specific transaction release. |
| 340 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 341 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
| 342 | { |
| 343 | gsm48_stop_cc_timer(trans); |
| 344 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 345 | /* send release to L4, if callref still exists */ |
| 346 | if (trans->callref) { |
Vadim Yanitskiy | dd466cf | 2021-02-05 19:17:31 +0100 | [diff] [blame] | 347 | /* Send MNCC REL.ind (cause='Resource unavailable') */ |
| 348 | if (trans->cc.mncc_initiated) { |
| 349 | mncc_release_ind(trans->net, trans, trans->callref, |
| 350 | GSM48_CAUSE_LOC_PRN_S_LU, |
Keith Whyte | ba4d682 | 2022-07-03 04:12:58 +0100 | [diff] [blame] | 351 | (trans->cc.state == GSM_CSTATE_CALL_RECEIVED) ? |
| 352 | GSM48_CC_CAUSE_USER_NOTRESPOND : |
Vadim Yanitskiy | dd466cf | 2021-02-05 19:17:31 +0100 | [diff] [blame] | 353 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 354 | } |
| 355 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 356 | /* FIXME: currently, a CC trans that would not yet be in state GSM_CSTATE_RELEASE_REQ fails to send a |
| 357 | * CC Release to the MS if it gets freed here. Hack it to do so. */ |
| 358 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) { |
| 359 | struct gsm_mncc rel = {}; |
| 360 | rel.callref = trans->callref; |
| 361 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 362 | gsm48_cc_tx_release(trans, &rel); |
| 363 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 364 | /* This is a final freeing of the transaction. The MNCC release may have triggered the |
| 365 | * T308 release timer, but we don't have the luxury of graceful CC Release here. */ |
| 366 | gsm48_stop_cc_timer(trans); |
| 367 | } |
| 368 | if (trans->cc.state != GSM_CSTATE_NULL) |
| 369 | new_cc_state(trans, GSM_CSTATE_NULL); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 370 | |
| 371 | gsm48_stop_guard_timer(trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 372 | |
| 373 | if (trans->msc_a && trans->msc_a->cc.active_trans == trans) |
| 374 | trans->msc_a->cc.active_trans = NULL; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 377 | /* call-back from paging the B-end of the connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 378 | static void cc_paging_cb(struct msc_a *msc_a, struct gsm_trans *trans) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 379 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 380 | if (trans->msc_a) { |
| 381 | LOG_MSC_A_CAT(msc_a, DPAG, LOGL_ERROR, |
| 382 | "Handle paging error: transaction already associated with subscriber," |
| 383 | " apparently it was already handled. Skip.\n"); |
| 384 | return; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 387 | if (msc_a) { |
| 388 | LOG_TRANS(trans, LOGL_DEBUG, "Paging succeeded\n"); |
| 389 | /* Assign conn */ |
| 390 | msc_a_get(msc_a, MSC_A_USE_CC); |
| 391 | trans->msc_a = msc_a; |
| 392 | trans->paging_request = NULL; |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 393 | |
| 394 | /* Get the GCR from the MO call leg (if any). */ |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 395 | if (!trans->cc.lcls) |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 396 | trans->cc.lcls = trans_lcls_compose(trans, true); |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 397 | if (trans->cc.lcls && trans->cc.msg.fields & MNCC_F_GCR) { |
| 398 | int rc = osmo_dec_gcr(&trans->cc.lcls->gcr, |
| 399 | &trans->cc.msg.gcr[0], |
| 400 | sizeof(trans->cc.msg.gcr)); |
| 401 | if (rc < 0) |
| 402 | LOG_TRANS(trans, LOGL_ERROR, "Failed to parse GCR\n"); |
| 403 | else |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 404 | trans->cc.lcls->gcr_available = true; |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 407 | osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans); |
| 408 | /* send SETUP request to called party */ |
| 409 | gsm48_cc_tx_setup(trans, &trans->cc.msg); |
| 410 | } else { |
| 411 | LOG_TRANS(trans, LOGL_DEBUG, "Paging expired\n"); |
| 412 | /* Temporarily out of order */ |
| 413 | mncc_release_ind(trans->net, trans, |
| 414 | trans->callref, |
| 415 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 416 | GSM48_CC_CAUSE_DEST_OOO); |
| 417 | trans->callref = 0; |
| 418 | trans->paging_request = NULL; |
| 419 | trans_free(trans); |
| 420 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* bridge channels of two transactions */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 424 | static int tch_bridge(struct gsm_network *net, const struct gsm_mncc_bridge *bridge) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 425 | { |
Andreas Eversberg | 7e4b032 | 2023-04-23 11:43:13 +0200 | [diff] [blame] | 426 | struct gsm_trans *trans1 = trans_find_by_callref(net, TRANS_CC, bridge->callref[0]); |
| 427 | struct gsm_trans *trans2 = trans_find_by_callref(net, TRANS_CC, bridge->callref[1]); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 428 | struct call_leg *cl1; |
| 429 | struct call_leg *cl2; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 430 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 431 | if (!trans1 || !trans2) { |
| 432 | LOG_TRANS(trans1 ? : trans2, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs are unset\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 433 | return -EIO; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 434 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 435 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 436 | if (!trans1->msc_a || !trans2->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 437 | LOG_TRANS(trans1, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs lack an active connection\n"); |
| 438 | LOG_TRANS(trans2, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs lack an active connection\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 439 | return -EIO; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | LOG_TRANS(trans1, LOGL_DEBUG, "MNCC_BRIDGE: Local bridge to callref 0x%x\n", trans2->callref); |
| 443 | LOG_TRANS(trans2, LOGL_DEBUG, "MNCC_BRIDGE: Local bridge to callref 0x%x\n", trans1->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 444 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 445 | /* This call bridging mechanism is only used with the internal MNCC (with external MNCC briding would be done by |
| 446 | * the PBX). For inter-MSC Handover scenarios, an external MNCC is mandatory. The conclusion is that in this |
| 447 | * code path, there is only one MSC, and the MSC-I role is local, and hence we can directly access the ran_conn. |
| 448 | * If we can't, then we must give up. */ |
| 449 | cl1 = trans1->msc_a->cc.call_leg; |
| 450 | cl2 = trans2->msc_a->cc.call_leg; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 451 | |
Andreas Eversberg | 712b28e | 2023-06-21 11:17:26 +0200 | [diff] [blame] | 452 | return call_leg_local_bridge(cl1, trans1->call_id, trans1, cl2, trans2->call_id, trans2); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 456 | { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 457 | LOG_TRANS(trans, LOGL_DEBUG, "-> STATUS ENQ\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 458 | return gsm48_cc_tx_status(trans, msg); |
| 459 | } |
| 460 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 461 | static void gsm48_cc_timeout(void *arg) |
| 462 | { |
| 463 | struct gsm_trans *trans = arg; |
| 464 | int disconnect = 0, release = 0; |
| 465 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 466 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 467 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 468 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
| 469 | struct gsm_mncc mo_rel, l4_rel; |
| 470 | |
Neels Hofmeyr | e29ee5a | 2022-08-06 14:16:55 +0200 | [diff] [blame] | 471 | LOG_TRANS(trans, LOGL_INFO, "Timeout of T%x\n", trans->cc.Tcurrent); |
| 472 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 473 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 474 | mo_rel.callref = trans->callref; |
| 475 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 476 | l4_rel.callref = trans->callref; |
| 477 | |
| 478 | switch(trans->cc.Tcurrent) { |
| 479 | case 0x303: |
| 480 | release = 1; |
| 481 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
| 482 | break; |
| 483 | case 0x310: |
| 484 | disconnect = 1; |
| 485 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
| 486 | break; |
| 487 | case 0x313: |
| 488 | disconnect = 1; |
| 489 | /* unknown, did not find it in the specs */ |
| 490 | break; |
| 491 | case 0x301: |
| 492 | disconnect = 1; |
| 493 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
| 494 | break; |
| 495 | case 0x308: |
| 496 | if (!trans->cc.T308_second) { |
| 497 | /* restart T308 a second time */ |
| 498 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 499 | trans->cc.T308_second = 1; |
| 500 | break; /* stay in release state */ |
| 501 | } |
| 502 | trans_free(trans); |
| 503 | return; |
| 504 | case 0x306: |
| 505 | release = 1; |
| 506 | mo_cause = trans->cc.msg.cause.value; |
| 507 | mo_location = trans->cc.msg.cause.location; |
| 508 | break; |
| 509 | case 0x323: |
| 510 | disconnect = 1; |
| 511 | break; |
| 512 | default: |
| 513 | release = 1; |
| 514 | } |
| 515 | |
| 516 | if (release && trans->callref) { |
| 517 | /* process release towards layer 4 */ |
| 518 | mncc_release_ind(trans->net, trans, trans->callref, |
| 519 | l4_location, l4_cause); |
| 520 | trans->callref = 0; |
| 521 | } |
| 522 | |
| 523 | if (disconnect && trans->callref) { |
| 524 | /* process disconnect towards layer 4 */ |
| 525 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
| 526 | mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &l4_rel); |
| 527 | } |
| 528 | |
| 529 | /* process disconnect towards mobile station */ |
| 530 | if (disconnect || release) { |
| 531 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
| 532 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 533 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 534 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
| 535 | mo_rel.cause.diag_len = 3; |
| 536 | |
| 537 | if (disconnect) |
| 538 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 539 | if (release) |
| 540 | gsm48_cc_tx_release(trans, &mo_rel); |
| 541 | } |
| 542 | |
| 543 | } |
| 544 | |
| 545 | /* disconnect both calls from the bridge */ |
| 546 | static inline void disconnect_bridge(struct gsm_network *net, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 547 | const struct gsm_mncc_bridge *bridge, int err) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 548 | { |
Andreas Eversberg | 7e4b032 | 2023-04-23 11:43:13 +0200 | [diff] [blame] | 549 | struct gsm_trans *trans0 = trans_find_by_callref(net, TRANS_CC, bridge->callref[0]); |
| 550 | struct gsm_trans *trans1 = trans_find_by_callref(net, TRANS_CC, bridge->callref[1]); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 551 | struct gsm_mncc mx_rel; |
| 552 | if (!trans0 || !trans1) |
| 553 | return; |
| 554 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 555 | LOG_TRANS(trans0, LOGL_ERROR, "Failed to bridge TCH for calls %x <-> %x :: %s \n", |
| 556 | trans0->callref, trans1->callref, strerror(err)); |
| 557 | LOG_TRANS(trans1, LOGL_ERROR, "Failed to bridge TCH for calls %x <-> %x :: %s \n", |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 558 | trans0->callref, trans1->callref, strerror(err)); |
| 559 | |
| 560 | memset(&mx_rel, 0, sizeof(struct gsm_mncc)); |
| 561 | mncc_set_cause(&mx_rel, GSM48_CAUSE_LOC_INN_NET, |
| 562 | GSM48_CC_CAUSE_CHAN_UNACCEPT); |
| 563 | |
| 564 | mx_rel.callref = trans0->callref; |
| 565 | gsm48_cc_tx_disconnect(trans0, &mx_rel); |
| 566 | |
| 567 | mx_rel.callref = trans1->callref; |
| 568 | gsm48_cc_tx_disconnect(trans1, &mx_rel); |
| 569 | } |
| 570 | |
| 571 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 572 | int sec, int micro) |
| 573 | { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 574 | LOG_TRANS(trans, LOGL_DEBUG, "starting timer T%x with %d seconds\n", current, sec); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 575 | osmo_timer_setup(&trans->cc.timer, gsm48_cc_timeout, trans); |
| 576 | osmo_timer_schedule(&trans->cc.timer, sec, micro); |
| 577 | trans->cc.Tcurrent = current; |
| 578 | } |
| 579 | |
| 580 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 581 | { |
| 582 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 583 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
| 584 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 585 | struct tlv_parsed tp; |
| 586 | struct gsm_mncc setup; |
| 587 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 588 | gsm48_start_guard_timer(trans); |
| 589 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 590 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 591 | setup.callref = trans->callref; |
| 592 | |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 593 | /* New Global Call Reference */ |
| 594 | if (!trans->cc.lcls) |
| 595 | trans->cc.lcls = trans_lcls_compose(trans, true); |
| 596 | |
| 597 | /* Pass the LCLS GCR on to the MT call leg via MNCC */ |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 598 | if (trans->cc.lcls) { |
| 599 | struct msgb *gcr_msg = msgb_alloc(sizeof(setup.gcr), "MNCC GCR"); |
| 600 | const struct osmo_gcr_parsed *gcr = &trans->cc.lcls->gcr; |
| 601 | int rc; |
| 602 | |
| 603 | if (gcr_msg != NULL && (rc = osmo_enc_gcr(gcr_msg, gcr)) > 0) { |
| 604 | memcpy(&setup.gcr[0], gcr_msg->data, rc); |
| 605 | setup.fields |= MNCC_F_GCR; |
| 606 | } else |
| 607 | LOG_TRANS(trans, LOGL_ERROR, "Failed to encode GCR\n"); |
| 608 | msgb_free(gcr_msg); |
| 609 | } |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 610 | |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 611 | OSMO_ASSERT(trans->msc_a); |
| 612 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 613 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 614 | /* emergency setup is identified by msg_type */ |
| 615 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) { |
| 616 | setup.fields |= MNCC_F_EMERGENCY; |
| 617 | setup.emergency = 1; |
| 618 | /* use destination number as configured by user (if any) */ |
| 619 | if (trans->net->emergency.route_to_msisdn) { |
| 620 | setup.fields |= MNCC_F_CALLED; |
| 621 | setup.called.type = 0; /* unknown */ |
| 622 | setup.called.plan = 0; /* unknown */ |
| 623 | OSMO_STRLCPY_ARRAY(setup.called.number, |
| 624 | trans->net->emergency.route_to_msisdn); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | /* use subscriber as calling party number */ |
| 629 | setup.fields |= MNCC_F_CALLING; |
| 630 | OSMO_STRLCPY_ARRAY(setup.calling.number, trans->vsub->msisdn); |
| 631 | OSMO_STRLCPY_ARRAY(setup.imsi, trans->vsub->imsi); |
| 632 | |
| 633 | /* bearer capability */ |
| 634 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 635 | setup.fields |= MNCC_F_BEARER_CAP; |
| 636 | gsm48_decode_bearer_cap(&setup.bearer_cap, |
| 637 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 638 | |
| 639 | /* Create a copy of the bearer capability |
| 640 | * in the transaction struct, so we can use |
| 641 | * this information later */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 642 | memcpy(&trans->bearer_cap, &setup.bearer_cap, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 643 | sizeof(trans->bearer_cap)); |
| 644 | } |
| 645 | /* facility */ |
| 646 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 647 | setup.fields |= MNCC_F_FACILITY; |
| 648 | gsm48_decode_facility(&setup.facility, |
| 649 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 650 | } |
| 651 | /* called party bcd number */ |
| 652 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 653 | setup.fields |= MNCC_F_CALLED; |
| 654 | gsm48_decode_called(&setup.called, |
| 655 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 656 | } |
Andreas Eversberg | 79e7b7d | 2023-12-19 12:56:44 +0100 | [diff] [blame] | 657 | /* low layer compatibility */ |
| 658 | if (TLVP_PRESENT(&tp, GSM48_IE_LOWL_COMPAT) && TLVP_LEN(&tp, GSM48_IE_LOWL_COMPAT) > 0 && |
| 659 | TLVP_LEN(&tp, GSM48_IE_LOWL_COMPAT) <= sizeof(setup.llc.compat)) { |
| 660 | setup.fields |= MNCC_F_LOWL_COMPAT; |
| 661 | setup.llc.len = TLVP_LEN(&tp, GSM48_IE_LOWL_COMPAT); |
| 662 | memcpy(setup.llc.compat, TLVP_VAL(&tp, GSM48_IE_LOWL_COMPAT), setup.llc.len); |
| 663 | } |
| 664 | /* high layer compatibility */ |
| 665 | if (TLVP_PRESENT(&tp, GSM48_IE_HIGHL_COMPAT) && TLVP_LEN(&tp, GSM48_IE_HIGHL_COMPAT) > 0 && |
| 666 | TLVP_LEN(&tp, GSM48_IE_HIGHL_COMPAT) <= sizeof(setup.hlc.compat)) { |
| 667 | setup.fields |= MNCC_F_HIGHL_COMPAT; |
| 668 | setup.hlc.len = TLVP_LEN(&tp, GSM48_IE_HIGHL_COMPAT); |
| 669 | memcpy(setup.hlc.compat, TLVP_VAL(&tp, GSM48_IE_HIGHL_COMPAT), setup.hlc.len); |
| 670 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 671 | /* user-user */ |
| 672 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 673 | setup.fields |= MNCC_F_USERUSER; |
| 674 | gsm48_decode_useruser(&setup.useruser, |
| 675 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 676 | } |
| 677 | /* ss-version */ |
| 678 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 679 | setup.fields |= MNCC_F_SSVERSION; |
| 680 | gsm48_decode_ssversion(&setup.ssversion, |
| 681 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 682 | } |
| 683 | /* CLIR suppression */ |
| 684 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 685 | setup.clir.sup = 1; |
| 686 | /* CLIR invocation */ |
| 687 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 688 | setup.clir.inv = 1; |
| 689 | /* cc cap */ |
| 690 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 691 | setup.fields |= MNCC_F_CCCAP; |
| 692 | gsm48_decode_cccap(&setup.cccap, |
| 693 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 694 | } |
| 695 | |
Neels Hofmeyr | f555952 | 2022-01-13 21:39:11 +0100 | [diff] [blame] | 696 | /* MO call leg starting, gather all codec information so far known: */ |
Oliver Smith | a35abb7 | 2023-05-23 17:29:57 +0200 | [diff] [blame] | 697 | trans_cc_filter_init(trans); |
Oliver Smith | c7c40c9 | 2023-05-23 17:43:40 +0200 | [diff] [blame] | 698 | trans_cc_filter_set_ran(trans, trans->msc_a->c.ran->type); |
Oliver Smith | 1c7f178 | 2023-05-23 17:58:26 +0200 | [diff] [blame] | 699 | trans_cc_filter_set_bss(trans, trans->msc_a); |
Neels Hofmeyr | f555952 | 2022-01-13 21:39:11 +0100 | [diff] [blame] | 700 | if (setup.fields & MNCC_F_BEARER_CAP) |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 701 | trans_cc_filter_set_ms_from_bc(trans, &trans->bearer_cap); |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 702 | trans_cc_filter_run(trans); |
Neels Hofmeyr | f555952 | 2022-01-13 21:39:11 +0100 | [diff] [blame] | 703 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 704 | LOG_TRANS(trans, setup.emergency ? LOGL_NOTICE : LOGL_INFO, "%sSETUP to %s\n", |
| 705 | setup.emergency ? "EMERGENCY_" : "", setup.called.number); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 706 | |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 707 | rate_ctr_inc(rate_ctr_group_get_ctr(trans->net->msc_ctrs, MSC_CTR_CALL_MO_SETUP)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 708 | |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 709 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 710 | |
| 711 | /* To complete the MNCC_SETUP_IND, we need to provide an RTP address and port. First instruct the MGW to create |
| 712 | * a CN-side RTP conn, and continue with MNCC_SETUP_IND once that is done. Leave trans.cc in GSM_CSTATE_NULL and |
| 713 | * note down the msg_type to indicate that we indeed composed an MNCC_SETUP_IND for later. */ |
| 714 | setup.msg_type = MNCC_SETUP_IND; |
| 715 | trans->cc.msg = setup; |
| 716 | return msc_a_try_call_assignment(trans); |
| 717 | /* continue in gsm48_cc_rx_setup_cn_local_rtp_port_known() */ |
| 718 | } |
| 719 | |
| 720 | /* Callback for MNCC_SETUP_IND waiting for the core network RTP port to be established by the MGW (via msc_a) */ |
| 721 | void gsm48_cc_rx_setup_cn_local_rtp_port_known(struct gsm_trans *trans) |
| 722 | { |
| 723 | struct msc_a *msc_a = trans->msc_a; |
| 724 | struct gsm_mncc setup = trans->cc.msg; |
| 725 | struct osmo_sockaddr_str *rtp_cn_local; |
| 726 | struct sdp_msg *sdp; |
| 727 | int rc; |
| 728 | |
| 729 | if (trans->cc.state != GSM_CSTATE_INITIATED |
| 730 | || setup.msg_type != MNCC_SETUP_IND) { |
| 731 | LOG_TRANS(trans, LOGL_ERROR, |
| 732 | "Unexpected CC state. Expected GSM_CSTATE_INITIATED and a buffered MNCC_SETUP_IND message," |
| 733 | " found CC state %d and msg_type %s\n", |
| 734 | trans->cc.state, get_mncc_name(setup.msg_type)); |
| 735 | trans->callref = 0; |
| 736 | trans_free(trans); |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | if (!msc_a) { |
| 741 | LOG_TRANS(trans, LOGL_ERROR, "No connection for CC trans\n"); |
| 742 | trans->callref = 0; |
| 743 | trans_free(trans); |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | /* 'setup' above has taken the value of trans->cc.msg, we can now clear that. */ |
| 748 | trans->cc.msg = (struct gsm_mncc){}; |
| 749 | |
| 750 | /* Insert the CN side RTP port now available into SDP and compose SDP string */ |
| 751 | rtp_cn_local = call_leg_local_ip(msc_a->cc.call_leg, RTP_TO_CN); |
| 752 | if (!osmo_sockaddr_str_is_nonzero(rtp_cn_local)) { |
| 753 | LOG_TRANS(trans, LOGL_ERROR, "Cannot compose SDP for MNCC_SETUP_IND: no RTP set up for the CN side\n"); |
| 754 | trans_free(trans); |
| 755 | return; |
| 756 | } |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 757 | trans->cc.local.rtp = *rtp_cn_local; |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 758 | |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 759 | sdp = trans->cc.local.audio_codecs.count ? &trans->cc.local : NULL; |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 760 | rc = sdp_msg_to_sdp_str_buf(setup.sdp, sizeof(setup.sdp), sdp); |
| 761 | if (rc >= sizeof(setup.sdp)) { |
| 762 | LOG_TRANS(trans, LOGL_ERROR, "MNCC_SETUP_IND: SDP too long (%d > %zu bytes)\n", rc, sizeof(setup.sdp)); |
| 763 | trans_free(trans); |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 764 | return; |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 765 | } |
| 766 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 767 | /* indicate setup to MNCC */ |
| 768 | mncc_recvmsg(trans->net, trans, MNCC_SETUP_IND, &setup); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 769 | } |
| 770 | |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 771 | static void rx_mncc_sdp(struct gsm_trans *trans, uint32_t mncc_msg_type, const char *sdp, |
| 772 | const struct gsm_mncc_bearer_cap *bcap) |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 773 | { |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 774 | struct codec_filter *codecs = &trans->cc.codecs; |
Neels Hofmeyr | 22d4f35 | 2024-06-21 19:08:34 +0200 | [diff] [blame] | 775 | struct msc_a *msc_a = trans->msc_a; |
| 776 | struct call_leg *cl = msc_a ? msc_a->cc.call_leg : NULL; |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 777 | struct rtp_stream *rtp_cn = cl ? cl->rtp[RTP_TO_CN] : NULL; |
| 778 | |
| 779 | if (sdp[0]) { |
| 780 | int rc = sdp_msg_from_sdp_str(&trans->cc.remote, sdp); |
| 781 | if (rc) |
| 782 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "rx %s: Failed to parse SDP: %d. Trying anyway.\n", |
| 783 | get_mncc_name(mncc_msg_type), rc); |
| 784 | } |
| 785 | |
| 786 | /* if there is no SDP information or we failed to parse it, try using the Bearer Cap from MNCC, if any. */ |
| 787 | if (!trans->cc.remote.audio_codecs.count && bcap) { |
| 788 | trans->cc.remote = (struct sdp_msg){}; |
| 789 | trans_cc_set_remote_from_bc(trans, bcap); |
| 790 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s Bearer Cap: remote=%s\n", |
| 791 | get_mncc_name(mncc_msg_type), sdp_msg_to_str(&trans->cc.remote)); |
| 792 | } |
| 793 | |
| 794 | if (!trans->cc.remote.audio_codecs.count) |
| 795 | LOG_TRANS(trans, LOGL_INFO, |
| 796 | "Got no information of remote audio codecs: neither SDP nor Bearer Capability. Trying anyway.\n"); |
| 797 | |
| 798 | trans_cc_filter_run(trans); |
| 799 | if (rtp_cn) { |
| 800 | rtp_stream_set_remote_addr_and_codecs(rtp_cn, &trans->cc.remote); |
| 801 | rtp_stream_commit(rtp_cn); |
| 802 | } |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 803 | |
| 804 | /* See if we need to switch codecs to maintain TFO: has the remote side changed the codecs information? If we |
| 805 | * have already assigned a specific codec here, but the remote call leg has now chosen a different codec, we |
| 806 | * need to re-assign this call leg to match the remote leg. */ |
| 807 | if (!sdp_audio_codec_is_set(&codecs->assignment)) { |
| 808 | /* Voice channel assignment has not completed. Do not interfere. */ |
| 809 | return; |
| 810 | } |
| 811 | if (!trans->cc.remote.audio_codecs.count) { |
| 812 | /* Don't know remote codecs, nothing to do. */ |
| 813 | return; |
| 814 | } |
| 815 | if (sdp_audio_codecs_by_descr(&trans->cc.remote.audio_codecs, &codecs->assignment)) { |
| 816 | /* The assigned codec is part of the remote codec set. All is well. */ |
| 817 | /* TODO: maybe this should require exactly the *first* remote codec to match, because we cannot flexibly |
| 818 | * transcode, and assume the actual payload we will receive is listed in the first place? */ |
| 819 | return; |
| 820 | } |
| 821 | |
Neels Hofmeyr | 22d4f35 | 2024-06-21 19:08:34 +0200 | [diff] [blame] | 822 | if (msc_a && osmo_timer_pending(&msc_a->cc.assignment_request_pending)) { |
| 823 | /* Still waiting for an Assignment Response. |
| 824 | * For example, when the remote call leg sends some MNCC with SDP with a mismatching codec, |
| 825 | * we start Re-Assignment to match that codec: we send an Assignment Request and wait for a response. |
| 826 | * When we receive another MNCC with SDP from the remote call leg before this Re-Assignment is |
| 827 | * completed, we must not trigger *another* Assignment Request, but instead wait for the Re-Assignment |
| 828 | * to come back with a response first. */ |
| 829 | return; |
| 830 | } |
| 831 | |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 832 | /* We've already completed Assignment of a voice channel (some time ago), and now the remote side has changed |
| 833 | * to a mismatching codec (list). Try to re-assign this side to a matching codec. */ |
| 834 | LOG_TRANS(trans, LOGL_INFO, "Remote call leg mismatches assigned codec: %s\n", |
| 835 | codec_filter_to_str(&trans->cc.codecs, &trans->cc.local, &trans->cc.remote)); |
| 836 | msc_a_tx_assignment_cmd(trans->msc_a); |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 839 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
| 840 | { |
Neels Hofmeyr | 3551d84 | 2022-01-13 19:35:12 +0100 | [diff] [blame] | 841 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC SETUP"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 842 | struct gsm48_hdr *gh; |
| 843 | struct gsm_mncc *setup = arg; |
| 844 | int rc, trans_id; |
Neels Hofmeyr | 909ea52 | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 845 | struct gsm_mncc_bearer_cap bearer_cap; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 846 | |
| 847 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 848 | |
| 849 | /* transaction id must not be assigned */ |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 850 | if (trans->transaction_id != TRANS_ID_UNASSIGNED) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 851 | LOG_TRANS(trans, LOGL_DEBUG, "TX Setup with assigned transaction. " |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 852 | "This is not allowed!\n"); |
| 853 | /* Temporarily out of order */ |
| 854 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
| 855 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 856 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 857 | trans->callref = 0; |
| 858 | trans_free(trans); |
Neels Hofmeyr | 61ae18c | 2019-08-28 03:41:05 +0200 | [diff] [blame] | 859 | msgb_free(msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 860 | return rc; |
| 861 | } |
| 862 | |
| 863 | /* Get free transaction_id */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 864 | trans_id = trans_assign_trans_id(trans->net, trans->vsub, TRANS_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 865 | if (trans_id < 0) { |
| 866 | /* no free transaction ID */ |
| 867 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
| 868 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 869 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 870 | trans->callref = 0; |
| 871 | trans_free(trans); |
Neels Hofmeyr | 61ae18c | 2019-08-28 03:41:05 +0200 | [diff] [blame] | 872 | msgb_free(msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 873 | return rc; |
| 874 | } |
| 875 | trans->transaction_id = trans_id; |
| 876 | |
| 877 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 878 | |
| 879 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
| 880 | |
Neels Hofmeyr | 7ddc48c | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 881 | /* MT call leg is starting. Gather all codecs information so far known. |
| 882 | * (Usually) paging has succeeded, and now we're processing the MNCC Setup from the remote MO call leg. |
| 883 | * Initialize the codecs filter with this side's BSS' codec list, received at Complete Layer 3. |
Oliver Smith | e545b9d | 2023-06-15 14:17:12 +0200 | [diff] [blame] | 884 | * We haven't received the MT MS's Bearer Capabilities yet; the Bearer Capabilities handled here are |
| 885 | * actually the remote call leg's Bearer Capabilities. */ |
Oliver Smith | a35abb7 | 2023-05-23 17:29:57 +0200 | [diff] [blame] | 886 | trans_cc_filter_init(trans); |
Oliver Smith | c7c40c9 | 2023-05-23 17:43:40 +0200 | [diff] [blame] | 887 | trans_cc_filter_set_ran(trans, trans->msc_a->c.ran->type); |
Oliver Smith | 1c7f178 | 2023-05-23 17:58:26 +0200 | [diff] [blame] | 888 | trans_cc_filter_set_bss(trans, trans->msc_a); |
Oliver Smith | 64f3930 | 2023-06-15 14:26:37 +0200 | [diff] [blame] | 889 | if (setup->fields & MNCC_F_BEARER_CAP) |
| 890 | trans->bearer_cap.transfer = setup->bearer_cap.transfer; |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 891 | |
| 892 | switch (trans->bearer_cap.transfer) { |
| 893 | case GSM48_BCAP_ITCAP_SPEECH: |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 894 | /* if SDP is included in the MNCC, take that as definitive list of remote audio codecs. */ |
| 895 | rx_mncc_sdp(trans, setup->msg_type, setup->sdp, |
| 896 | (setup->fields & MNCC_F_BEARER_CAP) ? &setup->bearer_cap : NULL); |
| 897 | /* rx_mncc_sdp() has called trans_cc_filter_run(trans); */ |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 898 | break; |
Manawyrm | 1ed12ea | 2023-10-14 17:23:04 +0200 | [diff] [blame] | 899 | case GSM48_BCAP_ITCAP_3k1_AUDIO: |
| 900 | case GSM48_BCAP_ITCAP_FAX_G3: |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 901 | case GSM48_BCAP_ITCAP_UNR_DIG_INF: |
Oliver Smith | 412cf92 | 2023-07-05 15:47:04 +0200 | [diff] [blame] | 902 | if (setup->fields & MNCC_F_BEARER_CAP) { |
| 903 | trans->cc.remote = (struct sdp_msg){}; |
| 904 | trans_cc_set_remote_from_bc(trans, &setup->bearer_cap); |
| 905 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s Bearer Cap: remote=%s\n", |
| 906 | get_mncc_name(setup->msg_type), sdp_msg_to_str(&trans->cc.remote)); |
| 907 | } else { |
| 908 | LOG_TRANS(trans, LOGL_INFO, |
| 909 | "Got no information of remote Bearer Capability. Trying anyway.\n"); |
| 910 | sdp_audio_codecs_set_csd(&trans->cc.codecs.ms); |
| 911 | } |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 912 | trans_cc_filter_run(trans); |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 913 | break; |
| 914 | default: |
| 915 | LOG_TRANS(trans, LOGL_ERROR, "Handling of information transfer capability %d not implemented\n", |
| 916 | trans->bearer_cap.transfer); |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 917 | break; |
Neels Hofmeyr | af9d30e | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 918 | } |
Neels Hofmeyr | af9d30e | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 919 | |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 920 | /* Compose Bearer Capability information that reflects only the codecs (Speech Versions) / CSD bearer services |
| 921 | * remaining after intersecting MS, BSS and remote call leg restrictions. To store in trans for later use, and |
| 922 | * to include in the outgoing CC Setup message. */ |
| 923 | switch (trans->bearer_cap.transfer) { |
| 924 | case GSM48_BCAP_ITCAP_SPEECH: |
| 925 | bearer_cap = (struct gsm_mncc_bearer_cap){ |
| 926 | .speech_ver = { -1 }, |
| 927 | }; |
| 928 | sdp_audio_codecs_to_bearer_cap(&bearer_cap, &trans->cc.local.audio_codecs); |
| 929 | rc = bearer_cap_set_radio(&bearer_cap); |
| 930 | if (rc) { |
| 931 | LOG_TRANS(trans, LOGL_ERROR, "Error composing Bearer Capability for CC Setup\n"); |
| 932 | trans_free(trans); |
| 933 | msgb_free(msg); |
| 934 | return rc; |
| 935 | } |
| 936 | /* If no resulting codecs remain, error out. We cannot find a codec that matches both call legs. If the MGW were |
| 937 | * able to transcode, we could use non-identical codecs on each conn of the MGW endpoint, but we are aiming for |
| 938 | * finding a matching codec. */ |
| 939 | if (bearer_cap.speech_ver[0] == -1) { |
| 940 | LOG_TRANS(trans, LOGL_ERROR, "%s: no codec match possible: %s\n", |
| 941 | get_mncc_name(setup->msg_type), |
| 942 | codec_filter_to_str(&trans->cc.codecs, &trans->cc.local, &trans->cc.remote)); |
| 943 | |
| 944 | /* incompatible codecs */ |
| 945 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
| 946 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 947 | GSM48_CC_CAUSE_INCOMPAT_DEST /* TODO: correct cause code? */); |
| 948 | trans->callref = 0; |
| 949 | trans_free(trans); |
| 950 | msgb_free(msg); |
| 951 | return rc; |
| 952 | } |
Andreas Eversberg | a980c57 | 2024-09-18 13:27:44 +0200 | [diff] [blame] | 953 | rc = bearer_cap_filter_rev_lev(&bearer_cap, trans->vsub->classmark.classmark1.rev_lev); |
| 954 | if (rc) { |
| 955 | LOG_TRANS(trans, LOGL_ERROR, "No codec offered is supported by phase 1 mobile.\n"); |
| 956 | trans_free(trans); |
| 957 | msgb_free(msg); |
| 958 | return rc; |
| 959 | } |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 960 | break; |
Manawyrm | 1ed12ea | 2023-10-14 17:23:04 +0200 | [diff] [blame] | 961 | case GSM48_BCAP_ITCAP_3k1_AUDIO: |
| 962 | case GSM48_BCAP_ITCAP_FAX_G3: |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 963 | case GSM48_BCAP_ITCAP_UNR_DIG_INF: |
| 964 | if (csd_bs_list_to_bearer_cap(&bearer_cap, &trans->cc.local.bearer_services) == 0) { |
| 965 | LOG_TRANS(trans, LOGL_ERROR, "Error composing Bearer Capability for CC Setup\n"); |
| 966 | |
| 967 | /* incompatible codecs */ |
| 968 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
| 969 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 970 | GSM48_CC_CAUSE_INCOMPAT_DEST /* TODO: correct cause code? */); |
| 971 | trans->callref = 0; |
| 972 | trans_free(trans); |
| 973 | msgb_free(msg); |
| 974 | return rc; |
| 975 | } |
| 976 | break; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 977 | } |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 978 | |
Neels Hofmeyr | 909ea52 | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 979 | /* Create a copy of the bearer capability in the transaction struct, so we can use this information later */ |
Neels Hofmeyr | 909ea52 | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 980 | trans->bearer_cap = bearer_cap; |
Neels Hofmeyr | 909ea52 | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 981 | |
Neels Hofmeyr | 909ea52 | 2022-01-13 21:40:58 +0100 | [diff] [blame] | 982 | gsm48_encode_bearer_cap(msg, 0, &bearer_cap); |
| 983 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 984 | /* facility */ |
| 985 | if (setup->fields & MNCC_F_FACILITY) |
| 986 | gsm48_encode_facility(msg, 0, &setup->facility); |
| 987 | /* progress */ |
| 988 | if (setup->fields & MNCC_F_PROGRESS) |
| 989 | gsm48_encode_progress(msg, 0, &setup->progress); |
| 990 | /* calling party BCD number */ |
| 991 | if (setup->fields & MNCC_F_CALLING) |
| 992 | gsm48_encode_calling(msg, &setup->calling); |
| 993 | /* called party BCD number */ |
| 994 | if (setup->fields & MNCC_F_CALLED) |
| 995 | gsm48_encode_called(msg, &setup->called); |
Andreas Eversberg | 79e7b7d | 2023-12-19 12:56:44 +0100 | [diff] [blame] | 996 | /* low layer compatibility */ |
| 997 | if (setup->fields & MNCC_F_LOWL_COMPAT && setup->llc.len > 0 && setup->llc.len <= sizeof(setup->llc.compat)) |
| 998 | msgb_tlv_put(msg, GSM48_IE_LOWL_COMPAT, setup->llc.len, setup->llc.compat); |
| 999 | /* high layer compatibility */ |
| 1000 | if (setup->fields & MNCC_F_HIGHL_COMPAT && setup->hlc.len > 0 && setup->hlc.len <= sizeof(setup->hlc.compat)) |
| 1001 | msgb_tlv_put(msg, GSM48_IE_HIGHL_COMPAT, setup->hlc.len, setup->hlc.compat); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1002 | /* user-user */ |
| 1003 | if (setup->fields & MNCC_F_USERUSER) |
| 1004 | gsm48_encode_useruser(msg, 0, &setup->useruser); |
| 1005 | /* redirecting party BCD number */ |
| 1006 | if (setup->fields & MNCC_F_REDIRECTING) |
| 1007 | gsm48_encode_redirecting(msg, &setup->redirecting); |
| 1008 | /* signal */ |
| 1009 | if (setup->fields & MNCC_F_SIGNAL) |
| 1010 | gsm48_encode_signal(msg, setup->signal); |
| 1011 | |
| 1012 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
| 1013 | |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 1014 | rate_ctr_inc(rate_ctr_group_get_ctr(trans->net->msc_ctrs, MSC_CTR_CALL_MT_SETUP)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1015 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1016 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 1020 | { |
| 1021 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1022 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1023 | struct tlv_parsed tp; |
| 1024 | struct gsm_mncc call_conf; |
| 1025 | int rc; |
| 1026 | |
| 1027 | gsm48_stop_cc_timer(trans); |
| 1028 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 1029 | |
| 1030 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 1031 | call_conf.callref = trans->callref; |
| 1032 | |
| 1033 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1034 | #if 0 |
| 1035 | /* repeat */ |
| 1036 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 1037 | call_conf.repeat = 1; |
| 1038 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 1039 | call_conf.repeat = 2; |
| 1040 | #endif |
| 1041 | /* bearer capability */ |
| 1042 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1043 | call_conf.fields |= MNCC_F_BEARER_CAP; |
| 1044 | gsm48_decode_bearer_cap(&call_conf.bearer_cap, |
| 1045 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1046 | |
| 1047 | /* Create a copy of the bearer capability |
| 1048 | * in the transaction struct, so we can use |
| 1049 | * this information later */ |
Neels Hofmeyr | a9e383f | 2022-01-13 19:58:05 +0100 | [diff] [blame] | 1050 | memcpy(&trans->bearer_cap, &call_conf.bearer_cap, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1051 | sizeof(trans->bearer_cap)); |
Neels Hofmeyr | 10357f8 | 2022-01-13 19:59:02 +0100 | [diff] [blame] | 1052 | |
| 1053 | /* This is the MT call leg's Call Conf, containing the MS Bearer Capabilities of the MT MS. |
| 1054 | * Store in codecs filter. */ |
Oliver Smith | 5375f78 | 2023-05-23 13:38:33 +0200 | [diff] [blame] | 1055 | trans_cc_filter_set_ms_from_bc(trans, &call_conf.bearer_cap); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1056 | } |
Neels Hofmeyr | a9e383f | 2022-01-13 19:58:05 +0100 | [diff] [blame] | 1057 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1058 | /* cause */ |
| 1059 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1060 | call_conf.fields |= MNCC_F_CAUSE; |
| 1061 | gsm48_decode_cause(&call_conf.cause, |
| 1062 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1063 | } |
| 1064 | /* cc cap */ |
| 1065 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 1066 | call_conf.fields |= MNCC_F_CCCAP; |
| 1067 | gsm48_decode_cccap(&call_conf.cccap, |
| 1068 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 1069 | } |
| 1070 | |
| 1071 | /* IMSI of called subscriber */ |
| 1072 | OSMO_STRLCPY_ARRAY(call_conf.imsi, trans->vsub->imsi); |
| 1073 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1074 | /* Assign call (if not done yet) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1075 | rc = msc_a_try_call_assignment(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1076 | |
| 1077 | /* don't continue, if there were problems with |
| 1078 | * the call assignment. */ |
| 1079 | if (rc) |
| 1080 | return rc; |
| 1081 | |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 1082 | /* Directly ack with MNCC_CALL_CONF_IND, not yet containing SDP or RTP IP:port information. */ |
| 1083 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 1084 | return mncc_recvmsg(trans->net, trans, MNCC_CALL_CONF_IND, &call_conf); |
| 1085 | } |
| 1086 | |
| 1087 | static int mncc_recv_rtp(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, |
| 1088 | int cmd, struct osmo_sockaddr_str *rtp_addr, uint32_t payload_type, |
| 1089 | uint32_t payload_msg_type, const struct sdp_msg *sdp); |
| 1090 | |
| 1091 | static int gsm48_cc_mt_rtp_port_and_codec_known(struct gsm_trans *trans) |
| 1092 | { |
| 1093 | struct msc_a *msc_a = trans->msc_a; |
| 1094 | struct osmo_sockaddr_str *rtp_cn_local; |
| 1095 | struct gsm_mncc_rtp; |
| 1096 | |
| 1097 | if (!msc_a) { |
| 1098 | LOG_TRANS(trans, LOGL_ERROR, "No connection for CC trans\n"); |
| 1099 | trans->callref = 0; |
| 1100 | trans_free(trans); |
| 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | |
| 1104 | /* Insert the CN side RTP port now available into SDP */ |
| 1105 | rtp_cn_local = call_leg_local_ip(msc_a->cc.call_leg, RTP_TO_CN); |
| 1106 | if (!rtp_cn_local) { |
| 1107 | LOG_TRANS(trans, LOGL_ERROR, "Cannot compose SDP for MNCC_RTP_CREATE: no RTP set up for the CN side\n"); |
| 1108 | trans_free(trans); |
| 1109 | return -EINVAL; |
| 1110 | } |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 1111 | trans->cc.local.rtp = *rtp_cn_local; |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 1112 | |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 1113 | trans_cc_filter_run(trans); |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 1114 | |
| 1115 | /* If we haven't completed Assignment yet, don't sent MNCC_RTP_CREATE */ |
| 1116 | if (!sdp_audio_codec_is_set(&trans->cc.codecs.assignment)) { |
| 1117 | LOG_TRANS(trans, LOGL_DEBUG, "no codec confirmed by Assignment yet\n"); |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | return mncc_recv_rtp(msc_a_net(msc_a), trans, trans->callref, MNCC_RTP_CREATE, rtp_cn_local, 0, 0, |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 1122 | &trans->cc.local); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | static int gsm48_cc_tx_call_proc_and_assign(struct gsm_trans *trans, void *arg) |
| 1126 | { |
| 1127 | struct gsm_mncc *proceeding = arg; |
| 1128 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROC"); |
| 1129 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1130 | int rc; |
| 1131 | |
| 1132 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 1133 | |
| 1134 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 1135 | |
| 1136 | /* bearer capability */ |
| 1137 | if (proceeding->fields & MNCC_F_BEARER_CAP) { |
Oliver Smith | 92caa1c | 2023-08-23 14:26:23 +0200 | [diff] [blame] | 1138 | /* MNCC should not switch from e.g. CSD to speech */ |
| 1139 | if (proceeding->bearer_cap.transfer != trans->bearer_cap.transfer) { |
| 1140 | LOG_TRANS(trans, LOGL_ERROR, "Unexpected Information Transfer Capability %d from MNCC," |
| 1141 | " transaction has %d\n", |
| 1142 | proceeding->bearer_cap.transfer, |
| 1143 | trans->bearer_cap.transfer); |
| 1144 | return -EINVAL; |
| 1145 | } |
Andreas Eversberg | a980c57 | 2024-09-18 13:27:44 +0200 | [diff] [blame] | 1146 | bearer_cap_filter_rev_lev(&proceeding->bearer_cap, trans->vsub->classmark.classmark1.rev_lev); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1147 | gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
| 1148 | memcpy(&trans->bearer_cap, &proceeding->bearer_cap, sizeof(trans->bearer_cap)); |
| 1149 | } |
| 1150 | /* facility */ |
| 1151 | if (proceeding->fields & MNCC_F_FACILITY) |
| 1152 | gsm48_encode_facility(msg, 0, &proceeding->facility); |
| 1153 | /* progress */ |
| 1154 | if (proceeding->fields & MNCC_F_PROGRESS) |
| 1155 | gsm48_encode_progress(msg, 0, &proceeding->progress); |
| 1156 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1157 | rc = trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1158 | if (rc) |
| 1159 | return rc; |
| 1160 | |
| 1161 | /* Assign call (if not done yet) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1162 | return msc_a_try_call_assignment(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 1166 | { |
| 1167 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1168 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1169 | struct tlv_parsed tp; |
| 1170 | struct gsm_mncc alerting; |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 1171 | int rc; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1172 | |
| 1173 | gsm48_stop_cc_timer(trans); |
| 1174 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 1175 | |
| 1176 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 1177 | alerting.callref = trans->callref; |
| 1178 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1179 | /* facility */ |
| 1180 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1181 | alerting.fields |= MNCC_F_FACILITY; |
| 1182 | gsm48_decode_facility(&alerting.facility, |
| 1183 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1184 | } |
| 1185 | |
| 1186 | /* progress */ |
| 1187 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 1188 | alerting.fields |= MNCC_F_PROGRESS; |
| 1189 | gsm48_decode_progress(&alerting.progress, |
| 1190 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 1191 | } |
| 1192 | /* ss-version */ |
| 1193 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1194 | alerting.fields |= MNCC_F_SSVERSION; |
| 1195 | gsm48_decode_ssversion(&alerting.ssversion, |
| 1196 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1197 | } |
| 1198 | |
| 1199 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 1200 | |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 1201 | trans_cc_filter_run(trans); |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 1202 | rc = sdp_msg_to_sdp_str_buf(alerting.sdp, sizeof(alerting.sdp), &trans->cc.local); |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 1203 | if (rc >= sizeof(alerting.sdp)) { |
| 1204 | LOG_TRANS(trans, LOGL_ERROR, "MNCC_ALERT_IND: SDP too long (%d > %zu bytes)\n", |
| 1205 | rc, sizeof(alerting.sdp)); |
| 1206 | trans_free(trans); |
| 1207 | return -EINVAL; |
| 1208 | } |
| 1209 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1210 | return mncc_recvmsg(trans->net, trans, MNCC_ALERT_IND, |
| 1211 | &alerting); |
| 1212 | } |
| 1213 | |
| 1214 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 1215 | { |
| 1216 | struct gsm_mncc *alerting = arg; |
| 1217 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC ALERT"); |
| 1218 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Oliver Smith | 8e16e8b | 2023-06-22 11:27:24 +0200 | [diff] [blame] | 1219 | int rc; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1220 | |
| 1221 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 1222 | |
| 1223 | /* facility */ |
| 1224 | if (alerting->fields & MNCC_F_FACILITY) |
| 1225 | gsm48_encode_facility(msg, 0, &alerting->facility); |
| 1226 | /* progress */ |
| 1227 | if (alerting->fields & MNCC_F_PROGRESS) |
| 1228 | gsm48_encode_progress(msg, 0, &alerting->progress); |
| 1229 | /* user-user */ |
| 1230 | if (alerting->fields & MNCC_F_USERUSER) |
| 1231 | gsm48_encode_useruser(msg, 0, &alerting->useruser); |
| 1232 | |
| 1233 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
| 1234 | |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 1235 | if (alerting->sdp[0]) |
| 1236 | rx_mncc_sdp(trans, alerting->msg_type, alerting->sdp, |
| 1237 | (alerting->fields & MNCC_F_BEARER_CAP) ? &alerting->bearer_cap : NULL); |
Oliver Smith | 8e16e8b | 2023-06-22 11:27:24 +0200 | [diff] [blame] | 1238 | |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 1239 | /* handle the MNCC event */ |
| 1240 | rc = trans_tx_gsm48(trans, msg); |
| 1241 | return rc; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 1245 | { |
| 1246 | struct gsm_mncc *progress = arg; |
| 1247 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROGRESS"); |
| 1248 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1249 | |
| 1250 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 1251 | |
| 1252 | /* progress */ |
| 1253 | gsm48_encode_progress(msg, 1, &progress->progress); |
| 1254 | /* user-user */ |
| 1255 | if (progress->fields & MNCC_F_USERUSER) |
| 1256 | gsm48_encode_useruser(msg, 0, &progress->useruser); |
| 1257 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1258 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 1262 | { |
| 1263 | struct gsm_mncc *connect = arg; |
| 1264 | struct msgb *msg = gsm48_msgb_alloc_name("GSN 04.08 CC CON"); |
| 1265 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1266 | |
| 1267 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 1268 | |
| 1269 | gsm48_stop_cc_timer(trans); |
| 1270 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 1271 | |
| 1272 | /* facility */ |
| 1273 | if (connect->fields & MNCC_F_FACILITY) |
| 1274 | gsm48_encode_facility(msg, 0, &connect->facility); |
| 1275 | /* progress */ |
| 1276 | if (connect->fields & MNCC_F_PROGRESS) |
| 1277 | gsm48_encode_progress(msg, 0, &connect->progress); |
| 1278 | /* connected number */ |
| 1279 | if (connect->fields & MNCC_F_CONNECTED) |
| 1280 | gsm48_encode_connected(msg, &connect->connected); |
| 1281 | /* user-user */ |
| 1282 | if (connect->fields & MNCC_F_USERUSER) |
| 1283 | gsm48_encode_useruser(msg, 0, &connect->useruser); |
| 1284 | |
| 1285 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 1286 | |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 1287 | if (connect->sdp[0]) |
| 1288 | rx_mncc_sdp(trans, connect->msg_type, connect->sdp, |
| 1289 | (connect->fields & MNCC_F_BEARER_CAP) ? &connect->bearer_cap : NULL); |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 1290 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1291 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 1295 | { |
| 1296 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1297 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1298 | struct tlv_parsed tp; |
| 1299 | struct gsm_mncc connect; |
| 1300 | |
| 1301 | gsm48_stop_cc_timer(trans); |
| 1302 | |
| 1303 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 1304 | connect.callref = trans->callref; |
| 1305 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1306 | /* use subscriber as connected party number */ |
| 1307 | connect.fields |= MNCC_F_CONNECTED; |
| 1308 | OSMO_STRLCPY_ARRAY(connect.connected.number, trans->vsub->msisdn); |
| 1309 | OSMO_STRLCPY_ARRAY(connect.imsi, trans->vsub->imsi); |
| 1310 | |
| 1311 | /* facility */ |
| 1312 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1313 | connect.fields |= MNCC_F_FACILITY; |
| 1314 | gsm48_decode_facility(&connect.facility, |
| 1315 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1316 | } |
| 1317 | /* user-user */ |
| 1318 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1319 | connect.fields |= MNCC_F_USERUSER; |
| 1320 | gsm48_decode_useruser(&connect.useruser, |
| 1321 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1322 | } |
| 1323 | /* ss-version */ |
| 1324 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1325 | connect.fields |= MNCC_F_SSVERSION; |
| 1326 | gsm48_decode_ssversion(&connect.ssversion, |
| 1327 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1328 | } |
| 1329 | |
| 1330 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 1331 | rate_ctr_inc(rate_ctr_group_get_ctr(trans->net->msc_ctrs, MSC_CTR_CALL_MT_CONNECT)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1332 | |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 1333 | trans_cc_filter_run(trans); |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 1334 | sdp_msg_to_sdp_str_buf(connect.sdp, sizeof(connect.sdp), &trans->cc.local); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1335 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_CNF, &connect); |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 1340 | { |
| 1341 | struct gsm_mncc connect_ack; |
| 1342 | |
| 1343 | gsm48_stop_cc_timer(trans); |
| 1344 | |
| 1345 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 1346 | rate_ctr_inc(rate_ctr_group_get_ctr(trans->net->msc_ctrs, MSC_CTR_CALL_MO_CONNECT_ACK)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1347 | |
| 1348 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 1349 | connect_ack.callref = trans->callref; |
| 1350 | |
| 1351 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_COMPL_IND, |
| 1352 | &connect_ack); |
| 1353 | } |
| 1354 | |
| 1355 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 1356 | { |
| 1357 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC CON ACK"); |
| 1358 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1359 | |
| 1360 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 1361 | |
| 1362 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1363 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1364 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 1368 | { |
| 1369 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1370 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1371 | struct tlv_parsed tp; |
| 1372 | struct gsm_mncc disc; |
| 1373 | |
| 1374 | gsm48_stop_cc_timer(trans); |
| 1375 | |
| 1376 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 1377 | |
| 1378 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 1379 | disc.callref = trans->callref; |
| 1380 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0); |
| 1381 | /* cause */ |
| 1382 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1383 | disc.fields |= MNCC_F_CAUSE; |
| 1384 | gsm48_decode_cause(&disc.cause, |
| 1385 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1386 | } |
| 1387 | /* facility */ |
| 1388 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1389 | disc.fields |= MNCC_F_FACILITY; |
| 1390 | gsm48_decode_facility(&disc.facility, |
| 1391 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1392 | } |
| 1393 | /* user-user */ |
| 1394 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1395 | disc.fields |= MNCC_F_USERUSER; |
| 1396 | gsm48_decode_useruser(&disc.useruser, |
| 1397 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1398 | } |
| 1399 | /* ss-version */ |
| 1400 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1401 | disc.fields |= MNCC_F_SSVERSION; |
| 1402 | gsm48_decode_ssversion(&disc.ssversion, |
| 1403 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1404 | } |
| 1405 | |
| 1406 | return mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | static struct gsm_mncc_cause default_cause = { |
| 1410 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 1411 | .coding = 0, |
| 1412 | .rec = 0, |
| 1413 | .rec_val = 0, |
| 1414 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 1415 | .diag_len = 0, |
| 1416 | .diag = { 0 }, |
| 1417 | }; |
| 1418 | |
| 1419 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 1420 | { |
| 1421 | struct gsm_mncc *disc = arg; |
| 1422 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC DISC"); |
| 1423 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1424 | |
| 1425 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 1426 | |
| 1427 | gsm48_stop_cc_timer(trans); |
| 1428 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 1429 | |
| 1430 | /* cause */ |
| 1431 | if (disc->fields & MNCC_F_CAUSE) |
| 1432 | gsm48_encode_cause(msg, 1, &disc->cause); |
| 1433 | else |
| 1434 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1435 | |
| 1436 | /* facility */ |
| 1437 | if (disc->fields & MNCC_F_FACILITY) |
| 1438 | gsm48_encode_facility(msg, 0, &disc->facility); |
| 1439 | /* progress */ |
| 1440 | if (disc->fields & MNCC_F_PROGRESS) |
| 1441 | gsm48_encode_progress(msg, 0, &disc->progress); |
| 1442 | /* user-user */ |
| 1443 | if (disc->fields & MNCC_F_USERUSER) |
| 1444 | gsm48_encode_useruser(msg, 0, &disc->useruser); |
| 1445 | |
| 1446 | /* store disconnect cause for T306 expiry */ |
| 1447 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
| 1448 | |
| 1449 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 1450 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1451 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 1455 | { |
| 1456 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1457 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1458 | struct tlv_parsed tp; |
| 1459 | struct gsm_mncc rel; |
| 1460 | int rc; |
| 1461 | |
| 1462 | gsm48_stop_cc_timer(trans); |
| 1463 | |
| 1464 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 1465 | rel.callref = trans->callref; |
| 1466 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1467 | /* cause */ |
| 1468 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1469 | rel.fields |= MNCC_F_CAUSE; |
| 1470 | gsm48_decode_cause(&rel.cause, |
| 1471 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1472 | } |
| 1473 | /* facility */ |
| 1474 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1475 | rel.fields |= MNCC_F_FACILITY; |
| 1476 | gsm48_decode_facility(&rel.facility, |
| 1477 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1478 | } |
| 1479 | /* user-user */ |
| 1480 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1481 | rel.fields |= MNCC_F_USERUSER; |
| 1482 | gsm48_decode_useruser(&rel.useruser, |
| 1483 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1484 | } |
| 1485 | /* ss-version */ |
| 1486 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1487 | rel.fields |= MNCC_F_SSVERSION; |
| 1488 | gsm48_decode_ssversion(&rel.ssversion, |
| 1489 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1490 | } |
| 1491 | |
| 1492 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
| 1493 | /* release collision 5.4.5 */ |
| 1494 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_CNF, &rel); |
| 1495 | } else { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1496 | rc = gsm48_tx_simple(trans->msc_a, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1497 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
| 1498 | GSM48_MT_CC_RELEASE_COMPL); |
| 1499 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_IND, &rel); |
| 1500 | } |
| 1501 | |
| 1502 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 1503 | |
| 1504 | trans->callref = 0; |
| 1505 | trans_free(trans); |
| 1506 | |
| 1507 | return rc; |
| 1508 | } |
| 1509 | |
| 1510 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 1511 | { |
| 1512 | struct gsm_mncc *rel = arg; |
Neels Hofmeyr | 2e8f881 | 2019-08-21 16:56:41 +0200 | [diff] [blame] | 1513 | struct msgb *msg; |
| 1514 | struct gsm48_hdr *gh; |
| 1515 | |
| 1516 | if (!trans->msc_a) { |
| 1517 | LOG_TRANS(trans, LOGL_DEBUG, "Cannot send CC REL, there is no MSC-A connection\n"); |
| 1518 | return -EINVAL; |
| 1519 | } |
| 1520 | |
| 1521 | msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL"); |
| 1522 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1523 | |
| 1524 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 1525 | |
| 1526 | gsm48_stop_cc_timer(trans); |
| 1527 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 1528 | |
| 1529 | /* cause */ |
| 1530 | if (rel->fields & MNCC_F_CAUSE) |
| 1531 | gsm48_encode_cause(msg, 0, &rel->cause); |
| 1532 | /* facility */ |
| 1533 | if (rel->fields & MNCC_F_FACILITY) |
| 1534 | gsm48_encode_facility(msg, 0, &rel->facility); |
| 1535 | /* user-user */ |
| 1536 | if (rel->fields & MNCC_F_USERUSER) |
| 1537 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
| 1538 | |
| 1539 | trans->cc.T308_second = 0; |
| 1540 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
| 1541 | |
| 1542 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
| 1543 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 1544 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1545 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 1549 | { |
| 1550 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1551 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1552 | struct tlv_parsed tp; |
| 1553 | struct gsm_mncc rel; |
| 1554 | int rc = 0; |
| 1555 | |
| 1556 | gsm48_stop_cc_timer(trans); |
| 1557 | |
| 1558 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 1559 | rel.callref = trans->callref; |
| 1560 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1561 | /* cause */ |
| 1562 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1563 | rel.fields |= MNCC_F_CAUSE; |
| 1564 | gsm48_decode_cause(&rel.cause, |
| 1565 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1566 | } |
| 1567 | /* facility */ |
| 1568 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1569 | rel.fields |= MNCC_F_FACILITY; |
| 1570 | gsm48_decode_facility(&rel.facility, |
| 1571 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1572 | } |
| 1573 | /* user-user */ |
| 1574 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1575 | rel.fields |= MNCC_F_USERUSER; |
| 1576 | gsm48_decode_useruser(&rel.useruser, |
| 1577 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1578 | } |
| 1579 | /* ss-version */ |
| 1580 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1581 | rel.fields |= MNCC_F_SSVERSION; |
| 1582 | gsm48_decode_ssversion(&rel.ssversion, |
| 1583 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1584 | } |
| 1585 | |
| 1586 | if (trans->callref) { |
| 1587 | switch (trans->cc.state) { |
| 1588 | case GSM_CSTATE_CALL_PRESENT: |
| 1589 | rc = mncc_recvmsg(trans->net, trans, |
| 1590 | MNCC_REJ_IND, &rel); |
| 1591 | break; |
| 1592 | case GSM_CSTATE_RELEASE_REQ: |
| 1593 | rc = mncc_recvmsg(trans->net, trans, |
| 1594 | MNCC_REL_CNF, &rel); |
| 1595 | break; |
| 1596 | default: |
| 1597 | rc = mncc_recvmsg(trans->net, trans, |
| 1598 | MNCC_REL_IND, &rel); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | trans->callref = 0; |
| 1603 | trans_free(trans); |
| 1604 | |
| 1605 | return rc; |
| 1606 | } |
| 1607 | |
| 1608 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 1609 | { |
| 1610 | struct gsm_mncc *rel = arg; |
| 1611 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL COMPL"); |
| 1612 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1613 | int ret; |
| 1614 | |
| 1615 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 1616 | |
| 1617 | trans->callref = 0; |
| 1618 | |
| 1619 | gsm48_stop_cc_timer(trans); |
| 1620 | |
| 1621 | /* cause */ |
| 1622 | if (rel->fields & MNCC_F_CAUSE) |
| 1623 | gsm48_encode_cause(msg, 0, &rel->cause); |
| 1624 | /* facility */ |
| 1625 | if (rel->fields & MNCC_F_FACILITY) |
| 1626 | gsm48_encode_facility(msg, 0, &rel->facility); |
| 1627 | /* user-user */ |
| 1628 | if (rel->fields & MNCC_F_USERUSER) |
| 1629 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
| 1630 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1631 | ret = trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1632 | |
| 1633 | trans_free(trans); |
| 1634 | |
| 1635 | return ret; |
| 1636 | } |
| 1637 | |
| 1638 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 1639 | { |
| 1640 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1641 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1642 | struct tlv_parsed tp; |
| 1643 | struct gsm_mncc fac; |
| 1644 | |
| 1645 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 1646 | fac.callref = trans->callref; |
| 1647 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0); |
| 1648 | /* facility */ |
| 1649 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1650 | fac.fields |= MNCC_F_FACILITY; |
| 1651 | gsm48_decode_facility(&fac.facility, |
| 1652 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1653 | } |
| 1654 | /* ss-version */ |
| 1655 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1656 | fac.fields |= MNCC_F_SSVERSION; |
| 1657 | gsm48_decode_ssversion(&fac.ssversion, |
| 1658 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1659 | } |
| 1660 | |
| 1661 | return mncc_recvmsg(trans->net, trans, MNCC_FACILITY_IND, &fac); |
| 1662 | } |
| 1663 | |
| 1664 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 1665 | { |
| 1666 | struct gsm_mncc *fac = arg; |
| 1667 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC FAC"); |
| 1668 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1669 | |
| 1670 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 1671 | |
| 1672 | /* facility */ |
| 1673 | gsm48_encode_facility(msg, 1, &fac->facility); |
| 1674 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1675 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 1679 | { |
| 1680 | struct gsm_mncc hold; |
| 1681 | |
| 1682 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 1683 | hold.callref = trans->callref; |
| 1684 | return mncc_recvmsg(trans->net, trans, MNCC_HOLD_IND, &hold); |
| 1685 | } |
| 1686 | |
| 1687 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 1688 | { |
| 1689 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD ACK"); |
| 1690 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1691 | |
| 1692 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 1693 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1694 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 1698 | { |
| 1699 | struct gsm_mncc *hold_rej = arg; |
| 1700 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD REJ"); |
| 1701 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1702 | |
| 1703 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 1704 | |
| 1705 | /* cause */ |
| 1706 | if (hold_rej->fields & MNCC_F_CAUSE) |
| 1707 | gsm48_encode_cause(msg, 1, &hold_rej->cause); |
| 1708 | else |
| 1709 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1710 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1711 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 1715 | { |
| 1716 | struct gsm_mncc retrieve; |
| 1717 | |
| 1718 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 1719 | retrieve.callref = trans->callref; |
| 1720 | return mncc_recvmsg(trans->net, trans, MNCC_RETRIEVE_IND, |
| 1721 | &retrieve); |
| 1722 | } |
| 1723 | |
| 1724 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 1725 | { |
| 1726 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR ACK"); |
| 1727 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1728 | |
| 1729 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 1730 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1731 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 1735 | { |
| 1736 | struct gsm_mncc *retrieve_rej = arg; |
| 1737 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR REJ"); |
| 1738 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1739 | |
| 1740 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 1741 | |
| 1742 | /* cause */ |
| 1743 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
| 1744 | gsm48_encode_cause(msg, 1, &retrieve_rej->cause); |
| 1745 | else |
| 1746 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1747 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1748 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 1752 | { |
| 1753 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1754 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1755 | struct tlv_parsed tp; |
| 1756 | struct gsm_mncc dtmf; |
| 1757 | |
| 1758 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 1759 | dtmf.callref = trans->callref; |
| 1760 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1761 | /* keypad facility */ |
| 1762 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 1763 | dtmf.fields |= MNCC_F_KEYPAD; |
| 1764 | gsm48_decode_keypad(&dtmf.keypad, |
| 1765 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 1766 | } |
| 1767 | |
| 1768 | return mncc_recvmsg(trans->net, trans, MNCC_START_DTMF_IND, &dtmf); |
| 1769 | } |
| 1770 | |
| 1771 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 1772 | { |
| 1773 | struct gsm_mncc *dtmf = arg; |
| 1774 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF ACK"); |
| 1775 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1776 | |
| 1777 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 1778 | |
| 1779 | /* keypad */ |
| 1780 | if (dtmf->fields & MNCC_F_KEYPAD) |
| 1781 | gsm48_encode_keypad(msg, dtmf->keypad); |
| 1782 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1783 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 1787 | { |
| 1788 | struct gsm_mncc *dtmf = arg; |
| 1789 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF REJ"); |
| 1790 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1791 | |
| 1792 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 1793 | |
| 1794 | /* cause */ |
| 1795 | if (dtmf->fields & MNCC_F_CAUSE) |
| 1796 | gsm48_encode_cause(msg, 1, &dtmf->cause); |
| 1797 | else |
| 1798 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1799 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1800 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 1804 | { |
| 1805 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF STP ACK"); |
| 1806 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1807 | |
| 1808 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 1809 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1810 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 1814 | { |
| 1815 | struct gsm_mncc dtmf; |
| 1816 | |
| 1817 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 1818 | dtmf.callref = trans->callref; |
| 1819 | |
| 1820 | return mncc_recvmsg(trans->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
| 1821 | } |
| 1822 | |
| 1823 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 1824 | { |
| 1825 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1826 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1827 | struct tlv_parsed tp; |
| 1828 | struct gsm_mncc modify; |
| 1829 | |
| 1830 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 1831 | modify.callref = trans->callref; |
| 1832 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 1833 | /* bearer capability */ |
| 1834 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1835 | modify.fields |= MNCC_F_BEARER_CAP; |
| 1836 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
| 1837 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1838 | |
| 1839 | /* Create a copy of the bearer capability |
| 1840 | * in the transaction struct, so we can use |
| 1841 | * this information later */ |
| 1842 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 1843 | sizeof(trans->bearer_cap)); |
| 1844 | } |
| 1845 | |
| 1846 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 1847 | |
| 1848 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_IND, &modify); |
| 1849 | } |
| 1850 | |
| 1851 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 1852 | { |
| 1853 | struct gsm_mncc *modify = arg; |
| 1854 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD"); |
| 1855 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1856 | |
| 1857 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 1858 | |
| 1859 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 1860 | |
| 1861 | /* bearer capability */ |
Andreas Eversberg | a980c57 | 2024-09-18 13:27:44 +0200 | [diff] [blame] | 1862 | bearer_cap_filter_rev_lev(&modify->bearer_cap, trans->vsub->classmark.classmark1.rev_lev); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1863 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 1864 | memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap)); |
| 1865 | |
| 1866 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 1867 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1868 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 1872 | { |
| 1873 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1874 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1875 | struct tlv_parsed tp; |
| 1876 | struct gsm_mncc modify; |
| 1877 | |
| 1878 | gsm48_stop_cc_timer(trans); |
| 1879 | |
| 1880 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 1881 | modify.callref = trans->callref; |
| 1882 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 1883 | /* bearer capability */ |
| 1884 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1885 | modify.fields |= MNCC_F_BEARER_CAP; |
| 1886 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
| 1887 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1888 | |
| 1889 | /* Create a copy of the bearer capability |
| 1890 | * in the transaction struct, so we can use |
| 1891 | * this information later */ |
| 1892 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 1893 | sizeof(trans->bearer_cap)); |
| 1894 | } |
| 1895 | |
| 1896 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1897 | |
| 1898 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_CNF, &modify); |
| 1899 | } |
| 1900 | |
| 1901 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 1902 | { |
| 1903 | struct gsm_mncc *modify = arg; |
| 1904 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD COMPL"); |
| 1905 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1906 | |
| 1907 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 1908 | |
| 1909 | /* bearer capability */ |
Andreas Eversberg | a980c57 | 2024-09-18 13:27:44 +0200 | [diff] [blame] | 1910 | bearer_cap_filter_rev_lev(&modify->bearer_cap, trans->vsub->classmark.classmark1.rev_lev); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1911 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 1912 | memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap)); |
| 1913 | |
| 1914 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1915 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1916 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 1920 | { |
| 1921 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1922 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1923 | struct tlv_parsed tp; |
| 1924 | struct gsm_mncc modify; |
| 1925 | |
| 1926 | gsm48_stop_cc_timer(trans); |
| 1927 | |
| 1928 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 1929 | modify.callref = trans->callref; |
| 1930 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE); |
| 1931 | /* bearer capability */ |
| 1932 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1933 | modify.fields |= GSM48_IE_BEARER_CAP; |
| 1934 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
| 1935 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1936 | |
| 1937 | /* Create a copy of the bearer capability |
| 1938 | * in the transaction struct, so we can use |
| 1939 | * this information later */ |
| 1940 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 1941 | sizeof(trans->bearer_cap)); |
| 1942 | } |
| 1943 | /* cause */ |
| 1944 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1945 | modify.fields |= MNCC_F_CAUSE; |
| 1946 | gsm48_decode_cause(&modify.cause, |
| 1947 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1948 | } |
| 1949 | |
| 1950 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1951 | |
| 1952 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_REJ, &modify); |
| 1953 | } |
| 1954 | |
| 1955 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 1956 | { |
| 1957 | struct gsm_mncc *modify = arg; |
| 1958 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD REJ"); |
| 1959 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1960 | |
| 1961 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 1962 | |
| 1963 | /* bearer capability */ |
Andreas Eversberg | a980c57 | 2024-09-18 13:27:44 +0200 | [diff] [blame] | 1964 | bearer_cap_filter_rev_lev(&modify->bearer_cap, trans->vsub->classmark.classmark1.rev_lev); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1965 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 1966 | memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap)); |
| 1967 | /* cause */ |
| 1968 | gsm48_encode_cause(msg, 1, &modify->cause); |
| 1969 | |
| 1970 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1971 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1972 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 1976 | { |
| 1977 | struct gsm_mncc *notify = arg; |
| 1978 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC NOT"); |
| 1979 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1980 | |
| 1981 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 1982 | |
| 1983 | /* notify */ |
| 1984 | gsm48_encode_notify(msg, notify->notify); |
| 1985 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1986 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 1990 | { |
| 1991 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1992 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1993 | // struct tlv_parsed tp; |
| 1994 | struct gsm_mncc notify; |
| 1995 | |
| 1996 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 1997 | notify.callref = trans->callref; |
| 1998 | // tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len); |
| 1999 | if (payload_len >= 1) |
| 2000 | gsm48_decode_notify(¬ify.notify, gh->data); |
| 2001 | |
| 2002 | return mncc_recvmsg(trans->net, trans, MNCC_NOTIFY_IND, ¬ify); |
| 2003 | } |
| 2004 | |
| 2005 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 2006 | { |
| 2007 | struct gsm_mncc *user = arg; |
| 2008 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USR INFO"); |
| 2009 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2010 | |
| 2011 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 2012 | |
| 2013 | /* user-user */ |
| 2014 | if (user->fields & MNCC_F_USERUSER) |
| 2015 | gsm48_encode_useruser(msg, 1, &user->useruser); |
| 2016 | /* more data */ |
| 2017 | if (user->more) |
| 2018 | gsm48_encode_more(msg); |
| 2019 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2020 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 2024 | { |
| 2025 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2026 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2027 | struct tlv_parsed tp; |
| 2028 | struct gsm_mncc user; |
| 2029 | |
| 2030 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 2031 | user.callref = trans->callref; |
| 2032 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0); |
| 2033 | /* user-user */ |
| 2034 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2035 | user.fields |= MNCC_F_USERUSER; |
| 2036 | gsm48_decode_useruser(&user.useruser, |
| 2037 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2038 | } |
| 2039 | /* more data */ |
| 2040 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 2041 | user.more = 1; |
| 2042 | |
| 2043 | return mncc_recvmsg(trans->net, trans, MNCC_USERINFO_IND, &user); |
| 2044 | } |
| 2045 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2046 | static int mncc_recv_rtp(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, |
| 2047 | int cmd, struct osmo_sockaddr_str *rtp_addr, uint32_t payload_type, |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 2048 | uint32_t payload_msg_type, const struct sdp_msg *sdp) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2049 | { |
| 2050 | uint8_t data[sizeof(struct gsm_mncc)]; |
| 2051 | struct gsm_mncc_rtp *rtp; |
| 2052 | |
| 2053 | memset(&data, 0, sizeof(data)); |
| 2054 | rtp = (struct gsm_mncc_rtp *) &data[0]; |
| 2055 | |
| 2056 | rtp->callref = callref; |
| 2057 | rtp->msg_type = cmd; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2058 | if (rtp_addr) { |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 2059 | if (osmo_sockaddr_str_to_sockaddr(rtp_addr, &rtp->addr) < 0) |
| 2060 | return -EINVAL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2061 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2062 | rtp->payload_type = payload_type; |
| 2063 | rtp->payload_msg_type = payload_msg_type; |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 2064 | if (sdp) |
| 2065 | sdp_msg_to_sdp_str_buf(rtp->sdp, sizeof(rtp->sdp), sdp); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2066 | return mncc_recvmsg(net, trans, cmd, (struct gsm_mncc *)data); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2067 | } |
| 2068 | |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 2069 | static void mncc_recv_rtp_err(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, int cmd) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2070 | { |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 2071 | mncc_recv_rtp(net, trans, callref, cmd, NULL, 0, 0, NULL); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2074 | static int tch_rtp_create(struct gsm_network *net, const struct gsm_mncc_rtp *rtp) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2075 | { |
| 2076 | struct gsm_trans *trans; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2077 | |
| 2078 | /* Find callref */ |
Andreas Eversberg | 7e4b032 | 2023-04-23 11:43:13 +0200 | [diff] [blame] | 2079 | trans = trans_find_by_callref(net, TRANS_CC, rtp->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2080 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2081 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP create for non-existing trans\n"); |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2082 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CREATE); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2083 | return -EIO; |
| 2084 | } |
| 2085 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2086 | if (!trans->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2087 | LOG_TRANS_CAT(trans, DMNCC, LOGL_NOTICE, "RTP create for trans without conn\n"); |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2088 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CREATE); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2089 | return 0; |
| 2090 | } |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2091 | log_mncc_rx_tx(trans, "rx", (const union mncc_msg *)rtp); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2092 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2093 | /* Assign call (if not done yet) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2094 | return msc_a_try_call_assignment(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2095 | } |
| 2096 | |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 2097 | int cc_on_cn_local_rtp_port_known(struct gsm_trans *cc_trans) |
| 2098 | { |
| 2099 | /* Depending on MO or MT call, dispatch the event differently */ |
| 2100 | switch (cc_trans->cc.state) { |
| 2101 | case GSM_CSTATE_INITIATED: |
| 2102 | if (cc_trans->cc.msg.msg_type != MNCC_SETUP_IND) { |
| 2103 | LOG_TRANS(cc_trans, LOGL_ERROR, "Assuming MO call, expected MNCC_SETUP_IND to be prepared\n"); |
| 2104 | return -EINVAL; |
| 2105 | } |
| 2106 | /* This is the MO call leg, waiting for a CN RTP be able to send initial MNCC_SETUP_IND. */ |
| 2107 | gsm48_cc_rx_setup_cn_local_rtp_port_known(cc_trans); |
| 2108 | return 0; |
| 2109 | |
| 2110 | case GSM_CSTATE_MO_TERM_CALL_CONF: |
| 2111 | /* This is the MT call leg, waiting for a CN RTP to be able to send MNCC_CALL_CONF_IND. */ |
| 2112 | return gsm48_cc_mt_rtp_port_and_codec_known(cc_trans); |
| 2113 | |
| 2114 | default: |
| 2115 | LOG_TRANS(cc_trans, LOGL_ERROR, "CN RTP address available, but in unexpected state %d\n", |
| 2116 | cc_trans->cc.state); |
| 2117 | return -EINVAL; |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | int cc_on_assignment_done(struct gsm_trans *trans) |
| 2122 | { |
| 2123 | struct msc_a *msc_a = trans->msc_a; |
| 2124 | |
| 2125 | switch (trans->cc.state) { |
| 2126 | case GSM_CSTATE_INITIATED: |
| 2127 | case GSM_CSTATE_MO_CALL_PROC: |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 2128 | /* MO call, send ACK in form of an MNCC_RTP_CREATE (below) */ |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 2129 | break; |
| 2130 | |
| 2131 | case GSM_CSTATE_CALL_RECEIVED: |
| 2132 | case GSM_CSTATE_MO_TERM_CALL_CONF: |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 2133 | /* MT call, send ACK in form of an MNCC_RTP_CREATE (below) */ |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 2134 | break; |
| 2135 | |
| 2136 | case GSM_CSTATE_ACTIVE: |
Neels Hofmeyr | d767c73 | 2023-11-17 04:12:29 +0100 | [diff] [blame] | 2137 | /* already active. We decided to re-assign later on during the call - at time of writing this never |
| 2138 | * happens. */ |
| 2139 | case GSM_CSTATE_CALL_DELIVERED: |
| 2140 | case GSM_CSTATE_CONNECT_IND: |
| 2141 | /* MNCC has progressed past the initial assignment. Usually it means that this happened: after |
| 2142 | * MNCC_ALERT_REQ, MO has triggered a re-assignment, to adjust MO's codec to MT's codec. */ |
| 2143 | LOG_TRANS(trans, LOGL_DEBUG, "Re-Assignment complete\n"); |
| 2144 | return 0; |
Neels Hofmeyr | bd5f8e9 | 2022-01-13 23:18:02 +0100 | [diff] [blame] | 2145 | |
| 2146 | default: |
| 2147 | LOG_TRANS(trans, LOGL_ERROR, "Assignment done in unexpected CC state: %d\n", trans->cc.state); |
| 2148 | return -EINVAL; |
| 2149 | } |
| 2150 | |
| 2151 | if (!call_leg_local_ip(msc_a->cc.call_leg, RTP_TO_CN)) { |
| 2152 | LOG_TRANS(trans, LOGL_DEBUG, |
| 2153 | "Assignment complete, but still waiting for the CRCX OK on the CN side RTP\n"); |
| 2154 | return 0; |
| 2155 | } |
| 2156 | return gsm48_tch_rtp_create(trans); |
| 2157 | } |
| 2158 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2159 | /* Trigger TCH_RTP_CREATE acknowledgement */ |
| 2160 | int gsm48_tch_rtp_create(struct gsm_trans *trans) |
| 2161 | { |
| 2162 | /* This function is called as soon as the port, on which the |
| 2163 | * mgcp-gw expects the incoming RTP stream from the remote |
| 2164 | * end (e.g. Asterisk) is known. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2165 | struct msc_a *msc_a = trans->msc_a; |
| 2166 | struct gsm_network *net = msc_a_net(msc_a); |
| 2167 | struct call_leg *cl = msc_a->cc.call_leg; |
| 2168 | struct osmo_sockaddr_str *rtp_cn_local; |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 2169 | struct rtp_stream *rtp_cn = cl ? cl->rtp[RTP_TO_CN] : NULL; |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2170 | int mncc_payload_msg_type; |
| 2171 | struct sdp_audio_codec *codec; |
Neels Hofmeyr | a001a70 | 2022-10-31 17:57:30 +0100 | [diff] [blame] | 2172 | const struct codec_mapping *m; |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2173 | struct sdp_audio_codecs *codecs; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2174 | |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 2175 | if (!rtp_cn) { |
| 2176 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no RTP set up for the CN side\n"); |
| 2177 | return -EINVAL; |
| 2178 | } |
| 2179 | |
Oliver Smith | ceca8e6 | 2023-05-24 11:15:52 +0200 | [diff] [blame] | 2180 | trans_cc_filter_run(trans); |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 2181 | codecs = &trans->cc.local.audio_codecs; |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2182 | if (!codecs->count) { |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 2183 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2184 | "Cannot RTP CREATE to MNCC, there is no codec available\n"); |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 2185 | return -EINVAL; |
| 2186 | } |
| 2187 | |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2188 | /* Populate the legacy MNCC codec elements: payload_type and payload_msg_type */ |
| 2189 | codec = &codecs->codec[0]; |
| 2190 | m = codec_mapping_by_subtype_name(codec->subtype_name); |
| 2191 | mncc_payload_msg_type = m ? m->mncc_payload_msg_type : 0; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2192 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2193 | rtp_cn_local = call_leg_local_ip(cl, RTP_TO_CN); |
| 2194 | if (!rtp_cn_local) { |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2195 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no local RTP IP:port to CN set up\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2196 | return -EINVAL; |
| 2197 | } |
| 2198 | |
Neels Hofmeyr | 006b0ee | 2022-11-07 16:59:09 +0100 | [diff] [blame] | 2199 | return mncc_recv_rtp(net, trans, trans->callref, MNCC_RTP_CREATE, rtp_cn_local, |
Oliver Smith | c63c3a0 | 2023-05-24 10:48:07 +0200 | [diff] [blame] | 2200 | codec->payload_type, mncc_payload_msg_type, &trans->cc.local); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2201 | } |
| 2202 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2203 | static int tch_rtp_connect(struct gsm_network *net, const struct gsm_mncc_rtp *rtp) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2204 | { |
| 2205 | struct gsm_trans *trans; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2206 | struct call_leg *cl; |
| 2207 | struct rtp_stream *rtps; |
Philipp Maier | 8ad3dac | 2018-08-07 13:00:14 +0200 | [diff] [blame] | 2208 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2209 | /* Find callref */ |
Andreas Eversberg | 7e4b032 | 2023-04-23 11:43:13 +0200 | [diff] [blame] | 2210 | trans = trans_find_by_callref(net, TRANS_CC, rtp->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2211 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2212 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for non-existing trans\n"); |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 2213 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2214 | return -EIO; |
| 2215 | } |
| 2216 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2217 | if (!trans->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2218 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for trans without conn\n"); |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 2219 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2220 | return -EIO; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2221 | } |
| 2222 | |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2223 | log_mncc_rx_tx(trans, "rx", (const union mncc_msg *)rtp); |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 2224 | |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 2225 | rx_mncc_sdp(trans, rtp->msg_type, rtp->sdp, NULL); |
| 2226 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2227 | cl = trans->msc_a->cc.call_leg; |
| 2228 | rtps = cl ? cl->rtp[RTP_TO_CN] : NULL; |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 2229 | if (rtps && !osmo_sockaddr_str_is_nonzero(&rtps->remote)) { |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 2230 | /* Didn't get an IP address from SDP. Try legacy MNCC IP address */ |
| 2231 | struct osmo_sockaddr_str rtp_addr; |
| 2232 | if (osmo_sockaddr_str_from_sockaddr(&rtp_addr, &rtp->addr) < 0) { |
| 2233 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect with invalid IP addr\n"); |
| 2234 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
| 2235 | return -EINVAL; |
| 2236 | } |
| 2237 | rtp_stream_set_remote_addr(rtps, &rtp_addr); |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 2238 | rtp_stream_commit(rtps); |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 2239 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2240 | return 0; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | static struct downstate { |
| 2244 | uint32_t states; |
| 2245 | int type; |
| 2246 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 2247 | } downstatelist[] = { |
| 2248 | /* mobile originating call establishment */ |
| 2249 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 2250 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc_and_assign}, |
| 2251 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 2252 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 2253 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC) | SBIT(GSM_CSTATE_CALL_DELIVERED), /* 5.2.1.2 | 5.2.1.6 | 5.2.1.6 */ |
| 2254 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 2255 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 2256 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 2257 | /* mobile terminating call establishment */ |
| 2258 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 2259 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 2260 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 2261 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 2262 | /* signalling during call */ |
| 2263 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2264 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 2265 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 2266 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 2267 | {ALL_STATES, |
| 2268 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 2269 | {ALL_STATES, |
| 2270 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 2271 | {ALL_STATES, |
| 2272 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 2273 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2274 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 2275 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2276 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 2277 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2278 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 2279 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2280 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 2281 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2282 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 2283 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 2284 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 2285 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 2286 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 2287 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2288 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 2289 | /* clearing */ |
| 2290 | {SBIT(GSM_CSTATE_INITIATED), |
| 2291 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 2292 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 2293 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 2294 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 2295 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 2296 | }; |
| 2297 | |
| 2298 | #define DOWNSLLEN \ |
| 2299 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 2300 | |
| 2301 | |
Philipp Maier | cd64af7 | 2019-08-01 09:46:40 +0200 | [diff] [blame] | 2302 | static int mncc_tx_to_gsm_cc(struct gsm_network *net, const union mncc_msg *msg) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2303 | { |
| 2304 | int i, rc = 0; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2305 | struct msc_a *msc_a = NULL; |
| 2306 | struct gsm_trans *trans = NULL; |
| 2307 | const struct gsm_mncc *data; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2308 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2309 | /* handle special messages */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2310 | switch(msg->msg_type) { |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2311 | case MNCC_BRIDGE: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2312 | rc = tch_bridge(net, &msg->bridge); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2313 | if (rc < 0) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2314 | disconnect_bridge(net, &msg->bridge, -rc); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2315 | return rc; |
| 2316 | case MNCC_RTP_CREATE: |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2317 | return tch_rtp_create(net, &msg->rtp); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2318 | case MNCC_RTP_CONNECT: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2319 | return tch_rtp_connect(net, &msg->rtp); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2320 | case MNCC_RTP_FREE: |
| 2321 | /* unused right now */ |
| 2322 | return -EIO; |
| 2323 | |
| 2324 | case MNCC_FRAME_DROP: |
| 2325 | case MNCC_FRAME_RECV: |
| 2326 | case GSM_TCHF_FRAME: |
| 2327 | case GSM_TCHF_FRAME_EFR: |
| 2328 | case GSM_TCHH_FRAME: |
| 2329 | case GSM_TCH_FRAME_AMR: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2330 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP streams must be handled externally; %s not supported.\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2331 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2332 | return -ENOTSUP; |
| 2333 | } |
| 2334 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2335 | data = &msg->signal; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2336 | |
| 2337 | /* Find callref */ |
Andreas Eversberg | 7e4b032 | 2023-04-23 11:43:13 +0200 | [diff] [blame] | 2338 | trans = trans_find_by_callref(net, TRANS_CC, data->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2339 | |
| 2340 | /* Callref unknown */ |
| 2341 | if (!trans) { |
| 2342 | struct vlr_subscr *vsub; |
| 2343 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2344 | if (msg->msg_type != MNCC_SETUP_REQ) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2345 | LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "Unknown call reference for %s\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2346 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2347 | /* Invalid call reference */ |
| 2348 | return mncc_release_ind(net, NULL, data->callref, |
| 2349 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2350 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
| 2351 | } |
| 2352 | if (!data->called.number[0] && !data->imsi[0]) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2353 | LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "Neither number nor IMSI in %s\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2354 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2355 | /* Invalid number */ |
| 2356 | return mncc_release_ind(net, NULL, data->callref, |
| 2357 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2358 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 2359 | } |
| 2360 | /* New transaction due to setup, find subscriber */ |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2361 | if (data->called.number[0]) { |
| 2362 | vsub = vlr_subscr_find_by_msisdn(net->vlr, data->called.number, __func__); |
| 2363 | if (!vsub) |
| 2364 | LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "rx %s for unknown subscriber number '%s'\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2365 | get_mncc_name(msg->msg_type), data->called.number); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2366 | } else { |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 2367 | vsub = vlr_subscr_find_by_imsi(net->vlr, data->imsi, __func__); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2368 | if (!vsub) |
| 2369 | LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "rx %s for unknown subscriber IMSI '%s'\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2370 | get_mncc_name(msg->msg_type), data->imsi); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2371 | } |
| 2372 | if (!vsub) |
| 2373 | return mncc_release_ind(net, NULL, data->callref, GSM48_CAUSE_LOC_PRN_S_LU, |
Neels Hofmeyr | 43a349f | 2019-08-22 22:30:20 +0200 | [diff] [blame] | 2374 | GSM48_CC_CAUSE_USER_NOTRESPOND); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2375 | /* update the subscriber we deal with */ |
| 2376 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 2377 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2378 | /* If subscriber is not "attached" */ |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2379 | if (!vsub->lu_complete) { |
| 2380 | LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "rx %s for subscriber that is not attached: %s\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2381 | get_mncc_name(msg->msg_type), vlr_subscr_name(vsub)); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 2382 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2383 | /* Temporarily out of order */ |
| 2384 | return mncc_release_ind(net, NULL, data->callref, |
| 2385 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2386 | GSM48_CC_CAUSE_DEST_OOO); |
| 2387 | } |
Keith Whyte | 991bb42 | 2019-08-08 15:43:40 +0200 | [diff] [blame] | 2388 | |
| 2389 | /* Find valid conn */ |
| 2390 | msc_a = msc_a_for_vsub(vsub, true); |
| 2391 | |
| 2392 | /* If subscriber is BUSY and we do not DO call in call aka "call-waiting" */ |
| 2393 | if (!net->call_waiting && msc_a) { |
| 2394 | struct gsm_trans *existing_cc_trans = trans_find_by_type(msc_a, TRANS_CC); |
| 2395 | if (existing_cc_trans && existing_cc_trans->cc.state != GSM_CSTATE_NULL) { |
| 2396 | LOG_TRANS_CAT(existing_cc_trans, DCC, LOGL_NOTICE, |
| 2397 | "rx '%s' for subscriber %s with trans state (%s)" |
| 2398 | " rejecting with USER_BUSY\n", |
| 2399 | get_mncc_name(msg->msg_type), data->called.number, |
| 2400 | gsm48_cc_state_name(existing_cc_trans->cc.state)); |
| 2401 | return mncc_release_ind(net, NULL, data->callref, |
| 2402 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2403 | GSM48_CC_CAUSE_USER_BUSY); |
| 2404 | } |
| 2405 | } |
| 2406 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2407 | /* Create transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2408 | trans = trans_alloc(net, vsub, TRANS_CC, |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 2409 | TRANS_ID_UNASSIGNED, data->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2410 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2411 | LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 2412 | vlr_subscr_put(vsub, __func__); |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 2413 | /* Resource unavailable */ |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2414 | mncc_release_ind(net, NULL, data->callref, |
| 2415 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2416 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 2417 | return -ENOMEM; |
| 2418 | } |
| 2419 | |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 2420 | /* Remember remote SDP, if any */ |
Neels Hofmeyr | cbabe1e | 2023-12-10 05:25:36 +0100 | [diff] [blame] | 2421 | rx_mncc_sdp(trans, data->msg_type, data->sdp, |
| 2422 | (data->fields & MNCC_F_BEARER_CAP) ? &data->bearer_cap : NULL); |
Neels Hofmeyr | 8dd1646 | 2022-01-13 20:06:53 +0100 | [diff] [blame] | 2423 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2424 | /* If subscriber has no conn */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2425 | if (!msc_a) { |
Neels Hofmeyr | c67b483 | 2019-10-21 02:34:54 +0200 | [diff] [blame] | 2426 | /* This condition will return before the common logging of the received MNCC message below, so |
| 2427 | * log it now. */ |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2428 | log_mncc_rx_tx(trans, "rx", msg); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2429 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2430 | /* store setup information until paging succeeds */ |
| 2431 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
| 2432 | |
Neels Hofmeyr | bde605d | 2019-10-21 03:07:25 +0200 | [diff] [blame] | 2433 | /* Request a channel. If Paging already started, paging_request_start() will append the new |
| 2434 | * trans to the already ongoing Paging. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2435 | trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_CALL_CONVERSATIONAL, |
| 2436 | cc_paging_cb, trans, "MNCC: establish call"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2437 | if (!trans->paging_request) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2438 | LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token.\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2439 | trans_free(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2440 | } |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 2441 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2442 | return 0; |
| 2443 | } |
| 2444 | |
| 2445 | /* Assign conn */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2446 | trans->msc_a = msc_a; |
| 2447 | msc_a_get(msc_a, MSC_A_USE_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2448 | trans->dlci = 0x00; /* SAPI=0, not SACCH */ |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 2449 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2450 | } else { |
| 2451 | /* update the subscriber we deal with */ |
| 2452 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 2453 | } |
| 2454 | |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2455 | log_mncc_rx_tx(trans, "rx", msg); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2456 | |
Mychaela N. Falconia | 9b7de74 | 2023-06-26 05:30:29 +0000 | [diff] [blame] | 2457 | /* |
| 2458 | * The step of gsm48_start_guard_timer() needs to be done for |
| 2459 | * major state-impacting MNCC messages, but not for those |
| 2460 | * that are a mere pass-through to CC messages to MS. |
| 2461 | */ |
| 2462 | switch (msg->msg_type) { |
| 2463 | case MNCC_PROGRESS_REQ: |
| 2464 | case MNCC_NOTIFY_REQ: |
| 2465 | case MNCC_FACILITY_REQ: |
| 2466 | case MNCC_START_DTMF_RSP: |
| 2467 | case MNCC_START_DTMF_REJ: |
| 2468 | case MNCC_STOP_DTMF_RSP: |
| 2469 | case MNCC_HOLD_CNF: |
| 2470 | case MNCC_HOLD_REJ: |
| 2471 | case MNCC_RETRIEVE_CNF: |
| 2472 | case MNCC_RETRIEVE_REJ: |
| 2473 | case MNCC_USERINFO_REQ: |
| 2474 | break; |
| 2475 | default: |
| 2476 | gsm48_start_guard_timer(trans); |
| 2477 | } |
Neels Hofmeyr | cf90bdb | 2019-10-01 19:47:26 +0200 | [diff] [blame] | 2478 | trans->cc.mncc_initiated = true; |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 2479 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2480 | if (trans->msc_a) |
| 2481 | msc_a = trans->msc_a; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2482 | |
| 2483 | /* if paging did not respond yet */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2484 | if (!msc_a) { |
| 2485 | struct gsm_mncc rel = { |
| 2486 | .callref = data->callref, |
| 2487 | }; |
Neels Hofmeyr | 58f4088 | 2023-03-08 04:04:27 +0100 | [diff] [blame] | 2488 | LOG_TRANS(trans, LOGL_DEBUG, "still paging\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2489 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 2490 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2491 | if (msg->msg_type == MNCC_REL_REQ) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2492 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 2493 | else |
| 2494 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 2495 | trans->callref = 0; |
| 2496 | trans_free(trans); |
| 2497 | return rc; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | /* Find function for current state and message */ |
| 2501 | for (i = 0; i < DOWNSLLEN; i++) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2502 | if ((msg->msg_type == downstatelist[i].type) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2503 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
| 2504 | break; |
| 2505 | if (i == DOWNSLLEN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2506 | LOG_TRANS(trans, LOGL_DEBUG, "Message '%s' unhandled at state '%s'\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2507 | get_mncc_name(msg->msg_type), gsm48_cc_state_name(trans->cc.state)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2508 | return 0; |
| 2509 | } |
| 2510 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2511 | rc = downstatelist[i].rout(trans, (void*)msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2512 | |
| 2513 | return rc; |
| 2514 | } |
| 2515 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2516 | struct mncc_call *mncc_find_by_callref_from_msg(const union mncc_msg *msg) |
| 2517 | { |
| 2518 | uint32_t callref; |
| 2519 | |
| 2520 | switch (msg->msg_type) { |
| 2521 | case MNCC_BRIDGE: |
| 2522 | callref = msg->bridge.callref[0]; |
| 2523 | break; |
| 2524 | case MNCC_RTP_CREATE: |
| 2525 | case MNCC_RTP_CONNECT: |
| 2526 | callref = msg->rtp.callref; |
| 2527 | break; |
| 2528 | |
| 2529 | case MNCC_RTP_FREE: |
| 2530 | case MNCC_FRAME_DROP: |
| 2531 | case MNCC_FRAME_RECV: |
| 2532 | case GSM_TCHF_FRAME: |
| 2533 | case GSM_TCHF_FRAME_EFR: |
| 2534 | case GSM_TCHH_FRAME: |
| 2535 | case GSM_TCH_FRAME_AMR: |
| 2536 | return NULL; |
| 2537 | |
| 2538 | default: |
| 2539 | callref = msg->signal.callref; |
| 2540 | break; |
| 2541 | } |
| 2542 | |
| 2543 | return mncc_call_find_by_callref(callref); |
| 2544 | } |
| 2545 | |
| 2546 | /* Demux incoming genuine calls to GSM CC from MNCC forwarding for inter-MSC handover */ |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 2547 | int mncc_tx_to_cc(struct gsm_network *net, void *arg) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2548 | { |
| 2549 | const union mncc_msg *msg = arg; |
| 2550 | struct mncc_call *mncc_call = NULL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2551 | |
| 2552 | if (msg->msg_type == MNCC_SETUP_REQ) { |
| 2553 | /* Incoming call to forward for inter-MSC Handover? */ |
| 2554 | mncc_call = msc_t_check_call_to_handover_number(&msg->signal); |
| 2555 | if (mncc_call) |
| 2556 | LOG_MNCC_CALL(mncc_call, LOGL_DEBUG, |
| 2557 | "Incoming call matches pending inter-MSC Handover Number\n"); |
| 2558 | } |
| 2559 | if (!mncc_call) { |
| 2560 | /* Find already active MNCC FSM for this callref. |
| 2561 | * Currently only for inter-MSC call forwarding, but mncc_fsm could at some point also be used for direct |
| 2562 | * MNCC<->GSM-CC call handling. */ |
| 2563 | mncc_call = mncc_find_by_callref_from_msg(msg); |
| 2564 | } |
| 2565 | if (mncc_call) { |
| 2566 | mncc_call_rx(mncc_call, msg); |
| 2567 | return 0; |
| 2568 | } |
| 2569 | |
| 2570 | /* None of the above? Then it must be a normal GSM CC call related message. */ |
| 2571 | return mncc_tx_to_gsm_cc(net, msg); |
| 2572 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2573 | |
| 2574 | static struct datastate { |
| 2575 | uint32_t states; |
| 2576 | int type; |
| 2577 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 2578 | } datastatelist[] = { |
| 2579 | /* mobile originating call establishment */ |
| 2580 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 2581 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 2582 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 2583 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 2584 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 2585 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 2586 | /* mobile terminating call establishment */ |
| 2587 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 2588 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 2589 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 2590 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
| 2591 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF) | SBIT(GSM_CSTATE_CALL_RECEIVED), /* (5.2.2.6) | 5.2.2.6 | 5.2.2.6 */ |
| 2592 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 2593 | /* signalling during call */ |
| 2594 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 2595 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 2596 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2597 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 2598 | {ALL_STATES, |
| 2599 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 2600 | {ALL_STATES, |
| 2601 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 2602 | {ALL_STATES, |
| 2603 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 2604 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2605 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 2606 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2607 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 2608 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2609 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 2610 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 2611 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 2612 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 2613 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 2614 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2615 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 2616 | /* clearing */ |
| 2617 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 2618 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 2619 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 2620 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 2621 | {ALL_STATES, /* 5.4.3.4 */ |
| 2622 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 2623 | }; |
| 2624 | |
| 2625 | #define DATASLLEN \ |
| 2626 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 2627 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2628 | int gsm0408_rcv_cc(struct msc_a *msc_a, struct msgb *msg) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2629 | { |
| 2630 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2631 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
| 2632 | uint8_t transaction_id = gsm48_hdr_trans_id_flip_ti(gh); |
| 2633 | struct gsm_trans *trans = NULL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2634 | struct vlr_subscr *vsub = msc_a_vsub(msc_a); |
| 2635 | struct gsm_network *net = msc_a_net(msc_a); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2636 | int i, rc = 0; |
| 2637 | |
| 2638 | if (msg_type & 0x80) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2639 | LOG_TRANS(trans, LOGL_DEBUG, "MSG 0x%2x not defined for PD error\n", msg_type); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2640 | return -EINVAL; |
| 2641 | } |
| 2642 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2643 | if (!vsub) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2644 | LOG_TRANS(trans, LOGL_ERROR, "Invalid conn: no subscriber\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2645 | return -EINVAL; |
| 2646 | } |
| 2647 | |
| 2648 | /* Find transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2649 | trans = trans_find_by_id(msc_a, TRANS_CC, transaction_id); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2650 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2651 | /* Create transaction */ |
| 2652 | if (!trans) { |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2653 | /* Create transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2654 | trans = trans_alloc(net, vsub, |
| 2655 | TRANS_CC, |
| 2656 | transaction_id, msc_cc_next_outgoing_callref()); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2657 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2658 | LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2659 | rc = gsm48_tx_simple(msc_a, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2660 | GSM48_PDISC_CC | (transaction_id << 4), |
| 2661 | GSM48_MT_CC_RELEASE_COMPL); |
| 2662 | return -ENOMEM; |
| 2663 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2664 | if (osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans)) { |
| 2665 | LOG_MSC_A(msc_a, LOGL_ERROR, "Not allowed to accept CC transaction\n"); |
| 2666 | trans_free(trans); |
| 2667 | return -EINVAL; |
| 2668 | } |
| 2669 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2670 | /* Assign transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2671 | msc_a_get(msc_a, MSC_A_USE_CC); |
| 2672 | trans->msc_a = msc_a; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2673 | trans->dlci = OMSC_LINKID_CB(msg); /* DLCI as received from BSC */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2674 | |
| 2675 | /* An earlier CM Service Request for this CC message now has concluded */ |
| 2676 | if (!osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_CC)) |
| 2677 | LOG_MSC_A(msc_a, LOGL_ERROR, |
| 2678 | "Creating new CC transaction without prior CM Service Request\n"); |
| 2679 | else |
| 2680 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2681 | } |
| 2682 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2683 | LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n", gsm48_cc_msg_name(msg_type), |
| 2684 | gsm48_cc_state_name(trans->cc.state)); |
| 2685 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2686 | /* find function for current state and message */ |
| 2687 | for (i = 0; i < DATASLLEN; i++) |
| 2688 | if ((msg_type == datastatelist[i].type) |
| 2689 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
| 2690 | break; |
| 2691 | if (i == DATASLLEN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2692 | LOG_TRANS(trans, LOGL_ERROR, "Message unhandled at this state.\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2693 | |
| 2694 | /* If a transaction was just now created, it was a bogus transaction ID, and we need to clean up the |
| 2695 | * transaction right away. */ |
| 2696 | if (trans->cc.state == GSM_CSTATE_NULL) { |
| 2697 | LOG_TRANS(trans, LOGL_ERROR, "Unknown transaction ID for non-SETUP message is not allowed" |
| 2698 | " -- disarding new CC transaction right away\n"); |
| 2699 | trans_free(trans); |
| 2700 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2701 | return 0; |
| 2702 | } |
| 2703 | |
| 2704 | assert(trans->vsub); |
| 2705 | |
| 2706 | rc = datastatelist[i].rout(trans, msg); |
| 2707 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2708 | return rc; |
| 2709 | } |