blob: a1fea9aa11f0bf4da6a033566d9d46c72a0337f6 [file] [log] [blame]
Harald Welte27989d42018-06-21 20:39:20 +02001/* 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 Hofmeyr5e19b9a2019-04-27 19:09:14 +020033#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
34
Harald Welte27989d42018-06-21 20:39:20 +020035#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 Welte27989d42018-06-21 20:39:20 +020047#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 Hofmeyrc4628a32018-12-07 14:47:34 +010051#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 Welte27989d42018-06-21 20:39:20 +020058
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 Welte27989d42018-06-21 20:39:20 +020069
70#include <assert.h>
71
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010072static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg);
73static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
74static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg);
75
76static 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
85uint32_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 Welte27989d42018-06-21 20:39:20 +020092
Philipp Maier9ca7b312018-10-10 17:00:49 +020093static void gsm48_cc_guard_timeout(void *arg)
94{
95 struct gsm_trans *trans = arg;
Neels Hofmeyrff7074a2019-02-28 05:50:06 +010096 LOG_TRANS(trans, LOGL_DEBUG, "guard timeout expired\n");
Philipp Maier9ca7b312018-10-10 17:00:49 +020097 trans_free(trans);
98 return;
99}
100
101static void gsm48_stop_guard_timer(struct gsm_trans *trans)
102{
103 if (osmo_timer_pending(&trans->cc.timer_guard)) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100104 LOG_TRANS(trans, LOGL_DEBUG, "stopping pending guard timer\n");
Philipp Maier9ca7b312018-10-10 17:00:49 +0200105 osmo_timer_del(&trans->cc.timer_guard);
106 }
107}
108
109static 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 Hofmeyrff7074a2019-02-28 05:50:06 +0100121 LOG_TRANS(trans, LOGL_DEBUG, "starting guard timer with %d seconds\n", trans->net->mncc_guard_timeout);
Philipp Maier9ca7b312018-10-10 17:00:49 +0200122 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 Welte27989d42018-06-21 20:39:20 +0200126
127/* Call Control */
128
129void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg)
130{
131 net->mncc_recv(net, msg);
132}
133
134int 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 Hofmeyrc4628a32018-12-07 14:47:34 +0100148 return trans_tx_gsm48(trans, ss_notify);
Harald Welte27989d42018-06-21 20:39:20 +0200149}
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 */
155static void count_statistics(struct gsm_trans *trans, int new_state)
156{
157 int old_state = trans->cc.state;
158 struct rate_ctr_group *msc = trans->net->msc_ctrs;
159
160 if (old_state == new_state)
161 return;
162
163 /* state incoming */
164 switch (new_state) {
165 case GSM_CSTATE_ACTIVE:
Alexander Couzensefa7b972019-04-27 23:45:37 +0200166 osmo_stat_item_inc(trans->net->statg->items[MSC_STAT_ACTIVE_CALLS], 1);
Harald Welte27989d42018-06-21 20:39:20 +0200167 rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_ACTIVE]);
168 break;
169 }
170
171 /* state outgoing */
172 switch (old_state) {
173 case GSM_CSTATE_ACTIVE:
Alexander Couzensefa7b972019-04-27 23:45:37 +0200174 osmo_stat_item_dec(trans->net->statg->items[MSC_STAT_ACTIVE_CALLS], 1);
Harald Welte27989d42018-06-21 20:39:20 +0200175 if (new_state == GSM_CSTATE_DISCONNECT_REQ ||
176 new_state == GSM_CSTATE_DISCONNECT_IND)
177 rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_COMPLETE]);
178 else
179 rate_ctr_inc(&msc->ctr[MSC_CTR_CALL_INCOMPLETE]);
180 break;
181 }
182}
183
Harald Welte27989d42018-06-21 20:39:20 +0200184static void new_cc_state(struct gsm_trans *trans, int state)
185{
186 if (state > 31 || state < 0)
187 return;
188
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100189 LOG_TRANS(trans, LOGL_DEBUG, "new state %s -> %s\n",
190 gsm48_cc_state_name(trans->cc.state),
191 gsm48_cc_state_name(state));
Harald Welte27989d42018-06-21 20:39:20 +0200192
193 count_statistics(trans, state);
194 trans->cc.state = state;
Philipp Maier9ca7b312018-10-10 17:00:49 +0200195
196 /* Stop the guard timer when a call reaches the active state */
197 if (state == GSM_CSTATE_ACTIVE)
198 gsm48_stop_guard_timer(trans);
Harald Welte27989d42018-06-21 20:39:20 +0200199}
200
201static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg)
202{
203 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STATUS");
204 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
205 uint8_t *cause, *call_state;
206
207 gh->msg_type = GSM48_MT_CC_STATUS;
208
209 cause = msgb_put(msg, 3);
210 cause[0] = 2;
211 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
212 cause[2] = 0x80 | 30; /* response to status inquiry */
213
214 call_state = msgb_put(msg, 1);
215 call_state[0] = 0xc0 | 0x00;
216
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100217 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200218}
219
220static void gsm48_stop_cc_timer(struct gsm_trans *trans)
221{
222 if (osmo_timer_pending(&trans->cc.timer)) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100223 LOG_TRANS(trans, LOGL_DEBUG, "stopping pending timer T%x\n", trans->cc.Tcurrent);
Harald Welte27989d42018-06-21 20:39:20 +0200224 osmo_timer_del(&trans->cc.timer);
225 trans->cc.Tcurrent = 0;
226 }
227}
228
229static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
230 int msg_type, struct gsm_mncc *mncc)
231{
232 struct msgb *msg;
233 unsigned char *data;
234
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100235 LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "tx %s\n", get_mncc_name(msg_type));
Harald Welte27989d42018-06-21 20:39:20 +0200236
237 mncc->msg_type = msg_type;
238
239 msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
240 if (!msg)
241 return -ENOMEM;
242
243 data = msgb_put(msg, sizeof(struct gsm_mncc));
244 memcpy(data, mncc, sizeof(struct gsm_mncc));
245
246 cc_tx_to_mncc(net, msg);
247
248 return 0;
249}
250
251int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans,
252 uint32_t callref, int location, int value)
253{
254 struct gsm_mncc rel;
255
256 memset(&rel, 0, sizeof(rel));
257 rel.callref = callref;
258 mncc_set_cause(&rel, location, value);
259 if (trans && trans->cc.state == GSM_CSTATE_RELEASE_REQ)
260 return mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
261 return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
262}
263
264/* Call Control Specific transaction release.
265 * gets called by trans_free, DO NOT CALL YOURSELF! */
266void _gsm48_cc_trans_free(struct gsm_trans *trans)
267{
268 gsm48_stop_cc_timer(trans);
269
Harald Welte27989d42018-06-21 20:39:20 +0200270 /* send release to L4, if callref still exists */
271 if (trans->callref) {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100272 /* FIXME: currently, a CC trans that would not yet be in state GSM_CSTATE_RELEASE_REQ fails to send a
273 * CC Release to the MS if it gets freed here. Hack it to do so. */
274 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) {
275 struct gsm_mncc rel = {};
276 rel.callref = trans->callref;
277 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
278 gsm48_cc_tx_release(trans, &rel);
279 }
Harald Welte27989d42018-06-21 20:39:20 +0200280 /* Ressource unavailable */
281 mncc_release_ind(trans->net, trans, trans->callref,
282 GSM48_CAUSE_LOC_PRN_S_LU,
283 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
284 /* This is a final freeing of the transaction. The MNCC release may have triggered the
285 * T308 release timer, but we don't have the luxury of graceful CC Release here. */
286 gsm48_stop_cc_timer(trans);
287 }
288 if (trans->cc.state != GSM_CSTATE_NULL)
289 new_cc_state(trans, GSM_CSTATE_NULL);
Philipp Maier9ca7b312018-10-10 17:00:49 +0200290
291 gsm48_stop_guard_timer(trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100292
293 if (trans->msc_a && trans->msc_a->cc.active_trans == trans)
294 trans->msc_a->cc.active_trans = NULL;
Harald Welte27989d42018-06-21 20:39:20 +0200295}
296
Harald Welte27989d42018-06-21 20:39:20 +0200297/* call-back from paging the B-end of the connection */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100298static void cc_paging_cb(struct msc_a *msc_a, struct gsm_trans *trans)
Harald Welte27989d42018-06-21 20:39:20 +0200299{
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100300 if (trans->msc_a) {
301 LOG_MSC_A_CAT(msc_a, DPAG, LOGL_ERROR,
302 "Handle paging error: transaction already associated with subscriber,"
303 " apparently it was already handled. Skip.\n");
304 return;
Harald Welte27989d42018-06-21 20:39:20 +0200305 }
306
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100307 if (msc_a) {
308 LOG_TRANS(trans, LOGL_DEBUG, "Paging succeeded\n");
309 /* Assign conn */
310 msc_a_get(msc_a, MSC_A_USE_CC);
311 trans->msc_a = msc_a;
312 trans->paging_request = NULL;
313 osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans);
314 /* send SETUP request to called party */
315 gsm48_cc_tx_setup(trans, &trans->cc.msg);
316 } else {
317 LOG_TRANS(trans, LOGL_DEBUG, "Paging expired\n");
318 /* Temporarily out of order */
319 mncc_release_ind(trans->net, trans,
320 trans->callref,
321 GSM48_CAUSE_LOC_PRN_S_LU,
322 GSM48_CC_CAUSE_DEST_OOO);
323 trans->callref = 0;
324 trans->paging_request = NULL;
325 trans_free(trans);
326 }
Harald Welte27989d42018-06-21 20:39:20 +0200327}
328
329/* bridge channels of two transactions */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100330static int tch_bridge(struct gsm_network *net, const struct gsm_mncc_bridge *bridge)
Harald Welte27989d42018-06-21 20:39:20 +0200331{
332 struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[0]);
333 struct gsm_trans *trans2 = trans_find_by_callref(net, bridge->callref[1]);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100334 struct call_leg *cl1;
335 struct call_leg *cl2;
Harald Welte27989d42018-06-21 20:39:20 +0200336
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100337 if (!trans1 || !trans2) {
338 LOG_TRANS(trans1 ? : trans2, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs are unset\n");
Harald Welte27989d42018-06-21 20:39:20 +0200339 return -EIO;
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100340 }
Harald Welte27989d42018-06-21 20:39:20 +0200341
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100342 if (!trans1->msc_a || !trans2->msc_a) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100343 LOG_TRANS(trans1, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs lack an active connection\n");
344 LOG_TRANS(trans2, LOGL_ERROR, "Cannot MNCC_BRIDGE, one or both call legs lack an active connection\n");
Harald Welte27989d42018-06-21 20:39:20 +0200345 return -EIO;
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100346 }
347
348 LOG_TRANS(trans1, LOGL_DEBUG, "MNCC_BRIDGE: Local bridge to callref 0x%x\n", trans2->callref);
349 LOG_TRANS(trans2, LOGL_DEBUG, "MNCC_BRIDGE: Local bridge to callref 0x%x\n", trans1->callref);
Harald Welte27989d42018-06-21 20:39:20 +0200350
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100351 /* This call bridging mechanism is only used with the internal MNCC (with external MNCC briding would be done by
352 * the PBX). For inter-MSC Handover scenarios, an external MNCC is mandatory. The conclusion is that in this
353 * code path, there is only one MSC, and the MSC-I role is local, and hence we can directly access the ran_conn.
354 * If we can't, then we must give up. */
355 cl1 = trans1->msc_a->cc.call_leg;
356 cl2 = trans2->msc_a->cc.call_leg;
Harald Welte27989d42018-06-21 20:39:20 +0200357
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100358 return call_leg_local_bridge(cl1, trans1->callref, trans1, cl2, trans2->callref, trans2);
Harald Welte27989d42018-06-21 20:39:20 +0200359}
360
361static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
362{
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100363 LOG_TRANS(trans, LOGL_DEBUG, "-> STATUS ENQ\n");
Harald Welte27989d42018-06-21 20:39:20 +0200364 return gsm48_cc_tx_status(trans, msg);
365}
366
Harald Welte27989d42018-06-21 20:39:20 +0200367static void gsm48_cc_timeout(void *arg)
368{
369 struct gsm_trans *trans = arg;
370 int disconnect = 0, release = 0;
371 int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER;
372 int mo_location = GSM48_CAUSE_LOC_USER;
373 int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC;
374 int l4_location = GSM48_CAUSE_LOC_PRN_S_LU;
375 struct gsm_mncc mo_rel, l4_rel;
376
377 memset(&mo_rel, 0, sizeof(struct gsm_mncc));
378 mo_rel.callref = trans->callref;
379 memset(&l4_rel, 0, sizeof(struct gsm_mncc));
380 l4_rel.callref = trans->callref;
381
382 switch(trans->cc.Tcurrent) {
383 case 0x303:
384 release = 1;
385 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
386 break;
387 case 0x310:
388 disconnect = 1;
389 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
390 break;
391 case 0x313:
392 disconnect = 1;
393 /* unknown, did not find it in the specs */
394 break;
395 case 0x301:
396 disconnect = 1;
397 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
398 break;
399 case 0x308:
400 if (!trans->cc.T308_second) {
401 /* restart T308 a second time */
402 gsm48_cc_tx_release(trans, &trans->cc.msg);
403 trans->cc.T308_second = 1;
404 break; /* stay in release state */
405 }
406 trans_free(trans);
407 return;
408 case 0x306:
409 release = 1;
410 mo_cause = trans->cc.msg.cause.value;
411 mo_location = trans->cc.msg.cause.location;
412 break;
413 case 0x323:
414 disconnect = 1;
415 break;
416 default:
417 release = 1;
418 }
419
420 if (release && trans->callref) {
421 /* process release towards layer 4 */
422 mncc_release_ind(trans->net, trans, trans->callref,
423 l4_location, l4_cause);
424 trans->callref = 0;
425 }
426
427 if (disconnect && trans->callref) {
428 /* process disconnect towards layer 4 */
429 mncc_set_cause(&l4_rel, l4_location, l4_cause);
430 mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &l4_rel);
431 }
432
433 /* process disconnect towards mobile station */
434 if (disconnect || release) {
435 mncc_set_cause(&mo_rel, mo_location, mo_cause);
436 mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0';
437 mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0';
438 mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0';
439 mo_rel.cause.diag_len = 3;
440
441 if (disconnect)
442 gsm48_cc_tx_disconnect(trans, &mo_rel);
443 if (release)
444 gsm48_cc_tx_release(trans, &mo_rel);
445 }
446
447}
448
449/* disconnect both calls from the bridge */
450static inline void disconnect_bridge(struct gsm_network *net,
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100451 const struct gsm_mncc_bridge *bridge, int err)
Harald Welte27989d42018-06-21 20:39:20 +0200452{
453 struct gsm_trans *trans0 = trans_find_by_callref(net, bridge->callref[0]);
454 struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[1]);
455 struct gsm_mncc mx_rel;
456 if (!trans0 || !trans1)
457 return;
458
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100459 LOG_TRANS(trans0, LOGL_ERROR, "Failed to bridge TCH for calls %x <-> %x :: %s \n",
460 trans0->callref, trans1->callref, strerror(err));
461 LOG_TRANS(trans1, LOGL_ERROR, "Failed to bridge TCH for calls %x <-> %x :: %s \n",
Harald Welte27989d42018-06-21 20:39:20 +0200462 trans0->callref, trans1->callref, strerror(err));
463
464 memset(&mx_rel, 0, sizeof(struct gsm_mncc));
465 mncc_set_cause(&mx_rel, GSM48_CAUSE_LOC_INN_NET,
466 GSM48_CC_CAUSE_CHAN_UNACCEPT);
467
468 mx_rel.callref = trans0->callref;
469 gsm48_cc_tx_disconnect(trans0, &mx_rel);
470
471 mx_rel.callref = trans1->callref;
472 gsm48_cc_tx_disconnect(trans1, &mx_rel);
473}
474
475static void gsm48_start_cc_timer(struct gsm_trans *trans, int current,
476 int sec, int micro)
477{
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100478 LOG_TRANS(trans, LOGL_DEBUG, "starting timer T%x with %d seconds\n", current, sec);
Harald Welte27989d42018-06-21 20:39:20 +0200479 osmo_timer_setup(&trans->cc.timer, gsm48_cc_timeout, trans);
480 osmo_timer_schedule(&trans->cc.timer, sec, micro);
481 trans->cc.Tcurrent = current;
482}
483
484static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
485{
486 struct gsm48_hdr *gh = msgb_l3(msg);
487 uint8_t msg_type = gsm48_hdr_msg_type(gh);
488 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
489 struct tlv_parsed tp;
490 struct gsm_mncc setup;
491
Philipp Maier9ca7b312018-10-10 17:00:49 +0200492 gsm48_start_guard_timer(trans);
493
Harald Welte27989d42018-06-21 20:39:20 +0200494 memset(&setup, 0, sizeof(struct gsm_mncc));
495 setup.callref = trans->callref;
496
497 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
498 /* emergency setup is identified by msg_type */
499 if (msg_type == GSM48_MT_CC_EMERG_SETUP) {
500 setup.fields |= MNCC_F_EMERGENCY;
501 setup.emergency = 1;
502 /* use destination number as configured by user (if any) */
503 if (trans->net->emergency.route_to_msisdn) {
504 setup.fields |= MNCC_F_CALLED;
505 setup.called.type = 0; /* unknown */
506 setup.called.plan = 0; /* unknown */
507 OSMO_STRLCPY_ARRAY(setup.called.number,
508 trans->net->emergency.route_to_msisdn);
509 }
510 }
511
512 /* use subscriber as calling party number */
513 setup.fields |= MNCC_F_CALLING;
514 OSMO_STRLCPY_ARRAY(setup.calling.number, trans->vsub->msisdn);
515 OSMO_STRLCPY_ARRAY(setup.imsi, trans->vsub->imsi);
516
517 /* bearer capability */
518 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
519 setup.fields |= MNCC_F_BEARER_CAP;
520 gsm48_decode_bearer_cap(&setup.bearer_cap,
521 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
522
523 /* Create a copy of the bearer capability
524 * in the transaction struct, so we can use
525 * this information later */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100526 memcpy(&trans->bearer_cap, &setup.bearer_cap,
Harald Welte27989d42018-06-21 20:39:20 +0200527 sizeof(trans->bearer_cap));
528 }
529 /* facility */
530 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
531 setup.fields |= MNCC_F_FACILITY;
532 gsm48_decode_facility(&setup.facility,
533 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
534 }
535 /* called party bcd number */
536 if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
537 setup.fields |= MNCC_F_CALLED;
538 gsm48_decode_called(&setup.called,
539 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
540 }
541 /* user-user */
542 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
543 setup.fields |= MNCC_F_USERUSER;
544 gsm48_decode_useruser(&setup.useruser,
545 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
546 }
547 /* ss-version */
548 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
549 setup.fields |= MNCC_F_SSVERSION;
550 gsm48_decode_ssversion(&setup.ssversion,
551 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
552 }
553 /* CLIR suppression */
554 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP))
555 setup.clir.sup = 1;
556 /* CLIR invocation */
557 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC))
558 setup.clir.inv = 1;
559 /* cc cap */
560 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
561 setup.fields |= MNCC_F_CCCAP;
562 gsm48_decode_cccap(&setup.cccap,
563 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
564 }
565
566 new_cc_state(trans, GSM_CSTATE_INITIATED);
567
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100568 LOG_TRANS(trans, setup.emergency ? LOGL_NOTICE : LOGL_INFO, "%sSETUP to %s\n",
569 setup.emergency ? "EMERGENCY_" : "", setup.called.number);
Harald Welte27989d42018-06-21 20:39:20 +0200570
571 rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MO_SETUP]);
572
573 /* indicate setup to MNCC */
574 mncc_recvmsg(trans->net, trans, MNCC_SETUP_IND, &setup);
575
576 /* MNCC code will modify the channel asynchronously, we should
577 * ipaccess-bind only after the modification has been made to the
578 * lchan->tch_mode */
579 return 0;
580}
581
582static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg)
583{
584 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC STUP");
585 struct gsm48_hdr *gh;
586 struct gsm_mncc *setup = arg;
587 int rc, trans_id;
588
589 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
590
591 /* transaction id must not be assigned */
Maxd8daaae2019-02-14 16:54:10 +0700592 if (trans->transaction_id != TRANS_ID_UNASSIGNED) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +0100593 LOG_TRANS(trans, LOGL_DEBUG, "TX Setup with assigned transaction. "
Harald Welte27989d42018-06-21 20:39:20 +0200594 "This is not allowed!\n");
595 /* Temporarily out of order */
596 rc = mncc_release_ind(trans->net, trans, trans->callref,
597 GSM48_CAUSE_LOC_PRN_S_LU,
598 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
599 trans->callref = 0;
600 trans_free(trans);
Neels Hofmeyr61ae18c2019-08-28 03:41:05 +0200601 msgb_free(msg);
Harald Welte27989d42018-06-21 20:39:20 +0200602 return rc;
603 }
604
605 /* Get free transaction_id */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100606 trans_id = trans_assign_trans_id(trans->net, trans->vsub, TRANS_CC);
Harald Welte27989d42018-06-21 20:39:20 +0200607 if (trans_id < 0) {
608 /* no free transaction ID */
609 rc = mncc_release_ind(trans->net, trans, trans->callref,
610 GSM48_CAUSE_LOC_PRN_S_LU,
611 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
612 trans->callref = 0;
613 trans_free(trans);
Neels Hofmeyr61ae18c2019-08-28 03:41:05 +0200614 msgb_free(msg);
Harald Welte27989d42018-06-21 20:39:20 +0200615 return rc;
616 }
617 trans->transaction_id = trans_id;
618
619 gh->msg_type = GSM48_MT_CC_SETUP;
620
621 gsm48_start_cc_timer(trans, 0x303, GSM48_T303);
622
623 /* bearer capability */
624 if (setup->fields & MNCC_F_BEARER_CAP) {
625 /* Create a copy of the bearer capability in the transaction struct, so we
626 * can use this information later */
627 memcpy(&trans->bearer_cap, &setup->bearer_cap, sizeof(trans->bearer_cap));
628 gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap);
629 }
630 /* facility */
631 if (setup->fields & MNCC_F_FACILITY)
632 gsm48_encode_facility(msg, 0, &setup->facility);
633 /* progress */
634 if (setup->fields & MNCC_F_PROGRESS)
635 gsm48_encode_progress(msg, 0, &setup->progress);
636 /* calling party BCD number */
637 if (setup->fields & MNCC_F_CALLING)
638 gsm48_encode_calling(msg, &setup->calling);
639 /* called party BCD number */
640 if (setup->fields & MNCC_F_CALLED)
641 gsm48_encode_called(msg, &setup->called);
642 /* user-user */
643 if (setup->fields & MNCC_F_USERUSER)
644 gsm48_encode_useruser(msg, 0, &setup->useruser);
645 /* redirecting party BCD number */
646 if (setup->fields & MNCC_F_REDIRECTING)
647 gsm48_encode_redirecting(msg, &setup->redirecting);
648 /* signal */
649 if (setup->fields & MNCC_F_SIGNAL)
650 gsm48_encode_signal(msg, setup->signal);
651
652 new_cc_state(trans, GSM_CSTATE_CALL_PRESENT);
653
654 rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MT_SETUP]);
655
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100656 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200657}
658
659static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
660{
661 struct gsm48_hdr *gh = msgb_l3(msg);
662 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
663 struct tlv_parsed tp;
664 struct gsm_mncc call_conf;
665 int rc;
666
667 gsm48_stop_cc_timer(trans);
668 gsm48_start_cc_timer(trans, 0x310, GSM48_T310);
669
670 memset(&call_conf, 0, sizeof(struct gsm_mncc));
671 call_conf.callref = trans->callref;
672
673 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
674#if 0
675 /* repeat */
676 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR))
677 call_conf.repeat = 1;
678 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ))
679 call_conf.repeat = 2;
680#endif
681 /* bearer capability */
682 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
683 call_conf.fields |= MNCC_F_BEARER_CAP;
684 gsm48_decode_bearer_cap(&call_conf.bearer_cap,
685 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
686
687 /* Create a copy of the bearer capability
688 * in the transaction struct, so we can use
689 * this information later */
690 memcpy(&trans->bearer_cap,&call_conf.bearer_cap,
691 sizeof(trans->bearer_cap));
692 }
693 /* cause */
694 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
695 call_conf.fields |= MNCC_F_CAUSE;
696 gsm48_decode_cause(&call_conf.cause,
697 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
698 }
699 /* cc cap */
700 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
701 call_conf.fields |= MNCC_F_CCCAP;
702 gsm48_decode_cccap(&call_conf.cccap,
703 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
704 }
705
706 /* IMSI of called subscriber */
707 OSMO_STRLCPY_ARRAY(call_conf.imsi, trans->vsub->imsi);
708
709 new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
710
711 /* Assign call (if not done yet) */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100712 rc = msc_a_try_call_assignment(trans);
Harald Welte27989d42018-06-21 20:39:20 +0200713
714 /* don't continue, if there were problems with
715 * the call assignment. */
716 if (rc)
717 return rc;
718
719 return mncc_recvmsg(trans->net, trans, MNCC_CALL_CONF_IND,
720 &call_conf);
721}
722
723static int gsm48_cc_tx_call_proc_and_assign(struct gsm_trans *trans, void *arg)
724{
725 struct gsm_mncc *proceeding = arg;
726 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROC");
727 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
728 int rc;
729
730 gh->msg_type = GSM48_MT_CC_CALL_PROC;
731
732 new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC);
733
734 /* bearer capability */
735 if (proceeding->fields & MNCC_F_BEARER_CAP) {
736 gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap);
737 memcpy(&trans->bearer_cap, &proceeding->bearer_cap, sizeof(trans->bearer_cap));
738 }
739 /* facility */
740 if (proceeding->fields & MNCC_F_FACILITY)
741 gsm48_encode_facility(msg, 0, &proceeding->facility);
742 /* progress */
743 if (proceeding->fields & MNCC_F_PROGRESS)
744 gsm48_encode_progress(msg, 0, &proceeding->progress);
745
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100746 rc = trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200747 if (rc)
748 return rc;
749
750 /* Assign call (if not done yet) */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100751 return msc_a_try_call_assignment(trans);
Harald Welte27989d42018-06-21 20:39:20 +0200752}
753
754static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
755{
756 struct gsm48_hdr *gh = msgb_l3(msg);
757 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
758 struct tlv_parsed tp;
759 struct gsm_mncc alerting;
760
761 gsm48_stop_cc_timer(trans);
762 gsm48_start_cc_timer(trans, 0x301, GSM48_T301);
763
764 memset(&alerting, 0, sizeof(struct gsm_mncc));
765 alerting.callref = trans->callref;
766 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
767 /* facility */
768 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
769 alerting.fields |= MNCC_F_FACILITY;
770 gsm48_decode_facility(&alerting.facility,
771 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
772 }
773
774 /* progress */
775 if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) {
776 alerting.fields |= MNCC_F_PROGRESS;
777 gsm48_decode_progress(&alerting.progress,
778 TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1);
779 }
780 /* ss-version */
781 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
782 alerting.fields |= MNCC_F_SSVERSION;
783 gsm48_decode_ssversion(&alerting.ssversion,
784 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
785 }
786
787 new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED);
788
789 return mncc_recvmsg(trans->net, trans, MNCC_ALERT_IND,
790 &alerting);
791}
792
793static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg)
794{
795 struct gsm_mncc *alerting = arg;
796 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC ALERT");
797 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
798
799 gh->msg_type = GSM48_MT_CC_ALERTING;
800
801 /* facility */
802 if (alerting->fields & MNCC_F_FACILITY)
803 gsm48_encode_facility(msg, 0, &alerting->facility);
804 /* progress */
805 if (alerting->fields & MNCC_F_PROGRESS)
806 gsm48_encode_progress(msg, 0, &alerting->progress);
807 /* user-user */
808 if (alerting->fields & MNCC_F_USERUSER)
809 gsm48_encode_useruser(msg, 0, &alerting->useruser);
810
811 new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED);
812
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100813 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200814}
815
816static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg)
817{
818 struct gsm_mncc *progress = arg;
819 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC PROGRESS");
820 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
821
822 gh->msg_type = GSM48_MT_CC_PROGRESS;
823
824 /* progress */
825 gsm48_encode_progress(msg, 1, &progress->progress);
826 /* user-user */
827 if (progress->fields & MNCC_F_USERUSER)
828 gsm48_encode_useruser(msg, 0, &progress->useruser);
829
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100830 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200831}
832
833static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg)
834{
835 struct gsm_mncc *connect = arg;
836 struct msgb *msg = gsm48_msgb_alloc_name("GSN 04.08 CC CON");
837 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
838
839 gh->msg_type = GSM48_MT_CC_CONNECT;
840
841 gsm48_stop_cc_timer(trans);
842 gsm48_start_cc_timer(trans, 0x313, GSM48_T313);
843
844 /* facility */
845 if (connect->fields & MNCC_F_FACILITY)
846 gsm48_encode_facility(msg, 0, &connect->facility);
847 /* progress */
848 if (connect->fields & MNCC_F_PROGRESS)
849 gsm48_encode_progress(msg, 0, &connect->progress);
850 /* connected number */
851 if (connect->fields & MNCC_F_CONNECTED)
852 gsm48_encode_connected(msg, &connect->connected);
853 /* user-user */
854 if (connect->fields & MNCC_F_USERUSER)
855 gsm48_encode_useruser(msg, 0, &connect->useruser);
856
857 new_cc_state(trans, GSM_CSTATE_CONNECT_IND);
858
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100859 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200860}
861
862static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
863{
864 struct gsm48_hdr *gh = msgb_l3(msg);
865 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
866 struct tlv_parsed tp;
867 struct gsm_mncc connect;
868
869 gsm48_stop_cc_timer(trans);
870
871 memset(&connect, 0, sizeof(struct gsm_mncc));
872 connect.callref = trans->callref;
873 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
874 /* use subscriber as connected party number */
875 connect.fields |= MNCC_F_CONNECTED;
876 OSMO_STRLCPY_ARRAY(connect.connected.number, trans->vsub->msisdn);
877 OSMO_STRLCPY_ARRAY(connect.imsi, trans->vsub->imsi);
878
879 /* facility */
880 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
881 connect.fields |= MNCC_F_FACILITY;
882 gsm48_decode_facility(&connect.facility,
883 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
884 }
885 /* user-user */
886 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
887 connect.fields |= MNCC_F_USERUSER;
888 gsm48_decode_useruser(&connect.useruser,
889 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
890 }
891 /* ss-version */
892 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
893 connect.fields |= MNCC_F_SSVERSION;
894 gsm48_decode_ssversion(&connect.ssversion,
895 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
896 }
897
898 new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST);
899 rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MT_CONNECT]);
900
901 return mncc_recvmsg(trans->net, trans, MNCC_SETUP_CNF, &connect);
902}
903
904
905static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg)
906{
907 struct gsm_mncc connect_ack;
908
909 gsm48_stop_cc_timer(trans);
910
911 new_cc_state(trans, GSM_CSTATE_ACTIVE);
912 rate_ctr_inc(&trans->net->msc_ctrs->ctr[MSC_CTR_CALL_MO_CONNECT_ACK]);
913
914 memset(&connect_ack, 0, sizeof(struct gsm_mncc));
915 connect_ack.callref = trans->callref;
916
917 return mncc_recvmsg(trans->net, trans, MNCC_SETUP_COMPL_IND,
918 &connect_ack);
919}
920
921static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg)
922{
923 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC CON ACK");
924 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
925
926 gh->msg_type = GSM48_MT_CC_CONNECT_ACK;
927
928 new_cc_state(trans, GSM_CSTATE_ACTIVE);
929
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100930 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +0200931}
932
933static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg)
934{
935 struct gsm48_hdr *gh = msgb_l3(msg);
936 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
937 struct tlv_parsed tp;
938 struct gsm_mncc disc;
939
940 gsm48_stop_cc_timer(trans);
941
942 new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ);
943
944 memset(&disc, 0, sizeof(struct gsm_mncc));
945 disc.callref = trans->callref;
946 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0);
947 /* cause */
948 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
949 disc.fields |= MNCC_F_CAUSE;
950 gsm48_decode_cause(&disc.cause,
951 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
952 }
953 /* facility */
954 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
955 disc.fields |= MNCC_F_FACILITY;
956 gsm48_decode_facility(&disc.facility,
957 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
958 }
959 /* user-user */
960 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
961 disc.fields |= MNCC_F_USERUSER;
962 gsm48_decode_useruser(&disc.useruser,
963 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
964 }
965 /* ss-version */
966 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
967 disc.fields |= MNCC_F_SSVERSION;
968 gsm48_decode_ssversion(&disc.ssversion,
969 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
970 }
971
972 return mncc_recvmsg(trans->net, trans, MNCC_DISC_IND, &disc);
Harald Welte27989d42018-06-21 20:39:20 +0200973}
974
975static struct gsm_mncc_cause default_cause = {
976 .location = GSM48_CAUSE_LOC_PRN_S_LU,
977 .coding = 0,
978 .rec = 0,
979 .rec_val = 0,
980 .value = GSM48_CC_CAUSE_NORMAL_UNSPEC,
981 .diag_len = 0,
982 .diag = { 0 },
983};
984
985static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg)
986{
987 struct gsm_mncc *disc = arg;
988 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC DISC");
989 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
990
991 gh->msg_type = GSM48_MT_CC_DISCONNECT;
992
993 gsm48_stop_cc_timer(trans);
994 gsm48_start_cc_timer(trans, 0x306, GSM48_T306);
995
996 /* cause */
997 if (disc->fields & MNCC_F_CAUSE)
998 gsm48_encode_cause(msg, 1, &disc->cause);
999 else
1000 gsm48_encode_cause(msg, 1, &default_cause);
1001
1002 /* facility */
1003 if (disc->fields & MNCC_F_FACILITY)
1004 gsm48_encode_facility(msg, 0, &disc->facility);
1005 /* progress */
1006 if (disc->fields & MNCC_F_PROGRESS)
1007 gsm48_encode_progress(msg, 0, &disc->progress);
1008 /* user-user */
1009 if (disc->fields & MNCC_F_USERUSER)
1010 gsm48_encode_useruser(msg, 0, &disc->useruser);
1011
1012 /* store disconnect cause for T306 expiry */
1013 memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc));
1014
1015 new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND);
1016
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001017 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001018}
1019
1020static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg)
1021{
1022 struct gsm48_hdr *gh = msgb_l3(msg);
1023 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1024 struct tlv_parsed tp;
1025 struct gsm_mncc rel;
1026 int rc;
1027
1028 gsm48_stop_cc_timer(trans);
1029
1030 memset(&rel, 0, sizeof(struct gsm_mncc));
1031 rel.callref = trans->callref;
1032 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
1033 /* cause */
1034 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1035 rel.fields |= MNCC_F_CAUSE;
1036 gsm48_decode_cause(&rel.cause,
1037 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1038 }
1039 /* facility */
1040 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1041 rel.fields |= MNCC_F_FACILITY;
1042 gsm48_decode_facility(&rel.facility,
1043 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1044 }
1045 /* user-user */
1046 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1047 rel.fields |= MNCC_F_USERUSER;
1048 gsm48_decode_useruser(&rel.useruser,
1049 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1050 }
1051 /* ss-version */
1052 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1053 rel.fields |= MNCC_F_SSVERSION;
1054 gsm48_decode_ssversion(&rel.ssversion,
1055 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1056 }
1057
1058 if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) {
1059 /* release collision 5.4.5 */
1060 rc = mncc_recvmsg(trans->net, trans, MNCC_REL_CNF, &rel);
1061 } else {
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001062 rc = gsm48_tx_simple(trans->msc_a,
Harald Welte27989d42018-06-21 20:39:20 +02001063 GSM48_PDISC_CC | (trans->transaction_id << 4),
1064 GSM48_MT_CC_RELEASE_COMPL);
1065 rc = mncc_recvmsg(trans->net, trans, MNCC_REL_IND, &rel);
1066 }
1067
1068 new_cc_state(trans, GSM_CSTATE_NULL);
1069
1070 trans->callref = 0;
1071 trans_free(trans);
1072
1073 return rc;
1074}
1075
1076static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg)
1077{
1078 struct gsm_mncc *rel = arg;
1079 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL");
1080 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1081
1082 gh->msg_type = GSM48_MT_CC_RELEASE;
1083
1084 gsm48_stop_cc_timer(trans);
1085 gsm48_start_cc_timer(trans, 0x308, GSM48_T308);
1086
1087 /* cause */
1088 if (rel->fields & MNCC_F_CAUSE)
1089 gsm48_encode_cause(msg, 0, &rel->cause);
1090 /* facility */
1091 if (rel->fields & MNCC_F_FACILITY)
1092 gsm48_encode_facility(msg, 0, &rel->facility);
1093 /* user-user */
1094 if (rel->fields & MNCC_F_USERUSER)
1095 gsm48_encode_useruser(msg, 0, &rel->useruser);
1096
1097 trans->cc.T308_second = 0;
1098 memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc));
1099
1100 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ)
1101 new_cc_state(trans, GSM_CSTATE_RELEASE_REQ);
1102
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001103 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001104}
1105
1106static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
1107{
1108 struct gsm48_hdr *gh = msgb_l3(msg);
1109 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1110 struct tlv_parsed tp;
1111 struct gsm_mncc rel;
1112 int rc = 0;
1113
1114 gsm48_stop_cc_timer(trans);
1115
1116 memset(&rel, 0, sizeof(struct gsm_mncc));
1117 rel.callref = trans->callref;
1118 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
1119 /* cause */
1120 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1121 rel.fields |= MNCC_F_CAUSE;
1122 gsm48_decode_cause(&rel.cause,
1123 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1124 }
1125 /* facility */
1126 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1127 rel.fields |= MNCC_F_FACILITY;
1128 gsm48_decode_facility(&rel.facility,
1129 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1130 }
1131 /* user-user */
1132 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1133 rel.fields |= MNCC_F_USERUSER;
1134 gsm48_decode_useruser(&rel.useruser,
1135 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1136 }
1137 /* ss-version */
1138 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1139 rel.fields |= MNCC_F_SSVERSION;
1140 gsm48_decode_ssversion(&rel.ssversion,
1141 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1142 }
1143
1144 if (trans->callref) {
1145 switch (trans->cc.state) {
1146 case GSM_CSTATE_CALL_PRESENT:
1147 rc = mncc_recvmsg(trans->net, trans,
1148 MNCC_REJ_IND, &rel);
1149 break;
1150 case GSM_CSTATE_RELEASE_REQ:
1151 rc = mncc_recvmsg(trans->net, trans,
1152 MNCC_REL_CNF, &rel);
1153 break;
1154 default:
1155 rc = mncc_recvmsg(trans->net, trans,
1156 MNCC_REL_IND, &rel);
1157 }
1158 }
1159
1160 trans->callref = 0;
1161 trans_free(trans);
1162
1163 return rc;
1164}
1165
1166static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg)
1167{
1168 struct gsm_mncc *rel = arg;
1169 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC REL COMPL");
1170 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1171 int ret;
1172
1173 gh->msg_type = GSM48_MT_CC_RELEASE_COMPL;
1174
1175 trans->callref = 0;
1176
1177 gsm48_stop_cc_timer(trans);
1178
1179 /* cause */
1180 if (rel->fields & MNCC_F_CAUSE)
1181 gsm48_encode_cause(msg, 0, &rel->cause);
1182 /* facility */
1183 if (rel->fields & MNCC_F_FACILITY)
1184 gsm48_encode_facility(msg, 0, &rel->facility);
1185 /* user-user */
1186 if (rel->fields & MNCC_F_USERUSER)
1187 gsm48_encode_useruser(msg, 0, &rel->useruser);
1188
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001189 ret = trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001190
1191 trans_free(trans);
1192
1193 return ret;
1194}
1195
1196static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg)
1197{
1198 struct gsm48_hdr *gh = msgb_l3(msg);
1199 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1200 struct tlv_parsed tp;
1201 struct gsm_mncc fac;
1202
1203 memset(&fac, 0, sizeof(struct gsm_mncc));
1204 fac.callref = trans->callref;
1205 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0);
1206 /* facility */
1207 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1208 fac.fields |= MNCC_F_FACILITY;
1209 gsm48_decode_facility(&fac.facility,
1210 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1211 }
1212 /* ss-version */
1213 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1214 fac.fields |= MNCC_F_SSVERSION;
1215 gsm48_decode_ssversion(&fac.ssversion,
1216 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1217 }
1218
1219 return mncc_recvmsg(trans->net, trans, MNCC_FACILITY_IND, &fac);
1220}
1221
1222static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg)
1223{
1224 struct gsm_mncc *fac = arg;
1225 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC FAC");
1226 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1227
1228 gh->msg_type = GSM48_MT_CC_FACILITY;
1229
1230 /* facility */
1231 gsm48_encode_facility(msg, 1, &fac->facility);
1232
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001233 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001234}
1235
1236static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg)
1237{
1238 struct gsm_mncc hold;
1239
1240 memset(&hold, 0, sizeof(struct gsm_mncc));
1241 hold.callref = trans->callref;
1242 return mncc_recvmsg(trans->net, trans, MNCC_HOLD_IND, &hold);
1243}
1244
1245static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg)
1246{
1247 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD ACK");
1248 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1249
1250 gh->msg_type = GSM48_MT_CC_HOLD_ACK;
1251
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001252 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001253}
1254
1255static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg)
1256{
1257 struct gsm_mncc *hold_rej = arg;
1258 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC HLD REJ");
1259 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1260
1261 gh->msg_type = GSM48_MT_CC_HOLD_REJ;
1262
1263 /* cause */
1264 if (hold_rej->fields & MNCC_F_CAUSE)
1265 gsm48_encode_cause(msg, 1, &hold_rej->cause);
1266 else
1267 gsm48_encode_cause(msg, 1, &default_cause);
1268
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001269 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001270}
1271
1272static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg)
1273{
1274 struct gsm_mncc retrieve;
1275
1276 memset(&retrieve, 0, sizeof(struct gsm_mncc));
1277 retrieve.callref = trans->callref;
1278 return mncc_recvmsg(trans->net, trans, MNCC_RETRIEVE_IND,
1279 &retrieve);
1280}
1281
1282static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg)
1283{
1284 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR ACK");
1285 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1286
1287 gh->msg_type = GSM48_MT_CC_RETR_ACK;
1288
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001289 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001290}
1291
1292static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg)
1293{
1294 struct gsm_mncc *retrieve_rej = arg;
1295 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC RETR REJ");
1296 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1297
1298 gh->msg_type = GSM48_MT_CC_RETR_REJ;
1299
1300 /* cause */
1301 if (retrieve_rej->fields & MNCC_F_CAUSE)
1302 gsm48_encode_cause(msg, 1, &retrieve_rej->cause);
1303 else
1304 gsm48_encode_cause(msg, 1, &default_cause);
1305
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001306 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001307}
1308
1309static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg)
1310{
1311 struct gsm48_hdr *gh = msgb_l3(msg);
1312 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1313 struct tlv_parsed tp;
1314 struct gsm_mncc dtmf;
1315
1316 memset(&dtmf, 0, sizeof(struct gsm_mncc));
1317 dtmf.callref = trans->callref;
1318 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
1319 /* keypad facility */
1320 if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) {
1321 dtmf.fields |= MNCC_F_KEYPAD;
1322 gsm48_decode_keypad(&dtmf.keypad,
1323 TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1);
1324 }
1325
1326 return mncc_recvmsg(trans->net, trans, MNCC_START_DTMF_IND, &dtmf);
1327}
1328
1329static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg)
1330{
1331 struct gsm_mncc *dtmf = arg;
1332 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF ACK");
1333 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1334
1335 gh->msg_type = GSM48_MT_CC_START_DTMF_ACK;
1336
1337 /* keypad */
1338 if (dtmf->fields & MNCC_F_KEYPAD)
1339 gsm48_encode_keypad(msg, dtmf->keypad);
1340
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001341 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001342}
1343
1344static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg)
1345{
1346 struct gsm_mncc *dtmf = arg;
1347 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF REJ");
1348 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1349
1350 gh->msg_type = GSM48_MT_CC_START_DTMF_REJ;
1351
1352 /* cause */
1353 if (dtmf->fields & MNCC_F_CAUSE)
1354 gsm48_encode_cause(msg, 1, &dtmf->cause);
1355 else
1356 gsm48_encode_cause(msg, 1, &default_cause);
1357
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001358 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001359}
1360
1361static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg)
1362{
1363 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 DTMF STP ACK");
1364 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1365
1366 gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK;
1367
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001368 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001369}
1370
1371static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg)
1372{
1373 struct gsm_mncc dtmf;
1374
1375 memset(&dtmf, 0, sizeof(struct gsm_mncc));
1376 dtmf.callref = trans->callref;
1377
1378 return mncc_recvmsg(trans->net, trans, MNCC_STOP_DTMF_IND, &dtmf);
1379}
1380
1381static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg)
1382{
1383 struct gsm48_hdr *gh = msgb_l3(msg);
1384 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1385 struct tlv_parsed tp;
1386 struct gsm_mncc modify;
1387
1388 memset(&modify, 0, sizeof(struct gsm_mncc));
1389 modify.callref = trans->callref;
1390 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
1391 /* bearer capability */
1392 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1393 modify.fields |= MNCC_F_BEARER_CAP;
1394 gsm48_decode_bearer_cap(&modify.bearer_cap,
1395 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1396
1397 /* Create a copy of the bearer capability
1398 * in the transaction struct, so we can use
1399 * this information later */
1400 memcpy(&trans->bearer_cap,&modify.bearer_cap,
1401 sizeof(trans->bearer_cap));
1402 }
1403
1404 new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY);
1405
1406 return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_IND, &modify);
1407}
1408
1409static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg)
1410{
1411 struct gsm_mncc *modify = arg;
1412 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD");
1413 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1414
1415 gh->msg_type = GSM48_MT_CC_MODIFY;
1416
1417 gsm48_start_cc_timer(trans, 0x323, GSM48_T323);
1418
1419 /* bearer capability */
1420 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
1421 memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap));
1422
1423 new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY);
1424
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001425 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001426}
1427
1428static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg)
1429{
1430 struct gsm48_hdr *gh = msgb_l3(msg);
1431 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1432 struct tlv_parsed tp;
1433 struct gsm_mncc modify;
1434
1435 gsm48_stop_cc_timer(trans);
1436
1437 memset(&modify, 0, sizeof(struct gsm_mncc));
1438 modify.callref = trans->callref;
1439 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
1440 /* bearer capability */
1441 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1442 modify.fields |= MNCC_F_BEARER_CAP;
1443 gsm48_decode_bearer_cap(&modify.bearer_cap,
1444 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1445
1446 /* Create a copy of the bearer capability
1447 * in the transaction struct, so we can use
1448 * this information later */
1449 memcpy(&trans->bearer_cap,&modify.bearer_cap,
1450 sizeof(trans->bearer_cap));
1451 }
1452
1453 new_cc_state(trans, GSM_CSTATE_ACTIVE);
1454
1455 return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_CNF, &modify);
1456}
1457
1458static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg)
1459{
1460 struct gsm_mncc *modify = arg;
1461 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD COMPL");
1462 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1463
1464 gh->msg_type = GSM48_MT_CC_MODIFY_COMPL;
1465
1466 /* bearer capability */
1467 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
1468 memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap));
1469
1470 new_cc_state(trans, GSM_CSTATE_ACTIVE);
1471
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001472 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001473}
1474
1475static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg)
1476{
1477 struct gsm48_hdr *gh = msgb_l3(msg);
1478 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1479 struct tlv_parsed tp;
1480 struct gsm_mncc modify;
1481
1482 gsm48_stop_cc_timer(trans);
1483
1484 memset(&modify, 0, sizeof(struct gsm_mncc));
1485 modify.callref = trans->callref;
1486 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE);
1487 /* bearer capability */
1488 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1489 modify.fields |= GSM48_IE_BEARER_CAP;
1490 gsm48_decode_bearer_cap(&modify.bearer_cap,
1491 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1492
1493 /* Create a copy of the bearer capability
1494 * in the transaction struct, so we can use
1495 * this information later */
1496 memcpy(&trans->bearer_cap,&modify.bearer_cap,
1497 sizeof(trans->bearer_cap));
1498 }
1499 /* cause */
1500 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1501 modify.fields |= MNCC_F_CAUSE;
1502 gsm48_decode_cause(&modify.cause,
1503 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1504 }
1505
1506 new_cc_state(trans, GSM_CSTATE_ACTIVE);
1507
1508 return mncc_recvmsg(trans->net, trans, MNCC_MODIFY_REJ, &modify);
1509}
1510
1511static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg)
1512{
1513 struct gsm_mncc *modify = arg;
1514 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC MOD REJ");
1515 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1516
1517 gh->msg_type = GSM48_MT_CC_MODIFY_REJECT;
1518
1519 /* bearer capability */
1520 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
1521 memcpy(&trans->bearer_cap, &modify->bearer_cap, sizeof(trans->bearer_cap));
1522 /* cause */
1523 gsm48_encode_cause(msg, 1, &modify->cause);
1524
1525 new_cc_state(trans, GSM_CSTATE_ACTIVE);
1526
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001527 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001528}
1529
1530static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg)
1531{
1532 struct gsm_mncc *notify = arg;
1533 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 CC NOT");
1534 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1535
1536 gh->msg_type = GSM48_MT_CC_NOTIFY;
1537
1538 /* notify */
1539 gsm48_encode_notify(msg, notify->notify);
1540
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001541 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001542}
1543
1544static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg)
1545{
1546 struct gsm48_hdr *gh = msgb_l3(msg);
1547 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1548// struct tlv_parsed tp;
1549 struct gsm_mncc notify;
1550
1551 memset(&notify, 0, sizeof(struct gsm_mncc));
1552 notify.callref = trans->callref;
1553// tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len);
1554 if (payload_len >= 1)
1555 gsm48_decode_notify(&notify.notify, gh->data);
1556
1557 return mncc_recvmsg(trans->net, trans, MNCC_NOTIFY_IND, &notify);
1558}
1559
1560static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg)
1561{
1562 struct gsm_mncc *user = arg;
1563 struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USR INFO");
1564 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1565
1566 gh->msg_type = GSM48_MT_CC_USER_INFO;
1567
1568 /* user-user */
1569 if (user->fields & MNCC_F_USERUSER)
1570 gsm48_encode_useruser(msg, 1, &user->useruser);
1571 /* more data */
1572 if (user->more)
1573 gsm48_encode_more(msg);
1574
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001575 return trans_tx_gsm48(trans, msg);
Harald Welte27989d42018-06-21 20:39:20 +02001576}
1577
1578static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg)
1579{
1580 struct gsm48_hdr *gh = msgb_l3(msg);
1581 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1582 struct tlv_parsed tp;
1583 struct gsm_mncc user;
1584
1585 memset(&user, 0, sizeof(struct gsm_mncc));
1586 user.callref = trans->callref;
1587 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0);
1588 /* user-user */
1589 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1590 user.fields |= MNCC_F_USERUSER;
1591 gsm48_decode_useruser(&user.useruser,
1592 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1593 }
1594 /* more data */
1595 if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA))
1596 user.more = 1;
1597
1598 return mncc_recvmsg(trans->net, trans, MNCC_USERINFO_IND, &user);
1599}
1600
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001601static int mncc_recv_rtp(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref,
1602 int cmd, struct osmo_sockaddr_str *rtp_addr, uint32_t payload_type,
1603 uint32_t payload_msg_type)
Harald Welte27989d42018-06-21 20:39:20 +02001604{
1605 uint8_t data[sizeof(struct gsm_mncc)];
1606 struct gsm_mncc_rtp *rtp;
1607
1608 memset(&data, 0, sizeof(data));
1609 rtp = (struct gsm_mncc_rtp *) &data[0];
1610
1611 rtp->callref = callref;
1612 rtp->msg_type = cmd;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001613 if (rtp_addr) {
1614 rtp->ip = osmo_htonl(inet_addr(rtp_addr->ip));
1615 rtp->port = rtp_addr->port;
1616 }
Harald Welte27989d42018-06-21 20:39:20 +02001617 rtp->payload_type = payload_type;
1618 rtp->payload_msg_type = payload_msg_type;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001619 return mncc_recvmsg(net, trans, cmd, (struct gsm_mncc *)data);
Harald Welte27989d42018-06-21 20:39:20 +02001620}
1621
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001622static void mncc_recv_rtp_err(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, int cmd)
Harald Welte27989d42018-06-21 20:39:20 +02001623{
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001624 mncc_recv_rtp(net, trans, callref, cmd, NULL, 0, 0);
Harald Welte27989d42018-06-21 20:39:20 +02001625}
1626
1627static int tch_rtp_create(struct gsm_network *net, uint32_t callref)
1628{
1629 struct gsm_trans *trans;
Harald Welte27989d42018-06-21 20:39:20 +02001630
1631 /* Find callref */
1632 trans = trans_find_by_callref(net, callref);
1633 if (!trans) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001634 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP create for non-existing trans\n");
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001635 mncc_recv_rtp_err(net, trans, callref, MNCC_RTP_CREATE);
Harald Welte27989d42018-06-21 20:39:20 +02001636 return -EIO;
1637 }
1638 log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001639 if (!trans->msc_a) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001640 LOG_TRANS_CAT(trans, DMNCC, LOGL_NOTICE, "RTP create for trans without conn\n");
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001641 mncc_recv_rtp_err(net, trans, callref, MNCC_RTP_CREATE);
Harald Welte27989d42018-06-21 20:39:20 +02001642 return 0;
1643 }
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001644 LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(MNCC_RTP_CREATE));
Harald Welte27989d42018-06-21 20:39:20 +02001645
Harald Welte27989d42018-06-21 20:39:20 +02001646 /* When we call msc_mgcp_call_assignment() we will trigger, depending
1647 * on the RAN type the call assignment on the A or Iu interface.
1648 * msc_mgcp_call_assignment() also takes care about sending the CRCX
1649 * command to the MGCP-GW. The CRCX will return the port number,
1650 * where the PBX (e.g. Asterisk) will send its RTP stream to. We
1651 * have to return this port number back to the MNCC by sending
1652 * it back with the TCH_RTP_CREATE message. To make sure that
1653 * this message is sent AFTER the response to CRCX from the
1654 * MGCP-GW has arrived, we need will instruct msc_mgcp_call_assignment()
1655 * to take care of this by setting trans->tch_rtp_create to true.
1656 * This will make sure that gsm48_tch_rtp_create() (below) is
1657 * called as soon as the local port number has become known. */
1658 trans->tch_rtp_create = true;
1659
1660 /* Assign call (if not done yet) */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001661 return msc_a_try_call_assignment(trans);
Harald Welte27989d42018-06-21 20:39:20 +02001662}
1663
1664/* Trigger TCH_RTP_CREATE acknowledgement */
1665int gsm48_tch_rtp_create(struct gsm_trans *trans)
1666{
1667 /* This function is called as soon as the port, on which the
1668 * mgcp-gw expects the incoming RTP stream from the remote
1669 * end (e.g. Asterisk) is known. */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001670 struct msc_a *msc_a = trans->msc_a;
1671 struct gsm_network *net = msc_a_net(msc_a);
1672 struct call_leg *cl = msc_a->cc.call_leg;
1673 struct osmo_sockaddr_str *rtp_cn_local;
Neels Hofmeyr5e19b9a2019-04-27 19:09:14 +02001674 struct rtp_stream *rtp_cn = cl ? cl->rtp[RTP_TO_CN] : NULL;
1675 uint32_t payload_type;
1676 int payload_msg_type;
1677 const struct mgcp_conn_peer *mgcp_info;
Harald Welte27989d42018-06-21 20:39:20 +02001678
Neels Hofmeyr5e19b9a2019-04-27 19:09:14 +02001679 if (!rtp_cn) {
1680 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no RTP set up for the CN side\n");
1681 return -EINVAL;
1682 }
1683
1684 if (!rtp_cn->codec_known) {
1685 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR,
1686 "Cannot RTP CREATE to MNCC, no codec set up for the RTP CN side\n");
1687 return -EINVAL;
1688 }
1689
1690 /* Codec */
1691 payload_msg_type = mgcp_codec_to_mncc_payload_msg_type(rtp_cn->codec);
1692
1693 /* Payload Type number */
1694 mgcp_info = osmo_mgcpc_ep_ci_get_rtp_info(rtp_cn->ci);
1695 payload_type = map_codec_to_pt(mgcp_info->ptmap, mgcp_info->ptmap_len, rtp_cn->codec);
Harald Welte27989d42018-06-21 20:39:20 +02001696
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001697 rtp_cn_local = call_leg_local_ip(cl, RTP_TO_CN);
1698 if (!rtp_cn_local) {
1699 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "Cannot RTP CREATE to MNCC, no local RTP IP:port set up\n");
1700 return -EINVAL;
1701 }
1702
Neels Hofmeyr5e19b9a2019-04-27 19:09:14 +02001703 return mncc_recv_rtp(net, trans, trans->callref, MNCC_RTP_CREATE, rtp_cn_local, payload_type, payload_msg_type);
Harald Welte27989d42018-06-21 20:39:20 +02001704}
1705
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001706static int tch_rtp_connect(struct gsm_network *net, const struct gsm_mncc_rtp *rtp)
Harald Welte27989d42018-06-21 20:39:20 +02001707{
1708 struct gsm_trans *trans;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001709 struct call_leg *cl;
1710 struct rtp_stream *rtps;
1711 struct osmo_sockaddr_str rtp_addr;
Harald Welte27989d42018-06-21 20:39:20 +02001712
Philipp Maier8ad3dac2018-08-07 13:00:14 +02001713 /* FIXME: in *rtp we should get the codec information of the remote
1714 * leg. We will have to populate trans->conn->rtp.codec_cn with a
1715 * meaningful value based on this information but unfortunately we
1716 * can't do that yet because the mncc API can not signal dynamic
1717 * payload types yet. This must be fixed first. Also there may be
1718 * additional members necessary in trans->conn->rtp because we
1719 * somehow need to deal with dynamic payload types that do not
1720 * comply to 3gpp's assumptions of payload type numbers on the A
1721 * interface. See also related tickets: OS#3399 and OS1683 */
1722
Harald Welte27989d42018-06-21 20:39:20 +02001723 /* Find callref */
1724 trans = trans_find_by_callref(net, rtp->callref);
1725 if (!trans) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001726 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for non-existing trans\n");
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001727 mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT);
Harald Welte27989d42018-06-21 20:39:20 +02001728 return -EIO;
1729 }
1730 log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001731 if (!trans->msc_a) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001732 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for trans without conn\n");
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001733 mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001734 return -EIO;
Harald Welte27989d42018-06-21 20:39:20 +02001735 }
1736
Neels Hofmeyrc65cfe82019-04-08 03:48:56 +02001737 LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(MNCC_RTP_CONNECT));
1738
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001739 cl = trans->msc_a->cc.call_leg;
1740 rtps = cl ? cl->rtp[RTP_TO_CN] : NULL;
1741
1742 if (!rtps) {
1743 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for trans without ongoing call\n");
1744 mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT);
1745 return -EINVAL;
1746 }
1747
1748 LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(MNCC_RTP_CONNECT));
1749
1750 osmo_sockaddr_str_from_32n(&rtp_addr, rtp->ip, rtp->port);
1751 rtp_stream_set_remote_addr(rtps, &rtp_addr);
1752 rtp_stream_commit(rtps);
1753 return 0;
Harald Welte27989d42018-06-21 20:39:20 +02001754}
1755
1756static struct downstate {
1757 uint32_t states;
1758 int type;
1759 int (*rout) (struct gsm_trans *trans, void *arg);
1760} downstatelist[] = {
1761 /* mobile originating call establishment */
1762 {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */
1763 MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc_and_assign},
1764 {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */
1765 MNCC_ALERT_REQ, gsm48_cc_tx_alerting},
1766 {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 */
1767 MNCC_SETUP_RSP, gsm48_cc_tx_connect},
1768 {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */
1769 MNCC_PROGRESS_REQ, gsm48_cc_tx_progress},
1770 /* mobile terminating call establishment */
1771 {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */
1772 MNCC_SETUP_REQ, gsm48_cc_tx_setup},
1773 {SBIT(GSM_CSTATE_CONNECT_REQUEST),
1774 MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack},
1775 /* signalling during call */
1776 {SBIT(GSM_CSTATE_ACTIVE),
1777 MNCC_NOTIFY_REQ, gsm48_cc_tx_notify},
1778 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ),
1779 MNCC_FACILITY_REQ, gsm48_cc_tx_facility},
1780 {ALL_STATES,
1781 MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack},
1782 {ALL_STATES,
1783 MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej},
1784 {ALL_STATES,
1785 MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack},
1786 {SBIT(GSM_CSTATE_ACTIVE),
1787 MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack},
1788 {SBIT(GSM_CSTATE_ACTIVE),
1789 MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej},
1790 {SBIT(GSM_CSTATE_ACTIVE),
1791 MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack},
1792 {SBIT(GSM_CSTATE_ACTIVE),
1793 MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej},
1794 {SBIT(GSM_CSTATE_ACTIVE),
1795 MNCC_MODIFY_REQ, gsm48_cc_tx_modify},
1796 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
1797 MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete},
1798 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
1799 MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject},
1800 {SBIT(GSM_CSTATE_ACTIVE),
1801 MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo},
1802 /* clearing */
1803 {SBIT(GSM_CSTATE_INITIATED),
1804 MNCC_REJ_REQ, gsm48_cc_tx_release_compl},
1805 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */
1806 MNCC_DISC_REQ, gsm48_cc_tx_disconnect},
1807 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
1808 MNCC_REL_REQ, gsm48_cc_tx_release},
1809};
1810
1811#define DOWNSLLEN \
1812 (sizeof(downstatelist) / sizeof(struct downstate))
1813
1814
Philipp Maiercd64af72019-08-01 09:46:40 +02001815static int mncc_tx_to_gsm_cc(struct gsm_network *net, const union mncc_msg *msg)
Harald Welte27989d42018-06-21 20:39:20 +02001816{
1817 int i, rc = 0;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001818 struct msc_a *msc_a = NULL;
1819 struct gsm_trans *trans = NULL;
1820 const struct gsm_mncc *data;
Harald Welte27989d42018-06-21 20:39:20 +02001821
Harald Welte27989d42018-06-21 20:39:20 +02001822 /* handle special messages */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001823 switch(msg->msg_type) {
Harald Welte27989d42018-06-21 20:39:20 +02001824 case MNCC_BRIDGE:
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001825 rc = tch_bridge(net, &msg->bridge);
Harald Welte27989d42018-06-21 20:39:20 +02001826 if (rc < 0)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001827 disconnect_bridge(net, &msg->bridge, -rc);
Harald Welte27989d42018-06-21 20:39:20 +02001828 return rc;
1829 case MNCC_RTP_CREATE:
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001830 return tch_rtp_create(net, msg->rtp.callref);
Harald Welte27989d42018-06-21 20:39:20 +02001831 case MNCC_RTP_CONNECT:
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001832 return tch_rtp_connect(net, &msg->rtp);
Harald Welte27989d42018-06-21 20:39:20 +02001833 case MNCC_RTP_FREE:
1834 /* unused right now */
1835 return -EIO;
1836
1837 case MNCC_FRAME_DROP:
1838 case MNCC_FRAME_RECV:
1839 case GSM_TCHF_FRAME:
1840 case GSM_TCHF_FRAME_EFR:
1841 case GSM_TCHH_FRAME:
1842 case GSM_TCH_FRAME_AMR:
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001843 LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP streams must be handled externally; %s not supported.\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001844 get_mncc_name(msg->msg_type));
Harald Welte27989d42018-06-21 20:39:20 +02001845 return -ENOTSUP;
1846 }
1847
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001848 data = &msg->signal;
Harald Welte27989d42018-06-21 20:39:20 +02001849
1850 /* Find callref */
1851 trans = trans_find_by_callref(net, data->callref);
1852
1853 /* Callref unknown */
1854 if (!trans) {
1855 struct vlr_subscr *vsub;
1856
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001857 if (msg->msg_type != MNCC_SETUP_REQ) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001858 LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "Unknown call reference for %s\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001859 get_mncc_name(msg->msg_type));
Harald Welte27989d42018-06-21 20:39:20 +02001860 /* Invalid call reference */
1861 return mncc_release_ind(net, NULL, data->callref,
1862 GSM48_CAUSE_LOC_PRN_S_LU,
1863 GSM48_CC_CAUSE_INVAL_TRANS_ID);
1864 }
1865 if (!data->called.number[0] && !data->imsi[0]) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001866 LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "Neither number nor IMSI in %s\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001867 get_mncc_name(msg->msg_type));
Harald Welte27989d42018-06-21 20:39:20 +02001868 /* Invalid number */
1869 return mncc_release_ind(net, NULL, data->callref,
1870 GSM48_CAUSE_LOC_PRN_S_LU,
1871 GSM48_CC_CAUSE_INV_NR_FORMAT);
1872 }
1873 /* New transaction due to setup, find subscriber */
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001874 if (data->called.number[0]) {
1875 vsub = vlr_subscr_find_by_msisdn(net->vlr, data->called.number, __func__);
1876 if (!vsub)
1877 LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "rx %s for unknown subscriber number '%s'\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001878 get_mncc_name(msg->msg_type), data->called.number);
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001879 } else {
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001880 vsub = vlr_subscr_find_by_imsi(net->vlr, data->imsi, __func__);
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001881 if (!vsub)
1882 LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "rx %s for unknown subscriber IMSI '%s'\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001883 get_mncc_name(msg->msg_type), data->imsi);
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001884 }
1885 if (!vsub)
1886 return mncc_release_ind(net, NULL, data->callref, GSM48_CAUSE_LOC_PRN_S_LU,
1887 GSM48_CC_CAUSE_UNASSIGNED_NR);
Harald Welte27989d42018-06-21 20:39:20 +02001888 /* update the subscriber we deal with */
1889 log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
1890
Harald Welte27989d42018-06-21 20:39:20 +02001891 /* If subscriber is not "attached" */
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001892 if (!vsub->lu_complete) {
1893 LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "rx %s for subscriber that is not attached: %s\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001894 get_mncc_name(msg->msg_type), vlr_subscr_name(vsub));
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001895 vlr_subscr_put(vsub, __func__);
Harald Welte27989d42018-06-21 20:39:20 +02001896 /* Temporarily out of order */
1897 return mncc_release_ind(net, NULL, data->callref,
1898 GSM48_CAUSE_LOC_PRN_S_LU,
1899 GSM48_CC_CAUSE_DEST_OOO);
1900 }
1901 /* Create transaction */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001902 trans = trans_alloc(net, vsub, TRANS_CC,
Maxd8daaae2019-02-14 16:54:10 +07001903 TRANS_ID_UNASSIGNED, data->callref);
Harald Welte27989d42018-06-21 20:39:20 +02001904 if (!trans) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001905 LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001906 vlr_subscr_put(vsub, __func__);
Harald Welte27989d42018-06-21 20:39:20 +02001907 /* Ressource unavailable */
1908 mncc_release_ind(net, NULL, data->callref,
1909 GSM48_CAUSE_LOC_PRN_S_LU,
1910 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
1911 return -ENOMEM;
1912 }
1913
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001914 /* Find valid conn */
1915 msc_a = msc_a_for_vsub(vsub, true);
Harald Welte27989d42018-06-21 20:39:20 +02001916
1917 /* If subscriber has no conn */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001918 if (!msc_a) {
1919
1920 if (vsub->cs.is_paging) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001921 LOG_TRANS(trans, LOGL_DEBUG,
1922 "rx %s, subscriber not yet connected, paging already started\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001923 get_mncc_name(msg->msg_type));
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001924 vlr_subscr_put(vsub, __func__);
Harald Welte27989d42018-06-21 20:39:20 +02001925 trans_free(trans);
1926 return 0;
1927 }
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001928
Harald Welte27989d42018-06-21 20:39:20 +02001929 /* store setup information until paging succeeds */
1930 memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
1931
1932 /* Request a channel */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001933 trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_CALL_CONVERSATIONAL,
1934 cc_paging_cb, trans, "MNCC: establish call");
Harald Welte27989d42018-06-21 20:39:20 +02001935 if (!trans->paging_request) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001936 LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token.\n");
Harald Welte27989d42018-06-21 20:39:20 +02001937 trans_free(trans);
Harald Welte27989d42018-06-21 20:39:20 +02001938 }
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001939 vlr_subscr_put(vsub, __func__);
Harald Welte27989d42018-06-21 20:39:20 +02001940 return 0;
1941 }
1942
1943 /* Assign conn */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001944 trans->msc_a = msc_a;
1945 msc_a_get(msc_a, MSC_A_USE_CC);
Harald Welte27989d42018-06-21 20:39:20 +02001946 trans->dlci = 0x00; /* SAPI=0, not SACCH */
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001947 vlr_subscr_put(vsub, __func__);
Harald Welte27989d42018-06-21 20:39:20 +02001948 } else {
1949 /* update the subscriber we deal with */
1950 log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub);
1951 }
1952
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001953 LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s\n", get_mncc_name(msg->msg_type));
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001954
Philipp Maier9ca7b312018-10-10 17:00:49 +02001955 gsm48_start_guard_timer(trans);
1956
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001957 if (trans->msc_a)
1958 msc_a = trans->msc_a;
Harald Welte27989d42018-06-21 20:39:20 +02001959
1960 /* if paging did not respond yet */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001961 if (!msc_a) {
1962 struct gsm_mncc rel = {
1963 .callref = data->callref,
1964 };
1965 LOG_TRANS(trans, LOGL_DEBUG, "rx %s in paging state\n", get_mncc_name(msg->msg_type));
Harald Welte27989d42018-06-21 20:39:20 +02001966 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU,
1967 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001968 if (msg->msg_type == MNCC_REL_REQ)
Harald Welte27989d42018-06-21 20:39:20 +02001969 rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
1970 else
1971 rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
1972 trans->callref = 0;
1973 trans_free(trans);
1974 return rc;
1975 } else {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001976 LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001977 get_mncc_name(msg->msg_type), gsm48_cc_state_name(trans->cc.state));
Harald Welte27989d42018-06-21 20:39:20 +02001978 }
1979
1980 /* Find function for current state and message */
1981 for (i = 0; i < DOWNSLLEN; i++)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001982 if ((msg->msg_type == downstatelist[i].type)
Harald Welte27989d42018-06-21 20:39:20 +02001983 && ((1 << trans->cc.state) & downstatelist[i].states))
1984 break;
1985 if (i == DOWNSLLEN) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01001986 LOG_TRANS(trans, LOGL_DEBUG, "Message '%s' unhandled at state '%s'\n",
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001987 get_mncc_name(msg->msg_type), gsm48_cc_state_name(trans->cc.state));
Harald Welte27989d42018-06-21 20:39:20 +02001988 return 0;
1989 }
1990
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001991 rc = downstatelist[i].rout(trans, (void*)msg);
Harald Welte27989d42018-06-21 20:39:20 +02001992
1993 return rc;
1994}
1995
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001996struct mncc_call *mncc_find_by_callref_from_msg(const union mncc_msg *msg)
1997{
1998 uint32_t callref;
1999
2000 switch (msg->msg_type) {
2001 case MNCC_BRIDGE:
2002 callref = msg->bridge.callref[0];
2003 break;
2004 case MNCC_RTP_CREATE:
2005 case MNCC_RTP_CONNECT:
2006 callref = msg->rtp.callref;
2007 break;
2008
2009 case MNCC_RTP_FREE:
2010 case MNCC_FRAME_DROP:
2011 case MNCC_FRAME_RECV:
2012 case GSM_TCHF_FRAME:
2013 case GSM_TCHF_FRAME_EFR:
2014 case GSM_TCHH_FRAME:
2015 case GSM_TCH_FRAME_AMR:
2016 return NULL;
2017
2018 default:
2019 callref = msg->signal.callref;
2020 break;
2021 }
2022
2023 return mncc_call_find_by_callref(callref);
2024}
2025
2026/* Demux incoming genuine calls to GSM CC from MNCC forwarding for inter-MSC handover */
Neels Hofmeyr52558742019-05-09 01:23:09 +02002027int mncc_tx_to_cc(struct gsm_network *net, void *arg)
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002028{
2029 const union mncc_msg *msg = arg;
2030 struct mncc_call *mncc_call = NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002031
2032 if (msg->msg_type == MNCC_SETUP_REQ) {
2033 /* Incoming call to forward for inter-MSC Handover? */
2034 mncc_call = msc_t_check_call_to_handover_number(&msg->signal);
2035 if (mncc_call)
2036 LOG_MNCC_CALL(mncc_call, LOGL_DEBUG,
2037 "Incoming call matches pending inter-MSC Handover Number\n");
2038 }
2039 if (!mncc_call) {
2040 /* Find already active MNCC FSM for this callref.
2041 * Currently only for inter-MSC call forwarding, but mncc_fsm could at some point also be used for direct
2042 * MNCC<->GSM-CC call handling. */
2043 mncc_call = mncc_find_by_callref_from_msg(msg);
2044 }
2045 if (mncc_call) {
2046 mncc_call_rx(mncc_call, msg);
2047 return 0;
2048 }
2049
2050 /* None of the above? Then it must be a normal GSM CC call related message. */
2051 return mncc_tx_to_gsm_cc(net, msg);
2052}
Harald Welte27989d42018-06-21 20:39:20 +02002053
2054static struct datastate {
2055 uint32_t states;
2056 int type;
2057 int (*rout) (struct gsm_trans *trans, struct msgb *msg);
2058} datastatelist[] = {
2059 /* mobile originating call establishment */
2060 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2061 GSM48_MT_CC_SETUP, gsm48_cc_rx_setup},
2062 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2063 GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup},
2064 {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */
2065 GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack},
2066 /* mobile terminating call establishment */
2067 {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */
2068 GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf},
2069 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */
2070 GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting},
2071 {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 */
2072 GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect},
2073 /* signalling during call */
2074 {ALL_STATES - SBIT(GSM_CSTATE_NULL),
2075 GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility},
2076 {SBIT(GSM_CSTATE_ACTIVE),
2077 GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify},
2078 {ALL_STATES,
2079 GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf},
2080 {ALL_STATES,
2081 GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf},
2082 {ALL_STATES,
2083 GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq},
2084 {SBIT(GSM_CSTATE_ACTIVE),
2085 GSM48_MT_CC_HOLD, gsm48_cc_rx_hold},
2086 {SBIT(GSM_CSTATE_ACTIVE),
2087 GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve},
2088 {SBIT(GSM_CSTATE_ACTIVE),
2089 GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify},
2090 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
2091 GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete},
2092 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
2093 GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject},
2094 {SBIT(GSM_CSTATE_ACTIVE),
2095 GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo},
2096 /* clearing */
2097 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
2098 GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect},
2099 {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */
2100 GSM48_MT_CC_RELEASE, gsm48_cc_rx_release},
2101 {ALL_STATES, /* 5.4.3.4 */
2102 GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl},
2103};
2104
2105#define DATASLLEN \
2106 (sizeof(datastatelist) / sizeof(struct datastate))
2107
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002108int gsm0408_rcv_cc(struct msc_a *msc_a, struct msgb *msg)
Harald Welte27989d42018-06-21 20:39:20 +02002109{
2110 struct gsm48_hdr *gh = msgb_l3(msg);
2111 uint8_t msg_type = gsm48_hdr_msg_type(gh);
2112 uint8_t transaction_id = gsm48_hdr_trans_id_flip_ti(gh);
2113 struct gsm_trans *trans = NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002114 struct vlr_subscr *vsub = msc_a_vsub(msc_a);
2115 struct gsm_network *net = msc_a_net(msc_a);
Harald Welte27989d42018-06-21 20:39:20 +02002116 int i, rc = 0;
2117
2118 if (msg_type & 0x80) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01002119 LOG_TRANS(trans, LOGL_DEBUG, "MSG 0x%2x not defined for PD error\n", msg_type);
Harald Welte27989d42018-06-21 20:39:20 +02002120 return -EINVAL;
2121 }
2122
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002123 if (!vsub) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01002124 LOG_TRANS(trans, LOGL_ERROR, "Invalid conn: no subscriber\n");
Harald Welte27989d42018-06-21 20:39:20 +02002125 return -EINVAL;
2126 }
2127
2128 /* Find transaction */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002129 trans = trans_find_by_id(msc_a, TRANS_CC, transaction_id);
Harald Welte27989d42018-06-21 20:39:20 +02002130
Harald Welte27989d42018-06-21 20:39:20 +02002131 /* Create transaction */
2132 if (!trans) {
Harald Welte27989d42018-06-21 20:39:20 +02002133 /* Create transaction */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002134 trans = trans_alloc(net, vsub,
2135 TRANS_CC,
2136 transaction_id, msc_cc_next_outgoing_callref());
Harald Welte27989d42018-06-21 20:39:20 +02002137 if (!trans) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01002138 LOG_TRANS(trans, LOGL_ERROR, "No memory for trans.\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002139 rc = gsm48_tx_simple(msc_a,
Harald Welte27989d42018-06-21 20:39:20 +02002140 GSM48_PDISC_CC | (transaction_id << 4),
2141 GSM48_MT_CC_RELEASE_COMPL);
2142 return -ENOMEM;
2143 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002144 if (osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans)) {
2145 LOG_MSC_A(msc_a, LOGL_ERROR, "Not allowed to accept CC transaction\n");
2146 trans_free(trans);
2147 return -EINVAL;
2148 }
2149
Harald Welte27989d42018-06-21 20:39:20 +02002150 /* Assign transaction */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002151 msc_a_get(msc_a, MSC_A_USE_CC);
2152 trans->msc_a = msc_a;
Harald Welte27989d42018-06-21 20:39:20 +02002153 trans->dlci = OMSC_LINKID_CB(msg); /* DLCI as received from BSC */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002154
2155 /* An earlier CM Service Request for this CC message now has concluded */
2156 if (!osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_CC))
2157 LOG_MSC_A(msc_a, LOGL_ERROR,
2158 "Creating new CC transaction without prior CM Service Request\n");
2159 else
2160 msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_CC);
Harald Welte27989d42018-06-21 20:39:20 +02002161 }
2162
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01002163 LOG_TRANS(trans, LOGL_DEBUG, "rx %s in state %s\n", gsm48_cc_msg_name(msg_type),
2164 gsm48_cc_state_name(trans->cc.state));
2165
Harald Welte27989d42018-06-21 20:39:20 +02002166 /* find function for current state and message */
2167 for (i = 0; i < DATASLLEN; i++)
2168 if ((msg_type == datastatelist[i].type)
2169 && ((1 << trans->cc.state) & datastatelist[i].states))
2170 break;
2171 if (i == DATASLLEN) {
Neels Hofmeyrff7074a2019-02-28 05:50:06 +01002172 LOG_TRANS(trans, LOGL_ERROR, "Message unhandled at this state.\n");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01002173
2174 /* If a transaction was just now created, it was a bogus transaction ID, and we need to clean up the
2175 * transaction right away. */
2176 if (trans->cc.state == GSM_CSTATE_NULL) {
2177 LOG_TRANS(trans, LOGL_ERROR, "Unknown transaction ID for non-SETUP message is not allowed"
2178 " -- disarding new CC transaction right away\n");
2179 trans_free(trans);
2180 }
Harald Welte27989d42018-06-21 20:39:20 +02002181 return 0;
2182 }
2183
2184 assert(trans->vsub);
2185
2186 rc = datastatelist[i].rout(trans, msg);
2187
Harald Welte27989d42018-06-21 20:39:20 +02002188 return rc;
2189}