blob: 57e8c15cedde07c67b1adea76b1f7023e5f4482c [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>
27#include <openbsc/talloc.h>
28#include <openbsc/timer.h>
29#include <openbsc/linuxlist.h>
30#include <openbsc/bsc_rll.h>
31#include <openbsc/gsm_data.h>
32#include <openbsc/chan_alloc.h>
33#include <openbsc/abis_rsl.h>
34
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);
55 put_lchan(rllr->lchan);
56 rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type);
57 talloc_free(rllr);
58}
59
60static void timer_cb(void *_rllr)
61{
62 struct bsc_rll_req *rllr = _rllr;
63
64 complete_rllr(rllr, BSC_RLLR_IND_TIMEOUT);
65}
66
67/* establish a RLL connection with given SAPI / priority */
68int rll_establish(struct gsm_lchan *lchan, u_int8_t link_id,
69 void (*cb)(struct gsm_lchan *, u_int8_t, void *,
70 enum bsc_rllr_ind),
71 void *data)
72{
73 struct bsc_rll_req *rllr = talloc_zero(tall_bsc_ctx, struct bsc_rll_req);
74 if (!rllr)
75 return -ENOMEM;
76
77 use_lchan(lchan);
78 rllr->lchan = lchan;
79 rllr->link_id = link_id;
80 rllr->cb = cb;
81 rllr->data = data;
82
Harald Welte1c409272009-08-09 14:13:58 +020083 llist_add(&rllr->list, &bsc_rll_reqs);
84
Harald Welteedcc5272009-08-09 13:47:35 +020085 rllr->timer.cb = &timer_cb;
Harald Welte1c409272009-08-09 14:13:58 +020086 rllr->timer.data = rllr;
87
Harald Welteedcc5272009-08-09 13:47:35 +020088 bsc_schedule_timer(&rllr->timer, 10, 0);
89
90 /* send the RSL RLL ESTablish REQuest */
91 return rsl_establish_request(rllr->lchan, rllr->link_id);
92}
93
94/* Called from RSL code in case we have received an indication regarding
95 * any RLL link */
96void rll_indication(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t type)
97{
98 struct bsc_rll_req *rllr, *rllr2;
99
100 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
101 if (rllr->lchan == lchan &&
102 (rllr->link_id & LINKID_MASK) == (link_id & LINKID_MASK)) {
Harald Welte1c409272009-08-09 14:13:58 +0200103 bsc_del_timer(&rllr->timer);
Harald Welteedcc5272009-08-09 13:47:35 +0200104 complete_rllr(rllr, type);
105 return;
106 }
107 }
108}