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 | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 223 | /* Send a BCCH_INFO message as per Chapter 8.5.1 */ |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 224 | 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] | 225 | const u_int8_t *data, int len) |
| 226 | { |
| 227 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 228 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 229 | |
| 230 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh); |
| 231 | init_dchan_hdr(dh, RSL_MT_BCCH_INFO); |
| 232 | dh->chan_nr = RSL_CHAN_BCCH; |
| 233 | |
| 234 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
| 235 | msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data); |
| 236 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 237 | msg->trx = trx; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 238 | |
| 239 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 242 | 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] | 243 | const u_int8_t *data, int len) |
| 244 | { |
| 245 | struct abis_rsl_common_hdr *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 246 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 247 | |
| 248 | ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch)); |
| 249 | ch->msg_discr = ABIS_RSL_MDISC_TRX; |
| 250 | ch->msg_type = RSL_MT_SACCH_FILL; |
| 251 | |
| 252 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 253 | msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 254 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 255 | msg->trx = trx; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 256 | |
| 257 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* Chapter 8.4.1 */ |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 261 | 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] | 262 | u_int8_t act_type, |
| 263 | struct rsl_ie_chan_mode *chan_mode, |
| 264 | struct rsl_ie_chan_ident *chan_ident, |
| 265 | u_int8_t bs_power, u_int8_t ms_power, |
| 266 | u_int8_t ta) |
| 267 | { |
| 268 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 269 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 270 | |
| 271 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 272 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 273 | dh->chan_nr = chan_nr; |
| 274 | |
| 275 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
| 276 | /* For compatibility with Phase 1 */ |
| 277 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode), |
| 278 | (u_int8_t *) chan_mode); |
| 279 | msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4, |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 280 | (u_int8_t *) chan_ident); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 281 | /* FIXME: this shoould be optional */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 282 | #if 0 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 283 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1, |
| 284 | (u_int8_t *) &encr_info); |
| 285 | msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 286 | #endif |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 287 | msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power); |
| 288 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 289 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 290 | msg->trx = trx; |
| 291 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 292 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | #define TSC 7 |
| 296 | |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 297 | int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type, |
| 298 | u_int8_t ta) |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 299 | { |
| 300 | struct abis_rsl_dchan_hdr *dh; |
| 301 | struct msgb *msg = rsl_msgb_alloc(); |
| 302 | /* FXIME: don't hardcode these!! */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 303 | u_int8_t ms_power = 0x0f; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 304 | |
| 305 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
| 306 | u_int16_t arfcn = lchan->ts->trx->arfcn; |
| 307 | struct rsl_ie_chan_mode cm; |
| 308 | struct rsl_ie_chan_ident ci; |
| 309 | |
| 310 | /* FIXME: what to do with data calls ? */ |
| 311 | cm.dtx_dtu = 0x00; |
| 312 | switch (lchan->type) { |
| 313 | case GSM_LCHAN_SDCCH: |
| 314 | cm.spd_ind = RSL_CMOD_SPD_SIGN; |
| 315 | cm.chan_rt = RSL_CMOD_CRT_SDCCH; |
| 316 | cm.chan_rate = 0x00; |
| 317 | break; |
| 318 | case GSM_LCHAN_TCH_F: |
| 319 | cm.spd_ind = RSL_CMOD_SPD_SPEECH; |
| 320 | cm.chan_rt = RSL_CMOD_CRT_TCH_Bm; |
| 321 | cm.chan_rate = 0x11; /* speech coding alg version 2*/ |
| 322 | break; |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 323 | case GSM_LCHAN_TCH_H: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 324 | DEBUGP(DRSL, "Unimplemented TCH_H activation\n"); |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 325 | return -1; |
| 326 | case GSM_LCHAN_UNKNOWN: |
| 327 | case GSM_LCHAN_NONE: |
| 328 | return -1; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | ci.chan_desc.iei = 0x64; |
| 332 | ci.chan_desc.chan_nr = chan_nr; |
| 333 | ci.chan_desc.oct3 = (TSC << 5) | ((arfcn & 0x3ff) >> 8); |
| 334 | ci.chan_desc.oct4 = arfcn & 0xff; |
| 335 | |
| 336 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 337 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 338 | dh->chan_nr = chan_nr; |
| 339 | |
| 340 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
| 341 | /* For compatibility with Phase 1 */ |
| 342 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm), |
| 343 | (u_int8_t *) &cm); |
| 344 | msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4, |
| 345 | (u_int8_t *) &ci); |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 346 | /* FIXME: this should be optional */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 347 | #if 0 |
| 348 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1, |
| 349 | (u_int8_t *) &encr_info); |
| 350 | msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power); |
| 351 | #endif |
| 352 | msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power); |
| 353 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 354 | |
Harald Welte | e79769b | 2009-02-07 00:48:17 +0000 | [diff] [blame] | 355 | msg->trx = lchan->ts->trx; |
| 356 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 357 | return abis_rsl_sendmsg(msg); |
| 358 | } |
| 359 | |
Holger Freyther | 36cbeff | 2008-12-30 19:15:20 +0000 | [diff] [blame] | 360 | /* Chapter 9.1.7 of 04.08 */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 361 | int rsl_chan_release(struct gsm_lchan *lchan) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 362 | { |
| 363 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 364 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 365 | |
| 366 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 367 | init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 368 | dh->chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 369 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 370 | msg->lchan = lchan; |
| 371 | msg->trx = lchan->ts->trx; |
| 372 | |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 373 | DEBUGP(DRSL, "Channel Release CMD, chan_nr=0x%02x\n", dh->chan_nr); |
| 374 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 375 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len, |
| 379 | u_int8_t *ms_ident, u_int8_t chan_needed) |
| 380 | { |
| 381 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 382 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 383 | |
| 384 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 385 | init_dchan_hdr(dh, RSL_MT_PAGING_CMD); |
| 386 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 387 | |
| 388 | msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group); |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 389 | 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] | 390 | msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed); |
| 391 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 392 | msg->trx = bts->c0; |
| 393 | |
| 394 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Holger Freyther | 7448a53 | 2009-01-04 20:18:23 +0000 | [diff] [blame] | 397 | int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need, |
| 398 | struct gsm_subscriber *subscr) |
| 399 | { |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 400 | #if 0 |
Holger Freyther | 7448a53 | 2009-01-04 20:18:23 +0000 | [diff] [blame] | 401 | u_int8_t mi[128]; |
| 402 | unsigned int mi_len; |
| 403 | u_int8_t paging_group; |
Holger Freyther | ca362a6 | 2009-01-04 21:05:01 +0000 | [diff] [blame] | 404 | #endif |
Holger Freyther | 7448a53 | 2009-01-04 20:18:23 +0000 | [diff] [blame] | 405 | |
| 406 | return -1; |
| 407 | } |
| 408 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 409 | int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in) |
| 410 | { |
| 411 | int i, len = strlen(str_in); |
| 412 | |
| 413 | for (i = 0; i < len; i++) { |
| 414 | int num = str_in[i] - 0x30; |
| 415 | if (num < 0 || num > 9) |
| 416 | return -1; |
| 417 | if (i % 2 == 0) |
| 418 | bcd_out[i/2] = num; |
| 419 | else |
| 420 | bcd_out[i/2] |= (num << 4); |
| 421 | } |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 426 | /* Chapter 8.5.6 */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 427 | int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val) |
| 428 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 429 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 430 | struct abis_rsl_dchan_hdr *dh; |
| 431 | |
| 432 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 433 | init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD); |
| 434 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 435 | |
| 436 | /* If phase 2, FULL_IMM_ASS_INFO */ |
| 437 | |
| 438 | msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val); |
| 439 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 440 | msg->trx = bts->c0; |
| 441 | |
| 442 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 445 | /* Send "DATA REQUEST" message with given L3 Info payload */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 446 | /* Chapter 8.3.1 */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 447 | int rsl_data_request(struct msgb *msg, u_int8_t link_id) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 448 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 449 | 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] | 450 | struct abis_rsl_rll_hdr *rh; |
| 451 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 452 | if (msg->lchan == NULL) { |
| 453 | fprintf(stderr, "cannot send DATA REQUEST to unknown lchan\n"); |
| 454 | return -EINVAL; |
| 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 | /* First push the L3 IE tag and length */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 458 | msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 459 | |
| 460 | /* Then push the RSL header */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 461 | rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh)); |
| 462 | init_llm_hdr(rh, RSL_MT_DATA_REQ); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 463 | rh->chan_nr = lchan2chan_nr(msg->lchan); |
| 464 | rh->link_id = 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 | msg->trx = msg->lchan->ts->trx; |
| 467 | |
| 468 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 471 | /* Chapter 8.4.2: Channel Activate Acknowledge */ |
| 472 | static int rsl_rx_chan_act_ack(struct msgb *msg) |
| 473 | { |
| 474 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 475 | |
| 476 | /* BTS has confirmed channel activation, we now need |
| 477 | * to assign the activated channel to the MS */ |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 478 | if (rslh->ie_chan != RSL_IE_CHAN_NR) |
| 479 | return -EINVAL; |
| 480 | |
| 481 | DEBUGP(DRSL, "Channel Activate ACK Channel 0x%02x\n", rslh->chan_nr); |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 482 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 483 | return 0; |
| 484 | } |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 485 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 486 | /* Chapter 8.4.3: Channel Activate NACK */ |
| 487 | static int rsl_rx_chan_act_nack(struct msgb *msg) |
| 488 | { |
| 489 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 490 | |
| 491 | /* BTS has confirmed channel activation, we now need |
| 492 | * to assign the activated channel to the MS */ |
| 493 | if (rslh->ie_chan != RSL_IE_CHAN_NR) |
| 494 | return -EINVAL; |
| 495 | |
| 496 | DEBUGP(DRSL, "Channel Activate NACK Channel 0x%02x\n", rslh->chan_nr); |
| 497 | |
| 498 | return 0; |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 501 | static int abis_rsl_rx_dchan(struct msgb *msg) |
| 502 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 503 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 504 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 505 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 506 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 507 | |
| 508 | switch (rslh->c.msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 509 | case RSL_MT_CHAN_ACTIV_ACK: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 510 | rc = rsl_rx_chan_act_ack(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 511 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 512 | case RSL_MT_CHAN_ACTIV_NACK: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 513 | rc = rsl_rx_chan_act_nack(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 514 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 515 | case RSL_MT_CONN_FAIL: |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 516 | DEBUGP(DRSL, "Connection Fail, release channel\n"); |
Harald Welte | 14537e5 | 2008-12-27 10:29:08 +0000 | [diff] [blame] | 517 | rc = rsl_chan_release(msg->lchan); |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 518 | /* only free it after channel release ACK */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 519 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 520 | case RSL_MT_MEAS_RES: |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 521 | DEBUGP(DRSL, "Measurement Result\n"); |
| 522 | break; |
| 523 | case RSL_MT_RF_CHAN_REL_ACK: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 524 | DEBUGP(DRSL, "RF CHANNEL RELEASE ACK chan_nr=0x%02x\n", |
| 525 | rslh->chan_nr); |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 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 */ |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 575 | fprintf(stderr, "RSL TRX: RF Interference Indication\n"); |
| 576 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 577 | case RSL_MT_OVERLOAD: |
| 578 | /* indicate CCCH / ACCH / processor overload */ |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 579 | fprintf(stderr, "RSL TRX: CCCH/ACCH/CPU Overload\n"); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 580 | break; |
| 581 | default: |
| 582 | fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n", |
| 583 | rslh->msg_type); |
| 584 | return -EINVAL; |
| 585 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 586 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 589 | /* MS has requested a channel on the RACH */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 590 | static int rsl_rx_chan_rqd(struct msgb *msg) |
| 591 | { |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 592 | struct gsm_bts *bts = msg->trx->bts; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 593 | struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg); |
| 594 | struct gsm48_req_ref *rqd_ref; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 595 | struct gsm48_imm_ass ia; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 596 | enum gsm_chan_t lctype; |
Harald Welte | 2cbe092 | 2008-12-29 04:09:31 +0000 | [diff] [blame] | 597 | enum gsm_chreq_reason_t chreq_reason; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 598 | struct gsm_lchan *lchan; |
| 599 | u_int8_t rqd_ta; |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 600 | int ret; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 601 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 602 | u_int16_t arfcn; |
| 603 | u_int8_t ts_number, subch; |
| 604 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 605 | /* parse request reference to be used in immediate assign */ |
| 606 | if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE) |
| 607 | return -EINVAL; |
| 608 | |
| 609 | rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1]; |
| 610 | |
| 611 | /* parse access delay and use as TA */ |
| 612 | if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY) |
| 613 | return -EINVAL; |
| 614 | rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2]; |
| 615 | |
| 616 | /* determine channel type (SDCCH/TCH_F/TCH_H) based on |
| 617 | * request reference RA */ |
| 618 | lctype = get_ctype_by_chreq(bts, rqd_ref->ra); |
Harald Welte | 2cbe092 | 2008-12-29 04:09:31 +0000 | [diff] [blame] | 619 | chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra); |
| 620 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 621 | /* check availability / allocate channel */ |
| 622 | lchan = lchan_alloc(bts, lctype); |
| 623 | if (!lchan) { |
| 624 | fprintf(stderr, "CHAN RQD: no resources\n"); |
| 625 | /* FIXME: send some kind of reject ?!? */ |
| 626 | return -ENOMEM; |
| 627 | } |
| 628 | |
| 629 | ts_number = lchan->ts->nr; |
| 630 | arfcn = lchan->ts->trx->arfcn; |
| 631 | subch = lchan->nr; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 632 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 633 | rsl_chan_activate_lchan(lchan, 0x00, rqd_ta); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 634 | |
| 635 | /* create IMMEDIATE ASSIGN 04.08 messge */ |
| 636 | memset(&ia, 0, sizeof(ia)); |
| 637 | ia.l2_plen = 0x2d; |
| 638 | ia.proto_discr = GSM48_PDISC_RR; |
| 639 | ia.msg_type = GSM48_MT_RR_IMM_ASS; |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 640 | ia.page_mode = GSM48_PM_SAME; |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 641 | ia.chan_desc.chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 642 | ia.chan_desc.h0.h = 0; |
| 643 | ia.chan_desc.h0.arfcn_high = arfcn >> 8; |
| 644 | ia.chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 645 | ia.chan_desc.h0.tsc = 7; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 646 | /* use request reference extracted from CHAN_RQD */ |
| 647 | memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref)); |
| 648 | ia.timing_advance = rqd_ta; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 649 | ia.mob_alloc_len = 0; |
| 650 | |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 651 | DEBUGP(DRSL, "Activating ARFCN(%u) TS(%u) SS(%u) lctype %s " |
| 652 | "chan_nr=0x%02x r=%s\n", |
Harald Welte | ca64da9 | 2009-01-04 16:54:12 +0000 | [diff] [blame] | 653 | arfcn, ts_number, subch, gsm_lchan_name(lchan->type), |
| 654 | ia.chan_desc.chan_nr, gsm_chreq_name(chreq_reason)); |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 655 | |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 656 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 657 | /* 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] | 658 | ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia); |
| 659 | |
Harald Welte | 817f3c8 | 2008-12-30 14:57:59 +0000 | [diff] [blame] | 660 | return ret; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 663 | /* MS has requested a channel on the RACH */ |
| 664 | static int rsl_rx_ccch_load(struct msgb *msg) |
| 665 | { |
| 666 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 667 | u_int16_t pg_buf_space; |
Holger Freyther | 8c563cf | 2009-02-03 20:08:51 +0000 | [diff] [blame] | 668 | u_int16_t rach_slot_count = -1; |
| 669 | u_int16_t rach_busy_count = -1; |
| 670 | u_int16_t rach_access_count = -1; |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 671 | |
| 672 | switch (rslh->data[0]) { |
| 673 | case RSL_IE_PAGING_LOAD: |
| 674 | pg_buf_space = rslh->data[1] << 8 | rslh->data[2]; |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 675 | paging_update_buffer_space(msg->trx->bts, pg_buf_space); |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 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 | } |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 683 | break; |
| 684 | default: |
| 685 | break; |
| 686 | } |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 691 | static int abis_rsl_rx_cchan(struct msgb *msg) |
| 692 | { |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 693 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 694 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 695 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 696 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 697 | |
| 698 | switch (rslh->c.msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 699 | case RSL_MT_CHAN_RQD: |
| 700 | /* MS has requested a channel on the RACH */ |
| 701 | rc = rsl_rx_chan_rqd(msg); |
| 702 | break; |
Harald Welte | ea28044 | 2009-02-02 22:29:56 +0000 | [diff] [blame] | 703 | case RSL_MT_CCCH_LOAD_IND: |
| 704 | /* current load on the CCCH */ |
| 705 | rc = rsl_rx_ccch_load(msg); |
| 706 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 707 | case RSL_MT_DELETE_IND: |
| 708 | /* CCCH overloaded, IMM_ASSIGN was dropped */ |
| 709 | case RSL_MT_CBCH_LOAD_IND: |
| 710 | /* current load on the CBCH */ |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 711 | fprintf(stderr, "Unimplemented Abis RSL TRX message type " |
| 712 | "0x%02x\n", rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 713 | break; |
| 714 | default: |
| 715 | fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 716 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 717 | return -EINVAL; |
| 718 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 719 | |
| 720 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 723 | static int rsl_rx_rll_err_ind(struct msgb *msg) |
| 724 | { |
| 725 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 726 | u_int8_t *rlm_cause = rllh->data; |
| 727 | |
| 728 | DEBUGP(DRLL, "RLL ERROR INDICATION: chan_nr=0x%02x cause=0x%02x\n", |
| 729 | rllh->chan_nr, rlm_cause[1]); |
| 730 | |
| 731 | return 0; |
| 732 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 733 | /* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST |
| 734 | 0x02, 0x06, |
| 735 | 0x01, 0x20, |
| 736 | 0x02, 0x00, |
| 737 | 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */ |
| 738 | |
| 739 | static int abis_rsl_rx_rll(struct msgb *msg) |
| 740 | { |
| 741 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 742 | int rc; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 743 | |
| 744 | msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 745 | |
| 746 | switch (rllh->c.msg_type) { |
| 747 | case RSL_MT_DATA_IND: |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 748 | DEBUGP(DRLL, "DATA INDICATION chan_nr=0x%02x\n", rllh->chan_nr); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 749 | /* FIXME: Verify L3 info element */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 750 | msg->l3h = &rllh->data[3]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 751 | rc = gsm0408_rcvmsg(msg); |
| 752 | break; |
| 753 | case RSL_MT_EST_IND: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 754 | DEBUGP(DRLL, "ESTABLISH INDICATION chan_nr=0x%02x\n", |
| 755 | rllh->chan_nr); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 756 | /* FIXME: Verify L3 info element */ |
Harald Welte | 702d870 | 2008-12-26 20:25:35 +0000 | [diff] [blame] | 757 | msg->l3h = &rllh->data[3]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 758 | rc = gsm0408_rcvmsg(msg); |
| 759 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 760 | case RSL_MT_REL_IND: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 761 | DEBUGP(DRLL, "RELEASE INDICATION chan_nr=0x%02x\n", |
| 762 | rllh->chan_nr); |
Harald Welte | 2d5b638 | 2008-12-27 19:46:06 +0000 | [diff] [blame] | 763 | break; |
| 764 | case RSL_MT_REL_CONF: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 765 | DEBUGP(DRLL, "RELEASE CONFIRMATION chan_nr=0x%02x\n", |
| 766 | rllh->chan_nr); |
Harald Welte | 4b63454 | 2008-12-27 01:55:51 +0000 | [diff] [blame] | 767 | break; |
| 768 | case RSL_MT_ERROR_IND: |
| 769 | rc = rsl_rx_rll_err_ind(msg); |
| 770 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 771 | case RSL_MT_UNIT_DATA_IND: |
| 772 | fprintf(stderr, "unimplemented Abis RLL message type 0x%02x\n", |
| 773 | rllh->c.msg_type); |
| 774 | break; |
| 775 | default: |
| 776 | fprintf(stderr, "unknown Abis RLL message type 0x%02x\n", |
| 777 | rllh->c.msg_type); |
| 778 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 779 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /* Entry-point where L2 RSL from BTS enters */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 783 | int abis_rsl_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 784 | { |
| 785 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ; |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 786 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 787 | |
| 788 | switch (rslh->msg_discr & 0xfe) { |
| 789 | case ABIS_RSL_MDISC_RLL: |
| 790 | rc = abis_rsl_rx_rll(msg); |
| 791 | break; |
| 792 | case ABIS_RSL_MDISC_DED_CHAN: |
| 793 | rc = abis_rsl_rx_dchan(msg); |
| 794 | break; |
| 795 | case ABIS_RSL_MDISC_COM_CHAN: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 796 | rc = abis_rsl_rx_cchan(msg); |
| 797 | break; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 798 | case ABIS_RSL_MDISC_TRX: |
| 799 | rc = abis_rsl_rx_trx(msg); |
| 800 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 801 | case ABIS_RSL_MDISC_LOC: |
Harald Welte | 8f5e239 | 2009-02-03 12:57:37 +0000 | [diff] [blame] | 802 | fprintf(stderr, "unimplemented RSL msg disc 0x%02x\n", |
| 803 | rslh->msg_discr); |
| 804 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 805 | default: |
| 806 | fprintf(stderr, "unknown RSL message discriminator 0x%02x\n", |
| 807 | rslh->msg_discr); |
| 808 | return -EINVAL; |
| 809 | } |
Harald Welte | 4f4a390 | 2008-12-26 00:04:49 +0000 | [diff] [blame] | 810 | msgb_free(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 811 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 812 | } |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 813 | |
| 814 | |
| 815 | /* Section 3.3.2.3 . I think this looks like a table */ |
| 816 | int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf) |
| 817 | { |
| 818 | switch (ccch_conf) { |
| 819 | case RSL_BCCH_CCCH_CONF_1_NC: |
| 820 | return 1; |
| 821 | case RSL_BCCH_CCCH_CONF_1_C: |
| 822 | return 1; |
| 823 | case RSL_BCCH_CCCH_CONF_2_NC: |
| 824 | return 2; |
| 825 | case RSL_BCCH_CCCH_CONF_3_NC: |
| 826 | return 3; |
| 827 | case RSL_BCCH_CCCH_CONF_4_NC: |
| 828 | return 4; |
| 829 | default: |
| 830 | return -1; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf) |
| 835 | { |
| 836 | switch (ccch_conf) { |
| 837 | case RSL_BCCH_CCCH_CONF_1_NC: |
| 838 | return 0; |
| 839 | case RSL_BCCH_CCCH_CONF_1_C: |
| 840 | return 1; |
| 841 | case RSL_BCCH_CCCH_CONF_2_NC: |
| 842 | return 0; |
| 843 | case RSL_BCCH_CCCH_CONF_3_NC: |
| 844 | return 0; |
| 845 | case RSL_BCCH_CCCH_CONF_4_NC: |
| 846 | return 0; |
| 847 | default: |
| 848 | return -1; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /* From Table 10.5.33 of GSM 04.08 */ |
| 853 | int rsl_number_of_paging_subchannels(struct gsm_bts *bts) |
| 854 | { |
| 855 | if (bts->chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) { |
| 856 | return MAX(1, (3 - bts->chan_desc.bs_ag_blks_res)) |
Holger Freyther | 3aa8d6c | 2009-02-04 02:14:45 +0000 | [diff] [blame] | 857 | * (bts->chan_desc.bs_pa_mfrms + 2); |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 858 | } else { |
| 859 | return (9 - bts->chan_desc.bs_ag_blks_res) |
Holger Freyther | 3aa8d6c | 2009-02-04 02:14:45 +0000 | [diff] [blame] | 860 | * (bts->chan_desc.bs_pa_mfrms + 2); |
Holger Freyther | 3b72a89 | 2009-02-04 00:31:39 +0000 | [diff] [blame] | 861 | } |
| 862 | } |