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