blob: 93b6210f0943ac76d893cfc21f7abe8b16e95fd9 [file] [log] [blame]
Holger Hans Peter Freytherec32b582010-03-23 07:40:46 +01001/* GSM 08.08 like API for OpenBSC. The bridge from MSC to BSC */
2
3/* (C) 2010 by Holger Hans Peter Freyther
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +08004 * (C) 2010 by On Waves
Holger Hans Peter Freyther2a9285c2010-06-14 18:03:06 +08005 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freytherec32b582010-03-23 07:40:46 +01006 *
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>
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +080026#include <openbsc/gsm_data.h>
27#include <openbsc/signal.h>
Holger Hans Peter Freytherec32b582010-03-23 07:40:46 +010028#include <openbsc/abis_rsl.h>
29
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +080030#include <osmocore/talloc.h>
31
32int bsc_api_init(struct gsm_network *network, struct bsc_api *api)
33{
34 network->bsc_api = api;
35 return 0;
36}
Holger Hans Peter Freytherec32b582010-03-23 07:40:46 +010037
38int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
39 struct msgb *msg, int link_id)
40{
41 msg->lchan = conn->lchan;
42 msg->trx = msg->lchan->ts->trx;
43 return rsl_data_request(msg, link_id);
44}
Holger Hans Peter Freyther2a9285c2010-06-14 18:03:06 +080045
46/* dequeue messages to layer 4 */
47int bsc_upqueue(struct gsm_network *net)
48{
49 struct gsm_mncc *mncc;
50 struct msgb *msg;
51 int work = 0;
52
53 if (net)
54 while ((msg = msgb_dequeue(&net->upqueue))) {
55 mncc = (struct gsm_mncc *)msg->data;
56 if (net->mncc_recv)
57 net->mncc_recv(net, mncc->msg_type, mncc);
58 work = 1; /* work done */
59 talloc_free(msg);
60 }
61
62 return work;
63}
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +080064
65static int bsc_handle_lchan_signal(unsigned int subsys, unsigned int signal,
66 void *handler_data, void *signal_data)
67{
68 struct bsc_api *bsc;
69 struct gsm_lchan *lchan;
70
71 if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE)
72 return 0;
73
74 lchan = (struct gsm_lchan *)signal_data;
75 if (!lchan)
76 return 0;
77
78
79 bsc = lchan->ts->trx->bts->network->bsc_api;
80 if (!bsc || !bsc->clear_request)
81 return 0;
82
83 bsc->clear_request(&lchan->conn, 0);
84 return 0;
85}
86
87static __attribute__((constructor)) void on_dso_load_bsc(void)
88{
89 register_signal_handler(SS_LCHAN, bsc_handle_lchan_signal, NULL);
90}