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