blob: 6a94e7abb46e4ac2c4f41a483de225896860edfe [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>
5 * (C) 2010 by On Waves
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (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
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25#include <openbsc/bsc_api.h>
26#include <openbsc/debug.h>
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +080027#include <openbsc/transaction.h>
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080028
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080029#include <openbsc/gsm_04_11.h>
30
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080031static void msc_sapi_n_reject(struct gsm_subscriber_connection* conn, int dlci)
32{
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080033 int sapi = dlci & 0x7;
34
35 if (sapi == UM_SAPI_SMS)
36 gsm411_sapi_n_reject(conn);
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080037}
38
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080039static void msc_clear_request(struct gsm_subscriber_connection* conn, uint32_t cause)
40{
41 gsm0408_clear_request(conn, cause);
42}
43
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080044static int msc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg,
45 uint16_t chosen_channel)
46{
47 gsm0408_dispatch(conn, msg);
48
49 /* TODO: do better */
50 return BSC_API_CONN_POL_ACCEPT;
51}
52
53static void msc_dtap(struct gsm_subscriber_connection *conn, struct msgb *msg)
54{
55 gsm0408_dispatch(conn, msg);
56}
57
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080058static struct bsc_api msc_handler = {
59 .sapi_n_reject = msc_sapi_n_reject,
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +080060 .clear_request = msc_clear_request,
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080061 .compl_l3 = msc_compl_l3,
62 .dtap = msc_dtap,
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080063};
64
65struct bsc_api *msc_bsc_api() {
66 return &msc_handler;
67}
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +080068
69/* lchan release handling */
70void msc_release_connection(struct gsm_subscriber_connection *conn)
71{
72 struct gsm_trans *trans;
73
74 /* skip when we are in release, e.g. due an error */
75 if (conn->in_release)
76 return;
77
78 /* skip releasing of silent calls as they have no transaction */
79 if (conn->silent_call)
80 return;
81
82 /* check if there is a pending operation */
83 if (conn->loc_operation || conn->sec_operation)
84 return;
85
86 llist_for_each_entry(trans, &conn->bts->network->trans_list, entry) {
87 if (trans->conn == conn)
88 return;
89 }
90
91 /* no more connections, asking to release the channel */
92 conn->in_release = 1;
93 gsm0808_clear(conn);
94}