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