blob: 60e64cf8e6ae4795028e5c1a4b2b3b9c01cf5602 [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
Harald Weltea22d36b2010-03-04 10:33:10 +01004/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte59b04682009-06-10 05:40:52 +08005 *
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 Weltef4625b12010-02-20 16:24:02 +010033#include <osmocore/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>
Harald Weltef4625b12010-02-20 16:24:02 +010038#include <osmocore/tlv.h>
Harald Welte59b04682009-06-10 05:40:52 +080039#include <openbsc/paging.h>
40#include <openbsc/signal.h>
Harald Weltec20bd1d2009-11-29 19:07:28 +010041#include <openbsc/meas_rep.h>
Harald Welte50517742009-12-20 15:42:44 +010042#include <openbsc/rtp_proxy.h>
Harald Welte1fa8bac2010-03-01 21:59:06 +010043#include <osmocore/rsl.h>
Harald Welte59b04682009-06-10 05:40:52 +080044
45#define RSL_ALLOC_SIZE 1024
46#define RSL_ALLOC_HEADROOM 128
47
48#define MAX(a, b) (a) >= (b) ? (a) : (b)
49
Harald Welte59b04682009-06-10 05:40:52 +080050static u_int8_t mdisc_by_msgtype(u_int8_t msg_type)
51{
52 /* mask off the transparent bit ? */
53 msg_type &= 0xfe;
54
55 if ((msg_type & 0xf0) == 0x00)
56 return ABIS_RSL_MDISC_RLL;
57 if ((msg_type & 0xf0) == 0x10) {
58 if (msg_type >= 0x19 && msg_type <= 0x22)
59 return ABIS_RSL_MDISC_TRX;
60 else
61 return ABIS_RSL_MDISC_COM_CHAN;
62 }
63 if ((msg_type & 0xe0) == 0x20)
64 return ABIS_RSL_MDISC_DED_CHAN;
65
66 return ABIS_RSL_MDISC_LOC;
67}
68
69static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh,
70 u_int8_t msg_type)
71{
72 dh->c.msg_discr = mdisc_by_msgtype(msg_type);
73 dh->c.msg_type = msg_type;
74 dh->ie_chan = RSL_IE_CHAN_NR;
75}
76
Harald Welte59b04682009-06-10 05:40:52 +080077/* determine logical channel based on TRX and channel number IE */
78struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr)
79{
80 struct gsm_lchan *lchan;
81 u_int8_t ts_nr = chan_nr & 0x07;
82 u_int8_t cbits = chan_nr >> 3;
83 u_int8_t lch_idx;
84 struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
85
86 if (cbits == 0x01) {
87 lch_idx = 0; /* TCH/F */
Harald Welte37884ed2009-10-24 10:25:50 +020088 if (ts->pchan != GSM_PCHAN_TCH_F &&
89 ts->pchan != GSM_PCHAN_PDCH &&
90 ts->pchan != GSM_PCHAN_TCH_F_PDCH)
Harald Weltecf2ec4a2009-12-17 23:10:46 +010091 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +080092 chan_nr, ts->pchan);
93 } else if ((cbits & 0x1e) == 0x02) {
94 lch_idx = cbits & 0x1; /* TCH/H */
95 if (ts->pchan != GSM_PCHAN_TCH_H)
Harald Weltecf2ec4a2009-12-17 23:10:46 +010096 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +080097 chan_nr, ts->pchan);
98 } else if ((cbits & 0x1c) == 0x04) {
99 lch_idx = cbits & 0x3; /* SDCCH/4 */
100 if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100101 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800102 chan_nr, ts->pchan);
103 } else if ((cbits & 0x18) == 0x08) {
104 lch_idx = cbits & 0x7; /* SDCCH/8 */
105 if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100106 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800107 chan_nr, ts->pchan);
108 } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
109 lch_idx = 0;
110 if (ts->pchan != GSM_PCHAN_CCCH &&
111 ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100112 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte59b04682009-06-10 05:40:52 +0800113 chan_nr, ts->pchan);
114 /* FIXME: we should not return first sdcch4 !!! */
115 } else {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100116 LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
Harald Welte59b04682009-06-10 05:40:52 +0800117 return NULL;
118 }
119
120 lchan = &ts->lchan[lch_idx];
Holger Hans Peter Freytherc8d862e2009-12-22 22:32:51 +0100121 debug_set_context(BSC_CTX_LCHAN, lchan);
122 debug_set_context(BSC_CTX_SUBSCR, lchan->subscr);
Harald Welte59b04682009-06-10 05:40:52 +0800123
124 return lchan;
125}
126
Holger Hans Peter Freyther942ff172009-10-22 11:47:45 +0200127/* See Table 10.5.25 of GSM04.08 */
Harald Welteb5586242009-12-09 19:18:32 +0100128u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan)
Harald Welte59b04682009-06-10 05:40:52 +0800129{
130 struct gsm_bts_trx_ts *ts = lchan->ts;
131 u_int8_t cbits, chan_nr;
132
133 switch (ts->pchan) {
134 case GSM_PCHAN_TCH_F:
Harald Welte37884ed2009-10-24 10:25:50 +0200135 case GSM_PCHAN_PDCH:
136 case GSM_PCHAN_TCH_F_PDCH:
Harald Welte59b04682009-06-10 05:40:52 +0800137 cbits = 0x01;
138 break;
139 case GSM_PCHAN_TCH_H:
140 cbits = 0x02;
141 cbits += lchan->nr;
142 break;
143 case GSM_PCHAN_CCCH_SDCCH4:
144 cbits = 0x04;
145 cbits += lchan->nr;
146 break;
147 case GSM_PCHAN_SDCCH8_SACCH8C:
148 cbits = 0x08;
149 cbits += lchan->nr;
150 break;
151 default:
152 case GSM_PCHAN_CCCH:
153 cbits = 0x10;
154 break;
155 }
156
157 chan_nr = (cbits << 3) | (ts->nr & 0x7);
158
159 return chan_nr;
160}
161
162/* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */
163u_int64_t str_to_imsi(const char *imsi_str)
164{
165 u_int64_t ret;
166
167 ret = strtoull(imsi_str, NULL, 10);
168
169 return ret;
170}
171
172/* Table 5 Clause 7 TS 05.02 */
173unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res)
174{
175 if (!bs_ccch_sdcch_comb)
176 return 9 - bs_ag_blks_res;
177 else
178 return 3 - bs_ag_blks_res;
179}
180
181/* Chapter 6.5.2 of TS 05.02 */
182unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans,
183 unsigned int n_pag_blocks)
184{
185 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks;
186}
187
188/* Chapter 6.5.2 of TS 05.02 */
189unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
190 int n_pag_blocks)
191{
192 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks;
193}
194
195static struct msgb *rsl_msgb_alloc(void)
196{
Harald Welte9cfc9352009-06-26 19:39:35 +0200197 return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM,
198 "RSL");
Harald Welte59b04682009-06-10 05:40:52 +0800199}
200
201#define MACBLOCK_SIZE 23
202static void pad_macblock(u_int8_t *out, const u_int8_t *in, int len)
203{
204 memcpy(out, in, len);
205
206 if (len < MACBLOCK_SIZE)
207 memset(out+len, 0x2b, MACBLOCK_SIZE-len);
208}
209
Harald Welted2dd9de2009-08-30 15:37:11 +0900210/* Chapter 9.3.7: Encryption Information */
211static int build_encr_info(u_int8_t *out, struct gsm_lchan *lchan)
212{
213 *out++ = lchan->encr.alg_id & 0xff;
214 if (lchan->encr.key_len)
215 memcpy(out, lchan->encr.key, lchan->encr.key_len);
216 return lchan->encr.key_len + 1;
217}
218
Harald Weltede4477a2009-12-24 12:20:20 +0100219static void print_rsl_cause(int lvl, const u_int8_t *cause_v, u_int8_t cause_len)
Harald Weltef1a168d2009-07-28 17:58:09 +0200220{
Harald Welte59b04682009-06-10 05:40:52 +0800221 int i;
222
Harald Weltede4477a2009-12-24 12:20:20 +0100223 LOGPC(DRSL, lvl, "CAUSE=0x%02x(%s) ",
Harald Weltef1a168d2009-07-28 17:58:09 +0200224 cause_v[0], rsl_err_name(cause_v[0]));
225 for (i = 1; i < cause_len-1; i++)
Harald Weltede4477a2009-12-24 12:20:20 +0100226 LOGPC(DRSL, lvl, "%02x ", cause_v[i]);
Harald Welte59b04682009-06-10 05:40:52 +0800227}
228
229/* Send a BCCH_INFO message as per Chapter 8.5.1 */
230int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type,
231 const u_int8_t *data, int len)
232{
233 struct abis_rsl_dchan_hdr *dh;
234 struct msgb *msg = rsl_msgb_alloc();
235
236 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh);
237 init_dchan_hdr(dh, RSL_MT_BCCH_INFO);
238 dh->chan_nr = RSL_CHAN_BCCH;
239
240 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
241 msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data);
242
243 msg->trx = trx;
244
245 return abis_rsl_sendmsg(msg);
246}
247
248int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type,
249 const u_int8_t *data, int len)
250{
251 struct abis_rsl_common_hdr *ch;
252 struct msgb *msg = rsl_msgb_alloc();
253
254 ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch));
255 ch->msg_discr = ABIS_RSL_MDISC_TRX;
256 ch->msg_type = RSL_MT_SACCH_FILL;
257
258 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
259 msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data);
260
261 msg->trx = trx;
262
263 return abis_rsl_sendmsg(msg);
264}
265
Harald Welte91afe4c2009-06-20 18:15:19 +0200266int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db)
267{
268 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200269 struct msgb *msg;
Harald Welte91afe4c2009-06-20 18:15:19 +0200270 u_int8_t chan_nr = lchan2chan_nr(lchan);
271
272 db = abs(db);
273 if (db > 30)
274 return -EINVAL;
275
Harald Welteed831842009-06-27 03:09:08 +0200276 msg = rsl_msgb_alloc();
277
Harald Welte91afe4c2009-06-20 18:15:19 +0200278 lchan->bs_power = db/2;
279 if (fpc)
280 lchan->bs_power |= 0x10;
281
282 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
283 init_dchan_hdr(dh, RSL_MT_BS_POWER_CONTROL);
284 dh->chan_nr = chan_nr;
285
286 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
287
288 msg->trx = lchan->ts->trx;
289
290 return abis_rsl_sendmsg(msg);
291}
292
Harald Welte91afe4c2009-06-20 18:15:19 +0200293int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm)
294{
295 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200296 struct msgb *msg;
Harald Welte91afe4c2009-06-20 18:15:19 +0200297 u_int8_t chan_nr = lchan2chan_nr(lchan);
298 int ctl_lvl;
299
Harald Weltec4dcda02009-08-09 14:45:18 +0200300 ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm);
Harald Welte91afe4c2009-06-20 18:15:19 +0200301 if (ctl_lvl < 0)
302 return ctl_lvl;
303
Harald Welteed831842009-06-27 03:09:08 +0200304 msg = rsl_msgb_alloc();
305
Harald Welte91afe4c2009-06-20 18:15:19 +0200306 lchan->ms_power = ctl_lvl;
307
308 if (fpc)
309 lchan->ms_power |= 0x20;
310
311 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
312 init_dchan_hdr(dh, RSL_MT_MS_POWER_CONTROL);
313 dh->chan_nr = chan_nr;
314
315 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
316
317 msg->trx = lchan->ts->trx;
318
319 return abis_rsl_sendmsg(msg);
320}
321
Harald Welte39274f42009-07-29 15:41:29 +0200322static int channel_mode_from_lchan(struct rsl_ie_chan_mode *cm,
323 struct gsm_lchan *lchan)
324{
325 memset(cm, 0, sizeof(cm));
326
327 /* FIXME: what to do with data calls ? */
328 cm->dtx_dtu = 0x00;
329
330 /* set TCH Speech/Data */
331 cm->spd_ind = lchan->rsl_cmode;
332
Harald Welte951e3512009-11-27 08:55:16 +0100333 if (lchan->rsl_cmode == RSL_CMOD_SPD_SIGN &&
334 lchan->tch_mode != GSM48_CMODE_SIGN)
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100335 LOGP(DRSL, LOGL_ERROR, "unsupported: rsl_mode == signalling, "
Harald Welte951e3512009-11-27 08:55:16 +0100336 "but tch_mode != signalling\n");
337
Harald Welte39274f42009-07-29 15:41:29 +0200338 switch (lchan->type) {
339 case GSM_LCHAN_SDCCH:
340 cm->chan_rt = RSL_CMOD_CRT_SDCCH;
341 break;
342 case GSM_LCHAN_TCH_F:
343 cm->chan_rt = RSL_CMOD_CRT_TCH_Bm;
344 break;
345 case GSM_LCHAN_TCH_H:
346 cm->chan_rt = RSL_CMOD_CRT_TCH_Lm;
347 break;
348 case GSM_LCHAN_NONE:
349 case GSM_LCHAN_UNKNOWN:
350 default:
351 return -EINVAL;
352 }
353
354 switch (lchan->tch_mode) {
355 case GSM48_CMODE_SIGN:
356 cm->chan_rate = 0;
357 break;
358 case GSM48_CMODE_SPEECH_V1:
359 cm->chan_rate = RSL_CMOD_SP_GSM1;
360 break;
361 case GSM48_CMODE_SPEECH_EFR:
362 cm->chan_rate = RSL_CMOD_SP_GSM2;
363 break;
364 case GSM48_CMODE_SPEECH_AMR:
365 cm->chan_rate = RSL_CMOD_SP_GSM3;
366 break;
367 case GSM48_CMODE_DATA_14k5:
368 cm->chan_rate = RSL_CMOD_SP_NT_14k5;
369 break;
370 case GSM48_CMODE_DATA_12k0:
371 cm->chan_rate = RSL_CMOD_SP_NT_12k0;
372 break;
373 case GSM48_CMODE_DATA_6k0:
374 cm->chan_rate = RSL_CMOD_SP_NT_6k0;
375 break;
376 default:
377 return -EINVAL;
378 }
379
380 return 0;
381}
382
Harald Welte59b04682009-06-10 05:40:52 +0800383/* Chapter 8.4.1 */
384#if 0
385int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
386 u_int8_t act_type,
387 struct rsl_ie_chan_mode *chan_mode,
388 struct rsl_ie_chan_ident *chan_ident,
389 u_int8_t bs_power, u_int8_t ms_power,
390 u_int8_t ta)
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_CHAN_ACTIV);
397 dh->chan_nr = chan_nr;
398
399 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
400 /* For compatibility with Phase 1 */
401 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode),
402 (u_int8_t *) chan_mode);
403 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
404 (u_int8_t *) chan_ident);
405#if 0
406 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
407 (u_int8_t *) &encr_info);
408#endif
409 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
410 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
411 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
412
413 msg->trx = trx;
414
415 return abis_rsl_sendmsg(msg);
416}
417#endif
418
419int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
Harald Welteb90d7bd2009-12-17 00:31:10 +0100420 u_int8_t ta, u_int8_t ho_ref)
Harald Welte59b04682009-06-10 05:40:52 +0800421{
422 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200423 struct msgb *msg;
Harald Welte39274f42009-07-29 15:41:29 +0200424 int rc;
Harald Welte59b04682009-06-10 05:40:52 +0800425
426 u_int8_t chan_nr = lchan2chan_nr(lchan);
427 u_int16_t arfcn = lchan->ts->trx->arfcn;
428 struct rsl_ie_chan_mode cm;
429 struct rsl_ie_chan_ident ci;
430
Harald Welte39274f42009-07-29 15:41:29 +0200431 rc = channel_mode_from_lchan(&cm, lchan);
432 if (rc < 0)
433 return rc;
Harald Welte59b04682009-06-10 05:40:52 +0800434
435 memset(&ci, 0, sizeof(ci));
436 ci.chan_desc.iei = 0x64;
437 ci.chan_desc.chan_nr = chan_nr;
438 ci.chan_desc.oct3 = (lchan->ts->trx->bts->tsc << 5) | ((arfcn & 0x3ff) >> 8);
439 ci.chan_desc.oct4 = arfcn & 0xff;
440
Harald Welteed831842009-06-27 03:09:08 +0200441 msg = rsl_msgb_alloc();
Harald Welte59b04682009-06-10 05:40:52 +0800442 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
443 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
444 dh->chan_nr = chan_nr;
445
446 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
Harald Welte59b04682009-06-10 05:40:52 +0800447 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
448 (u_int8_t *) &cm);
Harald Welteb90d7bd2009-12-17 00:31:10 +0100449 /* For compatibility with Phase 1 */
Harald Welte59b04682009-06-10 05:40:52 +0800450 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
451 (u_int8_t *) &ci);
Harald Welted2dd9de2009-08-30 15:37:11 +0900452
453 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
454 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
455 rc = build_encr_info(encr_info, lchan);
456 if (rc > 0)
457 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
458 }
459
Harald Welteb90d7bd2009-12-17 00:31:10 +0100460 switch (act_type) {
461 case RSL_ACT_INTER_ASYNC:
462 case RSL_ACT_INTER_SYNC:
463 msgb_tv_put(msg, RSL_IE_HANDO_REF, ho_ref);
464 break;
465 default:
466 break;
467 }
468
Harald Welte59b04682009-06-10 05:40:52 +0800469 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
470 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
471 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
472
Holger Hans Peter Freyther6fe8ab92010-01-28 04:45:05 +0100473 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR)
474 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
475 (u_int8_t *) &lchan->mr_conf);
476
Harald Welte59b04682009-06-10 05:40:52 +0800477 msg->trx = lchan->ts->trx;
478
479 return abis_rsl_sendmsg(msg);
480}
481
Harald Welte8e770492009-07-29 11:38:15 +0200482/* Chapter 8.4.9: Modify channel mode on BTS side */
Harald Welte59b04682009-06-10 05:40:52 +0800483int rsl_chan_mode_modify_req(struct gsm_lchan *lchan)
484{
485 struct abis_rsl_dchan_hdr *dh;
Harald Welteed831842009-06-27 03:09:08 +0200486 struct msgb *msg;
Harald Welte39274f42009-07-29 15:41:29 +0200487 int rc;
Harald Welte59b04682009-06-10 05:40:52 +0800488
489 u_int8_t chan_nr = lchan2chan_nr(lchan);
490 struct rsl_ie_chan_mode cm;
491
Harald Welte39274f42009-07-29 15:41:29 +0200492 rc = channel_mode_from_lchan(&cm, lchan);
493 if (rc < 0)
494 return rc;
Harald Welte59b04682009-06-10 05:40:52 +0800495
Harald Welteed831842009-06-27 03:09:08 +0200496 msg = rsl_msgb_alloc();
Harald Welte59b04682009-06-10 05:40:52 +0800497 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
498 init_dchan_hdr(dh, RSL_MT_MODE_MODIFY_REQ);
499 dh->chan_nr = chan_nr;
500
501 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
502 (u_int8_t *) &cm);
Harald Welted2dd9de2009-08-30 15:37:11 +0900503
504 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
505 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
506 rc = build_encr_info(encr_info, lchan);
507 if (rc > 0)
508 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
509 }
510
Holger Hans Peter Freyther3cce58f2009-11-18 22:57:02 +0100511 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) {
512 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
513 (u_int8_t *) &lchan->mr_conf);
514 }
515
Harald Welted2dd9de2009-08-30 15:37:11 +0900516 msg->trx = lchan->ts->trx;
517
518 return abis_rsl_sendmsg(msg);
519}
520
521/* Chapter 8.4.6: Send the encryption command with given L3 info */
522int rsl_encryption_cmd(struct msgb *msg)
523{
524 struct abis_rsl_dchan_hdr *dh;
525 struct gsm_lchan *lchan = msg->lchan;
526 u_int8_t chan_nr = lchan2chan_nr(lchan);
527 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
Sylvain Munaut01f1caf2009-09-27 11:13:18 +0200528 u_int8_t l3_len = msg->len;
Harald Welted2dd9de2009-08-30 15:37:11 +0900529 int rc;
530
531 /* First push the L3 IE tag and length */
532 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
533
534 /* then the link identifier (SAPI0, main sign link) */
535 msgb_tv_push(msg, RSL_IE_LINK_IDENT, 0);
536
537 /* then encryption information */
538 rc = build_encr_info(encr_info, lchan);
539 if (rc <= 0)
540 return rc;
541 msgb_tlv_push(msg, RSL_IE_ENCR_INFO, rc, encr_info);
542
543 /* and finally the DCHAN header */
544 dh = (struct abis_rsl_dchan_hdr *) msgb_push(msg, sizeof(*dh));
545 init_dchan_hdr(dh, RSL_MT_ENCR_CMD);
546 dh->chan_nr = chan_nr;
Harald Welte59b04682009-06-10 05:40:52 +0800547
548 msg->trx = lchan->ts->trx;
549
550 return abis_rsl_sendmsg(msg);
551}
552
Harald Welte85a163c2009-08-10 11:43:22 +0200553/* Chapter 8.4.5 / 4.6: Deactivate the SACCH after 04.08 RR CHAN RELEASE */
Harald Welteafe3c232009-07-19 18:36:49 +0200554int rsl_deact_sacch(struct gsm_lchan *lchan)
555{
556 struct abis_rsl_dchan_hdr *dh;
557 struct msgb *msg = rsl_msgb_alloc();
558
559 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
560 init_dchan_hdr(dh, RSL_MT_DEACTIVATE_SACCH);
561 dh->chan_nr = lchan2chan_nr(lchan);
562
563 msg->lchan = lchan;
564 msg->trx = lchan->ts->trx;
565
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100566 DEBUGP(DRSL, "%s DEACTivate SACCH CMD\n", gsm_lchan_name(lchan));
Harald Welteafe3c232009-07-19 18:36:49 +0200567
568 return abis_rsl_sendmsg(msg);
569}
570
Harald Welte85a163c2009-08-10 11:43:22 +0200571/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
572int rsl_rf_chan_release(struct gsm_lchan *lchan)
Harald Welte59b04682009-06-10 05:40:52 +0800573{
574 struct abis_rsl_dchan_hdr *dh;
575 struct msgb *msg = rsl_msgb_alloc();
576
577 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
578 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
579 dh->chan_nr = lchan2chan_nr(lchan);
580
581 msg->lchan = lchan;
582 msg->trx = lchan->ts->trx;
583
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100584 DEBUGP(DRSL, "%s RF Channel Release CMD\n", gsm_lchan_name(lchan));
Harald Welte59b04682009-06-10 05:40:52 +0800585
Harald Welte85a163c2009-08-10 11:43:22 +0200586 /* BTS will respond by RF CHAN REL ACK */
Harald Welte59b04682009-06-10 05:40:52 +0800587 return abis_rsl_sendmsg(msg);
588}
589
590int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
591 u_int8_t *ms_ident, u_int8_t chan_needed)
592{
593 struct abis_rsl_dchan_hdr *dh;
594 struct msgb *msg = rsl_msgb_alloc();
595
596 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
597 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
598 dh->chan_nr = RSL_CHAN_PCH_AGCH;
599
600 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
601 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
602 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
603
604 msg->trx = bts->c0;
605
606 return abis_rsl_sendmsg(msg);
607}
608
609int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
610 struct gsm_subscriber *subscr)
611{
612#if 0
613 u_int8_t mi[128];
614 unsigned int mi_len;
615 u_int8_t paging_group;
616#endif
617
618 return -1;
619}
620
621int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
622{
623 int i, len = strlen(str_in);
624
625 for (i = 0; i < len; i++) {
626 int num = str_in[i] - 0x30;
627 if (num < 0 || num > 9)
628 return -1;
629 if (i % 2 == 0)
630 bcd_out[i/2] = num;
631 else
632 bcd_out[i/2] |= (num << 4);
633 }
634
635 return 0;
636}
637
638/* Chapter 8.5.6 */
639int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
640{
641 struct msgb *msg = rsl_msgb_alloc();
642 struct abis_rsl_dchan_hdr *dh;
643 u_int8_t buf[MACBLOCK_SIZE];
644
645 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
646 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
647 dh->chan_nr = RSL_CHAN_PCH_AGCH;
648
649 switch (bts->type) {
650 case GSM_BTS_TYPE_BS11:
651 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
652 break;
653 default:
654 /* If phase 2, construct a FULL_IMM_ASS_INFO */
655 pad_macblock(buf, val, len);
656 msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf);
657 break;
658 }
659
660 msg->trx = bts->c0;
661
662 return abis_rsl_sendmsg(msg);
663}
664
Harald Welte4684e632009-08-10 09:51:40 +0200665/* Send Siemens specific MS RF Power Capability Indication */
Harald Welte12090752009-08-10 10:07:33 +0200666int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci)
Harald Welte4684e632009-08-10 09:51:40 +0200667{
668 struct msgb *msg = rsl_msgb_alloc();
669 struct abis_rsl_dchan_hdr *dh;
670
671 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
672 init_dchan_hdr(dh, RSL_MT_SIEMENS_MRPCI);
Harald Welte874a5b42009-08-10 11:26:14 +0200673 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
Harald Welte4684e632009-08-10 09:51:40 +0200674 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte12090752009-08-10 10:07:33 +0200675 msgb_tv_put(msg, RSL_IE_SIEMENS_MRPCI, *(u_int8_t *)mrpci);
Harald Welte4684e632009-08-10 09:51:40 +0200676
Harald Weltede4477a2009-12-24 12:20:20 +0100677 DEBUGP(DRSL, "%s TX Siemens MRPCI 0x%02x\n",
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100678 gsm_lchan_name(lchan), *(u_int8_t *)mrpci);
Harald Welte874a5b42009-08-10 11:26:14 +0200679
680 msg->trx = lchan->ts->trx;
681
Harald Welte4684e632009-08-10 09:51:40 +0200682 return abis_rsl_sendmsg(msg);
683}
684
685
Harald Welte59b04682009-06-10 05:40:52 +0800686/* Send "DATA REQUEST" message with given L3 Info payload */
687/* Chapter 8.3.1 */
688int rsl_data_request(struct msgb *msg, u_int8_t link_id)
689{
Harald Welte59b04682009-06-10 05:40:52 +0800690 if (msg->lchan == NULL) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100691 LOGP(DRSL, LOGL_ERROR, "cannot send DATA REQUEST to unknown lchan\n");
Harald Welte59b04682009-06-10 05:40:52 +0800692 return -EINVAL;
693 }
694
Harald Weltea22d36b2010-03-04 10:33:10 +0100695 rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, lchan2chan_nr(msg->lchan),
696 link_id, 1);
Harald Welte59b04682009-06-10 05:40:52 +0800697
698 msg->trx = msg->lchan->ts->trx;
699
700 return abis_rsl_sendmsg(msg);
701}
702
Harald Welteed9a5ab2009-08-09 13:47:35 +0200703/* Send "ESTABLISH REQUEST" message with given L3 Info payload */
704/* Chapter 8.3.1 */
705int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
706{
Harald Weltea22d36b2010-03-04 10:33:10 +0100707 struct msgb *msg;
Harald Welteed9a5ab2009-08-09 13:47:35 +0200708
Harald Weltea22d36b2010-03-04 10:33:10 +0100709 msg = rsl_rll_simple(RSL_MT_EST_REQ, lchan2chan_nr(lchan),
710 link_id, 0);
Harald Welteed9a5ab2009-08-09 13:47:35 +0200711 msg->trx = lchan->ts->trx;
712
713 return abis_rsl_sendmsg(msg);
714}
715
Harald Welte0f2e3c12009-08-08 13:15:07 +0200716/* Chapter 8.3.7 Request the release of multiframe mode of RLL connection.
717 This is what higher layers should call. The BTS then responds with
718 RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
719 which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
720 lchan_free() */
721int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id)
722{
Harald Welte0f2e3c12009-08-08 13:15:07 +0200723
Harald Weltea22d36b2010-03-04 10:33:10 +0100724 struct msgb *msg;
725
726 msg = rsl_rll_simple(RSL_MT_REL_REQ, lchan2chan_nr(lchan),
727 link_id, 0);
Harald Weltead738562009-08-10 00:19:36 +0200728 msgb_tv_put(msg, RSL_IE_RELEASE_MODE, 0); /* normal release */
Harald Welte0f2e3c12009-08-08 13:15:07 +0200729
Harald Weltec88a4432009-12-29 10:44:17 +0100730 lchan->state = LCHAN_S_REL_REQ;
731 /* FIXME: start some timer in case we don't receive a REL ACK ? */
732
Harald Welte0f2e3c12009-08-08 13:15:07 +0200733 msg->trx = lchan->ts->trx;
734
735 return abis_rsl_sendmsg(msg);
736}
737
Harald Welte59b04682009-06-10 05:40:52 +0800738/* Chapter 8.4.2: Channel Activate Acknowledge */
739static int rsl_rx_chan_act_ack(struct msgb *msg)
740{
741 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
742
743 /* BTS has confirmed channel activation, we now need
744 * to assign the activated channel to the MS */
745 if (rslh->ie_chan != RSL_IE_CHAN_NR)
746 return -EINVAL;
Harald Welte6720a432009-11-29 22:45:52 +0100747
Harald Weltec88a4432009-12-29 10:44:17 +0100748 if (msg->lchan->state != LCHAN_S_ACT_REQ)
Harald Welteab2534c2009-12-29 10:52:38 +0100749 LOGP(DRSL, LOGL_NOTICE, "%s CHAN ACT ACK, but state %s\n",
750 gsm_lchan_name(msg->lchan),
751 gsm_lchans_name(msg->lchan->state));
Harald Welte4baa9c52009-12-21 13:27:11 +0100752 msg->lchan->state = LCHAN_S_ACTIVE;
753
Harald Welte6720a432009-11-29 22:45:52 +0100754 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_ACK, msg->lchan);
755
Harald Welte59b04682009-06-10 05:40:52 +0800756 return 0;
757}
758
759/* Chapter 8.4.3: Channel Activate NACK */
760static int rsl_rx_chan_act_nack(struct msgb *msg)
761{
762 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
763 struct tlv_parsed tp;
764
Harald Welte (local)ed6d7622009-12-27 11:48:11 +0100765 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL ACTIVATE NACK",
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100766 gsm_lchan_name(msg->lchan));
Harald Welte (local)ed6d7622009-12-27 11:48:11 +0100767
Harald Welte59b04682009-06-10 05:40:52 +0800768 /* BTS has rejected channel activation ?!? */
769 if (dh->ie_chan != RSL_IE_CHAN_NR)
770 return -EINVAL;
771
772 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte (local)c3be50c2009-12-27 18:12:29 +0100773 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) {
774 const u_int8_t *cause = TLVP_VAL(&tp, RSL_IE_CAUSE);
775 print_rsl_cause(LOGL_ERROR, cause,
Harald Weltef1a168d2009-07-28 17:58:09 +0200776 TLVP_LEN(&tp, RSL_IE_CAUSE));
Harald Welte (local)c3be50c2009-12-27 18:12:29 +0100777 if (*cause != RSL_ERR_RCH_ALR_ACTV_ALLOC)
778 msg->lchan->state = LCHAN_S_NONE;
779 } else
780 msg->lchan->state = LCHAN_S_NONE;
781
Harald Welte (local)ed6d7622009-12-27 11:48:11 +0100782 LOGPC(DRSL, LOGL_ERROR, "\n");
783
Harald Welte6720a432009-11-29 22:45:52 +0100784 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_NACK, msg->lchan);
785
Harald Weltecddb9802009-08-09 19:50:08 +0200786 lchan_free(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +0800787 return 0;
788}
789
790/* Chapter 8.4.4: Connection Failure Indication */
791static int rsl_rx_conn_fail(struct msgb *msg)
792{
793 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
794 struct tlv_parsed tp;
795
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100796 /* FIXME: print which channel */
Harald Welte (local)4bd76642009-12-26 22:33:09 +0100797 LOGP(DRSL, LOGL_NOTICE, "%s CONNECTION FAIL: RELEASING ",
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100798 gsm_lchan_name(msg->lchan));
Harald Welte59b04682009-06-10 05:40:52 +0800799
800 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
801
Harald Weltef1a168d2009-07-28 17:58:09 +0200802 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Weltede4477a2009-12-24 12:20:20 +0100803 print_rsl_cause(LOGL_NOTICE, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Weltef1a168d2009-07-28 17:58:09 +0200804 TLVP_LEN(&tp, RSL_IE_CAUSE));
805
Harald Welte (local)4bd76642009-12-26 22:33:09 +0100806 LOGPC(DRSL, LOGL_NOTICE, "\n");
Harald Welte59b04682009-06-10 05:40:52 +0800807 /* FIXME: only free it after channel release ACK */
Harald Welte85a163c2009-08-10 11:43:22 +0200808 return rsl_rf_chan_release(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +0800809}
810
Harald Weltec20bd1d2009-11-29 19:07:28 +0100811static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
812 const char *prefix)
813{
Harald Welte0e4fa782009-12-16 16:52:07 +0100814 DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",
815 prefix, rxlev2dbm(mru->full.rx_lev),
816 prefix, rxlev2dbm(mru->sub.rx_lev));
Harald Weltec20bd1d2009-11-29 19:07:28 +0100817 DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",
818 prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);
819}
820
821static void print_meas_rep(struct gsm_meas_rep *mr)
822{
Harald Welte0e4fa782009-12-16 16:52:07 +0100823 int i;
824
Harald Weltec20bd1d2009-11-29 19:07:28 +0100825 DEBUGP(DMEAS, "MEASUREMENT RESULT NR=%d ", mr->nr);
826
827 if (mr->flags & MEAS_REP_F_DL_DTX)
828 DEBUGPC(DMEAS, "DTXd ");
829
830 print_meas_rep_uni(&mr->ul, "ul");
831 DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
832 if (mr->flags & MEAS_REP_F_MS_TO)
833 DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
834
835 if (mr->flags & MEAS_REP_F_MS_L1) {
Harald Welte0e4fa782009-12-16 16:52:07 +0100836 DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100837 DEBUGPC(DMEAS, "L1_FPC=%u ",
838 mr->flags & MEAS_REP_F_FPC ? 1 : 0);
839 DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);
840 }
841
842 if (mr->flags & MEAS_REP_F_UL_DTX)
843 DEBUGPC(DMEAS, "DTXu ");
844 if (mr->flags & MEAS_REP_F_BA1)
845 DEBUGPC(DMEAS, "BA1 ");
846 if (!(mr->flags & MEAS_REP_F_DL_VALID))
847 DEBUGPC(DMEAS, "NOT VALID ");
848 else
849 print_meas_rep_uni(&mr->dl, "dl");
850
851 DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);
Harald Welte0b833f82009-12-19 18:33:05 +0100852 if (mr->num_cell == 7)
853 return;
Harald Welte0e4fa782009-12-16 16:52:07 +0100854 for (i = 0; i < mr->num_cell; i++) {
855 struct gsm_meas_rep_cell *mrc = &mr->cell[i];
Harald Welte350c2d32009-12-25 23:02:22 +0100856 DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n",
857 mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
Harald Welte0e4fa782009-12-16 16:52:07 +0100858 }
Harald Weltec20bd1d2009-11-29 19:07:28 +0100859}
860
Harald Welte59b04682009-06-10 05:40:52 +0800861static int rsl_rx_meas_res(struct msgb *msg)
862{
863 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
864 struct tlv_parsed tp;
Harald Weltef9476812009-12-15 21:36:05 +0100865 struct gsm_meas_rep *mr = lchan_next_meas_rep(msg->lchan);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100866 u_int8_t len;
867 const u_int8_t *val;
868 int rc;
Harald Welte59b04682009-06-10 05:40:52 +0800869
Harald Welte4baa9c52009-12-21 13:27:11 +0100870 /* check if this channel is actually active */
871 /* FIXME: maybe this check should be way more generic/centralized */
Harald Weltec88a4432009-12-29 10:44:17 +0100872 if (msg->lchan->state != LCHAN_S_ACTIVE) {
873 LOGP(DRSL, LOGL_NOTICE, "%s: MEAS RES for inactive channel\n",
874 gsm_lchan_name(msg->lchan));
Harald Welte4baa9c52009-12-21 13:27:11 +0100875 return 0;
Harald Weltec88a4432009-12-29 10:44:17 +0100876 }
Harald Welte4baa9c52009-12-21 13:27:11 +0100877
Harald Weltef9476812009-12-15 21:36:05 +0100878 memset(mr, 0, sizeof(*mr));
Harald Welteaa0efa12009-12-16 23:29:34 +0100879 mr->lchan = msg->lchan;
Harald Welte4efcc542009-11-30 19:16:47 +0100880
Harald Welte59b04682009-06-10 05:40:52 +0800881 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
882
Harald Weltec20bd1d2009-11-29 19:07:28 +0100883 if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) ||
884 !TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) ||
885 !TLVP_PRESENT(&tp, RSL_IE_BS_POWER))
886 return -EIO;
887
888 /* Mandatory Parts */
Harald Weltef9476812009-12-15 21:36:05 +0100889 mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100890
891 len = TLVP_LEN(&tp, RSL_IE_UPLINK_MEAS);
892 val = TLVP_VAL(&tp, RSL_IE_UPLINK_MEAS);
893 if (len >= 3) {
894 if (val[0] & 0x40)
Harald Weltef9476812009-12-15 21:36:05 +0100895 mr->flags |= MEAS_REP_F_DL_DTX;
896 mr->ul.full.rx_lev = val[0] & 0x3f;
897 mr->ul.sub.rx_lev = val[1] & 0x3f;
898 mr->ul.full.rx_qual = val[2]>>3 & 0x7;
899 mr->ul.sub.rx_qual = val[2] & 0x7;
Harald Welte59b04682009-06-10 05:40:52 +0800900 }
Harald Weltec20bd1d2009-11-29 19:07:28 +0100901
Harald Weltef9476812009-12-15 21:36:05 +0100902 mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100903
904 /* Optional Parts */
Harald Welte59b04682009-06-10 05:40:52 +0800905 if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET))
Harald Weltef9476812009-12-15 21:36:05 +0100906 mr->ms_timing_offset =
Harald Weltec20bd1d2009-11-29 19:07:28 +0100907 *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET);
908
Harald Weltea1467eb2009-06-20 18:44:35 +0200909 if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) {
Harald Weltec20bd1d2009-11-29 19:07:28 +0100910 val = TLVP_VAL(&tp, RSL_IE_L1_INFO);
Harald Weltef9476812009-12-15 21:36:05 +0100911 mr->flags |= MEAS_REP_F_MS_L1;
912 mr->ms_l1.pwr = ms_pwr_dbm(msg->trx->bts->band, val[0] >> 3);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100913 if (val[0] & 0x04)
Harald Weltef9476812009-12-15 21:36:05 +0100914 mr->flags |= MEAS_REP_F_FPC;
915 mr->ms_l1.ta = val[1];
Harald Weltea1467eb2009-06-20 18:44:35 +0200916 }
Harald Welte59b04682009-06-10 05:40:52 +0800917 if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
Holger Hans Peter Freyther6d0c8b42009-10-22 15:43:55 +0200918 msg->l3h = (u_int8_t *) TLVP_VAL(&tp, RSL_IE_L3_INFO);
Harald Weltef9476812009-12-15 21:36:05 +0100919 rc = gsm48_parse_meas_rep(mr, msg);
Harald Weltec20bd1d2009-11-29 19:07:28 +0100920 if (rc < 0)
921 return rc;
922 }
923
Harald Weltef9476812009-12-15 21:36:05 +0100924 print_meas_rep(mr);
Harald Welte59b04682009-06-10 05:40:52 +0800925
Harald Weltef9476812009-12-15 21:36:05 +0100926 dispatch_signal(SS_LCHAN, S_LCHAN_MEAS_REP, mr);
Harald Welte4efcc542009-11-30 19:16:47 +0100927
Harald Welte59b04682009-06-10 05:40:52 +0800928 return 0;
929}
930
Harald Welte6720a432009-11-29 22:45:52 +0100931/* Chapter 8.4.7 */
932static int rsl_rx_hando_det(struct msgb *msg)
933{
934 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
935 struct tlv_parsed tp;
936
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100937 DEBUGP(DRSL, "%s HANDOVER DETECT ", gsm_lchan_name(msg->lchan));
Harald Welte6720a432009-11-29 22:45:52 +0100938
939 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
940
941 if (TLVP_PRESENT(&tp, RSL_IE_ACCESS_DELAY))
942 DEBUGPC(DRSL, "access delay = %u\n",
943 *TLVP_VAL(&tp, RSL_IE_ACCESS_DELAY));
944 else
945 DEBUGPC(DRSL, "\n");
946
947 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_DETECT, msg->lchan);
948
949 return 0;
950}
951
Harald Welte59b04682009-06-10 05:40:52 +0800952static int abis_rsl_rx_dchan(struct msgb *msg)
953{
954 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
955 int rc = 0;
956 char *ts_name;
957
958 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +0100959 ts_name = gsm_lchan_name(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +0800960
Harald Welte59b04682009-06-10 05:40:52 +0800961 switch (rslh->c.msg_type) {
962 case RSL_MT_CHAN_ACTIV_ACK:
Harald Weltede4477a2009-12-24 12:20:20 +0100963 DEBUGP(DRSL, "%s CHANNEL ACTIVATE ACK\n", ts_name);
Harald Welte59b04682009-06-10 05:40:52 +0800964 rc = rsl_rx_chan_act_ack(msg);
965 break;
966 case RSL_MT_CHAN_ACTIV_NACK:
Harald Welte59b04682009-06-10 05:40:52 +0800967 rc = rsl_rx_chan_act_nack(msg);
968 break;
969 case RSL_MT_CONN_FAIL:
970 rc = rsl_rx_conn_fail(msg);
971 break;
972 case RSL_MT_MEAS_RES:
973 rc = rsl_rx_meas_res(msg);
974 break;
Harald Welte6720a432009-11-29 22:45:52 +0100975 case RSL_MT_HANDO_DET:
976 rc = rsl_rx_hando_det(msg);
977 break;
Harald Welte59b04682009-06-10 05:40:52 +0800978 case RSL_MT_RF_CHAN_REL_ACK:
Harald Weltede4477a2009-12-24 12:20:20 +0100979 DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name);
Harald Weltec88a4432009-12-29 10:44:17 +0100980 if (msg->lchan->state != LCHAN_S_REL_REQ)
Harald Welteab2534c2009-12-29 10:52:38 +0100981 LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state %s\n",
982 gsm_lchan_name(msg->lchan),
983 gsm_lchans_name(msg->lchan->state));
Harald Welte4baa9c52009-12-21 13:27:11 +0100984 msg->lchan->state = LCHAN_S_NONE;
Harald Welte59b04682009-06-10 05:40:52 +0800985 lchan_free(msg->lchan);
986 break;
987 case RSL_MT_MODE_MODIFY_ACK:
Harald Weltede4477a2009-12-24 12:20:20 +0100988 DEBUGP(DRSL, "%s CHANNEL MODE MODIFY ACK\n", ts_name);
Harald Welte59b04682009-06-10 05:40:52 +0800989 break;
990 case RSL_MT_MODE_MODIFY_NACK:
Harald Weltede4477a2009-12-24 12:20:20 +0100991 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL MODE MODIFY NACK\n", ts_name);
Harald Welte59b04682009-06-10 05:40:52 +0800992 break;
Harald Welteaed946e2009-10-24 10:29:22 +0200993 case RSL_MT_IPAC_PDCH_ACT_ACK:
Harald Weltede4477a2009-12-24 12:20:20 +0100994 DEBUGPC(DRSL, "%s IPAC PDCH ACT ACK\n", ts_name);
Harald Welteaed946e2009-10-24 10:29:22 +0200995 break;
996 case RSL_MT_IPAC_PDCH_ACT_NACK:
Harald Weltede4477a2009-12-24 12:20:20 +0100997 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH ACT NACK\n", ts_name);
Harald Welteaed946e2009-10-24 10:29:22 +0200998 break;
999 case RSL_MT_IPAC_PDCH_DEACT_ACK:
Harald Weltede4477a2009-12-24 12:20:20 +01001000 DEBUGP(DRSL, "%s IPAC PDCH DEACT ACK\n", ts_name);
Harald Welteaed946e2009-10-24 10:29:22 +02001001 break;
1002 case RSL_MT_IPAC_PDCH_DEACT_NACK:
Harald Weltede4477a2009-12-24 12:20:20 +01001003 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH DEACT NACK\n", ts_name);
Harald Welteaed946e2009-10-24 10:29:22 +02001004 break;
Harald Welte59b04682009-06-10 05:40:52 +08001005 case RSL_MT_PHY_CONTEXT_CONF:
1006 case RSL_MT_PREPROC_MEAS_RES:
1007 case RSL_MT_TALKER_DET:
1008 case RSL_MT_LISTENER_DET:
1009 case RSL_MT_REMOTE_CODEC_CONF_REP:
1010 case RSL_MT_MR_CODEC_MOD_ACK:
1011 case RSL_MT_MR_CODEC_MOD_NACK:
1012 case RSL_MT_MR_CODEC_MOD_PER:
Harald Weltede4477a2009-12-24 12:20:20 +01001013 LOGP(DRSL, LOGL_NOTICE, "%s Unimplemented Abis RSL DChan "
1014 "msg 0x%02x\n", ts_name, rslh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001015 break;
1016 default:
Harald Weltede4477a2009-12-24 12:20:20 +01001017 LOGP(DRSL, LOGL_NOTICE, "%s unknown Abis RSL DChan msg 0x%02x\n",
1018 ts_name, rslh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001019 return -EINVAL;
1020 }
1021
1022 return rc;
1023}
1024
1025static int rsl_rx_error_rep(struct msgb *msg)
1026{
1027 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Weltef1a168d2009-07-28 17:58:09 +02001028 struct tlv_parsed tp;
Harald Welte59b04682009-06-10 05:40:52 +08001029
Harald Welte (local)ab788cf2009-12-28 23:14:22 +01001030 LOGP(DRSL, LOGL_ERROR, "%s ERROR REPORT ", gsm_trx_name(msg->trx));
Harald Weltef1a168d2009-07-28 17:58:09 +02001031
1032 rsl_tlv_parse(&tp, rslh->data, msgb_l2len(msg)-sizeof(*rslh));
1033
1034 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Weltede4477a2009-12-24 12:20:20 +01001035 print_rsl_cause(LOGL_ERROR, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Weltef1a168d2009-07-28 17:58:09 +02001036 TLVP_LEN(&tp, RSL_IE_CAUSE));
1037
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001038 LOGPC(DRSL, LOGL_ERROR, "\n");
Harald Welte59b04682009-06-10 05:40:52 +08001039
1040 return 0;
1041}
1042
1043static int abis_rsl_rx_trx(struct msgb *msg)
1044{
1045 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
1046 int rc = 0;
1047
1048 switch (rslh->msg_type) {
1049 case RSL_MT_ERROR_REPORT:
1050 rc = rsl_rx_error_rep(msg);
1051 break;
1052 case RSL_MT_RF_RES_IND:
1053 /* interference on idle channels of TRX */
Harald Welte (local)ab788cf2009-12-28 23:14:22 +01001054 //DEBUGP(DRSL, "%s RF Resource Indication\n", gsm_trx_name(msg->trx));
Harald Welte59b04682009-06-10 05:40:52 +08001055 break;
1056 case RSL_MT_OVERLOAD:
1057 /* indicate CCCH / ACCH / processor overload */
Harald Welte (local)ab788cf2009-12-28 23:14:22 +01001058 LOGP(DRSL, LOGL_ERROR, "%s CCCH/ACCH/CPU Overload\n",
1059 gsm_trx_name(msg->trx));
Harald Welte59b04682009-06-10 05:40:52 +08001060 break;
1061 default:
Harald Welte (local)ab788cf2009-12-28 23:14:22 +01001062 LOGP(DRSL, LOGL_NOTICE, "%s Unknown Abis RSL TRX message "
1063 "type 0x%02x\n", gsm_trx_name(msg->trx), rslh->msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001064 return -EINVAL;
1065 }
1066 return rc;
1067}
1068
Harald Welte427dbc42009-08-10 00:26:10 +02001069/* If T3101 expires, we never received a response to IMMEDIATE ASSIGN */
1070static void t3101_expired(void *data)
1071{
1072 struct gsm_lchan *lchan = data;
1073
Harald Welte85a163c2009-08-10 11:43:22 +02001074 rsl_rf_chan_release(lchan);
Harald Welte427dbc42009-08-10 00:26:10 +02001075}
1076
Harald Welte59b04682009-06-10 05:40:52 +08001077/* MS has requested a channel on the RACH */
1078static int rsl_rx_chan_rqd(struct msgb *msg)
1079{
1080 struct gsm_bts *bts = msg->trx->bts;
1081 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
1082 struct gsm48_req_ref *rqd_ref;
1083 struct gsm48_imm_ass ia;
1084 enum gsm_chan_t lctype;
1085 enum gsm_chreq_reason_t chreq_reason;
1086 struct gsm_lchan *lchan;
1087 u_int8_t rqd_ta;
1088 int ret;
1089
1090 u_int16_t arfcn;
1091 u_int8_t ts_number, subch;
1092
1093 /* parse request reference to be used in immediate assign */
1094 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
1095 return -EINVAL;
1096
1097 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
1098
1099 /* parse access delay and use as TA */
1100 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
1101 return -EINVAL;
1102 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
1103
1104 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
1105 * request reference RA */
Holger Hans Peter Freyther96c89822009-11-16 17:12:38 +01001106 lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
1107 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
Harald Welte59b04682009-06-10 05:40:52 +08001108
Harald Weltebdbb7442009-12-22 19:07:32 +01001109 counter_inc(bts->network->stats.chreq.total);
Harald Welte3edc5a92009-12-22 00:41:05 +01001110
Harald Welte59b04682009-06-10 05:40:52 +08001111 /* check availability / allocate channel */
1112 lchan = lchan_alloc(bts, lctype);
1113 if (!lchan) {
Harald Welte (local)e0bb5fa2009-12-27 13:48:09 +01001114 LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n",
Harald Welte (local)02204d02009-12-27 18:05:25 +01001115 msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra);
Harald Weltebdbb7442009-12-22 19:07:32 +01001116 counter_inc(bts->network->stats.chreq.no_channel);
Harald Welte59b04682009-06-10 05:40:52 +08001117 /* FIXME: send some kind of reject ?!? */
1118 return -ENOMEM;
1119 }
1120
Harald Weltec88a4432009-12-29 10:44:17 +01001121 if (lchan->state != LCHAN_S_NONE)
1122 LOGP(DRSL, LOGL_NOTICE, "%s lchan_alloc() returned channel "
Harald Welteab2534c2009-12-29 10:52:38 +01001123 "in state %s\n", gsm_lchan_name(lchan),
1124 gsm_lchans_name(lchan->state));
Harald Welte (local)c3be50c2009-12-27 18:12:29 +01001125 lchan->state = LCHAN_S_ACT_REQ;
1126
Harald Welte59b04682009-06-10 05:40:52 +08001127 ts_number = lchan->ts->nr;
1128 arfcn = lchan->ts->trx->arfcn;
1129 subch = lchan->nr;
1130
Harald Welted2dd9de2009-08-30 15:37:11 +09001131 lchan->encr.alg_id = RSL_ENC_ALG_A5(0); /* no encryption */
Harald Welte (local)cbd46102009-08-13 10:14:26 +02001132 lchan->ms_power = ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
Harald Welte9a229e12009-08-10 00:45:40 +02001133 lchan->bs_power = 0; /* 0dB reduction, output power = Pn */
Harald Welte39274f42009-07-29 15:41:29 +02001134 lchan->rsl_cmode = RSL_CMOD_SPD_SIGN;
Harald Welte77234e12009-08-28 23:28:28 +09001135 lchan->tch_mode = GSM48_CMODE_SIGN;
Harald Welteb90d7bd2009-12-17 00:31:10 +01001136 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta, 0);
Harald Welte59b04682009-06-10 05:40:52 +08001137
1138 /* create IMMEDIATE ASSIGN 04.08 messge */
1139 memset(&ia, 0, sizeof(ia));
1140 ia.l2_plen = 0x2d;
1141 ia.proto_discr = GSM48_PDISC_RR;
1142 ia.msg_type = GSM48_MT_RR_IMM_ASS;
1143 ia.page_mode = GSM48_PM_SAME;
1144 ia.chan_desc.chan_nr = lchan2chan_nr(lchan);
1145 ia.chan_desc.h0.h = 0;
1146 ia.chan_desc.h0.arfcn_high = arfcn >> 8;
1147 ia.chan_desc.h0.arfcn_low = arfcn & 0xff;
Harald Welte63d23c82009-07-21 20:55:56 +02001148 ia.chan_desc.h0.tsc = bts->tsc;
Harald Welte59b04682009-06-10 05:40:52 +08001149 /* use request reference extracted from CHAN_RQD */
1150 memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref));
1151 ia.timing_advance = rqd_ta;
1152 ia.mob_alloc_len = 0;
1153
Harald Weltede4477a2009-12-24 12:20:20 +01001154 DEBUGP(DRSL, "%s Activating ARFCN(%u) SS(%u) lctype %s "
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001155 "r=%s ra=0x%02x\n", gsm_lchan_name(lchan), arfcn, subch,
Harald Welte (local)02204d02009-12-27 18:05:25 +01001156 gsm_lchant_name(lchan->type), gsm_chreq_name(chreq_reason),
Harald Welte59b04682009-06-10 05:40:52 +08001157 rqd_ref->ra);
1158
Harald Welte427dbc42009-08-10 00:26:10 +02001159 /* Start timer T3101 to wait for GSM48_MT_RR_PAG_RESP */
1160 lchan->T3101.cb = t3101_expired;
1161 lchan->T3101.data = lchan;
Holger Hans Peter Freyther26ba2e72009-11-21 21:18:38 +01001162 bsc_schedule_timer(&lchan->T3101, bts->network->T3101, 0);
Harald Welte59b04682009-06-10 05:40:52 +08001163
1164 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
1165 ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia);
1166
1167 return ret;
1168}
1169
1170/* MS has requested a channel on the RACH */
1171static int rsl_rx_ccch_load(struct msgb *msg)
1172{
1173 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1174 u_int16_t pg_buf_space;
1175 u_int16_t rach_slot_count = -1;
1176 u_int16_t rach_busy_count = -1;
1177 u_int16_t rach_access_count = -1;
1178
1179 switch (rslh->data[0]) {
1180 case RSL_IE_PAGING_LOAD:
1181 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
1182 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
1183 break;
1184 case RSL_IE_RACH_LOAD:
1185 if (msg->data_len >= 7) {
1186 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
1187 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
1188 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
1189 }
1190 break;
1191 default:
1192 break;
1193 }
1194
1195 return 0;
1196}
1197
1198static int abis_rsl_rx_cchan(struct msgb *msg)
1199{
1200 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1201 int rc = 0;
1202
1203 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
1204
1205 switch (rslh->c.msg_type) {
1206 case RSL_MT_CHAN_RQD:
1207 /* MS has requested a channel on the RACH */
1208 rc = rsl_rx_chan_rqd(msg);
1209 break;
1210 case RSL_MT_CCCH_LOAD_IND:
1211 /* current load on the CCCH */
1212 rc = rsl_rx_ccch_load(msg);
1213 break;
1214 case RSL_MT_DELETE_IND:
1215 /* CCCH overloaded, IMM_ASSIGN was dropped */
1216 case RSL_MT_CBCH_LOAD_IND:
1217 /* current load on the CBCH */
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001218 LOGP(DRSL, LOGL_NOTICE, "Unimplemented Abis RSL TRX message "
1219 "type 0x%02x\n", rslh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001220 break;
1221 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001222 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message type "
1223 "0x%02x\n", rslh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001224 return -EINVAL;
1225 }
1226
1227 return rc;
1228}
1229
1230static int rsl_rx_rll_err_ind(struct msgb *msg)
1231{
1232 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1233 u_int8_t *rlm_cause = rllh->data;
1234
Harald Welte (local)bd76cce2009-12-26 23:55:00 +01001235 LOGP(DRLL, LOGL_ERROR, "%s ERROR INDICATION cause=%s\n",
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001236 gsm_lchan_name(msg->lchan),
Harald Welte1fa8bac2010-03-01 21:59:06 +01001237 get_value_string(rsl_rlm_cause_strs, rlm_cause[1]));
Harald Welteed9a5ab2009-08-09 13:47:35 +02001238
1239 rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND);
Harald Welte (local)bd76cce2009-12-26 23:55:00 +01001240
Harald Welte692f5852009-07-04 09:40:05 +02001241 if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED)
Harald Welte85a163c2009-08-10 11:43:22 +02001242 return rsl_rf_chan_release(msg->lchan);
Harald Welte692f5852009-07-04 09:40:05 +02001243
Harald Welte59b04682009-06-10 05:40:52 +08001244 return 0;
1245}
1246
1247/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
1248 0x02, 0x06,
1249 0x01, 0x20,
1250 0x02, 0x00,
1251 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
1252
1253static int abis_rsl_rx_rll(struct msgb *msg)
1254{
1255 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1256 int rc = 0;
1257 char *ts_name;
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001258 u_int8_t sapi = rllh->link_id & 7;
Harald Welte59b04682009-06-10 05:40:52 +08001259
1260 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001261 ts_name = gsm_lchan_name(msg->lchan);
Harald Weltede4477a2009-12-24 12:20:20 +01001262 DEBUGP(DRLL, "%s SAPI=%u ", ts_name, sapi);
Harald Welte59b04682009-06-10 05:40:52 +08001263
1264 switch (rllh->c.msg_type) {
1265 case RSL_MT_DATA_IND:
1266 DEBUGPC(DRLL, "DATA INDICATION\n");
1267 if (msgb_l2len(msg) >
1268 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1269 rllh->data[0] == RSL_IE_L3_INFO) {
1270 msg->l3h = &rllh->data[3];
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001271 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte59b04682009-06-10 05:40:52 +08001272 }
1273 break;
1274 case RSL_MT_EST_IND:
1275 DEBUGPC(DRLL, "ESTABLISH INDICATION\n");
Harald Welte427dbc42009-08-10 00:26:10 +02001276 /* lchan is established, stop T3101 */
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001277 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_MS;
Harald Welte427dbc42009-08-10 00:26:10 +02001278 bsc_del_timer(&msg->lchan->T3101);
Harald Welte59b04682009-06-10 05:40:52 +08001279 if (msgb_l2len(msg) >
1280 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1281 rllh->data[0] == RSL_IE_L3_INFO) {
1282 msg->l3h = &rllh->data[3];
Harald Welte (local)64994ce2009-08-14 11:41:12 +02001283 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte59b04682009-06-10 05:40:52 +08001284 }
1285 break;
Harald Welteed9a5ab2009-08-09 13:47:35 +02001286 case RSL_MT_EST_CONF:
Harald Welte61402172009-08-09 14:13:58 +02001287 DEBUGPC(DRLL, "ESTABLISH CONFIRM\n");
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001288 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_NET;
Harald Welteed9a5ab2009-08-09 13:47:35 +02001289 rll_indication(msg->lchan, rllh->link_id,
1290 BSC_RLLR_IND_EST_CONF);
1291 break;
Harald Welte59b04682009-06-10 05:40:52 +08001292 case RSL_MT_REL_IND:
Harald Welte0f2e3c12009-08-08 13:15:07 +02001293 /* BTS informs us of having received DISC from MS */
Harald Welteb6601442009-08-04 02:50:21 +02001294 DEBUGPC(DRLL, "RELEASE INDICATION\n");
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001295 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welteed9a5ab2009-08-09 13:47:35 +02001296 rll_indication(msg->lchan, rllh->link_id,
1297 BSC_RLLR_IND_REL_IND);
Harald Welte0f2e3c12009-08-08 13:15:07 +02001298 /* we can now releae the channel on the BTS/Abis side */
Harald Welte85a163c2009-08-10 11:43:22 +02001299 /* FIXME: officially we need to start T3111 and wait for
1300 * some grace period */
1301 rsl_rf_chan_release(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001302 break;
1303 case RSL_MT_REL_CONF:
Harald Welte0f2e3c12009-08-08 13:15:07 +02001304 /* BTS informs us of having received UA from MS,
1305 * in response to DISC that we've sent earlier */
Harald Welteb6601442009-08-04 02:50:21 +02001306 DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
Holger Hans Peter Freytherd8318052009-10-28 14:23:39 +01001307 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welte0f2e3c12009-08-08 13:15:07 +02001308 /* we can now releae the channel on the BTS/Abis side */
Harald Welte85a163c2009-08-10 11:43:22 +02001309 /* FIXME: officially we need to start T3111 and wait for
1310 * some grace period */
1311 rsl_rf_chan_release(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001312 break;
1313 case RSL_MT_ERROR_IND:
Harald Welte59b04682009-06-10 05:40:52 +08001314 rc = rsl_rx_rll_err_ind(msg);
1315 break;
1316 case RSL_MT_UNIT_DATA_IND:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001317 LOGP(DRLL, LOGL_NOTICE, "unimplemented Abis RLL message "
1318 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001319 break;
1320 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001321 LOGP(DRLL, LOGL_NOTICE, "unknown Abis RLL message "
1322 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001323 }
Harald Welte59b04682009-06-10 05:40:52 +08001324 return rc;
1325}
1326
Harald Welteb284b472009-12-02 01:58:23 +05301327static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
Harald Welte98d79f92009-07-28 18:11:56 +02001328{
Harald Welteb284b472009-12-02 01:58:23 +05301329 switch (lchan->tch_mode) {
Harald Welte98d79f92009-07-28 18:11:56 +02001330 case GSM48_CMODE_SPEECH_V1:
Harald Welteb284b472009-12-02 01:58:23 +05301331 switch (lchan->type) {
1332 case GSM_LCHAN_TCH_F:
1333 return 0x00;
1334 case GSM_LCHAN_TCH_H:
1335 return 0x03;
1336 default:
1337 break;
1338 }
Harald Welte98d79f92009-07-28 18:11:56 +02001339 case GSM48_CMODE_SPEECH_EFR:
Harald Welteb284b472009-12-02 01:58:23 +05301340 switch (lchan->type) {
1341 case GSM_LCHAN_TCH_F:
1342 return 0x01;
1343 /* there's no half-rate EFR */
1344 default:
1345 break;
1346 }
Harald Welte98d79f92009-07-28 18:11:56 +02001347 case GSM48_CMODE_SPEECH_AMR:
Harald Welteb284b472009-12-02 01:58:23 +05301348 switch (lchan->type) {
1349 case GSM_LCHAN_TCH_F:
1350 return 0x02;
1351 case GSM_LCHAN_TCH_H:
1352 return 0x05;
1353 default:
1354 break;
1355 }
1356 default:
1357 break;
Harald Welte98d79f92009-07-28 18:11:56 +02001358 }
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001359 LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access speech mode for "
Harald Welteb284b472009-12-02 01:58:23 +05301360 "tch_mode == 0x%02x\n", lchan->tch_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001361 return 0;
Harald Welte98d79f92009-07-28 18:11:56 +02001362}
1363
Harald Welte59b04682009-06-10 05:40:52 +08001364/* ip.access specific RSL extensions */
Harald Weltebffa4992009-12-19 16:42:06 +01001365static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
1366{
1367 struct in_addr ip;
1368 u_int16_t port, conn_id;
1369
1370 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_IP)) {
1371 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_IP));
1372 DEBUGPC(DRSL, "LOCAL_IP=%s ", inet_ntoa(ip));
1373 lchan->abis_ip.bound_ip = ntohl(ip.s_addr);
1374 }
1375
1376 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_PORT)) {
1377 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_PORT));
1378 port = ntohs(port);
1379 DEBUGPC(DRSL, "LOCAL_PORT=%u ", port);
1380 lchan->abis_ip.bound_port = port;
1381 }
1382
1383 if (TLVP_PRESENT(tv, RSL_IE_IPAC_CONN_ID)) {
1384 conn_id = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_CONN_ID));
1385 conn_id = ntohs(conn_id);
1386 DEBUGPC(DRSL, "CON_ID=%u ", conn_id);
1387 lchan->abis_ip.conn_id = conn_id;
1388 }
1389
1390 if (TLVP_PRESENT(tv, RSL_IE_IPAC_RTP_PAYLOAD2)) {
1391 lchan->abis_ip.rtp_payload2 =
1392 *TLVP_VAL(tv, RSL_IE_IPAC_RTP_PAYLOAD2);
1393 DEBUGPC(DRSL, "RTP_PAYLOAD2=0x%02x ",
1394 lchan->abis_ip.rtp_payload2);
1395 }
1396
1397 if (TLVP_PRESENT(tv, RSL_IE_IPAC_SPEECH_MODE)) {
1398 lchan->abis_ip.speech_mode =
1399 *TLVP_VAL(tv, RSL_IE_IPAC_SPEECH_MODE);
1400 DEBUGPC(DRSL, "speech_mode=0x%02x ",
1401 lchan->abis_ip.speech_mode);
1402 }
1403
1404 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_IP)) {
1405 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_IP));
1406 DEBUGPC(DRSL, "REMOTE_IP=%s ", inet_ntoa(ip));
1407 lchan->abis_ip.connect_ip = ntohl(ip.s_addr);
1408 }
1409
1410 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_PORT)) {
1411 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_PORT));
1412 port = ntohs(port);
1413 DEBUGPC(DRSL, "REMOTE_PORT=%u ", port);
1414 lchan->abis_ip.connect_port = port;
1415 }
1416}
1417
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001418int rsl_ipacc_crcx(struct gsm_lchan *lchan)
Harald Welte59b04682009-06-10 05:40:52 +08001419{
1420 struct msgb *msg = rsl_msgb_alloc();
1421 struct abis_rsl_dchan_hdr *dh;
1422
1423 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001424 init_dchan_hdr(dh, RSL_MT_IPAC_CRCX);
Harald Welte59b04682009-06-10 05:40:52 +08001425 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1426 dh->chan_nr = lchan2chan_nr(lchan);
1427
Harald Welte98d79f92009-07-28 18:11:56 +02001428 /* 0x1- == receive-only, 0x-1 == EFR codec */
Harald Weltebffa4992009-12-19 16:42:06 +01001429 lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
1430 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001431
Harald Weltede4477a2009-12-24 12:20:20 +01001432 DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x\n",
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001433 gsm_lchan_name(lchan), lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001434
Harald Welte59b04682009-06-10 05:40:52 +08001435 msg->trx = lchan->ts->trx;
1436
1437 return abis_rsl_sendmsg(msg);
1438}
1439
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001440int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
Harald Weltebffa4992009-12-19 16:42:06 +01001441 u_int8_t rtp_payload2)
Harald Welte59b04682009-06-10 05:40:52 +08001442{
1443 struct msgb *msg = rsl_msgb_alloc();
1444 struct abis_rsl_dchan_hdr *dh;
Harald Weltebffa4992009-12-19 16:42:06 +01001445 u_int32_t *att_ip;
Harald Welte98d79f92009-07-28 18:11:56 +02001446 struct in_addr ia;
Harald Welte59b04682009-06-10 05:40:52 +08001447
1448 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001449 init_dchan_hdr(dh, RSL_MT_IPAC_MDCX);
Harald Welte59b04682009-06-10 05:40:52 +08001450 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1451 dh->chan_nr = lchan2chan_nr(lchan);
1452
Harald Weltebffa4992009-12-19 16:42:06 +01001453 /* we need to store these now as MDCX_ACK does not return them :( */
1454 lchan->abis_ip.rtp_payload2 = rtp_payload2;
1455 lchan->abis_ip.connect_port = port;
1456 lchan->abis_ip.connect_ip = ip;
1457
Harald Weltefb4a9e92009-07-29 12:12:18 +02001458 /* 0x0- == both directions, 0x-1 == EFR codec */
Harald Weltebffa4992009-12-19 16:42:06 +01001459 lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
Harald Weltefb4a9e92009-07-29 12:12:18 +02001460
Harald Welte98d79f92009-07-28 18:11:56 +02001461 ia.s_addr = htonl(ip);
Harald Weltede4477a2009-12-24 12:20:20 +01001462 DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD2=%d CONN_ID=%d "
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001463 "speech_mode=0x%02x\n", gsm_lchan_name(lchan), inet_ntoa(ia), port,
Harald Weltebffa4992009-12-19 16:42:06 +01001464 rtp_payload2, lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001465
Harald Weltebffa4992009-12-19 16:42:06 +01001466 msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
1467 msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
1468 att_ip = (u_int32_t *) msgb_put(msg, sizeof(ip));
1469 *att_ip = ia.s_addr;
1470 msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
1471 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Harald Welte98d79f92009-07-28 18:11:56 +02001472 if (rtp_payload2)
1473 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
1474
Harald Welte59b04682009-06-10 05:40:52 +08001475 msg->trx = lchan->ts->trx;
1476
1477 return abis_rsl_sendmsg(msg);
1478}
1479
Harald Welte9947d9f2009-12-20 16:51:09 +01001480/* tell BTS to connect RTP stream to our local RTP socket */
1481int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan)
1482{
1483 struct rtp_socket *rs = lchan->abis_ip.rtp_socket;
1484 int rc;
1485
1486 rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr),
1487 ntohs(rs->rtp.sin_local.sin_port),
1488 /* FIXME: use RTP payload of bound socket, not BTS*/
1489 lchan->abis_ip.rtp_payload2);
1490
1491 return rc;
1492}
1493
Harald Welteaed946e2009-10-24 10:29:22 +02001494int rsl_ipacc_pdch_activate(struct gsm_lchan *lchan)
1495{
1496 struct msgb *msg = rsl_msgb_alloc();
1497 struct abis_rsl_dchan_hdr *dh;
1498
1499 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
1500 init_dchan_hdr(dh, RSL_MT_IPAC_PDCH_ACT);
1501 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
1502 dh->chan_nr = lchan2chan_nr(lchan);
1503
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001504 DEBUGP(DRSL, "%s IPAC_PDCH_ACT\n", gsm_lchan_name(lchan));
Harald Welteaed946e2009-10-24 10:29:22 +02001505
1506 msg->trx = lchan->ts->trx;
1507
1508 return abis_rsl_sendmsg(msg);
1509}
1510
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001511static int abis_rsl_rx_ipacc_crcx_ack(struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +08001512{
1513 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1514 struct tlv_parsed tv;
Harald Welte87504212009-12-02 01:56:49 +05301515 struct gsm_lchan *lchan = msg->lchan;
Harald Welte59b04682009-06-10 05:40:52 +08001516
1517 /* the BTS has acknowledged a local bind, it now tells us the IP
1518 * address and port number to which it has bound the given logical
1519 * channel */
1520
1521 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1522 if (!TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_PORT) ||
1523 !TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_IP) ||
Harald Welteb9498952009-07-12 09:45:05 +02001524 !TLVP_PRESENT(&tv, RSL_IE_IPAC_CONN_ID)) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001525 LOGP(DRSL, LOGL_NOTICE, "mandatory IE missing");
Harald Welte59b04682009-06-10 05:40:52 +08001526 return -EINVAL;
1527 }
Harald Welte50517742009-12-20 15:42:44 +01001528
Harald Weltebffa4992009-12-19 16:42:06 +01001529 ipac_parse_rtp(lchan, &tv);
Harald Welte50517742009-12-20 15:42:44 +01001530
1531 /* in case we don't use direct BTS-to-BTS RTP */
1532 if (!ipacc_rtp_direct) {
1533 int rc;
1534 /* the BTS has successfully bound a TCH to a local ip/port,
1535 * which means we can connect our UDP socket to it */
1536 if (lchan->abis_ip.rtp_socket) {
1537 rtp_socket_free(lchan->abis_ip.rtp_socket);
1538 lchan->abis_ip.rtp_socket = NULL;
1539 }
1540
1541 lchan->abis_ip.rtp_socket = rtp_socket_create();
1542 if (!lchan->abis_ip.rtp_socket)
1543 goto out_err;
1544
1545 rc = rtp_socket_connect(lchan->abis_ip.rtp_socket,
1546 lchan->abis_ip.bound_ip,
1547 lchan->abis_ip.bound_port);
1548 if (rc < 0)
1549 goto out_err;
1550 }
1551
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001552 dispatch_signal(SS_ABISIP, S_ABISIP_CRCX_ACK, msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001553
1554 return 0;
Harald Welte50517742009-12-20 15:42:44 +01001555out_err:
1556 return -EIO;
Harald Welte59b04682009-06-10 05:40:52 +08001557}
1558
Harald Weltebffa4992009-12-19 16:42:06 +01001559static int abis_rsl_rx_ipacc_mdcx_ack(struct msgb *msg)
1560{
1561 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1562 struct tlv_parsed tv;
1563 struct gsm_lchan *lchan = msg->lchan;
1564
1565 /* the BTS has acknowledged a remote connect request and
1566 * it now tells us the IP address and port number to which it has
1567 * connected the given logical channel */
1568
1569 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1570 ipac_parse_rtp(lchan, &tv);
1571 dispatch_signal(SS_ABISIP, S_ABISIP_MDCX_ACK, msg->lchan);
1572
1573 return 0;
1574}
1575
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001576static int abis_rsl_rx_ipacc_dlcx_ind(struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +08001577{
1578 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1579 struct tlv_parsed tv;
Harald Welte50517742009-12-20 15:42:44 +01001580 struct gsm_lchan *lchan = msg->lchan;
Harald Welte59b04682009-06-10 05:40:52 +08001581
1582 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte59b04682009-06-10 05:40:52 +08001583
Harald Weltef1a168d2009-07-28 17:58:09 +02001584 if (TLVP_PRESENT(&tv, RSL_IE_CAUSE))
Harald Weltede4477a2009-12-24 12:20:20 +01001585 print_rsl_cause(LOGL_DEBUG, TLVP_VAL(&tv, RSL_IE_CAUSE),
Harald Weltef1a168d2009-07-28 17:58:09 +02001586 TLVP_LEN(&tv, RSL_IE_CAUSE));
Harald Welte59b04682009-06-10 05:40:52 +08001587
Harald Welte50517742009-12-20 15:42:44 +01001588 /* the BTS tells us a RTP stream has been disconnected */
1589 if (lchan->abis_ip.rtp_socket) {
1590 rtp_socket_free(lchan->abis_ip.rtp_socket);
1591 lchan->abis_ip.rtp_socket = NULL;
1592 }
1593
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001594 dispatch_signal(SS_ABISIP, S_ABISIP_DLCX_IND, msg->lchan);
Harald Welteba4e58d2009-07-28 18:02:05 +02001595
Harald Welte59b04682009-06-10 05:40:52 +08001596 return 0;
1597}
1598
1599static int abis_rsl_rx_ipacc(struct msgb *msg)
1600{
1601 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Weltede4477a2009-12-24 12:20:20 +01001602 char *ts_name;
Harald Welte59b04682009-06-10 05:40:52 +08001603 int rc = 0;
1604
1605 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte (local)c4e9c9c2009-12-27 18:16:36 +01001606 ts_name = gsm_lchan_name(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001607
1608 switch (rllh->c.msg_type) {
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001609 case RSL_MT_IPAC_CRCX_ACK:
Harald Weltede4477a2009-12-24 12:20:20 +01001610 DEBUGP(DRSL, "%s IPAC_CRCX_ACK ", ts_name);
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001611 rc = abis_rsl_rx_ipacc_crcx_ack(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001612 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001613 case RSL_MT_IPAC_CRCX_NACK:
Harald Welte59b04682009-06-10 05:40:52 +08001614 /* somehow the BTS was unable to bind the lchan to its local
1615 * port?!? */
Harald Weltede4477a2009-12-24 12:20:20 +01001616 LOGP(DRSL, LOGL_ERROR, "%s IPAC_CRCX_NACK\n", ts_name);
Harald Welte59b04682009-06-10 05:40:52 +08001617 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001618 case RSL_MT_IPAC_MDCX_ACK:
Harald Welte59b04682009-06-10 05:40:52 +08001619 /* the BTS tells us that a connect operation was successful */
Harald Weltede4477a2009-12-24 12:20:20 +01001620 DEBUGP(DRSL, "%s IPAC_MDCX_ACK ", ts_name);
Harald Weltebffa4992009-12-19 16:42:06 +01001621 rc = abis_rsl_rx_ipacc_mdcx_ack(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001622 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001623 case RSL_MT_IPAC_MDCX_NACK:
Harald Welte59b04682009-06-10 05:40:52 +08001624 /* somehow the BTS was unable to connect the lchan to a remote
1625 * port */
Harald Weltede4477a2009-12-24 12:20:20 +01001626 LOGP(DRSL, LOGL_ERROR, "%s IPAC_MDCX_NACK\n", ts_name);
Harald Welte59b04682009-06-10 05:40:52 +08001627 break;
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001628 case RSL_MT_IPAC_DLCX_IND:
Harald Weltede4477a2009-12-24 12:20:20 +01001629 DEBUGP(DRSL, "%s IPAC_DLCX_IND ", ts_name);
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001630 rc = abis_rsl_rx_ipacc_dlcx_ind(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001631 break;
1632 default:
Harald Weltede4477a2009-12-24 12:20:20 +01001633 LOGP(DRSL, LOGL_NOTICE, "Unknown ip.access msg_type 0x%02x\n",
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001634 rllh->c.msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001635 break;
1636 }
1637 DEBUGPC(DRSL, "\n");
1638
1639 return rc;
1640}
1641
1642
1643/* Entry-point where L2 RSL from BTS enters */
1644int abis_rsl_rcvmsg(struct msgb *msg)
1645{
1646 struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
1647 int rc = 0;
1648
1649 switch (rslh->msg_discr & 0xfe) {
1650 case ABIS_RSL_MDISC_RLL:
1651 rc = abis_rsl_rx_rll(msg);
1652 break;
1653 case ABIS_RSL_MDISC_DED_CHAN:
1654 rc = abis_rsl_rx_dchan(msg);
1655 break;
1656 case ABIS_RSL_MDISC_COM_CHAN:
1657 rc = abis_rsl_rx_cchan(msg);
1658 break;
1659 case ABIS_RSL_MDISC_TRX:
1660 rc = abis_rsl_rx_trx(msg);
1661 break;
1662 case ABIS_RSL_MDISC_LOC:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001663 LOGP(DRSL, LOGL_NOTICE, "unimplemented RSL msg disc 0x%02x\n",
Harald Welte59b04682009-06-10 05:40:52 +08001664 rslh->msg_discr);
1665 break;
1666 case ABIS_RSL_MDISC_IPACCESS:
1667 rc = abis_rsl_rx_ipacc(msg);
1668 break;
1669 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +01001670 LOGP(DRSL, LOGL_NOTICE, "unknown RSL message discriminator "
1671 "0x%02x\n", rslh->msg_discr);
Harald Welte59b04682009-06-10 05:40:52 +08001672 return -EINVAL;
1673 }
1674 msgb_free(msg);
1675 return rc;
1676}
1677
Harald Welte59b04682009-06-10 05:40:52 +08001678/* From Table 10.5.33 of GSM 04.08 */
1679int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
1680{
Harald Weltea54a2bb2009-12-01 18:04:30 +05301681 if (bts->si_common.chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
1682 return MAX(1, (3 - bts->si_common.chan_desc.bs_ag_blks_res))
1683 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Harald Welte59b04682009-06-10 05:40:52 +08001684 } else {
Harald Weltea54a2bb2009-12-01 18:04:30 +05301685 return (9 - bts->si_common.chan_desc.bs_ag_blks_res)
1686 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Harald Welte59b04682009-06-10 05:40:52 +08001687 }
1688}