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> |
| 46 | #include <osmocom/msc/silent_call.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 47 | #include <osmocom/msc/mncc_int.h> |
| 48 | #include <osmocom/abis/e1_input.h> |
| 49 | #include <osmocom/core/bitvec.h> |
| 50 | #include <osmocom/msc/vlr.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 51 | #include <osmocom/msc/msub.h> |
| 52 | #include <osmocom/msc/msc_a.h> |
| 53 | #include <osmocom/msc/paging.h> |
| 54 | #include <osmocom/msc/call_leg.h> |
| 55 | #include <osmocom/msc/rtp_stream.h> |
| 56 | #include <osmocom/msc/mncc_call.h> |
| 57 | #include <osmocom/msc/msc_t.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 58 | |
| 59 | #include <osmocom/gsm/gsm48.h> |
| 60 | #include <osmocom/gsm/gsm0480.h> |
| 61 | #include <osmocom/gsm/gsm_utils.h> |
| 62 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 63 | #include <osmocom/core/msgb.h> |
| 64 | #include <osmocom/core/talloc.h> |
| 65 | #include <osmocom/core/utils.h> |
| 66 | #include <osmocom/core/byteswap.h> |
| 67 | #include <osmocom/gsm/tlv.h> |
| 68 | #include <osmocom/crypt/auth.h> |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 69 | |
| 70 | #include <assert.h> |
| 71 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 72 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg); |
| 73 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 74 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 75 | |
| 76 | static int trans_tx_gsm48(struct gsm_trans *trans, struct msgb *msg) |
| 77 | { |
| 78 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 79 | gh->proto_discr = GSM48_PDISC_CC | (trans->transaction_id << 4); |
| 80 | OMSC_LINKID_CB(msg) = trans->dlci; |
| 81 | |
| 82 | return msc_a_tx_dtap_to_i(trans->msc_a, msg); |
| 83 | } |
| 84 | |
| 85 | uint32_t msc_cc_next_outgoing_callref() { |
| 86 | static uint32_t last_callref = 0x80000000; |
| 87 | last_callref++; |
| 88 | if (last_callref < 0x80000001) |
| 89 | last_callref = 0x80000001; |
| 90 | return last_callref; |
| 91 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 92 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 93 | static void gsm48_cc_guard_timeout(void *arg) |
| 94 | { |
| 95 | struct gsm_trans *trans = arg; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 96 | LOG_TRANS(trans, LOGL_DEBUG, "guard timeout expired\n"); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 97 | trans_free(trans); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | static void gsm48_stop_guard_timer(struct gsm_trans *trans) |
| 102 | { |
| 103 | if (osmo_timer_pending(&trans->cc.timer_guard)) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 104 | LOG_TRANS(trans, LOGL_DEBUG, "stopping pending guard timer\n"); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 105 | osmo_timer_del(&trans->cc.timer_guard); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | static void gsm48_start_guard_timer(struct gsm_trans *trans) |
| 110 | { |
| 111 | /* NOTE: The purpose of this timer is to prevent the cc state machine |
| 112 | * from hanging in cases where mncc, gsm48 or both become unresponsive |
| 113 | * for some reason. The timer is started initially with the setup from |
| 114 | * the gsm48 side and then re-started with every incoming mncc message. |
| 115 | * Once the mncc state reaches its active state the timer is stopped. |
| 116 | * So if the cc state machine does not show any activity for an |
| 117 | * extended amount of time during call setup or teardown the guard |
| 118 | * timer will time out and hard-clear the connection. */ |
| 119 | if (osmo_timer_pending(&trans->cc.timer_guard)) |
| 120 | gsm48_stop_guard_timer(trans); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 121 | 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] | 122 | osmo_timer_setup(&trans->cc.timer_guard, gsm48_cc_guard_timeout, trans); |
| 123 | osmo_timer_schedule(&trans->cc.timer_guard, |
| 124 | trans->net->mncc_guard_timeout, 0); |
| 125 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 126 | |
| 127 | /* Call Control */ |
| 128 | |
| 129 | void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg) |
| 130 | { |
| 131 | net->mncc_recv(net, msg); |
| 132 | } |
| 133 | |
| 134 | int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message) |
| 135 | { |
| 136 | struct gsm48_hdr *gh; |
| 137 | struct msgb *ss_notify; |
| 138 | |
| 139 | ss_notify = gsm0480_create_notifySS(message); |
| 140 | if (!ss_notify) |
| 141 | return -1; |
| 142 | |
| 143 | gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0); |
| 144 | uint8_t *data = msgb_push(ss_notify, 1); |
| 145 | data[0] = ss_notify->len - 1; |
| 146 | gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh)); |
| 147 | gh->msg_type = GSM48_MT_CC_FACILITY; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 148 | return trans_tx_gsm48(trans, ss_notify); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* FIXME: this count_statistics is a state machine behaviour. we should convert |
| 152 | * the complete call control into a state machine. Afterwards we can move this |
| 153 | * code into state transitions. |
| 154 | */ |
| 155 | static void count_statistics(struct gsm_trans *trans, int new_state) |
| 156 | { |
| 157 | int old_state = trans->cc.state; |
| 158 | struct rate_ctr_group *msc = trans->net->msc_ctrs; |
| 159 | |
| 160 | if (old_state == new_state) |
| 161 | return; |
| 162 | |
| 163 | /* state incoming */ |
| 164 | switch (new_state) { |
| 165 | case GSM_CSTATE_ACTIVE: |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 166 | osmo_stat_item_inc(osmo_stat_item_group_get_item(trans->net->statg, MSC_STAT_ACTIVE_CALLS), |
| 167 | 1); |
| 168 | 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] | 169 | break; |
| 170 | } |
| 171 | |
| 172 | /* state outgoing */ |
| 173 | switch (old_state) { |
| 174 | case GSM_CSTATE_ACTIVE: |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 175 | osmo_stat_item_dec(osmo_stat_item_group_get_item(trans->net->statg, MSC_STAT_ACTIVE_CALLS), |
| 176 | 1); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 177 | if (new_state == GSM_CSTATE_DISCONNECT_REQ || |
| 178 | new_state == GSM_CSTATE_DISCONNECT_IND) |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 179 | 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] | 180 | else |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 181 | 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] | 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 186 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 187 | { |
| 188 | if (state > 31 || state < 0) |
| 189 | return; |
| 190 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 191 | LOG_TRANS(trans, LOGL_DEBUG, "new state %s -> %s\n", |
| 192 | gsm48_cc_state_name(trans->cc.state), |
| 193 | gsm48_cc_state_name(state)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 194 | |
| 195 | count_statistics(trans, state); |
| 196 | trans->cc.state = state; |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 197 | |
| 198 | /* Stop the guard timer when a call reaches the active state */ |
| 199 | if (state == GSM_CSTATE_ACTIVE) |
| 200 | gsm48_stop_guard_timer(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
| 204 | { |
| 205 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STATUS"); |
| 206 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 207 | uint8_t *cause, *call_state; |
| 208 | |
| 209 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 210 | |
| 211 | cause = msgb_put(msg, 3); |
| 212 | cause[0] = 2; |
| 213 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 214 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 215 | |
| 216 | call_state = msgb_put(msg, 1); |
| 217 | call_state[0] = 0xc0 | 0x00; |
| 218 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 219 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 223 | { |
| 224 | if (osmo_timer_pending(&trans->cc.timer)) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 225 | 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] | 226 | osmo_timer_del(&trans->cc.timer); |
| 227 | trans->cc.Tcurrent = 0; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans, |
| 232 | int msg_type, struct gsm_mncc *mncc) |
| 233 | { |
| 234 | struct msgb *msg; |
| 235 | unsigned char *data; |
| 236 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 237 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "tx %s\n", get_mncc_name(msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 238 | |
| 239 | mncc->msg_type = msg_type; |
| 240 | |
| 241 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
| 242 | if (!msg) |
| 243 | return -ENOMEM; |
| 244 | |
| 245 | data = msgb_put(msg, sizeof(struct gsm_mncc)); |
| 246 | memcpy(data, mncc, sizeof(struct gsm_mncc)); |
| 247 | |
| 248 | cc_tx_to_mncc(net, msg); |
Neels Hofmeyr | cf90bdb | 2019-10-01 19:47:26 +0200 | [diff] [blame] | 249 | /* trans may be NULL when sending an MNCC error reply upon an invalid MNCC request */ |
| 250 | if (trans) |
| 251 | trans->cc.mncc_initiated = true; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, |
| 257 | uint32_t callref, int location, int value) |
| 258 | { |
| 259 | struct gsm_mncc rel; |
| 260 | |
| 261 | memset(&rel, 0, sizeof(rel)); |
| 262 | rel.callref = callref; |
| 263 | mncc_set_cause(&rel, location, value); |
| 264 | if (trans && trans->cc.state == GSM_CSTATE_RELEASE_REQ) |
| 265 | return mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 266 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 267 | } |
| 268 | |
| 269 | /* Call Control Specific transaction release. |
| 270 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 271 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
| 272 | { |
| 273 | gsm48_stop_cc_timer(trans); |
| 274 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 275 | /* send release to L4, if callref still exists */ |
| 276 | if (trans->callref) { |
Vadim Yanitskiy | dd466cf | 2021-02-05 19:17:31 +0100 | [diff] [blame] | 277 | /* Send MNCC REL.ind (cause='Resource unavailable') */ |
| 278 | if (trans->cc.mncc_initiated) { |
| 279 | mncc_release_ind(trans->net, trans, trans->callref, |
| 280 | GSM48_CAUSE_LOC_PRN_S_LU, |
Keith Whyte | ba4d682 | 2022-07-03 04:12:58 +0100 | [diff] [blame] | 281 | (trans->cc.state == GSM_CSTATE_CALL_RECEIVED) ? |
| 282 | GSM48_CC_CAUSE_USER_NOTRESPOND : |
Vadim Yanitskiy | dd466cf | 2021-02-05 19:17:31 +0100 | [diff] [blame] | 283 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 284 | } |
| 285 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 286 | /* FIXME: currently, a CC trans that would not yet be in state GSM_CSTATE_RELEASE_REQ fails to send a |
| 287 | * CC Release to the MS if it gets freed here. Hack it to do so. */ |
| 288 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) { |
| 289 | struct gsm_mncc rel = {}; |
| 290 | rel.callref = trans->callref; |
| 291 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 292 | gsm48_cc_tx_release(trans, &rel); |
| 293 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 294 | /* This is a final freeing of the transaction. The MNCC release may have triggered the |
| 295 | * T308 release timer, but we don't have the luxury of graceful CC Release here. */ |
| 296 | gsm48_stop_cc_timer(trans); |
| 297 | } |
| 298 | if (trans->cc.state != GSM_CSTATE_NULL) |
| 299 | new_cc_state(trans, GSM_CSTATE_NULL); |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 300 | |
| 301 | gsm48_stop_guard_timer(trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 302 | |
| 303 | if (trans->msc_a && trans->msc_a->cc.active_trans == trans) |
| 304 | trans->msc_a->cc.active_trans = NULL; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 307 | /* call-back from paging the B-end of the connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 308 | 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] | 309 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 310 | if (trans->msc_a) { |
| 311 | LOG_MSC_A_CAT(msc_a, DPAG, LOGL_ERROR, |
| 312 | "Handle paging error: transaction already associated with subscriber," |
| 313 | " apparently it was already handled. Skip.\n"); |
| 314 | return; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 317 | if (msc_a) { |
| 318 | LOG_TRANS(trans, LOGL_DEBUG, "Paging succeeded\n"); |
| 319 | /* Assign conn */ |
| 320 | msc_a_get(msc_a, MSC_A_USE_CC); |
| 321 | trans->msc_a = msc_a; |
| 322 | trans->paging_request = NULL; |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 323 | |
| 324 | /* Get the GCR from the MO call leg (if any). */ |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 325 | if (!trans->cc.lcls) |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 326 | trans->cc.lcls = trans_lcls_compose(trans, true); |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 327 | if (trans->cc.lcls && trans->cc.msg.fields & MNCC_F_GCR) { |
| 328 | int rc = osmo_dec_gcr(&trans->cc.lcls->gcr, |
| 329 | &trans->cc.msg.gcr[0], |
| 330 | sizeof(trans->cc.msg.gcr)); |
| 331 | if (rc < 0) |
| 332 | LOG_TRANS(trans, LOGL_ERROR, "Failed to parse GCR\n"); |
| 333 | else |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 334 | trans->cc.lcls->gcr_available = true; |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 337 | osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans); |
| 338 | /* send SETUP request to called party */ |
| 339 | gsm48_cc_tx_setup(trans, &trans->cc.msg); |
| 340 | } else { |
| 341 | LOG_TRANS(trans, LOGL_DEBUG, "Paging expired\n"); |
| 342 | /* Temporarily out of order */ |
| 343 | mncc_release_ind(trans->net, trans, |
| 344 | trans->callref, |
| 345 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 346 | GSM48_CC_CAUSE_DEST_OOO); |
| 347 | trans->callref = 0; |
| 348 | trans->paging_request = NULL; |
| 349 | trans_free(trans); |
| 350 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* bridge channels of two transactions */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 354 | 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] | 355 | { |
| 356 | struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[0]); |
| 357 | struct gsm_trans *trans2 = trans_find_by_callref(net, bridge->callref[1]); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 358 | struct call_leg *cl1; |
| 359 | struct call_leg *cl2; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 360 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 361 | if (!trans1 || !trans2) { |
| 362 | 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] | 363 | return -EIO; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 364 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 365 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 366 | if (!trans1->msc_a || !trans2->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 367 | LOG_TRANS(trans1, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs lack an active connection\n"); |
| 368 | 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] | 369 | return -EIO; |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | LOG_TRANS(trans1, LOGL_DEBUG, "MNCC_BRIDGE: Local bridge to callref 0x%x\n", trans2->callref); |
| 373 | 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] | 374 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 375 | /* This call bridging mechanism is only used with the internal MNCC (with external MNCC briding would be done by |
| 376 | * the PBX). For inter-MSC Handover scenarios, an external MNCC is mandatory. The conclusion is that in this |
| 377 | * code path, there is only one MSC, and the MSC-I role is local, and hence we can directly access the ran_conn. |
| 378 | * If we can't, then we must give up. */ |
| 379 | cl1 = trans1->msc_a->cc.call_leg; |
| 380 | cl2 = trans2->msc_a->cc.call_leg; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 381 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 382 | return call_leg_local_bridge(cl1, trans1->callref, trans1, cl2, trans2->callref, trans2); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 386 | { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 387 | LOG_TRANS(trans, LOGL_DEBUG, "-> STATUS ENQ\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 388 | return gsm48_cc_tx_status(trans, msg); |
| 389 | } |
| 390 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 391 | static void gsm48_cc_timeout(void *arg) |
| 392 | { |
| 393 | struct gsm_trans *trans = arg; |
| 394 | int disconnect = 0, release = 0; |
| 395 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 396 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 397 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 398 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
| 399 | struct gsm_mncc mo_rel, l4_rel; |
| 400 | |
| 401 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 402 | mo_rel.callref = trans->callref; |
| 403 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 404 | l4_rel.callref = trans->callref; |
| 405 | |
| 406 | switch(trans->cc.Tcurrent) { |
| 407 | case 0x303: |
| 408 | release = 1; |
| 409 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
| 410 | break; |
| 411 | case 0x310: |
| 412 | disconnect = 1; |
| 413 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
| 414 | break; |
| 415 | case 0x313: |
| 416 | disconnect = 1; |
| 417 | /* unknown, did not find it in the specs */ |
| 418 | break; |
| 419 | case 0x301: |
| 420 | disconnect = 1; |
| 421 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
| 422 | break; |
| 423 | case 0x308: |
| 424 | if (!trans->cc.T308_second) { |
| 425 | /* restart T308 a second time */ |
| 426 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 427 | trans->cc.T308_second = 1; |
| 428 | break; /* stay in release state */ |
| 429 | } |
| 430 | trans_free(trans); |
| 431 | return; |
| 432 | case 0x306: |
| 433 | release = 1; |
| 434 | mo_cause = trans->cc.msg.cause.value; |
| 435 | mo_location = trans->cc.msg.cause.location; |
| 436 | break; |
| 437 | case 0x323: |
| 438 | disconnect = 1; |
| 439 | break; |
| 440 | default: |
| 441 | release = 1; |
| 442 | } |
| 443 | |
| 444 | if (release && trans->callref) { |
| 445 | /* process release towards layer 4 */ |
| 446 | mncc_release_ind(trans->net, trans, trans->callref, |
| 447 | l4_location, l4_cause); |
| 448 | trans->callref = 0; |
| 449 | } |
| 450 | |
| 451 | if (disconnect && trans->callref) { |
| 452 | /* process disconnect towards layer 4 */ |
| 453 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
| 454 | mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &l4_rel); |
| 455 | } |
| 456 | |
| 457 | /* process disconnect towards mobile station */ |
| 458 | if (disconnect || release) { |
| 459 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
| 460 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 461 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 462 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
| 463 | mo_rel.cause.diag_len = 3; |
| 464 | |
| 465 | if (disconnect) |
| 466 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 467 | if (release) |
| 468 | gsm48_cc_tx_release(trans, &mo_rel); |
| 469 | } |
| 470 | |
| 471 | } |
| 472 | |
| 473 | /* disconnect both calls from the bridge */ |
| 474 | static inline void disconnect_bridge(struct gsm_network *net, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 475 | const struct gsm_mncc_bridge *bridge, int err) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 476 | { |
| 477 | struct gsm_trans *trans0 = trans_find_by_callref(net, bridge->callref[0]); |
| 478 | struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[1]); |
| 479 | struct gsm_mncc mx_rel; |
| 480 | if (!trans0 || !trans1) |
| 481 | return; |
| 482 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 483 | LOG_TRANS(trans0, LOGL_ERROR, "Failed to bridge TCH for calls %x <-> %x :: %s \n", |
| 484 | trans0->callref, trans1->callref, strerror(err)); |
| 485 | 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] | 486 | trans0->callref, trans1->callref, strerror(err)); |
| 487 | |
| 488 | memset(&mx_rel, 0, sizeof(struct gsm_mncc)); |
| 489 | mncc_set_cause(&mx_rel, GSM48_CAUSE_LOC_INN_NET, |
| 490 | GSM48_CC_CAUSE_CHAN_UNACCEPT); |
| 491 | |
| 492 | mx_rel.callref = trans0->callref; |
| 493 | gsm48_cc_tx_disconnect(trans0, &mx_rel); |
| 494 | |
| 495 | mx_rel.callref = trans1->callref; |
| 496 | gsm48_cc_tx_disconnect(trans1, &mx_rel); |
| 497 | } |
| 498 | |
| 499 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 500 | int sec, int micro) |
| 501 | { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 502 | 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] | 503 | osmo_timer_setup(&trans->cc.timer, gsm48_cc_timeout, trans); |
| 504 | osmo_timer_schedule(&trans->cc.timer, sec, micro); |
| 505 | trans->cc.Tcurrent = current; |
| 506 | } |
| 507 | |
| 508 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 509 | { |
| 510 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 511 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
| 512 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 513 | struct tlv_parsed tp; |
| 514 | struct gsm_mncc setup; |
| 515 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 516 | gsm48_start_guard_timer(trans); |
| 517 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 518 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 519 | setup.callref = trans->callref; |
| 520 | |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 521 | /* New Global Call Reference */ |
| 522 | if (!trans->cc.lcls) |
| 523 | trans->cc.lcls = trans_lcls_compose(trans, true); |
| 524 | |
| 525 | /* Pass the LCLS GCR on to the MT call leg via MNCC */ |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 526 | if (trans->cc.lcls) { |
| 527 | struct msgb *gcr_msg = msgb_alloc(sizeof(setup.gcr), "MNCC GCR"); |
| 528 | const struct osmo_gcr_parsed *gcr = &trans->cc.lcls->gcr; |
| 529 | int rc; |
| 530 | |
| 531 | if (gcr_msg != NULL && (rc = osmo_enc_gcr(gcr_msg, gcr)) > 0) { |
| 532 | memcpy(&setup.gcr[0], gcr_msg->data, rc); |
| 533 | setup.fields |= MNCC_F_GCR; |
| 534 | } else |
| 535 | LOG_TRANS(trans, LOGL_ERROR, "Failed to encode GCR\n"); |
| 536 | msgb_free(gcr_msg); |
| 537 | } |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 538 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 539 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 540 | /* emergency setup is identified by msg_type */ |
| 541 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) { |
| 542 | setup.fields |= MNCC_F_EMERGENCY; |
| 543 | setup.emergency = 1; |
| 544 | /* use destination number as configured by user (if any) */ |
| 545 | if (trans->net->emergency.route_to_msisdn) { |
| 546 | setup.fields |= MNCC_F_CALLED; |
| 547 | setup.called.type = 0; /* unknown */ |
| 548 | setup.called.plan = 0; /* unknown */ |
| 549 | OSMO_STRLCPY_ARRAY(setup.called.number, |
| 550 | trans->net->emergency.route_to_msisdn); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | /* use subscriber as calling party number */ |
| 555 | setup.fields |= MNCC_F_CALLING; |
| 556 | OSMO_STRLCPY_ARRAY(setup.calling.number, trans->vsub->msisdn); |
| 557 | OSMO_STRLCPY_ARRAY(setup.imsi, trans->vsub->imsi); |
| 558 | |
| 559 | /* bearer capability */ |
| 560 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 561 | setup.fields |= MNCC_F_BEARER_CAP; |
| 562 | gsm48_decode_bearer_cap(&setup.bearer_cap, |
| 563 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 564 | |
| 565 | /* Create a copy of the bearer capability |
| 566 | * in the transaction struct, so we can use |
| 567 | * this information later */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 568 | memcpy(&trans->bearer_cap, &setup.bearer_cap, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 569 | sizeof(trans->bearer_cap)); |
| 570 | } |
| 571 | /* facility */ |
| 572 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 573 | setup.fields |= MNCC_F_FACILITY; |
| 574 | gsm48_decode_facility(&setup.facility, |
| 575 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 576 | } |
| 577 | /* called party bcd number */ |
| 578 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 579 | setup.fields |= MNCC_F_CALLED; |
| 580 | gsm48_decode_called(&setup.called, |
| 581 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 582 | } |
| 583 | /* user-user */ |
| 584 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 585 | setup.fields |= MNCC_F_USERUSER; |
| 586 | gsm48_decode_useruser(&setup.useruser, |
| 587 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 588 | } |
| 589 | /* ss-version */ |
| 590 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 591 | setup.fields |= MNCC_F_SSVERSION; |
| 592 | gsm48_decode_ssversion(&setup.ssversion, |
| 593 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 594 | } |
| 595 | /* CLIR suppression */ |
| 596 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 597 | setup.clir.sup = 1; |
| 598 | /* CLIR invocation */ |
| 599 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 600 | setup.clir.inv = 1; |
| 601 | /* cc cap */ |
| 602 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 603 | setup.fields |= MNCC_F_CCCAP; |
| 604 | gsm48_decode_cccap(&setup.cccap, |
| 605 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 606 | } |
| 607 | |
| 608 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 609 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 610 | LOG_TRANS(trans, setup.emergency ? LOGL_NOTICE : LOGL_INFO, "%sSETUP to %s\n", |
| 611 | setup.emergency ? "EMERGENCY_" : "", setup.called.number); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 612 | |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 613 | 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] | 614 | |
| 615 | /* indicate setup to MNCC */ |
| 616 | mncc_recvmsg(trans->net, trans, MNCC_SETUP_IND, &setup); |
| 617 | |
| 618 | /* MNCC code will modify the channel asynchronously, we should |
| 619 | * ipaccess-bind only after the modification has been made to the |
| 620 | * lchan->tch_mode */ |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
| 625 | { |
Neels Hofmeyr | 3551d84 | 2022-01-13 19:35:12 +0100 | [diff] [blame] | 626 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC SETUP"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 627 | struct gsm48_hdr *gh; |
| 628 | struct gsm_mncc *setup = arg; |
| 629 | int rc, trans_id; |
| 630 | |
| 631 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 632 | |
| 633 | /* transaction id must not be assigned */ |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 634 | if (trans->transaction_id != TRANS_ID_UNASSIGNED) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 635 | LOG_TRANS(trans, LOGL_DEBUG, "TX Setup with assigned transaction. " |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 636 | "This is not allowed!\n"); |
| 637 | /* Temporarily out of order */ |
| 638 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
| 639 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 640 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 641 | trans->callref = 0; |
| 642 | trans_free(trans); |
Neels Hofmeyr | 61ae18c | 2019-08-28 03:41:05 +0200 | [diff] [blame] | 643 | msgb_free(msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 644 | return rc; |
| 645 | } |
| 646 | |
| 647 | /* Get free transaction_id */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 648 | trans_id = trans_assign_trans_id(trans->net, trans->vsub, TRANS_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 649 | if (trans_id < 0) { |
| 650 | /* no free transaction ID */ |
| 651 | rc = mncc_release_ind(trans->net, trans, trans->callref, |
| 652 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 653 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 654 | trans->callref = 0; |
| 655 | trans_free(trans); |
Neels Hofmeyr | 61ae18c | 2019-08-28 03:41:05 +0200 | [diff] [blame] | 656 | msgb_free(msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 657 | return rc; |
| 658 | } |
| 659 | trans->transaction_id = trans_id; |
| 660 | |
| 661 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 662 | |
| 663 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
| 664 | |
| 665 | /* bearer capability */ |
| 666 | if (setup->fields & MNCC_F_BEARER_CAP) { |
| 667 | /* Create a copy of the bearer capability in the transaction struct, so we |
| 668 | * can use this information later */ |
| 669 | memcpy(&trans->bearer_cap, &setup->bearer_cap, sizeof(trans->bearer_cap)); |
| 670 | gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap); |
| 671 | } |
| 672 | /* facility */ |
| 673 | if (setup->fields & MNCC_F_FACILITY) |
| 674 | gsm48_encode_facility(msg, 0, &setup->facility); |
| 675 | /* progress */ |
| 676 | if (setup->fields & MNCC_F_PROGRESS) |
| 677 | gsm48_encode_progress(msg, 0, &setup->progress); |
| 678 | /* calling party BCD number */ |
| 679 | if (setup->fields & MNCC_F_CALLING) |
| 680 | gsm48_encode_calling(msg, &setup->calling); |
| 681 | /* called party BCD number */ |
| 682 | if (setup->fields & MNCC_F_CALLED) |
| 683 | gsm48_encode_called(msg, &setup->called); |
| 684 | /* user-user */ |
| 685 | if (setup->fields & MNCC_F_USERUSER) |
| 686 | gsm48_encode_useruser(msg, 0, &setup->useruser); |
| 687 | /* redirecting party BCD number */ |
| 688 | if (setup->fields & MNCC_F_REDIRECTING) |
| 689 | gsm48_encode_redirecting(msg, &setup->redirecting); |
| 690 | /* signal */ |
| 691 | if (setup->fields & MNCC_F_SIGNAL) |
| 692 | gsm48_encode_signal(msg, setup->signal); |
| 693 | |
| 694 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
| 695 | |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 696 | 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] | 697 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 698 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 702 | { |
| 703 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 704 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 705 | struct tlv_parsed tp; |
| 706 | struct gsm_mncc call_conf; |
| 707 | int rc; |
| 708 | |
| 709 | gsm48_stop_cc_timer(trans); |
| 710 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 711 | |
| 712 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 713 | call_conf.callref = trans->callref; |
| 714 | |
| 715 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 716 | #if 0 |
| 717 | /* repeat */ |
| 718 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 719 | call_conf.repeat = 1; |
| 720 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 721 | call_conf.repeat = 2; |
| 722 | #endif |
| 723 | /* bearer capability */ |
| 724 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 725 | call_conf.fields |= MNCC_F_BEARER_CAP; |
| 726 | gsm48_decode_bearer_cap(&call_conf.bearer_cap, |
| 727 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 728 | |
| 729 | /* Create a copy of the bearer capability |
| 730 | * in the transaction struct, so we can use |
| 731 | * this information later */ |
Neels Hofmeyr | a9e383f | 2022-01-13 19:58:05 +0100 | [diff] [blame] | 732 | memcpy(&trans->bearer_cap, &call_conf.bearer_cap, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 733 | sizeof(trans->bearer_cap)); |
| 734 | } |
Neels Hofmeyr | a9e383f | 2022-01-13 19:58:05 +0100 | [diff] [blame] | 735 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 736 | /* cause */ |
| 737 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 738 | call_conf.fields |= MNCC_F_CAUSE; |
| 739 | gsm48_decode_cause(&call_conf.cause, |
| 740 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 741 | } |
| 742 | /* cc cap */ |
| 743 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 744 | call_conf.fields |= MNCC_F_CCCAP; |
| 745 | gsm48_decode_cccap(&call_conf.cccap, |
| 746 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 747 | } |
| 748 | |
| 749 | /* IMSI of called subscriber */ |
| 750 | OSMO_STRLCPY_ARRAY(call_conf.imsi, trans->vsub->imsi); |
| 751 | |
| 752 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 753 | |
| 754 | /* Assign call (if not done yet) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 755 | rc = msc_a_try_call_assignment(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 756 | |
| 757 | /* don't continue, if there were problems with |
| 758 | * the call assignment. */ |
| 759 | if (rc) |
| 760 | return rc; |
| 761 | |
| 762 | return mncc_recvmsg(trans->net, trans, MNCC_CALL_CONF_IND, |
| 763 | &call_conf); |
| 764 | } |
| 765 | |
| 766 | static int gsm48_cc_tx_call_proc_and_assign(struct gsm_trans *trans, void *arg) |
| 767 | { |
| 768 | struct gsm_mncc *proceeding = arg; |
| 769 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROC"); |
| 770 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 771 | int rc; |
| 772 | |
| 773 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 774 | |
| 775 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 776 | |
| 777 | /* bearer capability */ |
| 778 | if (proceeding->fields & MNCC_F_BEARER_CAP) { |
| 779 | gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
| 780 | memcpy(&trans->bearer_cap, &proceeding->bearer_cap, sizeof(trans->bearer_cap)); |
| 781 | } |
| 782 | /* facility */ |
| 783 | if (proceeding->fields & MNCC_F_FACILITY) |
| 784 | gsm48_encode_facility(msg, 0, &proceeding->facility); |
| 785 | /* progress */ |
| 786 | if (proceeding->fields & MNCC_F_PROGRESS) |
| 787 | gsm48_encode_progress(msg, 0, &proceeding->progress); |
| 788 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 789 | rc = trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 790 | if (rc) |
| 791 | return rc; |
| 792 | |
| 793 | /* Assign call (if not done yet) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 794 | return msc_a_try_call_assignment(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 798 | { |
| 799 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 800 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 801 | struct tlv_parsed tp; |
| 802 | struct gsm_mncc alerting; |
| 803 | |
| 804 | gsm48_stop_cc_timer(trans); |
| 805 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 806 | |
| 807 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 808 | alerting.callref = trans->callref; |
| 809 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 810 | /* facility */ |
| 811 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 812 | alerting.fields |= MNCC_F_FACILITY; |
| 813 | gsm48_decode_facility(&alerting.facility, |
| 814 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 815 | } |
| 816 | |
| 817 | /* progress */ |
| 818 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 819 | alerting.fields |= MNCC_F_PROGRESS; |
| 820 | gsm48_decode_progress(&alerting.progress, |
| 821 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 822 | } |
| 823 | /* ss-version */ |
| 824 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 825 | alerting.fields |= MNCC_F_SSVERSION; |
| 826 | gsm48_decode_ssversion(&alerting.ssversion, |
| 827 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 828 | } |
| 829 | |
| 830 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 831 | |
| 832 | return mncc_recvmsg(trans->net, trans, MNCC_ALERT_IND, |
| 833 | &alerting); |
| 834 | } |
| 835 | |
| 836 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 837 | { |
| 838 | struct gsm_mncc *alerting = arg; |
| 839 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC ALERT"); |
| 840 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 841 | |
| 842 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 843 | |
| 844 | /* facility */ |
| 845 | if (alerting->fields & MNCC_F_FACILITY) |
| 846 | gsm48_encode_facility(msg, 0, &alerting->facility); |
| 847 | /* progress */ |
| 848 | if (alerting->fields & MNCC_F_PROGRESS) |
| 849 | gsm48_encode_progress(msg, 0, &alerting->progress); |
| 850 | /* user-user */ |
| 851 | if (alerting->fields & MNCC_F_USERUSER) |
| 852 | gsm48_encode_useruser(msg, 0, &alerting->useruser); |
| 853 | |
| 854 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
| 855 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 856 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 860 | { |
| 861 | struct gsm_mncc *progress = arg; |
| 862 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROGRESS"); |
| 863 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 864 | |
| 865 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 866 | |
| 867 | /* progress */ |
| 868 | gsm48_encode_progress(msg, 1, &progress->progress); |
| 869 | /* user-user */ |
| 870 | if (progress->fields & MNCC_F_USERUSER) |
| 871 | gsm48_encode_useruser(msg, 0, &progress->useruser); |
| 872 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 873 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 877 | { |
| 878 | struct gsm_mncc *connect = arg; |
| 879 | struct msgb *msg = gsm48_msgb_alloc_name("GSN 04.08 CC CON"); |
| 880 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 881 | |
| 882 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 883 | |
| 884 | gsm48_stop_cc_timer(trans); |
| 885 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 886 | |
| 887 | /* facility */ |
| 888 | if (connect->fields & MNCC_F_FACILITY) |
| 889 | gsm48_encode_facility(msg, 0, &connect->facility); |
| 890 | /* progress */ |
| 891 | if (connect->fields & MNCC_F_PROGRESS) |
| 892 | gsm48_encode_progress(msg, 0, &connect->progress); |
| 893 | /* connected number */ |
| 894 | if (connect->fields & MNCC_F_CONNECTED) |
| 895 | gsm48_encode_connected(msg, &connect->connected); |
| 896 | /* user-user */ |
| 897 | if (connect->fields & MNCC_F_USERUSER) |
| 898 | gsm48_encode_useruser(msg, 0, &connect->useruser); |
| 899 | |
| 900 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 901 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 902 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 906 | { |
| 907 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 908 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 909 | struct tlv_parsed tp; |
| 910 | struct gsm_mncc connect; |
| 911 | |
| 912 | gsm48_stop_cc_timer(trans); |
| 913 | |
| 914 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 915 | connect.callref = trans->callref; |
| 916 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 917 | /* use subscriber as connected party number */ |
| 918 | connect.fields |= MNCC_F_CONNECTED; |
| 919 | OSMO_STRLCPY_ARRAY(connect.connected.number, trans->vsub->msisdn); |
| 920 | OSMO_STRLCPY_ARRAY(connect.imsi, trans->vsub->imsi); |
| 921 | |
| 922 | /* facility */ |
| 923 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 924 | connect.fields |= MNCC_F_FACILITY; |
| 925 | gsm48_decode_facility(&connect.facility, |
| 926 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 927 | } |
| 928 | /* user-user */ |
| 929 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 930 | connect.fields |= MNCC_F_USERUSER; |
| 931 | gsm48_decode_useruser(&connect.useruser, |
| 932 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 933 | } |
| 934 | /* ss-version */ |
| 935 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 936 | connect.fields |= MNCC_F_SSVERSION; |
| 937 | gsm48_decode_ssversion(&connect.ssversion, |
| 938 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 939 | } |
| 940 | |
| 941 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 942 | 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] | 943 | |
| 944 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_CNF, &connect); |
| 945 | } |
| 946 | |
| 947 | |
| 948 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 949 | { |
| 950 | struct gsm_mncc connect_ack; |
| 951 | |
| 952 | gsm48_stop_cc_timer(trans); |
| 953 | |
| 954 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 955 | 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] | 956 | |
| 957 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 958 | connect_ack.callref = trans->callref; |
| 959 | |
| 960 | return mncc_recvmsg(trans->net, trans, MNCC_SETUP_COMPL_IND, |
| 961 | &connect_ack); |
| 962 | } |
| 963 | |
| 964 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 965 | { |
| 966 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC CON ACK"); |
| 967 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 968 | |
| 969 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 970 | |
| 971 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 972 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 973 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 977 | { |
| 978 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 979 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 980 | struct tlv_parsed tp; |
| 981 | struct gsm_mncc disc; |
| 982 | |
| 983 | gsm48_stop_cc_timer(trans); |
| 984 | |
| 985 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 986 | |
| 987 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 988 | disc.callref = trans->callref; |
| 989 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0); |
| 990 | /* cause */ |
| 991 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 992 | disc.fields |= MNCC_F_CAUSE; |
| 993 | gsm48_decode_cause(&disc.cause, |
| 994 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 995 | } |
| 996 | /* facility */ |
| 997 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 998 | disc.fields |= MNCC_F_FACILITY; |
| 999 | gsm48_decode_facility(&disc.facility, |
| 1000 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1001 | } |
| 1002 | /* user-user */ |
| 1003 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1004 | disc.fields |= MNCC_F_USERUSER; |
| 1005 | gsm48_decode_useruser(&disc.useruser, |
| 1006 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1007 | } |
| 1008 | /* ss-version */ |
| 1009 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1010 | disc.fields |= MNCC_F_SSVERSION; |
| 1011 | gsm48_decode_ssversion(&disc.ssversion, |
| 1012 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1013 | } |
| 1014 | |
| 1015 | return mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | static struct gsm_mncc_cause default_cause = { |
| 1019 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 1020 | .coding = 0, |
| 1021 | .rec = 0, |
| 1022 | .rec_val = 0, |
| 1023 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 1024 | .diag_len = 0, |
| 1025 | .diag = { 0 }, |
| 1026 | }; |
| 1027 | |
| 1028 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 1029 | { |
| 1030 | struct gsm_mncc *disc = arg; |
| 1031 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC DISC"); |
| 1032 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1033 | |
| 1034 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 1035 | |
| 1036 | gsm48_stop_cc_timer(trans); |
| 1037 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 1038 | |
| 1039 | /* cause */ |
| 1040 | if (disc->fields & MNCC_F_CAUSE) |
| 1041 | gsm48_encode_cause(msg, 1, &disc->cause); |
| 1042 | else |
| 1043 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1044 | |
| 1045 | /* facility */ |
| 1046 | if (disc->fields & MNCC_F_FACILITY) |
| 1047 | gsm48_encode_facility(msg, 0, &disc->facility); |
| 1048 | /* progress */ |
| 1049 | if (disc->fields & MNCC_F_PROGRESS) |
| 1050 | gsm48_encode_progress(msg, 0, &disc->progress); |
| 1051 | /* user-user */ |
| 1052 | if (disc->fields & MNCC_F_USERUSER) |
| 1053 | gsm48_encode_useruser(msg, 0, &disc->useruser); |
| 1054 | |
| 1055 | /* store disconnect cause for T306 expiry */ |
| 1056 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
| 1057 | |
| 1058 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 1059 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1060 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 1064 | { |
| 1065 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1066 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1067 | struct tlv_parsed tp; |
| 1068 | struct gsm_mncc rel; |
| 1069 | int rc; |
| 1070 | |
| 1071 | gsm48_stop_cc_timer(trans); |
| 1072 | |
| 1073 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 1074 | rel.callref = trans->callref; |
| 1075 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1076 | /* cause */ |
| 1077 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1078 | rel.fields |= MNCC_F_CAUSE; |
| 1079 | gsm48_decode_cause(&rel.cause, |
| 1080 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1081 | } |
| 1082 | /* facility */ |
| 1083 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1084 | rel.fields |= MNCC_F_FACILITY; |
| 1085 | gsm48_decode_facility(&rel.facility, |
| 1086 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1087 | } |
| 1088 | /* user-user */ |
| 1089 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1090 | rel.fields |= MNCC_F_USERUSER; |
| 1091 | gsm48_decode_useruser(&rel.useruser, |
| 1092 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1093 | } |
| 1094 | /* ss-version */ |
| 1095 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1096 | rel.fields |= MNCC_F_SSVERSION; |
| 1097 | gsm48_decode_ssversion(&rel.ssversion, |
| 1098 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1099 | } |
| 1100 | |
| 1101 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
| 1102 | /* release collision 5.4.5 */ |
| 1103 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_CNF, &rel); |
| 1104 | } else { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1105 | rc = gsm48_tx_simple(trans->msc_a, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1106 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
| 1107 | GSM48_MT_CC_RELEASE_COMPL); |
| 1108 | rc = mncc_recvmsg(trans->net, trans, MNCC_REL_IND, &rel); |
| 1109 | } |
| 1110 | |
| 1111 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 1112 | |
| 1113 | trans->callref = 0; |
| 1114 | trans_free(trans); |
| 1115 | |
| 1116 | return rc; |
| 1117 | } |
| 1118 | |
| 1119 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 1120 | { |
| 1121 | struct gsm_mncc *rel = arg; |
Neels Hofmeyr | 2e8f881 | 2019-08-21 16:56:41 +0200 | [diff] [blame] | 1122 | struct msgb *msg; |
| 1123 | struct gsm48_hdr *gh; |
| 1124 | |
| 1125 | if (!trans->msc_a) { |
| 1126 | LOG_TRANS(trans, LOGL_DEBUG, "Cannot send CC REL, there is no MSC-A connection\n"); |
| 1127 | return -EINVAL; |
| 1128 | } |
| 1129 | |
| 1130 | msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL"); |
| 1131 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1132 | |
| 1133 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 1134 | |
| 1135 | gsm48_stop_cc_timer(trans); |
| 1136 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 1137 | |
| 1138 | /* cause */ |
| 1139 | if (rel->fields & MNCC_F_CAUSE) |
| 1140 | gsm48_encode_cause(msg, 0, &rel->cause); |
| 1141 | /* facility */ |
| 1142 | if (rel->fields & MNCC_F_FACILITY) |
| 1143 | gsm48_encode_facility(msg, 0, &rel->facility); |
| 1144 | /* user-user */ |
| 1145 | if (rel->fields & MNCC_F_USERUSER) |
| 1146 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
| 1147 | |
| 1148 | trans->cc.T308_second = 0; |
| 1149 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
| 1150 | |
| 1151 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
| 1152 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 1153 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1154 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 1158 | { |
| 1159 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1160 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1161 | struct tlv_parsed tp; |
| 1162 | struct gsm_mncc rel; |
| 1163 | int rc = 0; |
| 1164 | |
| 1165 | gsm48_stop_cc_timer(trans); |
| 1166 | |
| 1167 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 1168 | rel.callref = trans->callref; |
| 1169 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1170 | /* cause */ |
| 1171 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1172 | rel.fields |= MNCC_F_CAUSE; |
| 1173 | gsm48_decode_cause(&rel.cause, |
| 1174 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1175 | } |
| 1176 | /* facility */ |
| 1177 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1178 | rel.fields |= MNCC_F_FACILITY; |
| 1179 | gsm48_decode_facility(&rel.facility, |
| 1180 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1181 | } |
| 1182 | /* user-user */ |
| 1183 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1184 | rel.fields |= MNCC_F_USERUSER; |
| 1185 | gsm48_decode_useruser(&rel.useruser, |
| 1186 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1187 | } |
| 1188 | /* ss-version */ |
| 1189 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1190 | rel.fields |= MNCC_F_SSVERSION; |
| 1191 | gsm48_decode_ssversion(&rel.ssversion, |
| 1192 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1193 | } |
| 1194 | |
| 1195 | if (trans->callref) { |
| 1196 | switch (trans->cc.state) { |
| 1197 | case GSM_CSTATE_CALL_PRESENT: |
| 1198 | rc = mncc_recvmsg(trans->net, trans, |
| 1199 | MNCC_REJ_IND, &rel); |
| 1200 | break; |
| 1201 | case GSM_CSTATE_RELEASE_REQ: |
| 1202 | rc = mncc_recvmsg(trans->net, trans, |
| 1203 | MNCC_REL_CNF, &rel); |
| 1204 | break; |
| 1205 | default: |
| 1206 | rc = mncc_recvmsg(trans->net, trans, |
| 1207 | MNCC_REL_IND, &rel); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | trans->callref = 0; |
| 1212 | trans_free(trans); |
| 1213 | |
| 1214 | return rc; |
| 1215 | } |
| 1216 | |
| 1217 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 1218 | { |
| 1219 | struct gsm_mncc *rel = arg; |
| 1220 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL COMPL"); |
| 1221 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1222 | int ret; |
| 1223 | |
| 1224 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 1225 | |
| 1226 | trans->callref = 0; |
| 1227 | |
| 1228 | gsm48_stop_cc_timer(trans); |
| 1229 | |
| 1230 | /* cause */ |
| 1231 | if (rel->fields & MNCC_F_CAUSE) |
| 1232 | gsm48_encode_cause(msg, 0, &rel->cause); |
| 1233 | /* facility */ |
| 1234 | if (rel->fields & MNCC_F_FACILITY) |
| 1235 | gsm48_encode_facility(msg, 0, &rel->facility); |
| 1236 | /* user-user */ |
| 1237 | if (rel->fields & MNCC_F_USERUSER) |
| 1238 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
| 1239 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1240 | ret = trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1241 | |
| 1242 | trans_free(trans); |
| 1243 | |
| 1244 | return ret; |
| 1245 | } |
| 1246 | |
| 1247 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 1248 | { |
| 1249 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1250 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1251 | struct tlv_parsed tp; |
| 1252 | struct gsm_mncc fac; |
| 1253 | |
| 1254 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 1255 | fac.callref = trans->callref; |
| 1256 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0); |
| 1257 | /* facility */ |
| 1258 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1259 | fac.fields |= MNCC_F_FACILITY; |
| 1260 | gsm48_decode_facility(&fac.facility, |
| 1261 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1262 | } |
| 1263 | /* ss-version */ |
| 1264 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1265 | fac.fields |= MNCC_F_SSVERSION; |
| 1266 | gsm48_decode_ssversion(&fac.ssversion, |
| 1267 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1268 | } |
| 1269 | |
| 1270 | return mncc_recvmsg(trans->net, trans, MNCC_FACILITY_IND, &fac); |
| 1271 | } |
| 1272 | |
| 1273 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 1274 | { |
| 1275 | struct gsm_mncc *fac = arg; |
| 1276 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC FAC"); |
| 1277 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1278 | |
| 1279 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 1280 | |
| 1281 | /* facility */ |
| 1282 | gsm48_encode_facility(msg, 1, &fac->facility); |
| 1283 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1284 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 1288 | { |
| 1289 | struct gsm_mncc hold; |
| 1290 | |
| 1291 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 1292 | hold.callref = trans->callref; |
| 1293 | return mncc_recvmsg(trans->net, trans, MNCC_HOLD_IND, &hold); |
| 1294 | } |
| 1295 | |
| 1296 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 1297 | { |
| 1298 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD ACK"); |
| 1299 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1300 | |
| 1301 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 1302 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1303 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 1307 | { |
| 1308 | struct gsm_mncc *hold_rej = arg; |
| 1309 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD REJ"); |
| 1310 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1311 | |
| 1312 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 1313 | |
| 1314 | /* cause */ |
| 1315 | if (hold_rej->fields & MNCC_F_CAUSE) |
| 1316 | gsm48_encode_cause(msg, 1, &hold_rej->cause); |
| 1317 | else |
| 1318 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1319 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1320 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 1324 | { |
| 1325 | struct gsm_mncc retrieve; |
| 1326 | |
| 1327 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 1328 | retrieve.callref = trans->callref; |
| 1329 | return mncc_recvmsg(trans->net, trans, MNCC_RETRIEVE_IND, |
| 1330 | &retrieve); |
| 1331 | } |
| 1332 | |
| 1333 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 1334 | { |
| 1335 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR ACK"); |
| 1336 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1337 | |
| 1338 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 1339 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1340 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 1344 | { |
| 1345 | struct gsm_mncc *retrieve_rej = arg; |
| 1346 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR REJ"); |
| 1347 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1348 | |
| 1349 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 1350 | |
| 1351 | /* cause */ |
| 1352 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
| 1353 | gsm48_encode_cause(msg, 1, &retrieve_rej->cause); |
| 1354 | else |
| 1355 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1356 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1357 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 1361 | { |
| 1362 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1363 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1364 | struct tlv_parsed tp; |
| 1365 | struct gsm_mncc dtmf; |
| 1366 | |
| 1367 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 1368 | dtmf.callref = trans->callref; |
| 1369 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 1370 | /* keypad facility */ |
| 1371 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 1372 | dtmf.fields |= MNCC_F_KEYPAD; |
| 1373 | gsm48_decode_keypad(&dtmf.keypad, |
| 1374 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 1375 | } |
| 1376 | |
| 1377 | return mncc_recvmsg(trans->net, trans, MNCC_START_DTMF_IND, &dtmf); |
| 1378 | } |
| 1379 | |
| 1380 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 1381 | { |
| 1382 | struct gsm_mncc *dtmf = arg; |
| 1383 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF ACK"); |
| 1384 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1385 | |
| 1386 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 1387 | |
| 1388 | /* keypad */ |
| 1389 | if (dtmf->fields & MNCC_F_KEYPAD) |
| 1390 | gsm48_encode_keypad(msg, dtmf->keypad); |
| 1391 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1392 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 1396 | { |
| 1397 | struct gsm_mncc *dtmf = arg; |
| 1398 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF REJ"); |
| 1399 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1400 | |
| 1401 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 1402 | |
| 1403 | /* cause */ |
| 1404 | if (dtmf->fields & MNCC_F_CAUSE) |
| 1405 | gsm48_encode_cause(msg, 1, &dtmf->cause); |
| 1406 | else |
| 1407 | gsm48_encode_cause(msg, 1, &default_cause); |
| 1408 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1409 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 1413 | { |
| 1414 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF STP ACK"); |
| 1415 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1416 | |
| 1417 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 1418 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1419 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 1423 | { |
| 1424 | struct gsm_mncc dtmf; |
| 1425 | |
| 1426 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 1427 | dtmf.callref = trans->callref; |
| 1428 | |
| 1429 | return mncc_recvmsg(trans->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
| 1430 | } |
| 1431 | |
| 1432 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 1433 | { |
| 1434 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1435 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1436 | struct tlv_parsed tp; |
| 1437 | struct gsm_mncc modify; |
| 1438 | |
| 1439 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 1440 | modify.callref = trans->callref; |
| 1441 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 1442 | /* bearer capability */ |
| 1443 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1444 | modify.fields |= MNCC_F_BEARER_CAP; |
| 1445 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
| 1446 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1447 | |
| 1448 | /* Create a copy of the bearer capability |
| 1449 | * in the transaction struct, so we can use |
| 1450 | * this information later */ |
| 1451 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 1452 | sizeof(trans->bearer_cap)); |
| 1453 | } |
| 1454 | |
| 1455 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 1456 | |
| 1457 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_IND, &modify); |
| 1458 | } |
| 1459 | |
| 1460 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 1461 | { |
| 1462 | struct gsm_mncc *modify = arg; |
| 1463 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD"); |
| 1464 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1465 | |
| 1466 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 1467 | |
| 1468 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 1469 | |
| 1470 | /* bearer capability */ |
| 1471 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 1472 | memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap)); |
| 1473 | |
| 1474 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 1475 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1476 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 1480 | { |
| 1481 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1482 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1483 | struct tlv_parsed tp; |
| 1484 | struct gsm_mncc modify; |
| 1485 | |
| 1486 | gsm48_stop_cc_timer(trans); |
| 1487 | |
| 1488 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 1489 | modify.callref = trans->callref; |
| 1490 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
| 1491 | /* bearer capability */ |
| 1492 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1493 | modify.fields |= MNCC_F_BEARER_CAP; |
| 1494 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
| 1495 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1496 | |
| 1497 | /* Create a copy of the bearer capability |
| 1498 | * in the transaction struct, so we can use |
| 1499 | * this information later */ |
| 1500 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 1501 | sizeof(trans->bearer_cap)); |
| 1502 | } |
| 1503 | |
| 1504 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1505 | |
| 1506 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_CNF, &modify); |
| 1507 | } |
| 1508 | |
| 1509 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 1510 | { |
| 1511 | struct gsm_mncc *modify = arg; |
| 1512 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD COMPL"); |
| 1513 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1514 | |
| 1515 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 1516 | |
| 1517 | /* bearer capability */ |
| 1518 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 1519 | memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap)); |
| 1520 | |
| 1521 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1522 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1523 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 1527 | { |
| 1528 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1529 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1530 | struct tlv_parsed tp; |
| 1531 | struct gsm_mncc modify; |
| 1532 | |
| 1533 | gsm48_stop_cc_timer(trans); |
| 1534 | |
| 1535 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 1536 | modify.callref = trans->callref; |
| 1537 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE); |
| 1538 | /* bearer capability */ |
| 1539 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1540 | modify.fields |= GSM48_IE_BEARER_CAP; |
| 1541 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
| 1542 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1543 | |
| 1544 | /* Create a copy of the bearer capability |
| 1545 | * in the transaction struct, so we can use |
| 1546 | * this information later */ |
| 1547 | memcpy(&trans->bearer_cap,&modify.bearer_cap, |
| 1548 | sizeof(trans->bearer_cap)); |
| 1549 | } |
| 1550 | /* cause */ |
| 1551 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1552 | modify.fields |= MNCC_F_CAUSE; |
| 1553 | gsm48_decode_cause(&modify.cause, |
| 1554 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1555 | } |
| 1556 | |
| 1557 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1558 | |
| 1559 | return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_REJ, &modify); |
| 1560 | } |
| 1561 | |
| 1562 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 1563 | { |
| 1564 | struct gsm_mncc *modify = arg; |
| 1565 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD REJ"); |
| 1566 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1567 | |
| 1568 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 1569 | |
| 1570 | /* bearer capability */ |
| 1571 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
| 1572 | memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap)); |
| 1573 | /* cause */ |
| 1574 | gsm48_encode_cause(msg, 1, &modify->cause); |
| 1575 | |
| 1576 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 1577 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1578 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 1582 | { |
| 1583 | struct gsm_mncc *notify = arg; |
| 1584 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC NOT"); |
| 1585 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1586 | |
| 1587 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 1588 | |
| 1589 | /* notify */ |
| 1590 | gsm48_encode_notify(msg, notify->notify); |
| 1591 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1592 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 1596 | { |
| 1597 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1598 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1599 | // struct tlv_parsed tp; |
| 1600 | struct gsm_mncc notify; |
| 1601 | |
| 1602 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 1603 | notify.callref = trans->callref; |
| 1604 | // tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len); |
| 1605 | if (payload_len >= 1) |
| 1606 | gsm48_decode_notify(¬ify.notify, gh->data); |
| 1607 | |
| 1608 | return mncc_recvmsg(trans->net, trans, MNCC_NOTIFY_IND, ¬ify); |
| 1609 | } |
| 1610 | |
| 1611 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 1612 | { |
| 1613 | struct gsm_mncc *user = arg; |
| 1614 | struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USR INFO"); |
| 1615 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1616 | |
| 1617 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 1618 | |
| 1619 | /* user-user */ |
| 1620 | if (user->fields & MNCC_F_USERUSER) |
| 1621 | gsm48_encode_useruser(msg, 1, &user->useruser); |
| 1622 | /* more data */ |
| 1623 | if (user->more) |
| 1624 | gsm48_encode_more(msg); |
| 1625 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1626 | return trans_tx_gsm48(trans, msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 1630 | { |
| 1631 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1632 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1633 | struct tlv_parsed tp; |
| 1634 | struct gsm_mncc user; |
| 1635 | |
| 1636 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 1637 | user.callref = trans->callref; |
| 1638 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0); |
| 1639 | /* user-user */ |
| 1640 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1641 | user.fields |= MNCC_F_USERUSER; |
| 1642 | gsm48_decode_useruser(&user.useruser, |
| 1643 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1644 | } |
| 1645 | /* more data */ |
| 1646 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 1647 | user.more = 1; |
| 1648 | |
| 1649 | return mncc_recvmsg(trans->net, trans, MNCC_USERINFO_IND, &user); |
| 1650 | } |
| 1651 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1652 | static int mncc_recv_rtp(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, |
| 1653 | int cmd, struct osmo_sockaddr_str *rtp_addr, uint32_t payload_type, |
| 1654 | uint32_t payload_msg_type) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1655 | { |
| 1656 | uint8_t data[sizeof(struct gsm_mncc)]; |
| 1657 | struct gsm_mncc_rtp *rtp; |
| 1658 | |
| 1659 | memset(&data, 0, sizeof(data)); |
| 1660 | rtp = (struct gsm_mncc_rtp *) &data[0]; |
| 1661 | |
| 1662 | rtp->callref = callref; |
| 1663 | rtp->msg_type = cmd; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1664 | if (rtp_addr) { |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 1665 | if (osmo_sockaddr_str_to_sockaddr(rtp_addr, &rtp->addr) < 0) |
| 1666 | return -EINVAL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1667 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1668 | rtp->payload_type = payload_type; |
| 1669 | rtp->payload_msg_type = payload_msg_type; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1670 | return mncc_recvmsg(net, trans, cmd, (struct gsm_mncc *)data); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1671 | } |
| 1672 | |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 1673 | 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] | 1674 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1675 | mncc_recv_rtp(net, trans, callref, cmd, NULL, 0, 0); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | static int tch_rtp_create(struct gsm_network *net, uint32_t callref) |
| 1679 | { |
| 1680 | struct gsm_trans *trans; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1681 | |
| 1682 | /* Find callref */ |
| 1683 | trans = trans_find_by_callref(net, callref); |
| 1684 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1685 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP create for non-existing trans\n"); |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 1686 | mncc_recv_rtp_err(net, trans, callref, MNCC_RTP_CREATE); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1687 | return -EIO; |
| 1688 | } |
| 1689 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1690 | if (!trans->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1691 | LOG_TRANS_CAT(trans, DMNCC, LOGL_NOTICE, "RTP create for trans without conn\n"); |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 1692 | mncc_recv_rtp_err(net, trans, callref, MNCC_RTP_CREATE); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1693 | return 0; |
| 1694 | } |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 1695 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(MNCC_RTP_CREATE)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1696 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1697 | /* Assign call (if not done yet) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1698 | return msc_a_try_call_assignment(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | /* Trigger TCH_RTP_CREATE acknowledgement */ |
| 1702 | int gsm48_tch_rtp_create(struct gsm_trans *trans) |
| 1703 | { |
| 1704 | /* This function is called as soon as the port, on which the |
| 1705 | * mgcp-gw expects the incoming RTP stream from the remote |
| 1706 | * end (e.g. Asterisk) is known. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1707 | struct msc_a *msc_a = trans->msc_a; |
| 1708 | struct gsm_network *net = msc_a_net(msc_a); |
| 1709 | struct call_leg *cl = msc_a->cc.call_leg; |
| 1710 | struct osmo_sockaddr_str *rtp_cn_local; |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 1711 | struct rtp_stream *rtp_cn = cl ? cl->rtp[RTP_TO_CN] : NULL; |
| 1712 | uint32_t payload_type; |
| 1713 | int payload_msg_type; |
| 1714 | const struct mgcp_conn_peer *mgcp_info; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1715 | |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 1716 | if (!rtp_cn) { |
| 1717 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no RTP set up for the CN side\n"); |
| 1718 | return -EINVAL; |
| 1719 | } |
| 1720 | |
| 1721 | if (!rtp_cn->codec_known) { |
| 1722 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, |
| 1723 | "Cannot RTP CREATE to MNCC, no codec set up for the RTP CN side\n"); |
| 1724 | return -EINVAL; |
| 1725 | } |
| 1726 | |
| 1727 | /* Codec */ |
| 1728 | payload_msg_type = mgcp_codec_to_mncc_payload_msg_type(rtp_cn->codec); |
| 1729 | |
| 1730 | /* Payload Type number */ |
| 1731 | mgcp_info = osmo_mgcpc_ep_ci_get_rtp_info(rtp_cn->ci); |
Neels Hofmeyr | 43e8d4d | 2019-08-30 01:05:58 +0200 | [diff] [blame] | 1732 | if (mgcp_info && mgcp_info->ptmap_len) |
| 1733 | payload_type = map_codec_to_pt(mgcp_info->ptmap, mgcp_info->ptmap_len, rtp_cn->codec); |
| 1734 | else |
| 1735 | payload_type = rtp_cn->codec; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1736 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1737 | rtp_cn_local = call_leg_local_ip(cl, RTP_TO_CN); |
| 1738 | if (!rtp_cn_local) { |
| 1739 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no local RTP IP:port set up\n"); |
| 1740 | return -EINVAL; |
| 1741 | } |
| 1742 | |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 1743 | return mncc_recv_rtp(net, trans, trans->callref, MNCC_RTP_CREATE, rtp_cn_local, payload_type, payload_msg_type); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1744 | } |
| 1745 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1746 | 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] | 1747 | { |
| 1748 | struct gsm_trans *trans; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1749 | struct call_leg *cl; |
| 1750 | struct rtp_stream *rtps; |
| 1751 | struct osmo_sockaddr_str rtp_addr; |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 1752 | char ipbuf[INET6_ADDRSTRLEN]; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1753 | |
Philipp Maier | 8ad3dac | 2018-08-07 13:00:14 +0200 | [diff] [blame] | 1754 | /* FIXME: in *rtp we should get the codec information of the remote |
| 1755 | * leg. We will have to populate trans->conn->rtp.codec_cn with a |
| 1756 | * meaningful value based on this information but unfortunately we |
| 1757 | * can't do that yet because the mncc API can not signal dynamic |
| 1758 | * payload types yet. This must be fixed first. Also there may be |
| 1759 | * additional members necessary in trans->conn->rtp because we |
| 1760 | * somehow need to deal with dynamic payload types that do not |
| 1761 | * comply to 3gpp's assumptions of payload type numbers on the A |
| 1762 | * interface. See also related tickets: OS#3399 and OS1683 */ |
| 1763 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1764 | /* Find callref */ |
| 1765 | trans = trans_find_by_callref(net, rtp->callref); |
| 1766 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1767 | 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] | 1768 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1769 | return -EIO; |
| 1770 | } |
| 1771 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1772 | if (!trans->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1773 | 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] | 1774 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1775 | return -EIO; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
Neels Hofmeyr | 90933d4 | 2022-01-13 20:10:52 +0100 | [diff] [blame] | 1778 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s %s:%u\n", get_mncc_name(rtp->msg_type), |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 1779 | osmo_sockaddr_ntop((const struct sockaddr*)&rtp->addr, ipbuf), |
| 1780 | osmo_sockaddr_port((const struct sockaddr*)&rtp->addr)); |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 1781 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1782 | cl = trans->msc_a->cc.call_leg; |
| 1783 | rtps = cl ? cl->rtp[RTP_TO_CN] : NULL; |
| 1784 | |
| 1785 | if (!rtps) { |
| 1786 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for trans without ongoing call\n"); |
| 1787 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
| 1788 | return -EINVAL; |
| 1789 | } |
| 1790 | |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 1791 | if (osmo_sockaddr_str_from_sockaddr(&rtp_addr, &rtp->addr) < 0) { |
| 1792 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect with invalid IP addr\n"); |
| 1793 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
| 1794 | return -EINVAL; |
| 1795 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1796 | rtp_stream_set_remote_addr(rtps, &rtp_addr); |
| 1797 | rtp_stream_commit(rtps); |
| 1798 | return 0; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | static struct downstate { |
| 1802 | uint32_t states; |
| 1803 | int type; |
| 1804 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 1805 | } downstatelist[] = { |
| 1806 | /* mobile originating call establishment */ |
| 1807 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 1808 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc_and_assign}, |
| 1809 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 1810 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 1811 | {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 */ |
| 1812 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 1813 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 1814 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 1815 | /* mobile terminating call establishment */ |
| 1816 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 1817 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 1818 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 1819 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 1820 | /* signalling during call */ |
| 1821 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1822 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 1823 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 1824 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 1825 | {ALL_STATES, |
| 1826 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 1827 | {ALL_STATES, |
| 1828 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 1829 | {ALL_STATES, |
| 1830 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 1831 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1832 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 1833 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1834 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 1835 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1836 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 1837 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1838 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 1839 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1840 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 1841 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 1842 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 1843 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 1844 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 1845 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1846 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 1847 | /* clearing */ |
| 1848 | {SBIT(GSM_CSTATE_INITIATED), |
| 1849 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 1850 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 1851 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 1852 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 1853 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 1854 | }; |
| 1855 | |
| 1856 | #define DOWNSLLEN \ |
| 1857 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 1858 | |
| 1859 | |
Philipp Maier | cd64af7 | 2019-08-01 09:46:40 +0200 | [diff] [blame] | 1860 | 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] | 1861 | { |
| 1862 | int i, rc = 0; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1863 | struct msc_a *msc_a = NULL; |
| 1864 | struct gsm_trans *trans = NULL; |
| 1865 | const struct gsm_mncc *data; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1866 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1867 | /* handle special messages */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1868 | switch(msg->msg_type) { |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1869 | case MNCC_BRIDGE: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1870 | rc = tch_bridge(net, &msg->bridge); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1871 | if (rc < 0) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1872 | disconnect_bridge(net, &msg->bridge, -rc); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1873 | return rc; |
| 1874 | case MNCC_RTP_CREATE: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1875 | return tch_rtp_create(net, msg->rtp.callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1876 | case MNCC_RTP_CONNECT: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1877 | return tch_rtp_connect(net, &msg->rtp); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1878 | case MNCC_RTP_FREE: |
| 1879 | /* unused right now */ |
| 1880 | return -EIO; |
| 1881 | |
| 1882 | case MNCC_FRAME_DROP: |
| 1883 | case MNCC_FRAME_RECV: |
| 1884 | case GSM_TCHF_FRAME: |
| 1885 | case GSM_TCHF_FRAME_EFR: |
| 1886 | case GSM_TCHH_FRAME: |
| 1887 | case GSM_TCH_FRAME_AMR: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1888 | 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] | 1889 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1890 | return -ENOTSUP; |
| 1891 | } |
| 1892 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1893 | data = &msg->signal; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1894 | |
| 1895 | /* Find callref */ |
| 1896 | trans = trans_find_by_callref(net, data->callref); |
| 1897 | |
| 1898 | /* Callref unknown */ |
| 1899 | if (!trans) { |
| 1900 | struct vlr_subscr *vsub; |
| 1901 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1902 | if (msg->msg_type != MNCC_SETUP_REQ) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1903 | 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] | 1904 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1905 | /* Invalid call reference */ |
| 1906 | return mncc_release_ind(net, NULL, data->callref, |
| 1907 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1908 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
| 1909 | } |
| 1910 | if (!data->called.number[0] && !data->imsi[0]) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1911 | 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] | 1912 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1913 | /* Invalid number */ |
| 1914 | return mncc_release_ind(net, NULL, data->callref, |
| 1915 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1916 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 1917 | } |
| 1918 | /* New transaction due to setup, find subscriber */ |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1919 | if (data->called.number[0]) { |
| 1920 | vsub = vlr_subscr_find_by_msisdn(net->vlr, data->called.number, __func__); |
| 1921 | if (!vsub) |
| 1922 | 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] | 1923 | get_mncc_name(msg->msg_type), data->called.number); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1924 | } else { |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1925 | vsub = vlr_subscr_find_by_imsi(net->vlr, data->imsi, __func__); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1926 | if (!vsub) |
| 1927 | 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] | 1928 | get_mncc_name(msg->msg_type), data->imsi); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1929 | } |
| 1930 | if (!vsub) |
| 1931 | 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] | 1932 | GSM48_CC_CAUSE_USER_NOTRESPOND); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1933 | /* update the subscriber we deal with */ |
| 1934 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 1935 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1936 | /* If subscriber is not "attached" */ |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1937 | if (!vsub->lu_complete) { |
| 1938 | 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] | 1939 | get_mncc_name(msg->msg_type), vlr_subscr_name(vsub)); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1940 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1941 | /* Temporarily out of order */ |
| 1942 | return mncc_release_ind(net, NULL, data->callref, |
| 1943 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1944 | GSM48_CC_CAUSE_DEST_OOO); |
| 1945 | } |
Keith Whyte | 991bb42 | 2019-08-08 15:43:40 +0200 | [diff] [blame] | 1946 | |
| 1947 | /* Find valid conn */ |
| 1948 | msc_a = msc_a_for_vsub(vsub, true); |
| 1949 | |
| 1950 | /* If subscriber is BUSY and we do not DO call in call aka "call-waiting" */ |
| 1951 | if (!net->call_waiting && msc_a) { |
| 1952 | struct gsm_trans *existing_cc_trans = trans_find_by_type(msc_a, TRANS_CC); |
| 1953 | if (existing_cc_trans && existing_cc_trans->cc.state != GSM_CSTATE_NULL) { |
| 1954 | LOG_TRANS_CAT(existing_cc_trans, DCC, LOGL_NOTICE, |
| 1955 | "rx '%s' for subscriber %s with trans state (%s)" |
| 1956 | " rejecting with USER_BUSY\n", |
| 1957 | get_mncc_name(msg->msg_type), data->called.number, |
| 1958 | gsm48_cc_state_name(existing_cc_trans->cc.state)); |
| 1959 | return mncc_release_ind(net, NULL, data->callref, |
| 1960 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1961 | GSM48_CC_CAUSE_USER_BUSY); |
| 1962 | } |
| 1963 | } |
| 1964 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1965 | /* Create transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1966 | trans = trans_alloc(net, vsub, TRANS_CC, |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 1967 | TRANS_ID_UNASSIGNED, data->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1968 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1969 | LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1970 | vlr_subscr_put(vsub, __func__); |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 1971 | /* Resource unavailable */ |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1972 | mncc_release_ind(net, NULL, data->callref, |
| 1973 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1974 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 1975 | return -ENOMEM; |
| 1976 | } |
| 1977 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1978 | /* If subscriber has no conn */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1979 | if (!msc_a) { |
Neels Hofmeyr | c67b483 | 2019-10-21 02:34:54 +0200 | [diff] [blame] | 1980 | /* This condition will return before the common logging of the received MNCC message below, so |
| 1981 | * log it now. */ |
| 1982 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(msg->msg_type)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1983 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1984 | /* store setup information until paging succeeds */ |
| 1985 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
| 1986 | |
Neels Hofmeyr | bde605d | 2019-10-21 03:07:25 +0200 | [diff] [blame] | 1987 | /* Request a channel. If Paging already started, paging_request_start() will append the new |
| 1988 | * trans to the already ongoing Paging. */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1989 | trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_CALL_CONVERSATIONAL, |
| 1990 | cc_paging_cb, trans, "MNCC: establish call"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1991 | if (!trans->paging_request) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1992 | LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token.\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1993 | trans_free(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1994 | } |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1995 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1996 | return 0; |
| 1997 | } |
| 1998 | |
| 1999 | /* Assign conn */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2000 | trans->msc_a = msc_a; |
| 2001 | msc_a_get(msc_a, MSC_A_USE_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2002 | trans->dlci = 0x00; /* SAPI=0, not SACCH */ |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 2003 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2004 | } else { |
| 2005 | /* update the subscriber we deal with */ |
| 2006 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 2007 | } |
| 2008 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2009 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(msg->msg_type)); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2010 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 2011 | gsm48_start_guard_timer(trans); |
Neels Hofmeyr | cf90bdb | 2019-10-01 19:47:26 +0200 | [diff] [blame] | 2012 | trans->cc.mncc_initiated = true; |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 2013 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2014 | if (trans->msc_a) |
| 2015 | msc_a = trans->msc_a; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2016 | |
| 2017 | /* if paging did not respond yet */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2018 | if (!msc_a) { |
| 2019 | struct gsm_mncc rel = { |
| 2020 | .callref = data->callref, |
| 2021 | }; |
| 2022 | LOG_TRANS(trans, LOGL_DEBUG, "rx %s in paging state\n", get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2023 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 2024 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2025 | if (msg->msg_type == MNCC_REL_REQ) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2026 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 2027 | else |
| 2028 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 2029 | trans->callref = 0; |
| 2030 | trans_free(trans); |
| 2031 | return rc; |
| 2032 | } else { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2033 | LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2034 | 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] | 2035 | } |
| 2036 | |
| 2037 | /* Find function for current state and message */ |
| 2038 | for (i = 0; i < DOWNSLLEN; i++) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2039 | if ((msg->msg_type == downstatelist[i].type) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2040 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
| 2041 | break; |
| 2042 | if (i == DOWNSLLEN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2043 | LOG_TRANS(trans, LOGL_DEBUG, "Message '%s' unhandled at state '%s'\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2044 | 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] | 2045 | return 0; |
| 2046 | } |
| 2047 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2048 | rc = downstatelist[i].rout(trans, (void*)msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2049 | |
| 2050 | return rc; |
| 2051 | } |
| 2052 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2053 | struct mncc_call *mncc_find_by_callref_from_msg(const union mncc_msg *msg) |
| 2054 | { |
| 2055 | uint32_t callref; |
| 2056 | |
| 2057 | switch (msg->msg_type) { |
| 2058 | case MNCC_BRIDGE: |
| 2059 | callref = msg->bridge.callref[0]; |
| 2060 | break; |
| 2061 | case MNCC_RTP_CREATE: |
| 2062 | case MNCC_RTP_CONNECT: |
| 2063 | callref = msg->rtp.callref; |
| 2064 | break; |
| 2065 | |
| 2066 | case MNCC_RTP_FREE: |
| 2067 | case MNCC_FRAME_DROP: |
| 2068 | case MNCC_FRAME_RECV: |
| 2069 | case GSM_TCHF_FRAME: |
| 2070 | case GSM_TCHF_FRAME_EFR: |
| 2071 | case GSM_TCHH_FRAME: |
| 2072 | case GSM_TCH_FRAME_AMR: |
| 2073 | return NULL; |
| 2074 | |
| 2075 | default: |
| 2076 | callref = msg->signal.callref; |
| 2077 | break; |
| 2078 | } |
| 2079 | |
| 2080 | return mncc_call_find_by_callref(callref); |
| 2081 | } |
| 2082 | |
| 2083 | /* 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] | 2084 | int mncc_tx_to_cc(struct gsm_network *net, void *arg) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2085 | { |
| 2086 | const union mncc_msg *msg = arg; |
| 2087 | struct mncc_call *mncc_call = NULL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2088 | |
| 2089 | if (msg->msg_type == MNCC_SETUP_REQ) { |
| 2090 | /* Incoming call to forward for inter-MSC Handover? */ |
| 2091 | mncc_call = msc_t_check_call_to_handover_number(&msg->signal); |
| 2092 | if (mncc_call) |
| 2093 | LOG_MNCC_CALL(mncc_call, LOGL_DEBUG, |
| 2094 | "Incoming call matches pending inter-MSC Handover Number\n"); |
| 2095 | } |
| 2096 | if (!mncc_call) { |
| 2097 | /* Find already active MNCC FSM for this callref. |
| 2098 | * Currently only for inter-MSC call forwarding, but mncc_fsm could at some point also be used for direct |
| 2099 | * MNCC<->GSM-CC call handling. */ |
| 2100 | mncc_call = mncc_find_by_callref_from_msg(msg); |
| 2101 | } |
| 2102 | if (mncc_call) { |
| 2103 | mncc_call_rx(mncc_call, msg); |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
| 2107 | /* None of the above? Then it must be a normal GSM CC call related message. */ |
| 2108 | return mncc_tx_to_gsm_cc(net, msg); |
| 2109 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2110 | |
| 2111 | static struct datastate { |
| 2112 | uint32_t states; |
| 2113 | int type; |
| 2114 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 2115 | } datastatelist[] = { |
| 2116 | /* mobile originating call establishment */ |
| 2117 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 2118 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 2119 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 2120 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 2121 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 2122 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 2123 | /* mobile terminating call establishment */ |
| 2124 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 2125 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 2126 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 2127 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
| 2128 | {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 */ |
| 2129 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 2130 | /* signalling during call */ |
| 2131 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 2132 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 2133 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2134 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 2135 | {ALL_STATES, |
| 2136 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 2137 | {ALL_STATES, |
| 2138 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 2139 | {ALL_STATES, |
| 2140 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 2141 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2142 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 2143 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2144 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 2145 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2146 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 2147 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 2148 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 2149 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 2150 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 2151 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2152 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 2153 | /* clearing */ |
| 2154 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 2155 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 2156 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 2157 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 2158 | {ALL_STATES, /* 5.4.3.4 */ |
| 2159 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 2160 | }; |
| 2161 | |
| 2162 | #define DATASLLEN \ |
| 2163 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 2164 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2165 | int gsm0408_rcv_cc(struct msc_a *msc_a, struct msgb *msg) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2166 | { |
| 2167 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2168 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
| 2169 | uint8_t transaction_id = gsm48_hdr_trans_id_flip_ti(gh); |
| 2170 | struct gsm_trans *trans = NULL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2171 | struct vlr_subscr *vsub = msc_a_vsub(msc_a); |
| 2172 | struct gsm_network *net = msc_a_net(msc_a); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2173 | int i, rc = 0; |
| 2174 | |
| 2175 | if (msg_type & 0x80) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2176 | 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] | 2177 | return -EINVAL; |
| 2178 | } |
| 2179 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2180 | if (!vsub) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2181 | LOG_TRANS(trans, LOGL_ERROR, "Invalid conn: no subscriber\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2182 | return -EINVAL; |
| 2183 | } |
| 2184 | |
| 2185 | /* Find transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2186 | trans = trans_find_by_id(msc_a, TRANS_CC, transaction_id); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2187 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2188 | /* Create transaction */ |
| 2189 | if (!trans) { |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2190 | /* Create transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2191 | trans = trans_alloc(net, vsub, |
| 2192 | TRANS_CC, |
| 2193 | transaction_id, msc_cc_next_outgoing_callref()); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2194 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2195 | LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2196 | rc = gsm48_tx_simple(msc_a, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2197 | GSM48_PDISC_CC | (transaction_id << 4), |
| 2198 | GSM48_MT_CC_RELEASE_COMPL); |
| 2199 | return -ENOMEM; |
| 2200 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2201 | if (osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans)) { |
| 2202 | LOG_MSC_A(msc_a, LOGL_ERROR, "Not allowed to accept CC transaction\n"); |
| 2203 | trans_free(trans); |
| 2204 | return -EINVAL; |
| 2205 | } |
| 2206 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2207 | /* Assign transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2208 | msc_a_get(msc_a, MSC_A_USE_CC); |
| 2209 | trans->msc_a = msc_a; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2210 | trans->dlci = OMSC_LINKID_CB(msg); /* DLCI as received from BSC */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2211 | |
| 2212 | /* An earlier CM Service Request for this CC message now has concluded */ |
| 2213 | if (!osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_CC)) |
| 2214 | LOG_MSC_A(msc_a, LOGL_ERROR, |
| 2215 | "Creating new CC transaction without prior CM Service Request\n"); |
| 2216 | else |
| 2217 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2218 | } |
| 2219 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2220 | LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n", gsm48_cc_msg_name(msg_type), |
| 2221 | gsm48_cc_state_name(trans->cc.state)); |
| 2222 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2223 | /* find function for current state and message */ |
| 2224 | for (i = 0; i < DATASLLEN; i++) |
| 2225 | if ((msg_type == datastatelist[i].type) |
| 2226 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
| 2227 | break; |
| 2228 | if (i == DATASLLEN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2229 | LOG_TRANS(trans, LOGL_ERROR, "Message unhandled at this state.\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2230 | |
| 2231 | /* If a transaction was just now created, it was a bogus transaction ID, and we need to clean up the |
| 2232 | * transaction right away. */ |
| 2233 | if (trans->cc.state == GSM_CSTATE_NULL) { |
| 2234 | LOG_TRANS(trans, LOGL_ERROR, "Unknown transaction ID for non-SETUP message is not allowed" |
| 2235 | " -- disarding new CC transaction right away\n"); |
| 2236 | trans_free(trans); |
| 2237 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2238 | return 0; |
| 2239 | } |
| 2240 | |
| 2241 | assert(trans->vsub); |
| 2242 | |
| 2243 | rc = datastatelist[i].rout(trans, msg); |
| 2244 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2245 | return rc; |
| 2246 | } |