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