blob: bb488da15985aca3cd44aeaca36d9b755c23d279 [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>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010026#include <osmocom/core/talloc.h>
27#include <osmocom/core/timer.h>
28#include <osmocom/core/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;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020037 struct osmo_timer_list timer;
Harald Welteedcc5272009-08-09 13:47:35 +020038
39 struct gsm_lchan *lchan;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020040 uint8_t link_id;
Harald Welteedcc5272009-08-09 13:47:35 +020041
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020042 void (*cb)(struct gsm_lchan *lchan, uint8_t link_id,
Harald Welteedcc5272009-08-09 13:47:35 +020043 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 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020067int rll_establish(struct gsm_lchan *lchan, uint8_t sapi,
68 void (*cb)(struct gsm_lchan *, uint8_t, void *,
Harald Welteedcc5272009-08-09 13:47:35 +020069 enum bsc_rllr_ind),
70 void *data)
71{
72 struct bsc_rll_req *rllr = talloc_zero(tall_bsc_ctx, struct bsc_rll_req);
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020073 uint8_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
Pablo Neira Ayuso51215762017-05-08 20:57:52 +020092 osmo_timer_setup(&rllr->timer, timer_cb, rllr);
Holger Hans Peter Freytherb1d71d42013-12-27 19:13:11 +010093 osmo_timer_schedule(&rllr->timer, 7, 0);
Harald Welteedcc5272009-08-09 13:47:35 +020094
95 /* send the RSL RLL ESTablish REQuest */
96 return rsl_establish_request(rllr->lchan, rllr->link_id);
97}
98
99/* Called from RSL code in case we have received an indication regarding
100 * any RLL link */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200101void rll_indication(struct gsm_lchan *lchan, uint8_t link_id, uint8_t type)
Harald Welteedcc5272009-08-09 13:47:35 +0200102{
103 struct bsc_rll_req *rllr, *rllr2;
104
105 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
106 if (rllr->lchan == lchan &&
107 (rllr->link_id & LINKID_MASK) == (link_id & LINKID_MASK)) {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200108 osmo_timer_del(&rllr->timer);
Harald Welteedcc5272009-08-09 13:47:35 +0200109 complete_rllr(rllr, type);
110 return;
111 }
112 }
113}
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +0800114
115static int rll_lchan_signal(unsigned int subsys, unsigned int signal,
116 void *handler_data, void *signal_data)
117{
118 struct challoc_signal_data *challoc;
119 struct bsc_rll_req *rllr, *rllr2;
120
121 if (subsys != SS_CHALLOC || signal != S_CHALLOC_FREED)
122 return 0;
123
124 challoc = (struct challoc_signal_data *) signal_data;
125
126 llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) {
127 if (rllr->lchan == challoc->lchan) {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200128 osmo_timer_del(&rllr->timer);
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +0800129 complete_rllr(rllr, BSC_RLLR_IND_ERR_IND);
130 }
131 }
132
133 return 0;
134}
135
136static __attribute__((constructor)) void on_dso_load_rll(void)
137{
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200138 osmo_signal_register_handler(SS_CHALLOC, rll_lchan_signal, NULL);
Holger Hans Peter Freyther2e234f52010-06-10 17:36:46 +0800139}