blob: 2d55806a19aaf3d26e7c9756bd067d9b3786b651 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* 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
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <errno.h>
27#include <sys/types.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30
31#include <openbsc/gsm_data.h>
32#include <openbsc/gsm_04_08.h>
Harald Weltec4dcda02009-08-09 14:45:18 +020033#include <openbsc/gsm_utils.h>
Harald Welte59b04682009-06-10 05:40:52 +080034#include <openbsc/abis_rsl.h>
35#include <openbsc/chan_alloc.h>
Harald Welteed9a5ab2009-08-09 13:47:35 +020036#include <openbsc/bsc_rll.h>
Harald Welte59b04682009-06-10 05:40:52 +080037#include <openbsc/debug.h>
38#include <openbsc/tlv.h>
39#include <openbsc/paging.h>
40#include <openbsc/signal.h>
Harald Weltec20bd1d2009-11-29 19:07:28 +010041#include <openbsc/meas_rep.h>
Harald Welte59b04682009-06-10 05:40:52 +080042
43#define RSL_ALLOC_SIZE 1024
44#define RSL_ALLOC_HEADROOM 128
45
46#define MAX(a, b) (a) >= (b) ? (a) : (b)
47
48static const struct tlv_definition rsl_att_tlvdef = {
49 .def = {
50 [RSL_IE_CHAN_NR] = { TLV_TYPE_TV },
51 [RSL_IE_LINK_IDENT] = { TLV_TYPE_TV },
52 [RSL_IE_ACT_TYPE] = { TLV_TYPE_TV },
53 [RSL_IE_BS_POWER] = { TLV_TYPE_TV },
54 [RSL_IE_CHAN_IDENT] = { TLV_TYPE_TLV },
55 [RSL_IE_CHAN_MODE] = { TLV_TYPE_TLV },
56 [RSL_IE_ENCR_INFO] = { TLV_TYPE_TLV },
57 [RSL_IE_FRAME_NUMBER] = { TLV_TYPE_FIXED, 2 },
58 [RSL_IE_HANDO_REF] = { TLV_TYPE_TV },
59 [RSL_IE_L1_INFO] = { TLV_TYPE_FIXED, 2 },
60 [RSL_IE_L3_INFO] = { TLV_TYPE_TL16V },
61 [RSL_IE_MS_IDENTITY] = { TLV_TYPE_TLV },
62 [RSL_IE_MS_POWER] = { TLV_TYPE_TV },
63 [RSL_IE_PAGING_GROUP] = { TLV_TYPE_TV },
64 [RSL_IE_PAGING_LOAD] = { TLV_TYPE_FIXED, 2 },
65 [RSL_IE_PYHS_CONTEXT] = { TLV_TYPE_TLV },
66 [RSL_IE_ACCESS_DELAY] = { TLV_TYPE_TV },
67 [RSL_IE_RACH_LOAD] = { TLV_TYPE_TLV },
68 [RSL_IE_REQ_REFERENCE] = { TLV_TYPE_FIXED, 3 },
69 [RSL_IE_RELEASE_MODE] = { TLV_TYPE_TV },
70 [RSL_IE_RESOURCE_INFO] = { TLV_TYPE_TLV },
71 [RSL_IE_RLM_CAUSE] = { TLV_TYPE_TLV },
72 [RSL_IE_STARTNG_TIME] = { TLV_TYPE_FIXED, 2 },
73 [RSL_IE_TIMING_ADVANCE] = { TLV_TYPE_TV },
74 [RSL_IE_UPLINK_MEAS] = { TLV_TYPE_TLV },
75 [RSL_IE_CAUSE] = { TLV_TYPE_TLV },
76 [RSL_IE_MEAS_RES_NR] = { TLV_TYPE_TV },
77 [RSL_IE_MSG_ID] = { TLV_TYPE_TV },
78 [RSL_IE_SYSINFO_TYPE] = { TLV_TYPE_TV },
79 [RSL_IE_MS_POWER_PARAM] = { TLV_TYPE_TLV },
80 [RSL_IE_BS_POWER_PARAM] = { TLV_TYPE_TLV },
81 [RSL_IE_PREPROC_PARAM] = { TLV_TYPE_TLV },
82 [RSL_IE_PREPROC_MEAS] = { TLV_TYPE_TLV },
83 [RSL_IE_IMM_ASS_INFO] = { TLV_TYPE_TLV },
84 [RSL_IE_SMSCB_INFO] = { TLV_TYPE_FIXED, 23 },
85 [RSL_IE_MS_TIMING_OFFSET] = { TLV_TYPE_TV },
86 [RSL_IE_ERR_MSG] = { TLV_TYPE_TLV },
87 [RSL_IE_FULL_BCCH_INFO] = { TLV_TYPE_TLV },
88 [RSL_IE_CHAN_NEEDED] = { TLV_TYPE_TV },
89 [RSL_IE_CB_CMD_TYPE] = { TLV_TYPE_TV },
90 [RSL_IE_SMSCB_MSG] = { TLV_TYPE_TLV },
91 [RSL_IE_FULL_IMM_ASS_INFO] = { TLV_TYPE_TLV },
92 [RSL_IE_SACCH_INFO] = { TLV_TYPE_TLV },
93 [RSL_IE_CBCH_LOAD_INFO] = { TLV_TYPE_TV },
94 [RSL_IE_SMSCB_CHAN_INDICATOR] = { TLV_TYPE_TV },
95 [RSL_IE_GROUP_CALL_REF] = { TLV_TYPE_TLV },
96 [RSL_IE_CHAN_DESC] = { TLV_TYPE_TLV },
97 [RSL_IE_NCH_DRX_INFO] = { TLV_TYPE_TLV },
98 [RSL_IE_CMD_INDICATOR] = { TLV_TYPE_TLV },
99 [RSL_IE_EMLPP_PRIO] = { TLV_TYPE_TV },
100 [RSL_IE_UIC] = { TLV_TYPE_TLV },
101 [RSL_IE_MAIN_CHAN_REF] = { TLV_TYPE_TV },
102 [RSL_IE_MR_CONFIG] = { TLV_TYPE_TLV },
103 [RSL_IE_MR_CONTROL] = { TLV_TYPE_TV },
104 [RSL_IE_SUP_CODEC_TYPES] = { TLV_TYPE_TLV },
105 [RSL_IE_CODEC_CONFIG] = { TLV_TYPE_TLV },
106 [RSL_IE_RTD] = { TLV_TYPE_TV },
107 [RSL_IE_TFO_STATUS] = { TLV_TYPE_TV },
108 [RSL_IE_LLP_APDU] = { TLV_TYPE_TLV },
Harald Welte4684e632009-08-10 09:51:40 +0200109 [RSL_IE_SIEMENS_MRPCI] = { TLV_TYPE_TV },
Harald Welte1610d302009-07-12 09:56:39 +0200110 [RSL_IE_IPAC_PROXY_UDP] = { TLV_TYPE_FIXED, 2 },
111 [RSL_IE_IPAC_BSCMPL_TOUT] = { TLV_TYPE_TV },
Harald Welte59b04682009-06-10 05:40:52 +0800112 [RSL_IE_IPAC_REMOTE_IP] = { TLV_TYPE_FIXED, 4 },
113 [RSL_IE_IPAC_REMOTE_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welte1610d302009-07-12 09:56:39 +0200114 [RSL_IE_IPAC_RTP_PAYLOAD] = { TLV_TYPE_TV },
Harald Welte59b04682009-06-10 05:40:52 +0800115 [RSL_IE_IPAC_LOCAL_PORT] = { TLV_TYPE_FIXED, 2 },
Harald Welteb9498952009-07-12 09:45:05 +0200116 [RSL_IE_IPAC_SPEECH_MODE] = { TLV_TYPE_TV },
Harald Welte1610d302009-07-12 09:56:39 +0200117 [RSL_IE_IPAC_LOCAL_IP] = { TLV_TYPE_FIXED, 4 },
Harald Welteb9498952009-07-12 09:45:05 +0200118 [RSL_IE_IPAC_CONN_ID] = { TLV_TYPE_FIXED, 2 },
Harald Welte1610d302009-07-12 09:56:39 +0200119 [RSL_IE_IPAC_RTP_CSD_FMT] = { TLV_TYPE_TV },
120 [RSL_IE_IPAC_RTP_JIT_BUF] = { TLV_TYPE_FIXED, 2 },
121 [RSL_IE_IPAC_RTP_COMPR] = { TLV_TYPE_TV },
Harald Welteb9498952009-07-12 09:45:05 +0200122 [RSL_IE_IPAC_RTP_PAYLOAD2] = { TLV_TYPE_TV },
Harald Welte1610d302009-07-12 09:56:39 +0200123 [RSL_IE_IPAC_RTP_MPLEX] = { TLV_TYPE_FIXED, 8 },
124 [RSL_IE_IPAC_RTP_MPLEX_ID] = { TLV_TYPE_TV },
Harald Welte59b04682009-06-10 05:40:52 +0800125 },
126};
127#define rsl_tlv_parse(dec, buf, len) \
128 tlv_parse(dec, &rsl_att_tlvdef, buf, len, 0, 0)
129
130static u_int8_t mdisc_by_msgtype(u_int8_t msg_type)
131{
132 /* mask off the transparent bit ? */
133 msg_type &= 0xfe;
134
135 if ((msg_type & 0xf0) == 0x00)
136 return ABIS_RSL_MDISC_RLL;
137 if ((msg_type & 0xf0) == 0x10) {
138 if (msg_type >= 0x19 && msg_type <= 0x22)
139 return ABIS_RSL_MDISC_TRX;
140 else
141 return ABIS_RSL_MDISC_COM_CHAN;
142 }
143 if ((msg_type & 0xe0) == 0x20)
144 return ABIS_RSL_MDISC_DED_CHAN;
145
146 return ABIS_RSL_MDISC_LOC;
147}
148
149static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh,
150 u_int8_t msg_type)
151{
152 dh->c.msg_discr = mdisc_by_msgtype(msg_type);
153 dh->c.msg_type = msg_type;
154 dh->ie_chan = RSL_IE_CHAN_NR;
155}
156
157static inline void init_llm_hdr(struct abis_rsl_rll_hdr *dh,
158 u_int8_t msg_type)
159{
160 /* dh->c.msg_discr = mdisc_by_msgtype(msg_type); */
161 dh->c.msg_discr = ABIS_RSL_MDISC_RLL;
162 dh->c.msg_type = msg_type;
163 dh->ie_chan = RSL_IE_CHAN_NR;
164 dh->ie_link_id = RSL_IE_LINK_IDENT;
165}
166
167
168/* encode channel number as per Section 9.3.1 */
169u_int8_t rsl_enc_chan_nr(u_int8_t type, u_int8_t subch, u_int8_t timeslot)
170{
171 u_int8_t ret;
172
173 ret = (timeslot & 0x07) | type;
174
175 switch (type) {
176 case RSL_CHAN_Lm_ACCHs:
177 subch &= 0x01;
178 break;
179 case RSL_CHAN_SDCCH4_ACCH:
180 subch &= 0x07;
181 break;
182 case RSL_CHAN_SDCCH8_ACCH:
183 subch &= 0x07;
184 break;
185 default:
186 /* no subchannels allowed */
187 subch = 0x00;
188 break;
189 }
190 ret |= (subch << 3);
191
192 return ret;
193}
194
195/* determine logical channel based on TRX and channel number IE */
196struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr)
197{
198 struct gsm_lchan *lchan;
199 u_int8_t ts_nr = chan_nr & 0x07;
200 u_int8_t cbits = chan_nr >> 3;
201 u_int8_t lch_idx;
202 struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
203
204 if (cbits == 0x01) {
205 lch_idx = 0; /* TCH/F */
Harald Welte37884ed2009-10-24 10:25:50 +0200206 if (ts->pchan != GSM_PCHAN_TCH_F &&
207 ts->pchan != GSM_PCHAN_PDCH &&
208 ts->pchan != GSM_PCHAN_TCH_F_PDCH)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100209 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800210 chan_nr, ts->pchan);
211 } else if ((cbits & 0x1e) == 0x02) {
212 lch_idx = cbits & 0x1; /* TCH/H */
213 if (ts->pchan != GSM_PCHAN_TCH_H)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100214 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800215 chan_nr, ts->pchan);
216 } else if ((cbits & 0x1c) == 0x04) {
217 lch_idx = cbits & 0x3; /* SDCCH/4 */
218 if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100219 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800220 chan_nr, ts->pchan);
221 } else if ((cbits & 0x18) == 0x08) {
222 lch_idx = cbits & 0x7; /* SDCCH/8 */
223 if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100224 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800225 chan_nr, ts->pchan);
226 } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
227 lch_idx = 0;
228 if (ts->pchan != GSM_PCHAN_CCCH &&
229 ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100230 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800231 chan_nr, ts->pchan);
232 /* FIXME: we should not return first sdcch4 !!! */
233 } else {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100234 LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800235 return NULL;
236 }
237
238 lchan = &ts->lchan[lch_idx];
239
240 return lchan;
241}
242
Holger Hans Peter Freyther942ff172009-10-22 11:47:45 +0200243/* See Table 10.5.25 of GSM04.08 */
Harald Welteb5586242009-12-09 19:18:32 +0100244u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan)
Harald Welte59b04682009-06-10 05:40:52 +0800245{
246 struct gsm_bts_trx_ts *ts = lchan->ts;
247 u_int8_t cbits, chan_nr;
248
249 switch (ts->pchan) {
250 case GSM_PCHAN_TCH_F:
Harald Welte37884ed2009-10-24 10:25:50 +0200251 case GSM_PCHAN_PDCH:
252 case GSM_PCHAN_TCH_F_PDCH:
Harald Welte59b04682009-06-10 05:40:52 +0800253 cbits = 0x01;
254 break;
255 case GSM_PCHAN_TCH_H:
256 cbits = 0x02;
257 cbits += lchan->nr;
258 break;
259 case GSM_PCHAN_CCCH_SDCCH4:
260 cbits = 0x04;
261 cbits += lchan->nr;
262 break;
263 case GSM_PCHAN_SDCCH8_SACCH8C:
264 cbits = 0x08;
265 cbits += lchan->nr;
266 break;
267 default:
268 case GSM_PCHAN_CCCH:
269 cbits = 0x10;
270 break;
271 }
272
273 chan_nr = (cbits << 3) | (ts->nr & 0x7);
274
275 return chan_nr;
276}
277
278/* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */
279u_int64_t str_to_imsi(const char *imsi_str)
280{
281 u_int64_t ret;
282
283 ret = strtoull(imsi_str, NULL, 10);
284
285 return ret;
286}
287
288/* Table 5 Clause 7 TS 05.02 */
289unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res)
290{
291 if (!bs_ccch_sdcch_comb)
292 return 9 - bs_ag_blks_res;
293 else
294 return 3 - bs_ag_blks_res;
295}
296
297/* Chapter 6.5.2 of TS 05.02 */
298unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans,
299 unsigned int n_pag_blocks)
300{
301 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks;
302}
303
304/* Chapter 6.5.2 of TS 05.02 */
305unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
306 int n_pag_blocks)
307{
308 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks;
309}
310
311static struct msgb *rsl_msgb_alloc(void)
312{
Harald Welte9cfc9352009-06-26 19:39:35 +0200313 return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM,
314 "RSL");
Harald Welte59b04682009-06-10 05:40:52 +0800315}
316
317#define MACBLOCK_SIZE 23
318static void pad_macblock(u_int8_t *out, const u_int8_t *in, int len)
319{
320 memcpy(out, in, len);
321
322 if (len < MACBLOCK_SIZE)
323 memset(out+len, 0x2b, MACBLOCK_SIZE-len);
324}
325
Harald Welted2dd9de2009-08-30 15:37:11 +0900326/* Chapter 9.3.7: Encryption Information */
327static int build_encr_info(u_int8_t *out, struct gsm_lchan *lchan)
328{
329 *out++ = lchan->encr.alg_id & 0xff;
330 if (lchan->encr.key_len)
331 memcpy(out, lchan->encr.key, lchan->encr.key_len);
332 return lchan->encr.key_len + 1;
333}
334
335
Harald Weltef1a168d2009-07-28 17:58:09 +0200336static const char *rsl_err_vals[0xff] = {
337 [RSL_ERR_RADIO_IF_FAIL] = "Radio Interface Failure",
338 [RSL_ERR_RADIO_LINK_FAIL] = "Radio Link Failure",
339 [RSL_ERR_HANDOVER_ACC_FAIL] = "Handover Access Failure",
340 [RSL_ERR_TALKER_ACC_FAIL] = "Talker Access Failure",
341 [RSL_ERR_OM_INTERVENTION] = "O&M Intervention",
342 [RSL_ERR_NORMAL_UNSPEC] = "Normal event, unspecified",
Harald Welteb1717e92009-08-04 02:31:05 +0200343 [RSL_ERR_T_MSRFPCI_EXP] = "Siemens: T_MSRFPCI Expired",
Harald Weltef1a168d2009-07-28 17:58:09 +0200344 [RSL_ERR_EQUIPMENT_FAIL] = "Equipment Failure",
345 [RSL_ERR_RR_UNAVAIL] = "Radio Resource not available",
346 [RSL_ERR_TERR_CH_FAIL] = "Terrestrial Channel Failure",
347 [RSL_ERR_CCCH_OVERLOAD] = "CCCH Overload",
348 [RSL_ERR_ACCH_OVERLOAD] = "ACCH Overload",
349 [RSL_ERR_PROCESSOR_OVERLOAD] = "Processor Overload",
350 [RSL_ERR_RES_UNAVAIL] = "Resource not available, unspecified",
351 [RSL_ERR_TRANSC_UNAVAIL] = "Transcoding not available",
352 [RSL_ERR_SERV_OPT_UNAVAIL] = "Service or Option not available",
353 [RSL_ERR_ENCR_UNIMPL] = "Encryption algorithm not implemented",
354 [RSL_ERR_SERV_OPT_UNIMPL] = "Service or Option not implemented",
355 [RSL_ERR_RCH_ALR_ACTV_ALLOC] = "Radio channel already activated",
356 [RSL_ERR_INVALID_MESSAGE] = "Invalid Message, unspecified",
357 [RSL_ERR_MSG_DISCR] = "Message Discriminator Error",
358 [RSL_ERR_MSG_TYPE] = "Message Type Error",
359 [RSL_ERR_MSG_SEQ] = "Message Sequence Error",
360 [RSL_ERR_IE_ERROR] = "General IE error",
361 [RSL_ERR_MAND_IE_ERROR] = "Mandatory IE error",
362 [RSL_ERR_OPT_IE_ERROR] = "Optional IE error",
363 [RSL_ERR_IE_NONEXIST] = "IE non-existent",
364 [RSL_ERR_IE_LENGTH] = "IE length error",
365 [RSL_ERR_IE_CONTENT] = "IE content error",
366 [RSL_ERR_PROTO] = "Protocol error, unspecified",
367 [RSL_ERR_INTERWORKING] = "Interworking error, unspecified",
368};
369
370static const char *rsl_err_name(u_int8_t err)
Harald Welte59b04682009-06-10 05:40:52 +0800371{
Harald Weltef1a168d2009-07-28 17:58:09 +0200372 if (rsl_err_vals[err])
373 return rsl_err_vals[err];
374 else
375 return "unknown";
376}
377
378static void print_rsl_cause(const u_int8_t *cause_v, u_int8_t cause_len)
379{
Harald Welte59b04682009-06-10 05:40:52 +0800380 int i;
381
Harald Weltef1a168d2009-07-28 17:58:09 +0200382 DEBUGPC(DRSL, "CAUSE=0x%02x(%s) ",
383 cause_v[0], rsl_err_name(cause_v[0]));
384 for (i = 1; i < cause_len-1; i++)
385 DEBUGPC(DRSL, "%02x ", cause_v[i]);
Harald Welte59b04682009-06-10 05:40:52 +0800386}
387
388/* Send a BCCH_INFO message as per Chapter 8.5.1 */
389int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type,
390 const u_int8_t *data, int len)
391{
392 struct abis_rsl_dchan_hdr *dh;
393 struct msgb *msg = rsl_msgb_alloc();
394
395 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh);
396 init_dchan_hdr(dh, RSL_MT_BCCH_INFO);
397 dh->chan_nr = RSL_CHAN_BCCH;
398
399 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
400 msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data);
401
402 msg->trx = trx;
403
404 return abis_rsl_sendmsg(msg);
405}
406
407int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type,
408 const u_int8_t *data, int len)
409{
410 struct abis_rsl_common_hdr *ch;
411 struct msgb *msg = rsl_msgb_alloc();
412
413 ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch));
414 ch->msg_discr = ABIS_RSL_MDISC_TRX;
415 ch->msg_type = RSL_MT_SACCH_FILL;
416
417 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
418 msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data);
419
420 msg->trx = trx;
421
422 return abis_rsl_sendmsg(msg);
423}
424
Harald Welte91afe4c2009-06-20 18:15:19 +0200425int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db)
426{
427 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200428 struct msgb *msg;
Harald Welte91afe4c2009-06-20 18:15:19 +0200429 u_int8_t chan_nr = lchan2chan_nr(lchan);
430
431 db = abs(db);
432 if (db > 30)
433 return -EINVAL;
434
Harald Welteed831842009-06-27 03:09:08 +0200435 msg = rsl_msgb_alloc();
436
Harald Welte91afe4c2009-06-20 18:15:19 +0200437 lchan->bs_power = db/2;
438 if (fpc)
439 lchan->bs_power |= 0x10;
440
441 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
442 init_dchan_hdr(dh, RSL_MT_BS_POWER_CONTROL);
443 dh->chan_nr = chan_nr;
444
445 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
446
447 msg->trx = lchan->ts->trx;
448
449 return abis_rsl_sendmsg(msg);
450}
451
Harald Welte91afe4c2009-06-20 18:15:19 +0200452int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm)
453{
454 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200455 struct msgb *msg;
Harald Welte91afe4c2009-06-20 18:15:19 +0200456 u_int8_t chan_nr = lchan2chan_nr(lchan);
457 int ctl_lvl;
458
Harald Weltec4dcda02009-08-09 14:45:18 +0200459 ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm);
Harald Welte91afe4c2009-06-20 18:15:19 +0200460 if (ctl_lvl < 0)
461 return ctl_lvl;
462
Harald Welteed831842009-06-27 03:09:08 +0200463 msg = rsl_msgb_alloc();
464
Harald Welte91afe4c2009-06-20 18:15:19 +0200465 lchan->ms_power = ctl_lvl;
466
467 if (fpc)
468 lchan->ms_power |= 0x20;
469
470 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
471 init_dchan_hdr(dh, RSL_MT_MS_POWER_CONTROL);
472 dh->chan_nr = chan_nr;
473
474 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
475
476 msg->trx = lchan->ts->trx;
477
478 return abis_rsl_sendmsg(msg);
479}
480
Harald Welte39274f42009-07-29 15:41:29 +0200481static int channel_mode_from_lchan(struct rsl_ie_chan_mode *cm,
482 struct gsm_lchan *lchan)
483{
484 memset(cm, 0, sizeof(cm));
485
486 /* FIXME: what to do with data calls ? */
487 cm->dtx_dtu = 0x00;
488
489 /* set TCH Speech/Data */
490 cm->spd_ind = lchan->rsl_cmode;
491
Harald Welte951e3512009-11-27 08:55:16 +0100492 if (lchan->rsl_cmode == RSL_CMOD_SPD_SIGN &&
493 lchan->tch_mode != GSM48_CMODE_SIGN)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100494 LOGP(DRSL, LOGL_ERROR, "unsupported: rsl_mode == signalling, "
Harald Welte951e3512009-11-27 08:55:16 +0100495 "but tch_mode != signalling\n");
496
Harald Welte39274f42009-07-29 15:41:29 +0200497 switch (lchan->type) {
498 case GSM_LCHAN_SDCCH:
499 cm->chan_rt = RSL_CMOD_CRT_SDCCH;
500 break;
501 case GSM_LCHAN_TCH_F:
502 cm->chan_rt = RSL_CMOD_CRT_TCH_Bm;
503 break;
504 case GSM_LCHAN_TCH_H:
505 cm->chan_rt = RSL_CMOD_CRT_TCH_Lm;
506 break;
507 case GSM_LCHAN_NONE:
508 case GSM_LCHAN_UNKNOWN:
509 default:
510 return -EINVAL;
511 }
512
513 switch (lchan->tch_mode) {
514 case GSM48_CMODE_SIGN:
515 cm->chan_rate = 0;
516 break;
517 case GSM48_CMODE_SPEECH_V1:
518 cm->chan_rate = RSL_CMOD_SP_GSM1;
519 break;
520 case GSM48_CMODE_SPEECH_EFR:
521 cm->chan_rate = RSL_CMOD_SP_GSM2;
522 break;
523 case GSM48_CMODE_SPEECH_AMR:
524 cm->chan_rate = RSL_CMOD_SP_GSM3;
525 break;
526 case GSM48_CMODE_DATA_14k5:
527 cm->chan_rate = RSL_CMOD_SP_NT_14k5;
528 break;
529 case GSM48_CMODE_DATA_12k0:
530 cm->chan_rate = RSL_CMOD_SP_NT_12k0;
531 break;
532 case GSM48_CMODE_DATA_6k0:
533 cm->chan_rate = RSL_CMOD_SP_NT_6k0;
534 break;
535 default:
536 return -EINVAL;
537 }
538
539 return 0;
540}
541
Harald Welte59b04682009-06-10 05:40:52 +0800542/* Chapter 8.4.1 */
543#if 0
544int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
545 u_int8_t act_type,
546 struct rsl_ie_chan_mode *chan_mode,
547 struct rsl_ie_chan_ident *chan_ident,
548 u_int8_t bs_power, u_int8_t ms_power,
549 u_int8_t ta)
550{
551 struct abis_rsl_dchan_hdr *dh;
552 struct msgb *msg = rsl_msgb_alloc();
553
554 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
555 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
556 dh->chan_nr = chan_nr;
557
558 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
559 /* For compatibility with Phase 1 */
560 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode),
561 (u_int8_t *) chan_mode);
562 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
563 (u_int8_t *) chan_ident);
564#if 0
565 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
566 (u_int8_t *) &encr_info);
567#endif
568 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
569 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
570 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
571
572 msg->trx = trx;
573
574 return abis_rsl_sendmsg(msg);
575}
576#endif
577
578int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
Harald Welteb90d7bd2009-12-17 00:31:10 +0100579 u_int8_t ta, u_int8_t ho_ref)
Harald Welte59b04682009-06-10 05:40:52 +0800580{
581 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200582 struct msgb *msg;
Harald Welte39274f42009-07-29 15:41:29 +0200583 int rc;
Harald Welte59b04682009-06-10 05:40:52 +0800584
585 u_int8_t chan_nr = lchan2chan_nr(lchan);
586 u_int16_t arfcn = lchan->ts->trx->arfcn;
587 struct rsl_ie_chan_mode cm;
588 struct rsl_ie_chan_ident ci;
589
Harald Welte39274f42009-07-29 15:41:29 +0200590 rc = channel_mode_from_lchan(&cm, lchan);
591 if (rc < 0)
592 return rc;
Harald Welte59b04682009-06-10 05:40:52 +0800593
594 memset(&ci, 0, sizeof(ci));
595 ci.chan_desc.iei = 0x64;
596 ci.chan_desc.chan_nr = chan_nr;
597 ci.chan_desc.oct3 = (lchan->ts->trx->bts->tsc << 5) | ((arfcn & 0x3ff) >> 8);
598 ci.chan_desc.oct4 = arfcn & 0xff;
599
Harald Welteed831842009-06-27 03:09:08 +0200600 msg = rsl_msgb_alloc();
Harald Welte59b04682009-06-10 05:40:52 +0800601 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
602 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
603 dh->chan_nr = chan_nr;
604
605 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
Harald Welte59b04682009-06-10 05:40:52 +0800606 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
607 (u_int8_t *) &cm);
Harald Welteb90d7bd2009-12-17 00:31:10 +0100608 /* For compatibility with Phase 1 */
Harald Welte59b04682009-06-10 05:40:52 +0800609 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
610 (u_int8_t *) &ci);
Harald Welted2dd9de2009-08-30 15:37:11 +0900611
612 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
613 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
614 rc = build_encr_info(encr_info, lchan);
615 if (rc > 0)
616 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
617 }
618
Harald Welteb90d7bd2009-12-17 00:31:10 +0100619 switch (act_type) {
620 case RSL_ACT_INTER_ASYNC:
621 case RSL_ACT_INTER_SYNC:
622 msgb_tv_put(msg, RSL_IE_HANDO_REF, ho_ref);
623 break;
624 default:
625 break;
626 }
627
Harald Welte59b04682009-06-10 05:40:52 +0800628 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
629 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
630 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
631
632 msg->trx = lchan->ts->trx;
633
634 return abis_rsl_sendmsg(msg);
635}
636
Harald Welte8e770492009-07-29 11:38:15 +0200637/* Chapter 8.4.9: Modify channel mode on BTS side */
Harald Welte59b04682009-06-10 05:40:52 +0800638int rsl_chan_mode_modify_req(struct gsm_lchan *lchan)
639{
640 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200641 struct msgb *msg;
Harald Welte39274f42009-07-29 15:41:29 +0200642 int rc;
Harald Welte59b04682009-06-10 05:40:52 +0800643
644 u_int8_t chan_nr = lchan2chan_nr(lchan);
645 struct rsl_ie_chan_mode cm;
646
Harald Welte39274f42009-07-29 15:41:29 +0200647 rc = channel_mode_from_lchan(&cm, lchan);
648 if (rc < 0)
649 return rc;
Harald Welte59b04682009-06-10 05:40:52 +0800650
Harald Welteed831842009-06-27 03:09:08 +0200651 msg = rsl_msgb_alloc();
Harald Welte59b04682009-06-10 05:40:52 +0800652 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
653 init_dchan_hdr(dh, RSL_MT_MODE_MODIFY_REQ);
654 dh->chan_nr = chan_nr;
655
656 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
657 (u_int8_t *) &cm);
Harald Welted2dd9de2009-08-30 15:37:11 +0900658
659 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
660 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
661 rc = build_encr_info(encr_info, lchan);
662 if (rc > 0)
663 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
664 }
665
Holger Hans Peter Freyther3cce58f2009-11-18 22:57:02 +0100666 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) {
667 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
668 (u_int8_t *) &lchan->mr_conf);
669 }
670
Harald Welted2dd9de2009-08-30 15:37:11 +0900671 msg->trx = lchan->ts->trx;
672
673 return abis_rsl_sendmsg(msg);
674}
675
676/* Chapter 8.4.6: Send the encryption command with given L3 info */
677int rsl_encryption_cmd(struct msgb *msg)
678{
679 struct abis_rsl_dchan_hdr *dh;
680 struct gsm_lchan *lchan = msg->lchan;
681 u_int8_t chan_nr = lchan2chan_nr(lchan);
682 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
Sylvain Munaut01f1caf2009-09-27 11:13:18 +0200683 u_int8_t l3_len = msg->len;
Harald Welted2dd9de2009-08-30 15:37:11 +0900684 int rc;
685
686 /* First push the L3 IE tag and length */
687 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
688
689 /* then the link identifier (SAPI0, main sign link) */
690 msgb_tv_push(msg, RSL_IE_LINK_IDENT, 0);
691
692 /* then encryption information */
693 rc = build_encr_info(encr_info, lchan);
694 if (rc <= 0)
695 return rc;
696 msgb_tlv_push(msg, RSL_IE_ENCR_INFO, rc, encr_info);
697
698 /* and finally the DCHAN header */
699 dh = (struct abis_rsl_dchan_hdr *) msgb_push(msg, sizeof(*dh));
700 init_dchan_hdr(dh, RSL_MT_ENCR_CMD);
701 dh->chan_nr = chan_nr;
Harald Welte59b04682009-06-10 05:40:52 +0800702
703 msg->trx = lchan->ts->trx;
704
705 return abis_rsl_sendmsg(msg);
706}
707
Harald Welte85a163c2009-08-10 11:43:22 +0200708/* Chapter 8.4.5 / 4.6: Deactivate the SACCH after 04.08 RR CHAN RELEASE */
Harald Welteafe3c232009-07-19 18:36:49 +0200709int rsl_deact_sacch(struct gsm_lchan *lchan)
710{
711 struct abis_rsl_dchan_hdr *dh;
712 struct msgb *msg = rsl_msgb_alloc();
713
714 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
715 init_dchan_hdr(dh, RSL_MT_DEACTIVATE_SACCH);
716 dh->chan_nr = lchan2chan_nr(lchan);
717
718 msg->lchan = lchan;
719 msg->trx = lchan->ts->trx;
720
721 DEBUGP(DRSL, "DEACTivate SACCH CMD channel=%s chan_nr=0x%02x\n",
722 gsm_ts_name(lchan->ts), dh->chan_nr);
723
724 return abis_rsl_sendmsg(msg);
725}
726
Harald Welte85a163c2009-08-10 11:43:22 +0200727/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
728int rsl_rf_chan_release(struct gsm_lchan *lchan)
Harald Welte59b04682009-06-10 05:40:52 +0800729{
730 struct abis_rsl_dchan_hdr *dh;
731 struct msgb *msg = rsl_msgb_alloc();
732
733 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
734 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
735 dh->chan_nr = lchan2chan_nr(lchan);
736
737 msg->lchan = lchan;
738 msg->trx = lchan->ts->trx;
739
Harald Welte85a163c2009-08-10 11:43:22 +0200740 DEBUGP(DRSL, "RF Channel Release CMD channel=%s chan_nr=0x%02x\n",
Harald Welte59b04682009-06-10 05:40:52 +0800741 gsm_ts_name(lchan->ts), dh->chan_nr);
742
Harald Welte85a163c2009-08-10 11:43:22 +0200743 /* BTS will respond by RF CHAN REL ACK */
Harald Welte59b04682009-06-10 05:40:52 +0800744 return abis_rsl_sendmsg(msg);
745}
746
747int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
748 u_int8_t *ms_ident, u_int8_t chan_needed)
749{
750 struct abis_rsl_dchan_hdr *dh;
751 struct msgb *msg = rsl_msgb_alloc();
752
753 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
754 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
755 dh->chan_nr = RSL_CHAN_PCH_AGCH;
756
757 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
758 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
759 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
760
761 msg->trx = bts->c0;
762
763 return abis_rsl_sendmsg(msg);
764}
765
766int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
767 struct gsm_subscriber *subscr)
768{
769#if 0
770 u_int8_t mi[128];
771 unsigned int mi_len;
772 u_int8_t paging_group;
773#endif
774
775 return -1;
776}
777
778int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
779{
780 int i, len = strlen(str_in);
781
782 for (i = 0; i < len; i++) {
783 int num = str_in[i] - 0x30;
784 if (num < 0 || num > 9)
785 return -1;
786 if (i % 2 == 0)
787 bcd_out[i/2] = num;
788 else
789 bcd_out[i/2] |= (num << 4);
790 }
791
792 return 0;
793}
794
795/* Chapter 8.5.6 */
796int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
797{
798 struct msgb *msg = rsl_msgb_alloc();
799 struct abis_rsl_dchan_hdr *dh;
800 u_int8_t buf[MACBLOCK_SIZE];
801
802 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
803 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
804 dh->chan_nr = RSL_CHAN_PCH_AGCH;
805
806 switch (bts->type) {
807 case GSM_BTS_TYPE_BS11:
808 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
809 break;
810 default:
811 /* If phase 2, construct a FULL_IMM_ASS_INFO */
812 pad_macblock(buf, val, len);
813 msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf);
814 break;
815 }
816
817 msg->trx = bts->c0;
818
819 return abis_rsl_sendmsg(msg);
820}
821
Harald Welte4684e632009-08-10 09:51:40 +0200822/* Send Siemens specific MS RF Power Capability Indication */
Harald Welte12090752009-08-10 10:07:33 +0200823int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci)
Harald Welte4684e632009-08-10 09:51:40 +0200824{
825 struct msgb *msg = rsl_msgb_alloc();
826 struct abis_rsl_dchan_hdr *dh;
827
828 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
829 init_dchan_hdr(dh, RSL_MT_SIEMENS_MRPCI);
Harald Welte874a5b42009-08-10 11:26:14 +0200830 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
Harald Welte4684e632009-08-10 09:51:40 +0200831 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte12090752009-08-10 10:07:33 +0200832 msgb_tv_put(msg, RSL_IE_SIEMENS_MRPCI, *(u_int8_t *)mrpci);
Harald Welte4684e632009-08-10 09:51:40 +0200833
Harald Welte874a5b42009-08-10 11:26:14 +0200834 DEBUGP(DRSL, "channel=%s chan_nr=0x%02x TX Siemens MRPCI 0x%02x\n",
835 gsm_ts_name(lchan->ts), dh->chan_nr, *(u_int8_t *)mrpci);
836
837 msg->trx = lchan->ts->trx;
838
Harald Welte4684e632009-08-10 09:51:40 +0200839 return abis_rsl_sendmsg(msg);
840}
841
842
Harald Welte59b04682009-06-10 05:40:52 +0800843/* Send "DATA REQUEST" message with given L3 Info payload */
844/* Chapter 8.3.1 */
845int rsl_data_request(struct msgb *msg, u_int8_t link_id)
846{
847 u_int8_t l3_len = msg->tail - (u_int8_t *)msgb_l3(msg);
848 struct abis_rsl_rll_hdr *rh;
849
850 if (msg->lchan == NULL) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100851 LOGP(DRSL, LOGL_ERROR, "cannot send DATA REQUEST to unknown lchan\n");
Harald Welte59b04682009-06-10 05:40:52 +0800852 return -EINVAL;
853 }
854
855 /* First push the L3 IE tag and length */
856 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
857
858 /* Then push the RSL header */
859 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
860 init_llm_hdr(rh, RSL_MT_DATA_REQ);
861 rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
862 rh->chan_nr = lchan2chan_nr(msg->lchan);
863 rh->link_id = link_id;
864
865 msg->trx = msg->lchan->ts->trx;
866
867 return abis_rsl_sendmsg(msg);
868}
869
Harald Welteed9a5ab2009-08-09 13:47:35 +0200870/* Send "ESTABLISH REQUEST" message with given L3 Info payload */
871/* Chapter 8.3.1 */
872int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
873{
874 struct msgb *msg = rsl_msgb_alloc();
875 struct abis_rsl_rll_hdr *rh;
876
877 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
Harald Welte61402172009-08-09 14:13:58 +0200878 init_llm_hdr(rh, RSL_MT_EST_REQ);
Harald Welteed9a5ab2009-08-09 13:47:35 +0200879 //rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
880 rh->chan_nr = lchan2chan_nr(lchan);
881 rh->link_id = link_id;
882
883 msg->trx = lchan->ts->trx;
884
885 return abis_rsl_sendmsg(msg);
886}
887
Harald Welte0f2e3c12009-08-08 13:15:07 +0200888/* Chapter 8.3.7 Request the release of multiframe mode of RLL connection.
889 This is what higher layers should call. The BTS then responds with
890 RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
891 which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
892 lchan_free() */
893int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id)
894{
895 struct msgb *msg = rsl_msgb_alloc();
896 struct abis_rsl_rll_hdr *rh;
897
898 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
899 init_llm_hdr(rh, RSL_MT_REL_REQ);
900 //rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
901 rh->chan_nr = lchan2chan_nr(lchan);
902 rh->link_id = link_id;
Harald Weltead738562009-08-10 00:19:36 +0200903 msgb_tv_put(msg, RSL_IE_RELEASE_MODE, 0); /* normal release */
Harald Welte0f2e3c12009-08-08 13:15:07 +0200904
905 msg->trx = lchan->ts->trx;
906
907 return abis_rsl_sendmsg(msg);
908}
909
Harald Welte59b04682009-06-10 05:40:52 +0800910/* Chapter 8.4.2: Channel Activate Acknowledge */
911static int rsl_rx_chan_act_ack(struct msgb *msg)
912{
913 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
914
915 /* BTS has confirmed channel activation, we now need
916 * to assign the activated channel to the MS */
917 if (rslh->ie_chan != RSL_IE_CHAN_NR)
918 return -EINVAL;
Harald Welte6720a432009-11-29 22:45:52 +0100919
920 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_ACK, msg->lchan);
921
Harald Welte59b04682009-06-10 05:40:52 +0800922 return 0;
923}
924
925/* Chapter 8.4.3: Channel Activate NACK */
926static int rsl_rx_chan_act_nack(struct msgb *msg)
927{
928 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
929 struct tlv_parsed tp;
930
931 /* BTS has rejected channel activation ?!? */
932 if (dh->ie_chan != RSL_IE_CHAN_NR)
933 return -EINVAL;
934
935 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
936 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Weltef1a168d2009-07-28 17:58:09 +0200937 print_rsl_cause(TLVP_VAL(&tp, RSL_IE_CAUSE),
938 TLVP_LEN(&tp, RSL_IE_CAUSE));
939
Harald Welte6720a432009-11-29 22:45:52 +0100940 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_NACK, msg->lchan);
941
Harald Weltecddb9802009-08-09 19:50:08 +0200942 lchan_free(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +0800943 return 0;
944}
945
946/* Chapter 8.4.4: Connection Failure Indication */
947static int rsl_rx_conn_fail(struct msgb *msg)
948{
949 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
950 struct tlv_parsed tp;
951
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100952 /* FIXME: print which channel */
953 LOGP(DRSL, LOGL_NOTICE, "CONNECTION FAIL: RELEASING\n");
Harald Welte59b04682009-06-10 05:40:52 +0800954
955 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
956
Harald Weltef1a168d2009-07-28 17:58:09 +0200957 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
958 print_rsl_cause(TLVP_VAL(&tp, RSL_IE_CAUSE),
959 TLVP_LEN(&tp, RSL_IE_CAUSE));
960
Harald Welte59b04682009-06-10 05:40:52 +0800961 /* FIXME: only free it after channel release ACK */
Harald Welte85a163c2009-08-10 11:43:22 +0200962 return rsl_rf_chan_release(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +0800963}
964
Harald Weltec20bd1d2009-11-29 19:07:28 +0100965static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
966 const char *prefix)
967{
Harald Welte0e4fa782009-12-16 16:52:07 +0100968 DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",
969 prefix, rxlev2dbm(mru->full.rx_lev),
970 prefix, rxlev2dbm(mru->sub.rx_lev));
Harald Weltec20bd1d2009-11-29 19:07:28 +0100971 DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",
972 prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);
973}
974
975static void print_meas_rep(struct gsm_meas_rep *mr)
976{
Harald Welte0e4fa782009-12-16 16:52:07 +0100977 int i;
978
Harald Weltec20bd1d2009-11-29 19:07:28 +0100979 DEBUGP(DMEAS, "MEASUREMENT RESULT NR=%d ", mr->nr);
980
981 if (mr->flags & MEAS_REP_F_DL_DTX)
982 DEBUGPC(DMEAS, "DTXd ");
983
984 print_meas_rep_uni(&mr->ul, "ul");
985 DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
986 if (mr->flags & MEAS_REP_F_MS_TO)
987 DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
988
989 if (mr->flags & MEAS_REP_F_MS_L1) {
Harald Welte0e4fa782009-12-16 16:52:07 +0100990 DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100991 DEBUGPC(DMEAS, "L1_FPC=%u ",
992 mr->flags & MEAS_REP_F_FPC ? 1 : 0);
993 DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);
994 }
995
996 if (mr->flags & MEAS_REP_F_UL_DTX)
997 DEBUGPC(DMEAS, "DTXu ");
998 if (mr->flags & MEAS_REP_F_BA1)
999 DEBUGPC(DMEAS, "BA1 ");
1000 if (!(mr->flags & MEAS_REP_F_DL_VALID))
1001 DEBUGPC(DMEAS, "NOT VALID ");
1002 else
1003 print_meas_rep_uni(&mr->dl, "dl");
1004
1005 DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);
Harald Welte0b833f82009-12-19 18:33:05 +01001006 if (mr->num_cell == 7)
1007 return;
Harald Welte0e4fa782009-12-16 16:52:07 +01001008 for (i = 0; i < mr->num_cell; i++) {
1009 struct gsm_meas_rep_cell *mrc = &mr->cell[i];
1010 DEBUGP(DMEAS, "ARFCN=%u BSIC=%u => %d dBm\n", mrc->arfcn, mrc->bsic,
1011 rxlev2dbm(mrc->rxlev));
1012 }
Harald Weltec20bd1d2009-11-29 19:07:28 +01001013}
1014
Harald Welte59b04682009-06-10 05:40:52 +08001015static int rsl_rx_meas_res(struct msgb *msg)
1016{
1017 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1018 struct tlv_parsed tp;
Harald Weltef9476812009-12-15 21:36:05 +01001019 struct gsm_meas_rep *mr = lchan_next_meas_rep(msg->lchan);
Harald Weltec20bd1d2009-11-29 19:07:28 +01001020 u_int8_t len;
1021 const u_int8_t *val;
1022 int rc;
Harald Welte59b04682009-06-10 05:40:52 +08001023
Harald Weltef9476812009-12-15 21:36:05 +01001024 memset(mr, 0, sizeof(*mr));
Harald Welteaa0efa12009-12-16 23:29:34 +01001025 mr->lchan = msg->lchan;
Harald Welte4efcc542009-11-30 19:16:47 +01001026
Harald Welte59b04682009-06-10 05:40:52 +08001027 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
1028
Harald Weltec20bd1d2009-11-29 19:07:28 +01001029 if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) ||
1030 !TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) ||
1031 !TLVP_PRESENT(&tp, RSL_IE_BS_POWER))
1032 return -EIO;
1033
1034 /* Mandatory Parts */
Harald Weltef9476812009-12-15 21:36:05 +01001035 mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR);
Harald Weltec20bd1d2009-11-29 19:07:28 +01001036
1037 len = TLVP_LEN(&tp, RSL_IE_UPLINK_MEAS);
1038 val = TLVP_VAL(&tp, RSL_IE_UPLINK_MEAS);
1039 if (len >= 3) {
1040 if (val[0] & 0x40)
Harald Weltef9476812009-12-15 21:36:05 +01001041 mr->flags |= MEAS_REP_F_DL_DTX;
1042 mr->ul.full.rx_lev = val[0] & 0x3f;
1043 mr->ul.sub.rx_lev = val[1] & 0x3f;
1044 mr->ul.full.rx_qual = val[2]>>3 & 0x7;
1045 mr->ul.sub.rx_qual = val[2] & 0x7;
Harald Welte59b04682009-06-10 05:40:52 +08001046 }
Harald Weltec20bd1d2009-11-29 19:07:28 +01001047
Harald Weltef9476812009-12-15 21:36:05 +01001048 mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
Harald Weltec20bd1d2009-11-29 19:07:28 +01001049
1050 /* Optional Parts */
Harald Welte59b04682009-06-10 05:40:52 +08001051 if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET))
Harald Weltef9476812009-12-15 21:36:05 +01001052 mr->ms_timing_offset =
Harald Weltec20bd1d2009-11-29 19:07:28 +01001053 *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET);
1054
Harald Weltea1467eb2009-06-20 18:44:35 +02001055 if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) {
Harald Weltec20bd1d2009-11-29 19:07:28 +01001056 val = TLVP_VAL(&tp, RSL_IE_L1_INFO);
Harald Weltef9476812009-12-15 21:36:05 +01001057 mr->flags |= MEAS_REP_F_MS_L1;
1058 mr->ms_l1.pwr = ms_pwr_dbm(msg->trx->bts->band, val[0] >> 3);
Harald Weltec20bd1d2009-11-29 19:07:28 +01001059 if (val[0] & 0x04)
Harald Weltef9476812009-12-15 21:36:05 +01001060 mr->flags |= MEAS_REP_F_FPC;
1061 mr->ms_l1.ta = val[1];
Harald Weltea1467eb2009-06-20 18:44:35 +02001062 }
Harald Welte59b04682009-06-10 05:40:52 +08001063 if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
Holger Hans Peter Freyther6d0c8b42009-10-22 15:43:55 +02001064 msg->l3h = (u_int8_t *) TLVP_VAL(&tp, RSL_IE_L3_INFO);
Harald Weltef9476812009-12-15 21:36:05 +01001065 rc = gsm48_parse_meas_rep(mr, msg);
Harald Weltec20bd1d2009-11-29 19:07:28 +01001066 if (rc < 0)
1067 return rc;
1068 }
1069
Harald Weltef9476812009-12-15 21:36:05 +01001070 print_meas_rep(mr);
Harald Welte59b04682009-06-10 05:40:52 +08001071
Harald Weltef9476812009-12-15 21:36:05 +01001072 dispatch_signal(SS_LCHAN, S_LCHAN_MEAS_REP, mr);
Harald Welte4efcc542009-11-30 19:16:47 +01001073
Harald Welte59b04682009-06-10 05:40:52 +08001074 return 0;
1075}
1076
Harald Welte6720a432009-11-29 22:45:52 +01001077/* Chapter 8.4.7 */
1078static int rsl_rx_hando_det(struct msgb *msg)
1079{
1080 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1081 struct tlv_parsed tp;
1082
1083 DEBUGP(DRSL, "HANDOVER DETECT ");
1084
1085 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
1086
1087 if (TLVP_PRESENT(&tp, RSL_IE_ACCESS_DELAY))
1088 DEBUGPC(DRSL, "access delay = %u\n",
1089 *TLVP_VAL(&tp, RSL_IE_ACCESS_DELAY));
1090 else
1091 DEBUGPC(DRSL, "\n");
1092
1093 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_DETECT, msg->lchan);
1094
1095 return 0;
1096}
1097
Harald Welte59b04682009-06-10 05:40:52 +08001098static int abis_rsl_rx_dchan(struct msgb *msg)
1099{
1100 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1101 int rc = 0;
1102 char *ts_name;
1103
1104 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
1105 ts_name = gsm_ts_name(msg->lchan->ts);
1106
Harald Welte02993682009-06-27 02:53:10 +02001107 if (rslh->c.msg_type != RSL_MT_MEAS_RES)
1108 DEBUGP(DRSL, "channel=%s chan_nr=0x%02x ", ts_name, rslh->chan_nr);
Harald Welte59b04682009-06-10 05:40:52 +08001109
1110 switch (rslh->c.msg_type) {
1111 case RSL_MT_CHAN_ACTIV_ACK:
1112 DEBUGPC(DRSL, "CHANNEL ACTIVATE ACK\n");
1113 rc = rsl_rx_chan_act_ack(msg);
1114 break;
1115 case RSL_MT_CHAN_ACTIV_NACK:
1116 DEBUGPC(DRSL, "CHANNEL ACTIVATE NACK\n");
1117 rc = rsl_rx_chan_act_nack(msg);
1118 break;
1119 case RSL_MT_CONN_FAIL:
1120 rc = rsl_rx_conn_fail(msg);
1121 break;
1122 case RSL_MT_MEAS_RES:
1123 rc = rsl_rx_meas_res(msg);
1124 break;
Harald Welte6720a432009-11-29 22:45:52 +01001125 case RSL_MT_HANDO_DET:
1126 rc = rsl_rx_hando_det(msg);
1127 break;
Harald Welte59b04682009-06-10 05:40:52 +08001128 case RSL_MT_RF_CHAN_REL_ACK:
1129 DEBUGPC(DRSL, "RF CHANNEL RELEASE ACK\n");
1130 lchan_free(msg->lchan);
1131 break;
1132 case RSL_MT_MODE_MODIFY_ACK:
1133 DEBUGPC(DRSL, "CHANNEL MODE MODIFY ACK\n");
1134 break;
1135 case RSL_MT_MODE_MODIFY_NACK:
1136 DEBUGPC(DRSL, "CHANNEL MODE MODIFY NACK\n");
1137 break;
Harald Welteaed946e2009-10-24 10:29:22 +02001138 case RSL_MT_IPAC_PDCH_ACT_ACK:
1139 DEBUGPC(DRSL, "IPAC PDCH ACT ACK\n");
1140 break;
1141 case RSL_MT_IPAC_PDCH_ACT_NACK:
1142 DEBUGPC(DRSL, "IPAC PDCH ACT NACK\n");
1143 break;
1144 case RSL_MT_IPAC_PDCH_DEACT_ACK:
1145 DEBUGPC(DRSL, "IPAC PDCH DEACT ACK\n");
1146 break;
1147 case RSL_MT_IPAC_PDCH_DEACT_NACK:
1148 DEBUGPC(DRSL, "IPAC PDCH DEACT NACK\n");
1149 break;
Harald Welte59b04682009-06-10 05:40:52 +08001150 case RSL_MT_PHY_CONTEXT_CONF:
1151 case RSL_MT_PREPROC_MEAS_RES:
1152 case RSL_MT_TALKER_DET:
1153 case RSL_MT_LISTENER_DET:
1154 case RSL_MT_REMOTE_CODEC_CONF_REP:
1155 case RSL_MT_MR_CODEC_MOD_ACK:
1156 case RSL_MT_MR_CODEC_MOD_NACK:
1157 case RSL_MT_MR_CODEC_MOD_PER:
1158 DEBUGPC(DRSL, "Unimplemented Abis RSL DChan msg 0x%02x\n",
1159 rslh->c.msg_type);
1160 break;
1161 default:
1162 DEBUGPC(DRSL, "unknown Abis RSL DChan msg 0x%02x\n",
1163 rslh->c.msg_type);
1164 return -EINVAL;
1165 }
1166
1167 return rc;
1168}
1169
1170static int rsl_rx_error_rep(struct msgb *msg)
1171{
1172 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Weltef1a168d2009-07-28 17:58:09 +02001173 struct tlv_parsed tp;
Harald Welte59b04682009-06-10 05:40:52 +08001174
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001175 LOGP(DRSL, LOGL_ERROR, "ERROR REPORT ");
Harald Weltef1a168d2009-07-28 17:58:09 +02001176
1177 rsl_tlv_parse(&tp, rslh->data, msgb_l2len(msg)-sizeof(*rslh));
1178
1179 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
1180 print_rsl_cause(TLVP_VAL(&tp, RSL_IE_CAUSE),
1181 TLVP_LEN(&tp, RSL_IE_CAUSE));
1182
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001183 LOGPC(DRSL, LOGL_ERROR, "\n");
Harald Welte59b04682009-06-10 05:40:52 +08001184
1185 return 0;
1186}
1187
1188static int abis_rsl_rx_trx(struct msgb *msg)
1189{
1190 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
1191 int rc = 0;
1192
1193 switch (rslh->msg_type) {
1194 case RSL_MT_ERROR_REPORT:
1195 rc = rsl_rx_error_rep(msg);
1196 break;
1197 case RSL_MT_RF_RES_IND:
1198 /* interference on idle channels of TRX */
1199 //DEBUGP(DRSL, "TRX: RF Interference Indication\n");
1200 break;
1201 case RSL_MT_OVERLOAD:
1202 /* indicate CCCH / ACCH / processor overload */
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001203 LOGP(DRSL, LOGL_ERROR, "TRX: CCCH/ACCH/CPU Overload\n");
Harald Welte59b04682009-06-10 05:40:52 +08001204 break;
1205 default:
1206 DEBUGP(DRSL, "Unknown Abis RSL TRX message type 0x%02x\n",
1207 rslh->msg_type);
1208 return -EINVAL;
1209 }
1210 return rc;
1211}
1212
Harald Welte427dbc42009-08-10 00:26:10 +02001213/* If T3101 expires, we never received a response to IMMEDIATE ASSIGN */
1214static void t3101_expired(void *data)
1215{
1216 struct gsm_lchan *lchan = data;
1217
Harald Welte85a163c2009-08-10 11:43:22 +02001218 rsl_rf_chan_release(lchan);
Harald Welte427dbc42009-08-10 00:26:10 +02001219}
1220
Harald Welte59b04682009-06-10 05:40:52 +08001221/* MS has requested a channel on the RACH */
1222static int rsl_rx_chan_rqd(struct msgb *msg)
1223{
1224 struct gsm_bts *bts = msg->trx->bts;
1225 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
1226 struct gsm48_req_ref *rqd_ref;
1227 struct gsm48_imm_ass ia;
1228 enum gsm_chan_t lctype;
1229 enum gsm_chreq_reason_t chreq_reason;
1230 struct gsm_lchan *lchan;
1231 u_int8_t rqd_ta;
1232 int ret;
1233
1234 u_int16_t arfcn;
1235 u_int8_t ts_number, subch;
1236
1237 /* parse request reference to be used in immediate assign */
1238 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
1239 return -EINVAL;
1240
1241 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
1242
1243 /* parse access delay and use as TA */
1244 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
1245 return -EINVAL;
1246 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
1247
1248 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
1249 * request reference RA */
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001250 lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
1251 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
Harald Welte59b04682009-06-10 05:40:52 +08001252
1253 /* check availability / allocate channel */
1254 lchan = lchan_alloc(bts, lctype);
1255 if (!lchan) {
Harald Welte059b6a82009-12-12 20:53:23 +01001256 DEBUGP(DRSL, "CHAN RQD: no resources for %s 0x%x\n",
1257 gsm_lchan_name(lctype), rqd_ref->ra);
Harald Welte59b04682009-06-10 05:40:52 +08001258 /* FIXME: send some kind of reject ?!? */
1259 return -ENOMEM;
1260 }
1261
1262 ts_number = lchan->ts->nr;
1263 arfcn = lchan->ts->trx->arfcn;
1264 subch = lchan->nr;
1265
Harald Welted2dd9de2009-08-30 15:37:11 +09001266 lchan->encr.alg_id = RSL_ENC_ALG_A5(0); /* no encryption */
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001267 lchan->ms_power = ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
Harald Welte9a229e12009-08-10 00:45:40 +02001268 lchan->bs_power = 0; /* 0dB reduction, output power = Pn */
Harald Welte39274f42009-07-29 15:41:29 +02001269 lchan->rsl_cmode = RSL_CMOD_SPD_SIGN;
Harald Welte77234e12009-08-28 23:28:28 +09001270 lchan->tch_mode = GSM48_CMODE_SIGN;
Harald Welteb90d7bd2009-12-17 00:31:10 +01001271 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta, 0);
Harald Welte59b04682009-06-10 05:40:52 +08001272
1273 /* create IMMEDIATE ASSIGN 04.08 messge */
1274 memset(&ia, 0, sizeof(ia));
1275 ia.l2_plen = 0x2d;
1276 ia.proto_discr = GSM48_PDISC_RR;
1277 ia.msg_type = GSM48_MT_RR_IMM_ASS;
1278 ia.page_mode = GSM48_PM_SAME;
1279 ia.chan_desc.chan_nr = lchan2chan_nr(lchan);
1280 ia.chan_desc.h0.h = 0;
1281 ia.chan_desc.h0.arfcn_high = arfcn >> 8;
1282 ia.chan_desc.h0.arfcn_low = arfcn & 0xff;
Harald Welte63d23c82009-07-21 20:55:56 +02001283 ia.chan_desc.h0.tsc = bts->tsc;
Harald Welte59b04682009-06-10 05:40:52 +08001284 /* use request reference extracted from CHAN_RQD */
1285 memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref));
1286 ia.timing_advance = rqd_ta;
1287 ia.mob_alloc_len = 0;
1288
1289 DEBUGP(DRSL, "Activating ARFCN(%u) TS(%u) SS(%u) lctype %s "
1290 "chan_nr=0x%02x r=%s ra=0x%02x\n",
1291 arfcn, ts_number, subch, gsm_lchan_name(lchan->type),
1292 ia.chan_desc.chan_nr, gsm_chreq_name(chreq_reason),
1293 rqd_ref->ra);
1294
Harald Welte427dbc42009-08-10 00:26:10 +02001295 /* Start timer T3101 to wait for GSM48_MT_RR_PAG_RESP */
1296 lchan->T3101.cb = t3101_expired;
1297 lchan->T3101.data = lchan;
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001298 bsc_schedule_timer(&lchan->T3101, bts->network->T3101, 0);
Harald Welte59b04682009-06-10 05:40:52 +08001299
1300 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
1301 ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia);
1302
1303 return ret;
1304}
1305
1306/* MS has requested a channel on the RACH */
1307static int rsl_rx_ccch_load(struct msgb *msg)
1308{
1309 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1310 u_int16_t pg_buf_space;
1311 u_int16_t rach_slot_count = -1;
1312 u_int16_t rach_busy_count = -1;
1313 u_int16_t rach_access_count = -1;
1314
1315 switch (rslh->data[0]) {
1316 case RSL_IE_PAGING_LOAD:
1317 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
1318 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
1319 break;
1320 case RSL_IE_RACH_LOAD:
1321 if (msg->data_len >= 7) {
1322 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
1323 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
1324 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
1325 }
1326 break;
1327 default:
1328 break;
1329 }
1330
1331 return 0;
1332}
1333
1334static int abis_rsl_rx_cchan(struct msgb *msg)
1335{
1336 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1337 int rc = 0;
1338
1339 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
1340
1341 switch (rslh->c.msg_type) {
1342 case RSL_MT_CHAN_RQD:
1343 /* MS has requested a channel on the RACH */
1344 rc = rsl_rx_chan_rqd(msg);
1345 break;
1346 case RSL_MT_CCCH_LOAD_IND:
1347 /* current load on the CCCH */
1348 rc = rsl_rx_ccch_load(msg);
1349 break;
1350 case RSL_MT_DELETE_IND:
1351 /* CCCH overloaded, IMM_ASSIGN was dropped */
1352 case RSL_MT_CBCH_LOAD_IND:
1353 /* current load on the CBCH */
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001354 LOGP(DRSL, LOGL_NOTICE, "Unimplemented Abis RSL TRX message "
1355 "type 0x%02x\n", rslh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001356 break;
1357 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001358 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message type "
1359 "0x%02x\n", rslh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001360 return -EINVAL;
1361 }
1362
1363 return rc;
1364}
1365
1366static int rsl_rx_rll_err_ind(struct msgb *msg)
1367{
1368 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1369 u_int8_t *rlm_cause = rllh->data;
1370
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001371 LOGP(DRLL, LOGL_ERROR, "ERROR INDICATION cause=0x%02x\n", rlm_cause[1]);
Harald Welteed9a5ab2009-08-09 13:47:35 +02001372
1373 rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND);
Harald Welte59b04682009-06-10 05:40:52 +08001374
Harald Welte692f5852009-07-04 09:40:05 +02001375 if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED)
Harald Welte85a163c2009-08-10 11:43:22 +02001376 return rsl_rf_chan_release(msg->lchan);
Harald Welte692f5852009-07-04 09:40:05 +02001377
Harald Welte59b04682009-06-10 05:40:52 +08001378 return 0;
1379}
1380
1381/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
1382 0x02, 0x06,
1383 0x01, 0x20,
1384 0x02, 0x00,
1385 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
1386
1387static int abis_rsl_rx_rll(struct msgb *msg)
1388{
1389 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1390 int rc = 0;
1391 char *ts_name;
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001392 u_int8_t sapi = rllh->link_id & 7;
Harald Welte59b04682009-06-10 05:40:52 +08001393
1394 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
1395 ts_name = gsm_ts_name(msg->lchan->ts);
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001396 DEBUGP(DRLL, "channel=%s chan_nr=0x%02x sapi=%u ", ts_name,
1397 rllh->chan_nr, sapi);
Harald Welte59b04682009-06-10 05:40:52 +08001398
1399 switch (rllh->c.msg_type) {
1400 case RSL_MT_DATA_IND:
1401 DEBUGPC(DRLL, "DATA INDICATION\n");
1402 if (msgb_l2len(msg) >
1403 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1404 rllh->data[0] == RSL_IE_L3_INFO) {
1405 msg->l3h = &rllh->data[3];
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001406 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte59b04682009-06-10 05:40:52 +08001407 }
1408 break;
1409 case RSL_MT_EST_IND:
1410 DEBUGPC(DRLL, "ESTABLISH INDICATION\n");
Harald Welte427dbc42009-08-10 00:26:10 +02001411 /* lchan is established, stop T3101 */
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001412 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_MS;
Harald Welte427dbc42009-08-10 00:26:10 +02001413 bsc_del_timer(&msg->lchan->T3101);
Harald Welte59b04682009-06-10 05:40:52 +08001414 if (msgb_l2len(msg) >
1415 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1416 rllh->data[0] == RSL_IE_L3_INFO) {
1417 msg->l3h = &rllh->data[3];
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001418 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte59b04682009-06-10 05:40:52 +08001419 }
1420 break;
Harald Welteed9a5ab2009-08-09 13:47:35 +02001421 case RSL_MT_EST_CONF:
Harald Welte61402172009-08-09 14:13:58 +02001422 DEBUGPC(DRLL, "ESTABLISH CONFIRM\n");
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001423 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_NET;
Harald Welteed9a5ab2009-08-09 13:47:35 +02001424 rll_indication(msg->lchan, rllh->link_id,
1425 BSC_RLLR_IND_EST_CONF);
1426 break;
Harald Welte59b04682009-06-10 05:40:52 +08001427 case RSL_MT_REL_IND:
Harald Welte0f2e3c12009-08-08 13:15:07 +02001428 /* BTS informs us of having received DISC from MS */
Harald Welteb6601442009-08-04 02:50:21 +02001429 DEBUGPC(DRLL, "RELEASE INDICATION\n");
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001430 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welteed9a5ab2009-08-09 13:47:35 +02001431 rll_indication(msg->lchan, rllh->link_id,
1432 BSC_RLLR_IND_REL_IND);
Harald Welte0f2e3c12009-08-08 13:15:07 +02001433 /* we can now releae the channel on the BTS/Abis side */
Harald Welte85a163c2009-08-10 11:43:22 +02001434 /* FIXME: officially we need to start T3111 and wait for
1435 * some grace period */
1436 rsl_rf_chan_release(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001437 break;
1438 case RSL_MT_REL_CONF:
Harald Welte0f2e3c12009-08-08 13:15:07 +02001439 /* BTS informs us of having received UA from MS,
1440 * in response to DISC that we've sent earlier */
Harald Welteb6601442009-08-04 02:50:21 +02001441 DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001442 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welte0f2e3c12009-08-08 13:15:07 +02001443 /* we can now releae the channel on the BTS/Abis side */
Harald Welte85a163c2009-08-10 11:43:22 +02001444 /* FIXME: officially we need to start T3111 and wait for
1445 * some grace period */
1446 rsl_rf_chan_release(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001447 break;
1448 case RSL_MT_ERROR_IND:
Harald Welte59b04682009-06-10 05:40:52 +08001449 rc = rsl_rx_rll_err_ind(msg);
1450 break;
1451 case RSL_MT_UNIT_DATA_IND:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001452 LOGP(DRLL, LOGL_NOTICE, "unimplemented Abis RLL message "
1453 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001454 break;
1455 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001456 LOGP(DRLL, LOGL_NOTICE, "unknown Abis RLL message "
1457 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001458 }
Harald Welte59b04682009-06-10 05:40:52 +08001459 return rc;
1460}
1461
Harald Welteb284b472009-12-02 01:58:23 +05301462static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
Harald Welte98d79f92009-07-28 18:11:56 +02001463{
Harald Welteb284b472009-12-02 01:58:23 +05301464 switch (lchan->tch_mode) {
Harald Welte98d79f92009-07-28 18:11:56 +02001465 case GSM48_CMODE_SPEECH_V1:
Harald Welteb284b472009-12-02 01:58:23 +05301466 switch (lchan->type) {
1467 case GSM_LCHAN_TCH_F:
1468 return 0x00;
1469 case GSM_LCHAN_TCH_H:
1470 return 0x03;
1471 default:
1472 break;
1473 }
Harald Welte98d79f92009-07-28 18:11:56 +02001474 case GSM48_CMODE_SPEECH_EFR:
Harald Welteb284b472009-12-02 01:58:23 +05301475 switch (lchan->type) {
1476 case GSM_LCHAN_TCH_F:
1477 return 0x01;
1478 /* there's no half-rate EFR */
1479 default:
1480 break;
1481 }
Harald Welte98d79f92009-07-28 18:11:56 +02001482 case GSM48_CMODE_SPEECH_AMR:
Harald Welteb284b472009-12-02 01:58:23 +05301483 switch (lchan->type) {
1484 case GSM_LCHAN_TCH_F:
1485 return 0x02;
1486 case GSM_LCHAN_TCH_H:
1487 return 0x05;
1488 default:
1489 break;
1490 }
1491 default:
1492 break;
Harald Welte98d79f92009-07-28 18:11:56 +02001493 }
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001494 LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access speech mode for "
Harald Welteb284b472009-12-02 01:58:23 +05301495 "tch_mode == 0x%02x\n", lchan->tch_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001496 return 0;
Harald Welte98d79f92009-07-28 18:11:56 +02001497}
1498
Harald Welte59b04682009-06-10 05:40:52 +08001499/* ip.access specific RSL extensions */
Harald Weltebffa4992009-12-19 16:42:06 +01001500static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
1501{
1502 struct in_addr ip;
1503 u_int16_t port, conn_id;
1504
1505 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_IP)) {
1506 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_IP));
1507 DEBUGPC(DRSL, "LOCAL_IP=%s ", inet_ntoa(ip));
1508 lchan->abis_ip.bound_ip = ntohl(ip.s_addr);
1509 }
1510
1511 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_PORT)) {
1512 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_PORT));
1513 port = ntohs(port);
1514 DEBUGPC(DRSL, "LOCAL_PORT=%u ", port);
1515 lchan->abis_ip.bound_port = port;
1516 }
1517
1518 if (TLVP_PRESENT(tv, RSL_IE_IPAC_CONN_ID)) {
1519 conn_id = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_CONN_ID));
1520 conn_id = ntohs(conn_id);
1521 DEBUGPC(DRSL, "CON_ID=%u ", conn_id);
1522 lchan->abis_ip.conn_id = conn_id;
1523 }
1524
1525 if (TLVP_PRESENT(tv, RSL_IE_IPAC_RTP_PAYLOAD2)) {
1526 lchan->abis_ip.rtp_payload2 =
1527 *TLVP_VAL(tv, RSL_IE_IPAC_RTP_PAYLOAD2);
1528 DEBUGPC(DRSL, "RTP_PAYLOAD2=0x%02x ",
1529 lchan->abis_ip.rtp_payload2);
1530 }
1531
1532 if (TLVP_PRESENT(tv, RSL_IE_IPAC_SPEECH_MODE)) {
1533 lchan->abis_ip.speech_mode =
1534 *TLVP_VAL(tv, RSL_IE_IPAC_SPEECH_MODE);
1535 DEBUGPC(DRSL, "speech_mode=0x%02x ",
1536 lchan->abis_ip.speech_mode);
1537 }
1538
1539 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_IP)) {
1540 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_IP));
1541 DEBUGPC(DRSL, "REMOTE_IP=%s ", inet_ntoa(ip));
1542 lchan->abis_ip.connect_ip = ntohl(ip.s_addr);
1543 }
1544
1545 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_PORT)) {
1546 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_PORT));
1547 port = ntohs(port);
1548 DEBUGPC(DRSL, "REMOTE_PORT=%u ", port);
1549 lchan->abis_ip.connect_port = port;
1550 }
1551}
1552
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001553int rsl_ipacc_crcx(struct gsm_lchan *lchan)
Harald Welte59b04682009-06-10 05:40:52 +08001554{
1555 struct msgb *msg = rsl_msgb_alloc();
1556 struct abis_rsl_dchan_hdr *dh;
1557
1558 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001559 init_dchan_hdr(dh, RSL_MT_IPAC_CRCX);
Harald Welte59b04682009-06-10 05:40:52 +08001560 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1561 dh->chan_nr = lchan2chan_nr(lchan);
1562
Harald Welte98d79f92009-07-28 18:11:56 +02001563 /* 0x1- == receive-only, 0x-1 == EFR codec */
Harald Weltebffa4992009-12-19 16:42:06 +01001564 lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
1565 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001566
Harald Weltefb4a9e92009-07-29 12:12:18 +02001567 DEBUGP(DRSL, "channel=%s chan_nr=0x%02x IPAC_BIND "
1568 "speech_mode=0x%02x\n", gsm_ts_name(lchan->ts),
Harald Weltebffa4992009-12-19 16:42:06 +01001569 dh->chan_nr, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001570
Harald Welte59b04682009-06-10 05:40:52 +08001571 msg->trx = lchan->ts->trx;
1572
1573 return abis_rsl_sendmsg(msg);
1574}
1575
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001576int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
Harald Weltebffa4992009-12-19 16:42:06 +01001577 u_int8_t rtp_payload2)
Harald Welte59b04682009-06-10 05:40:52 +08001578{
1579 struct msgb *msg = rsl_msgb_alloc();
1580 struct abis_rsl_dchan_hdr *dh;
Harald Weltebffa4992009-12-19 16:42:06 +01001581 u_int32_t *att_ip;
Harald Welte98d79f92009-07-28 18:11:56 +02001582 struct in_addr ia;
Harald Welte59b04682009-06-10 05:40:52 +08001583
1584 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001585 init_dchan_hdr(dh, RSL_MT_IPAC_MDCX);
Harald Welte59b04682009-06-10 05:40:52 +08001586 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1587 dh->chan_nr = lchan2chan_nr(lchan);
1588
Harald Weltebffa4992009-12-19 16:42:06 +01001589 /* we need to store these now as MDCX_ACK does not return them :( */
1590 lchan->abis_ip.rtp_payload2 = rtp_payload2;
1591 lchan->abis_ip.connect_port = port;
1592 lchan->abis_ip.connect_ip = ip;
1593
Harald Weltefb4a9e92009-07-29 12:12:18 +02001594 /* 0x0- == both directions, 0x-1 == EFR codec */
Harald Weltebffa4992009-12-19 16:42:06 +01001595 lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
Harald Weltefb4a9e92009-07-29 12:12:18 +02001596
Harald Welte98d79f92009-07-28 18:11:56 +02001597 ia.s_addr = htonl(ip);
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001598 DEBUGP(DRSL, "channel=%s chan_nr=0x%02x IPAC_MDCX "
Harald Weltefb4a9e92009-07-29 12:12:18 +02001599 "IP=%s PORT=%d RTP_PAYLOAD2=%d CONN_ID=%d speech_mode=0x%02x\n",
Harald Weltebffa4992009-12-19 16:42:06 +01001600 gsm_ts_name(lchan->ts), dh->chan_nr, inet_ntoa(ia), port,
1601 rtp_payload2, lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001602
Harald Weltebffa4992009-12-19 16:42:06 +01001603 msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
1604 msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
1605 att_ip = (u_int32_t *) msgb_put(msg, sizeof(ip));
1606 *att_ip = ia.s_addr;
1607 msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
1608 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001609 if (rtp_payload2)
1610 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
1611
Harald Welte59b04682009-06-10 05:40:52 +08001612 msg->trx = lchan->ts->trx;
1613
1614 return abis_rsl_sendmsg(msg);
1615}
1616
Harald Welteaed946e2009-10-24 10:29:22 +02001617int rsl_ipacc_pdch_activate(struct gsm_lchan *lchan)
1618{
1619 struct msgb *msg = rsl_msgb_alloc();
1620 struct abis_rsl_dchan_hdr *dh;
1621
1622 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
1623 init_dchan_hdr(dh, RSL_MT_IPAC_PDCH_ACT);
1624 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
1625 dh->chan_nr = lchan2chan_nr(lchan);
1626
1627 DEBUGP(DRSL, "channel=%s chan_nr=0x%02x IPAC_PDCH_ACT\n",
1628 gsm_ts_name(lchan->ts), dh->chan_nr);
1629
1630 msg->trx = lchan->ts->trx;
1631
1632 return abis_rsl_sendmsg(msg);
1633}
1634
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001635static int abis_rsl_rx_ipacc_crcx_ack(struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +08001636{
1637 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1638 struct tlv_parsed tv;
Harald Welte87504212009-12-02 01:56:49 +05301639 struct gsm_lchan *lchan = msg->lchan;
Harald Welte59b04682009-06-10 05:40:52 +08001640
1641 /* the BTS has acknowledged a local bind, it now tells us the IP
1642 * address and port number to which it has bound the given logical
1643 * channel */
1644
1645 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1646 if (!TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_PORT) ||
1647 !TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_IP) ||
Harald Welteb9498952009-07-12 09:45:05 +02001648 !TLVP_PRESENT(&tv, RSL_IE_IPAC_CONN_ID)) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001649 LOGP(DRSL, LOGL_NOTICE, "mandatory IE missing");
Harald Welte59b04682009-06-10 05:40:52 +08001650 return -EINVAL;
1651 }
Harald Weltebffa4992009-12-19 16:42:06 +01001652 ipac_parse_rtp(lchan, &tv);
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001653 dispatch_signal(SS_ABISIP, S_ABISIP_CRCX_ACK, msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001654
1655 return 0;
1656}
1657
Harald Weltebffa4992009-12-19 16:42:06 +01001658static int abis_rsl_rx_ipacc_mdcx_ack(struct msgb *msg)
1659{
1660 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1661 struct tlv_parsed tv;
1662 struct gsm_lchan *lchan = msg->lchan;
1663
1664 /* the BTS has acknowledged a remote connect request and
1665 * it now tells us the IP address and port number to which it has
1666 * connected the given logical channel */
1667
1668 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1669 ipac_parse_rtp(lchan, &tv);
1670 dispatch_signal(SS_ABISIP, S_ABISIP_MDCX_ACK, msg->lchan);
1671
1672 return 0;
1673}
1674
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001675static int abis_rsl_rx_ipacc_dlcx_ind(struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +08001676{
1677 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1678 struct tlv_parsed tv;
1679
1680 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte59b04682009-06-10 05:40:52 +08001681
Harald Weltef1a168d2009-07-28 17:58:09 +02001682 if (TLVP_PRESENT(&tv, RSL_IE_CAUSE))
1683 print_rsl_cause(TLVP_VAL(&tv, RSL_IE_CAUSE),
1684 TLVP_LEN(&tv, RSL_IE_CAUSE));
Harald Welte59b04682009-06-10 05:40:52 +08001685
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001686 dispatch_signal(SS_ABISIP, S_ABISIP_DLCX_IND, msg->lchan);
Harald Welteba4e58d2009-07-28 18:02:05 +02001687
Harald Welte59b04682009-06-10 05:40:52 +08001688 return 0;
1689}
1690
1691static int abis_rsl_rx_ipacc(struct msgb *msg)
1692{
1693 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1694 int rc = 0;
1695
1696 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
1697 DEBUGP(DRSL, "channel=%s chan_nr=0x%02x ",
1698 gsm_ts_name(msg->lchan->ts), rllh->chan_nr);
1699
1700 switch (rllh->c.msg_type) {
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001701 case RSL_MT_IPAC_CRCX_ACK:
1702 DEBUGPC(DRSL, "IPAC_CRCX_ACK ");
1703 rc = abis_rsl_rx_ipacc_crcx_ack(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001704 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001705 case RSL_MT_IPAC_CRCX_NACK:
Harald Welte59b04682009-06-10 05:40:52 +08001706 /* somehow the BTS was unable to bind the lchan to its local
1707 * port?!? */
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001708 DEBUGPC(DRSL, "IPAC_CRCX_NACK ");
Harald Welte59b04682009-06-10 05:40:52 +08001709 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001710 case RSL_MT_IPAC_MDCX_ACK:
Harald Welte59b04682009-06-10 05:40:52 +08001711 /* the BTS tells us that a connect operation was successful */
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001712 DEBUGPC(DRSL, "IPAC_MDCX_ACK ");
Harald Weltebffa4992009-12-19 16:42:06 +01001713 rc = abis_rsl_rx_ipacc_mdcx_ack(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001714 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001715 case RSL_MT_IPAC_MDCX_NACK:
Harald Welte59b04682009-06-10 05:40:52 +08001716 /* somehow the BTS was unable to connect the lchan to a remote
1717 * port */
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001718 DEBUGPC(DRSL, "IPAC_MDCX_NACK ");
Harald Welte59b04682009-06-10 05:40:52 +08001719 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001720 case RSL_MT_IPAC_DLCX_IND:
1721 DEBUGPC(DRSL, "IPAC_DLCX_IND ");
1722 rc = abis_rsl_rx_ipacc_dlcx_ind(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001723 break;
1724 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001725 LOGP(DRSL, LOGL_NOTICE, "Unknown ip.access msg_type 0x%02x",
1726 rllh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001727 break;
1728 }
1729 DEBUGPC(DRSL, "\n");
1730
1731 return rc;
1732}
1733
1734
1735/* Entry-point where L2 RSL from BTS enters */
1736int abis_rsl_rcvmsg(struct msgb *msg)
1737{
1738 struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
1739 int rc = 0;
1740
1741 switch (rslh->msg_discr & 0xfe) {
1742 case ABIS_RSL_MDISC_RLL:
1743 rc = abis_rsl_rx_rll(msg);
1744 break;
1745 case ABIS_RSL_MDISC_DED_CHAN:
1746 rc = abis_rsl_rx_dchan(msg);
1747 break;
1748 case ABIS_RSL_MDISC_COM_CHAN:
1749 rc = abis_rsl_rx_cchan(msg);
1750 break;
1751 case ABIS_RSL_MDISC_TRX:
1752 rc = abis_rsl_rx_trx(msg);
1753 break;
1754 case ABIS_RSL_MDISC_LOC:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001755 LOGP(DRSL, LOGL_NOTICE, "unimplemented RSL msg disc 0x%02x\n",
Harald Welte59b04682009-06-10 05:40:52 +08001756 rslh->msg_discr);
1757 break;
1758 case ABIS_RSL_MDISC_IPACCESS:
1759 rc = abis_rsl_rx_ipacc(msg);
1760 break;
1761 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001762 LOGP(DRSL, LOGL_NOTICE, "unknown RSL message discriminator "
1763 "0x%02x\n", rslh->msg_discr);
Harald Welte59b04682009-06-10 05:40:52 +08001764 return -EINVAL;
1765 }
1766 msgb_free(msg);
1767 return rc;
1768}
1769
1770
Holger Hans Peter Freyther4e0fdfd2009-07-09 20:43:16 +02001771/* Section 3.3.2.3 TS 05.02. I think this looks like a table */
Harald Welte59b04682009-06-10 05:40:52 +08001772int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
1773{
1774 switch (ccch_conf) {
1775 case RSL_BCCH_CCCH_CONF_1_NC:
1776 return 1;
1777 case RSL_BCCH_CCCH_CONF_1_C:
1778 return 1;
1779 case RSL_BCCH_CCCH_CONF_2_NC:
1780 return 2;
1781 case RSL_BCCH_CCCH_CONF_3_NC:
1782 return 3;
1783 case RSL_BCCH_CCCH_CONF_4_NC:
1784 return 4;
1785 default:
1786 return -1;
1787 }
1788}
1789
Holger Hans Peter Freyther4e0fdfd2009-07-09 20:43:16 +02001790/* Section 3.3.2.3 TS 05.02 */
Harald Welte59b04682009-06-10 05:40:52 +08001791int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
1792{
1793 switch (ccch_conf) {
1794 case RSL_BCCH_CCCH_CONF_1_NC:
1795 return 0;
1796 case RSL_BCCH_CCCH_CONF_1_C:
1797 return 1;
1798 case RSL_BCCH_CCCH_CONF_2_NC:
1799 return 0;
1800 case RSL_BCCH_CCCH_CONF_3_NC:
1801 return 0;
1802 case RSL_BCCH_CCCH_CONF_4_NC:
1803 return 0;
1804 default:
1805 return -1;
1806 }
1807}
1808
1809/* From Table 10.5.33 of GSM 04.08 */
1810int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
1811{
Harald Weltea54a2bb2009-12-01 18:04:30 +05301812 if (bts->si_common.chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
1813 return MAX(1, (3 - bts->si_common.chan_desc.bs_ag_blks_res))
1814 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Harald Welte59b04682009-06-10 05:40:52 +08001815 } else {
Harald Weltea54a2bb2009-12-01 18:04:30 +05301816 return (9 - bts->si_common.chan_desc.bs_ag_blks_res)
1817 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Harald Welte59b04682009-06-10 05:40:52 +08001818 }
1819}