blob: a8e642fa7b4101a57ebab834a533d1bec56077a6 [file] [log] [blame]
Harald Welteedcc5272009-08-09 13:47:35 +02001/* GSM BSC Radio Link Layer API
2 * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */
3
4/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
5 *
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#include <errno.h>
25
26#include <openbsc/debug.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010027#include <osmocore/talloc.h>
28#include <osmocore/timer.h>
29#include <osmocore/linuxlist.h>
Harald Welteedcc5272009-08-09 13:47:35 +020030#include <openbsc/bsc_rll.h>
31#include <openbsc/gsm_data.h>
32#include <openbsc/chan_alloc.h>
33#include <openbsc/abis_rsl.h>
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +080034#include <openbsc/signal.h>
Harald Welteedcc5272009-08-09 13:47:35 +020035
36struct bsc_rll_req {
37 struct llist_head list;
38 struct timer_list timer;
39
40 struct gsm_lchan *lchan;
41 u_int8_t link_id;
42
43 void (*cb)(struct gsm_lchan *lchan, u_int8_t link_id,
44 void *data, enum bsc_rllr_ind);
45 void *data;
46};
47
48/* we only compare C1, C2 and SAPI */
49#define LINKID_MASK 0xC7
50
51static LLIST_HEAD(bsc_rll_reqs);
52
53static void complete_rllr(struct bsc_rll_req *rllr, enum bsc_rllr_ind type)
54{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010055 struct gsm_subscriber_connection *conn;
56
57 conn = &rllr->lchan->conn;
Harald Welteedcc5272009-08-09 13:47:35 +020058 llist_del(&rllr->list);
Harald Welteedcc5272009-08-09 13:47:35 +020059 rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type);
60 talloc_free(rllr);
61}
62
63static void timer_cb(void *_rllr)
64{
65 struct bsc_rll_req *rllr = _rllr;
66
67 complete_rllr(rllr, BSC_RLLR_IND_TIMEOUT);
68}
69
70/* establish a RLL connection with given SAPI / priority */
Harald Welted11ea932009-08-09 19:06:24 +020071int rll_establish(struct gsm_lchan *lchan, u_int8_t sapi,
Harald Welteedcc5272009-08-09 13:47:35 +020072 void (*cb)(struct gsm_lchan *, u_int8_t, void *,
73 enum bsc_rllr_ind),
74 void *data)
75{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010076 struct gsm_subscriber_connection *conn;
Harald Welteedcc5272009-08-09 13:47:35 +020077 struct bsc_rll_req *rllr = talloc_zero(tall_bsc_ctx, struct bsc_rll_req);
Harald Welted11ea932009-08-09 19:06:24 +020078 u_int8_t link_id;
Harald Welteedcc5272009-08-09 13:47:35 +020079 if (!rllr)
80 return -ENOMEM;
81
Harald Welted11ea932009-08-09 19:06:24 +020082 link_id = sapi;
83
84 /* If we are a TCH and not in signalling mode, we need to
85 * indicate that the new RLL connection is to be made on the SACCH */
86 if ((lchan->type == GSM_LCHAN_TCH_F ||
Holger Hans Peter Freyther9cc020a2010-03-24 14:11:39 +010087 lchan->type == GSM_LCHAN_TCH_H) && sapi != 0)
Harald Welted11ea932009-08-09 19:06:24 +020088 link_id |= 0x40;
89
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010090 conn = &lchan->conn;
Harald Welteedcc5272009-08-09 13:47:35 +020091 rllr->lchan = lchan;
92 rllr->link_id = link_id;
93 rllr->cb = cb;
94 rllr->data = data;
95
Harald Welte1c409272009-08-09 14:13:58 +020096 llist_add(&rllr->list, &bsc_rll_reqs);
97
Harald Welteedcc5272009-08-09 13:47:35 +020098 rllr->timer.cb = &timer_cb;
Harald Welte1c409272009-08-09 14:13:58 +020099 rllr->timer.data = rllr;
100
Harald Welteedcc5272009-08-09 13:47:35 +0200101 bsc_schedule_timer(&rllr->timer, 10, 0);
102
103 /* send the RSL RLL ESTablish REQuest */
104 return rsl_establish_request(rllr->lchan, rllr->link_id);
105}
106
107/* Called from RSL code in case we have received an indication regarding
108 * any RLL link */
109void rll_indication(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t type)
110{
111 struct bsc_rll_req *rllr, *rllr2;
112
113 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
114 if (rllr->lchan == lchan &&
115 (rllr->link_id & LINKID_MASK) == (link_id & LINKID_MASK)) {
Harald Welte1c409272009-08-09 14:13:58 +0200116 bsc_del_timer(&rllr->timer);
Harald Welteedcc5272009-08-09 13:47:35 +0200117 complete_rllr(rllr, type);
118 return;
119 }
120 }
121}
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +0800122
123static int rll_lchan_signal(unsigned int subsys, unsigned int signal,
124 void *handler_data, void *signal_data)
125{
126 struct challoc_signal_data *challoc;
127 struct bsc_rll_req *rllr, *rllr2;
128
129 if (subsys != SS_CHALLOC || signal != S_CHALLOC_FREED)
130 return 0;
131
132 challoc = (struct challoc_signal_data *) signal_data;
133
134 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
135 if (rllr->lchan == challoc->lchan) {
136 bsc_del_timer(&rllr->timer);
137 complete_rllr(rllr, BSC_RLLR_IND_ERR_IND);
138 }
139 }
140
141 return 0;
142}
143
144static __attribute__((constructor)) void on_dso_load_rll(void)
145{
146 register_signal_handler(SS_CHALLOC, rll_lchan_signal, NULL);
147}