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