blob: 8c86dcc8e04f7d4ca701074318cfe44e681e4376 [file] [log] [blame]
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +08001/* main MSC management code... */
2
3/*
4 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freyther85531cc2010-10-06 20:37:09 +08005 * (C) 2010 by On-Waves
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +08006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080021 *
22 */
23
24#include <openbsc/bsc_api.h>
25#include <openbsc/debug.h>
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +080026#include <openbsc/transaction.h>
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080027
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080028#include <openbsc/gsm_04_11.h>
29
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +080030static void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci)
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080031{
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080032 int sapi = dlci & 0x7;
33
34 if (sapi == UM_SAPI_SMS)
35 gsm411_sapi_n_reject(conn);
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080036}
37
Holger Hans Peter Freyther05c68842010-11-03 19:01:58 +010038static int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080039{
40 gsm0408_clear_request(conn, cause);
Holger Hans Peter Freyther182c81f2010-12-29 16:28:33 +010041 if (conn->put_channel) {
42 conn->put_channel = 0;
43 subscr_put_channel(conn->subscr);
44 }
Holger Hans Peter Freyther05c68842010-11-03 19:01:58 +010045 return 1;
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080046}
47
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080048static int msc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg,
49 uint16_t chosen_channel)
50{
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080051 gsm0408_new_conn(conn);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080052 gsm0408_dispatch(conn, msg);
53
54 /* TODO: do better */
55 return BSC_API_CONN_POL_ACCEPT;
56}
57
Holger Hans Peter Freyther46caa302010-11-04 12:18:00 +010058static void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg)
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080059{
60 gsm0408_dispatch(conn, msg);
61}
62
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080063static struct bsc_api msc_handler = {
64 .sapi_n_reject = msc_sapi_n_reject,
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080065 .clear_request = msc_clear_request,
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080066 .compl_l3 = msc_compl_l3,
67 .dtap = msc_dtap,
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080068};
69
70struct bsc_api *msc_bsc_api() {
71 return &msc_handler;
72}
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +080073
74/* lchan release handling */
75void msc_release_connection(struct gsm_subscriber_connection *conn)
76{
77 struct gsm_trans *trans;
78
79 /* skip when we are in release, e.g. due an error */
80 if (conn->in_release)
81 return;
82
83 /* skip releasing of silent calls as they have no transaction */
84 if (conn->silent_call)
85 return;
86
87 /* check if there is a pending operation */
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080088 if (conn->loc_operation || conn->sec_operation || conn->anch_operation)
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +080089 return;
90
91 llist_for_each_entry(trans, &conn->bts->network->trans_list, entry) {
92 if (trans->conn == conn)
93 return;
94 }
95
96 /* no more connections, asking to release the channel */
97 conn->in_release = 1;
98 gsm0808_clear(conn);
Holger Hans Peter Freyther182c81f2010-12-29 16:28:33 +010099 if (conn->put_channel) {
100 conn->put_channel = 0;
101 subscr_put_channel(conn->subscr);
102 }
Holger Hans Peter Freytheraaa40b82010-09-16 20:48:15 +0800103 subscr_con_free(conn);
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800104}