blob: 9a4f5aae4c30c34e846069dc61b94fa1cc747d4b [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>
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{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010054 struct gsm_subscriber_connection *conn;
55
56 conn = &rllr->lchan->conn;
Harald Welteedcc5272009-08-09 13:47:35 +020057 llist_del(&rllr->list);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010058 put_subscr_con(conn);
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;
91 use_subscr_con(conn);
Harald Welteedcc5272009-08-09 13:47:35 +020092 rllr->lchan = lchan;
93 rllr->link_id = link_id;
94 rllr->cb = cb;
95 rllr->data = data;
96
Harald Welte1c409272009-08-09 14:13:58 +020097 llist_add(&rllr->list, &bsc_rll_reqs);
98
Harald Welteedcc5272009-08-09 13:47:35 +020099 rllr->timer.cb = &timer_cb;
Harald Welte1c409272009-08-09 14:13:58 +0200100 rllr->timer.data = rllr;
101
Harald Welteedcc5272009-08-09 13:47:35 +0200102 bsc_schedule_timer(&rllr->timer, 10, 0);
103
104 /* send the RSL RLL ESTablish REQuest */
105 return rsl_establish_request(rllr->lchan, rllr->link_id);
106}
107
108/* Called from RSL code in case we have received an indication regarding
109 * any RLL link */
110void rll_indication(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t type)
111{
112 struct bsc_rll_req *rllr, *rllr2;
113
114 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
115 if (rllr->lchan == lchan &&
116 (rllr->link_id & LINKID_MASK) == (link_id & LINKID_MASK)) {
Harald Welte1c409272009-08-09 14:13:58 +0200117 bsc_del_timer(&rllr->timer);
Harald Welteedcc5272009-08-09 13:47:35 +0200118 complete_rllr(rllr, type);
119 return;
120 }
121 }
122}