blob: 722f3fafcc27dc35565f1f6091432cb9c0f5bc95 [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
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
Harald Welteedcc5272009-08-09 13:47:35 +020011 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Harald Welteedcc5272009-08-09 13:47:35 +020017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welteedcc5272009-08-09 13:47:35 +020020 *
21 */
22
23#include <errno.h>
24
25#include <openbsc/debug.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010026#include <osmocore/talloc.h>
27#include <osmocore/timer.h>
28#include <osmocore/linuxlist.h>
Harald Welteedcc5272009-08-09 13:47:35 +020029#include <openbsc/bsc_rll.h>
30#include <openbsc/gsm_data.h>
31#include <openbsc/chan_alloc.h>
32#include <openbsc/abis_rsl.h>
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +080033#include <openbsc/signal.h>
Harald Welteedcc5272009-08-09 13:47:35 +020034
35struct bsc_rll_req {
36 struct llist_head list;
37 struct timer_list timer;
38
39 struct gsm_lchan *lchan;
40 u_int8_t link_id;
41
42 void (*cb)(struct gsm_lchan *lchan, u_int8_t link_id,
43 void *data, enum bsc_rllr_ind);
44 void *data;
45};
46
47/* we only compare C1, C2 and SAPI */
48#define LINKID_MASK 0xC7
49
50static LLIST_HEAD(bsc_rll_reqs);
51
52static void complete_rllr(struct bsc_rll_req *rllr, enum bsc_rllr_ind type)
53{
54 llist_del(&rllr->list);
Harald Welteedcc5272009-08-09 13:47:35 +020055 rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type);
56 talloc_free(rllr);
57}
58
59static void timer_cb(void *_rllr)
60{
61 struct bsc_rll_req *rllr = _rllr;
62
63 complete_rllr(rllr, BSC_RLLR_IND_TIMEOUT);
64}
65
66/* establish a RLL connection with given SAPI / priority */
Harald Welted11ea932009-08-09 19:06:24 +020067int rll_establish(struct gsm_lchan *lchan, u_int8_t sapi,
Harald Welteedcc5272009-08-09 13:47:35 +020068 void (*cb)(struct gsm_lchan *, u_int8_t, void *,
69 enum bsc_rllr_ind),
70 void *data)
71{
72 struct bsc_rll_req *rllr = talloc_zero(tall_bsc_ctx, struct bsc_rll_req);
Harald Welted11ea932009-08-09 19:06:24 +020073 u_int8_t link_id;
Harald Welteedcc5272009-08-09 13:47:35 +020074 if (!rllr)
75 return -ENOMEM;
76
Harald Welted11ea932009-08-09 19:06:24 +020077 link_id = sapi;
78
79 /* If we are a TCH and not in signalling mode, we need to
80 * indicate that the new RLL connection is to be made on the SACCH */
81 if ((lchan->type == GSM_LCHAN_TCH_F ||
Holger Hans Peter Freyther9cc020a2010-03-24 14:11:39 +010082 lchan->type == GSM_LCHAN_TCH_H) && sapi != 0)
Harald Welted11ea932009-08-09 19:06:24 +020083 link_id |= 0x40;
84
Harald Welteedcc5272009-08-09 13:47:35 +020085 rllr->lchan = lchan;
86 rllr->link_id = link_id;
87 rllr->cb = cb;
88 rllr->data = data;
89
Harald Welte1c409272009-08-09 14:13:58 +020090 llist_add(&rllr->list, &bsc_rll_reqs);
91
Harald Welteedcc5272009-08-09 13:47:35 +020092 rllr->timer.cb = &timer_cb;
Harald Welte1c409272009-08-09 14:13:58 +020093 rllr->timer.data = rllr;
94
Harald Welteedcc5272009-08-09 13:47:35 +020095 bsc_schedule_timer(&rllr->timer, 10, 0);
96
97 /* send the RSL RLL ESTablish REQuest */
98 return rsl_establish_request(rllr->lchan, rllr->link_id);
99}
100
101/* Called from RSL code in case we have received an indication regarding
102 * any RLL link */
103void rll_indication(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t type)
104{
105 struct bsc_rll_req *rllr, *rllr2;
106
107 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
108 if (rllr->lchan == lchan &&
109 (rllr->link_id & LINKID_MASK) == (link_id & LINKID_MASK)) {
Harald Welte1c409272009-08-09 14:13:58 +0200110 bsc_del_timer(&rllr->timer);
Harald Welteedcc5272009-08-09 13:47:35 +0200111 complete_rllr(rllr, type);
112 return;
113 }
114 }
115}
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +0800116
117static int rll_lchan_signal(unsigned int subsys, unsigned int signal,
118 void *handler_data, void *signal_data)
119{
120 struct challoc_signal_data *challoc;
121 struct bsc_rll_req *rllr, *rllr2;
122
123 if (subsys != SS_CHALLOC || signal != S_CHALLOC_FREED)
124 return 0;
125
126 challoc = (struct challoc_signal_data *) signal_data;
127
128 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
129 if (rllr->lchan == challoc->lchan) {
130 bsc_del_timer(&rllr->timer);
131 complete_rllr(rllr, BSC_RLLR_IND_ERR_IND);
132 }
133 }
134
135 return 0;
136}
137
138static __attribute__((constructor)) void on_dso_load_rll(void)
139{
140 register_signal_handler(SS_CHALLOC, rll_lchan_signal, NULL);
141}