Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1 | /* GSM Radio Signalling Link messages on the A-bis interface |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2 | * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */ |
| 3 | |
Harald Welte | a22d36b | 2010-03-04 10:33:10 +0100 | [diff] [blame] | 4 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 5 | * |
| 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> |
| 25 | #include <stdlib.h> |
| 26 | #include <errno.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <netinet/in.h> |
| 29 | #include <arpa/inet.h> |
| 30 | |
| 31 | #include <openbsc/gsm_data.h> |
| 32 | #include <openbsc/gsm_04_08.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 33 | #include <osmocore/gsm_utils.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 34 | #include <openbsc/abis_rsl.h> |
| 35 | #include <openbsc/chan_alloc.h> |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 36 | #include <openbsc/bsc_rll.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 37 | #include <openbsc/debug.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 38 | #include <osmocore/tlv.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 39 | #include <openbsc/paging.h> |
| 40 | #include <openbsc/signal.h> |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 41 | #include <openbsc/meas_rep.h> |
Harald Welte | 5051774 | 2009-12-20 15:42:44 +0100 | [diff] [blame] | 42 | #include <openbsc/rtp_proxy.h> |
Harald Welte | 1fa8bac | 2010-03-01 21:59:06 +0100 | [diff] [blame] | 43 | #include <osmocore/rsl.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 44 | |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 45 | #include <osmocore/talloc.h> |
| 46 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 47 | #define RSL_ALLOC_SIZE 1024 |
| 48 | #define RSL_ALLOC_HEADROOM 128 |
| 49 | |
| 50 | #define MAX(a, b) (a) >= (b) ? (a) : (b) |
| 51 | |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 52 | static int rsl_send_imm_assignment(struct gsm_lchan *lchan); |
| 53 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 54 | static u_int8_t mdisc_by_msgtype(u_int8_t msg_type) |
| 55 | { |
| 56 | /* mask off the transparent bit ? */ |
| 57 | msg_type &= 0xfe; |
| 58 | |
| 59 | if ((msg_type & 0xf0) == 0x00) |
| 60 | return ABIS_RSL_MDISC_RLL; |
| 61 | if ((msg_type & 0xf0) == 0x10) { |
| 62 | if (msg_type >= 0x19 && msg_type <= 0x22) |
| 63 | return ABIS_RSL_MDISC_TRX; |
| 64 | else |
| 65 | return ABIS_RSL_MDISC_COM_CHAN; |
| 66 | } |
| 67 | if ((msg_type & 0xe0) == 0x20) |
| 68 | return ABIS_RSL_MDISC_DED_CHAN; |
| 69 | |
| 70 | return ABIS_RSL_MDISC_LOC; |
| 71 | } |
| 72 | |
| 73 | static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh, |
| 74 | u_int8_t msg_type) |
| 75 | { |
| 76 | dh->c.msg_discr = mdisc_by_msgtype(msg_type); |
| 77 | dh->c.msg_type = msg_type; |
| 78 | dh->ie_chan = RSL_IE_CHAN_NR; |
| 79 | } |
| 80 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 81 | /* determine logical channel based on TRX and channel number IE */ |
| 82 | struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr) |
| 83 | { |
| 84 | struct gsm_lchan *lchan; |
| 85 | u_int8_t ts_nr = chan_nr & 0x07; |
| 86 | u_int8_t cbits = chan_nr >> 3; |
| 87 | u_int8_t lch_idx; |
| 88 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr]; |
| 89 | |
| 90 | if (cbits == 0x01) { |
| 91 | lch_idx = 0; /* TCH/F */ |
Harald Welte | 37884ed | 2009-10-24 10:25:50 +0200 | [diff] [blame] | 92 | if (ts->pchan != GSM_PCHAN_TCH_F && |
| 93 | ts->pchan != GSM_PCHAN_PDCH && |
| 94 | ts->pchan != GSM_PCHAN_TCH_F_PDCH) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 95 | LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 96 | chan_nr, ts->pchan); |
| 97 | } else if ((cbits & 0x1e) == 0x02) { |
| 98 | lch_idx = cbits & 0x1; /* TCH/H */ |
| 99 | if (ts->pchan != GSM_PCHAN_TCH_H) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 100 | LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 101 | chan_nr, ts->pchan); |
| 102 | } else if ((cbits & 0x1c) == 0x04) { |
| 103 | lch_idx = cbits & 0x3; /* SDCCH/4 */ |
| 104 | if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 105 | LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 106 | chan_nr, ts->pchan); |
| 107 | } else if ((cbits & 0x18) == 0x08) { |
| 108 | lch_idx = cbits & 0x7; /* SDCCH/8 */ |
| 109 | if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 110 | LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 111 | chan_nr, ts->pchan); |
| 112 | } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) { |
| 113 | lch_idx = 0; |
| 114 | if (ts->pchan != GSM_PCHAN_CCCH && |
| 115 | ts->pchan != GSM_PCHAN_CCCH_SDCCH4) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 116 | LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 117 | chan_nr, ts->pchan); |
| 118 | /* FIXME: we should not return first sdcch4 !!! */ |
| 119 | } else { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 120 | LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | lchan = &ts->lchan[lch_idx]; |
Harald Welte | 51d2a59 | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 125 | log_set_context(BSC_CTX_LCHAN, lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 126 | |
| 127 | return lchan; |
| 128 | } |
| 129 | |
Holger Hans Peter Freyther | 942ff17 | 2009-10-22 11:47:45 +0200 | [diff] [blame] | 130 | /* See Table 10.5.25 of GSM04.08 */ |
Harald Welte | b558624 | 2009-12-09 19:18:32 +0100 | [diff] [blame] | 131 | u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 132 | { |
| 133 | struct gsm_bts_trx_ts *ts = lchan->ts; |
| 134 | u_int8_t cbits, chan_nr; |
| 135 | |
| 136 | switch (ts->pchan) { |
| 137 | case GSM_PCHAN_TCH_F: |
Harald Welte | 37884ed | 2009-10-24 10:25:50 +0200 | [diff] [blame] | 138 | case GSM_PCHAN_PDCH: |
| 139 | case GSM_PCHAN_TCH_F_PDCH: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 140 | cbits = 0x01; |
| 141 | break; |
| 142 | case GSM_PCHAN_TCH_H: |
| 143 | cbits = 0x02; |
| 144 | cbits += lchan->nr; |
| 145 | break; |
| 146 | case GSM_PCHAN_CCCH_SDCCH4: |
| 147 | cbits = 0x04; |
| 148 | cbits += lchan->nr; |
| 149 | break; |
| 150 | case GSM_PCHAN_SDCCH8_SACCH8C: |
| 151 | cbits = 0x08; |
| 152 | cbits += lchan->nr; |
| 153 | break; |
| 154 | default: |
| 155 | case GSM_PCHAN_CCCH: |
| 156 | cbits = 0x10; |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | chan_nr = (cbits << 3) | (ts->nr & 0x7); |
| 161 | |
| 162 | return chan_nr; |
| 163 | } |
| 164 | |
| 165 | /* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */ |
| 166 | u_int64_t str_to_imsi(const char *imsi_str) |
| 167 | { |
| 168 | u_int64_t ret; |
| 169 | |
| 170 | ret = strtoull(imsi_str, NULL, 10); |
| 171 | |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | /* Table 5 Clause 7 TS 05.02 */ |
| 176 | unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res) |
| 177 | { |
| 178 | if (!bs_ccch_sdcch_comb) |
| 179 | return 9 - bs_ag_blks_res; |
| 180 | else |
| 181 | return 3 - bs_ag_blks_res; |
| 182 | } |
| 183 | |
| 184 | /* Chapter 6.5.2 of TS 05.02 */ |
| 185 | unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans, |
| 186 | unsigned int n_pag_blocks) |
| 187 | { |
| 188 | return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks; |
| 189 | } |
| 190 | |
| 191 | /* Chapter 6.5.2 of TS 05.02 */ |
| 192 | unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans, |
| 193 | int n_pag_blocks) |
| 194 | { |
| 195 | return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks; |
| 196 | } |
| 197 | |
| 198 | static struct msgb *rsl_msgb_alloc(void) |
| 199 | { |
Harald Welte | 9cfc935 | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 200 | return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM, |
| 201 | "RSL"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | #define MACBLOCK_SIZE 23 |
| 205 | static void pad_macblock(u_int8_t *out, const u_int8_t *in, int len) |
| 206 | { |
| 207 | memcpy(out, in, len); |
| 208 | |
| 209 | if (len < MACBLOCK_SIZE) |
| 210 | memset(out+len, 0x2b, MACBLOCK_SIZE-len); |
| 211 | } |
| 212 | |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 213 | /* Chapter 9.3.7: Encryption Information */ |
| 214 | static int build_encr_info(u_int8_t *out, struct gsm_lchan *lchan) |
| 215 | { |
| 216 | *out++ = lchan->encr.alg_id & 0xff; |
| 217 | if (lchan->encr.key_len) |
| 218 | memcpy(out, lchan->encr.key, lchan->encr.key_len); |
| 219 | return lchan->encr.key_len + 1; |
| 220 | } |
| 221 | |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 222 | static void print_rsl_cause(int lvl, const u_int8_t *cause_v, u_int8_t cause_len) |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 223 | { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 224 | int i; |
| 225 | |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 226 | LOGPC(DRSL, lvl, "CAUSE=0x%02x(%s) ", |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 227 | cause_v[0], rsl_err_name(cause_v[0])); |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 228 | for (i = 1; i < cause_len-1; i++) |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 229 | LOGPC(DRSL, lvl, "%02x ", cause_v[i]); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* Send a BCCH_INFO message as per Chapter 8.5.1 */ |
| 233 | int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type, |
| 234 | const u_int8_t *data, int len) |
| 235 | { |
| 236 | struct abis_rsl_dchan_hdr *dh; |
| 237 | struct msgb *msg = rsl_msgb_alloc(); |
| 238 | |
| 239 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh); |
| 240 | init_dchan_hdr(dh, RSL_MT_BCCH_INFO); |
| 241 | dh->chan_nr = RSL_CHAN_BCCH; |
| 242 | |
| 243 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
| 244 | msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data); |
| 245 | |
| 246 | msg->trx = trx; |
| 247 | |
| 248 | return abis_rsl_sendmsg(msg); |
| 249 | } |
| 250 | |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 251 | int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 252 | const u_int8_t *data, int len) |
| 253 | { |
| 254 | struct abis_rsl_common_hdr *ch; |
| 255 | struct msgb *msg = rsl_msgb_alloc(); |
| 256 | |
| 257 | ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch)); |
| 258 | ch->msg_discr = ABIS_RSL_MDISC_TRX; |
| 259 | ch->msg_type = RSL_MT_SACCH_FILL; |
| 260 | |
| 261 | msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type); |
| 262 | msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data); |
| 263 | |
| 264 | msg->trx = trx; |
| 265 | |
| 266 | return abis_rsl_sendmsg(msg); |
| 267 | } |
| 268 | |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 269 | int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db) |
| 270 | { |
| 271 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 272 | struct msgb *msg; |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 273 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
| 274 | |
| 275 | db = abs(db); |
| 276 | if (db > 30) |
| 277 | return -EINVAL; |
| 278 | |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 279 | msg = rsl_msgb_alloc(); |
| 280 | |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 281 | lchan->bs_power = db/2; |
| 282 | if (fpc) |
| 283 | lchan->bs_power |= 0x10; |
| 284 | |
| 285 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 286 | init_dchan_hdr(dh, RSL_MT_BS_POWER_CONTROL); |
| 287 | dh->chan_nr = chan_nr; |
| 288 | |
| 289 | msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power); |
| 290 | |
| 291 | msg->trx = lchan->ts->trx; |
| 292 | |
| 293 | return abis_rsl_sendmsg(msg); |
| 294 | } |
| 295 | |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 296 | int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm) |
| 297 | { |
| 298 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 299 | struct msgb *msg; |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 300 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
| 301 | int ctl_lvl; |
| 302 | |
Harald Welte | c4dcda0 | 2009-08-09 14:45:18 +0200 | [diff] [blame] | 303 | ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm); |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 304 | if (ctl_lvl < 0) |
| 305 | return ctl_lvl; |
| 306 | |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 307 | msg = rsl_msgb_alloc(); |
| 308 | |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 309 | lchan->ms_power = ctl_lvl; |
| 310 | |
| 311 | if (fpc) |
| 312 | lchan->ms_power |= 0x20; |
| 313 | |
| 314 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 315 | init_dchan_hdr(dh, RSL_MT_MS_POWER_CONTROL); |
| 316 | dh->chan_nr = chan_nr; |
| 317 | |
| 318 | msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power); |
| 319 | |
| 320 | msg->trx = lchan->ts->trx; |
| 321 | |
| 322 | return abis_rsl_sendmsg(msg); |
| 323 | } |
| 324 | |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 325 | static int channel_mode_from_lchan(struct rsl_ie_chan_mode *cm, |
| 326 | struct gsm_lchan *lchan) |
| 327 | { |
| 328 | memset(cm, 0, sizeof(cm)); |
| 329 | |
| 330 | /* FIXME: what to do with data calls ? */ |
| 331 | cm->dtx_dtu = 0x00; |
| 332 | |
| 333 | /* set TCH Speech/Data */ |
| 334 | cm->spd_ind = lchan->rsl_cmode; |
| 335 | |
Harald Welte | 951e351 | 2009-11-27 08:55:16 +0100 | [diff] [blame] | 336 | if (lchan->rsl_cmode == RSL_CMOD_SPD_SIGN && |
| 337 | lchan->tch_mode != GSM48_CMODE_SIGN) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 338 | LOGP(DRSL, LOGL_ERROR, "unsupported: rsl_mode == signalling, " |
Harald Welte | 951e351 | 2009-11-27 08:55:16 +0100 | [diff] [blame] | 339 | "but tch_mode != signalling\n"); |
| 340 | |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 341 | switch (lchan->type) { |
| 342 | case GSM_LCHAN_SDCCH: |
| 343 | cm->chan_rt = RSL_CMOD_CRT_SDCCH; |
| 344 | break; |
| 345 | case GSM_LCHAN_TCH_F: |
| 346 | cm->chan_rt = RSL_CMOD_CRT_TCH_Bm; |
| 347 | break; |
| 348 | case GSM_LCHAN_TCH_H: |
| 349 | cm->chan_rt = RSL_CMOD_CRT_TCH_Lm; |
| 350 | break; |
| 351 | case GSM_LCHAN_NONE: |
| 352 | case GSM_LCHAN_UNKNOWN: |
| 353 | default: |
| 354 | return -EINVAL; |
| 355 | } |
| 356 | |
| 357 | switch (lchan->tch_mode) { |
| 358 | case GSM48_CMODE_SIGN: |
| 359 | cm->chan_rate = 0; |
| 360 | break; |
| 361 | case GSM48_CMODE_SPEECH_V1: |
| 362 | cm->chan_rate = RSL_CMOD_SP_GSM1; |
| 363 | break; |
| 364 | case GSM48_CMODE_SPEECH_EFR: |
| 365 | cm->chan_rate = RSL_CMOD_SP_GSM2; |
| 366 | break; |
| 367 | case GSM48_CMODE_SPEECH_AMR: |
| 368 | cm->chan_rate = RSL_CMOD_SP_GSM3; |
| 369 | break; |
| 370 | case GSM48_CMODE_DATA_14k5: |
| 371 | cm->chan_rate = RSL_CMOD_SP_NT_14k5; |
| 372 | break; |
| 373 | case GSM48_CMODE_DATA_12k0: |
| 374 | cm->chan_rate = RSL_CMOD_SP_NT_12k0; |
| 375 | break; |
| 376 | case GSM48_CMODE_DATA_6k0: |
| 377 | cm->chan_rate = RSL_CMOD_SP_NT_6k0; |
| 378 | break; |
| 379 | default: |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 386 | /* Chapter 8.4.1 */ |
| 387 | #if 0 |
| 388 | int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr, |
| 389 | u_int8_t act_type, |
| 390 | struct rsl_ie_chan_mode *chan_mode, |
| 391 | struct rsl_ie_chan_ident *chan_ident, |
| 392 | u_int8_t bs_power, u_int8_t ms_power, |
| 393 | u_int8_t ta) |
| 394 | { |
| 395 | struct abis_rsl_dchan_hdr *dh; |
| 396 | struct msgb *msg = rsl_msgb_alloc(); |
| 397 | |
| 398 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 399 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 400 | dh->chan_nr = chan_nr; |
| 401 | |
| 402 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
| 403 | /* For compatibility with Phase 1 */ |
| 404 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode), |
| 405 | (u_int8_t *) chan_mode); |
| 406 | msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4, |
| 407 | (u_int8_t *) chan_ident); |
| 408 | #if 0 |
| 409 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1, |
| 410 | (u_int8_t *) &encr_info); |
| 411 | #endif |
| 412 | msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power); |
| 413 | msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power); |
| 414 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 415 | |
| 416 | msg->trx = trx; |
| 417 | |
| 418 | return abis_rsl_sendmsg(msg); |
| 419 | } |
| 420 | #endif |
| 421 | |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 422 | int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type, |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 423 | u_int8_t ta, u_int8_t ho_ref) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 424 | { |
| 425 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 426 | struct msgb *msg; |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 427 | int rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 428 | |
| 429 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 430 | struct rsl_ie_chan_mode cm; |
laforge | f723cf0 | 2010-06-20 21:38:19 +0200 | [diff] [blame] | 431 | struct gsm48_chan_desc cd; |
| 432 | uint8_t *msgb_cd; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 433 | |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 434 | rc = channel_mode_from_lchan(&cm, lchan); |
| 435 | if (rc < 0) |
| 436 | return rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 437 | |
laforge | f723cf0 | 2010-06-20 21:38:19 +0200 | [diff] [blame] | 438 | gsm48_lchan2chan_desc(&cd, lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 439 | |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 440 | msg = rsl_msgb_alloc(); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 441 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 442 | init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV); |
| 443 | dh->chan_nr = chan_nr; |
| 444 | |
| 445 | msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 446 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm), |
| 447 | (u_int8_t *) &cm); |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 448 | /* For compatibility with Phase 1 */ |
laforge | f723cf0 | 2010-06-20 21:38:19 +0200 | [diff] [blame] | 449 | /* RSL IE TAG */ |
| 450 | msgb_v_put(msg, RSL_IE_CHAN_IDENT); |
| 451 | /* RSL IE LEN: 04.08_cd_tag + CD + 04.08_ma_tag + 04.08_ma_len + ma_len */ |
| 452 | msgb_v_put(msg, 1 + sizeof(struct gsm48_chan_desc) + 2 + lchan->ts->hopping.ma_len); |
| 453 | /* GSM 04.08 Chan Desc 2 (TAG + fixed 3 byte length V) */ |
| 454 | msgb_v_put(msg, GSM48_IE_CHANDESC_2); |
| 455 | msgb_cd = msgb_put(msg, sizeof(cd)); |
| 456 | memcpy(msgb_cd, &cd, sizeof(cd)); |
| 457 | /* GSM 04.08 Mobile Allocation: TLV */ |
| 458 | msgb_tlv_put(msg, GSM48_IE_MA_AFTER, lchan->ts->hopping.ma_len, |
| 459 | lchan->ts->hopping.ma_data); |
| 460 | |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 461 | if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) { |
| 462 | u_int8_t encr_info[MAX_A5_KEY_LEN+2]; |
| 463 | rc = build_encr_info(encr_info, lchan); |
| 464 | if (rc > 0) |
| 465 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info); |
| 466 | } |
| 467 | |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 468 | switch (act_type) { |
| 469 | case RSL_ACT_INTER_ASYNC: |
| 470 | case RSL_ACT_INTER_SYNC: |
| 471 | msgb_tv_put(msg, RSL_IE_HANDO_REF, ho_ref); |
| 472 | break; |
| 473 | default: |
| 474 | break; |
| 475 | } |
| 476 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 477 | msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power); |
| 478 | msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power); |
| 479 | msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta); |
| 480 | |
Holger Hans Peter Freyther | 6fe8ab9 | 2010-01-28 04:45:05 +0100 | [diff] [blame] | 481 | if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) |
| 482 | msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf), |
| 483 | (u_int8_t *) &lchan->mr_conf); |
| 484 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 485 | msg->trx = lchan->ts->trx; |
| 486 | |
| 487 | return abis_rsl_sendmsg(msg); |
| 488 | } |
| 489 | |
Harald Welte | 8e77049 | 2009-07-29 11:38:15 +0200 | [diff] [blame] | 490 | /* Chapter 8.4.9: Modify channel mode on BTS side */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 491 | int rsl_chan_mode_modify_req(struct gsm_lchan *lchan) |
| 492 | { |
| 493 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 494 | struct msgb *msg; |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 495 | int rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 496 | |
| 497 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
| 498 | struct rsl_ie_chan_mode cm; |
| 499 | |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 500 | rc = channel_mode_from_lchan(&cm, lchan); |
| 501 | if (rc < 0) |
| 502 | return rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 503 | |
Harald Welte | ed83184 | 2009-06-27 03:09:08 +0200 | [diff] [blame] | 504 | msg = rsl_msgb_alloc(); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 505 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 506 | init_dchan_hdr(dh, RSL_MT_MODE_MODIFY_REQ); |
| 507 | dh->chan_nr = chan_nr; |
| 508 | |
| 509 | msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm), |
| 510 | (u_int8_t *) &cm); |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 511 | |
| 512 | if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) { |
| 513 | u_int8_t encr_info[MAX_A5_KEY_LEN+2]; |
| 514 | rc = build_encr_info(encr_info, lchan); |
| 515 | if (rc > 0) |
| 516 | msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info); |
| 517 | } |
| 518 | |
Holger Hans Peter Freyther | 3cce58f | 2009-11-18 22:57:02 +0100 | [diff] [blame] | 519 | if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) { |
| 520 | msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf), |
| 521 | (u_int8_t *) &lchan->mr_conf); |
| 522 | } |
| 523 | |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 524 | msg->trx = lchan->ts->trx; |
| 525 | |
| 526 | return abis_rsl_sendmsg(msg); |
| 527 | } |
| 528 | |
| 529 | /* Chapter 8.4.6: Send the encryption command with given L3 info */ |
| 530 | int rsl_encryption_cmd(struct msgb *msg) |
| 531 | { |
| 532 | struct abis_rsl_dchan_hdr *dh; |
| 533 | struct gsm_lchan *lchan = msg->lchan; |
| 534 | u_int8_t chan_nr = lchan2chan_nr(lchan); |
| 535 | u_int8_t encr_info[MAX_A5_KEY_LEN+2]; |
Sylvain Munaut | 01f1caf | 2009-09-27 11:13:18 +0200 | [diff] [blame] | 536 | u_int8_t l3_len = msg->len; |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 537 | int rc; |
| 538 | |
| 539 | /* First push the L3 IE tag and length */ |
| 540 | msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len); |
| 541 | |
| 542 | /* then the link identifier (SAPI0, main sign link) */ |
| 543 | msgb_tv_push(msg, RSL_IE_LINK_IDENT, 0); |
| 544 | |
| 545 | /* then encryption information */ |
| 546 | rc = build_encr_info(encr_info, lchan); |
| 547 | if (rc <= 0) |
| 548 | return rc; |
| 549 | msgb_tlv_push(msg, RSL_IE_ENCR_INFO, rc, encr_info); |
| 550 | |
| 551 | /* and finally the DCHAN header */ |
| 552 | dh = (struct abis_rsl_dchan_hdr *) msgb_push(msg, sizeof(*dh)); |
| 553 | init_dchan_hdr(dh, RSL_MT_ENCR_CMD); |
| 554 | dh->chan_nr = chan_nr; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 555 | |
| 556 | msg->trx = lchan->ts->trx; |
| 557 | |
| 558 | return abis_rsl_sendmsg(msg); |
| 559 | } |
| 560 | |
Harald Welte | 85a163c | 2009-08-10 11:43:22 +0200 | [diff] [blame] | 561 | /* Chapter 8.4.5 / 4.6: Deactivate the SACCH after 04.08 RR CHAN RELEASE */ |
Harald Welte | afe3c23 | 2009-07-19 18:36:49 +0200 | [diff] [blame] | 562 | int rsl_deact_sacch(struct gsm_lchan *lchan) |
| 563 | { |
| 564 | struct abis_rsl_dchan_hdr *dh; |
| 565 | struct msgb *msg = rsl_msgb_alloc(); |
| 566 | |
| 567 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 568 | init_dchan_hdr(dh, RSL_MT_DEACTIVATE_SACCH); |
| 569 | dh->chan_nr = lchan2chan_nr(lchan); |
| 570 | |
| 571 | msg->lchan = lchan; |
| 572 | msg->trx = lchan->ts->trx; |
| 573 | |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 574 | DEBUGP(DRSL, "%s DEACTivate SACCH CMD\n", gsm_lchan_name(lchan)); |
Harald Welte | afe3c23 | 2009-07-19 18:36:49 +0200 | [diff] [blame] | 575 | |
| 576 | return abis_rsl_sendmsg(msg); |
| 577 | } |
| 578 | |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 579 | static void error_timeout_cb(void *data) |
| 580 | { |
| 581 | struct gsm_lchan *lchan = data; |
| 582 | if (lchan->state != LCHAN_S_REL_ERR) { |
| 583 | LOGP(DRSL, LOGL_ERROR, "%s error timeout but not in error state: %d\n", |
| 584 | gsm_lchan_name(lchan), lchan->state); |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | /* go back to the none state */ |
| 589 | LOGP(DRSL, LOGL_NOTICE, "%s is back in operation.\n", gsm_lchan_name(lchan)); |
Holger Hans Peter Freyther | 456fb9d | 2010-06-08 11:53:33 +0800 | [diff] [blame] | 590 | rsl_lchan_set_state(lchan, LCHAN_S_NONE); |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 591 | } |
| 592 | |
Harald Welte | 85a163c | 2009-08-10 11:43:22 +0200 | [diff] [blame] | 593 | /* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */ |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 594 | static int rsl_rf_chan_release(struct gsm_lchan *lchan, int error) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 595 | { |
| 596 | struct abis_rsl_dchan_hdr *dh; |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 597 | struct msgb *msg; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 598 | |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 599 | if (lchan->state == LCHAN_S_REL_ERR) { |
| 600 | LOGP(DRSL, LOGL_NOTICE, "%s is in error state not sending release.\n", |
| 601 | gsm_lchan_name(lchan)); |
| 602 | return -1; |
| 603 | } |
| 604 | |
| 605 | msg = rsl_msgb_alloc(); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 606 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 607 | init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL); |
| 608 | dh->chan_nr = lchan2chan_nr(lchan); |
| 609 | |
| 610 | msg->lchan = lchan; |
| 611 | msg->trx = lchan->ts->trx; |
| 612 | |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 613 | DEBUGP(DRSL, "%s RF Channel Release CMD due error %d\n", gsm_lchan_name(lchan), error); |
| 614 | |
| 615 | if (error) { |
| 616 | /* |
| 617 | * the nanoBTS sends RLL release indications after the channel release. This can |
| 618 | * be a problem when we have reassigned the channel to someone else and then can |
| 619 | * not figure out who used this channel. |
| 620 | */ |
Holger Hans Peter Freyther | 456fb9d | 2010-06-08 11:53:33 +0800 | [diff] [blame] | 621 | rsl_lchan_set_state(lchan, LCHAN_S_REL_ERR); |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 622 | lchan->error_timer.data = lchan; |
| 623 | lchan->error_timer.cb = error_timeout_cb; |
| 624 | bsc_schedule_timer(&lchan->error_timer, |
| 625 | msg->trx->bts->network->T3111 + 2, 0); |
| 626 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 627 | |
Harald Welte | 85a163c | 2009-08-10 11:43:22 +0200 | [diff] [blame] | 628 | /* BTS will respond by RF CHAN REL ACK */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 629 | return abis_rsl_sendmsg(msg); |
| 630 | } |
| 631 | |
| 632 | int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len, |
| 633 | u_int8_t *ms_ident, u_int8_t chan_needed) |
| 634 | { |
| 635 | struct abis_rsl_dchan_hdr *dh; |
| 636 | struct msgb *msg = rsl_msgb_alloc(); |
| 637 | |
| 638 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 639 | init_dchan_hdr(dh, RSL_MT_PAGING_CMD); |
| 640 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 641 | |
| 642 | msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group); |
| 643 | msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2); |
| 644 | msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed); |
| 645 | |
| 646 | msg->trx = bts->c0; |
| 647 | |
| 648 | return abis_rsl_sendmsg(msg); |
| 649 | } |
| 650 | |
| 651 | int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need, |
| 652 | struct gsm_subscriber *subscr) |
| 653 | { |
| 654 | #if 0 |
| 655 | u_int8_t mi[128]; |
| 656 | unsigned int mi_len; |
| 657 | u_int8_t paging_group; |
| 658 | #endif |
| 659 | |
| 660 | return -1; |
| 661 | } |
| 662 | |
| 663 | int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in) |
| 664 | { |
| 665 | int i, len = strlen(str_in); |
| 666 | |
| 667 | for (i = 0; i < len; i++) { |
| 668 | int num = str_in[i] - 0x30; |
| 669 | if (num < 0 || num > 9) |
| 670 | return -1; |
| 671 | if (i % 2 == 0) |
| 672 | bcd_out[i/2] = num; |
| 673 | else |
| 674 | bcd_out[i/2] |= (num << 4); |
| 675 | } |
| 676 | |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /* Chapter 8.5.6 */ |
| 681 | int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val) |
| 682 | { |
| 683 | struct msgb *msg = rsl_msgb_alloc(); |
| 684 | struct abis_rsl_dchan_hdr *dh; |
| 685 | u_int8_t buf[MACBLOCK_SIZE]; |
| 686 | |
| 687 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 688 | init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD); |
| 689 | dh->chan_nr = RSL_CHAN_PCH_AGCH; |
| 690 | |
| 691 | switch (bts->type) { |
| 692 | case GSM_BTS_TYPE_BS11: |
| 693 | msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val); |
| 694 | break; |
| 695 | default: |
| 696 | /* If phase 2, construct a FULL_IMM_ASS_INFO */ |
| 697 | pad_macblock(buf, val, len); |
| 698 | msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf); |
| 699 | break; |
| 700 | } |
| 701 | |
| 702 | msg->trx = bts->c0; |
| 703 | |
| 704 | return abis_rsl_sendmsg(msg); |
| 705 | } |
| 706 | |
Harald Welte | 4684e63 | 2009-08-10 09:51:40 +0200 | [diff] [blame] | 707 | /* Send Siemens specific MS RF Power Capability Indication */ |
Harald Welte | 1209075 | 2009-08-10 10:07:33 +0200 | [diff] [blame] | 708 | int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci) |
Harald Welte | 4684e63 | 2009-08-10 09:51:40 +0200 | [diff] [blame] | 709 | { |
| 710 | struct msgb *msg = rsl_msgb_alloc(); |
| 711 | struct abis_rsl_dchan_hdr *dh; |
| 712 | |
| 713 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
| 714 | init_dchan_hdr(dh, RSL_MT_SIEMENS_MRPCI); |
Harald Welte | 874a5b4 | 2009-08-10 11:26:14 +0200 | [diff] [blame] | 715 | dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN; |
Harald Welte | 4684e63 | 2009-08-10 09:51:40 +0200 | [diff] [blame] | 716 | dh->chan_nr = lchan2chan_nr(lchan); |
Harald Welte | 1209075 | 2009-08-10 10:07:33 +0200 | [diff] [blame] | 717 | msgb_tv_put(msg, RSL_IE_SIEMENS_MRPCI, *(u_int8_t *)mrpci); |
Harald Welte | 4684e63 | 2009-08-10 09:51:40 +0200 | [diff] [blame] | 718 | |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 719 | DEBUGP(DRSL, "%s TX Siemens MRPCI 0x%02x\n", |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 720 | gsm_lchan_name(lchan), *(u_int8_t *)mrpci); |
Harald Welte | 874a5b4 | 2009-08-10 11:26:14 +0200 | [diff] [blame] | 721 | |
| 722 | msg->trx = lchan->ts->trx; |
| 723 | |
Harald Welte | 4684e63 | 2009-08-10 09:51:40 +0200 | [diff] [blame] | 724 | return abis_rsl_sendmsg(msg); |
| 725 | } |
| 726 | |
| 727 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 728 | /* Send "DATA REQUEST" message with given L3 Info payload */ |
| 729 | /* Chapter 8.3.1 */ |
| 730 | int rsl_data_request(struct msgb *msg, u_int8_t link_id) |
| 731 | { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 732 | if (msg->lchan == NULL) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 733 | LOGP(DRSL, LOGL_ERROR, "cannot send DATA REQUEST to unknown lchan\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 734 | return -EINVAL; |
| 735 | } |
| 736 | |
Harald Welte | a22d36b | 2010-03-04 10:33:10 +0100 | [diff] [blame] | 737 | rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, lchan2chan_nr(msg->lchan), |
| 738 | link_id, 1); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 739 | |
| 740 | msg->trx = msg->lchan->ts->trx; |
| 741 | |
| 742 | return abis_rsl_sendmsg(msg); |
| 743 | } |
| 744 | |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 745 | /* Send "ESTABLISH REQUEST" message with given L3 Info payload */ |
| 746 | /* Chapter 8.3.1 */ |
| 747 | int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id) |
| 748 | { |
Harald Welte | a22d36b | 2010-03-04 10:33:10 +0100 | [diff] [blame] | 749 | struct msgb *msg; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 750 | |
Harald Welte | a22d36b | 2010-03-04 10:33:10 +0100 | [diff] [blame] | 751 | msg = rsl_rll_simple(RSL_MT_EST_REQ, lchan2chan_nr(lchan), |
| 752 | link_id, 0); |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 753 | msg->trx = lchan->ts->trx; |
| 754 | |
| 755 | return abis_rsl_sendmsg(msg); |
| 756 | } |
| 757 | |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 758 | /* Chapter 8.3.7 Request the release of multiframe mode of RLL connection. |
| 759 | This is what higher layers should call. The BTS then responds with |
| 760 | RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE, |
| 761 | which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls |
| 762 | lchan_free() */ |
Holger Hans Peter Freyther | bcea9a7 | 2010-06-08 11:57:45 +0800 | [diff] [blame] | 763 | int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t reason) |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 764 | { |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 765 | |
Harald Welte | a22d36b | 2010-03-04 10:33:10 +0100 | [diff] [blame] | 766 | struct msgb *msg; |
| 767 | |
| 768 | msg = rsl_rll_simple(RSL_MT_REL_REQ, lchan2chan_nr(lchan), |
| 769 | link_id, 0); |
Holger Hans Peter Freyther | bcea9a7 | 2010-06-08 11:57:45 +0800 | [diff] [blame] | 770 | /* 0 is normal release, 1 is local end */ |
| 771 | msgb_tv_put(msg, RSL_IE_RELEASE_MODE, reason); |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 772 | |
Harald Welte | c88a443 | 2009-12-29 10:44:17 +0100 | [diff] [blame] | 773 | /* FIXME: start some timer in case we don't receive a REL ACK ? */ |
| 774 | |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 775 | msg->trx = lchan->ts->trx; |
| 776 | |
| 777 | return abis_rsl_sendmsg(msg); |
| 778 | } |
| 779 | |
Holger Hans Peter Freyther | 68914a0 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 780 | int rsl_lchan_set_state(struct gsm_lchan *lchan, int state) |
| 781 | { |
| 782 | lchan->state = state; |
| 783 | return 0; |
| 784 | } |
| 785 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 786 | /* Chapter 8.4.2: Channel Activate Acknowledge */ |
| 787 | static int rsl_rx_chan_act_ack(struct msgb *msg) |
| 788 | { |
| 789 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 790 | |
| 791 | /* BTS has confirmed channel activation, we now need |
| 792 | * to assign the activated channel to the MS */ |
| 793 | if (rslh->ie_chan != RSL_IE_CHAN_NR) |
| 794 | return -EINVAL; |
Harald Welte | 6720a43 | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 795 | |
Harald Welte | c88a443 | 2009-12-29 10:44:17 +0100 | [diff] [blame] | 796 | if (msg->lchan->state != LCHAN_S_ACT_REQ) |
Harald Welte | ab2534c | 2009-12-29 10:52:38 +0100 | [diff] [blame] | 797 | LOGP(DRSL, LOGL_NOTICE, "%s CHAN ACT ACK, but state %s\n", |
| 798 | gsm_lchan_name(msg->lchan), |
| 799 | gsm_lchans_name(msg->lchan->state)); |
Holger Hans Peter Freyther | 68914a0 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 800 | rsl_lchan_set_state(msg->lchan, LCHAN_S_ACTIVE); |
Harald Welte | 4baa9c5 | 2009-12-21 13:27:11 +0100 | [diff] [blame] | 801 | |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 802 | if (msg->lchan->rqd_ref) { |
| 803 | rsl_send_imm_assignment(msg->lchan); |
| 804 | talloc_free(msg->lchan->rqd_ref); |
| 805 | msg->lchan->rqd_ref = NULL; |
| 806 | msg->lchan->rqd_ta = 0; |
| 807 | } |
| 808 | |
Harald Welte | 6720a43 | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 809 | dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_ACK, msg->lchan); |
| 810 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /* Chapter 8.4.3: Channel Activate NACK */ |
| 815 | static int rsl_rx_chan_act_nack(struct msgb *msg) |
| 816 | { |
| 817 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 818 | struct tlv_parsed tp; |
| 819 | |
Harald Welte (local) | ed6d762 | 2009-12-27 11:48:11 +0100 | [diff] [blame] | 820 | LOGP(DRSL, LOGL_ERROR, "%s CHANNEL ACTIVATE NACK", |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 821 | gsm_lchan_name(msg->lchan)); |
Harald Welte (local) | ed6d762 | 2009-12-27 11:48:11 +0100 | [diff] [blame] | 822 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 823 | /* BTS has rejected channel activation ?!? */ |
| 824 | if (dh->ie_chan != RSL_IE_CHAN_NR) |
| 825 | return -EINVAL; |
| 826 | |
| 827 | rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
Harald Welte (local) | c3be50c | 2009-12-27 18:12:29 +0100 | [diff] [blame] | 828 | if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) { |
| 829 | const u_int8_t *cause = TLVP_VAL(&tp, RSL_IE_CAUSE); |
| 830 | print_rsl_cause(LOGL_ERROR, cause, |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 831 | TLVP_LEN(&tp, RSL_IE_CAUSE)); |
Harald Welte (local) | c3be50c | 2009-12-27 18:12:29 +0100 | [diff] [blame] | 832 | if (*cause != RSL_ERR_RCH_ALR_ACTV_ALLOC) |
Holger Hans Peter Freyther | 68914a0 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 833 | rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE); |
Harald Welte (local) | c3be50c | 2009-12-27 18:12:29 +0100 | [diff] [blame] | 834 | } else |
Holger Hans Peter Freyther | 68914a0 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 835 | rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE); |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 836 | |
Harald Welte (local) | ed6d762 | 2009-12-27 11:48:11 +0100 | [diff] [blame] | 837 | LOGPC(DRSL, LOGL_ERROR, "\n"); |
| 838 | |
Harald Welte | 6720a43 | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 839 | dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_NACK, msg->lchan); |
| 840 | |
Harald Welte | cddb980 | 2009-08-09 19:50:08 +0200 | [diff] [blame] | 841 | lchan_free(msg->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | /* Chapter 8.4.4: Connection Failure Indication */ |
| 846 | static int rsl_rx_conn_fail(struct msgb *msg) |
| 847 | { |
| 848 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 849 | struct tlv_parsed tp; |
| 850 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 851 | /* FIXME: print which channel */ |
Harald Welte (local) | 4bd7664 | 2009-12-26 22:33:09 +0100 | [diff] [blame] | 852 | LOGP(DRSL, LOGL_NOTICE, "%s CONNECTION FAIL: RELEASING ", |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 853 | gsm_lchan_name(msg->lchan)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 854 | |
| 855 | rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
| 856 | |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 857 | if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 858 | print_rsl_cause(LOGL_NOTICE, TLVP_VAL(&tp, RSL_IE_CAUSE), |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 859 | TLVP_LEN(&tp, RSL_IE_CAUSE)); |
| 860 | |
Harald Welte (local) | 4bd7664 | 2009-12-26 22:33:09 +0100 | [diff] [blame] | 861 | LOGPC(DRSL, LOGL_NOTICE, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 862 | /* FIXME: only free it after channel release ACK */ |
Holger Hans Peter Freyther | 27942e9 | 2010-04-17 06:48:29 +0200 | [diff] [blame] | 863 | counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rf_fail); |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 864 | return rsl_rf_chan_release(msg->lchan, 1); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 865 | } |
| 866 | |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 867 | static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru, |
| 868 | const char *prefix) |
| 869 | { |
Harald Welte | 0e4fa78 | 2009-12-16 16:52:07 +0100 | [diff] [blame] | 870 | DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ", |
| 871 | prefix, rxlev2dbm(mru->full.rx_lev), |
| 872 | prefix, rxlev2dbm(mru->sub.rx_lev)); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 873 | DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ", |
| 874 | prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual); |
| 875 | } |
| 876 | |
| 877 | static void print_meas_rep(struct gsm_meas_rep *mr) |
| 878 | { |
Harald Welte | 0e4fa78 | 2009-12-16 16:52:07 +0100 | [diff] [blame] | 879 | int i; |
| 880 | |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 881 | DEBUGP(DMEAS, "MEASUREMENT RESULT NR=%d ", mr->nr); |
| 882 | |
| 883 | if (mr->flags & MEAS_REP_F_DL_DTX) |
| 884 | DEBUGPC(DMEAS, "DTXd "); |
| 885 | |
| 886 | print_meas_rep_uni(&mr->ul, "ul"); |
| 887 | DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power); |
| 888 | if (mr->flags & MEAS_REP_F_MS_TO) |
| 889 | DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset); |
| 890 | |
| 891 | if (mr->flags & MEAS_REP_F_MS_L1) { |
Harald Welte | 0e4fa78 | 2009-12-16 16:52:07 +0100 | [diff] [blame] | 892 | DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 893 | DEBUGPC(DMEAS, "L1_FPC=%u ", |
| 894 | mr->flags & MEAS_REP_F_FPC ? 1 : 0); |
| 895 | DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta); |
| 896 | } |
| 897 | |
| 898 | if (mr->flags & MEAS_REP_F_UL_DTX) |
| 899 | DEBUGPC(DMEAS, "DTXu "); |
| 900 | if (mr->flags & MEAS_REP_F_BA1) |
| 901 | DEBUGPC(DMEAS, "BA1 "); |
| 902 | if (!(mr->flags & MEAS_REP_F_DL_VALID)) |
| 903 | DEBUGPC(DMEAS, "NOT VALID "); |
| 904 | else |
| 905 | print_meas_rep_uni(&mr->dl, "dl"); |
| 906 | |
| 907 | DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell); |
Harald Welte | 0b833f8 | 2009-12-19 18:33:05 +0100 | [diff] [blame] | 908 | if (mr->num_cell == 7) |
| 909 | return; |
Harald Welte | 0e4fa78 | 2009-12-16 16:52:07 +0100 | [diff] [blame] | 910 | for (i = 0; i < mr->num_cell; i++) { |
| 911 | struct gsm_meas_rep_cell *mrc = &mr->cell[i]; |
Harald Welte | 350c2d3 | 2009-12-25 23:02:22 +0100 | [diff] [blame] | 912 | DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n", |
| 913 | mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev)); |
Harald Welte | 0e4fa78 | 2009-12-16 16:52:07 +0100 | [diff] [blame] | 914 | } |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 917 | static int rsl_rx_meas_res(struct msgb *msg) |
| 918 | { |
| 919 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 920 | struct tlv_parsed tp; |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 921 | struct gsm_meas_rep *mr = lchan_next_meas_rep(msg->lchan); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 922 | u_int8_t len; |
| 923 | const u_int8_t *val; |
| 924 | int rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 925 | |
Harald Welte | 4baa9c5 | 2009-12-21 13:27:11 +0100 | [diff] [blame] | 926 | /* check if this channel is actually active */ |
| 927 | /* FIXME: maybe this check should be way more generic/centralized */ |
Harald Welte | c88a443 | 2009-12-29 10:44:17 +0100 | [diff] [blame] | 928 | if (msg->lchan->state != LCHAN_S_ACTIVE) { |
| 929 | LOGP(DRSL, LOGL_NOTICE, "%s: MEAS RES for inactive channel\n", |
| 930 | gsm_lchan_name(msg->lchan)); |
Harald Welte | 4baa9c5 | 2009-12-21 13:27:11 +0100 | [diff] [blame] | 931 | return 0; |
Harald Welte | c88a443 | 2009-12-29 10:44:17 +0100 | [diff] [blame] | 932 | } |
Harald Welte | 4baa9c5 | 2009-12-21 13:27:11 +0100 | [diff] [blame] | 933 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 934 | memset(mr, 0, sizeof(*mr)); |
Harald Welte | aa0efa1 | 2009-12-16 23:29:34 +0100 | [diff] [blame] | 935 | mr->lchan = msg->lchan; |
Harald Welte | 4efcc54 | 2009-11-30 19:16:47 +0100 | [diff] [blame] | 936 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 937 | rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
| 938 | |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 939 | if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) || |
| 940 | !TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) || |
| 941 | !TLVP_PRESENT(&tp, RSL_IE_BS_POWER)) |
| 942 | return -EIO; |
| 943 | |
| 944 | /* Mandatory Parts */ |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 945 | mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 946 | |
| 947 | len = TLVP_LEN(&tp, RSL_IE_UPLINK_MEAS); |
| 948 | val = TLVP_VAL(&tp, RSL_IE_UPLINK_MEAS); |
| 949 | if (len >= 3) { |
| 950 | if (val[0] & 0x40) |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 951 | mr->flags |= MEAS_REP_F_DL_DTX; |
| 952 | mr->ul.full.rx_lev = val[0] & 0x3f; |
| 953 | mr->ul.sub.rx_lev = val[1] & 0x3f; |
| 954 | mr->ul.full.rx_qual = val[2]>>3 & 0x7; |
| 955 | mr->ul.sub.rx_qual = val[2] & 0x7; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 956 | } |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 957 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 958 | mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 959 | |
| 960 | /* Optional Parts */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 961 | if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET)) |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 962 | mr->ms_timing_offset = |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 963 | *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET); |
| 964 | |
Harald Welte | a1467eb | 2009-06-20 18:44:35 +0200 | [diff] [blame] | 965 | if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) { |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 966 | val = TLVP_VAL(&tp, RSL_IE_L1_INFO); |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 967 | mr->flags |= MEAS_REP_F_MS_L1; |
| 968 | mr->ms_l1.pwr = ms_pwr_dbm(msg->trx->bts->band, val[0] >> 3); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 969 | if (val[0] & 0x04) |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 970 | mr->flags |= MEAS_REP_F_FPC; |
| 971 | mr->ms_l1.ta = val[1]; |
Harald Welte | a1467eb | 2009-06-20 18:44:35 +0200 | [diff] [blame] | 972 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 973 | if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) { |
Holger Hans Peter Freyther | 6d0c8b4 | 2009-10-22 15:43:55 +0200 | [diff] [blame] | 974 | msg->l3h = (u_int8_t *) TLVP_VAL(&tp, RSL_IE_L3_INFO); |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 975 | rc = gsm48_parse_meas_rep(mr, msg); |
Harald Welte | c20bd1d | 2009-11-29 19:07:28 +0100 | [diff] [blame] | 976 | if (rc < 0) |
| 977 | return rc; |
| 978 | } |
| 979 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 980 | print_meas_rep(mr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 981 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 982 | dispatch_signal(SS_LCHAN, S_LCHAN_MEAS_REP, mr); |
Harald Welte | 4efcc54 | 2009-11-30 19:16:47 +0100 | [diff] [blame] | 983 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 984 | return 0; |
| 985 | } |
| 986 | |
Harald Welte | 6720a43 | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 987 | /* Chapter 8.4.7 */ |
| 988 | static int rsl_rx_hando_det(struct msgb *msg) |
| 989 | { |
| 990 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 991 | struct tlv_parsed tp; |
| 992 | |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 993 | DEBUGP(DRSL, "%s HANDOVER DETECT ", gsm_lchan_name(msg->lchan)); |
Harald Welte | 6720a43 | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 994 | |
| 995 | rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
| 996 | |
| 997 | if (TLVP_PRESENT(&tp, RSL_IE_ACCESS_DELAY)) |
| 998 | DEBUGPC(DRSL, "access delay = %u\n", |
| 999 | *TLVP_VAL(&tp, RSL_IE_ACCESS_DELAY)); |
| 1000 | else |
| 1001 | DEBUGPC(DRSL, "\n"); |
| 1002 | |
| 1003 | dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_DETECT, msg->lchan); |
| 1004 | |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1008 | static int abis_rsl_rx_dchan(struct msgb *msg) |
| 1009 | { |
| 1010 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 1011 | int rc = 0; |
| 1012 | char *ts_name; |
| 1013 | |
| 1014 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 1015 | ts_name = gsm_lchan_name(msg->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1016 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1017 | switch (rslh->c.msg_type) { |
| 1018 | case RSL_MT_CHAN_ACTIV_ACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1019 | DEBUGP(DRSL, "%s CHANNEL ACTIVATE ACK\n", ts_name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1020 | rc = rsl_rx_chan_act_ack(msg); |
| 1021 | break; |
| 1022 | case RSL_MT_CHAN_ACTIV_NACK: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1023 | rc = rsl_rx_chan_act_nack(msg); |
| 1024 | break; |
| 1025 | case RSL_MT_CONN_FAIL: |
| 1026 | rc = rsl_rx_conn_fail(msg); |
| 1027 | break; |
| 1028 | case RSL_MT_MEAS_RES: |
| 1029 | rc = rsl_rx_meas_res(msg); |
| 1030 | break; |
Harald Welte | 6720a43 | 2009-11-29 22:45:52 +0100 | [diff] [blame] | 1031 | case RSL_MT_HANDO_DET: |
| 1032 | rc = rsl_rx_hando_det(msg); |
| 1033 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1034 | case RSL_MT_RF_CHAN_REL_ACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1035 | DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name); |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 1036 | if (msg->lchan->state != LCHAN_S_REL_REQ && msg->lchan->state != LCHAN_S_REL_ERR) |
Harald Welte | ab2534c | 2009-12-29 10:52:38 +0100 | [diff] [blame] | 1037 | LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state %s\n", |
| 1038 | gsm_lchan_name(msg->lchan), |
| 1039 | gsm_lchans_name(msg->lchan->state)); |
Holger Hans Peter Freyther | 4a00c06 | 2010-05-31 21:33:15 +0800 | [diff] [blame] | 1040 | bsc_del_timer(&msg->lchan->T3111); |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 1041 | /* we have an error timer pending to release that */ |
| 1042 | if (msg->lchan->state != LCHAN_S_REL_ERR) |
| 1043 | rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1044 | lchan_free(msg->lchan); |
| 1045 | break; |
| 1046 | case RSL_MT_MODE_MODIFY_ACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1047 | DEBUGP(DRSL, "%s CHANNEL MODE MODIFY ACK\n", ts_name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1048 | break; |
| 1049 | case RSL_MT_MODE_MODIFY_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1050 | LOGP(DRSL, LOGL_ERROR, "%s CHANNEL MODE MODIFY NACK\n", ts_name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1051 | break; |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1052 | case RSL_MT_IPAC_PDCH_ACT_ACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1053 | DEBUGPC(DRSL, "%s IPAC PDCH ACT ACK\n", ts_name); |
Harald Welte | 2b36152 | 2010-03-28 14:42:09 +0800 | [diff] [blame] | 1054 | msg->lchan->ts->flags |= TS_F_PDCH_MODE; |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1055 | break; |
| 1056 | case RSL_MT_IPAC_PDCH_ACT_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1057 | LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH ACT NACK\n", ts_name); |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1058 | break; |
| 1059 | case RSL_MT_IPAC_PDCH_DEACT_ACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1060 | DEBUGP(DRSL, "%s IPAC PDCH DEACT ACK\n", ts_name); |
Harald Welte | 2b36152 | 2010-03-28 14:42:09 +0800 | [diff] [blame] | 1061 | msg->lchan->ts->flags &= ~TS_F_PDCH_MODE; |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1062 | break; |
| 1063 | case RSL_MT_IPAC_PDCH_DEACT_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1064 | LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH DEACT NACK\n", ts_name); |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1065 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1066 | case RSL_MT_PHY_CONTEXT_CONF: |
| 1067 | case RSL_MT_PREPROC_MEAS_RES: |
| 1068 | case RSL_MT_TALKER_DET: |
| 1069 | case RSL_MT_LISTENER_DET: |
| 1070 | case RSL_MT_REMOTE_CODEC_CONF_REP: |
| 1071 | case RSL_MT_MR_CODEC_MOD_ACK: |
| 1072 | case RSL_MT_MR_CODEC_MOD_NACK: |
| 1073 | case RSL_MT_MR_CODEC_MOD_PER: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1074 | LOGP(DRSL, LOGL_NOTICE, "%s Unimplemented Abis RSL DChan " |
| 1075 | "msg 0x%02x\n", ts_name, rslh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1076 | break; |
| 1077 | default: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1078 | LOGP(DRSL, LOGL_NOTICE, "%s unknown Abis RSL DChan msg 0x%02x\n", |
| 1079 | ts_name, rslh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1080 | return -EINVAL; |
| 1081 | } |
| 1082 | |
| 1083 | return rc; |
| 1084 | } |
| 1085 | |
| 1086 | static int rsl_rx_error_rep(struct msgb *msg) |
| 1087 | { |
| 1088 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg); |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 1089 | struct tlv_parsed tp; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1090 | |
Harald Welte (local) | ab788cf | 2009-12-28 23:14:22 +0100 | [diff] [blame] | 1091 | LOGP(DRSL, LOGL_ERROR, "%s ERROR REPORT ", gsm_trx_name(msg->trx)); |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 1092 | |
| 1093 | rsl_tlv_parse(&tp, rslh->data, msgb_l2len(msg)-sizeof(*rslh)); |
| 1094 | |
| 1095 | if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1096 | print_rsl_cause(LOGL_ERROR, TLVP_VAL(&tp, RSL_IE_CAUSE), |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 1097 | TLVP_LEN(&tp, RSL_IE_CAUSE)); |
| 1098 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1099 | LOGPC(DRSL, LOGL_ERROR, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | static int abis_rsl_rx_trx(struct msgb *msg) |
| 1105 | { |
| 1106 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg); |
| 1107 | int rc = 0; |
| 1108 | |
| 1109 | switch (rslh->msg_type) { |
| 1110 | case RSL_MT_ERROR_REPORT: |
| 1111 | rc = rsl_rx_error_rep(msg); |
| 1112 | break; |
| 1113 | case RSL_MT_RF_RES_IND: |
| 1114 | /* interference on idle channels of TRX */ |
Harald Welte (local) | ab788cf | 2009-12-28 23:14:22 +0100 | [diff] [blame] | 1115 | //DEBUGP(DRSL, "%s RF Resource Indication\n", gsm_trx_name(msg->trx)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1116 | break; |
| 1117 | case RSL_MT_OVERLOAD: |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1118 | /* indicate CCCH / ACCH / processor overload */ |
Harald Welte (local) | ab788cf | 2009-12-28 23:14:22 +0100 | [diff] [blame] | 1119 | LOGP(DRSL, LOGL_ERROR, "%s CCCH/ACCH/CPU Overload\n", |
| 1120 | gsm_trx_name(msg->trx)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1121 | break; |
| 1122 | default: |
Harald Welte (local) | ab788cf | 2009-12-28 23:14:22 +0100 | [diff] [blame] | 1123 | LOGP(DRSL, LOGL_NOTICE, "%s Unknown Abis RSL TRX message " |
| 1124 | "type 0x%02x\n", gsm_trx_name(msg->trx), rslh->msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1125 | return -EINVAL; |
| 1126 | } |
| 1127 | return rc; |
| 1128 | } |
| 1129 | |
Harald Welte | 427dbc4 | 2009-08-10 00:26:10 +0200 | [diff] [blame] | 1130 | /* If T3101 expires, we never received a response to IMMEDIATE ASSIGN */ |
| 1131 | static void t3101_expired(void *data) |
| 1132 | { |
| 1133 | struct gsm_lchan *lchan = data; |
| 1134 | |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 1135 | rsl_rf_chan_release(lchan, 1); |
Harald Welte | 427dbc4 | 2009-08-10 00:26:10 +0200 | [diff] [blame] | 1136 | } |
| 1137 | |
Holger Hans Peter Freyther | 4a00c06 | 2010-05-31 21:33:15 +0800 | [diff] [blame] | 1138 | /* If T3111 expires, we will send the RF Channel Request */ |
| 1139 | static void t3111_expired(void *data) |
| 1140 | { |
| 1141 | struct gsm_lchan *lchan = data; |
| 1142 | |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 1143 | rsl_rf_chan_release(lchan, 0); |
Holger Hans Peter Freyther | 4a00c06 | 2010-05-31 21:33:15 +0800 | [diff] [blame] | 1144 | } |
| 1145 | |
laforge | 50312e8 | 2010-06-21 12:08:52 +0200 | [diff] [blame] | 1146 | #define GSM48_LEN2PLEN(a) (((a) << 2) | 1) |
| 1147 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1148 | /* MS has requested a channel on the RACH */ |
| 1149 | static int rsl_rx_chan_rqd(struct msgb *msg) |
| 1150 | { |
| 1151 | struct gsm_bts *bts = msg->trx->bts; |
| 1152 | struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg); |
| 1153 | struct gsm48_req_ref *rqd_ref; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1154 | enum gsm_chan_t lctype; |
| 1155 | enum gsm_chreq_reason_t chreq_reason; |
| 1156 | struct gsm_lchan *lchan; |
| 1157 | u_int8_t rqd_ta; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1158 | |
| 1159 | u_int16_t arfcn; |
| 1160 | u_int8_t ts_number, subch; |
| 1161 | |
| 1162 | /* parse request reference to be used in immediate assign */ |
| 1163 | if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE) |
| 1164 | return -EINVAL; |
| 1165 | |
| 1166 | rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1]; |
| 1167 | |
| 1168 | /* parse access delay and use as TA */ |
| 1169 | if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY) |
| 1170 | return -EINVAL; |
| 1171 | rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2]; |
| 1172 | |
| 1173 | /* determine channel type (SDCCH/TCH_F/TCH_H) based on |
| 1174 | * request reference RA */ |
Holger Hans Peter Freyther | 96c8982 | 2009-11-16 17:12:38 +0100 | [diff] [blame] | 1175 | lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci); |
| 1176 | chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1177 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 1178 | counter_inc(bts->network->stats.chreq.total); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 1179 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1180 | /* check availability / allocate channel */ |
| 1181 | lchan = lchan_alloc(bts, lctype); |
| 1182 | if (!lchan) { |
Harald Welte (local) | e0bb5fa | 2009-12-27 13:48:09 +0100 | [diff] [blame] | 1183 | LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n", |
Harald Welte (local) | 02204d0 | 2009-12-27 18:05:25 +0100 | [diff] [blame] | 1184 | msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 1185 | counter_inc(bts->network->stats.chreq.no_channel); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1186 | /* FIXME: send some kind of reject ?!? */ |
| 1187 | return -ENOMEM; |
| 1188 | } |
| 1189 | |
Harald Welte | c88a443 | 2009-12-29 10:44:17 +0100 | [diff] [blame] | 1190 | if (lchan->state != LCHAN_S_NONE) |
| 1191 | LOGP(DRSL, LOGL_NOTICE, "%s lchan_alloc() returned channel " |
Harald Welte | ab2534c | 2009-12-29 10:52:38 +0100 | [diff] [blame] | 1192 | "in state %s\n", gsm_lchan_name(lchan), |
| 1193 | gsm_lchans_name(lchan->state)); |
Holger Hans Peter Freyther | 68914a0 | 2010-04-10 00:12:31 +0200 | [diff] [blame] | 1194 | rsl_lchan_set_state(lchan, LCHAN_S_ACT_REQ); |
Harald Welte (local) | c3be50c | 2009-12-27 18:12:29 +0100 | [diff] [blame] | 1195 | |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 1196 | /* save the RACH data as we need it after the CHAN ACT ACK */ |
| 1197 | lchan->rqd_ref = talloc_zero(bts, struct gsm48_req_ref); |
| 1198 | if (!lchan->rqd_ref) { |
| 1199 | LOGP(DRSL, LOGL_ERROR, "Failed to allocate gsm48_req_ref.\n"); |
| 1200 | lchan_free(lchan); |
| 1201 | return -ENOMEM; |
| 1202 | } |
| 1203 | |
| 1204 | memcpy(lchan->rqd_ref, rqd_ref, sizeof(*rqd_ref)); |
| 1205 | lchan->rqd_ta = rqd_ta; |
| 1206 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1207 | ts_number = lchan->ts->nr; |
| 1208 | arfcn = lchan->ts->trx->arfcn; |
| 1209 | subch = lchan->nr; |
| 1210 | |
Harald Welte | d2dd9de | 2009-08-30 15:37:11 +0900 | [diff] [blame] | 1211 | lchan->encr.alg_id = RSL_ENC_ALG_A5(0); /* no encryption */ |
Harald Welte (local) | cbd4610 | 2009-08-13 10:14:26 +0200 | [diff] [blame] | 1212 | lchan->ms_power = ms_pwr_ctl_lvl(bts->band, bts->ms_max_power); |
Harald Welte | 9a229e1 | 2009-08-10 00:45:40 +0200 | [diff] [blame] | 1213 | lchan->bs_power = 0; /* 0dB reduction, output power = Pn */ |
Harald Welte | 39274f4 | 2009-07-29 15:41:29 +0200 | [diff] [blame] | 1214 | lchan->rsl_cmode = RSL_CMOD_SPD_SIGN; |
Harald Welte | 77234e1 | 2009-08-28 23:28:28 +0900 | [diff] [blame] | 1215 | lchan->tch_mode = GSM48_CMODE_SIGN; |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 1216 | |
| 1217 | /* FIXME: Start another timer or assume the BTS sends a ACK/NACK? */ |
Harald Welte | b90d7bd | 2009-12-17 00:31:10 +0100 | [diff] [blame] | 1218 | rsl_chan_activate_lchan(lchan, 0x00, rqd_ta, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1219 | |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 1220 | DEBUGP(DRSL, "%s Activating ARFCN(%u) SS(%u) lctype %s " |
| 1221 | "r=%s ra=0x%02x\n", gsm_lchan_name(lchan), arfcn, subch, |
| 1222 | gsm_lchant_name(lchan->type), gsm_chreq_name(chreq_reason), |
| 1223 | rqd_ref->ra); |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | static int rsl_send_imm_assignment(struct gsm_lchan *lchan) |
| 1228 | { |
| 1229 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 1230 | u_int8_t buf[GSM_MACBLOCK_LEN]; |
| 1231 | struct gsm48_imm_ass *ia = (struct gsm48_imm_ass *) buf; |
| 1232 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1233 | /* create IMMEDIATE ASSIGN 04.08 messge */ |
laforge | e06d598 | 2010-06-20 15:18:46 +0200 | [diff] [blame] | 1234 | memset(ia, 0, sizeof(*ia)); |
laforge | 50312e8 | 2010-06-21 12:08:52 +0200 | [diff] [blame] | 1235 | /* we set ia->l2_plen once we know the length of the MA below */ |
laforge | e06d598 | 2010-06-20 15:18:46 +0200 | [diff] [blame] | 1236 | ia->proto_discr = GSM48_PDISC_RR; |
| 1237 | ia->msg_type = GSM48_MT_RR_IMM_ASS; |
| 1238 | ia->page_mode = GSM48_PM_SAME; |
| 1239 | gsm48_lchan2chan_desc(&ia->chan_desc, lchan); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1240 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1241 | /* use request reference extracted from CHAN_RQD */ |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 1242 | memcpy(&ia->req_ref, lchan->rqd_ref, sizeof(ia->req_ref)); |
| 1243 | ia->timing_advance = lchan->rqd_ta; |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1244 | if (!lchan->ts->hopping.enabled) { |
laforge | e06d598 | 2010-06-20 15:18:46 +0200 | [diff] [blame] | 1245 | ia->mob_alloc_len = 0; |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1246 | } else { |
laforge | e06d598 | 2010-06-20 15:18:46 +0200 | [diff] [blame] | 1247 | ia->mob_alloc_len = lchan->ts->hopping.ma_len; |
| 1248 | memcpy(ia->mob_alloc, lchan->ts->hopping.ma_data, ia->mob_alloc_len); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1249 | } |
laforge | 50312e8 | 2010-06-21 12:08:52 +0200 | [diff] [blame] | 1250 | ia->l2_plen = GSM48_LEN2PLEN(sizeof(*ia) + ia->mob_alloc_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1251 | |
Harald Welte | 427dbc4 | 2009-08-10 00:26:10 +0200 | [diff] [blame] | 1252 | /* Start timer T3101 to wait for GSM48_MT_RR_PAG_RESP */ |
| 1253 | lchan->T3101.cb = t3101_expired; |
| 1254 | lchan->T3101.data = lchan; |
Holger Hans Peter Freyther | 26ba2e7 | 2009-11-21 21:18:38 +0100 | [diff] [blame] | 1255 | bsc_schedule_timer(&lchan->T3101, bts->network->T3101, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1256 | |
| 1257 | /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */ |
Holger Hans Peter Freyther | c08f6f0 | 2010-06-22 12:11:59 +0800 | [diff] [blame^] | 1258 | return rsl_imm_assign_cmd(bts, sizeof(*ia)+ia->mob_alloc_len, (u_int8_t *) ia); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /* MS has requested a channel on the RACH */ |
| 1262 | static int rsl_rx_ccch_load(struct msgb *msg) |
| 1263 | { |
| 1264 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 1265 | u_int16_t pg_buf_space; |
| 1266 | u_int16_t rach_slot_count = -1; |
| 1267 | u_int16_t rach_busy_count = -1; |
| 1268 | u_int16_t rach_access_count = -1; |
| 1269 | |
| 1270 | switch (rslh->data[0]) { |
| 1271 | case RSL_IE_PAGING_LOAD: |
| 1272 | pg_buf_space = rslh->data[1] << 8 | rslh->data[2]; |
Harald Welte | 008a492 | 2010-04-19 10:24:07 +0200 | [diff] [blame] | 1273 | if (is_ipaccess_bts(msg->trx->bts) && pg_buf_space == 0xffff) { |
| 1274 | /* paging load below configured threshold, use 50 as default */ |
| 1275 | pg_buf_space = 50; |
| 1276 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1277 | paging_update_buffer_space(msg->trx->bts, pg_buf_space); |
| 1278 | break; |
| 1279 | case RSL_IE_RACH_LOAD: |
| 1280 | if (msg->data_len >= 7) { |
| 1281 | rach_slot_count = rslh->data[2] << 8 | rslh->data[3]; |
| 1282 | rach_busy_count = rslh->data[4] << 8 | rslh->data[5]; |
| 1283 | rach_access_count = rslh->data[6] << 8 | rslh->data[7]; |
| 1284 | } |
| 1285 | break; |
| 1286 | default: |
| 1287 | break; |
| 1288 | } |
| 1289 | |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | static int abis_rsl_rx_cchan(struct msgb *msg) |
| 1294 | { |
| 1295 | struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg); |
| 1296 | int rc = 0; |
| 1297 | |
| 1298 | msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr); |
| 1299 | |
| 1300 | switch (rslh->c.msg_type) { |
| 1301 | case RSL_MT_CHAN_RQD: |
| 1302 | /* MS has requested a channel on the RACH */ |
| 1303 | rc = rsl_rx_chan_rqd(msg); |
| 1304 | break; |
| 1305 | case RSL_MT_CCCH_LOAD_IND: |
| 1306 | /* current load on the CCCH */ |
| 1307 | rc = rsl_rx_ccch_load(msg); |
| 1308 | break; |
| 1309 | case RSL_MT_DELETE_IND: |
| 1310 | /* CCCH overloaded, IMM_ASSIGN was dropped */ |
| 1311 | case RSL_MT_CBCH_LOAD_IND: |
| 1312 | /* current load on the CBCH */ |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1313 | LOGP(DRSL, LOGL_NOTICE, "Unimplemented Abis RSL TRX message " |
| 1314 | "type 0x%02x\n", rslh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1315 | break; |
| 1316 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1317 | LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message type " |
| 1318 | "0x%02x\n", rslh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1319 | return -EINVAL; |
| 1320 | } |
| 1321 | |
| 1322 | return rc; |
| 1323 | } |
| 1324 | |
| 1325 | static int rsl_rx_rll_err_ind(struct msgb *msg) |
| 1326 | { |
| 1327 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1328 | u_int8_t *rlm_cause = rllh->data; |
| 1329 | |
Harald Welte (local) | bd76cce | 2009-12-26 23:55:00 +0100 | [diff] [blame] | 1330 | LOGP(DRLL, LOGL_ERROR, "%s ERROR INDICATION cause=%s\n", |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 1331 | gsm_lchan_name(msg->lchan), |
Harald Welte | b30935e | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 1332 | rsl_rlm_cause_name(rlm_cause[1])); |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 1333 | |
| 1334 | rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND); |
Harald Welte (local) | bd76cce | 2009-12-26 23:55:00 +0100 | [diff] [blame] | 1335 | |
Holger Hans Peter Freyther | 27942e9 | 2010-04-17 06:48:29 +0200 | [diff] [blame] | 1336 | if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED) { |
| 1337 | counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rll_err); |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 1338 | return rsl_rf_chan_release(msg->lchan, 1); |
Holger Hans Peter Freyther | 27942e9 | 2010-04-17 06:48:29 +0200 | [diff] [blame] | 1339 | } |
Harald Welte | 692f585 | 2009-07-04 09:40:05 +0200 | [diff] [blame] | 1340 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1341 | return 0; |
| 1342 | } |
| 1343 | |
Holger Hans Peter Freyther | 65f0852 | 2010-04-08 22:39:34 +0200 | [diff] [blame] | 1344 | static void rsl_handle_release(struct gsm_lchan *lchan) |
| 1345 | { |
Holger Hans Peter Freyther | 4a00c06 | 2010-05-31 21:33:15 +0800 | [diff] [blame] | 1346 | struct gsm_bts *bts; |
Holger Hans Peter Freyther | d26cbc8 | 2010-04-08 22:47:44 +0200 | [diff] [blame] | 1347 | if (lchan->state != LCHAN_S_REL_REQ) |
| 1348 | LOGP(DRSL, LOGL_ERROR, "RF release on %s but state %s\n", |
| 1349 | gsm_lchan_name(lchan), |
| 1350 | gsm_lchans_name(lchan->state)); |
| 1351 | |
| 1352 | |
Holger Hans Peter Freyther | 4a00c06 | 2010-05-31 21:33:15 +0800 | [diff] [blame] | 1353 | /* wait a bit to send the RF Channel Release */ |
| 1354 | lchan->T3111.cb = t3111_expired; |
| 1355 | lchan->T3111.data = lchan; |
| 1356 | bts = lchan->ts->trx->bts; |
| 1357 | bsc_schedule_timer(&lchan->T3111, bts->network->T3111, 0); |
Holger Hans Peter Freyther | 65f0852 | 2010-04-08 22:39:34 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1360 | /* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1361 | 0x02, 0x06, |
| 1362 | 0x01, 0x20, |
| 1363 | 0x02, 0x00, |
| 1364 | 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */ |
| 1365 | |
| 1366 | static int abis_rsl_rx_rll(struct msgb *msg) |
| 1367 | { |
| 1368 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1369 | int rc = 0; |
| 1370 | char *ts_name; |
Harald Welte (local) | 64994ce | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 1371 | u_int8_t sapi = rllh->link_id & 7; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1372 | |
| 1373 | msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr); |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 1374 | ts_name = gsm_lchan_name(msg->lchan); |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1375 | DEBUGP(DRLL, "%s SAPI=%u ", ts_name, sapi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1376 | |
| 1377 | switch (rllh->c.msg_type) { |
| 1378 | case RSL_MT_DATA_IND: |
| 1379 | DEBUGPC(DRLL, "DATA INDICATION\n"); |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1380 | if (msgb_l2len(msg) > |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1381 | sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) && |
| 1382 | rllh->data[0] == RSL_IE_L3_INFO) { |
| 1383 | msg->l3h = &rllh->data[3]; |
Harald Welte (local) | 64994ce | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 1384 | return gsm0408_rcvmsg(msg, rllh->link_id); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1385 | } |
| 1386 | break; |
| 1387 | case RSL_MT_EST_IND: |
| 1388 | DEBUGPC(DRLL, "ESTABLISH INDICATION\n"); |
Harald Welte | 427dbc4 | 2009-08-10 00:26:10 +0200 | [diff] [blame] | 1389 | /* lchan is established, stop T3101 */ |
Holger Hans Peter Freyther | d831805 | 2009-10-28 14:23:39 +0100 | [diff] [blame] | 1390 | msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_MS; |
Harald Welte | 427dbc4 | 2009-08-10 00:26:10 +0200 | [diff] [blame] | 1391 | bsc_del_timer(&msg->lchan->T3101); |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1392 | if (msgb_l2len(msg) > |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1393 | sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) && |
| 1394 | rllh->data[0] == RSL_IE_L3_INFO) { |
| 1395 | msg->l3h = &rllh->data[3]; |
Harald Welte (local) | 64994ce | 2009-08-14 11:41:12 +0200 | [diff] [blame] | 1396 | return gsm0408_rcvmsg(msg, rllh->link_id); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1397 | } |
| 1398 | break; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 1399 | case RSL_MT_EST_CONF: |
Harald Welte | 6140217 | 2009-08-09 14:13:58 +0200 | [diff] [blame] | 1400 | DEBUGPC(DRLL, "ESTABLISH CONFIRM\n"); |
Holger Hans Peter Freyther | d831805 | 2009-10-28 14:23:39 +0100 | [diff] [blame] | 1401 | msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_NET; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 1402 | rll_indication(msg->lchan, rllh->link_id, |
| 1403 | BSC_RLLR_IND_EST_CONF); |
| 1404 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1405 | case RSL_MT_REL_IND: |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 1406 | /* BTS informs us of having received DISC from MS */ |
Harald Welte | b660144 | 2009-08-04 02:50:21 +0200 | [diff] [blame] | 1407 | DEBUGPC(DRLL, "RELEASE INDICATION\n"); |
Holger Hans Peter Freyther | d831805 | 2009-10-28 14:23:39 +0100 | [diff] [blame] | 1408 | msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED; |
Harald Welte | ed9a5ab | 2009-08-09 13:47:35 +0200 | [diff] [blame] | 1409 | rll_indication(msg->lchan, rllh->link_id, |
| 1410 | BSC_RLLR_IND_REL_IND); |
Holger Hans Peter Freyther | 65f0852 | 2010-04-08 22:39:34 +0200 | [diff] [blame] | 1411 | rsl_handle_release(msg->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1412 | break; |
| 1413 | case RSL_MT_REL_CONF: |
Harald Welte | 0f2e3c1 | 2009-08-08 13:15:07 +0200 | [diff] [blame] | 1414 | /* BTS informs us of having received UA from MS, |
| 1415 | * in response to DISC that we've sent earlier */ |
Harald Welte | b660144 | 2009-08-04 02:50:21 +0200 | [diff] [blame] | 1416 | DEBUGPC(DRLL, "RELEASE CONFIRMATION\n"); |
Holger Hans Peter Freyther | d831805 | 2009-10-28 14:23:39 +0100 | [diff] [blame] | 1417 | msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED; |
Holger Hans Peter Freyther | 65f0852 | 2010-04-08 22:39:34 +0200 | [diff] [blame] | 1418 | rsl_handle_release(msg->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1419 | break; |
| 1420 | case RSL_MT_ERROR_IND: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1421 | rc = rsl_rx_rll_err_ind(msg); |
| 1422 | break; |
| 1423 | case RSL_MT_UNIT_DATA_IND: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1424 | LOGP(DRLL, LOGL_NOTICE, "unimplemented Abis RLL message " |
| 1425 | "type 0x%02x\n", rllh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1426 | break; |
| 1427 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1428 | LOGP(DRLL, LOGL_NOTICE, "unknown Abis RLL message " |
| 1429 | "type 0x%02x\n", rllh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1430 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1431 | return rc; |
| 1432 | } |
| 1433 | |
Harald Welte | b284b47 | 2009-12-02 01:58:23 +0530 | [diff] [blame] | 1434 | static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan) |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1435 | { |
Harald Welte | b284b47 | 2009-12-02 01:58:23 +0530 | [diff] [blame] | 1436 | switch (lchan->tch_mode) { |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1437 | case GSM48_CMODE_SPEECH_V1: |
Harald Welte | b284b47 | 2009-12-02 01:58:23 +0530 | [diff] [blame] | 1438 | switch (lchan->type) { |
| 1439 | case GSM_LCHAN_TCH_F: |
| 1440 | return 0x00; |
| 1441 | case GSM_LCHAN_TCH_H: |
| 1442 | return 0x03; |
| 1443 | default: |
| 1444 | break; |
| 1445 | } |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1446 | case GSM48_CMODE_SPEECH_EFR: |
Harald Welte | b284b47 | 2009-12-02 01:58:23 +0530 | [diff] [blame] | 1447 | switch (lchan->type) { |
| 1448 | case GSM_LCHAN_TCH_F: |
| 1449 | return 0x01; |
| 1450 | /* there's no half-rate EFR */ |
| 1451 | default: |
| 1452 | break; |
| 1453 | } |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1454 | case GSM48_CMODE_SPEECH_AMR: |
Harald Welte | b284b47 | 2009-12-02 01:58:23 +0530 | [diff] [blame] | 1455 | switch (lchan->type) { |
| 1456 | case GSM_LCHAN_TCH_F: |
| 1457 | return 0x02; |
| 1458 | case GSM_LCHAN_TCH_H: |
| 1459 | return 0x05; |
| 1460 | default: |
| 1461 | break; |
| 1462 | } |
| 1463 | default: |
| 1464 | break; |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1465 | } |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1466 | LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access speech mode for " |
Harald Welte | b284b47 | 2009-12-02 01:58:23 +0530 | [diff] [blame] | 1467 | "tch_mode == 0x%02x\n", lchan->tch_mode); |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1468 | return 0; |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1471 | static u_int8_t ipa_rtp_pt_for_lchan(struct gsm_lchan *lchan) |
| 1472 | { |
| 1473 | switch (lchan->tch_mode) { |
| 1474 | case GSM48_CMODE_SPEECH_V1: |
| 1475 | switch (lchan->type) { |
| 1476 | case GSM_LCHAN_TCH_F: |
| 1477 | return RTP_PT_GSM_FULL; |
| 1478 | case GSM_LCHAN_TCH_H: |
| 1479 | return RTP_PT_GSM_HALF; |
| 1480 | default: |
| 1481 | break; |
| 1482 | } |
| 1483 | case GSM48_CMODE_SPEECH_EFR: |
| 1484 | switch (lchan->type) { |
| 1485 | case GSM_LCHAN_TCH_F: |
| 1486 | return RTP_PT_GSM_EFR; |
| 1487 | /* there's no half-rate EFR */ |
| 1488 | default: |
| 1489 | break; |
| 1490 | } |
| 1491 | case GSM48_CMODE_SPEECH_AMR: |
| 1492 | switch (lchan->type) { |
| 1493 | case GSM_LCHAN_TCH_F: |
| 1494 | return RTP_PT_AMR_FULL; |
| 1495 | case GSM_LCHAN_TCH_H: |
| 1496 | return RTP_PT_AMR_HALF; |
| 1497 | default: |
| 1498 | break; |
| 1499 | } |
| 1500 | default: |
| 1501 | break; |
| 1502 | } |
| 1503 | LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access rtp payload type for " |
| 1504 | "tch_mode == 0x%02x\n & lchan_type == %d", |
| 1505 | lchan->tch_mode, lchan->type); |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1509 | /* ip.access specific RSL extensions */ |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1510 | static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv) |
| 1511 | { |
| 1512 | struct in_addr ip; |
| 1513 | u_int16_t port, conn_id; |
| 1514 | |
| 1515 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_IP)) { |
| 1516 | ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_IP)); |
| 1517 | DEBUGPC(DRSL, "LOCAL_IP=%s ", inet_ntoa(ip)); |
| 1518 | lchan->abis_ip.bound_ip = ntohl(ip.s_addr); |
| 1519 | } |
| 1520 | |
| 1521 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_PORT)) { |
| 1522 | port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_PORT)); |
| 1523 | port = ntohs(port); |
| 1524 | DEBUGPC(DRSL, "LOCAL_PORT=%u ", port); |
| 1525 | lchan->abis_ip.bound_port = port; |
| 1526 | } |
| 1527 | |
| 1528 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_CONN_ID)) { |
| 1529 | conn_id = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_CONN_ID)); |
| 1530 | conn_id = ntohs(conn_id); |
| 1531 | DEBUGPC(DRSL, "CON_ID=%u ", conn_id); |
| 1532 | lchan->abis_ip.conn_id = conn_id; |
| 1533 | } |
| 1534 | |
| 1535 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_RTP_PAYLOAD2)) { |
| 1536 | lchan->abis_ip.rtp_payload2 = |
| 1537 | *TLVP_VAL(tv, RSL_IE_IPAC_RTP_PAYLOAD2); |
| 1538 | DEBUGPC(DRSL, "RTP_PAYLOAD2=0x%02x ", |
| 1539 | lchan->abis_ip.rtp_payload2); |
| 1540 | } |
| 1541 | |
| 1542 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_SPEECH_MODE)) { |
| 1543 | lchan->abis_ip.speech_mode = |
| 1544 | *TLVP_VAL(tv, RSL_IE_IPAC_SPEECH_MODE); |
| 1545 | DEBUGPC(DRSL, "speech_mode=0x%02x ", |
| 1546 | lchan->abis_ip.speech_mode); |
| 1547 | } |
| 1548 | |
| 1549 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_IP)) { |
| 1550 | ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_IP)); |
| 1551 | DEBUGPC(DRSL, "REMOTE_IP=%s ", inet_ntoa(ip)); |
| 1552 | lchan->abis_ip.connect_ip = ntohl(ip.s_addr); |
| 1553 | } |
| 1554 | |
| 1555 | if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_PORT)) { |
| 1556 | port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_PORT)); |
| 1557 | port = ntohs(port); |
| 1558 | DEBUGPC(DRSL, "REMOTE_PORT=%u ", port); |
| 1559 | lchan->abis_ip.connect_port = port; |
| 1560 | } |
| 1561 | } |
| 1562 | |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1563 | int rsl_ipacc_crcx(struct gsm_lchan *lchan) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1564 | { |
| 1565 | struct msgb *msg = rsl_msgb_alloc(); |
| 1566 | struct abis_rsl_dchan_hdr *dh; |
| 1567 | |
| 1568 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1569 | init_dchan_hdr(dh, RSL_MT_IPAC_CRCX); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1570 | dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS; |
| 1571 | dh->chan_nr = lchan2chan_nr(lchan); |
| 1572 | |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1573 | /* 0x1- == receive-only, 0x-1 == EFR codec */ |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1574 | lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan); |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1575 | lchan->abis_ip.rtp_payload = ipa_rtp_pt_for_lchan(lchan); |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1576 | msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode); |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1577 | msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD, lchan->abis_ip.rtp_payload); |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1578 | |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1579 | DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x RTP_PAYLOAD=%d\n", |
| 1580 | gsm_lchan_name(lchan), lchan->abis_ip.speech_mode, |
| 1581 | lchan->abis_ip.rtp_payload); |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1582 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1583 | msg->trx = lchan->ts->trx; |
| 1584 | |
| 1585 | return abis_rsl_sendmsg(msg); |
| 1586 | } |
| 1587 | |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1588 | int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port, |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1589 | u_int8_t rtp_payload2) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1590 | { |
| 1591 | struct msgb *msg = rsl_msgb_alloc(); |
| 1592 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1593 | u_int32_t *att_ip; |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1594 | struct in_addr ia; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1595 | |
| 1596 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1597 | init_dchan_hdr(dh, RSL_MT_IPAC_MDCX); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1598 | dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS; |
| 1599 | dh->chan_nr = lchan2chan_nr(lchan); |
| 1600 | |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1601 | /* we need to store these now as MDCX_ACK does not return them :( */ |
| 1602 | lchan->abis_ip.rtp_payload2 = rtp_payload2; |
| 1603 | lchan->abis_ip.connect_port = port; |
| 1604 | lchan->abis_ip.connect_ip = ip; |
| 1605 | |
Harald Welte | fb4a9e9 | 2009-07-29 12:12:18 +0200 | [diff] [blame] | 1606 | /* 0x0- == both directions, 0x-1 == EFR codec */ |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1607 | lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan); |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1608 | lchan->abis_ip.rtp_payload = ipa_rtp_pt_for_lchan(lchan); |
Harald Welte | fb4a9e9 | 2009-07-29 12:12:18 +0200 | [diff] [blame] | 1609 | |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1610 | ia.s_addr = htonl(ip); |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1611 | DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD=%d RTP_PAYLOAD2=%d " |
| 1612 | "CONN_ID=%d speech_mode=0x%02x\n", gsm_lchan_name(lchan), |
| 1613 | inet_ntoa(ia), port, lchan->abis_ip.rtp_payload, rtp_payload2, |
| 1614 | lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode); |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1615 | |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1616 | msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id); |
| 1617 | msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP); |
| 1618 | att_ip = (u_int32_t *) msgb_put(msg, sizeof(ip)); |
| 1619 | *att_ip = ia.s_addr; |
| 1620 | msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port); |
| 1621 | msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode); |
Sylvain Munaut | 1338a55 | 2009-12-20 22:06:40 +0100 | [diff] [blame] | 1622 | msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD, lchan->abis_ip.rtp_payload); |
Harald Welte | 98d79f9 | 2009-07-28 18:11:56 +0200 | [diff] [blame] | 1623 | if (rtp_payload2) |
| 1624 | msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2); |
| 1625 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1626 | msg->trx = lchan->ts->trx; |
| 1627 | |
| 1628 | return abis_rsl_sendmsg(msg); |
| 1629 | } |
| 1630 | |
Harald Welte | 9947d9f | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 1631 | /* tell BTS to connect RTP stream to our local RTP socket */ |
| 1632 | int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan) |
| 1633 | { |
| 1634 | struct rtp_socket *rs = lchan->abis_ip.rtp_socket; |
| 1635 | int rc; |
| 1636 | |
| 1637 | rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr), |
| 1638 | ntohs(rs->rtp.sin_local.sin_port), |
| 1639 | /* FIXME: use RTP payload of bound socket, not BTS*/ |
| 1640 | lchan->abis_ip.rtp_payload2); |
| 1641 | |
| 1642 | return rc; |
| 1643 | } |
| 1644 | |
Harald Welte | 2b36152 | 2010-03-28 14:42:09 +0800 | [diff] [blame] | 1645 | int rsl_ipacc_pdch_activate(struct gsm_lchan *lchan, int act) |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1646 | { |
| 1647 | struct msgb *msg = rsl_msgb_alloc(); |
| 1648 | struct abis_rsl_dchan_hdr *dh; |
Harald Welte | 2b36152 | 2010-03-28 14:42:09 +0800 | [diff] [blame] | 1649 | u_int8_t msg_type; |
| 1650 | |
| 1651 | if (act) |
| 1652 | msg_type = RSL_MT_IPAC_PDCH_ACT; |
| 1653 | else |
| 1654 | msg_type = RSL_MT_IPAC_PDCH_DEACT; |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1655 | |
| 1656 | dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh)); |
Harald Welte | 2b36152 | 2010-03-28 14:42:09 +0800 | [diff] [blame] | 1657 | init_dchan_hdr(dh, msg_type); |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1658 | dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN; |
| 1659 | dh->chan_nr = lchan2chan_nr(lchan); |
| 1660 | |
Harald Welte | 2b36152 | 2010-03-28 14:42:09 +0800 | [diff] [blame] | 1661 | DEBUGP(DRSL, "%s IPAC_PDCH_%sACT\n", gsm_lchan_name(lchan), |
| 1662 | act ? "" : "DE"); |
Harald Welte | aed946e | 2009-10-24 10:29:22 +0200 | [diff] [blame] | 1663 | |
| 1664 | msg->trx = lchan->ts->trx; |
| 1665 | |
| 1666 | return abis_rsl_sendmsg(msg); |
| 1667 | } |
| 1668 | |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1669 | static int abis_rsl_rx_ipacc_crcx_ack(struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1670 | { |
| 1671 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 1672 | struct tlv_parsed tv; |
Harald Welte | 8750421 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1673 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1674 | |
| 1675 | /* the BTS has acknowledged a local bind, it now tells us the IP |
| 1676 | * address and port number to which it has bound the given logical |
| 1677 | * channel */ |
| 1678 | |
| 1679 | rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
| 1680 | if (!TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_PORT) || |
| 1681 | !TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_IP) || |
Harald Welte | b949895 | 2009-07-12 09:45:05 +0200 | [diff] [blame] | 1682 | !TLVP_PRESENT(&tv, RSL_IE_IPAC_CONN_ID)) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1683 | LOGP(DRSL, LOGL_NOTICE, "mandatory IE missing"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1684 | return -EINVAL; |
| 1685 | } |
Harald Welte | 5051774 | 2009-12-20 15:42:44 +0100 | [diff] [blame] | 1686 | |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1687 | ipac_parse_rtp(lchan, &tv); |
Harald Welte | 5051774 | 2009-12-20 15:42:44 +0100 | [diff] [blame] | 1688 | |
| 1689 | /* in case we don't use direct BTS-to-BTS RTP */ |
| 1690 | if (!ipacc_rtp_direct) { |
| 1691 | int rc; |
| 1692 | /* the BTS has successfully bound a TCH to a local ip/port, |
| 1693 | * which means we can connect our UDP socket to it */ |
| 1694 | if (lchan->abis_ip.rtp_socket) { |
| 1695 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1696 | lchan->abis_ip.rtp_socket = NULL; |
| 1697 | } |
| 1698 | |
| 1699 | lchan->abis_ip.rtp_socket = rtp_socket_create(); |
| 1700 | if (!lchan->abis_ip.rtp_socket) |
| 1701 | goto out_err; |
| 1702 | |
| 1703 | rc = rtp_socket_connect(lchan->abis_ip.rtp_socket, |
| 1704 | lchan->abis_ip.bound_ip, |
| 1705 | lchan->abis_ip.bound_port); |
| 1706 | if (rc < 0) |
| 1707 | goto out_err; |
| 1708 | } |
| 1709 | |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1710 | dispatch_signal(SS_ABISIP, S_ABISIP_CRCX_ACK, msg->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1711 | |
| 1712 | return 0; |
Harald Welte | 5051774 | 2009-12-20 15:42:44 +0100 | [diff] [blame] | 1713 | out_err: |
| 1714 | return -EIO; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1715 | } |
| 1716 | |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1717 | static int abis_rsl_rx_ipacc_mdcx_ack(struct msgb *msg) |
| 1718 | { |
| 1719 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 1720 | struct tlv_parsed tv; |
| 1721 | struct gsm_lchan *lchan = msg->lchan; |
| 1722 | |
| 1723 | /* the BTS has acknowledged a remote connect request and |
| 1724 | * it now tells us the IP address and port number to which it has |
| 1725 | * connected the given logical channel */ |
| 1726 | |
| 1727 | rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
| 1728 | ipac_parse_rtp(lchan, &tv); |
| 1729 | dispatch_signal(SS_ABISIP, S_ABISIP_MDCX_ACK, msg->lchan); |
| 1730 | |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1734 | static int abis_rsl_rx_ipacc_dlcx_ind(struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1735 | { |
| 1736 | struct abis_rsl_dchan_hdr *dh = msgb_l2(msg); |
| 1737 | struct tlv_parsed tv; |
Harald Welte | 5051774 | 2009-12-20 15:42:44 +0100 | [diff] [blame] | 1738 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1739 | |
| 1740 | rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1741 | |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 1742 | if (TLVP_PRESENT(&tv, RSL_IE_CAUSE)) |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1743 | print_rsl_cause(LOGL_DEBUG, TLVP_VAL(&tv, RSL_IE_CAUSE), |
Harald Welte | f1a168d | 2009-07-28 17:58:09 +0200 | [diff] [blame] | 1744 | TLVP_LEN(&tv, RSL_IE_CAUSE)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1745 | |
Harald Welte | 5051774 | 2009-12-20 15:42:44 +0100 | [diff] [blame] | 1746 | /* the BTS tells us a RTP stream has been disconnected */ |
| 1747 | if (lchan->abis_ip.rtp_socket) { |
| 1748 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1749 | lchan->abis_ip.rtp_socket = NULL; |
| 1750 | } |
| 1751 | |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1752 | dispatch_signal(SS_ABISIP, S_ABISIP_DLCX_IND, msg->lchan); |
Harald Welte | ba4e58d | 2009-07-28 18:02:05 +0200 | [diff] [blame] | 1753 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1754 | return 0; |
| 1755 | } |
| 1756 | |
| 1757 | static int abis_rsl_rx_ipacc(struct msgb *msg) |
| 1758 | { |
| 1759 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1760 | char *ts_name; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1761 | int rc = 0; |
| 1762 | |
| 1763 | msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr); |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 1764 | ts_name = gsm_lchan_name(msg->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1765 | |
| 1766 | switch (rllh->c.msg_type) { |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1767 | case RSL_MT_IPAC_CRCX_ACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1768 | DEBUGP(DRSL, "%s IPAC_CRCX_ACK ", ts_name); |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1769 | rc = abis_rsl_rx_ipacc_crcx_ack(msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1770 | break; |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1771 | case RSL_MT_IPAC_CRCX_NACK: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1772 | /* somehow the BTS was unable to bind the lchan to its local |
| 1773 | * port?!? */ |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1774 | LOGP(DRSL, LOGL_ERROR, "%s IPAC_CRCX_NACK\n", ts_name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1775 | break; |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1776 | case RSL_MT_IPAC_MDCX_ACK: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1777 | /* the BTS tells us that a connect operation was successful */ |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1778 | DEBUGP(DRSL, "%s IPAC_MDCX_ACK ", ts_name); |
Harald Welte | bffa499 | 2009-12-19 16:42:06 +0100 | [diff] [blame] | 1779 | rc = abis_rsl_rx_ipacc_mdcx_ack(msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1780 | break; |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1781 | case RSL_MT_IPAC_MDCX_NACK: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1782 | /* somehow the BTS was unable to connect the lchan to a remote |
| 1783 | * port */ |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1784 | LOGP(DRSL, LOGL_ERROR, "%s IPAC_MDCX_NACK\n", ts_name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1785 | break; |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1786 | case RSL_MT_IPAC_DLCX_IND: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1787 | DEBUGP(DRSL, "%s IPAC_DLCX_IND ", ts_name); |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1788 | rc = abis_rsl_rx_ipacc_dlcx_ind(msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1789 | break; |
| 1790 | default: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 1791 | LOGP(DRSL, LOGL_NOTICE, "Unknown ip.access msg_type 0x%02x\n", |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1792 | rllh->c.msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1793 | break; |
| 1794 | } |
| 1795 | DEBUGPC(DRSL, "\n"); |
| 1796 | |
| 1797 | return rc; |
| 1798 | } |
| 1799 | |
| 1800 | |
| 1801 | /* Entry-point where L2 RSL from BTS enters */ |
| 1802 | int abis_rsl_rcvmsg(struct msgb *msg) |
| 1803 | { |
Holger Hans Peter Freyther | c7d9409 | 2009-11-20 15:14:01 +0100 | [diff] [blame] | 1804 | struct abis_rsl_common_hdr *rslh; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1805 | int rc = 0; |
| 1806 | |
Holger Hans Peter Freyther | c7d9409 | 2009-11-20 15:14:01 +0100 | [diff] [blame] | 1807 | if (!msg) { |
| 1808 | DEBUGP(DRSL, "Empty RSL msg?..\n"); |
| 1809 | return -1; |
| 1810 | } |
| 1811 | |
| 1812 | if (msgb_l2len(msg) < sizeof(*rslh)) { |
| 1813 | DEBUGP(DRSL, "Truncated RSL message with l2len: %u\n", msgb_l2len(msg)); |
| 1814 | return -1; |
| 1815 | } |
| 1816 | |
| 1817 | rslh = msgb_l2(msg); |
| 1818 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1819 | switch (rslh->msg_discr & 0xfe) { |
| 1820 | case ABIS_RSL_MDISC_RLL: |
| 1821 | rc = abis_rsl_rx_rll(msg); |
| 1822 | break; |
| 1823 | case ABIS_RSL_MDISC_DED_CHAN: |
| 1824 | rc = abis_rsl_rx_dchan(msg); |
| 1825 | break; |
| 1826 | case ABIS_RSL_MDISC_COM_CHAN: |
| 1827 | rc = abis_rsl_rx_cchan(msg); |
| 1828 | break; |
| 1829 | case ABIS_RSL_MDISC_TRX: |
| 1830 | rc = abis_rsl_rx_trx(msg); |
| 1831 | break; |
| 1832 | case ABIS_RSL_MDISC_LOC: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1833 | LOGP(DRSL, LOGL_NOTICE, "unimplemented RSL msg disc 0x%02x\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1834 | rslh->msg_discr); |
| 1835 | break; |
| 1836 | case ABIS_RSL_MDISC_IPACCESS: |
| 1837 | rc = abis_rsl_rx_ipacc(msg); |
| 1838 | break; |
| 1839 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 1840 | LOGP(DRSL, LOGL_NOTICE, "unknown RSL message discriminator " |
| 1841 | "0x%02x\n", rslh->msg_discr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1842 | return -EINVAL; |
| 1843 | } |
| 1844 | msgb_free(msg); |
| 1845 | return rc; |
| 1846 | } |
| 1847 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1848 | /* From Table 10.5.33 of GSM 04.08 */ |
| 1849 | int rsl_number_of_paging_subchannels(struct gsm_bts *bts) |
| 1850 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1851 | if (bts->si_common.chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) { |
| 1852 | return MAX(1, (3 - bts->si_common.chan_desc.bs_ag_blks_res)) |
| 1853 | * (bts->si_common.chan_desc.bs_pa_mfrms + 2); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1854 | } else { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1855 | return (9 - bts->si_common.chan_desc.bs_ag_blks_res) |
| 1856 | * (bts->si_common.chan_desc.bs_pa_mfrms + 2); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1857 | } |
| 1858 | } |