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