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