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