Harald Welte | edcc527 | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 9 | * 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 Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 17 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * 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 Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <errno.h> |
| 24 | |
| 25 | #include <openbsc/debug.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/core/talloc.h> |
| 27 | #include <osmocom/core/timer.h> |
| 28 | #include <osmocom/core/linuxlist.h> |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 29 | #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 Freyther | 2e234f5 | 2010-06-10 17:36:46 +0800 | [diff] [blame] | 33 | #include <openbsc/signal.h> |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 34 | |
| 35 | struct bsc_rll_req { |
| 36 | struct llist_head list; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 37 | struct osmo_timer_list timer; |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 38 | |
| 39 | struct gsm_lchan *lchan; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 40 | uint8_t link_id; |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 41 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 42 | void (*cb)(struct gsm_lchan *lchan, uint8_t link_id, |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 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 | |
| 50 | static LLIST_HEAD(bsc_rll_reqs); |
| 51 | |
| 52 | static void complete_rllr(struct bsc_rll_req *rllr, enum bsc_rllr_ind type) |
| 53 | { |
| 54 | llist_del(&rllr->list); |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 55 | rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type); |
| 56 | talloc_free(rllr); |
| 57 | } |
| 58 | |
| 59 | static 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 Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 67 | int rll_establish(struct gsm_lchan *lchan, uint8_t sapi, |
| 68 | void (*cb)(struct gsm_lchan *, uint8_t, void *, |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 69 | 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 Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 73 | uint8_t link_id; |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 74 | if (!rllr) |
| 75 | return -ENOMEM; |
| 76 | |
Harald Welte | d11ea93 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 77 | 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 Freyther | 9cc020a | 2010-03-24 14:11:39 +0100 | [diff] [blame] | 82 | lchan->type == GSM_LCHAN_TCH_H) && sapi != 0) |
Harald Welte | d11ea93 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 83 | link_id |= 0x40; |
| 84 | |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 85 | rllr->lchan = lchan; |
| 86 | rllr->link_id = link_id; |
| 87 | rllr->cb = cb; |
| 88 | rllr->data = data; |
| 89 | |
Harald Welte | 1c40927 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 90 | llist_add(&rllr->list, &bsc_rll_reqs); |
| 91 | |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 92 | rllr->timer.cb = &timer_cb; |
Harald Welte | 1c40927 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 93 | rllr->timer.data = rllr; |
| 94 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 95 | osmo_timer_schedule(&rllr->timer, 10, 0); |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 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 */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 103 | void rll_indication(struct gsm_lchan *lchan, uint8_t link_id, uint8_t type) |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 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)) { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 110 | osmo_timer_del(&rllr->timer); |
Harald Welte | edcc527 | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 111 | complete_rllr(rllr, type); |
| 112 | return; |
| 113 | } |
| 114 | } |
| 115 | } |
Holger Hans Peter Freyther | 2e234f5 | 2010-06-10 17:36:46 +0800 | [diff] [blame] | 116 | |
| 117 | static 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) { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 130 | osmo_timer_del(&rllr->timer); |
Holger Hans Peter Freyther | 2e234f5 | 2010-06-10 17:36:46 +0800 | [diff] [blame] | 131 | complete_rllr(rllr, BSC_RLLR_IND_ERR_IND); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static __attribute__((constructor)) void on_dso_load_rll(void) |
| 139 | { |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 140 | osmo_signal_register_handler(SS_CHALLOC, rll_lchan_signal, NULL); |
Holger Hans Peter Freyther | 2e234f5 | 2010-06-10 17:36:46 +0800 | [diff] [blame] | 141 | } |