Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* GSM Radio Signalling Link messages on the A-bis interface |
| 2 | * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */ |
| 3 | |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 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 <stdio.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 26 | #include <errno.h> |
| 27 | #include <sys/types.h> |
| 28 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 29 | #include <openbsc/gsm_data.h> |
| 30 | #include <openbsc/gsm_04_08.h> |
| 31 | #include <openbsc/abis_rsl.h> |
| 32 | #include <openbsc/chan_alloc.h> |
| 33 | #include <openbsc/debug.h> |
| 34 | #include <openbsc/tlv.h> |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 35 | #include <openbsc/paging.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 36 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 37 | #define RSL_ALLOC_SIZE 1024 |
| 38 | #define RSL_ALLOC_HEADROOM 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 39 | |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 40 | #define MAX(a, b) (a) >= (b) ? (a) : (b) |
| 41 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 42 | static u_int8_t mdisc_by_msgtype(u_int8_t msg_type) |
| 43 | { |
| 44 | /* mask off the transparent bit ? */ |
| 45 | msg_type &= 0xfe; |
| 46 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 47 | if ((msg_type & 0xf0) == 0x00) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 48 | return ABIS_RSL_MDISC_RLL; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 49 | if ((msg_type & 0xf0) == 0x10) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 50 | if (msg_type >= 0x19 && msg_type <= 0x22) |
| 51 | return ABIS_RSL_MDISC_TRX; |
| 52 | else |
| 53 | return ABIS_RSL_MDISC_COM_CHAN; |
| 54 | } |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 55 | if ((msg_type & 0xe0) == 0x20) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 56 | return ABIS_RSL_MDISC_DED_CHAN; |
| 57 | |
| 58 | return ABIS_RSL_MDISC_LOC; |
| 59 | } |
| 60 | |
| 61 | static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh, |
| 62 | u_int8_t msg_type) |
| 63 | { |
| 64 | dh->c.msg_discr = mdisc_by_msgtype(msg_type); |
| 65 | dh->c.msg_type = msg_type; |
| 66 | dh->ie_chan = RSL_IE_CHAN_NR; |
| 67 | } |
| 68 | |
| 69 | static inline void init_llm_hdr(struct abis_rsl_rll_hdr *dh, |
| 70 | u_int8_t msg_type) |
| 71 | { |
| 72 | /* dh->c.msg_discr = mdisc_by_msgtype(msg_type); */ |
| 73 | dh->c.msg_discr = ABIS_RSL_MDISC_RLL; |
| 74 | dh->c.msg_type = msg_type; |
| 75 | dh->ie_chan = RSL_IE_CHAN_NR; |
| 76 | dh->ie_link_id = RSL_IE_LINK_IDENT; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /* encode channel number as per Section 9.3.1 */ |
| 81 | u_int8_t rsl_enc_chan_nr(u_int8_t type, u_int8_t subch, u_int8_t timeslot) |
| 82 | { |
| 83 | u_int8_t ret; |
| 84 | |
| 85 | ret = (timeslot & 0x07) | type; |
| 86 | |
| 87 | switch (type) { |
| 88 | case RSL_CHAN_Lm_ACCHs: |
| 89 | subch &= 0x01; |
| 90 | break; |
| 91 | case RSL_CHAN_SDCCH4_ACCH: |
| 92 | subch &= 0x07; |
| 93 | break; |
| 94 | case RSL_CHAN_SDCCH8_ACCH: |
| 95 | subch &= 0x07; |
| 96 | break; |
| 97 | default: |
| 98 | /* no subchannels allowed */ |
| 99 | subch = 0x00; |
| 100 | break; |
| 101 | } |
| 102 | ret |= (subch << 3); |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 107 | /* determine logical channel based on TRX and channel number IE */ |
| 108 | struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr) |
| 109 | { |
| 110 | struct gsm_lchan *lchan; |
| 111 | u_int8_t ts_nr = chan_nr & 0x07; |
| 112 | u_int8_t cbits = chan_nr >> 3; |
| 113 | u_int8_t lch_idx; |
| 114 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr]; |
| 115 | |
| 116 | if (cbits == 0x01) { |
| 117 | lch_idx = 0; /* TCH/F */ |
| 118 | if (ts->pchan != GSM_PCHAN_TCH_F) |
| 119 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 120 | chan_nr, ts->pchan); |
| 121 | } else if ((cbits & 0x1e) == 0x02) { |
| 122 | lch_idx = cbits & 0x1; /* TCH/H */ |
| 123 | if (ts->pchan != GSM_PCHAN_TCH_H) |
| 124 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 125 | chan_nr, ts->pchan); |
| 126 | } else if ((cbits & 0x1c) == 0x04) { |
| 127 | lch_idx = cbits & 0x3; /* SDCCH/4 */ |
| 128 | if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4) |
| 129 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 130 | chan_nr, ts->pchan); |
| 131 | } else if ((cbits & 0x18) == 0x08) { |
| 132 | lch_idx = cbits & 0x7; /* SDCCH/8 */ |
| 133 | if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C) |
| 134 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 135 | chan_nr, ts->pchan); |
| 136 | } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) { |
| 137 | lch_idx = 0; |
| 138 | if (ts->pchan != GSM_PCHAN_CCCH && |
| 139 | ts->pchan != GSM_PCHAN_CCCH_SDCCH4) |
| 140 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 141 | chan_nr, ts->pchan); |
| 142 | /* FIXME: we should not return first sdcch4 !!! */ |
| 143 | } else { |
| 144 | fprintf(stderr, "unknown chan_nr=0x%02x\n", chan_nr); |
| 145 | return NULL; |
| 146 | } |
| 147 | |
| 148 | lchan = &ts->lchan[lch_idx]; |
| 149 | |
| 150 | return lchan; |
| 151 | } |
| 152 | |
| 153 | u_int8_t lchan2chan_nr(struct gsm_lchan *lchan) |
| 154 | { |
| 155 | struct gsm_bts_trx_ts *ts = lchan->ts; |
| 156 | u_int8_t cbits, chan_nr; |
| 157 | |
| 158 | switch (ts->pchan) { |
| 159 | case GSM_PCHAN_TCH_F: |
| 160 | cbits = 0x01; |
| 161 | break; |
| 162 | case GSM_PCHAN_TCH_H: |
| 163 | cbits = 0x02; |
| 164 | cbits += lchan->nr; |
| 165 | break; |
| 166 | case GSM_PCHAN_CCCH_SDCCH4: |
| 167 | cbits = 0x04; |
| 168 | cbits += lchan->nr; |
| 169 | break; |
| 170 | case GSM_PCHAN_SDCCH8_SACCH8C: |
| 171 | cbits = 0x08; |
| 172 | cbits += lchan->nr; |
| 173 | break; |
| 174 | default: |
| 175 | case GSM_PCHAN_CCCH: |
| 176 | cbits = 0x10; |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | chan_nr = (cbits << 3) | (ts->nr & 0x7); |
| 181 | |
| 182 | return chan_nr; |
| 183 | } |
| 184 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 185 | /* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */ |
| 186 | u_int64_t str_to_imsi(const char *imsi_str) |
| 187 | { |
| 188 | u_int64_t ret; |
| 189 | |
| 190 | ret = strtoull(imsi_str, NULL, 10); |
| 191 | |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | /* Table 5 Clause 7 TS 05.02 */ |
| 196 | unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res) |
| 197 | { |
| 198 | if (!bs_ccch_sdcch_comb) |
| 199 | return 9 - bs_ag_blks_res; |
| 200 | else |
| 201 | return 3 - bs_ag_blks_res; |
| 202 | } |
| 203 | |
| 204 | /* Chapter 6.5.2 of TS 05.02 */ |
| 205 | unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans, |
| 206 | unsigned int n_pag_blocks) |
| 207 | { |
| 208 | return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks; |
| 209 | } |
| 210 | |
| 211 | /* Chapter 6.5.2 of TS 05.02 */ |
| 212 | unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans, |
| 213 | int n_pag_blocks) |
| 214 | { |
| 215 | return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks; |
| 216 | } |
| 217 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 218 | static struct msgb *rsl_msgb_alloc(void) |
| 219 | { |
| 220 | return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM); |
| 221 | } |
| 222 | |
Harald Welte | 362322e | 2009-02-15 14:36:38 +0000 | [diff] [blame^] | 223 | #define MACBLOCK_SIZE 23 |
| 224 | static void pad_macblock(u_int8_t *out, const u_int8_t *in, int len) |
| 225 | { |
| 226 | memcpy(out, in, len); |
| 227 | |
| 228 | if (len < MACBLOCK_SIZE) |
| 229 | memset(out+len, 0x2b, MACBLOCK_SIZE-len); |
| 230 | } |
| 231 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 232 | /* Send a BCCH_INFO message as per Chapter 8.5.1 */ |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 233 | int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 234 | const u_int8_t *data, int len) |
| 235 | { |
| 236 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 237 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 238 | |
| 239 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh); |
| 240 | init_dchan_hdr(dh, RSL_MT_BCCH_INFO); |
| 241 | dh->chan_nr = RSL_CHAN_BCCH; |
| 242 | |
| 243 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
| 244 | msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data); |
| 245 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 246 | msg->trx = trx; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 247 | |
| 248 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 251 | int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 252 | const u_int8_t *data, int len) |
| 253 | { |
| 254 | struct abis_rsl_common_hdr *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 255 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 256 | |
| 257 | ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch)); |
| 258 | ch->msg_discr = ABIS_RSL_MDISC_TRX; |
| 259 | ch->msg_type = RSL_MT_SACCH_FILL; |
| 260 | |
| 261 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 262 | msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 263 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 264 | msg->trx = trx; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 265 | |
| 266 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* Chapter 8.4.1 */ |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 270 | int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr, |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 271 | u_int8_t act_type, |
| 272 | struct rsl_ie_chan_mode *chan_mode, |
| 273 | struct rsl_ie_chan_ident *chan_ident, |
| 274 | u_int8_t bs_power, u_int8_t ms_power, |
| 275 | u_int8_t ta) |
| 276 | { |
| 277 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 278 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 279 | |
| 280 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 281 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 282 | dh->chan_nr = chan_nr; |
| 283 | |
| 284 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
| 285 | /* For compatibility with Phase 1 */ |
| 286 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode), |
| 287 | (u_int8_t *) chan_mode); |
| 288 | msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4, |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 289 | (u_int8_t *) chan_ident); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 290 | /* FIXME: this shoould be optional */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 291 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 292 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1, |
| 293 | (u_int8_t *) &encr_info); |
| 294 | msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 295 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 296 | msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power); |
| 297 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 298 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 299 | msg->trx = trx; |
| 300 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 301 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | #define TSC 7 |
| 305 | |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 306 | int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type, |
| 307 | u_int8_t ta) |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 308 | { |
| 309 | struct abis_rsl_dchan_hdr *dh; |
| 310 | struct msgb *msg = rsl_msgb_alloc(); |
| 311 | /* FXIME: don't hardcode these!! */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 312 | u_int8_t ms_power = 0x0f; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 313 | |
| 314 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
| 315 | u_int16_t arfcn = lchan->ts->trx->arfcn; |
| 316 | struct rsl_ie_chan_mode cm; |
| 317 | struct rsl_ie_chan_ident ci; |
| 318 | |
| 319 | /* FIXME: what to do with data calls ? */ |
| 320 | cm.dtx_dtu = 0x00; |
| 321 | switch (lchan->type) { |
| 322 | case GSM_LCHAN_SDCCH: |
| 323 | cm.spd_ind = RSL_CMOD_SPD_SIGN; |
| 324 | cm.chan_rt = RSL_CMOD_CRT_SDCCH; |
| 325 | cm.chan_rate = 0x00; |
| 326 | break; |
| 327 | case GSM_LCHAN_TCH_F: |
| 328 | cm.spd_ind = RSL_CMOD_SPD_SPEECH; |
| 329 | cm.chan_rt = RSL_CMOD_CRT_TCH_Bm; |
| 330 | cm.chan_rate = 0x11; /* speech coding alg version 2*/ |
| 331 | break; |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 332 | case GSM_LCHAN_TCH_H: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 333 | DEBUGP(DRSL, "Unimplemented TCH_H activation\n"); |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 334 | return -1; |
| 335 | case GSM_LCHAN_UNKNOWN: |
| 336 | case GSM_LCHAN_NONE: |
| 337 | return -1; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | ci.chan_desc.iei = 0x64; |
| 341 | ci.chan_desc.chan_nr = chan_nr; |
| 342 | ci.chan_desc.oct3 = (TSC << 5) | ((arfcn & 0x3ff) >> 8); |
| 343 | ci.chan_desc.oct4 = arfcn & 0xff; |
| 344 | |
| 345 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 346 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 347 | dh->chan_nr = chan_nr; |
| 348 | |
| 349 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
| 350 | /* For compatibility with Phase 1 */ |
| 351 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm), |
| 352 | (u_int8_t *) &cm); |
| 353 | msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4, |
| 354 | (u_int8_t *) &ci); |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 355 | /* FIXME: this should be optional */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 356 | #if 0 |
| 357 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1, |
| 358 | (u_int8_t *) &encr_info); |
| 359 | msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power); |
| 360 | #endif |
| 361 | msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power); |
| 362 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 363 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 364 | msg->trx = lchan->ts->trx; |
| 365 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 366 | return abis_rsl_sendmsg(msg); |
| 367 | } |
| 368 | |
Holger Freyther | 36cbeff | 2008-12-30 19:15:20 +0000 | [diff] [blame] | 369 | /* Chapter 9.1.7 of 04.08 */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 370 | int rsl_chan_release(struct gsm_lchan *lchan) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 371 | { |
| 372 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 373 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 374 | |
| 375 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 376 | init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 377 | dh->chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 378 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 379 | msg->lchan = lchan; |
| 380 | msg->trx = lchan->ts->trx; |
| 381 | |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 382 | DEBUGP(DRSL, "Channel Release CMD, chan_nr=0x%02x\n", dh->chan_nr); |
| 383 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 384 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len, |
| 388 | u_int8_t *ms_ident, u_int8_t chan_needed) |
| 389 | { |
| 390 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 391 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 392 | |
| 393 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 394 | init_dchan_hdr(dh, RSL_MT_PAGING_CMD); |
| 395 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 396 | |
| 397 | msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 398 | msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 399 | msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed); |
| 400 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 401 | msg->trx = bts->c0; |
| 402 | |
| 403 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Holger Freyther | 7448a53 | 2009-01-04 20:18:23 +0000 | [diff] [blame] | 406 | int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need, |
| 407 | struct gsm_subscriber *subscr) |
| 408 | { |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 409 | #if 0 |
Holger Freyther | 7448a53 | 2009-01-04 20:18:23 +0000 | [diff] [blame] | 410 | u_int8_t mi[128]; |
| 411 | unsigned int mi_len; |
| 412 | u_int8_t paging_group; |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 413 | #endif |
Holger Freyther | 7448a53 | 2009-01-04 20:18:23 +0000 | [diff] [blame] | 414 | |
| 415 | return -1; |
| 416 | } |
| 417 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 418 | int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in) |
| 419 | { |
| 420 | int i, len = strlen(str_in); |
| 421 | |
| 422 | for (i = 0; i < len; i++) { |
| 423 | int num = str_in[i] - 0x30; |
| 424 | if (num < 0 || num > 9) |
| 425 | return -1; |
| 426 | if (i % 2 == 0) |
| 427 | bcd_out[i/2] = num; |
| 428 | else |
| 429 | bcd_out[i/2] |= (num << 4); |
| 430 | } |
| 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 435 | /* Chapter 8.5.6 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 436 | int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val) |
| 437 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 438 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 439 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 362322e | 2009-02-15 14:36:38 +0000 | [diff] [blame^] | 440 | u_int8_t buf[MACBLOCK_SIZE]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 441 | |
| 442 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 443 | init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD); |
| 444 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 445 | |
Harald Welte | 362322e | 2009-02-15 14:36:38 +0000 | [diff] [blame^] | 446 | switch (bts->type) { |
| 447 | case GSM_BTS_TYPE_BS11: |
| 448 | msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val); |
| 449 | break; |
| 450 | default: |
| 451 | /* If phase 2, construct a FULL_IMM_ASS_INFO */ |
| 452 | pad_macblock(buf, val, len); |
| 453 | msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf); |
| 454 | break; |
| 455 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 456 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 457 | msg->trx = bts->c0; |
| 458 | |
| 459 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 462 | /* Send "DATA REQUEST" message with given L3 Info payload */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 463 | /* Chapter 8.3.1 */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 464 | int rsl_data_request(struct msgb *msg, u_int8_t link_id) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 465 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 466 | u_int8_t l3_len = msg->tail - (u_int8_t *)msgb_l3(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 467 | struct abis_rsl_rll_hdr *rh; |
| 468 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 469 | if (msg->lchan == NULL) { |
| 470 | fprintf(stderr, "cannot send DATA REQUEST to unknown lchan\n"); |
| 471 | return -EINVAL; |
| 472 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 473 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 474 | /* First push the L3 IE tag and length */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 475 | msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 476 | |
| 477 | /* Then push the RSL header */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 478 | rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh)); |
| 479 | init_llm_hdr(rh, RSL_MT_DATA_REQ); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 480 | rh->chan_nr = lchan2chan_nr(msg->lchan); |
| 481 | rh->link_id = link_id; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 482 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 483 | msg->trx = msg->lchan->ts->trx; |
| 484 | |
| 485 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 488 | /* Chapter 8.4.2: Channel Activate Acknowledge */ |
| 489 | static int rsl_rx_chan_act_ack(struct msgb *msg) |
| 490 | { |
| 491 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 492 | |
| 493 | /* BTS has confirmed channel activation, we now need |
| 494 | * to assign the activated channel to the MS */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 495 | if (rslh->ie_chan != RSL_IE_CHAN_NR) |
| 496 | return -EINVAL; |
| 497 | |
| 498 | DEBUGP(DRSL, "Channel Activate ACK Channel 0x%02x\n", rslh->chan_nr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 499 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 500 | return 0; |
| 501 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 502 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 503 | /* Chapter 8.4.3: Channel Activate NACK */ |
| 504 | static int rsl_rx_chan_act_nack(struct msgb *msg) |
| 505 | { |
| 506 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 507 | |
| 508 | /* BTS has confirmed channel activation, we now need |
| 509 | * to assign the activated channel to the MS */ |
| 510 | if (rslh->ie_chan != RSL_IE_CHAN_NR) |
| 511 | return -EINVAL; |
| 512 | |
| 513 | DEBUGP(DRSL, "Channel Activate NACK Channel 0x%02x\n", rslh->chan_nr); |
| 514 | |
| 515 | return 0; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 518 | static int abis_rsl_rx_dchan(struct msgb *msg) |
| 519 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 520 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 521 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 522 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 523 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 524 | |
| 525 | switch (rslh->c.msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 526 | case RSL_MT_CHAN_ACTIV_ACK: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 527 | rc = rsl_rx_chan_act_ack(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 528 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 529 | case RSL_MT_CHAN_ACTIV_NACK: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 530 | rc = rsl_rx_chan_act_nack(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 531 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 532 | case RSL_MT_CONN_FAIL: |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 533 | DEBUGP(DRSL, "Connection Fail, release channel\n"); |
Harald Welte | 14537e5 | 2008-12-27 10:29:08 +0000 | [diff] [blame] | 534 | rc = rsl_chan_release(msg->lchan); |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 535 | /* only free it after channel release ACK */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 536 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 537 | case RSL_MT_MEAS_RES: |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 538 | DEBUGP(DRSL, "Measurement Result\n"); |
| 539 | break; |
| 540 | case RSL_MT_RF_CHAN_REL_ACK: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 541 | DEBUGP(DRSL, "RF CHANNEL RELEASE ACK chan_nr=0x%02x\n", |
| 542 | rslh->chan_nr); |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 543 | lchan_free(msg->lchan); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 544 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 545 | case RSL_MT_MODE_MODIFY_ACK: |
| 546 | case RSL_MT_MODE_MODIFY_NACK: |
| 547 | case RSL_MT_PHY_CONTEXT_CONF: |
| 548 | case RSL_MT_PREPROC_MEAS_RES: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 549 | case RSL_MT_TALKER_DET: |
| 550 | case RSL_MT_LISTENER_DET: |
| 551 | case RSL_MT_REMOTE_CODEC_CONF_REP: |
| 552 | case RSL_MT_MR_CODEC_MOD_ACK: |
| 553 | case RSL_MT_MR_CODEC_MOD_NACK: |
| 554 | case RSL_MT_MR_CODEC_MOD_PER: |
| 555 | fprintf(stderr, "Unimplemented Abis RSL DChan msg 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 556 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 557 | break; |
| 558 | default: |
| 559 | fprintf(stderr, "unknown Abis RSL DChan msg 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 560 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 561 | return -EINVAL; |
| 562 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 563 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 566 | static int rsl_rx_error_rep(struct msgb *msg) |
| 567 | { |
| 568 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg); |
| 569 | u_int8_t cause_len; |
| 570 | |
| 571 | if (rslh->data[0] != RSL_IE_CAUSE) |
| 572 | return -EINVAL; |
| 573 | |
| 574 | cause_len = rslh->data[1]; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 575 | fprintf(stdout, "RSL ERROR REPORT, Cause "); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 576 | hexdump(&rslh->data[2], cause_len); |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 581 | static int abis_rsl_rx_trx(struct msgb *msg) |
| 582 | { |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 583 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 584 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 585 | |
| 586 | switch (rslh->msg_type) { |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 587 | case RSL_MT_ERROR_REPORT: |
| 588 | rc = rsl_rx_error_rep(msg); |
| 589 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 590 | case RSL_MT_RF_RES_IND: |
| 591 | /* interference on idle channels of TRX */ |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 592 | fprintf(stderr, "RSL TRX: RF Interference Indication\n"); |
| 593 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 594 | case RSL_MT_OVERLOAD: |
| 595 | /* indicate CCCH / ACCH / processor overload */ |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 596 | fprintf(stderr, "RSL TRX: CCCH/ACCH/CPU Overload\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 597 | break; |
| 598 | default: |
| 599 | fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n", |
| 600 | rslh->msg_type); |
| 601 | return -EINVAL; |
| 602 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 603 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 606 | /* MS has requested a channel on the RACH */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 607 | static int rsl_rx_chan_rqd(struct msgb *msg) |
| 608 | { |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 609 | struct gsm_bts *bts = msg->trx->bts; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 610 | struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg); |
| 611 | struct gsm48_req_ref *rqd_ref; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 612 | struct gsm48_imm_ass ia; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 613 | enum gsm_chan_t lctype; |
Harald Welte | 2cbe092 | 2008-12-29 04:09:31 +0000 | [diff] [blame] | 614 | enum gsm_chreq_reason_t chreq_reason; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 615 | struct gsm_lchan *lchan; |
| 616 | u_int8_t rqd_ta; |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 617 | int ret; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 618 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 619 | u_int16_t arfcn; |
| 620 | u_int8_t ts_number, subch; |
| 621 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 622 | /* parse request reference to be used in immediate assign */ |
| 623 | if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE) |
| 624 | return -EINVAL; |
| 625 | |
| 626 | rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1]; |
| 627 | |
| 628 | /* parse access delay and use as TA */ |
| 629 | if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY) |
| 630 | return -EINVAL; |
| 631 | rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2]; |
| 632 | |
| 633 | /* determine channel type (SDCCH/TCH_F/TCH_H) based on |
| 634 | * request reference RA */ |
| 635 | lctype = get_ctype_by_chreq(bts, rqd_ref->ra); |
Harald Welte | 2cbe092 | 2008-12-29 04:09:31 +0000 | [diff] [blame] | 636 | chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra); |
| 637 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 638 | /* check availability / allocate channel */ |
| 639 | lchan = lchan_alloc(bts, lctype); |
| 640 | if (!lchan) { |
| 641 | fprintf(stderr, "CHAN RQD: no resources\n"); |
| 642 | /* FIXME: send some kind of reject ?!? */ |
| 643 | return -ENOMEM; |
| 644 | } |
| 645 | |
| 646 | ts_number = lchan->ts->nr; |
| 647 | arfcn = lchan->ts->trx->arfcn; |
| 648 | subch = lchan->nr; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 649 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 650 | rsl_chan_activate_lchan(lchan, 0x00, rqd_ta); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 651 | |
| 652 | /* create IMMEDIATE ASSIGN 04.08 messge */ |
| 653 | memset(&ia, 0, sizeof(ia)); |
| 654 | ia.l2_plen = 0x2d; |
| 655 | ia.proto_discr = GSM48_PDISC_RR; |
| 656 | ia.msg_type = GSM48_MT_RR_IMM_ASS; |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 657 | ia.page_mode = GSM48_PM_SAME; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 658 | ia.chan_desc.chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 659 | ia.chan_desc.h0.h = 0; |
| 660 | ia.chan_desc.h0.arfcn_high = arfcn >> 8; |
| 661 | ia.chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 662 | ia.chan_desc.h0.tsc = 7; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 663 | /* use request reference extracted from CHAN_RQD */ |
| 664 | memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref)); |
| 665 | ia.timing_advance = rqd_ta; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 666 | ia.mob_alloc_len = 0; |
| 667 | |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 668 | DEBUGP(DRSL, "Activating ARFCN(%u) TS(%u) SS(%u) lctype %s " |
| 669 | "chan_nr=0x%02x r=%s\n", |
Harald Welte | ca64da9 | 2009-01-04 16:54:12 +0000 | [diff] [blame] | 670 | arfcn, ts_number, subch, gsm_lchan_name(lchan->type), |
| 671 | ia.chan_desc.chan_nr, gsm_chreq_name(chreq_reason)); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 672 | |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 673 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 674 | /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */ |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 675 | ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia); |
| 676 | |
Harald Welte | 817f3c8 | 2008-12-30 14:57:59 +0000 | [diff] [blame] | 677 | return ret; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 680 | /* MS has requested a channel on the RACH */ |
| 681 | static int rsl_rx_ccch_load(struct msgb *msg) |
| 682 | { |
| 683 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 684 | u_int16_t pg_buf_space; |
Holger Freyther | 8c563cf | 2009-02-03 20:08:51 +0000 | [diff] [blame] | 685 | u_int16_t rach_slot_count = -1; |
| 686 | u_int16_t rach_busy_count = -1; |
| 687 | u_int16_t rach_access_count = -1; |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 688 | |
| 689 | switch (rslh->data[0]) { |
| 690 | case RSL_IE_PAGING_LOAD: |
| 691 | pg_buf_space = rslh->data[1] << 8 | rslh->data[2]; |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 692 | paging_update_buffer_space(msg->trx->bts, pg_buf_space); |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 693 | break; |
| 694 | case RSL_IE_RACH_LOAD: |
Holger Freyther | 8c563cf | 2009-02-03 20:08:51 +0000 | [diff] [blame] | 695 | if (msg->data_len >= 7) { |
| 696 | rach_slot_count = rslh->data[2] << 8 | rslh->data[3]; |
| 697 | rach_busy_count = rslh->data[4] << 8 | rslh->data[5]; |
| 698 | rach_access_count = rslh->data[6] << 8 | rslh->data[7]; |
| 699 | } |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 700 | break; |
| 701 | default: |
| 702 | break; |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 708 | static int abis_rsl_rx_cchan(struct msgb *msg) |
| 709 | { |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 710 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 711 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 712 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 713 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 714 | |
| 715 | switch (rslh->c.msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 716 | case RSL_MT_CHAN_RQD: |
| 717 | /* MS has requested a channel on the RACH */ |
| 718 | rc = rsl_rx_chan_rqd(msg); |
| 719 | break; |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 720 | case RSL_MT_CCCH_LOAD_IND: |
| 721 | /* current load on the CCCH */ |
| 722 | rc = rsl_rx_ccch_load(msg); |
| 723 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 724 | case RSL_MT_DELETE_IND: |
| 725 | /* CCCH overloaded, IMM_ASSIGN was dropped */ |
| 726 | case RSL_MT_CBCH_LOAD_IND: |
| 727 | /* current load on the CBCH */ |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 728 | fprintf(stderr, "Unimplemented Abis RSL TRX message type " |
| 729 | "0x%02x\n", rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 730 | break; |
| 731 | default: |
| 732 | fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 733 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 734 | return -EINVAL; |
| 735 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 736 | |
| 737 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 740 | static int rsl_rx_rll_err_ind(struct msgb *msg) |
| 741 | { |
| 742 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 743 | u_int8_t *rlm_cause = rllh->data; |
| 744 | |
| 745 | DEBUGP(DRLL, "RLL ERROR INDICATION: chan_nr=0x%02x cause=0x%02x\n", |
| 746 | rllh->chan_nr, rlm_cause[1]); |
| 747 | |
| 748 | return 0; |
| 749 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 750 | /* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST |
| 751 | 0x02, 0x06, |
| 752 | 0x01, 0x20, |
| 753 | 0x02, 0x00, |
| 754 | 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */ |
| 755 | |
| 756 | static int abis_rsl_rx_rll(struct msgb *msg) |
| 757 | { |
| 758 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 759 | int rc; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 760 | |
| 761 | msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 762 | |
| 763 | switch (rllh->c.msg_type) { |
| 764 | case RSL_MT_DATA_IND: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 765 | DEBUGP(DRLL, "DATA INDICATION chan_nr=0x%02x\n", rllh->chan_nr); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 766 | /* FIXME: Verify L3 info element */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 767 | msg->l3h = &rllh->data[3]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 768 | rc = gsm0408_rcvmsg(msg); |
| 769 | break; |
| 770 | case RSL_MT_EST_IND: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 771 | DEBUGP(DRLL, "ESTABLISH INDICATION chan_nr=0x%02x\n", |
| 772 | rllh->chan_nr); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 773 | /* FIXME: Verify L3 info element */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 774 | msg->l3h = &rllh->data[3]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 775 | rc = gsm0408_rcvmsg(msg); |
| 776 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 777 | case RSL_MT_REL_IND: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 778 | DEBUGP(DRLL, "RELEASE INDICATION chan_nr=0x%02x\n", |
| 779 | rllh->chan_nr); |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 780 | break; |
| 781 | case RSL_MT_REL_CONF: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 782 | DEBUGP(DRLL, "RELEASE CONFIRMATION chan_nr=0x%02x\n", |
| 783 | rllh->chan_nr); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 784 | break; |
| 785 | case RSL_MT_ERROR_IND: |
| 786 | rc = rsl_rx_rll_err_ind(msg); |
| 787 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 788 | case RSL_MT_UNIT_DATA_IND: |
| 789 | fprintf(stderr, "unimplemented Abis RLL message type 0x%02x\n", |
| 790 | rllh->c.msg_type); |
| 791 | break; |
| 792 | default: |
| 793 | fprintf(stderr, "unknown Abis RLL message type 0x%02x\n", |
| 794 | rllh->c.msg_type); |
| 795 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 796 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /* Entry-point where L2 RSL from BTS enters */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 800 | int abis_rsl_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 801 | { |
| 802 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ; |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 803 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 804 | |
| 805 | switch (rslh->msg_discr & 0xfe) { |
| 806 | case ABIS_RSL_MDISC_RLL: |
| 807 | rc = abis_rsl_rx_rll(msg); |
| 808 | break; |
| 809 | case ABIS_RSL_MDISC_DED_CHAN: |
| 810 | rc = abis_rsl_rx_dchan(msg); |
| 811 | break; |
| 812 | case ABIS_RSL_MDISC_COM_CHAN: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 813 | rc = abis_rsl_rx_cchan(msg); |
| 814 | break; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 815 | case ABIS_RSL_MDISC_TRX: |
| 816 | rc = abis_rsl_rx_trx(msg); |
| 817 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 818 | case ABIS_RSL_MDISC_LOC: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 819 | fprintf(stderr, "unimplemented RSL msg disc 0x%02x\n", |
| 820 | rslh->msg_discr); |
| 821 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 822 | default: |
| 823 | fprintf(stderr, "unknown RSL message discriminator 0x%02x\n", |
| 824 | rslh->msg_discr); |
| 825 | return -EINVAL; |
| 826 | } |
Harald Welte | 4f4a390 | 2008-12-26 00:04:49 +0000 | [diff] [blame] | 827 | msgb_free(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 828 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 829 | } |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 830 | |
| 831 | |
| 832 | /* Section 3.3.2.3 . I think this looks like a table */ |
| 833 | int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf) |
| 834 | { |
| 835 | switch (ccch_conf) { |
| 836 | case RSL_BCCH_CCCH_CONF_1_NC: |
| 837 | return 1; |
| 838 | case RSL_BCCH_CCCH_CONF_1_C: |
| 839 | return 1; |
| 840 | case RSL_BCCH_CCCH_CONF_2_NC: |
| 841 | return 2; |
| 842 | case RSL_BCCH_CCCH_CONF_3_NC: |
| 843 | return 3; |
| 844 | case RSL_BCCH_CCCH_CONF_4_NC: |
| 845 | return 4; |
| 846 | default: |
| 847 | return -1; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf) |
| 852 | { |
| 853 | switch (ccch_conf) { |
| 854 | case RSL_BCCH_CCCH_CONF_1_NC: |
| 855 | return 0; |
| 856 | case RSL_BCCH_CCCH_CONF_1_C: |
| 857 | return 1; |
| 858 | case RSL_BCCH_CCCH_CONF_2_NC: |
| 859 | return 0; |
| 860 | case RSL_BCCH_CCCH_CONF_3_NC: |
| 861 | return 0; |
| 862 | case RSL_BCCH_CCCH_CONF_4_NC: |
| 863 | return 0; |
| 864 | default: |
| 865 | return -1; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /* From Table 10.5.33 of GSM 04.08 */ |
| 870 | int rsl_number_of_paging_subchannels(struct gsm_bts *bts) |
| 871 | { |
| 872 | if (bts->chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) { |
| 873 | return MAX(1, (3 - bts->chan_desc.bs_ag_blks_res)) |
Holger Freyther | 3aa8d6c | 2009-02-04 02:14:45 +0000 | [diff] [blame] | 874 | * (bts->chan_desc.bs_pa_mfrms + 2); |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 875 | } else { |
| 876 | return (9 - bts->chan_desc.bs_ag_blks_res) |
Holger Freyther | 3aa8d6c | 2009-02-04 02:14:45 +0000 | [diff] [blame] | 877 | * (bts->chan_desc.bs_pa_mfrms + 2); |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 878 | } |
| 879 | } |