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