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