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