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