Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 1 | /* 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 Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 27 | #include <osmocore/talloc.h> |
| 28 | #include <osmocore/timer.h> |
| 29 | #include <osmocore/linuxlist.h> |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 30 | #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 Freyther | b9c5c20 | 2010-06-10 17:36:46 +0800 | [diff] [blame] | 34 | #include <openbsc/signal.h> |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 35 | |
| 36 | struct 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 | |
| 51 | static LLIST_HEAD(bsc_rll_reqs); |
| 52 | |
| 53 | static void complete_rllr(struct bsc_rll_req *rllr, enum bsc_rllr_ind type) |
| 54 | { |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 55 | struct gsm_subscriber_connection *conn; |
| 56 | |
| 57 | conn = &rllr->lchan->conn; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 58 | llist_del(&rllr->list); |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 59 | rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type); |
| 60 | talloc_free(rllr); |
| 61 | } |
| 62 | |
| 63 | static 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 Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 71 | int rll_establish(struct gsm_lchan *lchan, u_int8_t sapi, |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 72 | void (*cb)(struct gsm_lchan *, u_int8_t, void *, |
| 73 | enum bsc_rllr_ind), |
| 74 | void *data) |
| 75 | { |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 76 | struct gsm_subscriber_connection *conn; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 77 | struct bsc_rll_req *rllr = talloc_zero(tall_bsc_ctx, struct bsc_rll_req); |
Harald Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 78 | u_int8_t link_id; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 79 | if (!rllr) |
| 80 | return -ENOMEM; |
| 81 | |
Harald Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 82 | 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 Freyther | f670ec1 | 2010-03-24 14:11:39 +0100 | [diff] [blame] | 87 | lchan->type == GSM_LCHAN_TCH_H) && sapi != 0) |
Harald Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 88 | link_id |= 0x40; |
| 89 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 90 | conn = &lchan->conn; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 91 | rllr->lchan = lchan; |
| 92 | rllr->link_id = link_id; |
| 93 | rllr->cb = cb; |
| 94 | rllr->data = data; |
| 95 | |
Harald Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 96 | llist_add(&rllr->list, &bsc_rll_reqs); |
| 97 | |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 98 | rllr->timer.cb = &timer_cb; |
Harald Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 99 | rllr->timer.data = rllr; |
| 100 | |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 101 | 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 */ |
| 109 | void 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 Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 116 | bsc_del_timer(&rllr->timer); |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 117 | complete_rllr(rllr, type); |
| 118 | return; |
| 119 | } |
| 120 | } |
| 121 | } |
Holger Hans Peter Freyther | b9c5c20 | 2010-06-10 17:36:46 +0800 | [diff] [blame] | 122 | |
| 123 | static 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 | |
| 144 | static __attribute__((constructor)) void on_dso_load_rll(void) |
| 145 | { |
| 146 | register_signal_handler(SS_CHALLOC, rll_lchan_signal, NULL); |
| 147 | } |