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