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); |
| 1703 | payload_type = map_codec_to_pt(mgcp_info->ptmap, mgcp_info->ptmap_len, rtp_cn->codec); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1704 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1705 | rtp_cn_local = call_leg_local_ip(cl, RTP_TO_CN); |
| 1706 | if (!rtp_cn_local) { |
| 1707 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no local RTP IP:port set up\n"); |
| 1708 | return -EINVAL; |
| 1709 | } |
| 1710 | |
Neels Hofmeyr | 5e19b9a | 2019-04-27 19:09:14 +0200 | [diff] [blame] | 1711 | 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] | 1712 | } |
| 1713 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1714 | 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] | 1715 | { |
| 1716 | struct gsm_trans *trans; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1717 | struct call_leg *cl; |
| 1718 | struct rtp_stream *rtps; |
| 1719 | struct osmo_sockaddr_str rtp_addr; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1720 | |
Philipp Maier | 8ad3dac | 2018-08-07 13:00:14 +0200 | [diff] [blame] | 1721 | /* FIXME: in *rtp we should get the codec information of the remote |
| 1722 | * leg. We will have to populate trans->conn->rtp.codec_cn with a |
| 1723 | * meaningful value based on this information but unfortunately we |
| 1724 | * can't do that yet because the mncc API can not signal dynamic |
| 1725 | * payload types yet. This must be fixed first. Also there may be |
| 1726 | * additional members necessary in trans->conn->rtp because we |
| 1727 | * somehow need to deal with dynamic payload types that do not |
| 1728 | * comply to 3gpp's assumptions of payload type numbers on the A |
| 1729 | * interface. See also related tickets: OS#3399 and OS1683 */ |
| 1730 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1731 | /* Find callref */ |
| 1732 | trans = trans_find_by_callref(net, rtp->callref); |
| 1733 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1734 | 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] | 1735 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1736 | return -EIO; |
| 1737 | } |
| 1738 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1739 | if (!trans->msc_a) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1740 | 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] | 1741 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1742 | return -EIO; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1743 | } |
| 1744 | |
Neels Hofmeyr | c65cfe8 | 2019-04-08 03:48:56 +0200 | [diff] [blame] | 1745 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(MNCC_RTP_CONNECT)); |
| 1746 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1747 | cl = trans->msc_a->cc.call_leg; |
| 1748 | rtps = cl ? cl->rtp[RTP_TO_CN] : NULL; |
| 1749 | |
| 1750 | if (!rtps) { |
| 1751 | LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for trans without ongoing call\n"); |
| 1752 | mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT); |
| 1753 | return -EINVAL; |
| 1754 | } |
| 1755 | |
| 1756 | LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(MNCC_RTP_CONNECT)); |
| 1757 | |
| 1758 | osmo_sockaddr_str_from_32n(&rtp_addr, rtp->ip, rtp->port); |
| 1759 | rtp_stream_set_remote_addr(rtps, &rtp_addr); |
| 1760 | rtp_stream_commit(rtps); |
| 1761 | return 0; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | static struct downstate { |
| 1765 | uint32_t states; |
| 1766 | int type; |
| 1767 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 1768 | } downstatelist[] = { |
| 1769 | /* mobile originating call establishment */ |
| 1770 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 1771 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc_and_assign}, |
| 1772 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 1773 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 1774 | {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 */ |
| 1775 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 1776 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 1777 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 1778 | /* mobile terminating call establishment */ |
| 1779 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 1780 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 1781 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 1782 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 1783 | /* signalling during call */ |
| 1784 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1785 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 1786 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 1787 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 1788 | {ALL_STATES, |
| 1789 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 1790 | {ALL_STATES, |
| 1791 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 1792 | {ALL_STATES, |
| 1793 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 1794 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1795 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 1796 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1797 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 1798 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1799 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 1800 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1801 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 1802 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1803 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 1804 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 1805 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 1806 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 1807 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 1808 | {SBIT(GSM_CSTATE_ACTIVE), |
| 1809 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 1810 | /* clearing */ |
| 1811 | {SBIT(GSM_CSTATE_INITIATED), |
| 1812 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 1813 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 1814 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 1815 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 1816 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 1817 | }; |
| 1818 | |
| 1819 | #define DOWNSLLEN \ |
| 1820 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 1821 | |
| 1822 | |
Philipp Maier | cd64af7 | 2019-08-01 09:46:40 +0200 | [diff] [blame] | 1823 | 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] | 1824 | { |
| 1825 | int i, rc = 0; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1826 | struct msc_a *msc_a = NULL; |
| 1827 | struct gsm_trans *trans = NULL; |
| 1828 | const struct gsm_mncc *data; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1829 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1830 | /* handle special messages */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1831 | switch(msg->msg_type) { |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1832 | case MNCC_BRIDGE: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1833 | rc = tch_bridge(net, &msg->bridge); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1834 | if (rc < 0) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1835 | disconnect_bridge(net, &msg->bridge, -rc); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1836 | return rc; |
| 1837 | case MNCC_RTP_CREATE: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1838 | return tch_rtp_create(net, msg->rtp.callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1839 | case MNCC_RTP_CONNECT: |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1840 | return tch_rtp_connect(net, &msg->rtp); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1841 | case MNCC_RTP_FREE: |
| 1842 | /* unused right now */ |
| 1843 | return -EIO; |
| 1844 | |
| 1845 | case MNCC_FRAME_DROP: |
| 1846 | case MNCC_FRAME_RECV: |
| 1847 | case GSM_TCHF_FRAME: |
| 1848 | case GSM_TCHF_FRAME_EFR: |
| 1849 | case GSM_TCHH_FRAME: |
| 1850 | case GSM_TCH_FRAME_AMR: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1851 | 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] | 1852 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1853 | return -ENOTSUP; |
| 1854 | } |
| 1855 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1856 | data = &msg->signal; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1857 | |
| 1858 | /* Find callref */ |
| 1859 | trans = trans_find_by_callref(net, data->callref); |
| 1860 | |
| 1861 | /* Callref unknown */ |
| 1862 | if (!trans) { |
| 1863 | struct vlr_subscr *vsub; |
| 1864 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1865 | if (msg->msg_type != MNCC_SETUP_REQ) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1866 | 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] | 1867 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1868 | /* Invalid call reference */ |
| 1869 | return mncc_release_ind(net, NULL, data->callref, |
| 1870 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1871 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
| 1872 | } |
| 1873 | if (!data->called.number[0] && !data->imsi[0]) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1874 | 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] | 1875 | get_mncc_name(msg->msg_type)); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1876 | /* Invalid number */ |
| 1877 | return mncc_release_ind(net, NULL, data->callref, |
| 1878 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1879 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 1880 | } |
| 1881 | /* New transaction due to setup, find subscriber */ |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1882 | if (data->called.number[0]) { |
| 1883 | vsub = vlr_subscr_find_by_msisdn(net->vlr, data->called.number, __func__); |
| 1884 | if (!vsub) |
| 1885 | 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] | 1886 | get_mncc_name(msg->msg_type), data->called.number); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1887 | } else { |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1888 | vsub = vlr_subscr_find_by_imsi(net->vlr, data->imsi, __func__); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1889 | if (!vsub) |
| 1890 | 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] | 1891 | get_mncc_name(msg->msg_type), data->imsi); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1892 | } |
| 1893 | if (!vsub) |
| 1894 | return mncc_release_ind(net, NULL, data->callref, GSM48_CAUSE_LOC_PRN_S_LU, |
| 1895 | GSM48_CC_CAUSE_UNASSIGNED_NR); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1896 | /* update the subscriber we deal with */ |
| 1897 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 1898 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1899 | /* If subscriber is not "attached" */ |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1900 | if (!vsub->lu_complete) { |
| 1901 | 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] | 1902 | get_mncc_name(msg->msg_type), vlr_subscr_name(vsub)); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1903 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1904 | /* Temporarily out of order */ |
| 1905 | return mncc_release_ind(net, NULL, data->callref, |
| 1906 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1907 | GSM48_CC_CAUSE_DEST_OOO); |
| 1908 | } |
| 1909 | /* Create transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1910 | trans = trans_alloc(net, vsub, TRANS_CC, |
Max | d8daaae | 2019-02-14 16:54:10 +0700 | [diff] [blame] | 1911 | TRANS_ID_UNASSIGNED, data->callref); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1912 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1913 | LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1914 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1915 | /* Ressource unavailable */ |
| 1916 | mncc_release_ind(net, NULL, data->callref, |
| 1917 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1918 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 1919 | return -ENOMEM; |
| 1920 | } |
| 1921 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1922 | /* Find valid conn */ |
| 1923 | msc_a = msc_a_for_vsub(vsub, true); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1924 | |
| 1925 | /* If subscriber has no conn */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1926 | if (!msc_a) { |
| 1927 | |
| 1928 | if (vsub->cs.is_paging) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1929 | LOG_TRANS(trans, LOGL_DEBUG, |
| 1930 | "rx %s, subscriber not yet connected, paging already started\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1931 | get_mncc_name(msg->msg_type)); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1932 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1933 | trans_free(trans); |
| 1934 | return 0; |
| 1935 | } |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1936 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1937 | /* store setup information until paging succeeds */ |
| 1938 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
| 1939 | |
| 1940 | /* Request a channel */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1941 | trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_CALL_CONVERSATIONAL, |
| 1942 | cc_paging_cb, trans, "MNCC: establish call"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1943 | if (!trans->paging_request) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1944 | LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token.\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1945 | trans_free(trans); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1946 | } |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1947 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | /* Assign conn */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1952 | trans->msc_a = msc_a; |
| 1953 | msc_a_get(msc_a, MSC_A_USE_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1954 | trans->dlci = 0x00; /* SAPI=0, not SACCH */ |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 1955 | vlr_subscr_put(vsub, __func__); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1956 | } else { |
| 1957 | /* update the subscriber we deal with */ |
| 1958 | log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); |
| 1959 | } |
| 1960 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1961 | 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] | 1962 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 1963 | gsm48_start_guard_timer(trans); |
| 1964 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1965 | if (trans->msc_a) |
| 1966 | msc_a = trans->msc_a; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1967 | |
| 1968 | /* if paging did not respond yet */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1969 | if (!msc_a) { |
| 1970 | struct gsm_mncc rel = { |
| 1971 | .callref = data->callref, |
| 1972 | }; |
| 1973 | 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] | 1974 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 1975 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1976 | if (msg->msg_type == MNCC_REL_REQ) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1977 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 1978 | else |
| 1979 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 1980 | trans->callref = 0; |
| 1981 | trans_free(trans); |
| 1982 | return rc; |
| 1983 | } else { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1984 | LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1985 | 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] | 1986 | } |
| 1987 | |
| 1988 | /* Find function for current state and message */ |
| 1989 | for (i = 0; i < DOWNSLLEN; i++) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1990 | if ((msg->msg_type == downstatelist[i].type) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 1991 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
| 1992 | break; |
| 1993 | if (i == DOWNSLLEN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 1994 | LOG_TRANS(trans, LOGL_DEBUG, "Message '%s' unhandled at state '%s'\n", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1995 | 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] | 1996 | return 0; |
| 1997 | } |
| 1998 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1999 | rc = downstatelist[i].rout(trans, (void*)msg); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2000 | |
| 2001 | return rc; |
| 2002 | } |
| 2003 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2004 | struct mncc_call *mncc_find_by_callref_from_msg(const union mncc_msg *msg) |
| 2005 | { |
| 2006 | uint32_t callref; |
| 2007 | |
| 2008 | switch (msg->msg_type) { |
| 2009 | case MNCC_BRIDGE: |
| 2010 | callref = msg->bridge.callref[0]; |
| 2011 | break; |
| 2012 | case MNCC_RTP_CREATE: |
| 2013 | case MNCC_RTP_CONNECT: |
| 2014 | callref = msg->rtp.callref; |
| 2015 | break; |
| 2016 | |
| 2017 | case MNCC_RTP_FREE: |
| 2018 | case MNCC_FRAME_DROP: |
| 2019 | case MNCC_FRAME_RECV: |
| 2020 | case GSM_TCHF_FRAME: |
| 2021 | case GSM_TCHF_FRAME_EFR: |
| 2022 | case GSM_TCHH_FRAME: |
| 2023 | case GSM_TCH_FRAME_AMR: |
| 2024 | return NULL; |
| 2025 | |
| 2026 | default: |
| 2027 | callref = msg->signal.callref; |
| 2028 | break; |
| 2029 | } |
| 2030 | |
| 2031 | return mncc_call_find_by_callref(callref); |
| 2032 | } |
| 2033 | |
| 2034 | /* 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] | 2035 | int mncc_tx_to_cc(struct gsm_network *net, void *arg) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2036 | { |
| 2037 | const union mncc_msg *msg = arg; |
| 2038 | struct mncc_call *mncc_call = NULL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2039 | |
| 2040 | if (msg->msg_type == MNCC_SETUP_REQ) { |
| 2041 | /* Incoming call to forward for inter-MSC Handover? */ |
| 2042 | mncc_call = msc_t_check_call_to_handover_number(&msg->signal); |
| 2043 | if (mncc_call) |
| 2044 | LOG_MNCC_CALL(mncc_call, LOGL_DEBUG, |
| 2045 | "Incoming call matches pending inter-MSC Handover Number\n"); |
| 2046 | } |
| 2047 | if (!mncc_call) { |
| 2048 | /* Find already active MNCC FSM for this callref. |
| 2049 | * Currently only for inter-MSC call forwarding, but mncc_fsm could at some point also be used for direct |
| 2050 | * MNCC<->GSM-CC call handling. */ |
| 2051 | mncc_call = mncc_find_by_callref_from_msg(msg); |
| 2052 | } |
| 2053 | if (mncc_call) { |
| 2054 | mncc_call_rx(mncc_call, msg); |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
| 2058 | /* None of the above? Then it must be a normal GSM CC call related message. */ |
| 2059 | return mncc_tx_to_gsm_cc(net, msg); |
| 2060 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2061 | |
| 2062 | static struct datastate { |
| 2063 | uint32_t states; |
| 2064 | int type; |
| 2065 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 2066 | } datastatelist[] = { |
| 2067 | /* mobile originating call establishment */ |
| 2068 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 2069 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 2070 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 2071 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 2072 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 2073 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 2074 | /* mobile terminating call establishment */ |
| 2075 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 2076 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 2077 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 2078 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
| 2079 | {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 */ |
| 2080 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 2081 | /* signalling during call */ |
| 2082 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 2083 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 2084 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2085 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 2086 | {ALL_STATES, |
| 2087 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 2088 | {ALL_STATES, |
| 2089 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 2090 | {ALL_STATES, |
| 2091 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 2092 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2093 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 2094 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2095 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 2096 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2097 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 2098 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 2099 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 2100 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 2101 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 2102 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2103 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 2104 | /* clearing */ |
| 2105 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 2106 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 2107 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 2108 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 2109 | {ALL_STATES, /* 5.4.3.4 */ |
| 2110 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 2111 | }; |
| 2112 | |
| 2113 | #define DATASLLEN \ |
| 2114 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 2115 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2116 | int gsm0408_rcv_cc(struct msc_a *msc_a, struct msgb *msg) |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2117 | { |
| 2118 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2119 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
| 2120 | uint8_t transaction_id = gsm48_hdr_trans_id_flip_ti(gh); |
| 2121 | struct gsm_trans *trans = NULL; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2122 | struct vlr_subscr *vsub = msc_a_vsub(msc_a); |
| 2123 | struct gsm_network *net = msc_a_net(msc_a); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2124 | int i, rc = 0; |
| 2125 | |
| 2126 | if (msg_type & 0x80) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2127 | 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] | 2128 | return -EINVAL; |
| 2129 | } |
| 2130 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2131 | if (!vsub) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2132 | LOG_TRANS(trans, LOGL_ERROR, "Invalid conn: no subscriber\n"); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2133 | return -EINVAL; |
| 2134 | } |
| 2135 | |
| 2136 | /* Find transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2137 | trans = trans_find_by_id(msc_a, TRANS_CC, transaction_id); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2138 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2139 | /* Create transaction */ |
| 2140 | if (!trans) { |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2141 | /* Create transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2142 | trans = trans_alloc(net, vsub, |
| 2143 | TRANS_CC, |
| 2144 | transaction_id, msc_cc_next_outgoing_callref()); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2145 | if (!trans) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2146 | LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2147 | rc = gsm48_tx_simple(msc_a, |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2148 | GSM48_PDISC_CC | (transaction_id << 4), |
| 2149 | GSM48_MT_CC_RELEASE_COMPL); |
| 2150 | return -ENOMEM; |
| 2151 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2152 | if (osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans)) { |
| 2153 | LOG_MSC_A(msc_a, LOGL_ERROR, "Not allowed to accept CC transaction\n"); |
| 2154 | trans_free(trans); |
| 2155 | return -EINVAL; |
| 2156 | } |
| 2157 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2158 | /* Assign transaction */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2159 | msc_a_get(msc_a, MSC_A_USE_CC); |
| 2160 | trans->msc_a = msc_a; |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2161 | trans->dlci = OMSC_LINKID_CB(msg); /* DLCI as received from BSC */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2162 | |
| 2163 | /* An earlier CM Service Request for this CC message now has concluded */ |
| 2164 | if (!osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_CC)) |
| 2165 | LOG_MSC_A(msc_a, LOGL_ERROR, |
| 2166 | "Creating new CC transaction without prior CM Service Request\n"); |
| 2167 | else |
| 2168 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_CC); |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2169 | } |
| 2170 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2171 | LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n", gsm48_cc_msg_name(msg_type), |
| 2172 | gsm48_cc_state_name(trans->cc.state)); |
| 2173 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2174 | /* find function for current state and message */ |
| 2175 | for (i = 0; i < DATASLLEN; i++) |
| 2176 | if ((msg_type == datastatelist[i].type) |
| 2177 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
| 2178 | break; |
| 2179 | if (i == DATASLLEN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 2180 | LOG_TRANS(trans, LOGL_ERROR, "Message unhandled at this state.\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 2181 | |
| 2182 | /* If a transaction was just now created, it was a bogus transaction ID, and we need to clean up the |
| 2183 | * transaction right away. */ |
| 2184 | if (trans->cc.state == GSM_CSTATE_NULL) { |
| 2185 | LOG_TRANS(trans, LOGL_ERROR, "Unknown transaction ID for non-SETUP message is not allowed" |
| 2186 | " -- disarding new CC transaction right away\n"); |
| 2187 | trans_free(trans); |
| 2188 | } |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | assert(trans->vsub); |
| 2193 | |
| 2194 | rc = datastatelist[i].rout(trans, msg); |
| 2195 | |
Harald Welte | 27989d4 | 2018-06-21 20:39:20 +0200 | [diff] [blame] | 2196 | return rc; |
| 2197 | } |