Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 1 | /* mncc_builtin.c - default, minimal built-in MNCC Application for |
| 2 | * standalone bsc_hack (netowrk-in-the-box mode) */ |
| 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 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <errno.h> |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 29 | |
| 30 | #include <openbsc/gsm_04_08.h> |
| 31 | #include <openbsc/debug.h> |
| 32 | #include <openbsc/mncc.h> |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 33 | #include <openbsc/mncc_int.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 34 | #include <osmocom/core/talloc.h> |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 35 | #include <openbsc/gsm_data.h> |
| 36 | #include <openbsc/transaction.h> |
| 37 | #include <openbsc/rtp_proxy.h> |
| 38 | |
| 39 | void *tall_call_ctx; |
| 40 | |
| 41 | static LLIST_HEAD(call_list); |
| 42 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 43 | static uint32_t new_callref = 0x00000001; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 44 | |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 45 | struct mncc_int mncc_int = { |
Andreas Eversberg | 976493b | 2013-12-07 18:32:28 +0100 | [diff] [blame] | 46 | .def_codec = { GSM48_CMODE_SPEECH_V1, GSM48_CMODE_SPEECH_V1 }, |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 49 | static void free_call(struct gsm_call *call) |
| 50 | { |
| 51 | llist_del(&call->entry); |
| 52 | DEBUGP(DMNCC, "(call %x) Call removed.\n", call->callref); |
| 53 | talloc_free(call); |
| 54 | } |
| 55 | |
| 56 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 57 | static struct gsm_call *get_call_ref(uint32_t callref) |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 58 | { |
| 59 | struct gsm_call *callt; |
| 60 | |
| 61 | llist_for_each_entry(callt, &call_list, entry) { |
| 62 | if (callt->callref == callref) |
| 63 | return callt; |
| 64 | } |
| 65 | return NULL; |
| 66 | } |
| 67 | |
Holger Hans Peter Freyther | 8d88a92 | 2015-08-20 19:10:58 +0200 | [diff] [blame] | 68 | uint8_t mncc_codec_for_mode(int lchan_type) |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 69 | { |
| 70 | /* FIXME: check codec capabilities of the phone */ |
| 71 | |
Holger Hans Peter Freyther | 8d88a92 | 2015-08-20 19:10:58 +0200 | [diff] [blame] | 72 | if (lchan_type != GSM_LCHAN_TCH_H) |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 73 | return mncc_int.def_codec[0]; |
| 74 | else |
| 75 | return mncc_int.def_codec[1]; |
| 76 | } |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 77 | |
Holger Hans Peter Freyther | 8d88a92 | 2015-08-20 19:10:58 +0200 | [diff] [blame] | 78 | static uint8_t determine_lchan_mode(struct gsm_mncc *setup) |
| 79 | { |
| 80 | return mncc_codec_for_mode(setup->lchan_type); |
| 81 | } |
| 82 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 83 | /* on incoming call, look up database and send setup to remote subscr. */ |
| 84 | static int mncc_setup_ind(struct gsm_call *call, int msg_type, |
| 85 | struct gsm_mncc *setup) |
| 86 | { |
| 87 | struct gsm_mncc mncc; |
| 88 | struct gsm_call *remote; |
| 89 | |
| 90 | memset(&mncc, 0, sizeof(struct gsm_mncc)); |
| 91 | mncc.callref = call->callref; |
| 92 | |
| 93 | /* already have remote call */ |
| 94 | if (call->remote_ref) |
| 95 | return 0; |
| 96 | |
| 97 | /* transfer mode 1 would be packet mode, which was never specified */ |
| 98 | if (setup->bearer_cap.mode != 0) { |
| 99 | LOGP(DMNCC, LOGL_NOTICE, "(call %x) We don't support " |
| 100 | "packet mode\n", call->callref); |
| 101 | mncc_set_cause(&mncc, GSM48_CAUSE_LOC_PRN_S_LU, |
| 102 | GSM48_CC_CAUSE_BEARER_CA_UNAVAIL); |
| 103 | goto out_reject; |
| 104 | } |
| 105 | |
| 106 | /* we currently only do speech */ |
| 107 | if (setup->bearer_cap.transfer != GSM_MNCC_BCAP_SPEECH) { |
| 108 | LOGP(DMNCC, LOGL_NOTICE, "(call %x) We only support " |
| 109 | "voice calls\n", call->callref); |
| 110 | mncc_set_cause(&mncc, GSM48_CAUSE_LOC_PRN_S_LU, |
| 111 | GSM48_CC_CAUSE_BEARER_CA_UNAVAIL); |
| 112 | goto out_reject; |
| 113 | } |
| 114 | |
| 115 | /* create remote call */ |
Andreas Eversberg | 60628b8 | 2013-01-25 08:36:32 +0100 | [diff] [blame] | 116 | if (!(remote = talloc_zero(tall_call_ctx, struct gsm_call))) { |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 117 | mncc_set_cause(&mncc, GSM48_CAUSE_LOC_PRN_S_LU, |
| 118 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
| 119 | goto out_reject; |
| 120 | } |
| 121 | llist_add_tail(&remote->entry, &call_list); |
| 122 | remote->net = call->net; |
| 123 | remote->callref = new_callref++; |
| 124 | DEBUGP(DMNCC, "(call %x) Creating new remote instance %x.\n", |
| 125 | call->callref, remote->callref); |
| 126 | |
| 127 | /* link remote call */ |
| 128 | call->remote_ref = remote->callref; |
| 129 | remote->remote_ref = call->callref; |
| 130 | |
Harald Welte | 194aee1 | 2012-08-24 16:48:21 +0200 | [diff] [blame] | 131 | /* send call proceeding */ |
| 132 | memset(&mncc, 0, sizeof(struct gsm_mncc)); |
| 133 | mncc.callref = call->callref; |
| 134 | DEBUGP(DMNCC, "(call %x) Accepting call.\n", call->callref); |
| 135 | mncc_tx_to_cc(call->net, MNCC_CALL_PROC_REQ, &mncc); |
| 136 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 137 | /* modify mode */ |
| 138 | memset(&mncc, 0, sizeof(struct gsm_mncc)); |
| 139 | mncc.callref = call->callref; |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 140 | mncc.lchan_mode = determine_lchan_mode(setup); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 141 | DEBUGP(DMNCC, "(call %x) Modify channel mode.\n", call->callref); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 142 | mncc_tx_to_cc(call->net, MNCC_LCHAN_MODIFY, &mncc); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 143 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 144 | /* send setup to remote */ |
| 145 | // setup->fields |= MNCC_F_SIGNAL; |
| 146 | // setup->signal = GSM48_SIGNAL_DIALTONE; |
| 147 | setup->callref = remote->callref; |
| 148 | DEBUGP(DMNCC, "(call %x) Forwarding SETUP to remote.\n", call->callref); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 149 | return mncc_tx_to_cc(remote->net, MNCC_SETUP_REQ, setup); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 150 | |
| 151 | out_reject: |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 152 | mncc_tx_to_cc(call->net, MNCC_REJ_REQ, &mncc); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 153 | free_call(call); |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static int mncc_alert_ind(struct gsm_call *call, int msg_type, |
| 158 | struct gsm_mncc *alert) |
| 159 | { |
| 160 | struct gsm_call *remote; |
| 161 | |
| 162 | /* send alerting to remote */ |
| 163 | if (!(remote = get_call_ref(call->remote_ref))) |
| 164 | return 0; |
| 165 | alert->callref = remote->callref; |
| 166 | DEBUGP(DMNCC, "(call %x) Forwarding ALERT to remote.\n", call->callref); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 167 | return mncc_tx_to_cc(remote->net, MNCC_ALERT_REQ, alert); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static int mncc_notify_ind(struct gsm_call *call, int msg_type, |
| 171 | struct gsm_mncc *notify) |
| 172 | { |
| 173 | struct gsm_call *remote; |
| 174 | |
| 175 | /* send notify to remote */ |
| 176 | if (!(remote = get_call_ref(call->remote_ref))) |
| 177 | return 0; |
| 178 | notify->callref = remote->callref; |
| 179 | DEBUGP(DMNCC, "(call %x) Forwarding NOTIF to remote.\n", call->callref); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 180 | return mncc_tx_to_cc(remote->net, MNCC_NOTIFY_REQ, notify); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static int mncc_setup_cnf(struct gsm_call *call, int msg_type, |
| 184 | struct gsm_mncc *connect) |
| 185 | { |
| 186 | struct gsm_mncc connect_ack, frame_recv; |
| 187 | struct gsm_network *net = call->net; |
| 188 | struct gsm_call *remote; |
Harald Welte | 71a3c39 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 189 | struct gsm_mncc_bridge bridge = { .msg_type = MNCC_BRIDGE }; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 190 | |
| 191 | /* acknowledge connect */ |
| 192 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 193 | connect_ack.callref = call->callref; |
| 194 | DEBUGP(DMNCC, "(call %x) Acknowledge SETUP.\n", call->callref); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 195 | mncc_tx_to_cc(call->net, MNCC_SETUP_COMPL_REQ, &connect_ack); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 196 | |
| 197 | /* send connect message to remote */ |
| 198 | if (!(remote = get_call_ref(call->remote_ref))) |
| 199 | return 0; |
| 200 | connect->callref = remote->callref; |
| 201 | DEBUGP(DMNCC, "(call %x) Sending CONNECT to remote.\n", call->callref); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 202 | mncc_tx_to_cc(remote->net, MNCC_SETUP_RSP, connect); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 203 | |
| 204 | /* bridge tch */ |
Harald Welte | 71a3c39 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 205 | bridge.callref[0] = call->callref; |
| 206 | bridge.callref[1] = call->remote_ref; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 207 | DEBUGP(DMNCC, "(call %x) Bridging with remote.\n", call->callref); |
| 208 | |
| 209 | /* in direct mode, we always have to bridge the channels */ |
| 210 | if (ipacc_rtp_direct) |
Harald Welte | 71a3c39 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 211 | return mncc_tx_to_cc(call->net, MNCC_BRIDGE, &bridge); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 212 | |
| 213 | /* proxy mode */ |
| 214 | if (!net->handover.active) { |
| 215 | /* in the no-handover case, we can bridge, i.e. use |
| 216 | * the old RTP proxy code */ |
Harald Welte | 71a3c39 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 217 | return mncc_tx_to_cc(call->net, MNCC_BRIDGE, &bridge); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 218 | } else { |
| 219 | /* in case of handover, we need to re-write the RTP |
| 220 | * SSRC, sequence and timestamp values and thus |
| 221 | * need to enable RTP receive for both directions */ |
| 222 | memset(&frame_recv, 0, sizeof(struct gsm_mncc)); |
| 223 | frame_recv.callref = call->callref; |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 224 | mncc_tx_to_cc(call->net, MNCC_FRAME_RECV, &frame_recv); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 225 | frame_recv.callref = call->remote_ref; |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 226 | return mncc_tx_to_cc(call->net, MNCC_FRAME_RECV, &frame_recv); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | static int mncc_disc_ind(struct gsm_call *call, int msg_type, |
| 231 | struct gsm_mncc *disc) |
| 232 | { |
| 233 | struct gsm_call *remote; |
| 234 | |
| 235 | /* send release */ |
| 236 | DEBUGP(DMNCC, "(call %x) Releasing call with cause %d\n", |
| 237 | call->callref, disc->cause.value); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 238 | mncc_tx_to_cc(call->net, MNCC_REL_REQ, disc); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 239 | |
| 240 | /* send disc to remote */ |
| 241 | if (!(remote = get_call_ref(call->remote_ref))) { |
| 242 | return 0; |
| 243 | } |
| 244 | disc->callref = remote->callref; |
| 245 | DEBUGP(DMNCC, "(call %x) Disconnecting remote with cause %d\n", |
| 246 | remote->callref, disc->cause.value); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 247 | return mncc_tx_to_cc(remote->net, MNCC_DISC_REQ, disc); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static int mncc_rel_ind(struct gsm_call *call, int msg_type, struct gsm_mncc *rel) |
| 251 | { |
| 252 | struct gsm_call *remote; |
| 253 | |
| 254 | /* send release to remote */ |
| 255 | if (!(remote = get_call_ref(call->remote_ref))) { |
| 256 | free_call(call); |
| 257 | return 0; |
| 258 | } |
Holger Hans Peter Freyther | cc2b8b3 | 2011-01-27 15:05:45 +0100 | [diff] [blame] | 259 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 260 | rel->callref = remote->callref; |
| 261 | DEBUGP(DMNCC, "(call %x) Releasing remote with cause %d\n", |
| 262 | call->callref, rel->cause.value); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 263 | |
Holger Hans Peter Freyther | cc2b8b3 | 2011-01-27 15:05:45 +0100 | [diff] [blame] | 264 | /* |
| 265 | * Release this side of the call right now. Otherwise we end up |
| 266 | * in this method for the other call and will also try to release |
| 267 | * it and then we will end up with a double free and a crash |
| 268 | */ |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 269 | free_call(call); |
Holger Hans Peter Freyther | cc2b8b3 | 2011-01-27 15:05:45 +0100 | [diff] [blame] | 270 | mncc_tx_to_cc(remote->net, MNCC_REL_REQ, rel); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static int mncc_rel_cnf(struct gsm_call *call, int msg_type, struct gsm_mncc *rel) |
| 276 | { |
| 277 | free_call(call); |
| 278 | return 0; |
| 279 | } |
| 280 | |
Andreas Eversberg | 5e2832e | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 281 | /* receiving a (speech) traffic frame from the BSC code */ |
| 282 | static int mncc_rcv_data(struct gsm_call *call, int msg_type, |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 283 | struct gsm_data_frame *dfr) |
| 284 | { |
| 285 | struct gsm_trans *remote_trans; |
| 286 | |
| 287 | remote_trans = trans_find_by_callref(call->net, call->remote_ref); |
| 288 | |
| 289 | /* this shouldn't really happen */ |
| 290 | if (!remote_trans || !remote_trans->conn) { |
| 291 | LOGP(DMNCC, LOGL_ERROR, "No transaction or transaction without lchan?!?\n"); |
| 292 | return -EIO; |
| 293 | } |
| 294 | |
| 295 | /* RTP socket of remote end has meanwhile died */ |
| 296 | if (!remote_trans->conn->lchan->abis_ip.rtp_socket) |
| 297 | return -EIO; |
| 298 | |
| 299 | return rtp_send_frame(remote_trans->conn->lchan->abis_ip.rtp_socket, dfr); |
| 300 | } |
| 301 | |
| 302 | |
| 303 | /* Internal MNCC handler input function (from CC -> MNCC -> here) */ |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 304 | int int_mncc_recv(struct gsm_network *net, struct msgb *msg) |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 305 | { |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 306 | void *arg = msgb_data(msg); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 307 | struct gsm_mncc *data = arg; |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 308 | int msg_type = data->msg_type; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 309 | int callref; |
| 310 | struct gsm_call *call = NULL, *callt; |
| 311 | int rc = 0; |
| 312 | |
| 313 | /* Special messages */ |
| 314 | switch(msg_type) { |
| 315 | } |
| 316 | |
| 317 | /* find callref */ |
| 318 | callref = data->callref; |
| 319 | llist_for_each_entry(callt, &call_list, entry) { |
| 320 | if (callt->callref == callref) { |
| 321 | call = callt; |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /* create callref, if setup is received */ |
| 327 | if (!call) { |
| 328 | if (msg_type != MNCC_SETUP_IND) |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 329 | goto out_free; /* drop */ |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 330 | /* create call */ |
| 331 | if (!(call = talloc_zero(tall_call_ctx, struct gsm_call))) { |
| 332 | struct gsm_mncc rel; |
| 333 | |
| 334 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 335 | rel.callref = callref; |
| 336 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 337 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 338 | mncc_tx_to_cc(net, MNCC_REL_REQ, &rel); |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 339 | goto out_free; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 340 | } |
| 341 | llist_add_tail(&call->entry, &call_list); |
| 342 | call->net = net; |
| 343 | call->callref = callref; |
| 344 | DEBUGP(DMNCC, "(call %x) Call created.\n", call->callref); |
| 345 | } |
| 346 | |
Andreas Eversberg | 5e2832e | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 347 | if (mncc_is_data_frame(msg_type)) { |
| 348 | rc = mncc_rcv_data(call, msg_type, arg); |
| 349 | goto out_free; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 350 | } |
| 351 | |
Andreas Eversberg | 5e2832e | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 352 | DEBUGP(DMNCC, "(call %x) Received message %s\n", call->callref, |
| 353 | get_mncc_name(msg_type)); |
| 354 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 355 | switch(msg_type) { |
| 356 | case MNCC_SETUP_IND: |
| 357 | rc = mncc_setup_ind(call, msg_type, arg); |
| 358 | break; |
| 359 | case MNCC_SETUP_CNF: |
| 360 | rc = mncc_setup_cnf(call, msg_type, arg); |
| 361 | break; |
| 362 | case MNCC_SETUP_COMPL_IND: |
| 363 | break; |
| 364 | case MNCC_CALL_CONF_IND: |
| 365 | /* we now need to MODIFY the channel */ |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 366 | data->lchan_mode = determine_lchan_mode(data); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 367 | mncc_tx_to_cc(call->net, MNCC_LCHAN_MODIFY, data); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 368 | break; |
| 369 | case MNCC_ALERT_IND: |
| 370 | rc = mncc_alert_ind(call, msg_type, arg); |
| 371 | break; |
| 372 | case MNCC_NOTIFY_IND: |
| 373 | rc = mncc_notify_ind(call, msg_type, arg); |
| 374 | break; |
| 375 | case MNCC_DISC_IND: |
| 376 | rc = mncc_disc_ind(call, msg_type, arg); |
| 377 | break; |
| 378 | case MNCC_REL_IND: |
| 379 | case MNCC_REJ_IND: |
| 380 | rc = mncc_rel_ind(call, msg_type, arg); |
| 381 | break; |
| 382 | case MNCC_REL_CNF: |
| 383 | rc = mncc_rel_cnf(call, msg_type, arg); |
| 384 | break; |
| 385 | case MNCC_FACILITY_IND: |
| 386 | break; |
| 387 | case MNCC_START_DTMF_IND: |
| 388 | break; |
| 389 | case MNCC_STOP_DTMF_IND: |
| 390 | break; |
| 391 | case MNCC_MODIFY_IND: |
| 392 | mncc_set_cause(data, GSM48_CAUSE_LOC_PRN_S_LU, |
| 393 | GSM48_CC_CAUSE_SERV_OPT_UNIMPL); |
| 394 | DEBUGP(DMNCC, "(call %x) Rejecting MODIFY with cause %d\n", |
| 395 | call->callref, data->cause.value); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 396 | rc = mncc_tx_to_cc(net, MNCC_MODIFY_REJ, data); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 397 | break; |
| 398 | case MNCC_MODIFY_CNF: |
| 399 | break; |
| 400 | case MNCC_HOLD_IND: |
| 401 | mncc_set_cause(data, GSM48_CAUSE_LOC_PRN_S_LU, |
| 402 | GSM48_CC_CAUSE_SERV_OPT_UNIMPL); |
| 403 | DEBUGP(DMNCC, "(call %x) Rejecting HOLD with cause %d\n", |
| 404 | call->callref, data->cause.value); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 405 | rc = mncc_tx_to_cc(net, MNCC_HOLD_REJ, data); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 406 | break; |
| 407 | case MNCC_RETRIEVE_IND: |
| 408 | mncc_set_cause(data, GSM48_CAUSE_LOC_PRN_S_LU, |
| 409 | GSM48_CC_CAUSE_SERV_OPT_UNIMPL); |
| 410 | DEBUGP(DMNCC, "(call %x) Rejecting RETRIEVE with cause %d\n", |
| 411 | call->callref, data->cause.value); |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 412 | rc = mncc_tx_to_cc(net, MNCC_RETRIEVE_REJ, data); |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 413 | break; |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 414 | default: |
| 415 | LOGP(DMNCC, LOGL_NOTICE, "(call %x) Message unhandled\n", callref); |
| 416 | break; |
| 417 | } |
| 418 | |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 419 | out_free: |
Holger Hans Peter Freyther | 1bcd637 | 2012-03-01 20:30:32 +0100 | [diff] [blame] | 420 | msgb_free(msg); |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 421 | |
Harald Welte | 5f77b7f | 2010-12-22 23:54:51 +0100 | [diff] [blame] | 422 | return rc; |
| 423 | } |