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