Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | /* GSM Radio Signalling Link messages on the A-bis interface |
| 2 | * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */ |
| 3 | |
| 4 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 26 | #include <errno.h> |
| 27 | #include <sys/types.h> |
| 28 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 29 | #include <openbsc/gsm_data.h> |
| 30 | #include <openbsc/gsm_04_08.h> |
| 31 | #include <openbsc/abis_rsl.h> |
| 32 | #include <openbsc/chan_alloc.h> |
| 33 | #include <openbsc/debug.h> |
| 34 | #include <openbsc/tlv.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 35 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 36 | #define RSL_ALLOC_SIZE 1024 |
| 37 | #define RSL_ALLOC_HEADROOM 128 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 38 | |
| 39 | static u_int8_t mdisc_by_msgtype(u_int8_t msg_type) |
| 40 | { |
| 41 | /* mask off the transparent bit ? */ |
| 42 | msg_type &= 0xfe; |
| 43 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 44 | if ((msg_type & 0xf0) == 0x00) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 45 | return ABIS_RSL_MDISC_RLL; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 46 | if ((msg_type & 0xf0) == 0x10) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 47 | if (msg_type >= 0x19 && msg_type <= 0x22) |
| 48 | return ABIS_RSL_MDISC_TRX; |
| 49 | else |
| 50 | return ABIS_RSL_MDISC_COM_CHAN; |
| 51 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 52 | if ((msg_type & 0xc) == 0x00) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 53 | return ABIS_RSL_MDISC_DED_CHAN; |
| 54 | |
| 55 | return ABIS_RSL_MDISC_LOC; |
| 56 | } |
| 57 | |
| 58 | static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh, |
| 59 | u_int8_t msg_type) |
| 60 | { |
| 61 | dh->c.msg_discr = mdisc_by_msgtype(msg_type); |
| 62 | dh->c.msg_type = msg_type; |
| 63 | dh->ie_chan = RSL_IE_CHAN_NR; |
| 64 | } |
| 65 | |
| 66 | static inline void init_llm_hdr(struct abis_rsl_rll_hdr *dh, |
| 67 | u_int8_t msg_type) |
| 68 | { |
| 69 | /* dh->c.msg_discr = mdisc_by_msgtype(msg_type); */ |
| 70 | dh->c.msg_discr = ABIS_RSL_MDISC_RLL; |
| 71 | dh->c.msg_type = msg_type; |
| 72 | dh->ie_chan = RSL_IE_CHAN_NR; |
| 73 | dh->ie_link_id = RSL_IE_LINK_IDENT; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /* encode channel number as per Section 9.3.1 */ |
| 78 | u_int8_t rsl_enc_chan_nr(u_int8_t type, u_int8_t subch, u_int8_t timeslot) |
| 79 | { |
| 80 | u_int8_t ret; |
| 81 | |
| 82 | ret = (timeslot & 0x07) | type; |
| 83 | |
| 84 | switch (type) { |
| 85 | case RSL_CHAN_Lm_ACCHs: |
| 86 | subch &= 0x01; |
| 87 | break; |
| 88 | case RSL_CHAN_SDCCH4_ACCH: |
| 89 | subch &= 0x07; |
| 90 | break; |
| 91 | case RSL_CHAN_SDCCH8_ACCH: |
| 92 | subch &= 0x07; |
| 93 | break; |
| 94 | default: |
| 95 | /* no subchannels allowed */ |
| 96 | subch = 0x00; |
| 97 | break; |
| 98 | } |
| 99 | ret |= (subch << 3); |
| 100 | |
| 101 | return ret; |
| 102 | } |
| 103 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 104 | /* determine logical channel based on TRX and channel number IE */ |
| 105 | struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr) |
| 106 | { |
| 107 | struct gsm_lchan *lchan; |
| 108 | u_int8_t ts_nr = chan_nr & 0x07; |
| 109 | u_int8_t cbits = chan_nr >> 3; |
| 110 | u_int8_t lch_idx; |
| 111 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr]; |
| 112 | |
| 113 | if (cbits == 0x01) { |
| 114 | lch_idx = 0; /* TCH/F */ |
| 115 | if (ts->pchan != GSM_PCHAN_TCH_F) |
| 116 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 117 | chan_nr, ts->pchan); |
| 118 | } else if ((cbits & 0x1e) == 0x02) { |
| 119 | lch_idx = cbits & 0x1; /* TCH/H */ |
| 120 | if (ts->pchan != GSM_PCHAN_TCH_H) |
| 121 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 122 | chan_nr, ts->pchan); |
| 123 | } else if ((cbits & 0x1c) == 0x04) { |
| 124 | lch_idx = cbits & 0x3; /* SDCCH/4 */ |
| 125 | if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4) |
| 126 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 127 | chan_nr, ts->pchan); |
| 128 | } else if ((cbits & 0x18) == 0x08) { |
| 129 | lch_idx = cbits & 0x7; /* SDCCH/8 */ |
| 130 | if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C) |
| 131 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 132 | chan_nr, ts->pchan); |
| 133 | } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) { |
| 134 | lch_idx = 0; |
| 135 | if (ts->pchan != GSM_PCHAN_CCCH && |
| 136 | ts->pchan != GSM_PCHAN_CCCH_SDCCH4) |
| 137 | fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n", |
| 138 | chan_nr, ts->pchan); |
| 139 | /* FIXME: we should not return first sdcch4 !!! */ |
| 140 | } else { |
| 141 | fprintf(stderr, "unknown chan_nr=0x%02x\n", chan_nr); |
| 142 | return NULL; |
| 143 | } |
| 144 | |
| 145 | lchan = &ts->lchan[lch_idx]; |
| 146 | |
| 147 | return lchan; |
| 148 | } |
| 149 | |
| 150 | u_int8_t lchan2chan_nr(struct gsm_lchan *lchan) |
| 151 | { |
| 152 | struct gsm_bts_trx_ts *ts = lchan->ts; |
| 153 | u_int8_t cbits, chan_nr; |
| 154 | |
| 155 | switch (ts->pchan) { |
| 156 | case GSM_PCHAN_TCH_F: |
| 157 | cbits = 0x01; |
| 158 | break; |
| 159 | case GSM_PCHAN_TCH_H: |
| 160 | cbits = 0x02; |
| 161 | cbits += lchan->nr; |
| 162 | break; |
| 163 | case GSM_PCHAN_CCCH_SDCCH4: |
| 164 | cbits = 0x04; |
| 165 | cbits += lchan->nr; |
| 166 | break; |
| 167 | case GSM_PCHAN_SDCCH8_SACCH8C: |
| 168 | cbits = 0x08; |
| 169 | cbits += lchan->nr; |
| 170 | break; |
| 171 | default: |
| 172 | case GSM_PCHAN_CCCH: |
| 173 | cbits = 0x10; |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | chan_nr = (cbits << 3) | (ts->nr & 0x7); |
| 178 | |
| 179 | return chan_nr; |
| 180 | } |
| 181 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 182 | /* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */ |
| 183 | u_int64_t str_to_imsi(const char *imsi_str) |
| 184 | { |
| 185 | u_int64_t ret; |
| 186 | |
| 187 | ret = strtoull(imsi_str, NULL, 10); |
| 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | /* Table 5 Clause 7 TS 05.02 */ |
| 193 | unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res) |
| 194 | { |
| 195 | if (!bs_ccch_sdcch_comb) |
| 196 | return 9 - bs_ag_blks_res; |
| 197 | else |
| 198 | return 3 - bs_ag_blks_res; |
| 199 | } |
| 200 | |
| 201 | /* Chapter 6.5.2 of TS 05.02 */ |
| 202 | unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans, |
| 203 | unsigned int n_pag_blocks) |
| 204 | { |
| 205 | return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks; |
| 206 | } |
| 207 | |
| 208 | /* Chapter 6.5.2 of TS 05.02 */ |
| 209 | unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans, |
| 210 | int n_pag_blocks) |
| 211 | { |
| 212 | return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks; |
| 213 | } |
| 214 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 215 | static struct msgb *rsl_msgb_alloc(void) |
| 216 | { |
| 217 | return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM); |
| 218 | } |
| 219 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 220 | /* Send a BCCH_INFO message as per Chapter 8.5.1 */ |
| 221 | int rsl_bcch_info(struct gsm_bts *bts, u_int8_t type, |
| 222 | const u_int8_t *data, int len) |
| 223 | { |
| 224 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 225 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 226 | |
| 227 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh); |
| 228 | init_dchan_hdr(dh, RSL_MT_BCCH_INFO); |
| 229 | dh->chan_nr = RSL_CHAN_BCCH; |
| 230 | |
| 231 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
| 232 | msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data); |
| 233 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 234 | msg->trx = bts->c0; |
| 235 | |
| 236 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | int rsl_sacch_filling(struct gsm_bts *bts, u_int8_t type, |
| 240 | const u_int8_t *data, int len) |
| 241 | { |
| 242 | struct abis_rsl_common_hdr *ch; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 243 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 244 | |
| 245 | ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch)); |
| 246 | ch->msg_discr = ABIS_RSL_MDISC_TRX; |
| 247 | ch->msg_type = RSL_MT_SACCH_FILL; |
| 248 | |
| 249 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
| 250 | msgb_tlv_put(msg, RSL_IE_L3_INFO, len, data); |
| 251 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 252 | msg->trx = bts->c0; |
| 253 | |
| 254 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /* Chapter 8.4.1 */ |
| 258 | int rsl_chan_activate(struct gsm_bts *bts, u_int8_t chan_nr, |
| 259 | u_int8_t act_type, |
| 260 | struct rsl_ie_chan_mode *chan_mode, |
| 261 | struct rsl_ie_chan_ident *chan_ident, |
| 262 | u_int8_t bs_power, u_int8_t ms_power, |
| 263 | u_int8_t ta) |
| 264 | { |
| 265 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 266 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 267 | u_int8_t encr_info = 0x01; |
| 268 | |
| 269 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 270 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 271 | dh->chan_nr = chan_nr; |
| 272 | |
| 273 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
| 274 | /* For compatibility with Phase 1 */ |
| 275 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode), |
| 276 | (u_int8_t *) chan_mode); |
| 277 | msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4, |
| 278 | (u_int8_t *) &chan_ident); |
| 279 | /* FIXME: this shoould be optional */ |
| 280 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1, |
| 281 | (u_int8_t *) &encr_info); |
| 282 | msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power); |
| 283 | msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power); |
| 284 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 285 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 286 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | #define TSC 7 |
| 290 | |
| 291 | int rsl_chan_activate_tch_f(struct gsm_bts_trx_ts *ts) |
| 292 | { |
| 293 | u_int8_t chan_nr = rsl_enc_chan_nr(RSL_CHAN_Bm_ACCHs, 0, ts->nr); |
| 294 | u_int16_t arfcn = ts->trx->arfcn; |
| 295 | struct rsl_ie_chan_mode cm; |
| 296 | struct rsl_ie_chan_ident ci; |
| 297 | |
| 298 | cm.dtx_dtu = 0; |
| 299 | cm.spd_ind = RSL_CMOD_SPD_SPEECH; |
| 300 | cm.chan_rt = RSL_CMOD_CRT_TCH_Bm; |
| 301 | cm.chan_rate = RSL_CMOD_SP_GSM1; |
| 302 | |
| 303 | ci.chan_desc.iei = 0x64; |
| 304 | ci.chan_desc.chan_nr = chan_nr; |
| 305 | /* FIXME: this doesn't support hopping */ |
| 306 | ci.chan_desc.oct3 = (TSC << 5) | ((arfcn & 0x3ff) >> 8); |
| 307 | ci.chan_desc.oct4 = arfcn & 0xff; |
| 308 | #if 0 |
| 309 | ci.mobile_alloc.tag = 0x72; |
| 310 | ci.mobile_alloc.len = 0; /* as per Section 9.3.5 */ |
| 311 | #endif |
| 312 | |
| 313 | return rsl_chan_activate(ts->trx->bts, chan_nr, 0x01, &cm, &ci, 0x01, 0x0f, 0x00); |
| 314 | } |
| 315 | |
| 316 | int rsl_chan_activate_sdcch(struct gsm_bts_trx_ts *ts) |
| 317 | { |
| 318 | u_int8_t chan_nr = rsl_enc_chan_nr(RSL_CHAN_SDCCH4_ACCH, 0, ts->nr); |
| 319 | u_int16_t arfcn = ts->trx->arfcn; |
| 320 | struct rsl_ie_chan_mode cm; |
| 321 | struct rsl_ie_chan_ident ci; |
| 322 | |
| 323 | cm.dtx_dtu = 0x00; |
| 324 | cm.spd_ind = RSL_CMOD_SPD_SIGN; |
| 325 | cm.chan_rt = RSL_CMOD_CRT_SDCCH; |
| 326 | cm.chan_rate = 0x00; |
| 327 | |
| 328 | ci.chan_desc.iei = 0x64; |
| 329 | ci.chan_desc.chan_nr = chan_nr; |
| 330 | ci.chan_desc.oct3 = (TSC << 5) | ((arfcn & 0x3ff) >> 8); |
| 331 | ci.chan_desc.oct4 = arfcn & 0xff; |
| 332 | |
| 333 | /* FIXME: we're sending BS power IE, whcih Abissim doesn't */ |
| 334 | return rsl_chan_activate(ts->trx->bts, chan_nr, 0x00, &cm, &ci, 0x01, 0x0f, 0x00); |
| 335 | } |
| 336 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 337 | int rsl_chan_release(struct gsm_lchan *lchan) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 338 | { |
| 339 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 340 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 341 | |
| 342 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 343 | init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 344 | dh->chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 345 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 346 | msg->lchan = lchan; |
| 347 | msg->trx = lchan->ts->trx; |
| 348 | |
| 349 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len, |
| 353 | u_int8_t *ms_ident, u_int8_t chan_needed) |
| 354 | { |
| 355 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 356 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 357 | |
| 358 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 359 | init_dchan_hdr(dh, RSL_MT_PAGING_CMD); |
| 360 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 361 | |
| 362 | msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group); |
| 363 | msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len, ms_ident); |
| 364 | msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed); |
| 365 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 366 | msg->trx = bts->c0; |
| 367 | |
| 368 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in) |
| 372 | { |
| 373 | int i, len = strlen(str_in); |
| 374 | |
| 375 | for (i = 0; i < len; i++) { |
| 376 | int num = str_in[i] - 0x30; |
| 377 | if (num < 0 || num > 9) |
| 378 | return -1; |
| 379 | if (i % 2 == 0) |
| 380 | bcd_out[i/2] = num; |
| 381 | else |
| 382 | bcd_out[i/2] |= (num << 4); |
| 383 | } |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | # if 0 |
| 389 | int rsl_paging_cmd_imsi(struct gsm_bts *bts, u_int8_t chan_needed, const char *imsi_str) |
| 390 | { |
| 391 | /* FIXME: derive the MS Identity */ |
| 392 | return rsl_paging_cmd(bts, paging_group, x, y, chan_needed); |
| 393 | } |
| 394 | #endif |
| 395 | |
| 396 | int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val) |
| 397 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 398 | struct msgb *msg = rsl_msgb_alloc(); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 399 | struct abis_rsl_dchan_hdr *dh; |
| 400 | |
| 401 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 402 | init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD); |
| 403 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 404 | |
| 405 | /* If phase 2, FULL_IMM_ASS_INFO */ |
| 406 | |
| 407 | msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val); |
| 408 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 409 | msg->trx = bts->c0; |
| 410 | |
| 411 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 414 | /* Send "DATA REQUEST" message with given L3 Info payload */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 415 | /* Chapter 8.3.1 */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 416 | int rsl_data_request(struct msgb *msg, u_int8_t link_id) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 417 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 418 | 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] | 419 | struct abis_rsl_rll_hdr *rh; |
| 420 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 421 | if (msg->lchan == NULL) { |
| 422 | fprintf(stderr, "cannot send DATA REQUEST to unknown lchan\n"); |
| 423 | return -EINVAL; |
| 424 | } |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 425 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 426 | /* First push the L3 IE tag and length */ |
| 427 | msgb_tv_push(msg, RSL_IE_L3_INFO, l3_len); |
| 428 | |
| 429 | /* Then push the RSL header */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 430 | rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh)); |
| 431 | init_llm_hdr(rh, RSL_MT_DATA_REQ); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 432 | rh->chan_nr = lchan2chan_nr(msg->lchan); |
| 433 | rh->link_id = link_id; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 434 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 435 | msg->trx = msg->lchan->ts->trx; |
| 436 | |
| 437 | return abis_rsl_sendmsg(msg); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static int abis_rsl_rx_dchan(struct msgb *msg) |
| 441 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 442 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 443 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 444 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 445 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 446 | |
| 447 | switch (rslh->c.msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 448 | case RSL_MT_CHAN_ACTIV_ACK: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 449 | DEBUGP(DRSL, "rsl_rx_dchan: Channel Activate ACK\n"); |
| 450 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 451 | case RSL_MT_CHAN_ACTIV_NACK: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 452 | DEBUGP(DRSL, "rsl_rx_dchan: Channel Activate NACK\n"); |
| 453 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 454 | case RSL_MT_CONN_FAIL: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 455 | DEBUGP(DRSL, "rsl_rx_dchan: Connection Fail\n"); |
| 456 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 457 | case RSL_MT_MEAS_RES: |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 458 | DEBUGP(DRSL, "rsl_rx_dchan: Measurement Result\n"); |
| 459 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 460 | case RSL_MT_MODE_MODIFY_ACK: |
| 461 | case RSL_MT_MODE_MODIFY_NACK: |
| 462 | case RSL_MT_PHY_CONTEXT_CONF: |
| 463 | case RSL_MT_PREPROC_MEAS_RES: |
| 464 | case RSL_MT_RF_CHAN_REL_ACK: |
| 465 | case RSL_MT_TALKER_DET: |
| 466 | case RSL_MT_LISTENER_DET: |
| 467 | case RSL_MT_REMOTE_CODEC_CONF_REP: |
| 468 | case RSL_MT_MR_CODEC_MOD_ACK: |
| 469 | case RSL_MT_MR_CODEC_MOD_NACK: |
| 470 | case RSL_MT_MR_CODEC_MOD_PER: |
| 471 | fprintf(stderr, "Unimplemented Abis RSL DChan msg 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 472 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 473 | break; |
| 474 | default: |
| 475 | fprintf(stderr, "unknown Abis RSL DChan msg 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 476 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 477 | return -EINVAL; |
| 478 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 479 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static int abis_rsl_rx_trx(struct msgb *msg) |
| 483 | { |
| 484 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 485 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 486 | |
| 487 | switch (rslh->msg_type) { |
| 488 | case RSL_MT_RF_RES_IND: |
| 489 | /* interference on idle channels of TRX */ |
| 490 | case RSL_MT_OVERLOAD: |
| 491 | /* indicate CCCH / ACCH / processor overload */ |
| 492 | case RSL_MT_ERROR_REPORT: |
| 493 | fprintf(stderr, "Unimplemented Abis RSL TRX message type 0x%02x\n", |
| 494 | rslh->msg_type); |
| 495 | break; |
| 496 | default: |
| 497 | fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n", |
| 498 | rslh->msg_type); |
| 499 | return -EINVAL; |
| 500 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 501 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 504 | /* MS has requested a channel on the RACH */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 505 | static int rsl_rx_chan_rqd(struct msgb *msg) |
| 506 | { |
| 507 | struct gsm_bts *bts = msg->bts_link->bts; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 508 | struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg); |
| 509 | struct gsm48_req_ref *rqd_ref; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 510 | struct gsm48_imm_ass ia; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 511 | enum gsm_chan_t lctype; |
| 512 | struct gsm_lchan *lchan; |
| 513 | u_int8_t rqd_ta; |
| 514 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 515 | u_int16_t arfcn; |
| 516 | u_int8_t ts_number, subch; |
| 517 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 518 | /* parse request reference to be used in immediate assign */ |
| 519 | if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE) |
| 520 | return -EINVAL; |
| 521 | |
| 522 | rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1]; |
| 523 | |
| 524 | /* parse access delay and use as TA */ |
| 525 | if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY) |
| 526 | return -EINVAL; |
| 527 | rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2]; |
| 528 | |
| 529 | /* determine channel type (SDCCH/TCH_F/TCH_H) based on |
| 530 | * request reference RA */ |
| 531 | lctype = get_ctype_by_chreq(bts, rqd_ref->ra); |
| 532 | |
| 533 | /* check availability / allocate channel */ |
| 534 | lchan = lchan_alloc(bts, lctype); |
| 535 | if (!lchan) { |
| 536 | fprintf(stderr, "CHAN RQD: no resources\n"); |
| 537 | /* FIXME: send some kind of reject ?!? */ |
| 538 | return -ENOMEM; |
| 539 | } |
| 540 | |
| 541 | ts_number = lchan->ts->nr; |
| 542 | arfcn = lchan->ts->trx->arfcn; |
| 543 | subch = lchan->nr; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 544 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 545 | DEBUGP(DRSL, "Activating ARFCN(%u) TS(%u) SS(%u) lctype %u\n", |
| 546 | arfcn, ts_number, subch, lchan->type); |
| 547 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 548 | /* send CHANNEL ACTIVATION on RSL to BTS */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 549 | if (lchan->ts->pchan == GSM_PCHAN_SDCCH8_SACCH8C) |
| 550 | rsl_chan_activate_sdcch(lchan->ts); |
| 551 | else |
| 552 | rsl_chan_activate_tch_f(lchan->ts); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 553 | |
| 554 | /* create IMMEDIATE ASSIGN 04.08 messge */ |
| 555 | memset(&ia, 0, sizeof(ia)); |
| 556 | ia.l2_plen = 0x2d; |
| 557 | ia.proto_discr = GSM48_PDISC_RR; |
| 558 | ia.msg_type = GSM48_MT_RR_IMM_ASS; |
| 559 | ia.page_mode = GSM48_PM_NORMAL; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 560 | ia.chan_desc.chan_nr = rsl_enc_chan_nr(lchan->ts->pchan, subch, ts_number); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 561 | ia.chan_desc.h0.h = 0; |
| 562 | ia.chan_desc.h0.arfcn_high = arfcn >> 8; |
| 563 | ia.chan_desc.h0.arfcn_low = arfcn & 0xff; |
| 564 | ia.chan_desc.h0.tsc = 7; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 565 | /* use request reference extracted from CHAN_RQD */ |
| 566 | memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref)); |
| 567 | ia.timing_advance = rqd_ta; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 568 | ia.mob_alloc_len = 0; |
| 569 | |
| 570 | /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */ |
| 571 | return rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia); |
| 572 | } |
| 573 | |
| 574 | static int abis_rsl_rx_cchan(struct msgb *msg) |
| 575 | { |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 576 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg) ; |
| 577 | int rc = 0; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 578 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 579 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 580 | |
| 581 | switch (rslh->c.msg_type) { |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 582 | case RSL_MT_CHAN_RQD: |
| 583 | /* MS has requested a channel on the RACH */ |
| 584 | rc = rsl_rx_chan_rqd(msg); |
| 585 | break; |
| 586 | case RSL_MT_DELETE_IND: |
| 587 | /* CCCH overloaded, IMM_ASSIGN was dropped */ |
| 588 | case RSL_MT_CBCH_LOAD_IND: |
| 589 | /* current load on the CBCH */ |
| 590 | case RSL_MT_CCCH_LOAD_IND: |
| 591 | /* current load on the CCCH */ |
| 592 | fprintf(stderr, "Unimplemented Abis RSL TRX message type 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 593 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 594 | break; |
| 595 | default: |
| 596 | fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n", |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 597 | rslh->c.msg_type); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 598 | return -EINVAL; |
| 599 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 600 | |
| 601 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST |
| 605 | 0x02, 0x06, |
| 606 | 0x01, 0x20, |
| 607 | 0x02, 0x00, |
| 608 | 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */ |
| 609 | |
| 610 | static int abis_rsl_rx_rll(struct msgb *msg) |
| 611 | { |
| 612 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 613 | int rc; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 614 | |
| 615 | msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 616 | |
| 617 | switch (rllh->c.msg_type) { |
| 618 | case RSL_MT_DATA_IND: |
| 619 | DEBUGP(DRLL, "DATA INDICATION\n"); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 620 | /* FIXME: Verify L3 info element */ |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame^] | 621 | msg->l3h = &rllh->data[2]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 622 | rc = gsm0408_rcvmsg(msg); |
| 623 | break; |
| 624 | case RSL_MT_EST_IND: |
| 625 | DEBUGP(DRLL, "ESTABLISH INDICATION\n"); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 626 | /* FIXME: Verify L3 info element */ |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame^] | 627 | msg->l3h = &rllh->data[2]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 628 | rc = gsm0408_rcvmsg(msg); |
| 629 | break; |
| 630 | case RSL_MT_ERROR_IND: |
| 631 | case RSL_MT_REL_IND: |
| 632 | case RSL_MT_UNIT_DATA_IND: |
| 633 | fprintf(stderr, "unimplemented Abis RLL message type 0x%02x\n", |
| 634 | rllh->c.msg_type); |
| 635 | break; |
| 636 | default: |
| 637 | fprintf(stderr, "unknown Abis RLL message type 0x%02x\n", |
| 638 | rllh->c.msg_type); |
| 639 | } |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 640 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /* Entry-point where L2 RSL from BTS enters */ |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 644 | int abis_rsl_rcvmsg(struct msgb *msg) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 645 | { |
| 646 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ; |
| 647 | unsigned int l2_len = (void *)msg->tail - msgb_l2(msg); |
| 648 | int rc; |
| 649 | |
| 650 | switch (rslh->msg_discr & 0xfe) { |
| 651 | case ABIS_RSL_MDISC_RLL: |
| 652 | rc = abis_rsl_rx_rll(msg); |
| 653 | break; |
| 654 | case ABIS_RSL_MDISC_DED_CHAN: |
| 655 | rc = abis_rsl_rx_dchan(msg); |
| 656 | break; |
| 657 | case ABIS_RSL_MDISC_COM_CHAN: |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 658 | rc = abis_rsl_rx_cchan(msg); |
| 659 | break; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 660 | case ABIS_RSL_MDISC_TRX: |
| 661 | rc = abis_rsl_rx_trx(msg); |
| 662 | break; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 663 | case ABIS_RSL_MDISC_LOC: |
| 664 | default: |
| 665 | fprintf(stderr, "unknown RSL message discriminator 0x%02x\n", |
| 666 | rslh->msg_discr); |
| 667 | return -EINVAL; |
| 668 | } |
Harald Welte | 4f4a390 | 2008-12-26 00:04:49 +0000 | [diff] [blame] | 669 | msgb_free(msg); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 670 | return rc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 671 | } |