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> |
| 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 | |
| 35 | struct 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 | |
| 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); |
| 55 | put_lchan(rllr->lchan); |
| 56 | rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type); |
| 57 | talloc_free(rllr); |
| 58 | } |
| 59 | |
| 60 | static 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 */ |
Harald Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 68 | int rll_establish(struct gsm_lchan *lchan, u_int8_t sapi, |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 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); |
Harald Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 74 | u_int8_t link_id; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 75 | if (!rllr) |
| 76 | return -ENOMEM; |
| 77 | |
Harald Welte | cd419d3 | 2009-08-09 19:06:24 +0200 | [diff] [blame] | 78 | link_id = sapi; |
| 79 | |
| 80 | /* If we are a TCH and not in signalling mode, we need to |
| 81 | * indicate that the new RLL connection is to be made on the SACCH */ |
| 82 | if ((lchan->type == GSM_LCHAN_TCH_F || |
| 83 | lchan->type == GSM_LCHAN_TCH_H) && |
| 84 | lchan->rsl_cmode != RSL_CMOD_SPD_SIGN) |
| 85 | link_id |= 0x40; |
| 86 | |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 87 | use_lchan(lchan); |
| 88 | rllr->lchan = lchan; |
| 89 | rllr->link_id = link_id; |
| 90 | rllr->cb = cb; |
| 91 | rllr->data = data; |
| 92 | |
Harald Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 93 | llist_add(&rllr->list, &bsc_rll_reqs); |
| 94 | |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 95 | rllr->timer.cb = &timer_cb; |
Harald Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 96 | rllr->timer.data = rllr; |
| 97 | |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 98 | bsc_schedule_timer(&rllr->timer, 10, 0); |
| 99 | |
| 100 | /* send the RSL RLL ESTablish REQuest */ |
| 101 | return rsl_establish_request(rllr->lchan, rllr->link_id); |
| 102 | } |
| 103 | |
| 104 | /* Called from RSL code in case we have received an indication regarding |
| 105 | * any RLL link */ |
| 106 | void rll_indication(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t type) |
| 107 | { |
| 108 | struct bsc_rll_req *rllr, *rllr2; |
| 109 | |
| 110 | llist_for_each_entry_safe(rllr, rllr2, &bsc_rll_reqs, list) { |
| 111 | if (rllr->lchan == lchan && |
| 112 | (rllr->link_id & LINKID_MASK) == (link_id & LINKID_MASK)) { |
Harald Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 113 | bsc_del_timer(&rllr->timer); |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 114 | complete_rllr(rllr, type); |
| 115 | return; |
| 116 | } |
| 117 | } |
| 118 | } |