Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 1 | /* mncc_builtin.c - default, minimal built-in MNCC Application for |
Alexander Couzens | fbd96f5 | 2016-08-29 18:40:02 +0200 | [diff] [blame] | 2 | * standalone bsc_hack (network-in-the-box mode) */ |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 3 | |
| 4 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2009 by Andreas Eversberg <Andreas.Eversberg@versatel.de> |
| 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 General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 17 | * |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <errno.h> |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 25 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 26 | #include <osmocom/msc/gsm_04_08.h> |
| 27 | #include <osmocom/msc/debug.h> |
| 28 | #include <osmocom/msc/mncc.h> |
| 29 | #include <osmocom/msc/mncc_int.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 30 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 31 | #include <osmocom/msc/gsm_data.h> |
| 32 | #include <osmocom/msc/transaction.h> |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 33 | |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 34 | #define DEBUGCC(l, r, fmt, args...) DEBUGP(DMNCC, "(call %x, remote %x) " fmt, l->callref, r->callref, ##args) |
| 35 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 36 | void *tall_call_ctx; |
| 37 | |
| 38 | static LLIST_HEAD(call_list); |
| 39 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 40 | static uint32_t new_callref = 0x00000001; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 41 | |
Harald Welte | ab386e6 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 42 | struct mncc_int mncc_int = { |
Andreas Eversberg | a83d511 | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 43 | .def_codec = { GSM48_CMODE_SPEECH_V1, GSM48_CMODE_SPEECH_V1 }, |
Harald Welte | ab386e6 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 46 | static void free_call(struct gsm_call *call) |
| 47 | { |
| 48 | llist_del(&call->entry); |
| 49 | DEBUGP(DMNCC, "(call %x) Call removed.\n", call->callref); |
| 50 | talloc_free(call); |
| 51 | } |
| 52 | |
| 53 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 54 | static struct gsm_call *get_call_ref(uint32_t callref) |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 55 | { |
| 56 | struct gsm_call *callt; |
| 57 | |
| 58 | llist_for_each_entry(callt, &call_list, entry) { |
| 59 | if (callt->callref == callref) |
| 60 | return callt; |
| 61 | } |
| 62 | return NULL; |
| 63 | } |
| 64 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 65 | /* on incoming call, look up database and send setup to remote subscr. */ |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 66 | static int mncc_setup_ind(struct gsm_call *call, |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 67 | struct gsm_mncc *setup) |
| 68 | { |
| 69 | struct gsm_mncc mncc; |
| 70 | struct gsm_call *remote; |
| 71 | |
| 72 | memset(&mncc, 0, sizeof(struct gsm_mncc)); |
| 73 | mncc.callref = call->callref; |
| 74 | |
| 75 | /* already have remote call */ |
| 76 | if (call->remote_ref) |
| 77 | return 0; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 78 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 79 | /* transfer mode 1 would be packet mode, which was never specified */ |
| 80 | if (setup->bearer_cap.mode != 0) { |
| 81 | LOGP(DMNCC, LOGL_NOTICE, "(call %x) We don't support " |
| 82 | "packet mode\n", call->callref); |
| 83 | mncc_set_cause(&mncc, GSM48_CAUSE_LOC_PRN_S_LU, |
| 84 | GSM48_CC_CAUSE_BEARER_CA_UNAVAIL); |
| 85 | goto out_reject; |
| 86 | } |
| 87 | |
Oliver Smith | 429ab7b | 2023-07-10 16:24:36 +0200 | [diff] [blame] | 88 | /* we currently only do speech and CSD */ |
| 89 | switch (setup->bearer_cap.transfer) { |
| 90 | case GSM_MNCC_BCAP_SPEECH: |
Manawyrm | 1ed12ea | 2023-10-14 17:23:04 +0200 | [diff] [blame] | 91 | case GSM_MNCC_BCAP_AUDIO: |
| 92 | case GSM_MNCC_BCAP_FAX_G3: |
Oliver Smith | 429ab7b | 2023-07-10 16:24:36 +0200 | [diff] [blame] | 93 | case GSM_MNCC_BCAP_UNR_DIG: |
| 94 | break; |
| 95 | default: |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 96 | LOGP(DMNCC, LOGL_NOTICE, "(call %x) We only support " |
Oliver Smith | 429ab7b | 2023-07-10 16:24:36 +0200 | [diff] [blame] | 97 | "voice calls and CSD\n", call->callref); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 98 | mncc_set_cause(&mncc, GSM48_CAUSE_LOC_PRN_S_LU, |
| 99 | GSM48_CC_CAUSE_BEARER_CA_UNAVAIL); |
| 100 | goto out_reject; |
| 101 | } |
| 102 | |
| 103 | /* create remote call */ |
Andreas Eversberg | c5e0851 | 2013-01-25 08:36:32 +0100 | [diff] [blame] | 104 | if (!(remote = talloc_zero(tall_call_ctx, struct gsm_call))) { |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 105 | mncc_set_cause(&mncc, GSM48_CAUSE_LOC_PRN_S_LU, |
| 106 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 107 | goto out_reject; |
| 108 | } |
| 109 | llist_add_tail(&remote->entry, &call_list); |
| 110 | remote->net = call->net; |
| 111 | remote->callref = new_callref++; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 112 | DEBUGCC(call, remote, "Creating new remote instance.\n"); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 113 | |
| 114 | /* link remote call */ |
| 115 | call->remote_ref = remote->callref; |
| 116 | remote->remote_ref = call->callref; |
| 117 | |
Harald Welte | bf0a7c9 | 2012-08-24 16:48:21 +0200 | [diff] [blame] | 118 | /* send call proceeding */ |
| 119 | memset(&mncc, 0, sizeof(struct gsm_mncc)); |
| 120 | mncc.callref = call->callref; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 121 | mncc.msg_type = MNCC_CALL_PROC_REQ; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 122 | DEBUGCC(call, remote, "Accepting call.\n"); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 123 | mncc_tx_to_cc(call->net, &mncc); |
Harald Welte | bf0a7c9 | 2012-08-24 16:48:21 +0200 | [diff] [blame] | 124 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 125 | /* modify mode */ |
| 126 | memset(&mncc, 0, sizeof(struct gsm_mncc)); |
| 127 | mncc.callref = call->callref; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 128 | mncc.msg_type = MNCC_LCHAN_MODIFY; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 129 | DEBUGCC(call, remote, "Modify channel mode.\n"); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 130 | mncc_tx_to_cc(call->net, &mncc); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 131 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 132 | /* send setup to remote */ |
| 133 | // setup->fields |= MNCC_F_SIGNAL; |
| 134 | // setup->signal = GSM48_SIGNAL_DIALTONE; |
| 135 | setup->callref = remote->callref; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 136 | setup->msg_type = MNCC_SETUP_REQ; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 137 | DEBUGCC(call, remote, "Forwarding SETUP to remote.\n"); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 138 | return mncc_tx_to_cc(remote->net, setup); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 139 | |
| 140 | out_reject: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 141 | mncc.msg_type = MNCC_REJ_REQ; |
| 142 | mncc_tx_to_cc(call->net, &mncc); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 143 | free_call(call); |
| 144 | return 0; |
| 145 | } |
| 146 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 147 | static int mncc_alert_ind(struct gsm_call *call, |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 148 | struct gsm_mncc *alert) |
| 149 | { |
| 150 | struct gsm_call *remote; |
| 151 | |
| 152 | /* send alerting to remote */ |
| 153 | if (!(remote = get_call_ref(call->remote_ref))) |
| 154 | return 0; |
| 155 | alert->callref = remote->callref; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 156 | alert->msg_type = MNCC_ALERT_REQ; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 157 | DEBUGCC(call, remote, "Forwarding ALERT to remote.\n"); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 158 | return mncc_tx_to_cc(remote->net, alert); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 161 | static int mncc_notify_ind(struct gsm_call *call, |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 162 | struct gsm_mncc *notify) |
| 163 | { |
| 164 | struct gsm_call *remote; |
| 165 | |
| 166 | /* send notify to remote */ |
| 167 | if (!(remote = get_call_ref(call->remote_ref))) |
| 168 | return 0; |
| 169 | notify->callref = remote->callref; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 170 | notify->msg_type = MNCC_NOTIFY_REQ; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 171 | DEBUGCC(call, remote, "Forwarding NOTIF to remote.\n"); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 172 | return mncc_tx_to_cc(remote->net, notify); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 175 | static int mncc_setup_cnf(struct gsm_call *call, |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 176 | struct gsm_mncc *connect) |
| 177 | { |
Neels Hofmeyr | f9773b0 | 2018-11-29 23:01:58 +0100 | [diff] [blame] | 178 | struct gsm_mncc connect_ack; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 179 | struct gsm_call *remote; |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 180 | struct gsm_mncc_bridge bridge = { .msg_type = MNCC_BRIDGE }; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 181 | |
| 182 | /* acknowledge connect */ |
| 183 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 184 | connect_ack.msg_type = MNCC_SETUP_COMPL_REQ; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 185 | connect_ack.callref = call->callref; |
| 186 | DEBUGP(DMNCC, "(call %x) Acknowledge SETUP.\n", call->callref); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 187 | mncc_tx_to_cc(call->net, &connect_ack); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 188 | |
| 189 | /* send connect message to remote */ |
| 190 | if (!(remote = get_call_ref(call->remote_ref))) |
| 191 | return 0; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 192 | connect->msg_type = MNCC_SETUP_RSP; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 193 | connect->callref = remote->callref; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 194 | DEBUGCC(call, remote, "Sending CONNECT to remote.\n"); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 195 | mncc_tx_to_cc(remote->net, connect); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 196 | |
| 197 | /* bridge tch */ |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 198 | bridge.msg_type = MNCC_BRIDGE; |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 199 | bridge.callref[0] = call->callref; |
| 200 | bridge.callref[1] = call->remote_ref; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 201 | DEBUGCC(call, remote, "Bridging with remote.\n"); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 202 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 203 | return mncc_tx_to_cc(call->net, &bridge); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 206 | static int mncc_disc_ind(struct gsm_call *call, |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 207 | struct gsm_mncc *disc) |
| 208 | { |
| 209 | struct gsm_call *remote; |
| 210 | |
| 211 | /* send release */ |
| 212 | DEBUGP(DMNCC, "(call %x) Releasing call with cause %d\n", |
| 213 | call->callref, disc->cause.value); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 214 | disc->msg_type = MNCC_REL_REQ; |
| 215 | mncc_tx_to_cc(call->net, disc); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 216 | |
| 217 | /* send disc to remote */ |
| 218 | if (!(remote = get_call_ref(call->remote_ref))) { |
| 219 | return 0; |
| 220 | } |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 221 | disc->msg_type = MNCC_DISC_REQ; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 222 | disc->callref = remote->callref; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 223 | DEBUGCC(call, remote, "Disconnecting remote with cause %d\n", disc->cause.value); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 224 | return mncc_tx_to_cc(remote->net, disc); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 227 | static int mncc_rel_ind(struct gsm_call *call, struct gsm_mncc *rel) |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 228 | { |
| 229 | struct gsm_call *remote; |
| 230 | |
| 231 | /* send release to remote */ |
| 232 | if (!(remote = get_call_ref(call->remote_ref))) { |
| 233 | free_call(call); |
| 234 | return 0; |
| 235 | } |
Holger Hans Peter Freyther | a61c709 | 2011-01-27 15:05:45 +0100 | [diff] [blame] | 236 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 237 | rel->msg_type = MNCC_REL_REQ; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 238 | rel->callref = remote->callref; |
Max | 3332ac4 | 2018-12-17 11:17:33 +0100 | [diff] [blame] | 239 | DEBUGCC(call, remote, "Releasing remote with cause %d\n", rel->cause.value); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 240 | |
Holger Hans Peter Freyther | a61c709 | 2011-01-27 15:05:45 +0100 | [diff] [blame] | 241 | /* |
| 242 | * Release this side of the call right now. Otherwise we end up |
| 243 | * in this method for the other call and will also try to release |
| 244 | * it and then we will end up with a double free and a crash |
| 245 | */ |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 246 | free_call(call); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 247 | mncc_tx_to_cc(remote->net, rel); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 252 | static int mncc_rel_cnf(struct gsm_call *call, struct gsm_mncc *rel) |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 253 | { |
| 254 | free_call(call); |
| 255 | return 0; |
| 256 | } |
| 257 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 258 | /* Internal MNCC handler input function (from CC -> MNCC -> here) */ |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 259 | int int_mncc_recv(struct gsm_network *net, struct msgb *msg) |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 260 | { |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 261 | void *arg = msgb_data(msg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 262 | struct gsm_mncc *data = arg; |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 263 | int msg_type = data->msg_type; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 264 | int callref; |
| 265 | struct gsm_call *call = NULL, *callt; |
| 266 | int rc = 0; |
| 267 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 268 | /* find callref */ |
| 269 | callref = data->callref; |
| 270 | llist_for_each_entry(callt, &call_list, entry) { |
| 271 | if (callt->callref == callref) { |
| 272 | call = callt; |
| 273 | break; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /* create callref, if setup is received */ |
| 278 | if (!call) { |
| 279 | if (msg_type != MNCC_SETUP_IND) |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 280 | goto out_free; /* drop */ |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 281 | /* create call */ |
| 282 | if (!(call = talloc_zero(tall_call_ctx, struct gsm_call))) { |
| 283 | struct gsm_mncc rel; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 284 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 285 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 286 | rel.msg_type = MNCC_REL_REQ; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 287 | rel.callref = callref; |
| 288 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 289 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 290 | mncc_tx_to_cc(net, &rel); |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 291 | goto out_free; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 292 | } |
| 293 | llist_add_tail(&call->entry, &call_list); |
| 294 | call->net = net; |
| 295 | call->callref = callref; |
| 296 | DEBUGP(DMNCC, "(call %x) Call created.\n", call->callref); |
| 297 | } |
| 298 | |
Andreas Eversberg | 9acbe4c | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 299 | if (mncc_is_data_frame(msg_type)) { |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 300 | LOGP(DMNCC, LOGL_ERROR, "(call %x) Received data frame, which is not supported.\n", |
| 301 | call->callref); |
Andreas Eversberg | 9acbe4c | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 302 | goto out_free; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Andreas Eversberg | 9acbe4c | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 305 | DEBUGP(DMNCC, "(call %x) Received message %s\n", call->callref, |
| 306 | get_mncc_name(msg_type)); |
| 307 | |
Vadim Yanitskiy | 880a693 | 2020-08-22 17:47:54 +0700 | [diff] [blame] | 308 | switch (msg_type) { |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 309 | case MNCC_SETUP_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 310 | rc = mncc_setup_ind(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 311 | break; |
| 312 | case MNCC_SETUP_CNF: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 313 | rc = mncc_setup_cnf(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 314 | break; |
| 315 | case MNCC_SETUP_COMPL_IND: |
| 316 | break; |
| 317 | case MNCC_CALL_CONF_IND: |
| 318 | /* we now need to MODIFY the channel */ |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 319 | data->msg_type = MNCC_LCHAN_MODIFY; |
| 320 | mncc_tx_to_cc(call->net, data); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 321 | break; |
| 322 | case MNCC_ALERT_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 323 | rc = mncc_alert_ind(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 324 | break; |
| 325 | case MNCC_NOTIFY_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 326 | rc = mncc_notify_ind(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 327 | break; |
| 328 | case MNCC_DISC_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 329 | rc = mncc_disc_ind(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 330 | break; |
| 331 | case MNCC_REL_IND: |
| 332 | case MNCC_REJ_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 333 | rc = mncc_rel_ind(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 334 | break; |
| 335 | case MNCC_REL_CNF: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 336 | rc = mncc_rel_cnf(call, arg); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 337 | break; |
| 338 | case MNCC_FACILITY_IND: |
| 339 | break; |
| 340 | case MNCC_START_DTMF_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 341 | data->msg_type = MNCC_START_DTMF_REJ; |
| 342 | rc = mncc_tx_to_cc(net, data); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 343 | break; |
| 344 | case MNCC_STOP_DTMF_IND: |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 345 | data->msg_type = MNCC_STOP_DTMF_RSP; |
| 346 | rc = mncc_tx_to_cc(net, data); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 347 | break; |
| 348 | case MNCC_MODIFY_IND: |
| 349 | mncc_set_cause(data, GSM48_CAUSE_LOC_PRN_S_LU, |
| 350 | GSM48_CC_CAUSE_SERV_OPT_UNIMPL); |
| 351 | DEBUGP(DMNCC, "(call %x) Rejecting MODIFY with cause %d\n", |
| 352 | call->callref, data->cause.value); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 353 | data->msg_type = MNCC_MODIFY_REJ; |
| 354 | rc = mncc_tx_to_cc(net, data); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 355 | break; |
| 356 | case MNCC_MODIFY_CNF: |
| 357 | break; |
| 358 | case MNCC_HOLD_IND: |
| 359 | mncc_set_cause(data, GSM48_CAUSE_LOC_PRN_S_LU, |
| 360 | GSM48_CC_CAUSE_SERV_OPT_UNIMPL); |
| 361 | DEBUGP(DMNCC, "(call %x) Rejecting HOLD with cause %d\n", |
| 362 | call->callref, data->cause.value); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 363 | data->msg_type = MNCC_HOLD_REJ; |
| 364 | rc = mncc_tx_to_cc(net, data); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 365 | break; |
| 366 | case MNCC_RETRIEVE_IND: |
| 367 | mncc_set_cause(data, GSM48_CAUSE_LOC_PRN_S_LU, |
| 368 | GSM48_CC_CAUSE_SERV_OPT_UNIMPL); |
| 369 | DEBUGP(DMNCC, "(call %x) Rejecting RETRIEVE with cause %d\n", |
| 370 | call->callref, data->cause.value); |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 371 | data->msg_type = MNCC_RETRIEVE_REJ; |
| 372 | rc = mncc_tx_to_cc(net, data); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 373 | break; |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 374 | default: |
Vadim Yanitskiy | 4d75559 | 2020-08-22 17:49:35 +0700 | [diff] [blame] | 375 | LOGP(DMNCC, LOGL_NOTICE, "(call %x) Message '%s' unhandled\n", |
| 376 | callref, get_mncc_name(msg_type)); |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 377 | break; |
| 378 | } |
| 379 | |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 380 | out_free: |
Holger Hans Peter Freyther | a8ddb08 | 2012-03-01 20:30:32 +0100 | [diff] [blame] | 381 | msgb_free(msg); |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 382 | |
Harald Welte | 3e6376d | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 383 | return rc; |
| 384 | } |