blob: 26da704b64fe6f73e22bb3c7cb9caeab7ec2c3e9 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* 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 Welte8f5e2392009-02-03 12:57:37 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * 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 Welte8470bf22008-12-25 23:28:35 +000025#include <stdlib.h>
Harald Welte52b1f982008-12-23 20:25:15 +000026#include <errno.h>
27#include <sys/types.h>
Harald Welte75099262009-02-16 21:12:08 +000028#include <netinet/in.h>
Harald Welte167df882009-02-17 14:35:45 +000029#include <arpa/inet.h>
Harald Welte52b1f982008-12-23 20:25:15 +000030
Harald Welte8470bf22008-12-25 23:28:35 +000031#include <openbsc/gsm_data.h>
32#include <openbsc/gsm_04_08.h>
Harald Welte66b6a8d2009-08-09 14:45:18 +020033#include <openbsc/gsm_utils.h>
Harald Welte8470bf22008-12-25 23:28:35 +000034#include <openbsc/abis_rsl.h>
35#include <openbsc/chan_alloc.h>
Harald Welteedcc5272009-08-09 13:47:35 +020036#include <openbsc/bsc_rll.h>
Harald Welte8470bf22008-12-25 23:28:35 +000037#include <openbsc/debug.h>
38#include <openbsc/tlv.h>
Holger Freyther392209c2009-02-10 00:06:19 +000039#include <openbsc/paging.h>
Harald Welte167df882009-02-17 14:35:45 +000040#include <openbsc/signal.h>
Harald Welte3c7dc6e2009-11-29 19:07:28 +010041#include <openbsc/meas_rep.h>
Harald Welte17f5bf62009-12-20 15:42:44 +010042#include <openbsc/rtp_proxy.h>
Harald Welte52b1f982008-12-23 20:25:15 +000043
Harald Welte8470bf22008-12-25 23:28:35 +000044#define RSL_ALLOC_SIZE 1024
45#define RSL_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000046
Holger Freyther3b72a892009-02-04 00:31:39 +000047#define MAX(a, b) (a) >= (b) ? (a) : (b)
48
Harald Welte75099262009-02-16 21:12:08 +000049static 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 Welte67fa91b2009-08-10 09:51:40 +0200110 [RSL_IE_SIEMENS_MRPCI] = { TLV_TYPE_TV },
Harald Welteab46d742009-07-12 09:56:39 +0200111 [RSL_IE_IPAC_PROXY_UDP] = { TLV_TYPE_FIXED, 2 },
112 [RSL_IE_IPAC_BSCMPL_TOUT] = { TLV_TYPE_TV },
Harald Welte75099262009-02-16 21:12:08 +0000113 [RSL_IE_IPAC_REMOTE_IP] = { TLV_TYPE_FIXED, 4 },
114 [RSL_IE_IPAC_REMOTE_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welteab46d742009-07-12 09:56:39 +0200115 [RSL_IE_IPAC_RTP_PAYLOAD] = { TLV_TYPE_TV },
Harald Welte75099262009-02-16 21:12:08 +0000116 [RSL_IE_IPAC_LOCAL_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte86c162d2009-07-12 09:45:05 +0200117 [RSL_IE_IPAC_SPEECH_MODE] = { TLV_TYPE_TV },
Harald Welteab46d742009-07-12 09:56:39 +0200118 [RSL_IE_IPAC_LOCAL_IP] = { TLV_TYPE_FIXED, 4 },
Harald Welte86c162d2009-07-12 09:45:05 +0200119 [RSL_IE_IPAC_CONN_ID] = { TLV_TYPE_FIXED, 2 },
Harald Welteab46d742009-07-12 09:56:39 +0200120 [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 Welte86c162d2009-07-12 09:45:05 +0200123 [RSL_IE_IPAC_RTP_PAYLOAD2] = { TLV_TYPE_TV },
Harald Welteab46d742009-07-12 09:56:39 +0200124 [RSL_IE_IPAC_RTP_MPLEX] = { TLV_TYPE_FIXED, 8 },
125 [RSL_IE_IPAC_RTP_MPLEX_ID] = { TLV_TYPE_TV },
Harald Welte75099262009-02-16 21:12:08 +0000126 },
127};
Harald Weltea4d49e92009-05-23 06:39:58 +0000128#define rsl_tlv_parse(dec, buf, len) \
129 tlv_parse(dec, &rsl_att_tlvdef, buf, len, 0, 0)
Harald Welte75099262009-02-16 21:12:08 +0000130
Harald Welte52b1f982008-12-23 20:25:15 +0000131static u_int8_t mdisc_by_msgtype(u_int8_t msg_type)
132{
133 /* mask off the transparent bit ? */
134 msg_type &= 0xfe;
135
Harald Welte8470bf22008-12-25 23:28:35 +0000136 if ((msg_type & 0xf0) == 0x00)
Harald Welte52b1f982008-12-23 20:25:15 +0000137 return ABIS_RSL_MDISC_RLL;
Harald Welte8470bf22008-12-25 23:28:35 +0000138 if ((msg_type & 0xf0) == 0x10) {
Harald Welte52b1f982008-12-23 20:25:15 +0000139 if (msg_type >= 0x19 && msg_type <= 0x22)
140 return ABIS_RSL_MDISC_TRX;
141 else
142 return ABIS_RSL_MDISC_COM_CHAN;
143 }
Harald Welte2d5b6382008-12-27 19:46:06 +0000144 if ((msg_type & 0xe0) == 0x20)
Harald Welte52b1f982008-12-23 20:25:15 +0000145 return ABIS_RSL_MDISC_DED_CHAN;
146
147 return ABIS_RSL_MDISC_LOC;
148}
149
150static 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
158static 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 */
170u_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 Welte8470bf22008-12-25 23:28:35 +0000196/* determine logical channel based on TRX and channel number IE */
197struct 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 Weltea1499d02009-10-24 10:25:50 +0200207 if (ts->pchan != GSM_PCHAN_TCH_F &&
208 ts->pchan != GSM_PCHAN_PDCH &&
209 ts->pchan != GSM_PCHAN_TCH_F_PDCH)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100210 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000211 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 Welteb1d4c8e2009-12-17 23:10:46 +0100215 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000216 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 Welteb1d4c8e2009-12-17 23:10:46 +0100220 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000221 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 Welteb1d4c8e2009-12-17 23:10:46 +0100225 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000226 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 Welteb1d4c8e2009-12-17 23:10:46 +0100231 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000232 chan_nr, ts->pchan);
233 /* FIXME: we should not return first sdcch4 !!! */
234 } else {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100235 LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
Harald Welte8470bf22008-12-25 23:28:35 +0000236 return NULL;
237 }
238
239 lchan = &ts->lchan[lch_idx];
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100240 debug_set_context(BSC_CTX_LCHAN, lchan);
241 debug_set_context(BSC_CTX_SUBSCR, lchan->subscr);
Harald Welte8470bf22008-12-25 23:28:35 +0000242
243 return lchan;
244}
245
Holger Hans Peter Freythere81a6102009-10-22 11:47:45 +0200246/* See Table 10.5.25 of GSM04.08 */
Harald Welte24766092009-12-09 19:18:32 +0100247u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan)
Harald Welte8470bf22008-12-25 23:28:35 +0000248{
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 Weltea1499d02009-10-24 10:25:50 +0200254 case GSM_PCHAN_PDCH:
255 case GSM_PCHAN_TCH_F_PDCH:
Harald Welte8470bf22008-12-25 23:28:35 +0000256 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 Welte52b1f982008-12-23 20:25:15 +0000281/* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */
282u_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 */
292unsigned 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 */
301unsigned 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 */
308unsigned 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 Welte8470bf22008-12-25 23:28:35 +0000314static struct msgb *rsl_msgb_alloc(void)
315{
Harald Welte966636f2009-06-26 19:39:35 +0200316 return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM,
317 "RSL");
Harald Welte8470bf22008-12-25 23:28:35 +0000318}
319
Harald Welte362322e2009-02-15 14:36:38 +0000320#define MACBLOCK_SIZE 23
321static 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 Welte08d91a52009-08-30 15:37:11 +0900329/* Chapter 9.3.7: Encryption Information */
330static 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 Welte8830e072009-07-28 17:58:09 +0200339static 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 Welte2da86292009-08-04 02:31:05 +0200346 [RSL_ERR_T_MSRFPCI_EXP] = "Siemens: T_MSRFPCI Expired",
Harald Welte8830e072009-07-28 17:58:09 +0200347 [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
373static const char *rsl_err_name(u_int8_t err)
Harald Welte7f93cea2009-02-23 00:02:59 +0000374{
Harald Welte8830e072009-07-28 17:58:09 +0200375 if (rsl_err_vals[err])
376 return rsl_err_vals[err];
377 else
378 return "unknown";
379}
380
Harald Welte5b8ed432009-12-24 12:20:20 +0100381static void print_rsl_cause(int lvl, const u_int8_t *cause_v, u_int8_t cause_len)
Harald Welte8830e072009-07-28 17:58:09 +0200382{
Harald Welte7f93cea2009-02-23 00:02:59 +0000383 int i;
384
Harald Welte5b8ed432009-12-24 12:20:20 +0100385 LOGPC(DRSL, lvl, "CAUSE=0x%02x(%s) ",
Harald Welte8830e072009-07-28 17:58:09 +0200386 cause_v[0], rsl_err_name(cause_v[0]));
387 for (i = 1; i < cause_len-1; i++)
Harald Welte5b8ed432009-12-24 12:20:20 +0100388 LOGPC(DRSL, lvl, "%02x ", cause_v[i]);
Harald Welte7f93cea2009-02-23 00:02:59 +0000389}
390
Harald Welte52b1f982008-12-23 20:25:15 +0000391/* Send a BCCH_INFO message as per Chapter 8.5.1 */
Harald Weltee79769b2009-02-07 00:48:17 +0000392int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000393 const u_int8_t *data, int len)
394{
395 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000396 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000397
398 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh);
399 init_dchan_hdr(dh, RSL_MT_BCCH_INFO);
400 dh->chan_nr = RSL_CHAN_BCCH;
401
402 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
403 msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data);
404
Harald Weltee79769b2009-02-07 00:48:17 +0000405 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000406
407 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000408}
409
Harald Weltee79769b2009-02-07 00:48:17 +0000410int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000411 const u_int8_t *data, int len)
412{
413 struct abis_rsl_common_hdr *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000414 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000415
416 ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch));
417 ch->msg_discr = ABIS_RSL_MDISC_TRX;
418 ch->msg_type = RSL_MT_SACCH_FILL;
419
420 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
Harald Welte702d8702008-12-26 20:25:35 +0000421 msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data);
Harald Welte52b1f982008-12-23 20:25:15 +0000422
Harald Weltee79769b2009-02-07 00:48:17 +0000423 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000424
425 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000426}
427
Harald Weltefcd24452009-06-20 18:15:19 +0200428int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db)
429{
430 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200431 struct msgb *msg;
Harald Weltefcd24452009-06-20 18:15:19 +0200432 u_int8_t chan_nr = lchan2chan_nr(lchan);
433
434 db = abs(db);
435 if (db > 30)
436 return -EINVAL;
437
Harald Welteeab33352009-06-27 03:09:08 +0200438 msg = rsl_msgb_alloc();
439
Harald Weltefcd24452009-06-20 18:15:19 +0200440 lchan->bs_power = db/2;
441 if (fpc)
442 lchan->bs_power |= 0x10;
443
444 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
445 init_dchan_hdr(dh, RSL_MT_BS_POWER_CONTROL);
446 dh->chan_nr = chan_nr;
447
448 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
449
450 msg->trx = lchan->ts->trx;
451
452 return abis_rsl_sendmsg(msg);
453}
454
Harald Weltefcd24452009-06-20 18:15:19 +0200455int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm)
456{
457 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200458 struct msgb *msg;
Harald Weltefcd24452009-06-20 18:15:19 +0200459 u_int8_t chan_nr = lchan2chan_nr(lchan);
460 int ctl_lvl;
461
Harald Welte66b6a8d2009-08-09 14:45:18 +0200462 ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm);
Harald Weltefcd24452009-06-20 18:15:19 +0200463 if (ctl_lvl < 0)
464 return ctl_lvl;
465
Harald Welteeab33352009-06-27 03:09:08 +0200466 msg = rsl_msgb_alloc();
467
Harald Weltefcd24452009-06-20 18:15:19 +0200468 lchan->ms_power = ctl_lvl;
469
470 if (fpc)
471 lchan->ms_power |= 0x20;
472
473 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
474 init_dchan_hdr(dh, RSL_MT_MS_POWER_CONTROL);
475 dh->chan_nr = chan_nr;
476
477 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
478
479 msg->trx = lchan->ts->trx;
480
481 return abis_rsl_sendmsg(msg);
482}
483
Harald Welte9943c5b2009-07-29 15:41:29 +0200484static int channel_mode_from_lchan(struct rsl_ie_chan_mode *cm,
485 struct gsm_lchan *lchan)
486{
487 memset(cm, 0, sizeof(cm));
488
489 /* FIXME: what to do with data calls ? */
490 cm->dtx_dtu = 0x00;
491
492 /* set TCH Speech/Data */
493 cm->spd_ind = lchan->rsl_cmode;
494
Harald Welte1a79d362009-11-27 08:55:16 +0100495 if (lchan->rsl_cmode == RSL_CMOD_SPD_SIGN &&
496 lchan->tch_mode != GSM48_CMODE_SIGN)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100497 LOGP(DRSL, LOGL_ERROR, "unsupported: rsl_mode == signalling, "
Harald Welte1a79d362009-11-27 08:55:16 +0100498 "but tch_mode != signalling\n");
499
Harald Welte9943c5b2009-07-29 15:41:29 +0200500 switch (lchan->type) {
501 case GSM_LCHAN_SDCCH:
502 cm->chan_rt = RSL_CMOD_CRT_SDCCH;
503 break;
504 case GSM_LCHAN_TCH_F:
505 cm->chan_rt = RSL_CMOD_CRT_TCH_Bm;
506 break;
507 case GSM_LCHAN_TCH_H:
508 cm->chan_rt = RSL_CMOD_CRT_TCH_Lm;
509 break;
510 case GSM_LCHAN_NONE:
511 case GSM_LCHAN_UNKNOWN:
512 default:
513 return -EINVAL;
514 }
515
516 switch (lchan->tch_mode) {
517 case GSM48_CMODE_SIGN:
518 cm->chan_rate = 0;
519 break;
520 case GSM48_CMODE_SPEECH_V1:
521 cm->chan_rate = RSL_CMOD_SP_GSM1;
522 break;
523 case GSM48_CMODE_SPEECH_EFR:
524 cm->chan_rate = RSL_CMOD_SP_GSM2;
525 break;
526 case GSM48_CMODE_SPEECH_AMR:
527 cm->chan_rate = RSL_CMOD_SP_GSM3;
528 break;
529 case GSM48_CMODE_DATA_14k5:
530 cm->chan_rate = RSL_CMOD_SP_NT_14k5;
531 break;
532 case GSM48_CMODE_DATA_12k0:
533 cm->chan_rate = RSL_CMOD_SP_NT_12k0;
534 break;
535 case GSM48_CMODE_DATA_6k0:
536 cm->chan_rate = RSL_CMOD_SP_NT_6k0;
537 break;
538 default:
539 return -EINVAL;
540 }
541
542 return 0;
543}
544
Harald Welte52b1f982008-12-23 20:25:15 +0000545/* Chapter 8.4.1 */
Harald Welteddab3c72009-02-28 13:19:15 +0000546#if 0
Harald Weltee79769b2009-02-07 00:48:17 +0000547int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
Harald Welte52b1f982008-12-23 20:25:15 +0000548 u_int8_t act_type,
549 struct rsl_ie_chan_mode *chan_mode,
550 struct rsl_ie_chan_ident *chan_ident,
551 u_int8_t bs_power, u_int8_t ms_power,
552 u_int8_t ta)
553{
554 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000555 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000556
557 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
558 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
559 dh->chan_nr = chan_nr;
560
561 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
562 /* For compatibility with Phase 1 */
563 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode),
564 (u_int8_t *) chan_mode);
565 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
Harald Welte702d8702008-12-26 20:25:35 +0000566 (u_int8_t *) chan_ident);
Harald Welte702d8702008-12-26 20:25:35 +0000567#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000568 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
569 (u_int8_t *) &encr_info);
Harald Welte702d8702008-12-26 20:25:35 +0000570#endif
Harald Welted4c9bf32009-02-15 16:56:18 +0000571 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
Harald Welte52b1f982008-12-23 20:25:15 +0000572 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
573 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
574
Harald Weltee79769b2009-02-07 00:48:17 +0000575 msg->trx = trx;
576
Harald Welte8470bf22008-12-25 23:28:35 +0000577 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000578}
Harald Welteddab3c72009-02-28 13:19:15 +0000579#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000580
Harald Welte8f5e2392009-02-03 12:57:37 +0000581int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
Harald Welte8d77b952009-12-17 00:31:10 +0100582 u_int8_t ta, u_int8_t ho_ref)
Harald Welte4b634542008-12-27 01:55:51 +0000583{
584 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200585 struct msgb *msg;
Harald Welte9943c5b2009-07-29 15:41:29 +0200586 int rc;
Harald Welte4b634542008-12-27 01:55:51 +0000587
588 u_int8_t chan_nr = lchan2chan_nr(lchan);
589 u_int16_t arfcn = lchan->ts->trx->arfcn;
590 struct rsl_ie_chan_mode cm;
591 struct rsl_ie_chan_ident ci;
592
Harald Welte9943c5b2009-07-29 15:41:29 +0200593 rc = channel_mode_from_lchan(&cm, lchan);
594 if (rc < 0)
595 return rc;
Harald Welte4b634542008-12-27 01:55:51 +0000596
Harald Welte02b0e092009-02-28 13:11:07 +0000597 memset(&ci, 0, sizeof(ci));
Harald Welte4b634542008-12-27 01:55:51 +0000598 ci.chan_desc.iei = 0x64;
599 ci.chan_desc.chan_nr = chan_nr;
Harald Welte02b0e092009-02-28 13:11:07 +0000600 ci.chan_desc.oct3 = (lchan->ts->trx->bts->tsc << 5) | ((arfcn & 0x3ff) >> 8);
Harald Welte4b634542008-12-27 01:55:51 +0000601 ci.chan_desc.oct4 = arfcn & 0xff;
602
Harald Welteeab33352009-06-27 03:09:08 +0200603 msg = rsl_msgb_alloc();
Harald Welte4b634542008-12-27 01:55:51 +0000604 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
605 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
606 dh->chan_nr = chan_nr;
607
608 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
Harald Welte4b634542008-12-27 01:55:51 +0000609 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
610 (u_int8_t *) &cm);
Harald Welte8d77b952009-12-17 00:31:10 +0100611 /* For compatibility with Phase 1 */
Harald Welte4b634542008-12-27 01:55:51 +0000612 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
613 (u_int8_t *) &ci);
Harald Welte08d91a52009-08-30 15:37:11 +0900614
615 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
616 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
617 rc = build_encr_info(encr_info, lchan);
618 if (rc > 0)
619 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
620 }
621
Harald Welte8d77b952009-12-17 00:31:10 +0100622 switch (act_type) {
623 case RSL_ACT_INTER_ASYNC:
624 case RSL_ACT_INTER_SYNC:
625 msgb_tv_put(msg, RSL_IE_HANDO_REF, ho_ref);
626 break;
627 default:
628 break;
629 }
630
Harald Welted4c9bf32009-02-15 16:56:18 +0000631 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
632 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
Harald Welte4b634542008-12-27 01:55:51 +0000633 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
634
Harald Weltee79769b2009-02-07 00:48:17 +0000635 msg->trx = lchan->ts->trx;
636
Harald Welte4b634542008-12-27 01:55:51 +0000637 return abis_rsl_sendmsg(msg);
638}
639
Harald Welte470abb72009-07-29 11:38:15 +0200640/* Chapter 8.4.9: Modify channel mode on BTS side */
Harald Welteda783762009-02-18 03:29:53 +0000641int rsl_chan_mode_modify_req(struct gsm_lchan *lchan)
642{
643 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200644 struct msgb *msg;
Harald Welte9943c5b2009-07-29 15:41:29 +0200645 int rc;
Harald Welteda783762009-02-18 03:29:53 +0000646
647 u_int8_t chan_nr = lchan2chan_nr(lchan);
648 struct rsl_ie_chan_mode cm;
649
Harald Welte9943c5b2009-07-29 15:41:29 +0200650 rc = channel_mode_from_lchan(&cm, lchan);
651 if (rc < 0)
652 return rc;
Harald Welteda783762009-02-18 03:29:53 +0000653
Harald Welteeab33352009-06-27 03:09:08 +0200654 msg = rsl_msgb_alloc();
Harald Welteda783762009-02-18 03:29:53 +0000655 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
656 init_dchan_hdr(dh, RSL_MT_MODE_MODIFY_REQ);
657 dh->chan_nr = chan_nr;
658
659 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
660 (u_int8_t *) &cm);
Harald Welte08d91a52009-08-30 15:37:11 +0900661
662 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
663 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
664 rc = build_encr_info(encr_info, lchan);
665 if (rc > 0)
666 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
667 }
668
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100669 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) {
670 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
671 (u_int8_t *) &lchan->mr_conf);
672 }
673
Harald Welte08d91a52009-08-30 15:37:11 +0900674 msg->trx = lchan->ts->trx;
675
676 return abis_rsl_sendmsg(msg);
677}
678
679/* Chapter 8.4.6: Send the encryption command with given L3 info */
680int rsl_encryption_cmd(struct msgb *msg)
681{
682 struct abis_rsl_dchan_hdr *dh;
683 struct gsm_lchan *lchan = msg->lchan;
684 u_int8_t chan_nr = lchan2chan_nr(lchan);
685 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
Sylvain Munaut82aa6842009-09-27 11:13:18 +0200686 u_int8_t l3_len = msg->len;
Harald Welte08d91a52009-08-30 15:37:11 +0900687 int rc;
688
689 /* First push the L3 IE tag and length */
690 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
691
692 /* then the link identifier (SAPI0, main sign link) */
693 msgb_tv_push(msg, RSL_IE_LINK_IDENT, 0);
694
695 /* then encryption information */
696 rc = build_encr_info(encr_info, lchan);
697 if (rc <= 0)
698 return rc;
699 msgb_tlv_push(msg, RSL_IE_ENCR_INFO, rc, encr_info);
700
701 /* and finally the DCHAN header */
702 dh = (struct abis_rsl_dchan_hdr *) msgb_push(msg, sizeof(*dh));
703 init_dchan_hdr(dh, RSL_MT_ENCR_CMD);
704 dh->chan_nr = chan_nr;
Harald Welteda783762009-02-18 03:29:53 +0000705
706 msg->trx = lchan->ts->trx;
707
708 return abis_rsl_sendmsg(msg);
709}
710
Harald Welte115d1032009-08-10 11:43:22 +0200711/* Chapter 8.4.5 / 4.6: Deactivate the SACCH after 04.08 RR CHAN RELEASE */
Harald Welteae0f2362009-07-19 18:36:49 +0200712int rsl_deact_sacch(struct gsm_lchan *lchan)
713{
714 struct abis_rsl_dchan_hdr *dh;
715 struct msgb *msg = rsl_msgb_alloc();
716
717 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
718 init_dchan_hdr(dh, RSL_MT_DEACTIVATE_SACCH);
719 dh->chan_nr = lchan2chan_nr(lchan);
720
721 msg->lchan = lchan;
722 msg->trx = lchan->ts->trx;
723
Harald Welte5b8ed432009-12-24 12:20:20 +0100724 DEBUGP(DRSL, "%s DEACTivate SACCH CMD\n", gsm_ts_name(lchan->ts));
Harald Welteae0f2362009-07-19 18:36:49 +0200725
726 return abis_rsl_sendmsg(msg);
727}
728
Harald Welte115d1032009-08-10 11:43:22 +0200729/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
730int rsl_rf_chan_release(struct gsm_lchan *lchan)
Harald Welte52b1f982008-12-23 20:25:15 +0000731{
732 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000733 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000734
735 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
736 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
Harald Welte8470bf22008-12-25 23:28:35 +0000737 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000738
Harald Welte8470bf22008-12-25 23:28:35 +0000739 msg->lchan = lchan;
740 msg->trx = lchan->ts->trx;
741
Harald Welte5b8ed432009-12-24 12:20:20 +0100742 DEBUGP(DRSL, "%s RF Channel Release CMD\n", gsm_ts_name(lchan->ts));
Harald Welte2d5b6382008-12-27 19:46:06 +0000743
Harald Welte115d1032009-08-10 11:43:22 +0200744 /* BTS will respond by RF CHAN REL ACK */
Harald Welte8470bf22008-12-25 23:28:35 +0000745 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000746}
747
748int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
749 u_int8_t *ms_ident, u_int8_t chan_needed)
750{
751 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000752 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000753
754 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
755 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
756 dh->chan_nr = RSL_CHAN_PCH_AGCH;
757
758 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
Harald Welte255539c2008-12-28 02:26:27 +0000759 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
Harald Welte52b1f982008-12-23 20:25:15 +0000760 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
761
Harald Welte8470bf22008-12-25 23:28:35 +0000762 msg->trx = bts->c0;
763
764 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000765}
766
Holger Freyther7448a532009-01-04 20:18:23 +0000767int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
768 struct gsm_subscriber *subscr)
769{
Holger Freytherca362a62009-01-04 21:05:01 +0000770#if 0
Holger Freyther7448a532009-01-04 20:18:23 +0000771 u_int8_t mi[128];
772 unsigned int mi_len;
773 u_int8_t paging_group;
Holger Freytherca362a62009-01-04 21:05:01 +0000774#endif
Holger Freyther7448a532009-01-04 20:18:23 +0000775
776 return -1;
777}
778
Harald Welte52b1f982008-12-23 20:25:15 +0000779int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
780{
781 int i, len = strlen(str_in);
782
783 for (i = 0; i < len; i++) {
784 int num = str_in[i] - 0x30;
785 if (num < 0 || num > 9)
786 return -1;
787 if (i % 2 == 0)
788 bcd_out[i/2] = num;
789 else
790 bcd_out[i/2] |= (num << 4);
791 }
792
793 return 0;
794}
795
Harald Welte702d8702008-12-26 20:25:35 +0000796/* Chapter 8.5.6 */
Harald Welte52b1f982008-12-23 20:25:15 +0000797int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
798{
Harald Welte8470bf22008-12-25 23:28:35 +0000799 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000800 struct abis_rsl_dchan_hdr *dh;
Harald Welte362322e2009-02-15 14:36:38 +0000801 u_int8_t buf[MACBLOCK_SIZE];
Harald Welte52b1f982008-12-23 20:25:15 +0000802
803 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
804 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
805 dh->chan_nr = RSL_CHAN_PCH_AGCH;
806
Harald Welte362322e2009-02-15 14:36:38 +0000807 switch (bts->type) {
808 case GSM_BTS_TYPE_BS11:
809 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
810 break;
811 default:
812 /* If phase 2, construct a FULL_IMM_ASS_INFO */
813 pad_macblock(buf, val, len);
814 msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf);
815 break;
816 }
Harald Welte52b1f982008-12-23 20:25:15 +0000817
Harald Welte8470bf22008-12-25 23:28:35 +0000818 msg->trx = bts->c0;
819
820 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000821}
822
Harald Welte67fa91b2009-08-10 09:51:40 +0200823/* Send Siemens specific MS RF Power Capability Indication */
Harald Welte31c48932009-08-10 10:07:33 +0200824int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci)
Harald Welte67fa91b2009-08-10 09:51:40 +0200825{
826 struct msgb *msg = rsl_msgb_alloc();
827 struct abis_rsl_dchan_hdr *dh;
828
829 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
830 init_dchan_hdr(dh, RSL_MT_SIEMENS_MRPCI);
Harald Welte3c456d02009-08-10 11:26:14 +0200831 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
Harald Welte67fa91b2009-08-10 09:51:40 +0200832 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte31c48932009-08-10 10:07:33 +0200833 msgb_tv_put(msg, RSL_IE_SIEMENS_MRPCI, *(u_int8_t *)mrpci);
Harald Welte67fa91b2009-08-10 09:51:40 +0200834
Harald Welte5b8ed432009-12-24 12:20:20 +0100835 DEBUGP(DRSL, "%s TX Siemens MRPCI 0x%02x\n",
836 gsm_ts_name(lchan->ts), *(u_int8_t *)mrpci);
Harald Welte3c456d02009-08-10 11:26:14 +0200837
838 msg->trx = lchan->ts->trx;
839
Harald Welte67fa91b2009-08-10 09:51:40 +0200840 return abis_rsl_sendmsg(msg);
841}
842
843
Harald Welte8470bf22008-12-25 23:28:35 +0000844/* Send "DATA REQUEST" message with given L3 Info payload */
Harald Welte52b1f982008-12-23 20:25:15 +0000845/* Chapter 8.3.1 */
Harald Welte8470bf22008-12-25 23:28:35 +0000846int rsl_data_request(struct msgb *msg, u_int8_t link_id)
Harald Welte52b1f982008-12-23 20:25:15 +0000847{
Harald Welte8470bf22008-12-25 23:28:35 +0000848 u_int8_t l3_len = msg->tail - (u_int8_t *)msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000849 struct abis_rsl_rll_hdr *rh;
850
Harald Welte8470bf22008-12-25 23:28:35 +0000851 if (msg->lchan == NULL) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100852 LOGP(DRSL, LOGL_ERROR, "cannot send DATA REQUEST to unknown lchan\n");
Harald Welte8470bf22008-12-25 23:28:35 +0000853 return -EINVAL;
854 }
Harald Welte52b1f982008-12-23 20:25:15 +0000855
Harald Welte8470bf22008-12-25 23:28:35 +0000856 /* First push the L3 IE tag and length */
Harald Welte4b634542008-12-27 01:55:51 +0000857 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
Harald Welte8470bf22008-12-25 23:28:35 +0000858
859 /* Then push the RSL header */
Harald Welte52b1f982008-12-23 20:25:15 +0000860 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
861 init_llm_hdr(rh, RSL_MT_DATA_REQ);
Harald Welte4a543e82009-02-28 13:17:55 +0000862 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
Harald Welte8470bf22008-12-25 23:28:35 +0000863 rh->chan_nr = lchan2chan_nr(msg->lchan);
864 rh->link_id = link_id;
Harald Welte52b1f982008-12-23 20:25:15 +0000865
Harald Welte8470bf22008-12-25 23:28:35 +0000866 msg->trx = msg->lchan->ts->trx;
867
868 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000869}
870
Harald Welteedcc5272009-08-09 13:47:35 +0200871/* Send "ESTABLISH REQUEST" message with given L3 Info payload */
872/* Chapter 8.3.1 */
873int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
874{
875 struct msgb *msg = rsl_msgb_alloc();
876 struct abis_rsl_rll_hdr *rh;
877
878 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
Harald Welte1c409272009-08-09 14:13:58 +0200879 init_llm_hdr(rh, RSL_MT_EST_REQ);
Harald Welteedcc5272009-08-09 13:47:35 +0200880 //rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
881 rh->chan_nr = lchan2chan_nr(lchan);
882 rh->link_id = link_id;
883
884 msg->trx = lchan->ts->trx;
885
886 return abis_rsl_sendmsg(msg);
887}
888
Harald Welted2dc1de2009-08-08 13:15:07 +0200889/* Chapter 8.3.7 Request the release of multiframe mode of RLL connection.
890 This is what higher layers should call. The BTS then responds with
891 RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
892 which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
893 lchan_free() */
894int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id)
895{
896 struct msgb *msg = rsl_msgb_alloc();
897 struct abis_rsl_rll_hdr *rh;
898
899 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
900 init_llm_hdr(rh, RSL_MT_REL_REQ);
901 //rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
902 rh->chan_nr = lchan2chan_nr(lchan);
903 rh->link_id = link_id;
Harald Welte6c3d2ed2009-08-10 00:19:36 +0200904 msgb_tv_put(msg, RSL_IE_RELEASE_MODE, 0); /* normal release */
Harald Welted2dc1de2009-08-08 13:15:07 +0200905
906 msg->trx = lchan->ts->trx;
907
908 return abis_rsl_sendmsg(msg);
909}
910
Harald Welte702d8702008-12-26 20:25:35 +0000911/* Chapter 8.4.2: Channel Activate Acknowledge */
912static int rsl_rx_chan_act_ack(struct msgb *msg)
913{
914 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
915
916 /* BTS has confirmed channel activation, we now need
917 * to assign the activated channel to the MS */
Harald Welte4b634542008-12-27 01:55:51 +0000918 if (rslh->ie_chan != RSL_IE_CHAN_NR)
919 return -EINVAL;
Harald Welted011e8b2009-11-29 22:45:52 +0100920
Harald Welteb8bfc562009-12-21 13:27:11 +0100921 msg->lchan->state = LCHAN_S_ACTIVE;
922
Harald Welted011e8b2009-11-29 22:45:52 +0100923 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_ACK, msg->lchan);
924
Harald Welte4b634542008-12-27 01:55:51 +0000925 return 0;
926}
Harald Welte702d8702008-12-26 20:25:35 +0000927
Harald Welte4b634542008-12-27 01:55:51 +0000928/* Chapter 8.4.3: Channel Activate NACK */
929static int rsl_rx_chan_act_nack(struct msgb *msg)
930{
Harald Welte6dab0552009-05-01 17:21:37 +0000931 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
932 struct tlv_parsed tp;
Harald Welte4b634542008-12-27 01:55:51 +0000933
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100934 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL ACTIVATE NACK",
935 gsm_ts_name(msg->lchan->ts));
936
Harald Welte6dab0552009-05-01 17:21:37 +0000937 /* BTS has rejected channel activation ?!? */
938 if (dh->ie_chan != RSL_IE_CHAN_NR)
Harald Welte4b634542008-12-27 01:55:51 +0000939 return -EINVAL;
Harald Welte6dab0552009-05-01 17:21:37 +0000940
941 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte (local)3e460312009-12-27 18:12:29 +0100942 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) {
943 const u_int8_t *cause = TLVP_VAL(&tp, RSL_IE_CAUSE);
944 print_rsl_cause(LOGL_ERROR, cause,
Harald Welte8830e072009-07-28 17:58:09 +0200945 TLVP_LEN(&tp, RSL_IE_CAUSE));
Harald Welte (local)3e460312009-12-27 18:12:29 +0100946 if (*cause != RSL_ERR_RCH_ALR_ACTV_ALLOC)
947 msg->lchan->state = LCHAN_S_NONE;
948 } else
949 msg->lchan->state = LCHAN_S_NONE;
950
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100951 LOGPC(DRSL, LOGL_ERROR, "\n");
952
Harald Welted011e8b2009-11-29 22:45:52 +0100953 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_NACK, msg->lchan);
954
Harald Welte3073a9f2009-08-09 19:50:08 +0200955 lchan_free(msg->lchan);
Harald Welte4b634542008-12-27 01:55:51 +0000956 return 0;
Harald Welte702d8702008-12-26 20:25:35 +0000957}
958
Harald Welte7f93cea2009-02-23 00:02:59 +0000959/* Chapter 8.4.4: Connection Failure Indication */
960static int rsl_rx_conn_fail(struct msgb *msg)
961{
962 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
963 struct tlv_parsed tp;
964
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100965 /* FIXME: print which channel */
Harald Welte (local)fc057502009-12-26 22:33:09 +0100966 LOGP(DRSL, LOGL_NOTICE, "%s CONNECTION FAIL: RELEASING ",
967 gsm_ts_name(msg->lchan->ts));
Harald Welte7f93cea2009-02-23 00:02:59 +0000968
969 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
970
Harald Welte8830e072009-07-28 17:58:09 +0200971 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +0100972 print_rsl_cause(LOGL_NOTICE, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +0200973 TLVP_LEN(&tp, RSL_IE_CAUSE));
974
Harald Welte (local)fc057502009-12-26 22:33:09 +0100975 LOGPC(DRSL, LOGL_NOTICE, "\n");
Harald Welte7f93cea2009-02-23 00:02:59 +0000976 /* FIXME: only free it after channel release ACK */
Harald Welte115d1032009-08-10 11:43:22 +0200977 return rsl_rf_chan_release(msg->lchan);
Harald Welte7f93cea2009-02-23 00:02:59 +0000978}
979
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100980static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
981 const char *prefix)
982{
Harald Welte6739dfb2009-12-16 16:52:07 +0100983 DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",
984 prefix, rxlev2dbm(mru->full.rx_lev),
985 prefix, rxlev2dbm(mru->sub.rx_lev));
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100986 DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",
987 prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);
988}
989
990static void print_meas_rep(struct gsm_meas_rep *mr)
991{
Harald Welte6739dfb2009-12-16 16:52:07 +0100992 int i;
993
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100994 DEBUGP(DMEAS, "MEASUREMENT RESULT NR=%d ", mr->nr);
995
996 if (mr->flags & MEAS_REP_F_DL_DTX)
997 DEBUGPC(DMEAS, "DTXd ");
998
999 print_meas_rep_uni(&mr->ul, "ul");
1000 DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
1001 if (mr->flags & MEAS_REP_F_MS_TO)
1002 DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
1003
1004 if (mr->flags & MEAS_REP_F_MS_L1) {
Harald Welte6739dfb2009-12-16 16:52:07 +01001005 DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001006 DEBUGPC(DMEAS, "L1_FPC=%u ",
1007 mr->flags & MEAS_REP_F_FPC ? 1 : 0);
1008 DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);
1009 }
1010
1011 if (mr->flags & MEAS_REP_F_UL_DTX)
1012 DEBUGPC(DMEAS, "DTXu ");
1013 if (mr->flags & MEAS_REP_F_BA1)
1014 DEBUGPC(DMEAS, "BA1 ");
1015 if (!(mr->flags & MEAS_REP_F_DL_VALID))
1016 DEBUGPC(DMEAS, "NOT VALID ");
1017 else
1018 print_meas_rep_uni(&mr->dl, "dl");
1019
1020 DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);
Harald Welte479015b2009-12-19 18:33:05 +01001021 if (mr->num_cell == 7)
1022 return;
Harald Welte6739dfb2009-12-16 16:52:07 +01001023 for (i = 0; i < mr->num_cell; i++) {
1024 struct gsm_meas_rep_cell *mrc = &mr->cell[i];
Harald Welte303e5e02009-12-25 23:02:22 +01001025 DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n",
1026 mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
Harald Welte6739dfb2009-12-16 16:52:07 +01001027 }
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001028}
1029
Harald Welte440fed02009-05-01 18:43:47 +00001030static int rsl_rx_meas_res(struct msgb *msg)
1031{
1032 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1033 struct tlv_parsed tp;
Harald Welted12b0fd2009-12-15 21:36:05 +01001034 struct gsm_meas_rep *mr = lchan_next_meas_rep(msg->lchan);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001035 u_int8_t len;
1036 const u_int8_t *val;
1037 int rc;
Harald Welte440fed02009-05-01 18:43:47 +00001038
Harald Welteb8bfc562009-12-21 13:27:11 +01001039 /* check if this channel is actually active */
1040 /* FIXME: maybe this check should be way more generic/centralized */
1041 if (msg->lchan->state != LCHAN_S_ACTIVE)
1042 return 0;
1043
Harald Welted12b0fd2009-12-15 21:36:05 +01001044 memset(mr, 0, sizeof(*mr));
Harald Welte33e65972009-12-16 23:29:34 +01001045 mr->lchan = msg->lchan;
Harald Weltedbb1d882009-11-30 19:16:47 +01001046
Harald Welte440fed02009-05-01 18:43:47 +00001047 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
1048
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001049 if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) ||
1050 !TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) ||
1051 !TLVP_PRESENT(&tp, RSL_IE_BS_POWER))
1052 return -EIO;
1053
1054 /* Mandatory Parts */
Harald Welted12b0fd2009-12-15 21:36:05 +01001055 mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001056
1057 len = TLVP_LEN(&tp, RSL_IE_UPLINK_MEAS);
1058 val = TLVP_VAL(&tp, RSL_IE_UPLINK_MEAS);
1059 if (len >= 3) {
1060 if (val[0] & 0x40)
Harald Welted12b0fd2009-12-15 21:36:05 +01001061 mr->flags |= MEAS_REP_F_DL_DTX;
1062 mr->ul.full.rx_lev = val[0] & 0x3f;
1063 mr->ul.sub.rx_lev = val[1] & 0x3f;
1064 mr->ul.full.rx_qual = val[2]>>3 & 0x7;
1065 mr->ul.sub.rx_qual = val[2] & 0x7;
Harald Welte440fed02009-05-01 18:43:47 +00001066 }
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001067
Harald Welted12b0fd2009-12-15 21:36:05 +01001068 mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001069
1070 /* Optional Parts */
Harald Welte440fed02009-05-01 18:43:47 +00001071 if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET))
Harald Welted12b0fd2009-12-15 21:36:05 +01001072 mr->ms_timing_offset =
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001073 *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET);
1074
Harald Weltefe9af262009-06-20 18:44:35 +02001075 if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) {
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001076 val = TLVP_VAL(&tp, RSL_IE_L1_INFO);
Harald Welted12b0fd2009-12-15 21:36:05 +01001077 mr->flags |= MEAS_REP_F_MS_L1;
1078 mr->ms_l1.pwr = ms_pwr_dbm(msg->trx->bts->band, val[0] >> 3);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001079 if (val[0] & 0x04)
Harald Welted12b0fd2009-12-15 21:36:05 +01001080 mr->flags |= MEAS_REP_F_FPC;
1081 mr->ms_l1.ta = val[1];
Harald Weltefe9af262009-06-20 18:44:35 +02001082 }
Harald Weltef7c43522009-06-09 20:24:21 +00001083 if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
Holger Hans Peter Freytherddd918f2009-10-22 15:43:55 +02001084 msg->l3h = (u_int8_t *) TLVP_VAL(&tp, RSL_IE_L3_INFO);
Harald Welted12b0fd2009-12-15 21:36:05 +01001085 rc = gsm48_parse_meas_rep(mr, msg);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001086 if (rc < 0)
1087 return rc;
1088 }
1089
Harald Welted12b0fd2009-12-15 21:36:05 +01001090 print_meas_rep(mr);
Harald Welte60d68f12009-06-05 20:07:43 +00001091
Harald Welted12b0fd2009-12-15 21:36:05 +01001092 dispatch_signal(SS_LCHAN, S_LCHAN_MEAS_REP, mr);
Harald Weltedbb1d882009-11-30 19:16:47 +01001093
Harald Welte75d34a82009-05-23 06:11:13 +00001094 return 0;
Harald Welte440fed02009-05-01 18:43:47 +00001095}
1096
Harald Welted011e8b2009-11-29 22:45:52 +01001097/* Chapter 8.4.7 */
1098static int rsl_rx_hando_det(struct msgb *msg)
1099{
1100 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1101 struct tlv_parsed tp;
1102
Harald Welte (local)fc057502009-12-26 22:33:09 +01001103 DEBUGP(DRSL, "%s HANDOVER DETECT ", gsm_ts_name(msg->lchan->ts));
Harald Welted011e8b2009-11-29 22:45:52 +01001104
1105 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
1106
1107 if (TLVP_PRESENT(&tp, RSL_IE_ACCESS_DELAY))
1108 DEBUGPC(DRSL, "access delay = %u\n",
1109 *TLVP_VAL(&tp, RSL_IE_ACCESS_DELAY));
1110 else
1111 DEBUGPC(DRSL, "\n");
1112
1113 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_DETECT, msg->lchan);
1114
1115 return 0;
1116}
1117
Harald Welte52b1f982008-12-23 20:25:15 +00001118static int abis_rsl_rx_dchan(struct msgb *msg)
1119{
Harald Welte8470bf22008-12-25 23:28:35 +00001120 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1121 int rc = 0;
Harald Weltef325eb42009-02-19 17:07:39 +00001122 char *ts_name;
Harald Welte52b1f982008-12-23 20:25:15 +00001123
Harald Welte8470bf22008-12-25 23:28:35 +00001124 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
Harald Weltef325eb42009-02-19 17:07:39 +00001125 ts_name = gsm_ts_name(msg->lchan->ts);
1126
Harald Welte8470bf22008-12-25 23:28:35 +00001127 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +00001128 case RSL_MT_CHAN_ACTIV_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001129 DEBUGP(DRSL, "%s CHANNEL ACTIVATE ACK\n", ts_name);
Harald Welte4b634542008-12-27 01:55:51 +00001130 rc = rsl_rx_chan_act_ack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001131 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001132 case RSL_MT_CHAN_ACTIV_NACK:
Harald Welte4b634542008-12-27 01:55:51 +00001133 rc = rsl_rx_chan_act_nack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001134 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001135 case RSL_MT_CONN_FAIL:
Harald Welte7f93cea2009-02-23 00:02:59 +00001136 rc = rsl_rx_conn_fail(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001137 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001138 case RSL_MT_MEAS_RES:
Harald Welte440fed02009-05-01 18:43:47 +00001139 rc = rsl_rx_meas_res(msg);
Harald Welte2d5b6382008-12-27 19:46:06 +00001140 break;
Harald Welted011e8b2009-11-29 22:45:52 +01001141 case RSL_MT_HANDO_DET:
1142 rc = rsl_rx_hando_det(msg);
1143 break;
Harald Welte2d5b6382008-12-27 19:46:06 +00001144 case RSL_MT_RF_CHAN_REL_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001145 DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name);
Harald Welteb8bfc562009-12-21 13:27:11 +01001146 msg->lchan->state = LCHAN_S_NONE;
Harald Welte2d5b6382008-12-27 19:46:06 +00001147 lchan_free(msg->lchan);
Harald Welte8470bf22008-12-25 23:28:35 +00001148 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001149 case RSL_MT_MODE_MODIFY_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001150 DEBUGP(DRSL, "%s CHANNEL MODE MODIFY ACK\n", ts_name);
Harald Welteda783762009-02-18 03:29:53 +00001151 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001152 case RSL_MT_MODE_MODIFY_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001153 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL MODE MODIFY NACK\n", ts_name);
Harald Welteda783762009-02-18 03:29:53 +00001154 break;
Harald Welte9c880c92009-10-24 10:29:22 +02001155 case RSL_MT_IPAC_PDCH_ACT_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001156 DEBUGPC(DRSL, "%s IPAC PDCH ACT ACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001157 break;
1158 case RSL_MT_IPAC_PDCH_ACT_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001159 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH ACT NACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001160 break;
1161 case RSL_MT_IPAC_PDCH_DEACT_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001162 DEBUGP(DRSL, "%s IPAC PDCH DEACT ACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001163 break;
1164 case RSL_MT_IPAC_PDCH_DEACT_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001165 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH DEACT NACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001166 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001167 case RSL_MT_PHY_CONTEXT_CONF:
1168 case RSL_MT_PREPROC_MEAS_RES:
Harald Welte52b1f982008-12-23 20:25:15 +00001169 case RSL_MT_TALKER_DET:
1170 case RSL_MT_LISTENER_DET:
1171 case RSL_MT_REMOTE_CODEC_CONF_REP:
1172 case RSL_MT_MR_CODEC_MOD_ACK:
1173 case RSL_MT_MR_CODEC_MOD_NACK:
1174 case RSL_MT_MR_CODEC_MOD_PER:
Harald Welte5b8ed432009-12-24 12:20:20 +01001175 LOGP(DRSL, LOGL_NOTICE, "%s Unimplemented Abis RSL DChan "
1176 "msg 0x%02x\n", ts_name, rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001177 break;
1178 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001179 LOGP(DRSL, LOGL_NOTICE, "%s unknown Abis RSL DChan msg 0x%02x\n",
1180 ts_name, rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001181 return -EINVAL;
1182 }
Harald Weltef325eb42009-02-19 17:07:39 +00001183
Harald Welte8470bf22008-12-25 23:28:35 +00001184 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001185}
1186
Harald Welte702d8702008-12-26 20:25:35 +00001187static int rsl_rx_error_rep(struct msgb *msg)
1188{
1189 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8830e072009-07-28 17:58:09 +02001190 struct tlv_parsed tp;
Harald Welte702d8702008-12-26 20:25:35 +00001191
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001192 LOGP(DRSL, LOGL_ERROR, "ERROR REPORT ");
Harald Welte8830e072009-07-28 17:58:09 +02001193
1194 rsl_tlv_parse(&tp, rslh->data, msgb_l2len(msg)-sizeof(*rslh));
1195
1196 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +01001197 print_rsl_cause(LOGL_ERROR, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +02001198 TLVP_LEN(&tp, RSL_IE_CAUSE));
1199
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001200 LOGPC(DRSL, LOGL_ERROR, "\n");
Harald Welte702d8702008-12-26 20:25:35 +00001201
1202 return 0;
1203}
1204
Harald Welte52b1f982008-12-23 20:25:15 +00001205static int abis_rsl_rx_trx(struct msgb *msg)
1206{
Harald Welte702d8702008-12-26 20:25:35 +00001207 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001208 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001209
1210 switch (rslh->msg_type) {
Harald Welte702d8702008-12-26 20:25:35 +00001211 case RSL_MT_ERROR_REPORT:
1212 rc = rsl_rx_error_rep(msg);
1213 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001214 case RSL_MT_RF_RES_IND:
1215 /* interference on idle channels of TRX */
Harald Welte3cf7c3f2009-05-01 18:28:00 +00001216 //DEBUGP(DRSL, "TRX: RF Interference Indication\n");
Harald Welte8f5e2392009-02-03 12:57:37 +00001217 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001218 case RSL_MT_OVERLOAD:
1219 /* indicate CCCH / ACCH / processor overload */
Harald Welte (local)b29b57a2009-12-27 16:54:47 +01001220 LOGP(DRSL, LOGL_ERROR, "(bts=%u, trx=%u) CCCH/ACCH/CPU Overload\n",
1221 msg->trx->bts->nr, msg->trx->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001222 break;
1223 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001224 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message "
1225 "type 0x%02x\n", rslh->msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001226 return -EINVAL;
1227 }
Harald Welte8470bf22008-12-25 23:28:35 +00001228 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001229}
1230
Harald Welteb7e81162009-08-10 00:26:10 +02001231/* If T3101 expires, we never received a response to IMMEDIATE ASSIGN */
1232static void t3101_expired(void *data)
1233{
1234 struct gsm_lchan *lchan = data;
1235
Harald Welte115d1032009-08-10 11:43:22 +02001236 rsl_rf_chan_release(lchan);
Harald Welteb7e81162009-08-10 00:26:10 +02001237}
1238
Harald Welte8470bf22008-12-25 23:28:35 +00001239/* MS has requested a channel on the RACH */
Harald Welte52b1f982008-12-23 20:25:15 +00001240static int rsl_rx_chan_rqd(struct msgb *msg)
1241{
Harald Welte702d8702008-12-26 20:25:35 +00001242 struct gsm_bts *bts = msg->trx->bts;
Harald Welte8470bf22008-12-25 23:28:35 +00001243 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
1244 struct gsm48_req_ref *rqd_ref;
Harald Welte52b1f982008-12-23 20:25:15 +00001245 struct gsm48_imm_ass ia;
Harald Welte8470bf22008-12-25 23:28:35 +00001246 enum gsm_chan_t lctype;
Harald Welte2cbe0922008-12-29 04:09:31 +00001247 enum gsm_chreq_reason_t chreq_reason;
Harald Welte8470bf22008-12-25 23:28:35 +00001248 struct gsm_lchan *lchan;
1249 u_int8_t rqd_ta;
Holger Freyther3186bf22008-12-29 06:23:49 +00001250 int ret;
Harald Welte8470bf22008-12-25 23:28:35 +00001251
Harald Welte52b1f982008-12-23 20:25:15 +00001252 u_int16_t arfcn;
1253 u_int8_t ts_number, subch;
1254
Harald Welte8470bf22008-12-25 23:28:35 +00001255 /* parse request reference to be used in immediate assign */
1256 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
1257 return -EINVAL;
1258
1259 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
1260
1261 /* parse access delay and use as TA */
1262 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
1263 return -EINVAL;
1264 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
1265
1266 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
1267 * request reference RA */
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001268 lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
1269 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
Harald Welte2cbe0922008-12-29 04:09:31 +00001270
Harald Welteffa55a42009-12-22 19:07:32 +01001271 counter_inc(bts->network->stats.chreq.total);
Harald Welte24ff6ee2009-12-22 00:41:05 +01001272
Harald Welte8470bf22008-12-25 23:28:35 +00001273 /* check availability / allocate channel */
1274 lchan = lchan_alloc(bts, lctype);
1275 if (!lchan) {
Harald Welte (local)2f5df852009-12-27 13:48:09 +01001276 LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n",
Harald Welte (local)ccd88452009-12-27 18:05:25 +01001277 msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra);
Harald Welteffa55a42009-12-22 19:07:32 +01001278 counter_inc(bts->network->stats.chreq.no_channel);
Harald Welte8470bf22008-12-25 23:28:35 +00001279 /* FIXME: send some kind of reject ?!? */
1280 return -ENOMEM;
1281 }
1282
Harald Welte (local)3e460312009-12-27 18:12:29 +01001283 lchan->state = LCHAN_S_ACT_REQ;
1284
Harald Welte8470bf22008-12-25 23:28:35 +00001285 ts_number = lchan->ts->nr;
1286 arfcn = lchan->ts->trx->arfcn;
1287 subch = lchan->nr;
Harald Welte52b1f982008-12-23 20:25:15 +00001288
Harald Welte08d91a52009-08-30 15:37:11 +09001289 lchan->encr.alg_id = RSL_ENC_ALG_A5(0); /* no encryption */
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001290 lchan->ms_power = ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
Harald Welte0b2124b2009-08-10 00:45:40 +02001291 lchan->bs_power = 0; /* 0dB reduction, output power = Pn */
Harald Welte9943c5b2009-07-29 15:41:29 +02001292 lchan->rsl_cmode = RSL_CMOD_SPD_SIGN;
Harald Welte196d0522009-08-28 23:28:28 +09001293 lchan->tch_mode = GSM48_CMODE_SIGN;
Harald Welte8d77b952009-12-17 00:31:10 +01001294 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta, 0);
Harald Welte52b1f982008-12-23 20:25:15 +00001295
1296 /* create IMMEDIATE ASSIGN 04.08 messge */
1297 memset(&ia, 0, sizeof(ia));
1298 ia.l2_plen = 0x2d;
1299 ia.proto_discr = GSM48_PDISC_RR;
1300 ia.msg_type = GSM48_MT_RR_IMM_ASS;
Harald Welte2d5b6382008-12-27 19:46:06 +00001301 ia.page_mode = GSM48_PM_SAME;
Harald Welte4b634542008-12-27 01:55:51 +00001302 ia.chan_desc.chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +00001303 ia.chan_desc.h0.h = 0;
1304 ia.chan_desc.h0.arfcn_high = arfcn >> 8;
1305 ia.chan_desc.h0.arfcn_low = arfcn & 0xff;
Harald Welte814c4b72009-07-21 20:55:56 +02001306 ia.chan_desc.h0.tsc = bts->tsc;
Harald Welte8470bf22008-12-25 23:28:35 +00001307 /* use request reference extracted from CHAN_RQD */
1308 memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref));
1309 ia.timing_advance = rqd_ta;
Harald Welte52b1f982008-12-23 20:25:15 +00001310 ia.mob_alloc_len = 0;
1311
Harald Welte5b8ed432009-12-24 12:20:20 +01001312 DEBUGP(DRSL, "%s Activating ARFCN(%u) SS(%u) lctype %s "
1313 "r=%s ra=0x%02x\n", gsm_ts_name(lchan->ts), arfcn, subch,
Harald Welte (local)ccd88452009-12-27 18:05:25 +01001314 gsm_lchant_name(lchan->type), gsm_chreq_name(chreq_reason),
Harald Welte4a543e82009-02-28 13:17:55 +00001315 rqd_ref->ra);
Harald Welte75a983f2008-12-27 21:34:06 +00001316
Harald Welteb7e81162009-08-10 00:26:10 +02001317 /* Start timer T3101 to wait for GSM48_MT_RR_PAG_RESP */
1318 lchan->T3101.cb = t3101_expired;
1319 lchan->T3101.data = lchan;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001320 bsc_schedule_timer(&lchan->T3101, bts->network->T3101, 0);
Holger Freyther3186bf22008-12-29 06:23:49 +00001321
Harald Welte52b1f982008-12-23 20:25:15 +00001322 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
Holger Freyther3186bf22008-12-29 06:23:49 +00001323 ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia);
1324
Harald Welte817f3c82008-12-30 14:57:59 +00001325 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +00001326}
1327
Harald Welteea280442009-02-02 22:29:56 +00001328/* MS has requested a channel on the RACH */
1329static int rsl_rx_ccch_load(struct msgb *msg)
1330{
1331 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1332 u_int16_t pg_buf_space;
Holger Freyther8c563cf2009-02-03 20:08:51 +00001333 u_int16_t rach_slot_count = -1;
1334 u_int16_t rach_busy_count = -1;
1335 u_int16_t rach_access_count = -1;
Harald Welteea280442009-02-02 22:29:56 +00001336
1337 switch (rslh->data[0]) {
1338 case RSL_IE_PAGING_LOAD:
1339 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
Holger Freyther392209c2009-02-10 00:06:19 +00001340 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
Harald Welteea280442009-02-02 22:29:56 +00001341 break;
1342 case RSL_IE_RACH_LOAD:
Holger Freyther8c563cf2009-02-03 20:08:51 +00001343 if (msg->data_len >= 7) {
1344 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
1345 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
1346 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
1347 }
Harald Welteea280442009-02-02 22:29:56 +00001348 break;
1349 default:
1350 break;
1351 }
1352
1353 return 0;
1354}
1355
Harald Welte52b1f982008-12-23 20:25:15 +00001356static int abis_rsl_rx_cchan(struct msgb *msg)
1357{
Harald Welteea280442009-02-02 22:29:56 +00001358 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001359 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001360
Harald Welte8470bf22008-12-25 23:28:35 +00001361 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
1362
1363 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +00001364 case RSL_MT_CHAN_RQD:
1365 /* MS has requested a channel on the RACH */
1366 rc = rsl_rx_chan_rqd(msg);
1367 break;
Harald Welteea280442009-02-02 22:29:56 +00001368 case RSL_MT_CCCH_LOAD_IND:
1369 /* current load on the CCCH */
1370 rc = rsl_rx_ccch_load(msg);
1371 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001372 case RSL_MT_DELETE_IND:
1373 /* CCCH overloaded, IMM_ASSIGN was dropped */
1374 case RSL_MT_CBCH_LOAD_IND:
1375 /* current load on the CBCH */
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001376 LOGP(DRSL, LOGL_NOTICE, "Unimplemented Abis RSL TRX message "
1377 "type 0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001378 break;
1379 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001380 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message type "
1381 "0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001382 return -EINVAL;
1383 }
Harald Welte8470bf22008-12-25 23:28:35 +00001384
1385 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001386}
1387
Harald Welte4b634542008-12-27 01:55:51 +00001388static int rsl_rx_rll_err_ind(struct msgb *msg)
1389{
1390 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1391 u_int8_t *rlm_cause = rllh->data;
1392
Harald Welte (local)73b82bb2009-12-26 22:40:22 +01001393 LOGP(DRLL, LOGL_ERROR, "%s ERROR INDICATION cause=0x%02x\n",
1394 gsm_ts_name(msg->lchan->ts), rlm_cause[1]);
Harald Welteedcc5272009-08-09 13:47:35 +02001395
1396 rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND);
Harald Welte4b634542008-12-27 01:55:51 +00001397
Harald Welte81543bc2009-07-04 09:40:05 +02001398 if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED)
Harald Welte115d1032009-08-10 11:43:22 +02001399 return rsl_rf_chan_release(msg->lchan);
Harald Welte81543bc2009-07-04 09:40:05 +02001400
Harald Welte4b634542008-12-27 01:55:51 +00001401 return 0;
1402}
Harald Weltef325eb42009-02-19 17:07:39 +00001403
Harald Welte52b1f982008-12-23 20:25:15 +00001404/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
1405 0x02, 0x06,
1406 0x01, 0x20,
1407 0x02, 0x00,
1408 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
1409
1410static int abis_rsl_rx_rll(struct msgb *msg)
1411{
1412 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Weltef325eb42009-02-19 17:07:39 +00001413 int rc = 0;
1414 char *ts_name;
Harald Welte (local)daef6062009-08-14 11:41:12 +02001415 u_int8_t sapi = rllh->link_id & 7;
Harald Welte8470bf22008-12-25 23:28:35 +00001416
1417 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Weltef325eb42009-02-19 17:07:39 +00001418 ts_name = gsm_ts_name(msg->lchan->ts);
Harald Welte5b8ed432009-12-24 12:20:20 +01001419 DEBUGP(DRLL, "%s SAPI=%u ", ts_name, sapi);
Harald Welte52b1f982008-12-23 20:25:15 +00001420
1421 switch (rllh->c.msg_type) {
1422 case RSL_MT_DATA_IND:
Harald Weltef325eb42009-02-19 17:07:39 +00001423 DEBUGPC(DRLL, "DATA INDICATION\n");
Harald Welte4a543e82009-02-28 13:17:55 +00001424 if (msgb_l2len(msg) >
1425 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1426 rllh->data[0] == RSL_IE_L3_INFO) {
1427 msg->l3h = &rllh->data[3];
Harald Welte (local)daef6062009-08-14 11:41:12 +02001428 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte4a543e82009-02-28 13:17:55 +00001429 }
Harald Welte52b1f982008-12-23 20:25:15 +00001430 break;
1431 case RSL_MT_EST_IND:
Harald Weltef325eb42009-02-19 17:07:39 +00001432 DEBUGPC(DRLL, "ESTABLISH INDICATION\n");
Harald Welteb7e81162009-08-10 00:26:10 +02001433 /* lchan is established, stop T3101 */
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001434 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_MS;
Harald Welteb7e81162009-08-10 00:26:10 +02001435 bsc_del_timer(&msg->lchan->T3101);
Harald Welte4a543e82009-02-28 13:17:55 +00001436 if (msgb_l2len(msg) >
1437 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1438 rllh->data[0] == RSL_IE_L3_INFO) {
1439 msg->l3h = &rllh->data[3];
Harald Welte (local)daef6062009-08-14 11:41:12 +02001440 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte4a543e82009-02-28 13:17:55 +00001441 }
Harald Welte52b1f982008-12-23 20:25:15 +00001442 break;
Harald Welteedcc5272009-08-09 13:47:35 +02001443 case RSL_MT_EST_CONF:
Harald Welte1c409272009-08-09 14:13:58 +02001444 DEBUGPC(DRLL, "ESTABLISH CONFIRM\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001445 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_NET;
Harald Welteedcc5272009-08-09 13:47:35 +02001446 rll_indication(msg->lchan, rllh->link_id,
1447 BSC_RLLR_IND_EST_CONF);
1448 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001449 case RSL_MT_REL_IND:
Harald Welted2dc1de2009-08-08 13:15:07 +02001450 /* BTS informs us of having received DISC from MS */
Harald Welte602f2b82009-08-04 02:50:21 +02001451 DEBUGPC(DRLL, "RELEASE INDICATION\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001452 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welteedcc5272009-08-09 13:47:35 +02001453 rll_indication(msg->lchan, rllh->link_id,
1454 BSC_RLLR_IND_REL_IND);
Harald Welted2dc1de2009-08-08 13:15:07 +02001455 /* we can now releae the channel on the BTS/Abis side */
Harald Welte115d1032009-08-10 11:43:22 +02001456 /* FIXME: officially we need to start T3111 and wait for
1457 * some grace period */
1458 rsl_rf_chan_release(msg->lchan);
Harald Welte2d5b6382008-12-27 19:46:06 +00001459 break;
1460 case RSL_MT_REL_CONF:
Harald Welted2dc1de2009-08-08 13:15:07 +02001461 /* BTS informs us of having received UA from MS,
1462 * in response to DISC that we've sent earlier */
Harald Welte602f2b82009-08-04 02:50:21 +02001463 DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001464 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welted2dc1de2009-08-08 13:15:07 +02001465 /* we can now releae the channel on the BTS/Abis side */
Harald Welte115d1032009-08-10 11:43:22 +02001466 /* FIXME: officially we need to start T3111 and wait for
1467 * some grace period */
1468 rsl_rf_chan_release(msg->lchan);
Harald Welte4b634542008-12-27 01:55:51 +00001469 break;
1470 case RSL_MT_ERROR_IND:
1471 rc = rsl_rx_rll_err_ind(msg);
1472 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001473 case RSL_MT_UNIT_DATA_IND:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001474 LOGP(DRLL, LOGL_NOTICE, "unimplemented Abis RLL message "
1475 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001476 break;
1477 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001478 LOGP(DRLL, LOGL_NOTICE, "unknown Abis RLL message "
1479 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001480 }
Harald Welte8470bf22008-12-25 23:28:35 +00001481 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001482}
1483
Harald Welte0603c9d2009-12-02 01:58:23 +05301484static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
Harald Weltef4e79f22009-07-28 18:11:56 +02001485{
Harald Welte0603c9d2009-12-02 01:58:23 +05301486 switch (lchan->tch_mode) {
Harald Weltef4e79f22009-07-28 18:11:56 +02001487 case GSM48_CMODE_SPEECH_V1:
Harald Welte0603c9d2009-12-02 01:58:23 +05301488 switch (lchan->type) {
1489 case GSM_LCHAN_TCH_F:
1490 return 0x00;
1491 case GSM_LCHAN_TCH_H:
1492 return 0x03;
1493 default:
1494 break;
1495 }
Harald Weltef4e79f22009-07-28 18:11:56 +02001496 case GSM48_CMODE_SPEECH_EFR:
Harald Welte0603c9d2009-12-02 01:58:23 +05301497 switch (lchan->type) {
1498 case GSM_LCHAN_TCH_F:
1499 return 0x01;
1500 /* there's no half-rate EFR */
1501 default:
1502 break;
1503 }
Harald Weltef4e79f22009-07-28 18:11:56 +02001504 case GSM48_CMODE_SPEECH_AMR:
Harald Welte0603c9d2009-12-02 01:58:23 +05301505 switch (lchan->type) {
1506 case GSM_LCHAN_TCH_F:
1507 return 0x02;
1508 case GSM_LCHAN_TCH_H:
1509 return 0x05;
1510 default:
1511 break;
1512 }
1513 default:
1514 break;
Harald Weltef4e79f22009-07-28 18:11:56 +02001515 }
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001516 LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access speech mode for "
Harald Welte0603c9d2009-12-02 01:58:23 +05301517 "tch_mode == 0x%02x\n", lchan->tch_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001518 return 0;
Harald Weltef4e79f22009-07-28 18:11:56 +02001519}
1520
Harald Welte75099262009-02-16 21:12:08 +00001521/* ip.access specific RSL extensions */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001522static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
1523{
1524 struct in_addr ip;
1525 u_int16_t port, conn_id;
1526
1527 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_IP)) {
1528 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_IP));
1529 DEBUGPC(DRSL, "LOCAL_IP=%s ", inet_ntoa(ip));
1530 lchan->abis_ip.bound_ip = ntohl(ip.s_addr);
1531 }
1532
1533 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_PORT)) {
1534 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_PORT));
1535 port = ntohs(port);
1536 DEBUGPC(DRSL, "LOCAL_PORT=%u ", port);
1537 lchan->abis_ip.bound_port = port;
1538 }
1539
1540 if (TLVP_PRESENT(tv, RSL_IE_IPAC_CONN_ID)) {
1541 conn_id = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_CONN_ID));
1542 conn_id = ntohs(conn_id);
1543 DEBUGPC(DRSL, "CON_ID=%u ", conn_id);
1544 lchan->abis_ip.conn_id = conn_id;
1545 }
1546
1547 if (TLVP_PRESENT(tv, RSL_IE_IPAC_RTP_PAYLOAD2)) {
1548 lchan->abis_ip.rtp_payload2 =
1549 *TLVP_VAL(tv, RSL_IE_IPAC_RTP_PAYLOAD2);
1550 DEBUGPC(DRSL, "RTP_PAYLOAD2=0x%02x ",
1551 lchan->abis_ip.rtp_payload2);
1552 }
1553
1554 if (TLVP_PRESENT(tv, RSL_IE_IPAC_SPEECH_MODE)) {
1555 lchan->abis_ip.speech_mode =
1556 *TLVP_VAL(tv, RSL_IE_IPAC_SPEECH_MODE);
1557 DEBUGPC(DRSL, "speech_mode=0x%02x ",
1558 lchan->abis_ip.speech_mode);
1559 }
1560
1561 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_IP)) {
1562 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_IP));
1563 DEBUGPC(DRSL, "REMOTE_IP=%s ", inet_ntoa(ip));
1564 lchan->abis_ip.connect_ip = ntohl(ip.s_addr);
1565 }
1566
1567 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_PORT)) {
1568 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_PORT));
1569 port = ntohs(port);
1570 DEBUGPC(DRSL, "REMOTE_PORT=%u ", port);
1571 lchan->abis_ip.connect_port = port;
1572 }
1573}
1574
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001575int rsl_ipacc_crcx(struct gsm_lchan *lchan)
Harald Welte75099262009-02-16 21:12:08 +00001576{
1577 struct msgb *msg = rsl_msgb_alloc();
1578 struct abis_rsl_dchan_hdr *dh;
1579
1580 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001581 init_dchan_hdr(dh, RSL_MT_IPAC_CRCX);
Harald Welte75099262009-02-16 21:12:08 +00001582 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1583 dh->chan_nr = lchan2chan_nr(lchan);
1584
Harald Weltef4e79f22009-07-28 18:11:56 +02001585 /* 0x1- == receive-only, 0x-1 == EFR codec */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001586 lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
1587 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001588
Harald Welte5b8ed432009-12-24 12:20:20 +01001589 DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x\n",
1590 gsm_ts_name(lchan->ts), lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001591
Harald Welte75099262009-02-16 21:12:08 +00001592 msg->trx = lchan->ts->trx;
1593
1594 return abis_rsl_sendmsg(msg);
1595}
1596
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001597int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
Harald Welte5e3d91b2009-12-19 16:42:06 +01001598 u_int8_t rtp_payload2)
Harald Welte75099262009-02-16 21:12:08 +00001599{
1600 struct msgb *msg = rsl_msgb_alloc();
1601 struct abis_rsl_dchan_hdr *dh;
Harald Welte5e3d91b2009-12-19 16:42:06 +01001602 u_int32_t *att_ip;
Harald Weltef4e79f22009-07-28 18:11:56 +02001603 struct in_addr ia;
Harald Welte75099262009-02-16 21:12:08 +00001604
1605 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001606 init_dchan_hdr(dh, RSL_MT_IPAC_MDCX);
Harald Welte75099262009-02-16 21:12:08 +00001607 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1608 dh->chan_nr = lchan2chan_nr(lchan);
1609
Harald Welte5e3d91b2009-12-19 16:42:06 +01001610 /* we need to store these now as MDCX_ACK does not return them :( */
1611 lchan->abis_ip.rtp_payload2 = rtp_payload2;
1612 lchan->abis_ip.connect_port = port;
1613 lchan->abis_ip.connect_ip = ip;
1614
Harald Welte58ca5b72009-07-29 12:12:18 +02001615 /* 0x0- == both directions, 0x-1 == EFR codec */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001616 lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
Harald Welte58ca5b72009-07-29 12:12:18 +02001617
Harald Weltef4e79f22009-07-28 18:11:56 +02001618 ia.s_addr = htonl(ip);
Harald Welte5b8ed432009-12-24 12:20:20 +01001619 DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD2=%d CONN_ID=%d "
1620 "speech_mode=0x%02x\n", gsm_ts_name(lchan->ts), inet_ntoa(ia), port,
Harald Welte5e3d91b2009-12-19 16:42:06 +01001621 rtp_payload2, lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001622
Harald Welte5e3d91b2009-12-19 16:42:06 +01001623 msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
1624 msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
1625 att_ip = (u_int32_t *) msgb_put(msg, sizeof(ip));
1626 *att_ip = ia.s_addr;
1627 msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
1628 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001629 if (rtp_payload2)
1630 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
1631
Harald Welte75099262009-02-16 21:12:08 +00001632 msg->trx = lchan->ts->trx;
1633
1634 return abis_rsl_sendmsg(msg);
1635}
1636
Harald Weltea72273e2009-12-20 16:51:09 +01001637/* tell BTS to connect RTP stream to our local RTP socket */
1638int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan)
1639{
1640 struct rtp_socket *rs = lchan->abis_ip.rtp_socket;
1641 int rc;
1642
1643 rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr),
1644 ntohs(rs->rtp.sin_local.sin_port),
1645 /* FIXME: use RTP payload of bound socket, not BTS*/
1646 lchan->abis_ip.rtp_payload2);
1647
1648 return rc;
1649}
1650
Harald Welte9c880c92009-10-24 10:29:22 +02001651int rsl_ipacc_pdch_activate(struct gsm_lchan *lchan)
1652{
1653 struct msgb *msg = rsl_msgb_alloc();
1654 struct abis_rsl_dchan_hdr *dh;
1655
1656 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
1657 init_dchan_hdr(dh, RSL_MT_IPAC_PDCH_ACT);
1658 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
1659 dh->chan_nr = lchan2chan_nr(lchan);
1660
Harald Welte5b8ed432009-12-24 12:20:20 +01001661 DEBUGP(DRSL, "%s IPAC_PDCH_ACT\n", gsm_ts_name(lchan->ts));
Harald Welte9c880c92009-10-24 10:29:22 +02001662
1663 msg->trx = lchan->ts->trx;
1664
1665 return abis_rsl_sendmsg(msg);
1666}
1667
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001668static int abis_rsl_rx_ipacc_crcx_ack(struct msgb *msg)
Harald Welte75099262009-02-16 21:12:08 +00001669{
1670 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1671 struct tlv_parsed tv;
Harald Welte2c828992009-12-02 01:56:49 +05301672 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75099262009-02-16 21:12:08 +00001673
1674 /* the BTS has acknowledged a local bind, it now tells us the IP
1675 * address and port number to which it has bound the given logical
1676 * channel */
1677
1678 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1679 if (!TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_PORT) ||
1680 !TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_IP) ||
Harald Welte86c162d2009-07-12 09:45:05 +02001681 !TLVP_PRESENT(&tv, RSL_IE_IPAC_CONN_ID)) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001682 LOGP(DRSL, LOGL_NOTICE, "mandatory IE missing");
Harald Welte75099262009-02-16 21:12:08 +00001683 return -EINVAL;
1684 }
Harald Welte17f5bf62009-12-20 15:42:44 +01001685
Harald Welte5e3d91b2009-12-19 16:42:06 +01001686 ipac_parse_rtp(lchan, &tv);
Harald Welte17f5bf62009-12-20 15:42:44 +01001687
1688 /* in case we don't use direct BTS-to-BTS RTP */
1689 if (!ipacc_rtp_direct) {
1690 int rc;
1691 /* the BTS has successfully bound a TCH to a local ip/port,
1692 * which means we can connect our UDP socket to it */
1693 if (lchan->abis_ip.rtp_socket) {
1694 rtp_socket_free(lchan->abis_ip.rtp_socket);
1695 lchan->abis_ip.rtp_socket = NULL;
1696 }
1697
1698 lchan->abis_ip.rtp_socket = rtp_socket_create();
1699 if (!lchan->abis_ip.rtp_socket)
1700 goto out_err;
1701
1702 rc = rtp_socket_connect(lchan->abis_ip.rtp_socket,
1703 lchan->abis_ip.bound_ip,
1704 lchan->abis_ip.bound_port);
1705 if (rc < 0)
1706 goto out_err;
1707 }
1708
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001709 dispatch_signal(SS_ABISIP, S_ABISIP_CRCX_ACK, msg->lchan);
Harald Welte167df882009-02-17 14:35:45 +00001710
Harald Welte75099262009-02-16 21:12:08 +00001711 return 0;
Harald Welte17f5bf62009-12-20 15:42:44 +01001712out_err:
1713 return -EIO;
Harald Welte75099262009-02-16 21:12:08 +00001714}
1715
Harald Welte5e3d91b2009-12-19 16:42:06 +01001716static int abis_rsl_rx_ipacc_mdcx_ack(struct msgb *msg)
1717{
1718 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1719 struct tlv_parsed tv;
1720 struct gsm_lchan *lchan = msg->lchan;
1721
1722 /* the BTS has acknowledged a remote connect request and
1723 * it now tells us the IP address and port number to which it has
1724 * connected the given logical channel */
1725
1726 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1727 ipac_parse_rtp(lchan, &tv);
1728 dispatch_signal(SS_ABISIP, S_ABISIP_MDCX_ACK, msg->lchan);
1729
1730 return 0;
1731}
1732
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001733static int abis_rsl_rx_ipacc_dlcx_ind(struct msgb *msg)
Harald Welte75099262009-02-16 21:12:08 +00001734{
1735 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1736 struct tlv_parsed tv;
Harald Welte17f5bf62009-12-20 15:42:44 +01001737 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75099262009-02-16 21:12:08 +00001738
1739 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte75099262009-02-16 21:12:08 +00001740
Harald Welte8830e072009-07-28 17:58:09 +02001741 if (TLVP_PRESENT(&tv, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +01001742 print_rsl_cause(LOGL_DEBUG, TLVP_VAL(&tv, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +02001743 TLVP_LEN(&tv, RSL_IE_CAUSE));
Harald Welte75099262009-02-16 21:12:08 +00001744
Harald Welte17f5bf62009-12-20 15:42:44 +01001745 /* the BTS tells us a RTP stream has been disconnected */
1746 if (lchan->abis_ip.rtp_socket) {
1747 rtp_socket_free(lchan->abis_ip.rtp_socket);
1748 lchan->abis_ip.rtp_socket = NULL;
1749 }
1750
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001751 dispatch_signal(SS_ABISIP, S_ABISIP_DLCX_IND, msg->lchan);
Harald Welte888b1142009-07-28 18:02:05 +02001752
Harald Welte75099262009-02-16 21:12:08 +00001753 return 0;
1754}
1755
1756static int abis_rsl_rx_ipacc(struct msgb *msg)
1757{
1758 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Welte5b8ed432009-12-24 12:20:20 +01001759 char *ts_name;
Harald Welte75099262009-02-16 21:12:08 +00001760 int rc = 0;
1761
1762 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte5b8ed432009-12-24 12:20:20 +01001763 ts_name = gsm_ts_name(msg->lchan->ts);
Harald Welte75099262009-02-16 21:12:08 +00001764
1765 switch (rllh->c.msg_type) {
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001766 case RSL_MT_IPAC_CRCX_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001767 DEBUGP(DRSL, "%s IPAC_CRCX_ACK ", ts_name);
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001768 rc = abis_rsl_rx_ipacc_crcx_ack(msg);
Harald Welte75099262009-02-16 21:12:08 +00001769 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001770 case RSL_MT_IPAC_CRCX_NACK:
Harald Welte75099262009-02-16 21:12:08 +00001771 /* somehow the BTS was unable to bind the lchan to its local
1772 * port?!? */
Harald Welte5b8ed432009-12-24 12:20:20 +01001773 LOGP(DRSL, LOGL_ERROR, "%s IPAC_CRCX_NACK\n", ts_name);
Harald Welte75099262009-02-16 21:12:08 +00001774 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001775 case RSL_MT_IPAC_MDCX_ACK:
Harald Welte75099262009-02-16 21:12:08 +00001776 /* the BTS tells us that a connect operation was successful */
Harald Welte5b8ed432009-12-24 12:20:20 +01001777 DEBUGP(DRSL, "%s IPAC_MDCX_ACK ", ts_name);
Harald Welte5e3d91b2009-12-19 16:42:06 +01001778 rc = abis_rsl_rx_ipacc_mdcx_ack(msg);
Harald Welte75099262009-02-16 21:12:08 +00001779 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001780 case RSL_MT_IPAC_MDCX_NACK:
Harald Welte75099262009-02-16 21:12:08 +00001781 /* somehow the BTS was unable to connect the lchan to a remote
1782 * port */
Harald Welte5b8ed432009-12-24 12:20:20 +01001783 LOGP(DRSL, LOGL_ERROR, "%s IPAC_MDCX_NACK\n", ts_name);
Harald Welte75099262009-02-16 21:12:08 +00001784 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001785 case RSL_MT_IPAC_DLCX_IND:
Harald Welte5b8ed432009-12-24 12:20:20 +01001786 DEBUGP(DRSL, "%s IPAC_DLCX_IND ", ts_name);
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001787 rc = abis_rsl_rx_ipacc_dlcx_ind(msg);
Harald Welte75099262009-02-16 21:12:08 +00001788 break;
1789 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001790 LOGP(DRSL, LOGL_NOTICE, "Unknown ip.access msg_type 0x%02x\n",
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001791 rllh->c.msg_type);
Harald Welte75099262009-02-16 21:12:08 +00001792 break;
1793 }
Harald Welte6dab0552009-05-01 17:21:37 +00001794 DEBUGPC(DRSL, "\n");
Harald Welte75099262009-02-16 21:12:08 +00001795
1796 return rc;
1797}
1798
1799
Harald Welte52b1f982008-12-23 20:25:15 +00001800/* Entry-point where L2 RSL from BTS enters */
Harald Welte8470bf22008-12-25 23:28:35 +00001801int abis_rsl_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001802{
1803 struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
Harald Welte8f5e2392009-02-03 12:57:37 +00001804 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001805
1806 switch (rslh->msg_discr & 0xfe) {
1807 case ABIS_RSL_MDISC_RLL:
1808 rc = abis_rsl_rx_rll(msg);
1809 break;
1810 case ABIS_RSL_MDISC_DED_CHAN:
1811 rc = abis_rsl_rx_dchan(msg);
1812 break;
1813 case ABIS_RSL_MDISC_COM_CHAN:
Harald Welte52b1f982008-12-23 20:25:15 +00001814 rc = abis_rsl_rx_cchan(msg);
1815 break;
Harald Welte8470bf22008-12-25 23:28:35 +00001816 case ABIS_RSL_MDISC_TRX:
1817 rc = abis_rsl_rx_trx(msg);
1818 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001819 case ABIS_RSL_MDISC_LOC:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001820 LOGP(DRSL, LOGL_NOTICE, "unimplemented RSL msg disc 0x%02x\n",
Harald Welte8f5e2392009-02-03 12:57:37 +00001821 rslh->msg_discr);
1822 break;
Harald Welte75099262009-02-16 21:12:08 +00001823 case ABIS_RSL_MDISC_IPACCESS:
1824 rc = abis_rsl_rx_ipacc(msg);
1825 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001826 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001827 LOGP(DRSL, LOGL_NOTICE, "unknown RSL message discriminator "
1828 "0x%02x\n", rslh->msg_discr);
Harald Welte52b1f982008-12-23 20:25:15 +00001829 return -EINVAL;
1830 }
Harald Welte4f4a3902008-12-26 00:04:49 +00001831 msgb_free(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001832 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001833}
Holger Freyther3b72a892009-02-04 00:31:39 +00001834
1835
Holger Hans Peter Freyther3d571832009-07-09 20:43:16 +02001836/* Section 3.3.2.3 TS 05.02. I think this looks like a table */
Holger Freyther3b72a892009-02-04 00:31:39 +00001837int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
1838{
1839 switch (ccch_conf) {
1840 case RSL_BCCH_CCCH_CONF_1_NC:
1841 return 1;
1842 case RSL_BCCH_CCCH_CONF_1_C:
1843 return 1;
1844 case RSL_BCCH_CCCH_CONF_2_NC:
1845 return 2;
1846 case RSL_BCCH_CCCH_CONF_3_NC:
1847 return 3;
1848 case RSL_BCCH_CCCH_CONF_4_NC:
1849 return 4;
1850 default:
1851 return -1;
1852 }
1853}
1854
Holger Hans Peter Freyther3d571832009-07-09 20:43:16 +02001855/* Section 3.3.2.3 TS 05.02 */
Holger Freyther3b72a892009-02-04 00:31:39 +00001856int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
1857{
1858 switch (ccch_conf) {
1859 case RSL_BCCH_CCCH_CONF_1_NC:
1860 return 0;
1861 case RSL_BCCH_CCCH_CONF_1_C:
1862 return 1;
1863 case RSL_BCCH_CCCH_CONF_2_NC:
1864 return 0;
1865 case RSL_BCCH_CCCH_CONF_3_NC:
1866 return 0;
1867 case RSL_BCCH_CCCH_CONF_4_NC:
1868 return 0;
1869 default:
1870 return -1;
1871 }
1872}
1873
1874/* From Table 10.5.33 of GSM 04.08 */
1875int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
1876{
Harald Weltea43f7892009-12-01 18:04:30 +05301877 if (bts->si_common.chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
1878 return MAX(1, (3 - bts->si_common.chan_desc.bs_ag_blks_res))
1879 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +00001880 } else {
Harald Weltea43f7892009-12-01 18:04:30 +05301881 return (9 - bts->si_common.chan_desc.bs_ag_blks_res)
1882 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +00001883 }
1884}