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