blob: 6f13b4b30cc9cb35c24127e0ca355662b2ac5792 [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
Harald Welte (local)9538efc2009-12-26 23:55:00 +0100373static 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 Welte8830e072009-07-28 17:58:09 +0200391static const char *rsl_err_name(u_int8_t err)
Harald Welte7f93cea2009-02-23 00:02:59 +0000392{
Harald Welte8830e072009-07-28 17:58:09 +0200393 if (rsl_err_vals[err])
394 return rsl_err_vals[err];
395 else
396 return "unknown";
397}
398
Harald Welte5b8ed432009-12-24 12:20:20 +0100399static void print_rsl_cause(int lvl, const u_int8_t *cause_v, u_int8_t cause_len)
Harald Welte8830e072009-07-28 17:58:09 +0200400{
Harald Welte7f93cea2009-02-23 00:02:59 +0000401 int i;
402
Harald Welte5b8ed432009-12-24 12:20:20 +0100403 LOGPC(DRSL, lvl, "CAUSE=0x%02x(%s) ",
Harald Welte8830e072009-07-28 17:58:09 +0200404 cause_v[0], rsl_err_name(cause_v[0]));
405 for (i = 1; i < cause_len-1; i++)
Harald Welte5b8ed432009-12-24 12:20:20 +0100406 LOGPC(DRSL, lvl, "%02x ", cause_v[i]);
Harald Welte7f93cea2009-02-23 00:02:59 +0000407}
408
Harald Welte52b1f982008-12-23 20:25:15 +0000409/* Send a BCCH_INFO message as per Chapter 8.5.1 */
Harald Weltee79769b2009-02-07 00:48:17 +0000410int rsl_bcch_info(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_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000414 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000415
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 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 Weltee79769b2009-02-07 00:48:17 +0000428int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000429 const u_int8_t *data, int len)
430{
431 struct abis_rsl_common_hdr *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000432 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000433
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 Welte702d8702008-12-26 20:25:35 +0000439 msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data);
Harald Welte52b1f982008-12-23 20:25:15 +0000440
Harald Weltee79769b2009-02-07 00:48:17 +0000441 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000442
443 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000444}
445
Harald Weltefcd24452009-06-20 18:15:19 +0200446int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db)
447{
448 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200449 struct msgb *msg;
Harald Weltefcd24452009-06-20 18:15:19 +0200450 u_int8_t chan_nr = lchan2chan_nr(lchan);
451
452 db = abs(db);
453 if (db > 30)
454 return -EINVAL;
455
Harald Welteeab33352009-06-27 03:09:08 +0200456 msg = rsl_msgb_alloc();
457
Harald Weltefcd24452009-06-20 18:15:19 +0200458 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 Weltefcd24452009-06-20 18:15:19 +0200473int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm)
474{
475 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200476 struct msgb *msg;
Harald Weltefcd24452009-06-20 18:15:19 +0200477 u_int8_t chan_nr = lchan2chan_nr(lchan);
478 int ctl_lvl;
479
Harald Welte66b6a8d2009-08-09 14:45:18 +0200480 ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm);
Harald Weltefcd24452009-06-20 18:15:19 +0200481 if (ctl_lvl < 0)
482 return ctl_lvl;
483
Harald Welteeab33352009-06-27 03:09:08 +0200484 msg = rsl_msgb_alloc();
485
Harald Weltefcd24452009-06-20 18:15:19 +0200486 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 Welte9943c5b2009-07-29 15:41:29 +0200502static 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 Welte1a79d362009-11-27 08:55:16 +0100513 if (lchan->rsl_cmode == RSL_CMOD_SPD_SIGN &&
514 lchan->tch_mode != GSM48_CMODE_SIGN)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100515 LOGP(DRSL, LOGL_ERROR, "unsupported: rsl_mode == signalling, "
Harald Welte1a79d362009-11-27 08:55:16 +0100516 "but tch_mode != signalling\n");
517
Harald Welte9943c5b2009-07-29 15:41:29 +0200518 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 Welte52b1f982008-12-23 20:25:15 +0000563/* Chapter 8.4.1 */
Harald Welteddab3c72009-02-28 13:19:15 +0000564#if 0
Harald Weltee79769b2009-02-07 00:48:17 +0000565int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
Harald Welte52b1f982008-12-23 20:25:15 +0000566 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 Welte8470bf22008-12-25 23:28:35 +0000573 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000574
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 Welte702d8702008-12-26 20:25:35 +0000584 (u_int8_t *) chan_ident);
Harald Welte702d8702008-12-26 20:25:35 +0000585#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000586 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
587 (u_int8_t *) &encr_info);
Harald Welte702d8702008-12-26 20:25:35 +0000588#endif
Harald Welted4c9bf32009-02-15 16:56:18 +0000589 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
Harald Welte52b1f982008-12-23 20:25:15 +0000590 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
591 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
592
Harald Weltee79769b2009-02-07 00:48:17 +0000593 msg->trx = trx;
594
Harald Welte8470bf22008-12-25 23:28:35 +0000595 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000596}
Harald Welteddab3c72009-02-28 13:19:15 +0000597#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000598
Harald Welte8f5e2392009-02-03 12:57:37 +0000599int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
Harald Welte8d77b952009-12-17 00:31:10 +0100600 u_int8_t ta, u_int8_t ho_ref)
Harald Welte4b634542008-12-27 01:55:51 +0000601{
602 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200603 struct msgb *msg;
Harald Welte9943c5b2009-07-29 15:41:29 +0200604 int rc;
Harald Welte4b634542008-12-27 01:55:51 +0000605
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 Welte9943c5b2009-07-29 15:41:29 +0200611 rc = channel_mode_from_lchan(&cm, lchan);
612 if (rc < 0)
613 return rc;
Harald Welte4b634542008-12-27 01:55:51 +0000614
Harald Welte02b0e092009-02-28 13:11:07 +0000615 memset(&ci, 0, sizeof(ci));
Harald Welte4b634542008-12-27 01:55:51 +0000616 ci.chan_desc.iei = 0x64;
617 ci.chan_desc.chan_nr = chan_nr;
Harald Welte02b0e092009-02-28 13:11:07 +0000618 ci.chan_desc.oct3 = (lchan->ts->trx->bts->tsc << 5) | ((arfcn & 0x3ff) >> 8);
Harald Welte4b634542008-12-27 01:55:51 +0000619 ci.chan_desc.oct4 = arfcn & 0xff;
620
Harald Welteeab33352009-06-27 03:09:08 +0200621 msg = rsl_msgb_alloc();
Harald Welte4b634542008-12-27 01:55:51 +0000622 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 Welte4b634542008-12-27 01:55:51 +0000627 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
628 (u_int8_t *) &cm);
Harald Welte8d77b952009-12-17 00:31:10 +0100629 /* For compatibility with Phase 1 */
Harald Welte4b634542008-12-27 01:55:51 +0000630 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
631 (u_int8_t *) &ci);
Harald Welte08d91a52009-08-30 15:37:11 +0900632
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 Welte8d77b952009-12-17 00:31:10 +0100640 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 Welted4c9bf32009-02-15 16:56:18 +0000649 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
650 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
Harald Welte4b634542008-12-27 01:55:51 +0000651 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
652
Harald Weltee79769b2009-02-07 00:48:17 +0000653 msg->trx = lchan->ts->trx;
654
Harald Welte4b634542008-12-27 01:55:51 +0000655 return abis_rsl_sendmsg(msg);
656}
657
Harald Welte470abb72009-07-29 11:38:15 +0200658/* Chapter 8.4.9: Modify channel mode on BTS side */
Harald Welteda783762009-02-18 03:29:53 +0000659int rsl_chan_mode_modify_req(struct gsm_lchan *lchan)
660{
661 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200662 struct msgb *msg;
Harald Welte9943c5b2009-07-29 15:41:29 +0200663 int rc;
Harald Welteda783762009-02-18 03:29:53 +0000664
665 u_int8_t chan_nr = lchan2chan_nr(lchan);
666 struct rsl_ie_chan_mode cm;
667
Harald Welte9943c5b2009-07-29 15:41:29 +0200668 rc = channel_mode_from_lchan(&cm, lchan);
669 if (rc < 0)
670 return rc;
Harald Welteda783762009-02-18 03:29:53 +0000671
Harald Welteeab33352009-06-27 03:09:08 +0200672 msg = rsl_msgb_alloc();
Harald Welteda783762009-02-18 03:29:53 +0000673 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
674 init_dchan_hdr(dh, RSL_MT_MODE_MODIFY_REQ);
675 dh->chan_nr = chan_nr;
676
677 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
678 (u_int8_t *) &cm);
Harald Welte08d91a52009-08-30 15:37:11 +0900679
680 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
681 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
682 rc = build_encr_info(encr_info, lchan);
683 if (rc > 0)
684 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
685 }
686
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100687 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) {
688 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
689 (u_int8_t *) &lchan->mr_conf);
690 }
691
Harald Welte08d91a52009-08-30 15:37:11 +0900692 msg->trx = lchan->ts->trx;
693
694 return abis_rsl_sendmsg(msg);
695}
696
697/* Chapter 8.4.6: Send the encryption command with given L3 info */
698int rsl_encryption_cmd(struct msgb *msg)
699{
700 struct abis_rsl_dchan_hdr *dh;
701 struct gsm_lchan *lchan = msg->lchan;
702 u_int8_t chan_nr = lchan2chan_nr(lchan);
703 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
Sylvain Munaut82aa6842009-09-27 11:13:18 +0200704 u_int8_t l3_len = msg->len;
Harald Welte08d91a52009-08-30 15:37:11 +0900705 int rc;
706
707 /* First push the L3 IE tag and length */
708 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
709
710 /* then the link identifier (SAPI0, main sign link) */
711 msgb_tv_push(msg, RSL_IE_LINK_IDENT, 0);
712
713 /* then encryption information */
714 rc = build_encr_info(encr_info, lchan);
715 if (rc <= 0)
716 return rc;
717 msgb_tlv_push(msg, RSL_IE_ENCR_INFO, rc, encr_info);
718
719 /* and finally the DCHAN header */
720 dh = (struct abis_rsl_dchan_hdr *) msgb_push(msg, sizeof(*dh));
721 init_dchan_hdr(dh, RSL_MT_ENCR_CMD);
722 dh->chan_nr = chan_nr;
Harald Welteda783762009-02-18 03:29:53 +0000723
724 msg->trx = lchan->ts->trx;
725
726 return abis_rsl_sendmsg(msg);
727}
728
Harald Welte115d1032009-08-10 11:43:22 +0200729/* Chapter 8.4.5 / 4.6: Deactivate the SACCH after 04.08 RR CHAN RELEASE */
Harald Welteae0f2362009-07-19 18:36:49 +0200730int rsl_deact_sacch(struct gsm_lchan *lchan)
731{
732 struct abis_rsl_dchan_hdr *dh;
733 struct msgb *msg = rsl_msgb_alloc();
734
735 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
736 init_dchan_hdr(dh, RSL_MT_DEACTIVATE_SACCH);
737 dh->chan_nr = lchan2chan_nr(lchan);
738
739 msg->lchan = lchan;
740 msg->trx = lchan->ts->trx;
741
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100742 DEBUGP(DRSL, "%s DEACTivate SACCH CMD\n", gsm_lchan_name(lchan));
Harald Welteae0f2362009-07-19 18:36:49 +0200743
744 return abis_rsl_sendmsg(msg);
745}
746
Harald Welte115d1032009-08-10 11:43:22 +0200747/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
748int rsl_rf_chan_release(struct gsm_lchan *lchan)
Harald Welte52b1f982008-12-23 20:25:15 +0000749{
750 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000751 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000752
753 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
754 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
Harald Welte8470bf22008-12-25 23:28:35 +0000755 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000756
Harald Welte8470bf22008-12-25 23:28:35 +0000757 msg->lchan = lchan;
758 msg->trx = lchan->ts->trx;
759
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100760 DEBUGP(DRSL, "%s RF Channel Release CMD\n", gsm_lchan_name(lchan));
Harald Welte2d5b6382008-12-27 19:46:06 +0000761
Harald Welte115d1032009-08-10 11:43:22 +0200762 /* BTS will respond by RF CHAN REL ACK */
Harald Welte8470bf22008-12-25 23:28:35 +0000763 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000764}
765
766int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
767 u_int8_t *ms_ident, u_int8_t chan_needed)
768{
769 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000770 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000771
772 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
773 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
774 dh->chan_nr = RSL_CHAN_PCH_AGCH;
775
776 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
Harald Welte255539c2008-12-28 02:26:27 +0000777 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
Harald Welte52b1f982008-12-23 20:25:15 +0000778 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
779
Harald Welte8470bf22008-12-25 23:28:35 +0000780 msg->trx = bts->c0;
781
782 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000783}
784
Holger Freyther7448a532009-01-04 20:18:23 +0000785int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
786 struct gsm_subscriber *subscr)
787{
Holger Freytherca362a62009-01-04 21:05:01 +0000788#if 0
Holger Freyther7448a532009-01-04 20:18:23 +0000789 u_int8_t mi[128];
790 unsigned int mi_len;
791 u_int8_t paging_group;
Holger Freytherca362a62009-01-04 21:05:01 +0000792#endif
Holger Freyther7448a532009-01-04 20:18:23 +0000793
794 return -1;
795}
796
Harald Welte52b1f982008-12-23 20:25:15 +0000797int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
798{
799 int i, len = strlen(str_in);
800
801 for (i = 0; i < len; i++) {
802 int num = str_in[i] - 0x30;
803 if (num < 0 || num > 9)
804 return -1;
805 if (i % 2 == 0)
806 bcd_out[i/2] = num;
807 else
808 bcd_out[i/2] |= (num << 4);
809 }
810
811 return 0;
812}
813
Harald Welte702d8702008-12-26 20:25:35 +0000814/* Chapter 8.5.6 */
Harald Welte52b1f982008-12-23 20:25:15 +0000815int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
816{
Harald Welte8470bf22008-12-25 23:28:35 +0000817 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000818 struct abis_rsl_dchan_hdr *dh;
Harald Welte362322e2009-02-15 14:36:38 +0000819 u_int8_t buf[MACBLOCK_SIZE];
Harald Welte52b1f982008-12-23 20:25:15 +0000820
821 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
822 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
823 dh->chan_nr = RSL_CHAN_PCH_AGCH;
824
Harald Welte362322e2009-02-15 14:36:38 +0000825 switch (bts->type) {
826 case GSM_BTS_TYPE_BS11:
827 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
828 break;
829 default:
830 /* If phase 2, construct a FULL_IMM_ASS_INFO */
831 pad_macblock(buf, val, len);
832 msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf);
833 break;
834 }
Harald Welte52b1f982008-12-23 20:25:15 +0000835
Harald Welte8470bf22008-12-25 23:28:35 +0000836 msg->trx = bts->c0;
837
838 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000839}
840
Harald Welte67fa91b2009-08-10 09:51:40 +0200841/* Send Siemens specific MS RF Power Capability Indication */
Harald Welte31c48932009-08-10 10:07:33 +0200842int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci)
Harald Welte67fa91b2009-08-10 09:51:40 +0200843{
844 struct msgb *msg = rsl_msgb_alloc();
845 struct abis_rsl_dchan_hdr *dh;
846
847 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
848 init_dchan_hdr(dh, RSL_MT_SIEMENS_MRPCI);
Harald Welte3c456d02009-08-10 11:26:14 +0200849 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
Harald Welte67fa91b2009-08-10 09:51:40 +0200850 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte31c48932009-08-10 10:07:33 +0200851 msgb_tv_put(msg, RSL_IE_SIEMENS_MRPCI, *(u_int8_t *)mrpci);
Harald Welte67fa91b2009-08-10 09:51:40 +0200852
Harald Welte5b8ed432009-12-24 12:20:20 +0100853 DEBUGP(DRSL, "%s TX Siemens MRPCI 0x%02x\n",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100854 gsm_lchan_name(lchan), *(u_int8_t *)mrpci);
Harald Welte3c456d02009-08-10 11:26:14 +0200855
856 msg->trx = lchan->ts->trx;
857
Harald Welte67fa91b2009-08-10 09:51:40 +0200858 return abis_rsl_sendmsg(msg);
859}
860
861
Harald Welte8470bf22008-12-25 23:28:35 +0000862/* Send "DATA REQUEST" message with given L3 Info payload */
Harald Welte52b1f982008-12-23 20:25:15 +0000863/* Chapter 8.3.1 */
Harald Welte8470bf22008-12-25 23:28:35 +0000864int rsl_data_request(struct msgb *msg, u_int8_t link_id)
Harald Welte52b1f982008-12-23 20:25:15 +0000865{
Harald Welte8470bf22008-12-25 23:28:35 +0000866 u_int8_t l3_len = msg->tail - (u_int8_t *)msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000867 struct abis_rsl_rll_hdr *rh;
868
Harald Welte8470bf22008-12-25 23:28:35 +0000869 if (msg->lchan == NULL) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100870 LOGP(DRSL, LOGL_ERROR, "cannot send DATA REQUEST to unknown lchan\n");
Harald Welte8470bf22008-12-25 23:28:35 +0000871 return -EINVAL;
872 }
Harald Welte52b1f982008-12-23 20:25:15 +0000873
Harald Welte8470bf22008-12-25 23:28:35 +0000874 /* First push the L3 IE tag and length */
Harald Welte4b634542008-12-27 01:55:51 +0000875 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
Harald Welte8470bf22008-12-25 23:28:35 +0000876
877 /* Then push the RSL header */
Harald Welte52b1f982008-12-23 20:25:15 +0000878 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
879 init_llm_hdr(rh, RSL_MT_DATA_REQ);
Harald Welte4a543e82009-02-28 13:17:55 +0000880 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
Harald Welte8470bf22008-12-25 23:28:35 +0000881 rh->chan_nr = lchan2chan_nr(msg->lchan);
882 rh->link_id = link_id;
Harald Welte52b1f982008-12-23 20:25:15 +0000883
Harald Welte8470bf22008-12-25 23:28:35 +0000884 msg->trx = msg->lchan->ts->trx;
885
886 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000887}
888
Harald Welteedcc5272009-08-09 13:47:35 +0200889/* Send "ESTABLISH REQUEST" message with given L3 Info payload */
890/* Chapter 8.3.1 */
891int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
892{
893 struct msgb *msg = rsl_msgb_alloc();
894 struct abis_rsl_rll_hdr *rh;
895
896 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
Harald Welte1c409272009-08-09 14:13:58 +0200897 init_llm_hdr(rh, RSL_MT_EST_REQ);
Harald Welteedcc5272009-08-09 13:47:35 +0200898 //rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
899 rh->chan_nr = lchan2chan_nr(lchan);
900 rh->link_id = link_id;
901
902 msg->trx = lchan->ts->trx;
903
904 return abis_rsl_sendmsg(msg);
905}
906
Harald Welted2dc1de2009-08-08 13:15:07 +0200907/* Chapter 8.3.7 Request the release of multiframe mode of RLL connection.
908 This is what higher layers should call. The BTS then responds with
909 RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
910 which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
911 lchan_free() */
912int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id)
913{
914 struct msgb *msg = rsl_msgb_alloc();
915 struct abis_rsl_rll_hdr *rh;
916
917 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
918 init_llm_hdr(rh, RSL_MT_REL_REQ);
919 //rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
920 rh->chan_nr = lchan2chan_nr(lchan);
921 rh->link_id = link_id;
Harald Welte6c3d2ed2009-08-10 00:19:36 +0200922 msgb_tv_put(msg, RSL_IE_RELEASE_MODE, 0); /* normal release */
Harald Welted2dc1de2009-08-08 13:15:07 +0200923
Harald Welte8e93b792009-12-29 10:44:17 +0100924 lchan->state = LCHAN_S_REL_REQ;
925 /* FIXME: start some timer in case we don't receive a REL ACK ? */
926
Harald Welted2dc1de2009-08-08 13:15:07 +0200927 msg->trx = lchan->ts->trx;
928
929 return abis_rsl_sendmsg(msg);
930}
931
Harald Welte702d8702008-12-26 20:25:35 +0000932/* Chapter 8.4.2: Channel Activate Acknowledge */
933static int rsl_rx_chan_act_ack(struct msgb *msg)
934{
935 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
936
937 /* BTS has confirmed channel activation, we now need
938 * to assign the activated channel to the MS */
Harald Welte4b634542008-12-27 01:55:51 +0000939 if (rslh->ie_chan != RSL_IE_CHAN_NR)
940 return -EINVAL;
Harald Welted011e8b2009-11-29 22:45:52 +0100941
Harald Welte8e93b792009-12-29 10:44:17 +0100942 if (msg->lchan->state != LCHAN_S_ACT_REQ)
943 LOGP(DRSL, LOGL_NOTICE, "%s CHAN ACT ACK, but state %u\n",
944 gsm_lchan_name(msg->lchan), msg->lchan->state);
Harald Welteb8bfc562009-12-21 13:27:11 +0100945 msg->lchan->state = LCHAN_S_ACTIVE;
946
Harald Welted011e8b2009-11-29 22:45:52 +0100947 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_ACK, msg->lchan);
948
Harald Welte4b634542008-12-27 01:55:51 +0000949 return 0;
950}
Harald Welte702d8702008-12-26 20:25:35 +0000951
Harald Welte4b634542008-12-27 01:55:51 +0000952/* Chapter 8.4.3: Channel Activate NACK */
953static int rsl_rx_chan_act_nack(struct msgb *msg)
954{
Harald Welte6dab0552009-05-01 17:21:37 +0000955 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
956 struct tlv_parsed tp;
Harald Welte4b634542008-12-27 01:55:51 +0000957
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100958 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL ACTIVATE NACK",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100959 gsm_lchan_name(msg->lchan));
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100960
Harald Welte6dab0552009-05-01 17:21:37 +0000961 /* BTS has rejected channel activation ?!? */
962 if (dh->ie_chan != RSL_IE_CHAN_NR)
Harald Welte4b634542008-12-27 01:55:51 +0000963 return -EINVAL;
Harald Welte6dab0552009-05-01 17:21:37 +0000964
965 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte (local)3e460312009-12-27 18:12:29 +0100966 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) {
967 const u_int8_t *cause = TLVP_VAL(&tp, RSL_IE_CAUSE);
968 print_rsl_cause(LOGL_ERROR, cause,
Harald Welte8830e072009-07-28 17:58:09 +0200969 TLVP_LEN(&tp, RSL_IE_CAUSE));
Harald Welte (local)3e460312009-12-27 18:12:29 +0100970 if (*cause != RSL_ERR_RCH_ALR_ACTV_ALLOC)
971 msg->lchan->state = LCHAN_S_NONE;
972 } else
973 msg->lchan->state = LCHAN_S_NONE;
974
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100975 LOGPC(DRSL, LOGL_ERROR, "\n");
976
Harald Welted011e8b2009-11-29 22:45:52 +0100977 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_NACK, msg->lchan);
978
Harald Welte3073a9f2009-08-09 19:50:08 +0200979 lchan_free(msg->lchan);
Harald Welte4b634542008-12-27 01:55:51 +0000980 return 0;
Harald Welte702d8702008-12-26 20:25:35 +0000981}
982
Harald Welte7f93cea2009-02-23 00:02:59 +0000983/* Chapter 8.4.4: Connection Failure Indication */
984static int rsl_rx_conn_fail(struct msgb *msg)
985{
986 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
987 struct tlv_parsed tp;
988
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100989 /* FIXME: print which channel */
Harald Welte (local)fc057502009-12-26 22:33:09 +0100990 LOGP(DRSL, LOGL_NOTICE, "%s CONNECTION FAIL: RELEASING ",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100991 gsm_lchan_name(msg->lchan));
Harald Welte7f93cea2009-02-23 00:02:59 +0000992
993 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
994
Harald Welte8830e072009-07-28 17:58:09 +0200995 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +0100996 print_rsl_cause(LOGL_NOTICE, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +0200997 TLVP_LEN(&tp, RSL_IE_CAUSE));
998
Harald Welte (local)fc057502009-12-26 22:33:09 +0100999 LOGPC(DRSL, LOGL_NOTICE, "\n");
Harald Welte7f93cea2009-02-23 00:02:59 +00001000 /* FIXME: only free it after channel release ACK */
Harald Welte115d1032009-08-10 11:43:22 +02001001 return rsl_rf_chan_release(msg->lchan);
Harald Welte7f93cea2009-02-23 00:02:59 +00001002}
1003
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001004static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
1005 const char *prefix)
1006{
Harald Welte6739dfb2009-12-16 16:52:07 +01001007 DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",
1008 prefix, rxlev2dbm(mru->full.rx_lev),
1009 prefix, rxlev2dbm(mru->sub.rx_lev));
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001010 DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",
1011 prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);
1012}
1013
1014static void print_meas_rep(struct gsm_meas_rep *mr)
1015{
Harald Welte6739dfb2009-12-16 16:52:07 +01001016 int i;
1017
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001018 DEBUGP(DMEAS, "MEASUREMENT RESULT NR=%d ", mr->nr);
1019
1020 if (mr->flags & MEAS_REP_F_DL_DTX)
1021 DEBUGPC(DMEAS, "DTXd ");
1022
1023 print_meas_rep_uni(&mr->ul, "ul");
1024 DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
1025 if (mr->flags & MEAS_REP_F_MS_TO)
1026 DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
1027
1028 if (mr->flags & MEAS_REP_F_MS_L1) {
Harald Welte6739dfb2009-12-16 16:52:07 +01001029 DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001030 DEBUGPC(DMEAS, "L1_FPC=%u ",
1031 mr->flags & MEAS_REP_F_FPC ? 1 : 0);
1032 DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);
1033 }
1034
1035 if (mr->flags & MEAS_REP_F_UL_DTX)
1036 DEBUGPC(DMEAS, "DTXu ");
1037 if (mr->flags & MEAS_REP_F_BA1)
1038 DEBUGPC(DMEAS, "BA1 ");
1039 if (!(mr->flags & MEAS_REP_F_DL_VALID))
1040 DEBUGPC(DMEAS, "NOT VALID ");
1041 else
1042 print_meas_rep_uni(&mr->dl, "dl");
1043
1044 DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);
Harald Welte479015b2009-12-19 18:33:05 +01001045 if (mr->num_cell == 7)
1046 return;
Harald Welte6739dfb2009-12-16 16:52:07 +01001047 for (i = 0; i < mr->num_cell; i++) {
1048 struct gsm_meas_rep_cell *mrc = &mr->cell[i];
Harald Welte303e5e02009-12-25 23:02:22 +01001049 DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n",
1050 mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
Harald Welte6739dfb2009-12-16 16:52:07 +01001051 }
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001052}
1053
Harald Welte440fed02009-05-01 18:43:47 +00001054static int rsl_rx_meas_res(struct msgb *msg)
1055{
1056 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1057 struct tlv_parsed tp;
Harald Welted12b0fd2009-12-15 21:36:05 +01001058 struct gsm_meas_rep *mr = lchan_next_meas_rep(msg->lchan);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001059 u_int8_t len;
1060 const u_int8_t *val;
1061 int rc;
Harald Welte440fed02009-05-01 18:43:47 +00001062
Harald Welteb8bfc562009-12-21 13:27:11 +01001063 /* check if this channel is actually active */
1064 /* FIXME: maybe this check should be way more generic/centralized */
Harald Welte8e93b792009-12-29 10:44:17 +01001065 if (msg->lchan->state != LCHAN_S_ACTIVE) {
1066 LOGP(DRSL, LOGL_NOTICE, "%s: MEAS RES for inactive channel\n",
1067 gsm_lchan_name(msg->lchan));
Harald Welteb8bfc562009-12-21 13:27:11 +01001068 return 0;
Harald Welte8e93b792009-12-29 10:44:17 +01001069 }
Harald Welteb8bfc562009-12-21 13:27:11 +01001070
Harald Welted12b0fd2009-12-15 21:36:05 +01001071 memset(mr, 0, sizeof(*mr));
Harald Welte33e65972009-12-16 23:29:34 +01001072 mr->lchan = msg->lchan;
Harald Weltedbb1d882009-11-30 19:16:47 +01001073
Harald Welte440fed02009-05-01 18:43:47 +00001074 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
1075
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001076 if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) ||
1077 !TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) ||
1078 !TLVP_PRESENT(&tp, RSL_IE_BS_POWER))
1079 return -EIO;
1080
1081 /* Mandatory Parts */
Harald Welted12b0fd2009-12-15 21:36:05 +01001082 mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001083
1084 len = TLVP_LEN(&tp, RSL_IE_UPLINK_MEAS);
1085 val = TLVP_VAL(&tp, RSL_IE_UPLINK_MEAS);
1086 if (len >= 3) {
1087 if (val[0] & 0x40)
Harald Welted12b0fd2009-12-15 21:36:05 +01001088 mr->flags |= MEAS_REP_F_DL_DTX;
1089 mr->ul.full.rx_lev = val[0] & 0x3f;
1090 mr->ul.sub.rx_lev = val[1] & 0x3f;
1091 mr->ul.full.rx_qual = val[2]>>3 & 0x7;
1092 mr->ul.sub.rx_qual = val[2] & 0x7;
Harald Welte440fed02009-05-01 18:43:47 +00001093 }
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001094
Harald Welted12b0fd2009-12-15 21:36:05 +01001095 mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001096
1097 /* Optional Parts */
Harald Welte440fed02009-05-01 18:43:47 +00001098 if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET))
Harald Welted12b0fd2009-12-15 21:36:05 +01001099 mr->ms_timing_offset =
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001100 *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET);
1101
Harald Weltefe9af262009-06-20 18:44:35 +02001102 if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) {
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001103 val = TLVP_VAL(&tp, RSL_IE_L1_INFO);
Harald Welted12b0fd2009-12-15 21:36:05 +01001104 mr->flags |= MEAS_REP_F_MS_L1;
1105 mr->ms_l1.pwr = ms_pwr_dbm(msg->trx->bts->band, val[0] >> 3);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001106 if (val[0] & 0x04)
Harald Welted12b0fd2009-12-15 21:36:05 +01001107 mr->flags |= MEAS_REP_F_FPC;
1108 mr->ms_l1.ta = val[1];
Harald Weltefe9af262009-06-20 18:44:35 +02001109 }
Harald Weltef7c43522009-06-09 20:24:21 +00001110 if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
Holger Hans Peter Freytherddd918f2009-10-22 15:43:55 +02001111 msg->l3h = (u_int8_t *) TLVP_VAL(&tp, RSL_IE_L3_INFO);
Harald Welted12b0fd2009-12-15 21:36:05 +01001112 rc = gsm48_parse_meas_rep(mr, msg);
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001113 if (rc < 0)
1114 return rc;
1115 }
1116
Harald Welted12b0fd2009-12-15 21:36:05 +01001117 print_meas_rep(mr);
Harald Welte60d68f12009-06-05 20:07:43 +00001118
Harald Welted12b0fd2009-12-15 21:36:05 +01001119 dispatch_signal(SS_LCHAN, S_LCHAN_MEAS_REP, mr);
Harald Weltedbb1d882009-11-30 19:16:47 +01001120
Harald Welte75d34a82009-05-23 06:11:13 +00001121 return 0;
Harald Welte440fed02009-05-01 18:43:47 +00001122}
1123
Harald Welted011e8b2009-11-29 22:45:52 +01001124/* Chapter 8.4.7 */
1125static int rsl_rx_hando_det(struct msgb *msg)
1126{
1127 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1128 struct tlv_parsed tp;
1129
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001130 DEBUGP(DRSL, "%s HANDOVER DETECT ", gsm_lchan_name(msg->lchan));
Harald Welted011e8b2009-11-29 22:45:52 +01001131
1132 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
1133
1134 if (TLVP_PRESENT(&tp, RSL_IE_ACCESS_DELAY))
1135 DEBUGPC(DRSL, "access delay = %u\n",
1136 *TLVP_VAL(&tp, RSL_IE_ACCESS_DELAY));
1137 else
1138 DEBUGPC(DRSL, "\n");
1139
1140 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_DETECT, msg->lchan);
1141
1142 return 0;
1143}
1144
Harald Welte52b1f982008-12-23 20:25:15 +00001145static int abis_rsl_rx_dchan(struct msgb *msg)
1146{
Harald Welte8470bf22008-12-25 23:28:35 +00001147 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1148 int rc = 0;
Harald Weltef325eb42009-02-19 17:07:39 +00001149 char *ts_name;
Harald Welte52b1f982008-12-23 20:25:15 +00001150
Harald Welte8470bf22008-12-25 23:28:35 +00001151 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001152 ts_name = gsm_lchan_name(msg->lchan);
Harald Weltef325eb42009-02-19 17:07:39 +00001153
Harald Welte8470bf22008-12-25 23:28:35 +00001154 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +00001155 case RSL_MT_CHAN_ACTIV_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001156 DEBUGP(DRSL, "%s CHANNEL ACTIVATE ACK\n", ts_name);
Harald Welte4b634542008-12-27 01:55:51 +00001157 rc = rsl_rx_chan_act_ack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001158 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001159 case RSL_MT_CHAN_ACTIV_NACK:
Harald Welte4b634542008-12-27 01:55:51 +00001160 rc = rsl_rx_chan_act_nack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001161 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001162 case RSL_MT_CONN_FAIL:
Harald Welte7f93cea2009-02-23 00:02:59 +00001163 rc = rsl_rx_conn_fail(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001164 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001165 case RSL_MT_MEAS_RES:
Harald Welte440fed02009-05-01 18:43:47 +00001166 rc = rsl_rx_meas_res(msg);
Harald Welte2d5b6382008-12-27 19:46:06 +00001167 break;
Harald Welted011e8b2009-11-29 22:45:52 +01001168 case RSL_MT_HANDO_DET:
1169 rc = rsl_rx_hando_det(msg);
1170 break;
Harald Welte2d5b6382008-12-27 19:46:06 +00001171 case RSL_MT_RF_CHAN_REL_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001172 DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name);
Harald Welte8e93b792009-12-29 10:44:17 +01001173 if (msg->lchan->state != LCHAN_S_REL_REQ)
1174 LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state=%u\n",
1175 gsm_lchan_name(msg->lchan), msg->lchan->state);
Harald Welteb8bfc562009-12-21 13:27:11 +01001176 msg->lchan->state = LCHAN_S_NONE;
Harald Welte2d5b6382008-12-27 19:46:06 +00001177 lchan_free(msg->lchan);
Harald Welte8470bf22008-12-25 23:28:35 +00001178 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001179 case RSL_MT_MODE_MODIFY_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001180 DEBUGP(DRSL, "%s CHANNEL MODE MODIFY ACK\n", ts_name);
Harald Welteda783762009-02-18 03:29:53 +00001181 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001182 case RSL_MT_MODE_MODIFY_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001183 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL MODE MODIFY NACK\n", ts_name);
Harald Welteda783762009-02-18 03:29:53 +00001184 break;
Harald Welte9c880c92009-10-24 10:29:22 +02001185 case RSL_MT_IPAC_PDCH_ACT_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001186 DEBUGPC(DRSL, "%s IPAC PDCH ACT ACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001187 break;
1188 case RSL_MT_IPAC_PDCH_ACT_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001189 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH ACT NACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001190 break;
1191 case RSL_MT_IPAC_PDCH_DEACT_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001192 DEBUGP(DRSL, "%s IPAC PDCH DEACT ACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001193 break;
1194 case RSL_MT_IPAC_PDCH_DEACT_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001195 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH DEACT NACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001196 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001197 case RSL_MT_PHY_CONTEXT_CONF:
1198 case RSL_MT_PREPROC_MEAS_RES:
Harald Welte52b1f982008-12-23 20:25:15 +00001199 case RSL_MT_TALKER_DET:
1200 case RSL_MT_LISTENER_DET:
1201 case RSL_MT_REMOTE_CODEC_CONF_REP:
1202 case RSL_MT_MR_CODEC_MOD_ACK:
1203 case RSL_MT_MR_CODEC_MOD_NACK:
1204 case RSL_MT_MR_CODEC_MOD_PER:
Harald Welte5b8ed432009-12-24 12:20:20 +01001205 LOGP(DRSL, LOGL_NOTICE, "%s Unimplemented Abis RSL DChan "
1206 "msg 0x%02x\n", ts_name, rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001207 break;
1208 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001209 LOGP(DRSL, LOGL_NOTICE, "%s unknown Abis RSL DChan msg 0x%02x\n",
1210 ts_name, rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001211 return -EINVAL;
1212 }
Harald Weltef325eb42009-02-19 17:07:39 +00001213
Harald Welte8470bf22008-12-25 23:28:35 +00001214 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001215}
1216
Harald Welte702d8702008-12-26 20:25:35 +00001217static int rsl_rx_error_rep(struct msgb *msg)
1218{
1219 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8830e072009-07-28 17:58:09 +02001220 struct tlv_parsed tp;
Harald Welte702d8702008-12-26 20:25:35 +00001221
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001222 LOGP(DRSL, LOGL_ERROR, "ERROR REPORT ");
Harald Welte8830e072009-07-28 17:58:09 +02001223
1224 rsl_tlv_parse(&tp, rslh->data, msgb_l2len(msg)-sizeof(*rslh));
1225
1226 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +01001227 print_rsl_cause(LOGL_ERROR, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +02001228 TLVP_LEN(&tp, RSL_IE_CAUSE));
1229
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001230 LOGPC(DRSL, LOGL_ERROR, "\n");
Harald Welte702d8702008-12-26 20:25:35 +00001231
1232 return 0;
1233}
1234
Harald Welte52b1f982008-12-23 20:25:15 +00001235static int abis_rsl_rx_trx(struct msgb *msg)
1236{
Harald Welte702d8702008-12-26 20:25:35 +00001237 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001238 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001239
1240 switch (rslh->msg_type) {
Harald Welte702d8702008-12-26 20:25:35 +00001241 case RSL_MT_ERROR_REPORT:
1242 rc = rsl_rx_error_rep(msg);
1243 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001244 case RSL_MT_RF_RES_IND:
1245 /* interference on idle channels of TRX */
Harald Welte3cf7c3f2009-05-01 18:28:00 +00001246 //DEBUGP(DRSL, "TRX: RF Interference Indication\n");
Harald Welte8f5e2392009-02-03 12:57:37 +00001247 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001248 case RSL_MT_OVERLOAD:
1249 /* indicate CCCH / ACCH / processor overload */
Harald Welte (local)b29b57a2009-12-27 16:54:47 +01001250 LOGP(DRSL, LOGL_ERROR, "(bts=%u, trx=%u) CCCH/ACCH/CPU Overload\n",
1251 msg->trx->bts->nr, msg->trx->nr);
Harald Welte52b1f982008-12-23 20:25:15 +00001252 break;
1253 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001254 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message "
1255 "type 0x%02x\n", rslh->msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001256 return -EINVAL;
1257 }
Harald Welte8470bf22008-12-25 23:28:35 +00001258 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001259}
1260
Harald Welteb7e81162009-08-10 00:26:10 +02001261/* If T3101 expires, we never received a response to IMMEDIATE ASSIGN */
1262static void t3101_expired(void *data)
1263{
1264 struct gsm_lchan *lchan = data;
1265
Harald Welte115d1032009-08-10 11:43:22 +02001266 rsl_rf_chan_release(lchan);
Harald Welteb7e81162009-08-10 00:26:10 +02001267}
1268
Harald Welte8470bf22008-12-25 23:28:35 +00001269/* MS has requested a channel on the RACH */
Harald Welte52b1f982008-12-23 20:25:15 +00001270static int rsl_rx_chan_rqd(struct msgb *msg)
1271{
Harald Welte702d8702008-12-26 20:25:35 +00001272 struct gsm_bts *bts = msg->trx->bts;
Harald Welte8470bf22008-12-25 23:28:35 +00001273 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
1274 struct gsm48_req_ref *rqd_ref;
Harald Welte52b1f982008-12-23 20:25:15 +00001275 struct gsm48_imm_ass ia;
Harald Welte8470bf22008-12-25 23:28:35 +00001276 enum gsm_chan_t lctype;
Harald Welte2cbe0922008-12-29 04:09:31 +00001277 enum gsm_chreq_reason_t chreq_reason;
Harald Welte8470bf22008-12-25 23:28:35 +00001278 struct gsm_lchan *lchan;
1279 u_int8_t rqd_ta;
Holger Freyther3186bf22008-12-29 06:23:49 +00001280 int ret;
Harald Welte8470bf22008-12-25 23:28:35 +00001281
Harald Welte52b1f982008-12-23 20:25:15 +00001282 u_int16_t arfcn;
1283 u_int8_t ts_number, subch;
1284
Harald Welte8470bf22008-12-25 23:28:35 +00001285 /* parse request reference to be used in immediate assign */
1286 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
1287 return -EINVAL;
1288
1289 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
1290
1291 /* parse access delay and use as TA */
1292 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
1293 return -EINVAL;
1294 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
1295
1296 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
1297 * request reference RA */
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001298 lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
1299 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
Harald Welte2cbe0922008-12-29 04:09:31 +00001300
Harald Welteffa55a42009-12-22 19:07:32 +01001301 counter_inc(bts->network->stats.chreq.total);
Harald Welte24ff6ee2009-12-22 00:41:05 +01001302
Harald Welte8470bf22008-12-25 23:28:35 +00001303 /* check availability / allocate channel */
1304 lchan = lchan_alloc(bts, lctype);
1305 if (!lchan) {
Harald Welte (local)2f5df852009-12-27 13:48:09 +01001306 LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n",
Harald Welte (local)ccd88452009-12-27 18:05:25 +01001307 msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra);
Harald Welteffa55a42009-12-22 19:07:32 +01001308 counter_inc(bts->network->stats.chreq.no_channel);
Harald Welte8470bf22008-12-25 23:28:35 +00001309 /* FIXME: send some kind of reject ?!? */
1310 return -ENOMEM;
1311 }
1312
Harald Welte8e93b792009-12-29 10:44:17 +01001313 if (lchan->state != LCHAN_S_NONE)
1314 LOGP(DRSL, LOGL_NOTICE, "%s lchan_alloc() returned channel "
1315 "in state %u\n", gsm_lchan_name(lchan), lchan->state);
Harald Welte (local)3e460312009-12-27 18:12:29 +01001316 lchan->state = LCHAN_S_ACT_REQ;
1317
Harald Welte8470bf22008-12-25 23:28:35 +00001318 ts_number = lchan->ts->nr;
1319 arfcn = lchan->ts->trx->arfcn;
1320 subch = lchan->nr;
Harald Welte52b1f982008-12-23 20:25:15 +00001321
Harald Welte08d91a52009-08-30 15:37:11 +09001322 lchan->encr.alg_id = RSL_ENC_ALG_A5(0); /* no encryption */
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001323 lchan->ms_power = ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
Harald Welte0b2124b2009-08-10 00:45:40 +02001324 lchan->bs_power = 0; /* 0dB reduction, output power = Pn */
Harald Welte9943c5b2009-07-29 15:41:29 +02001325 lchan->rsl_cmode = RSL_CMOD_SPD_SIGN;
Harald Welte196d0522009-08-28 23:28:28 +09001326 lchan->tch_mode = GSM48_CMODE_SIGN;
Harald Welte8d77b952009-12-17 00:31:10 +01001327 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta, 0);
Harald Welte52b1f982008-12-23 20:25:15 +00001328
1329 /* create IMMEDIATE ASSIGN 04.08 messge */
1330 memset(&ia, 0, sizeof(ia));
1331 ia.l2_plen = 0x2d;
1332 ia.proto_discr = GSM48_PDISC_RR;
1333 ia.msg_type = GSM48_MT_RR_IMM_ASS;
Harald Welte2d5b6382008-12-27 19:46:06 +00001334 ia.page_mode = GSM48_PM_SAME;
Harald Welte4b634542008-12-27 01:55:51 +00001335 ia.chan_desc.chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +00001336 ia.chan_desc.h0.h = 0;
1337 ia.chan_desc.h0.arfcn_high = arfcn >> 8;
1338 ia.chan_desc.h0.arfcn_low = arfcn & 0xff;
Harald Welte814c4b72009-07-21 20:55:56 +02001339 ia.chan_desc.h0.tsc = bts->tsc;
Harald Welte8470bf22008-12-25 23:28:35 +00001340 /* use request reference extracted from CHAN_RQD */
1341 memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref));
1342 ia.timing_advance = rqd_ta;
Harald Welte52b1f982008-12-23 20:25:15 +00001343 ia.mob_alloc_len = 0;
1344
Harald Welte5b8ed432009-12-24 12:20:20 +01001345 DEBUGP(DRSL, "%s Activating ARFCN(%u) SS(%u) lctype %s "
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001346 "r=%s ra=0x%02x\n", gsm_lchan_name(lchan), arfcn, subch,
Harald Welte (local)ccd88452009-12-27 18:05:25 +01001347 gsm_lchant_name(lchan->type), gsm_chreq_name(chreq_reason),
Harald Welte4a543e82009-02-28 13:17:55 +00001348 rqd_ref->ra);
Harald Welte75a983f2008-12-27 21:34:06 +00001349
Harald Welteb7e81162009-08-10 00:26:10 +02001350 /* Start timer T3101 to wait for GSM48_MT_RR_PAG_RESP */
1351 lchan->T3101.cb = t3101_expired;
1352 lchan->T3101.data = lchan;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001353 bsc_schedule_timer(&lchan->T3101, bts->network->T3101, 0);
Holger Freyther3186bf22008-12-29 06:23:49 +00001354
Harald Welte52b1f982008-12-23 20:25:15 +00001355 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
Holger Freyther3186bf22008-12-29 06:23:49 +00001356 ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia);
1357
Harald Welte817f3c82008-12-30 14:57:59 +00001358 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +00001359}
1360
Harald Welteea280442009-02-02 22:29:56 +00001361/* MS has requested a channel on the RACH */
1362static int rsl_rx_ccch_load(struct msgb *msg)
1363{
1364 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1365 u_int16_t pg_buf_space;
Holger Freyther8c563cf2009-02-03 20:08:51 +00001366 u_int16_t rach_slot_count = -1;
1367 u_int16_t rach_busy_count = -1;
1368 u_int16_t rach_access_count = -1;
Harald Welteea280442009-02-02 22:29:56 +00001369
1370 switch (rslh->data[0]) {
1371 case RSL_IE_PAGING_LOAD:
1372 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
Holger Freyther392209c2009-02-10 00:06:19 +00001373 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
Harald Welteea280442009-02-02 22:29:56 +00001374 break;
1375 case RSL_IE_RACH_LOAD:
Holger Freyther8c563cf2009-02-03 20:08:51 +00001376 if (msg->data_len >= 7) {
1377 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
1378 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
1379 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
1380 }
Harald Welteea280442009-02-02 22:29:56 +00001381 break;
1382 default:
1383 break;
1384 }
1385
1386 return 0;
1387}
1388
Harald Welte52b1f982008-12-23 20:25:15 +00001389static int abis_rsl_rx_cchan(struct msgb *msg)
1390{
Harald Welteea280442009-02-02 22:29:56 +00001391 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001392 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001393
Harald Welte8470bf22008-12-25 23:28:35 +00001394 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
1395
1396 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +00001397 case RSL_MT_CHAN_RQD:
1398 /* MS has requested a channel on the RACH */
1399 rc = rsl_rx_chan_rqd(msg);
1400 break;
Harald Welteea280442009-02-02 22:29:56 +00001401 case RSL_MT_CCCH_LOAD_IND:
1402 /* current load on the CCCH */
1403 rc = rsl_rx_ccch_load(msg);
1404 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001405 case RSL_MT_DELETE_IND:
1406 /* CCCH overloaded, IMM_ASSIGN was dropped */
1407 case RSL_MT_CBCH_LOAD_IND:
1408 /* current load on the CBCH */
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001409 LOGP(DRSL, LOGL_NOTICE, "Unimplemented Abis RSL TRX message "
1410 "type 0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001411 break;
1412 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001413 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message type "
1414 "0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001415 return -EINVAL;
1416 }
Harald Welte8470bf22008-12-25 23:28:35 +00001417
1418 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001419}
1420
Harald Welte4b634542008-12-27 01:55:51 +00001421static int rsl_rx_rll_err_ind(struct msgb *msg)
1422{
1423 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1424 u_int8_t *rlm_cause = rllh->data;
1425
Harald Welte (local)9538efc2009-12-26 23:55:00 +01001426 LOGP(DRLL, LOGL_ERROR, "%s ERROR INDICATION cause=%s\n",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001427 gsm_lchan_name(msg->lchan),
Harald Welte (local)9538efc2009-12-26 23:55:00 +01001428 get_value_string(rlm_cause_strs, rlm_cause[1]));
Harald Welteedcc5272009-08-09 13:47:35 +02001429
1430 rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND);
Harald Welte (local)9538efc2009-12-26 23:55:00 +01001431
Harald Welte81543bc2009-07-04 09:40:05 +02001432 if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED)
Harald Welte115d1032009-08-10 11:43:22 +02001433 return rsl_rf_chan_release(msg->lchan);
Harald Welte81543bc2009-07-04 09:40:05 +02001434
Harald Welte4b634542008-12-27 01:55:51 +00001435 return 0;
1436}
Harald Weltef325eb42009-02-19 17:07:39 +00001437
Harald Welte52b1f982008-12-23 20:25:15 +00001438/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
1439 0x02, 0x06,
1440 0x01, 0x20,
1441 0x02, 0x00,
1442 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
1443
1444static int abis_rsl_rx_rll(struct msgb *msg)
1445{
1446 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Weltef325eb42009-02-19 17:07:39 +00001447 int rc = 0;
1448 char *ts_name;
Harald Welte (local)daef6062009-08-14 11:41:12 +02001449 u_int8_t sapi = rllh->link_id & 7;
Harald Welte8470bf22008-12-25 23:28:35 +00001450
1451 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001452 ts_name = gsm_lchan_name(msg->lchan);
Harald Welte5b8ed432009-12-24 12:20:20 +01001453 DEBUGP(DRLL, "%s SAPI=%u ", ts_name, sapi);
Harald Welte52b1f982008-12-23 20:25:15 +00001454
1455 switch (rllh->c.msg_type) {
1456 case RSL_MT_DATA_IND:
Harald Weltef325eb42009-02-19 17:07:39 +00001457 DEBUGPC(DRLL, "DATA INDICATION\n");
Harald Welte4a543e82009-02-28 13:17:55 +00001458 if (msgb_l2len(msg) >
1459 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1460 rllh->data[0] == RSL_IE_L3_INFO) {
1461 msg->l3h = &rllh->data[3];
Harald Welte (local)daef6062009-08-14 11:41:12 +02001462 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte4a543e82009-02-28 13:17:55 +00001463 }
Harald Welte52b1f982008-12-23 20:25:15 +00001464 break;
1465 case RSL_MT_EST_IND:
Harald Weltef325eb42009-02-19 17:07:39 +00001466 DEBUGPC(DRLL, "ESTABLISH INDICATION\n");
Harald Welteb7e81162009-08-10 00:26:10 +02001467 /* lchan is established, stop T3101 */
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001468 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_MS;
Harald Welteb7e81162009-08-10 00:26:10 +02001469 bsc_del_timer(&msg->lchan->T3101);
Harald Welte4a543e82009-02-28 13:17:55 +00001470 if (msgb_l2len(msg) >
1471 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1472 rllh->data[0] == RSL_IE_L3_INFO) {
1473 msg->l3h = &rllh->data[3];
Harald Welte (local)daef6062009-08-14 11:41:12 +02001474 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte4a543e82009-02-28 13:17:55 +00001475 }
Harald Welte52b1f982008-12-23 20:25:15 +00001476 break;
Harald Welteedcc5272009-08-09 13:47:35 +02001477 case RSL_MT_EST_CONF:
Harald Welte1c409272009-08-09 14:13:58 +02001478 DEBUGPC(DRLL, "ESTABLISH CONFIRM\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001479 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_NET;
Harald Welteedcc5272009-08-09 13:47:35 +02001480 rll_indication(msg->lchan, rllh->link_id,
1481 BSC_RLLR_IND_EST_CONF);
1482 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001483 case RSL_MT_REL_IND:
Harald Welted2dc1de2009-08-08 13:15:07 +02001484 /* BTS informs us of having received DISC from MS */
Harald Welte602f2b82009-08-04 02:50:21 +02001485 DEBUGPC(DRLL, "RELEASE INDICATION\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001486 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welteedcc5272009-08-09 13:47:35 +02001487 rll_indication(msg->lchan, rllh->link_id,
1488 BSC_RLLR_IND_REL_IND);
Harald Welted2dc1de2009-08-08 13:15:07 +02001489 /* we can now releae the channel on the BTS/Abis side */
Harald Welte115d1032009-08-10 11:43:22 +02001490 /* FIXME: officially we need to start T3111 and wait for
1491 * some grace period */
1492 rsl_rf_chan_release(msg->lchan);
Harald Welte2d5b6382008-12-27 19:46:06 +00001493 break;
1494 case RSL_MT_REL_CONF:
Harald Welted2dc1de2009-08-08 13:15:07 +02001495 /* BTS informs us of having received UA from MS,
1496 * in response to DISC that we've sent earlier */
Harald Welte602f2b82009-08-04 02:50:21 +02001497 DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001498 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welted2dc1de2009-08-08 13:15:07 +02001499 /* we can now releae the channel on the BTS/Abis side */
Harald Welte115d1032009-08-10 11:43:22 +02001500 /* FIXME: officially we need to start T3111 and wait for
1501 * some grace period */
1502 rsl_rf_chan_release(msg->lchan);
Harald Welte4b634542008-12-27 01:55:51 +00001503 break;
1504 case RSL_MT_ERROR_IND:
1505 rc = rsl_rx_rll_err_ind(msg);
1506 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001507 case RSL_MT_UNIT_DATA_IND:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001508 LOGP(DRLL, LOGL_NOTICE, "unimplemented Abis RLL message "
1509 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001510 break;
1511 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001512 LOGP(DRLL, LOGL_NOTICE, "unknown Abis RLL message "
1513 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001514 }
Harald Welte8470bf22008-12-25 23:28:35 +00001515 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001516}
1517
Harald Welte0603c9d2009-12-02 01:58:23 +05301518static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
Harald Weltef4e79f22009-07-28 18:11:56 +02001519{
Harald Welte0603c9d2009-12-02 01:58:23 +05301520 switch (lchan->tch_mode) {
Harald Weltef4e79f22009-07-28 18:11:56 +02001521 case GSM48_CMODE_SPEECH_V1:
Harald Welte0603c9d2009-12-02 01:58:23 +05301522 switch (lchan->type) {
1523 case GSM_LCHAN_TCH_F:
1524 return 0x00;
1525 case GSM_LCHAN_TCH_H:
1526 return 0x03;
1527 default:
1528 break;
1529 }
Harald Weltef4e79f22009-07-28 18:11:56 +02001530 case GSM48_CMODE_SPEECH_EFR:
Harald Welte0603c9d2009-12-02 01:58:23 +05301531 switch (lchan->type) {
1532 case GSM_LCHAN_TCH_F:
1533 return 0x01;
1534 /* there's no half-rate EFR */
1535 default:
1536 break;
1537 }
Harald Weltef4e79f22009-07-28 18:11:56 +02001538 case GSM48_CMODE_SPEECH_AMR:
Harald Welte0603c9d2009-12-02 01:58:23 +05301539 switch (lchan->type) {
1540 case GSM_LCHAN_TCH_F:
1541 return 0x02;
1542 case GSM_LCHAN_TCH_H:
1543 return 0x05;
1544 default:
1545 break;
1546 }
1547 default:
1548 break;
Harald Weltef4e79f22009-07-28 18:11:56 +02001549 }
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001550 LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access speech mode for "
Harald Welte0603c9d2009-12-02 01:58:23 +05301551 "tch_mode == 0x%02x\n", lchan->tch_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001552 return 0;
Harald Weltef4e79f22009-07-28 18:11:56 +02001553}
1554
Harald Welte75099262009-02-16 21:12:08 +00001555/* ip.access specific RSL extensions */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001556static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
1557{
1558 struct in_addr ip;
1559 u_int16_t port, conn_id;
1560
1561 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_IP)) {
1562 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_IP));
1563 DEBUGPC(DRSL, "LOCAL_IP=%s ", inet_ntoa(ip));
1564 lchan->abis_ip.bound_ip = ntohl(ip.s_addr);
1565 }
1566
1567 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_PORT)) {
1568 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_PORT));
1569 port = ntohs(port);
1570 DEBUGPC(DRSL, "LOCAL_PORT=%u ", port);
1571 lchan->abis_ip.bound_port = port;
1572 }
1573
1574 if (TLVP_PRESENT(tv, RSL_IE_IPAC_CONN_ID)) {
1575 conn_id = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_CONN_ID));
1576 conn_id = ntohs(conn_id);
1577 DEBUGPC(DRSL, "CON_ID=%u ", conn_id);
1578 lchan->abis_ip.conn_id = conn_id;
1579 }
1580
1581 if (TLVP_PRESENT(tv, RSL_IE_IPAC_RTP_PAYLOAD2)) {
1582 lchan->abis_ip.rtp_payload2 =
1583 *TLVP_VAL(tv, RSL_IE_IPAC_RTP_PAYLOAD2);
1584 DEBUGPC(DRSL, "RTP_PAYLOAD2=0x%02x ",
1585 lchan->abis_ip.rtp_payload2);
1586 }
1587
1588 if (TLVP_PRESENT(tv, RSL_IE_IPAC_SPEECH_MODE)) {
1589 lchan->abis_ip.speech_mode =
1590 *TLVP_VAL(tv, RSL_IE_IPAC_SPEECH_MODE);
1591 DEBUGPC(DRSL, "speech_mode=0x%02x ",
1592 lchan->abis_ip.speech_mode);
1593 }
1594
1595 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_IP)) {
1596 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_IP));
1597 DEBUGPC(DRSL, "REMOTE_IP=%s ", inet_ntoa(ip));
1598 lchan->abis_ip.connect_ip = ntohl(ip.s_addr);
1599 }
1600
1601 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_PORT)) {
1602 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_PORT));
1603 port = ntohs(port);
1604 DEBUGPC(DRSL, "REMOTE_PORT=%u ", port);
1605 lchan->abis_ip.connect_port = port;
1606 }
1607}
1608
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001609int rsl_ipacc_crcx(struct gsm_lchan *lchan)
Harald Welte75099262009-02-16 21:12:08 +00001610{
1611 struct msgb *msg = rsl_msgb_alloc();
1612 struct abis_rsl_dchan_hdr *dh;
1613
1614 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001615 init_dchan_hdr(dh, RSL_MT_IPAC_CRCX);
Harald Welte75099262009-02-16 21:12:08 +00001616 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1617 dh->chan_nr = lchan2chan_nr(lchan);
1618
Harald Weltef4e79f22009-07-28 18:11:56 +02001619 /* 0x1- == receive-only, 0x-1 == EFR codec */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001620 lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
1621 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001622
Harald Welte5b8ed432009-12-24 12:20:20 +01001623 DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x\n",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001624 gsm_lchan_name(lchan), lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001625
Harald Welte75099262009-02-16 21:12:08 +00001626 msg->trx = lchan->ts->trx;
1627
1628 return abis_rsl_sendmsg(msg);
1629}
1630
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001631int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
Harald Welte5e3d91b2009-12-19 16:42:06 +01001632 u_int8_t rtp_payload2)
Harald Welte75099262009-02-16 21:12:08 +00001633{
1634 struct msgb *msg = rsl_msgb_alloc();
1635 struct abis_rsl_dchan_hdr *dh;
Harald Welte5e3d91b2009-12-19 16:42:06 +01001636 u_int32_t *att_ip;
Harald Weltef4e79f22009-07-28 18:11:56 +02001637 struct in_addr ia;
Harald Welte75099262009-02-16 21:12:08 +00001638
1639 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001640 init_dchan_hdr(dh, RSL_MT_IPAC_MDCX);
Harald Welte75099262009-02-16 21:12:08 +00001641 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1642 dh->chan_nr = lchan2chan_nr(lchan);
1643
Harald Welte5e3d91b2009-12-19 16:42:06 +01001644 /* we need to store these now as MDCX_ACK does not return them :( */
1645 lchan->abis_ip.rtp_payload2 = rtp_payload2;
1646 lchan->abis_ip.connect_port = port;
1647 lchan->abis_ip.connect_ip = ip;
1648
Harald Welte58ca5b72009-07-29 12:12:18 +02001649 /* 0x0- == both directions, 0x-1 == EFR codec */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001650 lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
Harald Welte58ca5b72009-07-29 12:12:18 +02001651
Harald Weltef4e79f22009-07-28 18:11:56 +02001652 ia.s_addr = htonl(ip);
Harald Welte5b8ed432009-12-24 12:20:20 +01001653 DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD2=%d CONN_ID=%d "
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001654 "speech_mode=0x%02x\n", gsm_lchan_name(lchan), inet_ntoa(ia), port,
Harald Welte5e3d91b2009-12-19 16:42:06 +01001655 rtp_payload2, lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001656
Harald Welte5e3d91b2009-12-19 16:42:06 +01001657 msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
1658 msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
1659 att_ip = (u_int32_t *) msgb_put(msg, sizeof(ip));
1660 *att_ip = ia.s_addr;
1661 msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
1662 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001663 if (rtp_payload2)
1664 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
1665
Harald Welte75099262009-02-16 21:12:08 +00001666 msg->trx = lchan->ts->trx;
1667
1668 return abis_rsl_sendmsg(msg);
1669}
1670
Harald Weltea72273e2009-12-20 16:51:09 +01001671/* tell BTS to connect RTP stream to our local RTP socket */
1672int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan)
1673{
1674 struct rtp_socket *rs = lchan->abis_ip.rtp_socket;
1675 int rc;
1676
1677 rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr),
1678 ntohs(rs->rtp.sin_local.sin_port),
1679 /* FIXME: use RTP payload of bound socket, not BTS*/
1680 lchan->abis_ip.rtp_payload2);
1681
1682 return rc;
1683}
1684
Harald Welte9c880c92009-10-24 10:29:22 +02001685int rsl_ipacc_pdch_activate(struct gsm_lchan *lchan)
1686{
1687 struct msgb *msg = rsl_msgb_alloc();
1688 struct abis_rsl_dchan_hdr *dh;
1689
1690 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
1691 init_dchan_hdr(dh, RSL_MT_IPAC_PDCH_ACT);
1692 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
1693 dh->chan_nr = lchan2chan_nr(lchan);
1694
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001695 DEBUGP(DRSL, "%s IPAC_PDCH_ACT\n", gsm_lchan_name(lchan));
Harald Welte9c880c92009-10-24 10:29:22 +02001696
1697 msg->trx = lchan->ts->trx;
1698
1699 return abis_rsl_sendmsg(msg);
1700}
1701
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001702static int abis_rsl_rx_ipacc_crcx_ack(struct msgb *msg)
Harald Welte75099262009-02-16 21:12:08 +00001703{
1704 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1705 struct tlv_parsed tv;
Harald Welte2c828992009-12-02 01:56:49 +05301706 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75099262009-02-16 21:12:08 +00001707
1708 /* the BTS has acknowledged a local bind, it now tells us the IP
1709 * address and port number to which it has bound the given logical
1710 * channel */
1711
1712 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1713 if (!TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_PORT) ||
1714 !TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_IP) ||
Harald Welte86c162d2009-07-12 09:45:05 +02001715 !TLVP_PRESENT(&tv, RSL_IE_IPAC_CONN_ID)) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001716 LOGP(DRSL, LOGL_NOTICE, "mandatory IE missing");
Harald Welte75099262009-02-16 21:12:08 +00001717 return -EINVAL;
1718 }
Harald Welte17f5bf62009-12-20 15:42:44 +01001719
Harald Welte5e3d91b2009-12-19 16:42:06 +01001720 ipac_parse_rtp(lchan, &tv);
Harald Welte17f5bf62009-12-20 15:42:44 +01001721
1722 /* in case we don't use direct BTS-to-BTS RTP */
1723 if (!ipacc_rtp_direct) {
1724 int rc;
1725 /* the BTS has successfully bound a TCH to a local ip/port,
1726 * which means we can connect our UDP socket to it */
1727 if (lchan->abis_ip.rtp_socket) {
1728 rtp_socket_free(lchan->abis_ip.rtp_socket);
1729 lchan->abis_ip.rtp_socket = NULL;
1730 }
1731
1732 lchan->abis_ip.rtp_socket = rtp_socket_create();
1733 if (!lchan->abis_ip.rtp_socket)
1734 goto out_err;
1735
1736 rc = rtp_socket_connect(lchan->abis_ip.rtp_socket,
1737 lchan->abis_ip.bound_ip,
1738 lchan->abis_ip.bound_port);
1739 if (rc < 0)
1740 goto out_err;
1741 }
1742
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001743 dispatch_signal(SS_ABISIP, S_ABISIP_CRCX_ACK, msg->lchan);
Harald Welte167df882009-02-17 14:35:45 +00001744
Harald Welte75099262009-02-16 21:12:08 +00001745 return 0;
Harald Welte17f5bf62009-12-20 15:42:44 +01001746out_err:
1747 return -EIO;
Harald Welte75099262009-02-16 21:12:08 +00001748}
1749
Harald Welte5e3d91b2009-12-19 16:42:06 +01001750static int abis_rsl_rx_ipacc_mdcx_ack(struct msgb *msg)
1751{
1752 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1753 struct tlv_parsed tv;
1754 struct gsm_lchan *lchan = msg->lchan;
1755
1756 /* the BTS has acknowledged a remote connect request and
1757 * it now tells us the IP address and port number to which it has
1758 * connected the given logical channel */
1759
1760 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1761 ipac_parse_rtp(lchan, &tv);
1762 dispatch_signal(SS_ABISIP, S_ABISIP_MDCX_ACK, msg->lchan);
1763
1764 return 0;
1765}
1766
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001767static int abis_rsl_rx_ipacc_dlcx_ind(struct msgb *msg)
Harald Welte75099262009-02-16 21:12:08 +00001768{
1769 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1770 struct tlv_parsed tv;
Harald Welte17f5bf62009-12-20 15:42:44 +01001771 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75099262009-02-16 21:12:08 +00001772
1773 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte75099262009-02-16 21:12:08 +00001774
Harald Welte8830e072009-07-28 17:58:09 +02001775 if (TLVP_PRESENT(&tv, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +01001776 print_rsl_cause(LOGL_DEBUG, TLVP_VAL(&tv, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +02001777 TLVP_LEN(&tv, RSL_IE_CAUSE));
Harald Welte75099262009-02-16 21:12:08 +00001778
Harald Welte17f5bf62009-12-20 15:42:44 +01001779 /* the BTS tells us a RTP stream has been disconnected */
1780 if (lchan->abis_ip.rtp_socket) {
1781 rtp_socket_free(lchan->abis_ip.rtp_socket);
1782 lchan->abis_ip.rtp_socket = NULL;
1783 }
1784
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001785 dispatch_signal(SS_ABISIP, S_ABISIP_DLCX_IND, msg->lchan);
Harald Welte888b1142009-07-28 18:02:05 +02001786
Harald Welte75099262009-02-16 21:12:08 +00001787 return 0;
1788}
1789
1790static int abis_rsl_rx_ipacc(struct msgb *msg)
1791{
1792 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Welte5b8ed432009-12-24 12:20:20 +01001793 char *ts_name;
Harald Welte75099262009-02-16 21:12:08 +00001794 int rc = 0;
1795
1796 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001797 ts_name = gsm_lchan_name(msg->lchan);
Harald Welte75099262009-02-16 21:12:08 +00001798
1799 switch (rllh->c.msg_type) {
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001800 case RSL_MT_IPAC_CRCX_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001801 DEBUGP(DRSL, "%s IPAC_CRCX_ACK ", ts_name);
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001802 rc = abis_rsl_rx_ipacc_crcx_ack(msg);
Harald Welte75099262009-02-16 21:12:08 +00001803 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001804 case RSL_MT_IPAC_CRCX_NACK:
Harald Welte75099262009-02-16 21:12:08 +00001805 /* somehow the BTS was unable to bind the lchan to its local
1806 * port?!? */
Harald Welte5b8ed432009-12-24 12:20:20 +01001807 LOGP(DRSL, LOGL_ERROR, "%s IPAC_CRCX_NACK\n", ts_name);
Harald Welte75099262009-02-16 21:12:08 +00001808 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001809 case RSL_MT_IPAC_MDCX_ACK:
Harald Welte75099262009-02-16 21:12:08 +00001810 /* the BTS tells us that a connect operation was successful */
Harald Welte5b8ed432009-12-24 12:20:20 +01001811 DEBUGP(DRSL, "%s IPAC_MDCX_ACK ", ts_name);
Harald Welte5e3d91b2009-12-19 16:42:06 +01001812 rc = abis_rsl_rx_ipacc_mdcx_ack(msg);
Harald Welte75099262009-02-16 21:12:08 +00001813 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001814 case RSL_MT_IPAC_MDCX_NACK:
Harald Welte75099262009-02-16 21:12:08 +00001815 /* somehow the BTS was unable to connect the lchan to a remote
1816 * port */
Harald Welte5b8ed432009-12-24 12:20:20 +01001817 LOGP(DRSL, LOGL_ERROR, "%s IPAC_MDCX_NACK\n", ts_name);
Harald Welte75099262009-02-16 21:12:08 +00001818 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001819 case RSL_MT_IPAC_DLCX_IND:
Harald Welte5b8ed432009-12-24 12:20:20 +01001820 DEBUGP(DRSL, "%s IPAC_DLCX_IND ", ts_name);
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001821 rc = abis_rsl_rx_ipacc_dlcx_ind(msg);
Harald Welte75099262009-02-16 21:12:08 +00001822 break;
1823 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001824 LOGP(DRSL, LOGL_NOTICE, "Unknown ip.access msg_type 0x%02x\n",
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001825 rllh->c.msg_type);
Harald Welte75099262009-02-16 21:12:08 +00001826 break;
1827 }
Harald Welte6dab0552009-05-01 17:21:37 +00001828 DEBUGPC(DRSL, "\n");
Harald Welte75099262009-02-16 21:12:08 +00001829
1830 return rc;
1831}
1832
1833
Harald Welte52b1f982008-12-23 20:25:15 +00001834/* Entry-point where L2 RSL from BTS enters */
Harald Welte8470bf22008-12-25 23:28:35 +00001835int abis_rsl_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001836{
1837 struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
Harald Welte8f5e2392009-02-03 12:57:37 +00001838 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001839
1840 switch (rslh->msg_discr & 0xfe) {
1841 case ABIS_RSL_MDISC_RLL:
1842 rc = abis_rsl_rx_rll(msg);
1843 break;
1844 case ABIS_RSL_MDISC_DED_CHAN:
1845 rc = abis_rsl_rx_dchan(msg);
1846 break;
1847 case ABIS_RSL_MDISC_COM_CHAN:
Harald Welte52b1f982008-12-23 20:25:15 +00001848 rc = abis_rsl_rx_cchan(msg);
1849 break;
Harald Welte8470bf22008-12-25 23:28:35 +00001850 case ABIS_RSL_MDISC_TRX:
1851 rc = abis_rsl_rx_trx(msg);
1852 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001853 case ABIS_RSL_MDISC_LOC:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001854 LOGP(DRSL, LOGL_NOTICE, "unimplemented RSL msg disc 0x%02x\n",
Harald Welte8f5e2392009-02-03 12:57:37 +00001855 rslh->msg_discr);
1856 break;
Harald Welte75099262009-02-16 21:12:08 +00001857 case ABIS_RSL_MDISC_IPACCESS:
1858 rc = abis_rsl_rx_ipacc(msg);
1859 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001860 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001861 LOGP(DRSL, LOGL_NOTICE, "unknown RSL message discriminator "
1862 "0x%02x\n", rslh->msg_discr);
Harald Welte52b1f982008-12-23 20:25:15 +00001863 return -EINVAL;
1864 }
Harald Welte4f4a3902008-12-26 00:04:49 +00001865 msgb_free(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001866 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001867}
Holger Freyther3b72a892009-02-04 00:31:39 +00001868
1869
Holger Hans Peter Freyther3d571832009-07-09 20:43:16 +02001870/* Section 3.3.2.3 TS 05.02. I think this looks like a table */
Holger Freyther3b72a892009-02-04 00:31:39 +00001871int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
1872{
1873 switch (ccch_conf) {
1874 case RSL_BCCH_CCCH_CONF_1_NC:
1875 return 1;
1876 case RSL_BCCH_CCCH_CONF_1_C:
1877 return 1;
1878 case RSL_BCCH_CCCH_CONF_2_NC:
1879 return 2;
1880 case RSL_BCCH_CCCH_CONF_3_NC:
1881 return 3;
1882 case RSL_BCCH_CCCH_CONF_4_NC:
1883 return 4;
1884 default:
1885 return -1;
1886 }
1887}
1888
Holger Hans Peter Freyther3d571832009-07-09 20:43:16 +02001889/* Section 3.3.2.3 TS 05.02 */
Holger Freyther3b72a892009-02-04 00:31:39 +00001890int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
1891{
1892 switch (ccch_conf) {
1893 case RSL_BCCH_CCCH_CONF_1_NC:
1894 return 0;
1895 case RSL_BCCH_CCCH_CONF_1_C:
1896 return 1;
1897 case RSL_BCCH_CCCH_CONF_2_NC:
1898 return 0;
1899 case RSL_BCCH_CCCH_CONF_3_NC:
1900 return 0;
1901 case RSL_BCCH_CCCH_CONF_4_NC:
1902 return 0;
1903 default:
1904 return -1;
1905 }
1906}
1907
1908/* From Table 10.5.33 of GSM 04.08 */
1909int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
1910{
Harald Weltea43f7892009-12-01 18:04:30 +05301911 if (bts->si_common.chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
1912 return MAX(1, (3 - bts->si_common.chan_desc.bs_ag_blks_res))
1913 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +00001914 } else {
Harald Weltea43f7892009-12-01 18:04:30 +05301915 return (9 - bts->si_common.chan_desc.bs_ag_blks_res)
1916 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +00001917 }
1918}