blob: 6a905d25265fb1362b02887abe53f231ad21b628 [file] [log] [blame]
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001/* GSM Radio Signalling Link messages on the A-bis interface
Harald Welte52b1f982008-12-23 20:25:15 +00002 * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */
3
Harald Welte3c9c5f92010-03-04 10:33:10 +01004/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdio.h>
Harald Welte8470bf22008-12-25 23:28:35 +000025#include <stdlib.h>
Harald Welte52b1f982008-12-23 20:25:15 +000026#include <errno.h>
27#include <sys/types.h>
Harald Welte75099262009-02-16 21:12:08 +000028#include <netinet/in.h>
Harald Welte167df882009-02-17 14:35:45 +000029#include <arpa/inet.h>
Harald Welte52b1f982008-12-23 20:25:15 +000030
Harald Welte8470bf22008-12-25 23:28:35 +000031#include <openbsc/gsm_data.h>
32#include <openbsc/gsm_04_08.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010033#include <osmocore/gsm_utils.h>
Harald Welte8470bf22008-12-25 23:28:35 +000034#include <openbsc/abis_rsl.h>
35#include <openbsc/chan_alloc.h>
Harald Welteedcc5272009-08-09 13:47:35 +020036#include <openbsc/bsc_rll.h>
Harald Welte8470bf22008-12-25 23:28:35 +000037#include <openbsc/debug.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010038#include <osmocore/tlv.h>
Holger Freyther392209c2009-02-10 00:06:19 +000039#include <openbsc/paging.h>
Harald Welte167df882009-02-17 14:35:45 +000040#include <openbsc/signal.h>
Harald Welte3c7dc6e2009-11-29 19:07:28 +010041#include <openbsc/meas_rep.h>
Harald Welte17f5bf62009-12-20 15:42:44 +010042#include <openbsc/rtp_proxy.h>
Harald Welte2e411c72010-03-01 21:59:06 +010043#include <osmocore/rsl.h>
Harald Welte52b1f982008-12-23 20:25:15 +000044
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +080045#include <osmocore/talloc.h>
46
Harald Welte8470bf22008-12-25 23:28:35 +000047#define RSL_ALLOC_SIZE 1024
48#define RSL_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000049
Holger Freyther3b72a892009-02-04 00:31:39 +000050#define MAX(a, b) (a) >= (b) ? (a) : (b)
51
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +080052static int rsl_send_imm_assignment(struct gsm_lchan *lchan);
53
Harald Welte52b1f982008-12-23 20:25:15 +000054static u_int8_t mdisc_by_msgtype(u_int8_t msg_type)
55{
56 /* mask off the transparent bit ? */
57 msg_type &= 0xfe;
58
Harald Welte8470bf22008-12-25 23:28:35 +000059 if ((msg_type & 0xf0) == 0x00)
Harald Welte52b1f982008-12-23 20:25:15 +000060 return ABIS_RSL_MDISC_RLL;
Harald Welte8470bf22008-12-25 23:28:35 +000061 if ((msg_type & 0xf0) == 0x10) {
Harald Welte52b1f982008-12-23 20:25:15 +000062 if (msg_type >= 0x19 && msg_type <= 0x22)
63 return ABIS_RSL_MDISC_TRX;
64 else
65 return ABIS_RSL_MDISC_COM_CHAN;
66 }
Harald Welte2d5b6382008-12-27 19:46:06 +000067 if ((msg_type & 0xe0) == 0x20)
Harald Welte52b1f982008-12-23 20:25:15 +000068 return ABIS_RSL_MDISC_DED_CHAN;
69
70 return ABIS_RSL_MDISC_LOC;
71}
72
73static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh,
74 u_int8_t msg_type)
75{
76 dh->c.msg_discr = mdisc_by_msgtype(msg_type);
77 dh->c.msg_type = msg_type;
78 dh->ie_chan = RSL_IE_CHAN_NR;
79}
80
Harald Welte8470bf22008-12-25 23:28:35 +000081/* determine logical channel based on TRX and channel number IE */
82struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr)
83{
84 struct gsm_lchan *lchan;
85 u_int8_t ts_nr = chan_nr & 0x07;
86 u_int8_t cbits = chan_nr >> 3;
87 u_int8_t lch_idx;
88 struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
89
90 if (cbits == 0x01) {
91 lch_idx = 0; /* TCH/F */
Harald Weltea1499d02009-10-24 10:25:50 +020092 if (ts->pchan != GSM_PCHAN_TCH_F &&
93 ts->pchan != GSM_PCHAN_PDCH &&
94 ts->pchan != GSM_PCHAN_TCH_F_PDCH)
Harald Welteb1d4c8e2009-12-17 23:10:46 +010095 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +000096 chan_nr, ts->pchan);
97 } else if ((cbits & 0x1e) == 0x02) {
98 lch_idx = cbits & 0x1; /* TCH/H */
99 if (ts->pchan != GSM_PCHAN_TCH_H)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100100 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000101 chan_nr, ts->pchan);
102 } else if ((cbits & 0x1c) == 0x04) {
103 lch_idx = cbits & 0x3; /* SDCCH/4 */
104 if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100105 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000106 chan_nr, ts->pchan);
107 } else if ((cbits & 0x18) == 0x08) {
108 lch_idx = cbits & 0x7; /* SDCCH/8 */
109 if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100110 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000111 chan_nr, ts->pchan);
112 } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
113 lch_idx = 0;
114 if (ts->pchan != GSM_PCHAN_CCCH &&
115 ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100116 LOGP(DRSL, LOGL_ERROR, "chan_nr=0x%02x but pchan=%u\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000117 chan_nr, ts->pchan);
118 /* FIXME: we should not return first sdcch4 !!! */
119 } else {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100120 LOGP(DRSL, LOGL_ERROR, "unknown chan_nr=0x%02x\n", chan_nr);
Harald Welte8470bf22008-12-25 23:28:35 +0000121 return NULL;
122 }
123
124 lchan = &ts->lchan[lch_idx];
Harald Weltedc5062b2010-03-26 21:28:59 +0800125 log_set_context(BSC_CTX_LCHAN, lchan);
Harald Welte8470bf22008-12-25 23:28:35 +0000126
127 return lchan;
128}
129
Holger Hans Peter Freythere81a6102009-10-22 11:47:45 +0200130/* See Table 10.5.25 of GSM04.08 */
Harald Welte24766092009-12-09 19:18:32 +0100131u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan)
Harald Welte8470bf22008-12-25 23:28:35 +0000132{
133 struct gsm_bts_trx_ts *ts = lchan->ts;
134 u_int8_t cbits, chan_nr;
135
136 switch (ts->pchan) {
137 case GSM_PCHAN_TCH_F:
Harald Weltea1499d02009-10-24 10:25:50 +0200138 case GSM_PCHAN_PDCH:
139 case GSM_PCHAN_TCH_F_PDCH:
Harald Welte8470bf22008-12-25 23:28:35 +0000140 cbits = 0x01;
141 break;
142 case GSM_PCHAN_TCH_H:
143 cbits = 0x02;
144 cbits += lchan->nr;
145 break;
146 case GSM_PCHAN_CCCH_SDCCH4:
147 cbits = 0x04;
148 cbits += lchan->nr;
149 break;
150 case GSM_PCHAN_SDCCH8_SACCH8C:
151 cbits = 0x08;
152 cbits += lchan->nr;
153 break;
154 default:
155 case GSM_PCHAN_CCCH:
156 cbits = 0x10;
157 break;
158 }
159
160 chan_nr = (cbits << 3) | (ts->nr & 0x7);
161
162 return chan_nr;
163}
164
Harald Welte52b1f982008-12-23 20:25:15 +0000165/* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */
166u_int64_t str_to_imsi(const char *imsi_str)
167{
168 u_int64_t ret;
169
170 ret = strtoull(imsi_str, NULL, 10);
171
172 return ret;
173}
174
175/* Table 5 Clause 7 TS 05.02 */
176unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res)
177{
178 if (!bs_ccch_sdcch_comb)
179 return 9 - bs_ag_blks_res;
180 else
181 return 3 - bs_ag_blks_res;
182}
183
184/* Chapter 6.5.2 of TS 05.02 */
185unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans,
186 unsigned int n_pag_blocks)
187{
188 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks;
189}
190
191/* Chapter 6.5.2 of TS 05.02 */
192unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
193 int n_pag_blocks)
194{
195 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks;
196}
197
Harald Welte8470bf22008-12-25 23:28:35 +0000198static struct msgb *rsl_msgb_alloc(void)
199{
Harald Welte966636f2009-06-26 19:39:35 +0200200 return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM,
201 "RSL");
Harald Welte8470bf22008-12-25 23:28:35 +0000202}
203
Harald Welte362322e2009-02-15 14:36:38 +0000204#define MACBLOCK_SIZE 23
205static void pad_macblock(u_int8_t *out, const u_int8_t *in, int len)
206{
207 memcpy(out, in, len);
208
209 if (len < MACBLOCK_SIZE)
210 memset(out+len, 0x2b, MACBLOCK_SIZE-len);
211}
212
Harald Welte08d91a52009-08-30 15:37:11 +0900213/* Chapter 9.3.7: Encryption Information */
214static int build_encr_info(u_int8_t *out, struct gsm_lchan *lchan)
215{
216 *out++ = lchan->encr.alg_id & 0xff;
217 if (lchan->encr.key_len)
218 memcpy(out, lchan->encr.key, lchan->encr.key_len);
219 return lchan->encr.key_len + 1;
220}
221
Harald Welte5b8ed432009-12-24 12:20:20 +0100222static void print_rsl_cause(int lvl, const u_int8_t *cause_v, u_int8_t cause_len)
Harald Welte8830e072009-07-28 17:58:09 +0200223{
Harald Welte7f93cea2009-02-23 00:02:59 +0000224 int i;
225
Harald Welte5b8ed432009-12-24 12:20:20 +0100226 LOGPC(DRSL, lvl, "CAUSE=0x%02x(%s) ",
Harald Welte8830e072009-07-28 17:58:09 +0200227 cause_v[0], rsl_err_name(cause_v[0]));
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +0200228 for (i = 1; i < cause_len-1; i++)
Harald Welte5b8ed432009-12-24 12:20:20 +0100229 LOGPC(DRSL, lvl, "%02x ", cause_v[i]);
Harald Welte7f93cea2009-02-23 00:02:59 +0000230}
231
Harald Welte52b1f982008-12-23 20:25:15 +0000232/* Send a BCCH_INFO message as per Chapter 8.5.1 */
Harald Weltee79769b2009-02-07 00:48:17 +0000233int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000234 const u_int8_t *data, int len)
235{
236 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000237 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000238
239 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh);
240 init_dchan_hdr(dh, RSL_MT_BCCH_INFO);
241 dh->chan_nr = RSL_CHAN_BCCH;
242
243 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
244 msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data);
245
Harald Weltee79769b2009-02-07 00:48:17 +0000246 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000247
248 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000249}
250
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +0200251int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000252 const u_int8_t *data, int len)
253{
254 struct abis_rsl_common_hdr *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000255 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000256
257 ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch));
258 ch->msg_discr = ABIS_RSL_MDISC_TRX;
259 ch->msg_type = RSL_MT_SACCH_FILL;
260
261 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
Harald Welte702d8702008-12-26 20:25:35 +0000262 msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data);
Harald Welte52b1f982008-12-23 20:25:15 +0000263
Harald Weltee79769b2009-02-07 00:48:17 +0000264 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000265
266 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000267}
268
Harald Weltefcd24452009-06-20 18:15:19 +0200269int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db)
270{
271 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200272 struct msgb *msg;
Harald Weltefcd24452009-06-20 18:15:19 +0200273 u_int8_t chan_nr = lchan2chan_nr(lchan);
274
275 db = abs(db);
276 if (db > 30)
277 return -EINVAL;
278
Harald Welteeab33352009-06-27 03:09:08 +0200279 msg = rsl_msgb_alloc();
280
Harald Weltefcd24452009-06-20 18:15:19 +0200281 lchan->bs_power = db/2;
282 if (fpc)
283 lchan->bs_power |= 0x10;
284
285 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
286 init_dchan_hdr(dh, RSL_MT_BS_POWER_CONTROL);
287 dh->chan_nr = chan_nr;
288
289 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
290
291 msg->trx = lchan->ts->trx;
292
293 return abis_rsl_sendmsg(msg);
294}
295
Harald Weltefcd24452009-06-20 18:15:19 +0200296int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm)
297{
298 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200299 struct msgb *msg;
Harald Weltefcd24452009-06-20 18:15:19 +0200300 u_int8_t chan_nr = lchan2chan_nr(lchan);
301 int ctl_lvl;
302
Harald Welte66b6a8d2009-08-09 14:45:18 +0200303 ctl_lvl = ms_pwr_ctl_lvl(lchan->ts->trx->bts->band, dbm);
Harald Weltefcd24452009-06-20 18:15:19 +0200304 if (ctl_lvl < 0)
305 return ctl_lvl;
306
Harald Welteeab33352009-06-27 03:09:08 +0200307 msg = rsl_msgb_alloc();
308
Harald Weltefcd24452009-06-20 18:15:19 +0200309 lchan->ms_power = ctl_lvl;
310
311 if (fpc)
312 lchan->ms_power |= 0x20;
313
314 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
315 init_dchan_hdr(dh, RSL_MT_MS_POWER_CONTROL);
316 dh->chan_nr = chan_nr;
317
318 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
319
320 msg->trx = lchan->ts->trx;
321
322 return abis_rsl_sendmsg(msg);
323}
324
Harald Welte9943c5b2009-07-29 15:41:29 +0200325static int channel_mode_from_lchan(struct rsl_ie_chan_mode *cm,
326 struct gsm_lchan *lchan)
327{
328 memset(cm, 0, sizeof(cm));
329
330 /* FIXME: what to do with data calls ? */
331 cm->dtx_dtu = 0x00;
332
333 /* set TCH Speech/Data */
334 cm->spd_ind = lchan->rsl_cmode;
335
Harald Welte1a79d362009-11-27 08:55:16 +0100336 if (lchan->rsl_cmode == RSL_CMOD_SPD_SIGN &&
337 lchan->tch_mode != GSM48_CMODE_SIGN)
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100338 LOGP(DRSL, LOGL_ERROR, "unsupported: rsl_mode == signalling, "
Harald Welte1a79d362009-11-27 08:55:16 +0100339 "but tch_mode != signalling\n");
340
Harald Welte9943c5b2009-07-29 15:41:29 +0200341 switch (lchan->type) {
342 case GSM_LCHAN_SDCCH:
343 cm->chan_rt = RSL_CMOD_CRT_SDCCH;
344 break;
345 case GSM_LCHAN_TCH_F:
346 cm->chan_rt = RSL_CMOD_CRT_TCH_Bm;
347 break;
348 case GSM_LCHAN_TCH_H:
349 cm->chan_rt = RSL_CMOD_CRT_TCH_Lm;
350 break;
351 case GSM_LCHAN_NONE:
352 case GSM_LCHAN_UNKNOWN:
353 default:
354 return -EINVAL;
355 }
356
357 switch (lchan->tch_mode) {
358 case GSM48_CMODE_SIGN:
359 cm->chan_rate = 0;
360 break;
361 case GSM48_CMODE_SPEECH_V1:
362 cm->chan_rate = RSL_CMOD_SP_GSM1;
363 break;
364 case GSM48_CMODE_SPEECH_EFR:
365 cm->chan_rate = RSL_CMOD_SP_GSM2;
366 break;
367 case GSM48_CMODE_SPEECH_AMR:
368 cm->chan_rate = RSL_CMOD_SP_GSM3;
369 break;
370 case GSM48_CMODE_DATA_14k5:
371 cm->chan_rate = RSL_CMOD_SP_NT_14k5;
372 break;
373 case GSM48_CMODE_DATA_12k0:
374 cm->chan_rate = RSL_CMOD_SP_NT_12k0;
375 break;
376 case GSM48_CMODE_DATA_6k0:
377 cm->chan_rate = RSL_CMOD_SP_NT_6k0;
378 break;
379 default:
380 return -EINVAL;
381 }
382
383 return 0;
384}
385
Harald Welte52b1f982008-12-23 20:25:15 +0000386/* Chapter 8.4.1 */
Harald Welteddab3c72009-02-28 13:19:15 +0000387#if 0
Harald Weltee79769b2009-02-07 00:48:17 +0000388int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
Harald Welte52b1f982008-12-23 20:25:15 +0000389 u_int8_t act_type,
390 struct rsl_ie_chan_mode *chan_mode,
391 struct rsl_ie_chan_ident *chan_ident,
392 u_int8_t bs_power, u_int8_t ms_power,
393 u_int8_t ta)
394{
395 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000396 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000397
398 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
399 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
400 dh->chan_nr = chan_nr;
401
402 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
403 /* For compatibility with Phase 1 */
404 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode),
405 (u_int8_t *) chan_mode);
406 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
Harald Welte702d8702008-12-26 20:25:35 +0000407 (u_int8_t *) chan_ident);
Harald Welte702d8702008-12-26 20:25:35 +0000408#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000409 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
410 (u_int8_t *) &encr_info);
Harald Welte702d8702008-12-26 20:25:35 +0000411#endif
Harald Welted4c9bf32009-02-15 16:56:18 +0000412 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
Harald Welte52b1f982008-12-23 20:25:15 +0000413 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
414 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
415
Harald Weltee79769b2009-02-07 00:48:17 +0000416 msg->trx = trx;
417
Harald Welte8470bf22008-12-25 23:28:35 +0000418 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000419}
Harald Welteddab3c72009-02-28 13:19:15 +0000420#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000421
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +0200422int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
Harald Welte8d77b952009-12-17 00:31:10 +0100423 u_int8_t ta, u_int8_t ho_ref)
Harald Welte4b634542008-12-27 01:55:51 +0000424{
425 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200426 struct msgb *msg;
Harald Welte9943c5b2009-07-29 15:41:29 +0200427 int rc;
Harald Welte4b634542008-12-27 01:55:51 +0000428
429 u_int8_t chan_nr = lchan2chan_nr(lchan);
Harald Welte4b634542008-12-27 01:55:51 +0000430 struct rsl_ie_chan_mode cm;
laforge694a5cf2010-06-20 21:38:19 +0200431 struct gsm48_chan_desc cd;
432 uint8_t *msgb_cd;
Harald Welte4b634542008-12-27 01:55:51 +0000433
Harald Welte9943c5b2009-07-29 15:41:29 +0200434 rc = channel_mode_from_lchan(&cm, lchan);
435 if (rc < 0)
436 return rc;
Harald Welte4b634542008-12-27 01:55:51 +0000437
laforge694a5cf2010-06-20 21:38:19 +0200438 gsm48_lchan2chan_desc(&cd, lchan);
Harald Welte4b634542008-12-27 01:55:51 +0000439
Harald Welteeab33352009-06-27 03:09:08 +0200440 msg = rsl_msgb_alloc();
Harald Welte4b634542008-12-27 01:55:51 +0000441 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
442 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
443 dh->chan_nr = chan_nr;
444
445 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
Harald Welte4b634542008-12-27 01:55:51 +0000446 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
447 (u_int8_t *) &cm);
Harald Welte8d77b952009-12-17 00:31:10 +0100448 /* For compatibility with Phase 1 */
laforge694a5cf2010-06-20 21:38:19 +0200449 /* RSL IE TAG */
450 msgb_v_put(msg, RSL_IE_CHAN_IDENT);
451 /* RSL IE LEN: 04.08_cd_tag + CD + 04.08_ma_tag + 04.08_ma_len + ma_len */
452 msgb_v_put(msg, 1 + sizeof(struct gsm48_chan_desc) + 2 + lchan->ts->hopping.ma_len);
453 /* GSM 04.08 Chan Desc 2 (TAG + fixed 3 byte length V) */
454 msgb_v_put(msg, GSM48_IE_CHANDESC_2);
455 msgb_cd = msgb_put(msg, sizeof(cd));
456 memcpy(msgb_cd, &cd, sizeof(cd));
457 /* GSM 04.08 Mobile Allocation: TLV */
458 msgb_tlv_put(msg, GSM48_IE_MA_AFTER, lchan->ts->hopping.ma_len,
459 lchan->ts->hopping.ma_data);
460
Harald Welte08d91a52009-08-30 15:37:11 +0900461 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
462 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
463 rc = build_encr_info(encr_info, lchan);
464 if (rc > 0)
465 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
466 }
467
Harald Welte8d77b952009-12-17 00:31:10 +0100468 switch (act_type) {
469 case RSL_ACT_INTER_ASYNC:
470 case RSL_ACT_INTER_SYNC:
471 msgb_tv_put(msg, RSL_IE_HANDO_REF, ho_ref);
472 break;
473 default:
474 break;
475 }
476
Harald Welted4c9bf32009-02-15 16:56:18 +0000477 msgb_tv_put(msg, RSL_IE_BS_POWER, lchan->bs_power);
478 msgb_tv_put(msg, RSL_IE_MS_POWER, lchan->ms_power);
Harald Welte4b634542008-12-27 01:55:51 +0000479 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
480
Holger Hans Peter Freyther93b6c652010-01-28 04:45:05 +0100481 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR)
482 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
483 (u_int8_t *) &lchan->mr_conf);
484
Harald Weltee79769b2009-02-07 00:48:17 +0000485 msg->trx = lchan->ts->trx;
486
Harald Welte4b634542008-12-27 01:55:51 +0000487 return abis_rsl_sendmsg(msg);
488}
489
Harald Welte470abb72009-07-29 11:38:15 +0200490/* Chapter 8.4.9: Modify channel mode on BTS side */
Harald Welteda783762009-02-18 03:29:53 +0000491int rsl_chan_mode_modify_req(struct gsm_lchan *lchan)
492{
493 struct abis_rsl_dchan_hdr *dh;
Harald Welteeab33352009-06-27 03:09:08 +0200494 struct msgb *msg;
Harald Welte9943c5b2009-07-29 15:41:29 +0200495 int rc;
Harald Welteda783762009-02-18 03:29:53 +0000496
497 u_int8_t chan_nr = lchan2chan_nr(lchan);
498 struct rsl_ie_chan_mode cm;
499
Harald Welte9943c5b2009-07-29 15:41:29 +0200500 rc = channel_mode_from_lchan(&cm, lchan);
501 if (rc < 0)
502 return rc;
Harald Welteda783762009-02-18 03:29:53 +0000503
Harald Welteeab33352009-06-27 03:09:08 +0200504 msg = rsl_msgb_alloc();
Harald Welteda783762009-02-18 03:29:53 +0000505 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
506 init_dchan_hdr(dh, RSL_MT_MODE_MODIFY_REQ);
507 dh->chan_nr = chan_nr;
508
509 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
510 (u_int8_t *) &cm);
Harald Welte08d91a52009-08-30 15:37:11 +0900511
512 if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
513 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
514 rc = build_encr_info(encr_info, lchan);
515 if (rc > 0)
516 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, rc, encr_info);
517 }
518
Holger Hans Peter Freytherea528022009-11-18 22:57:02 +0100519 if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) {
520 msgb_tlv_put(msg, RSL_IE_MR_CONFIG, sizeof(lchan->mr_conf),
521 (u_int8_t *) &lchan->mr_conf);
522 }
523
Harald Welte08d91a52009-08-30 15:37:11 +0900524 msg->trx = lchan->ts->trx;
525
526 return abis_rsl_sendmsg(msg);
527}
528
529/* Chapter 8.4.6: Send the encryption command with given L3 info */
530int rsl_encryption_cmd(struct msgb *msg)
531{
532 struct abis_rsl_dchan_hdr *dh;
533 struct gsm_lchan *lchan = msg->lchan;
534 u_int8_t chan_nr = lchan2chan_nr(lchan);
535 u_int8_t encr_info[MAX_A5_KEY_LEN+2];
Sylvain Munaut82aa6842009-09-27 11:13:18 +0200536 u_int8_t l3_len = msg->len;
Harald Welte08d91a52009-08-30 15:37:11 +0900537 int rc;
538
539 /* First push the L3 IE tag and length */
540 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
541
542 /* then the link identifier (SAPI0, main sign link) */
543 msgb_tv_push(msg, RSL_IE_LINK_IDENT, 0);
544
545 /* then encryption information */
546 rc = build_encr_info(encr_info, lchan);
547 if (rc <= 0)
548 return rc;
549 msgb_tlv_push(msg, RSL_IE_ENCR_INFO, rc, encr_info);
550
551 /* and finally the DCHAN header */
552 dh = (struct abis_rsl_dchan_hdr *) msgb_push(msg, sizeof(*dh));
553 init_dchan_hdr(dh, RSL_MT_ENCR_CMD);
554 dh->chan_nr = chan_nr;
Harald Welteda783762009-02-18 03:29:53 +0000555
556 msg->trx = lchan->ts->trx;
557
558 return abis_rsl_sendmsg(msg);
559}
560
Harald Welte115d1032009-08-10 11:43:22 +0200561/* Chapter 8.4.5 / 4.6: Deactivate the SACCH after 04.08 RR CHAN RELEASE */
Harald Welteae0f2362009-07-19 18:36:49 +0200562int rsl_deact_sacch(struct gsm_lchan *lchan)
563{
564 struct abis_rsl_dchan_hdr *dh;
565 struct msgb *msg = rsl_msgb_alloc();
566
567 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
568 init_dchan_hdr(dh, RSL_MT_DEACTIVATE_SACCH);
569 dh->chan_nr = lchan2chan_nr(lchan);
570
571 msg->lchan = lchan;
572 msg->trx = lchan->ts->trx;
573
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100574 DEBUGP(DRSL, "%s DEACTivate SACCH CMD\n", gsm_lchan_name(lchan));
Harald Welteae0f2362009-07-19 18:36:49 +0200575
576 return abis_rsl_sendmsg(msg);
577}
578
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800579static void error_timeout_cb(void *data)
580{
581 struct gsm_lchan *lchan = data;
582 if (lchan->state != LCHAN_S_REL_ERR) {
583 LOGP(DRSL, LOGL_ERROR, "%s error timeout but not in error state: %d\n",
584 gsm_lchan_name(lchan), lchan->state);
585 return;
586 }
587
588 /* go back to the none state */
589 LOGP(DRSL, LOGL_NOTICE, "%s is back in operation.\n", gsm_lchan_name(lchan));
Holger Hans Peter Freyther44752d92010-06-08 11:53:33 +0800590 rsl_lchan_set_state(lchan, LCHAN_S_NONE);
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800591}
592
Harald Welte115d1032009-08-10 11:43:22 +0200593/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800594static int rsl_rf_chan_release(struct gsm_lchan *lchan, int error)
Harald Welte52b1f982008-12-23 20:25:15 +0000595{
596 struct abis_rsl_dchan_hdr *dh;
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800597 struct msgb *msg;
Harald Welte52b1f982008-12-23 20:25:15 +0000598
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800599 if (lchan->state == LCHAN_S_REL_ERR) {
600 LOGP(DRSL, LOGL_NOTICE, "%s is in error state not sending release.\n",
601 gsm_lchan_name(lchan));
602 return -1;
603 }
604
605 msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000606 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
607 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
Harald Welte8470bf22008-12-25 23:28:35 +0000608 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000609
Harald Welte8470bf22008-12-25 23:28:35 +0000610 msg->lchan = lchan;
611 msg->trx = lchan->ts->trx;
612
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800613 DEBUGP(DRSL, "%s RF Channel Release CMD due error %d\n", gsm_lchan_name(lchan), error);
614
615 if (error) {
616 /*
617 * the nanoBTS sends RLL release indications after the channel release. This can
618 * be a problem when we have reassigned the channel to someone else and then can
619 * not figure out who used this channel.
620 */
Holger Hans Peter Freyther44752d92010-06-08 11:53:33 +0800621 rsl_lchan_set_state(lchan, LCHAN_S_REL_ERR);
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800622 lchan->error_timer.data = lchan;
623 lchan->error_timer.cb = error_timeout_cb;
624 bsc_schedule_timer(&lchan->error_timer,
625 msg->trx->bts->network->T3111 + 2, 0);
626 }
Harald Welte2d5b6382008-12-27 19:46:06 +0000627
Harald Welte115d1032009-08-10 11:43:22 +0200628 /* BTS will respond by RF CHAN REL ACK */
Harald Welte8470bf22008-12-25 23:28:35 +0000629 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000630}
631
632int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
633 u_int8_t *ms_ident, u_int8_t chan_needed)
634{
635 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000636 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000637
638 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
639 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
640 dh->chan_nr = RSL_CHAN_PCH_AGCH;
641
642 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
Harald Welte255539c2008-12-28 02:26:27 +0000643 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
Harald Welte52b1f982008-12-23 20:25:15 +0000644 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
645
Harald Welte8470bf22008-12-25 23:28:35 +0000646 msg->trx = bts->c0;
647
648 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000649}
650
Holger Freyther7448a532009-01-04 20:18:23 +0000651int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
652 struct gsm_subscriber *subscr)
653{
Holger Freytherca362a62009-01-04 21:05:01 +0000654#if 0
Holger Freyther7448a532009-01-04 20:18:23 +0000655 u_int8_t mi[128];
656 unsigned int mi_len;
657 u_int8_t paging_group;
Holger Freytherca362a62009-01-04 21:05:01 +0000658#endif
Holger Freyther7448a532009-01-04 20:18:23 +0000659
660 return -1;
661}
662
Harald Welte52b1f982008-12-23 20:25:15 +0000663int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
664{
665 int i, len = strlen(str_in);
666
667 for (i = 0; i < len; i++) {
668 int num = str_in[i] - 0x30;
669 if (num < 0 || num > 9)
670 return -1;
671 if (i % 2 == 0)
672 bcd_out[i/2] = num;
673 else
674 bcd_out[i/2] |= (num << 4);
675 }
676
677 return 0;
678}
679
Harald Welte702d8702008-12-26 20:25:35 +0000680/* Chapter 8.5.6 */
Harald Welte52b1f982008-12-23 20:25:15 +0000681int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
682{
Harald Welte8470bf22008-12-25 23:28:35 +0000683 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000684 struct abis_rsl_dchan_hdr *dh;
Harald Welte362322e2009-02-15 14:36:38 +0000685 u_int8_t buf[MACBLOCK_SIZE];
Harald Welte52b1f982008-12-23 20:25:15 +0000686
687 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
688 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
689 dh->chan_nr = RSL_CHAN_PCH_AGCH;
690
Harald Welte362322e2009-02-15 14:36:38 +0000691 switch (bts->type) {
692 case GSM_BTS_TYPE_BS11:
693 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
694 break;
695 default:
696 /* If phase 2, construct a FULL_IMM_ASS_INFO */
697 pad_macblock(buf, val, len);
698 msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf);
699 break;
700 }
Harald Welte52b1f982008-12-23 20:25:15 +0000701
Harald Welte8470bf22008-12-25 23:28:35 +0000702 msg->trx = bts->c0;
703
704 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000705}
706
Harald Welte67fa91b2009-08-10 09:51:40 +0200707/* Send Siemens specific MS RF Power Capability Indication */
Harald Welte31c48932009-08-10 10:07:33 +0200708int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci)
Harald Welte67fa91b2009-08-10 09:51:40 +0200709{
710 struct msgb *msg = rsl_msgb_alloc();
711 struct abis_rsl_dchan_hdr *dh;
712
713 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
714 init_dchan_hdr(dh, RSL_MT_SIEMENS_MRPCI);
Harald Welte3c456d02009-08-10 11:26:14 +0200715 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
Harald Welte67fa91b2009-08-10 09:51:40 +0200716 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte31c48932009-08-10 10:07:33 +0200717 msgb_tv_put(msg, RSL_IE_SIEMENS_MRPCI, *(u_int8_t *)mrpci);
Harald Welte67fa91b2009-08-10 09:51:40 +0200718
Harald Welte5b8ed432009-12-24 12:20:20 +0100719 DEBUGP(DRSL, "%s TX Siemens MRPCI 0x%02x\n",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100720 gsm_lchan_name(lchan), *(u_int8_t *)mrpci);
Harald Welte3c456d02009-08-10 11:26:14 +0200721
722 msg->trx = lchan->ts->trx;
723
Harald Welte67fa91b2009-08-10 09:51:40 +0200724 return abis_rsl_sendmsg(msg);
725}
726
727
Harald Welte8470bf22008-12-25 23:28:35 +0000728/* Send "DATA REQUEST" message with given L3 Info payload */
Harald Welte52b1f982008-12-23 20:25:15 +0000729/* Chapter 8.3.1 */
Harald Welte8470bf22008-12-25 23:28:35 +0000730int rsl_data_request(struct msgb *msg, u_int8_t link_id)
Harald Welte52b1f982008-12-23 20:25:15 +0000731{
Harald Welte8470bf22008-12-25 23:28:35 +0000732 if (msg->lchan == NULL) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100733 LOGP(DRSL, LOGL_ERROR, "cannot send DATA REQUEST to unknown lchan\n");
Harald Welte8470bf22008-12-25 23:28:35 +0000734 return -EINVAL;
735 }
Harald Welte52b1f982008-12-23 20:25:15 +0000736
Harald Welte3c9c5f92010-03-04 10:33:10 +0100737 rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, lchan2chan_nr(msg->lchan),
738 link_id, 1);
Harald Welte52b1f982008-12-23 20:25:15 +0000739
Harald Welte8470bf22008-12-25 23:28:35 +0000740 msg->trx = msg->lchan->ts->trx;
741
742 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000743}
744
Harald Welteedcc5272009-08-09 13:47:35 +0200745/* Send "ESTABLISH REQUEST" message with given L3 Info payload */
746/* Chapter 8.3.1 */
747int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
748{
Harald Welte3c9c5f92010-03-04 10:33:10 +0100749 struct msgb *msg;
Harald Welteedcc5272009-08-09 13:47:35 +0200750
Harald Welte3c9c5f92010-03-04 10:33:10 +0100751 msg = rsl_rll_simple(RSL_MT_EST_REQ, lchan2chan_nr(lchan),
752 link_id, 0);
Harald Welteedcc5272009-08-09 13:47:35 +0200753 msg->trx = lchan->ts->trx;
754
755 return abis_rsl_sendmsg(msg);
756}
757
Harald Welted2dc1de2009-08-08 13:15:07 +0200758/* Chapter 8.3.7 Request the release of multiframe mode of RLL connection.
759 This is what higher layers should call. The BTS then responds with
760 RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
761 which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
762 lchan_free() */
Holger Hans Peter Freyther4f5848d2010-06-08 11:57:45 +0800763int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t reason)
Harald Welted2dc1de2009-08-08 13:15:07 +0200764{
Harald Welted2dc1de2009-08-08 13:15:07 +0200765
Harald Welte3c9c5f92010-03-04 10:33:10 +0100766 struct msgb *msg;
767
768 msg = rsl_rll_simple(RSL_MT_REL_REQ, lchan2chan_nr(lchan),
769 link_id, 0);
Holger Hans Peter Freyther4f5848d2010-06-08 11:57:45 +0800770 /* 0 is normal release, 1 is local end */
771 msgb_tv_put(msg, RSL_IE_RELEASE_MODE, reason);
Harald Welted2dc1de2009-08-08 13:15:07 +0200772
Harald Welte8e93b792009-12-29 10:44:17 +0100773 /* FIXME: start some timer in case we don't receive a REL ACK ? */
774
Harald Welted2dc1de2009-08-08 13:15:07 +0200775 msg->trx = lchan->ts->trx;
776
777 return abis_rsl_sendmsg(msg);
778}
779
Holger Hans Peter Freyther74419492010-04-10 00:12:31 +0200780int rsl_lchan_set_state(struct gsm_lchan *lchan, int state)
781{
782 lchan->state = state;
783 return 0;
784}
785
Harald Welte702d8702008-12-26 20:25:35 +0000786/* Chapter 8.4.2: Channel Activate Acknowledge */
787static int rsl_rx_chan_act_ack(struct msgb *msg)
788{
789 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
790
791 /* BTS has confirmed channel activation, we now need
792 * to assign the activated channel to the MS */
Harald Welte4b634542008-12-27 01:55:51 +0000793 if (rslh->ie_chan != RSL_IE_CHAN_NR)
794 return -EINVAL;
Harald Welted011e8b2009-11-29 22:45:52 +0100795
Harald Welte8e93b792009-12-29 10:44:17 +0100796 if (msg->lchan->state != LCHAN_S_ACT_REQ)
Harald Welte1887f9d2009-12-29 10:52:38 +0100797 LOGP(DRSL, LOGL_NOTICE, "%s CHAN ACT ACK, but state %s\n",
798 gsm_lchan_name(msg->lchan),
799 gsm_lchans_name(msg->lchan->state));
Holger Hans Peter Freyther74419492010-04-10 00:12:31 +0200800 rsl_lchan_set_state(msg->lchan, LCHAN_S_ACTIVE);
Harald Welteb8bfc562009-12-21 13:27:11 +0100801
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +0800802 if (msg->lchan->rqd_ref) {
803 rsl_send_imm_assignment(msg->lchan);
804 talloc_free(msg->lchan->rqd_ref);
805 msg->lchan->rqd_ref = NULL;
806 msg->lchan->rqd_ta = 0;
807 }
808
Harald Welted011e8b2009-11-29 22:45:52 +0100809 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_ACK, msg->lchan);
810
Harald Welte4b634542008-12-27 01:55:51 +0000811 return 0;
812}
Harald Welte702d8702008-12-26 20:25:35 +0000813
Harald Welte4b634542008-12-27 01:55:51 +0000814/* Chapter 8.4.3: Channel Activate NACK */
815static int rsl_rx_chan_act_nack(struct msgb *msg)
816{
Harald Welte6dab0552009-05-01 17:21:37 +0000817 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
818 struct tlv_parsed tp;
Harald Welte4b634542008-12-27 01:55:51 +0000819
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100820 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL ACTIVATE NACK",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100821 gsm_lchan_name(msg->lchan));
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100822
Harald Welte6dab0552009-05-01 17:21:37 +0000823 /* BTS has rejected channel activation ?!? */
824 if (dh->ie_chan != RSL_IE_CHAN_NR)
Harald Welte4b634542008-12-27 01:55:51 +0000825 return -EINVAL;
Harald Welte6dab0552009-05-01 17:21:37 +0000826
827 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte (local)3e460312009-12-27 18:12:29 +0100828 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE)) {
829 const u_int8_t *cause = TLVP_VAL(&tp, RSL_IE_CAUSE);
830 print_rsl_cause(LOGL_ERROR, cause,
Harald Welte8830e072009-07-28 17:58:09 +0200831 TLVP_LEN(&tp, RSL_IE_CAUSE));
Harald Welte (local)3e460312009-12-27 18:12:29 +0100832 if (*cause != RSL_ERR_RCH_ALR_ACTV_ALLOC)
Holger Hans Peter Freyther74419492010-04-10 00:12:31 +0200833 rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE);
Harald Welte (local)3e460312009-12-27 18:12:29 +0100834 } else
Holger Hans Peter Freyther74419492010-04-10 00:12:31 +0200835 rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE);
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +0200836
Harald Welte (local)91b603d2009-12-27 11:48:11 +0100837 LOGPC(DRSL, LOGL_ERROR, "\n");
838
Harald Welted011e8b2009-11-29 22:45:52 +0100839 dispatch_signal(SS_LCHAN, S_LCHAN_ACTIVATE_NACK, msg->lchan);
840
Harald Welte3073a9f2009-08-09 19:50:08 +0200841 lchan_free(msg->lchan);
Harald Welte4b634542008-12-27 01:55:51 +0000842 return 0;
Harald Welte702d8702008-12-26 20:25:35 +0000843}
844
Harald Welte7f93cea2009-02-23 00:02:59 +0000845/* Chapter 8.4.4: Connection Failure Indication */
846static int rsl_rx_conn_fail(struct msgb *msg)
847{
848 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
849 struct tlv_parsed tp;
850
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100851 /* FIXME: print which channel */
Harald Welte (local)fc057502009-12-26 22:33:09 +0100852 LOGP(DRSL, LOGL_NOTICE, "%s CONNECTION FAIL: RELEASING ",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100853 gsm_lchan_name(msg->lchan));
Harald Welte7f93cea2009-02-23 00:02:59 +0000854
855 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
856
Harald Welte8830e072009-07-28 17:58:09 +0200857 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +0100858 print_rsl_cause(LOGL_NOTICE, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +0200859 TLVP_LEN(&tp, RSL_IE_CAUSE));
860
Harald Welte (local)fc057502009-12-26 22:33:09 +0100861 LOGPC(DRSL, LOGL_NOTICE, "\n");
Harald Welte7f93cea2009-02-23 00:02:59 +0000862 /* FIXME: only free it after channel release ACK */
Holger Hans Peter Freyther3ba36d52010-04-17 06:48:29 +0200863 counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rf_fail);
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +0800864 return rsl_rf_chan_release(msg->lchan, 1);
Harald Welte7f93cea2009-02-23 00:02:59 +0000865}
866
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100867static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
868 const char *prefix)
869{
Harald Welte6739dfb2009-12-16 16:52:07 +0100870 DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",
871 prefix, rxlev2dbm(mru->full.rx_lev),
872 prefix, rxlev2dbm(mru->sub.rx_lev));
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100873 DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",
874 prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);
875}
876
877static void print_meas_rep(struct gsm_meas_rep *mr)
878{
Harald Welte6739dfb2009-12-16 16:52:07 +0100879 int i;
880
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100881 DEBUGP(DMEAS, "MEASUREMENT RESULT NR=%d ", mr->nr);
882
883 if (mr->flags & MEAS_REP_F_DL_DTX)
884 DEBUGPC(DMEAS, "DTXd ");
885
886 print_meas_rep_uni(&mr->ul, "ul");
887 DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
888 if (mr->flags & MEAS_REP_F_MS_TO)
889 DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
890
891 if (mr->flags & MEAS_REP_F_MS_L1) {
Harald Welte6739dfb2009-12-16 16:52:07 +0100892 DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100893 DEBUGPC(DMEAS, "L1_FPC=%u ",
894 mr->flags & MEAS_REP_F_FPC ? 1 : 0);
895 DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);
896 }
897
898 if (mr->flags & MEAS_REP_F_UL_DTX)
899 DEBUGPC(DMEAS, "DTXu ");
900 if (mr->flags & MEAS_REP_F_BA1)
901 DEBUGPC(DMEAS, "BA1 ");
902 if (!(mr->flags & MEAS_REP_F_DL_VALID))
903 DEBUGPC(DMEAS, "NOT VALID ");
904 else
905 print_meas_rep_uni(&mr->dl, "dl");
906
907 DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);
Harald Welte479015b2009-12-19 18:33:05 +0100908 if (mr->num_cell == 7)
909 return;
Harald Welte6739dfb2009-12-16 16:52:07 +0100910 for (i = 0; i < mr->num_cell; i++) {
911 struct gsm_meas_rep_cell *mrc = &mr->cell[i];
Harald Welte303e5e02009-12-25 23:02:22 +0100912 DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n",
913 mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
Harald Welte6739dfb2009-12-16 16:52:07 +0100914 }
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100915}
916
Harald Welte440fed02009-05-01 18:43:47 +0000917static int rsl_rx_meas_res(struct msgb *msg)
918{
919 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
920 struct tlv_parsed tp;
Harald Welted12b0fd2009-12-15 21:36:05 +0100921 struct gsm_meas_rep *mr = lchan_next_meas_rep(msg->lchan);
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100922 u_int8_t len;
923 const u_int8_t *val;
924 int rc;
Harald Welte440fed02009-05-01 18:43:47 +0000925
Harald Welteb8bfc562009-12-21 13:27:11 +0100926 /* check if this channel is actually active */
927 /* FIXME: maybe this check should be way more generic/centralized */
Harald Welte8e93b792009-12-29 10:44:17 +0100928 if (msg->lchan->state != LCHAN_S_ACTIVE) {
929 LOGP(DRSL, LOGL_NOTICE, "%s: MEAS RES for inactive channel\n",
930 gsm_lchan_name(msg->lchan));
Harald Welteb8bfc562009-12-21 13:27:11 +0100931 return 0;
Harald Welte8e93b792009-12-29 10:44:17 +0100932 }
Harald Welteb8bfc562009-12-21 13:27:11 +0100933
Harald Welted12b0fd2009-12-15 21:36:05 +0100934 memset(mr, 0, sizeof(*mr));
Harald Welte33e65972009-12-16 23:29:34 +0100935 mr->lchan = msg->lchan;
Harald Weltedbb1d882009-11-30 19:16:47 +0100936
Harald Welte440fed02009-05-01 18:43:47 +0000937 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
938
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100939 if (!TLVP_PRESENT(&tp, RSL_IE_MEAS_RES_NR) ||
940 !TLVP_PRESENT(&tp, RSL_IE_UPLINK_MEAS) ||
941 !TLVP_PRESENT(&tp, RSL_IE_BS_POWER))
942 return -EIO;
943
944 /* Mandatory Parts */
Harald Welted12b0fd2009-12-15 21:36:05 +0100945 mr->nr = *TLVP_VAL(&tp, RSL_IE_MEAS_RES_NR);
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100946
947 len = TLVP_LEN(&tp, RSL_IE_UPLINK_MEAS);
948 val = TLVP_VAL(&tp, RSL_IE_UPLINK_MEAS);
949 if (len >= 3) {
950 if (val[0] & 0x40)
Harald Welted12b0fd2009-12-15 21:36:05 +0100951 mr->flags |= MEAS_REP_F_DL_DTX;
952 mr->ul.full.rx_lev = val[0] & 0x3f;
953 mr->ul.sub.rx_lev = val[1] & 0x3f;
954 mr->ul.full.rx_qual = val[2]>>3 & 0x7;
955 mr->ul.sub.rx_qual = val[2] & 0x7;
Harald Welte440fed02009-05-01 18:43:47 +0000956 }
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100957
Harald Welted12b0fd2009-12-15 21:36:05 +0100958 mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100959
960 /* Optional Parts */
Harald Welte440fed02009-05-01 18:43:47 +0000961 if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET))
Harald Welted12b0fd2009-12-15 21:36:05 +0100962 mr->ms_timing_offset =
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100963 *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET);
964
Harald Weltefe9af262009-06-20 18:44:35 +0200965 if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) {
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100966 val = TLVP_VAL(&tp, RSL_IE_L1_INFO);
Harald Welted12b0fd2009-12-15 21:36:05 +0100967 mr->flags |= MEAS_REP_F_MS_L1;
968 mr->ms_l1.pwr = ms_pwr_dbm(msg->trx->bts->band, val[0] >> 3);
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100969 if (val[0] & 0x04)
Harald Welted12b0fd2009-12-15 21:36:05 +0100970 mr->flags |= MEAS_REP_F_FPC;
971 mr->ms_l1.ta = val[1];
Harald Weltefe9af262009-06-20 18:44:35 +0200972 }
Harald Weltef7c43522009-06-09 20:24:21 +0000973 if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
Holger Hans Peter Freytherddd918f2009-10-22 15:43:55 +0200974 msg->l3h = (u_int8_t *) TLVP_VAL(&tp, RSL_IE_L3_INFO);
Harald Welted12b0fd2009-12-15 21:36:05 +0100975 rc = gsm48_parse_meas_rep(mr, msg);
Harald Welte3c7dc6e2009-11-29 19:07:28 +0100976 if (rc < 0)
977 return rc;
978 }
979
Harald Welted12b0fd2009-12-15 21:36:05 +0100980 print_meas_rep(mr);
Harald Welte60d68f12009-06-05 20:07:43 +0000981
Harald Welted12b0fd2009-12-15 21:36:05 +0100982 dispatch_signal(SS_LCHAN, S_LCHAN_MEAS_REP, mr);
Harald Weltedbb1d882009-11-30 19:16:47 +0100983
Harald Welte75d34a82009-05-23 06:11:13 +0000984 return 0;
Harald Welte440fed02009-05-01 18:43:47 +0000985}
986
Harald Welted011e8b2009-11-29 22:45:52 +0100987/* Chapter 8.4.7 */
988static int rsl_rx_hando_det(struct msgb *msg)
989{
990 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
991 struct tlv_parsed tp;
992
Harald Welte (local)19ef62a2009-12-27 18:16:36 +0100993 DEBUGP(DRSL, "%s HANDOVER DETECT ", gsm_lchan_name(msg->lchan));
Harald Welted011e8b2009-11-29 22:45:52 +0100994
995 rsl_tlv_parse(&tp, dh->data, msgb_l2len(msg)-sizeof(*dh));
996
997 if (TLVP_PRESENT(&tp, RSL_IE_ACCESS_DELAY))
998 DEBUGPC(DRSL, "access delay = %u\n",
999 *TLVP_VAL(&tp, RSL_IE_ACCESS_DELAY));
1000 else
1001 DEBUGPC(DRSL, "\n");
1002
1003 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_DETECT, msg->lchan);
1004
1005 return 0;
1006}
1007
Harald Welte52b1f982008-12-23 20:25:15 +00001008static int abis_rsl_rx_dchan(struct msgb *msg)
1009{
Harald Welte8470bf22008-12-25 23:28:35 +00001010 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1011 int rc = 0;
Harald Weltef325eb42009-02-19 17:07:39 +00001012 char *ts_name;
Harald Welte52b1f982008-12-23 20:25:15 +00001013
Harald Welte8470bf22008-12-25 23:28:35 +00001014 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001015 ts_name = gsm_lchan_name(msg->lchan);
Harald Weltef325eb42009-02-19 17:07:39 +00001016
Harald Welte8470bf22008-12-25 23:28:35 +00001017 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +00001018 case RSL_MT_CHAN_ACTIV_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001019 DEBUGP(DRSL, "%s CHANNEL ACTIVATE ACK\n", ts_name);
Harald Welte4b634542008-12-27 01:55:51 +00001020 rc = rsl_rx_chan_act_ack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001021 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001022 case RSL_MT_CHAN_ACTIV_NACK:
Harald Welte4b634542008-12-27 01:55:51 +00001023 rc = rsl_rx_chan_act_nack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001024 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001025 case RSL_MT_CONN_FAIL:
Harald Welte7f93cea2009-02-23 00:02:59 +00001026 rc = rsl_rx_conn_fail(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001027 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001028 case RSL_MT_MEAS_RES:
Harald Welte440fed02009-05-01 18:43:47 +00001029 rc = rsl_rx_meas_res(msg);
Harald Welte2d5b6382008-12-27 19:46:06 +00001030 break;
Harald Welted011e8b2009-11-29 22:45:52 +01001031 case RSL_MT_HANDO_DET:
1032 rc = rsl_rx_hando_det(msg);
1033 break;
Harald Welte2d5b6382008-12-27 19:46:06 +00001034 case RSL_MT_RF_CHAN_REL_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001035 DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name);
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +08001036 if (msg->lchan->state != LCHAN_S_REL_REQ && msg->lchan->state != LCHAN_S_REL_ERR)
Harald Welte1887f9d2009-12-29 10:52:38 +01001037 LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state %s\n",
1038 gsm_lchan_name(msg->lchan),
1039 gsm_lchans_name(msg->lchan->state));
Holger Hans Peter Freytherf30c0dc2010-05-31 21:33:15 +08001040 bsc_del_timer(&msg->lchan->T3111);
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +08001041 /* we have an error timer pending to release that */
1042 if (msg->lchan->state != LCHAN_S_REL_ERR)
1043 rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE);
Harald Welte2d5b6382008-12-27 19:46:06 +00001044 lchan_free(msg->lchan);
Harald Welte8470bf22008-12-25 23:28:35 +00001045 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001046 case RSL_MT_MODE_MODIFY_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001047 DEBUGP(DRSL, "%s CHANNEL MODE MODIFY ACK\n", ts_name);
Harald Welteda783762009-02-18 03:29:53 +00001048 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001049 case RSL_MT_MODE_MODIFY_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001050 LOGP(DRSL, LOGL_ERROR, "%s CHANNEL MODE MODIFY NACK\n", ts_name);
Harald Welteda783762009-02-18 03:29:53 +00001051 break;
Harald Welte9c880c92009-10-24 10:29:22 +02001052 case RSL_MT_IPAC_PDCH_ACT_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001053 DEBUGPC(DRSL, "%s IPAC PDCH ACT ACK\n", ts_name);
Harald Welte4563eab2010-03-28 14:42:09 +08001054 msg->lchan->ts->flags |= TS_F_PDCH_MODE;
Harald Welte9c880c92009-10-24 10:29:22 +02001055 break;
1056 case RSL_MT_IPAC_PDCH_ACT_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001057 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH ACT NACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001058 break;
1059 case RSL_MT_IPAC_PDCH_DEACT_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001060 DEBUGP(DRSL, "%s IPAC PDCH DEACT ACK\n", ts_name);
Harald Welte4563eab2010-03-28 14:42:09 +08001061 msg->lchan->ts->flags &= ~TS_F_PDCH_MODE;
Harald Welte9c880c92009-10-24 10:29:22 +02001062 break;
1063 case RSL_MT_IPAC_PDCH_DEACT_NACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001064 LOGP(DRSL, LOGL_ERROR, "%s IPAC PDCH DEACT NACK\n", ts_name);
Harald Welte9c880c92009-10-24 10:29:22 +02001065 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001066 case RSL_MT_PHY_CONTEXT_CONF:
1067 case RSL_MT_PREPROC_MEAS_RES:
Harald Welte52b1f982008-12-23 20:25:15 +00001068 case RSL_MT_TALKER_DET:
1069 case RSL_MT_LISTENER_DET:
1070 case RSL_MT_REMOTE_CODEC_CONF_REP:
1071 case RSL_MT_MR_CODEC_MOD_ACK:
1072 case RSL_MT_MR_CODEC_MOD_NACK:
1073 case RSL_MT_MR_CODEC_MOD_PER:
Harald Welte5b8ed432009-12-24 12:20:20 +01001074 LOGP(DRSL, LOGL_NOTICE, "%s Unimplemented Abis RSL DChan "
1075 "msg 0x%02x\n", ts_name, rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001076 break;
1077 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001078 LOGP(DRSL, LOGL_NOTICE, "%s unknown Abis RSL DChan msg 0x%02x\n",
1079 ts_name, rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001080 return -EINVAL;
1081 }
Harald Weltef325eb42009-02-19 17:07:39 +00001082
Harald Welte8470bf22008-12-25 23:28:35 +00001083 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001084}
1085
Harald Welte702d8702008-12-26 20:25:35 +00001086static int rsl_rx_error_rep(struct msgb *msg)
1087{
1088 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8830e072009-07-28 17:58:09 +02001089 struct tlv_parsed tp;
Harald Welte702d8702008-12-26 20:25:35 +00001090
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +01001091 LOGP(DRSL, LOGL_ERROR, "%s ERROR REPORT ", gsm_trx_name(msg->trx));
Harald Welte8830e072009-07-28 17:58:09 +02001092
1093 rsl_tlv_parse(&tp, rslh->data, msgb_l2len(msg)-sizeof(*rslh));
1094
1095 if (TLVP_PRESENT(&tp, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +01001096 print_rsl_cause(LOGL_ERROR, TLVP_VAL(&tp, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +02001097 TLVP_LEN(&tp, RSL_IE_CAUSE));
1098
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001099 LOGPC(DRSL, LOGL_ERROR, "\n");
Harald Welte702d8702008-12-26 20:25:35 +00001100
1101 return 0;
1102}
1103
Harald Welte52b1f982008-12-23 20:25:15 +00001104static int abis_rsl_rx_trx(struct msgb *msg)
1105{
Harald Welte702d8702008-12-26 20:25:35 +00001106 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001107 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001108
1109 switch (rslh->msg_type) {
Harald Welte702d8702008-12-26 20:25:35 +00001110 case RSL_MT_ERROR_REPORT:
1111 rc = rsl_rx_error_rep(msg);
1112 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001113 case RSL_MT_RF_RES_IND:
1114 /* interference on idle channels of TRX */
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +01001115 //DEBUGP(DRSL, "%s RF Resource Indication\n", gsm_trx_name(msg->trx));
Harald Welte8f5e2392009-02-03 12:57:37 +00001116 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001117 case RSL_MT_OVERLOAD:
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001118 /* indicate CCCH / ACCH / processor overload */
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +01001119 LOGP(DRSL, LOGL_ERROR, "%s CCCH/ACCH/CPU Overload\n",
1120 gsm_trx_name(msg->trx));
Harald Welte52b1f982008-12-23 20:25:15 +00001121 break;
1122 default:
Harald Welte (local)d48f4eb2009-12-28 23:14:22 +01001123 LOGP(DRSL, LOGL_NOTICE, "%s Unknown Abis RSL TRX message "
1124 "type 0x%02x\n", gsm_trx_name(msg->trx), rslh->msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001125 return -EINVAL;
1126 }
Harald Welte8470bf22008-12-25 23:28:35 +00001127 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001128}
1129
Harald Welteb7e81162009-08-10 00:26:10 +02001130/* If T3101 expires, we never received a response to IMMEDIATE ASSIGN */
1131static void t3101_expired(void *data)
1132{
1133 struct gsm_lchan *lchan = data;
1134
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +08001135 rsl_rf_chan_release(lchan, 1);
Harald Welteb7e81162009-08-10 00:26:10 +02001136}
1137
Holger Hans Peter Freytherf30c0dc2010-05-31 21:33:15 +08001138/* If T3111 expires, we will send the RF Channel Request */
1139static void t3111_expired(void *data)
1140{
1141 struct gsm_lchan *lchan = data;
1142
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +08001143 rsl_rf_chan_release(lchan, 0);
Holger Hans Peter Freytherf30c0dc2010-05-31 21:33:15 +08001144}
1145
laforgecfa4a012010-06-21 12:08:52 +02001146#define GSM48_LEN2PLEN(a) (((a) << 2) | 1)
1147
Harald Welte8470bf22008-12-25 23:28:35 +00001148/* MS has requested a channel on the RACH */
Harald Welte52b1f982008-12-23 20:25:15 +00001149static int rsl_rx_chan_rqd(struct msgb *msg)
1150{
Harald Welte702d8702008-12-26 20:25:35 +00001151 struct gsm_bts *bts = msg->trx->bts;
Harald Welte8470bf22008-12-25 23:28:35 +00001152 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
1153 struct gsm48_req_ref *rqd_ref;
Harald Welte8470bf22008-12-25 23:28:35 +00001154 enum gsm_chan_t lctype;
Harald Welte2cbe0922008-12-29 04:09:31 +00001155 enum gsm_chreq_reason_t chreq_reason;
Harald Welte8470bf22008-12-25 23:28:35 +00001156 struct gsm_lchan *lchan;
1157 u_int8_t rqd_ta;
1158
Harald Welte52b1f982008-12-23 20:25:15 +00001159 u_int16_t arfcn;
1160 u_int8_t ts_number, subch;
1161
Harald Welte8470bf22008-12-25 23:28:35 +00001162 /* parse request reference to be used in immediate assign */
1163 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
1164 return -EINVAL;
1165
1166 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
1167
1168 /* parse access delay and use as TA */
1169 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
1170 return -EINVAL;
1171 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
1172
1173 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
1174 * request reference RA */
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +01001175 lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
1176 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
Harald Welte2cbe0922008-12-29 04:09:31 +00001177
Harald Welteffa55a42009-12-22 19:07:32 +01001178 counter_inc(bts->network->stats.chreq.total);
Harald Welte24ff6ee2009-12-22 00:41:05 +01001179
Harald Welte8470bf22008-12-25 23:28:35 +00001180 /* check availability / allocate channel */
1181 lchan = lchan_alloc(bts, lctype);
1182 if (!lchan) {
Harald Welte (local)2f5df852009-12-27 13:48:09 +01001183 LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n",
Harald Welte (local)ccd88452009-12-27 18:05:25 +01001184 msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra);
Harald Welteffa55a42009-12-22 19:07:32 +01001185 counter_inc(bts->network->stats.chreq.no_channel);
Harald Welte8470bf22008-12-25 23:28:35 +00001186 /* FIXME: send some kind of reject ?!? */
1187 return -ENOMEM;
1188 }
1189
Harald Welte8e93b792009-12-29 10:44:17 +01001190 if (lchan->state != LCHAN_S_NONE)
1191 LOGP(DRSL, LOGL_NOTICE, "%s lchan_alloc() returned channel "
Harald Welte1887f9d2009-12-29 10:52:38 +01001192 "in state %s\n", gsm_lchan_name(lchan),
1193 gsm_lchans_name(lchan->state));
Holger Hans Peter Freyther74419492010-04-10 00:12:31 +02001194 rsl_lchan_set_state(lchan, LCHAN_S_ACT_REQ);
Harald Welte (local)3e460312009-12-27 18:12:29 +01001195
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +08001196 /* save the RACH data as we need it after the CHAN ACT ACK */
1197 lchan->rqd_ref = talloc_zero(bts, struct gsm48_req_ref);
1198 if (!lchan->rqd_ref) {
1199 LOGP(DRSL, LOGL_ERROR, "Failed to allocate gsm48_req_ref.\n");
1200 lchan_free(lchan);
1201 return -ENOMEM;
1202 }
1203
1204 memcpy(lchan->rqd_ref, rqd_ref, sizeof(*rqd_ref));
1205 lchan->rqd_ta = rqd_ta;
1206
Harald Welte8470bf22008-12-25 23:28:35 +00001207 ts_number = lchan->ts->nr;
1208 arfcn = lchan->ts->trx->arfcn;
1209 subch = lchan->nr;
Harald Welte52b1f982008-12-23 20:25:15 +00001210
Harald Welte08d91a52009-08-30 15:37:11 +09001211 lchan->encr.alg_id = RSL_ENC_ALG_A5(0); /* no encryption */
Harald Welte (local)0e451d02009-08-13 10:14:26 +02001212 lchan->ms_power = ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
Harald Welte0b2124b2009-08-10 00:45:40 +02001213 lchan->bs_power = 0; /* 0dB reduction, output power = Pn */
Harald Welte9943c5b2009-07-29 15:41:29 +02001214 lchan->rsl_cmode = RSL_CMOD_SPD_SIGN;
Harald Welte196d0522009-08-28 23:28:28 +09001215 lchan->tch_mode = GSM48_CMODE_SIGN;
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +08001216
1217 /* FIXME: Start another timer or assume the BTS sends a ACK/NACK? */
Harald Welte8d77b952009-12-17 00:31:10 +01001218 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta, 0);
Harald Welte52b1f982008-12-23 20:25:15 +00001219
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +08001220 DEBUGP(DRSL, "%s Activating ARFCN(%u) SS(%u) lctype %s "
1221 "r=%s ra=0x%02x\n", gsm_lchan_name(lchan), arfcn, subch,
1222 gsm_lchant_name(lchan->type), gsm_chreq_name(chreq_reason),
1223 rqd_ref->ra);
1224 return 0;
1225}
1226
1227static int rsl_send_imm_assignment(struct gsm_lchan *lchan)
1228{
1229 struct gsm_bts *bts = lchan->ts->trx->bts;
1230 u_int8_t buf[GSM_MACBLOCK_LEN];
1231 struct gsm48_imm_ass *ia = (struct gsm48_imm_ass *) buf;
1232
Harald Welte52b1f982008-12-23 20:25:15 +00001233 /* create IMMEDIATE ASSIGN 04.08 messge */
laforge09108bf2010-06-20 15:18:46 +02001234 memset(ia, 0, sizeof(*ia));
laforgecfa4a012010-06-21 12:08:52 +02001235 /* we set ia->l2_plen once we know the length of the MA below */
laforge09108bf2010-06-20 15:18:46 +02001236 ia->proto_discr = GSM48_PDISC_RR;
1237 ia->msg_type = GSM48_MT_RR_IMM_ASS;
1238 ia->page_mode = GSM48_PM_SAME;
1239 gsm48_lchan2chan_desc(&ia->chan_desc, lchan);
Harald Weltea39b0f22010-06-14 22:26:10 +02001240
Harald Welte8470bf22008-12-25 23:28:35 +00001241 /* use request reference extracted from CHAN_RQD */
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +08001242 memcpy(&ia->req_ref, lchan->rqd_ref, sizeof(ia->req_ref));
1243 ia->timing_advance = lchan->rqd_ta;
Harald Weltea39b0f22010-06-14 22:26:10 +02001244 if (!lchan->ts->hopping.enabled) {
laforge09108bf2010-06-20 15:18:46 +02001245 ia->mob_alloc_len = 0;
Harald Weltea39b0f22010-06-14 22:26:10 +02001246 } else {
laforge09108bf2010-06-20 15:18:46 +02001247 ia->mob_alloc_len = lchan->ts->hopping.ma_len;
1248 memcpy(ia->mob_alloc, lchan->ts->hopping.ma_data, ia->mob_alloc_len);
Harald Weltea39b0f22010-06-14 22:26:10 +02001249 }
laforgecfa4a012010-06-21 12:08:52 +02001250 ia->l2_plen = GSM48_LEN2PLEN(sizeof(*ia) + ia->mob_alloc_len);
Harald Welte52b1f982008-12-23 20:25:15 +00001251
Harald Welteb7e81162009-08-10 00:26:10 +02001252 /* Start timer T3101 to wait for GSM48_MT_RR_PAG_RESP */
1253 lchan->T3101.cb = t3101_expired;
1254 lchan->T3101.data = lchan;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +01001255 bsc_schedule_timer(&lchan->T3101, bts->network->T3101, 0);
Holger Freyther3186bf22008-12-29 06:23:49 +00001256
Harald Welte52b1f982008-12-23 20:25:15 +00001257 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
Holger Hans Peter Freyther5ba05f42010-06-22 12:11:59 +08001258 return rsl_imm_assign_cmd(bts, sizeof(*ia)+ia->mob_alloc_len, (u_int8_t *) ia);
Harald Welte52b1f982008-12-23 20:25:15 +00001259}
1260
Harald Welteea280442009-02-02 22:29:56 +00001261/* MS has requested a channel on the RACH */
1262static int rsl_rx_ccch_load(struct msgb *msg)
1263{
1264 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
1265 u_int16_t pg_buf_space;
Holger Freyther8c563cf2009-02-03 20:08:51 +00001266 u_int16_t rach_slot_count = -1;
1267 u_int16_t rach_busy_count = -1;
1268 u_int16_t rach_access_count = -1;
Harald Welteea280442009-02-02 22:29:56 +00001269
1270 switch (rslh->data[0]) {
1271 case RSL_IE_PAGING_LOAD:
1272 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
Harald Welte38e9c822010-04-19 10:24:07 +02001273 if (is_ipaccess_bts(msg->trx->bts) && pg_buf_space == 0xffff) {
1274 /* paging load below configured threshold, use 50 as default */
1275 pg_buf_space = 50;
1276 }
Holger Freyther392209c2009-02-10 00:06:19 +00001277 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
Harald Welteea280442009-02-02 22:29:56 +00001278 break;
1279 case RSL_IE_RACH_LOAD:
Holger Freyther8c563cf2009-02-03 20:08:51 +00001280 if (msg->data_len >= 7) {
1281 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
1282 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
1283 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
1284 }
Harald Welteea280442009-02-02 22:29:56 +00001285 break;
1286 default:
1287 break;
1288 }
1289
1290 return 0;
1291}
1292
Harald Welte52b1f982008-12-23 20:25:15 +00001293static int abis_rsl_rx_cchan(struct msgb *msg)
1294{
Harald Welteea280442009-02-02 22:29:56 +00001295 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001296 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001297
Harald Welte8470bf22008-12-25 23:28:35 +00001298 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
1299
1300 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +00001301 case RSL_MT_CHAN_RQD:
1302 /* MS has requested a channel on the RACH */
1303 rc = rsl_rx_chan_rqd(msg);
1304 break;
Harald Welteea280442009-02-02 22:29:56 +00001305 case RSL_MT_CCCH_LOAD_IND:
1306 /* current load on the CCCH */
1307 rc = rsl_rx_ccch_load(msg);
1308 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001309 case RSL_MT_DELETE_IND:
1310 /* CCCH overloaded, IMM_ASSIGN was dropped */
1311 case RSL_MT_CBCH_LOAD_IND:
1312 /* current load on the CBCH */
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001313 LOGP(DRSL, LOGL_NOTICE, "Unimplemented Abis RSL TRX message "
1314 "type 0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001315 break;
1316 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001317 LOGP(DRSL, LOGL_NOTICE, "Unknown Abis RSL TRX message type "
1318 "0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001319 return -EINVAL;
1320 }
Harald Welte8470bf22008-12-25 23:28:35 +00001321
1322 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001323}
1324
Harald Welte4b634542008-12-27 01:55:51 +00001325static int rsl_rx_rll_err_ind(struct msgb *msg)
1326{
1327 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1328 u_int8_t *rlm_cause = rllh->data;
1329
Harald Welte (local)9538efc2009-12-26 23:55:00 +01001330 LOGP(DRLL, LOGL_ERROR, "%s ERROR INDICATION cause=%s\n",
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001331 gsm_lchan_name(msg->lchan),
Harald Weltee95daf12010-03-25 12:13:02 +08001332 rsl_rlm_cause_name(rlm_cause[1]));
Harald Welteedcc5272009-08-09 13:47:35 +02001333
1334 rll_indication(msg->lchan, rllh->link_id, BSC_RLLR_IND_ERR_IND);
Harald Welte (local)9538efc2009-12-26 23:55:00 +01001335
Holger Hans Peter Freyther3ba36d52010-04-17 06:48:29 +02001336 if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED) {
1337 counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rll_err);
Holger Hans Peter Freyther4b4dd102010-05-31 21:38:24 +08001338 return rsl_rf_chan_release(msg->lchan, 1);
Holger Hans Peter Freyther3ba36d52010-04-17 06:48:29 +02001339 }
Harald Welte81543bc2009-07-04 09:40:05 +02001340
Harald Welte4b634542008-12-27 01:55:51 +00001341 return 0;
1342}
Harald Weltef325eb42009-02-19 17:07:39 +00001343
Holger Hans Peter Freytherdbc5fae2010-04-08 22:39:34 +02001344static void rsl_handle_release(struct gsm_lchan *lchan)
1345{
Holger Hans Peter Freytherf30c0dc2010-05-31 21:33:15 +08001346 struct gsm_bts *bts;
Holger Hans Peter Freytherd7fd3062010-04-08 22:47:44 +02001347 if (lchan->state != LCHAN_S_REL_REQ)
1348 LOGP(DRSL, LOGL_ERROR, "RF release on %s but state %s\n",
1349 gsm_lchan_name(lchan),
1350 gsm_lchans_name(lchan->state));
1351
1352
Holger Hans Peter Freytherf30c0dc2010-05-31 21:33:15 +08001353 /* wait a bit to send the RF Channel Release */
1354 lchan->T3111.cb = t3111_expired;
1355 lchan->T3111.data = lchan;
1356 bts = lchan->ts->trx->bts;
1357 bsc_schedule_timer(&lchan->T3111, bts->network->T3111, 0);
Holger Hans Peter Freytherdbc5fae2010-04-08 22:39:34 +02001358}
1359
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001360/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
Harald Welte52b1f982008-12-23 20:25:15 +00001361 0x02, 0x06,
1362 0x01, 0x20,
1363 0x02, 0x00,
1364 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
1365
1366static int abis_rsl_rx_rll(struct msgb *msg)
1367{
1368 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Weltef325eb42009-02-19 17:07:39 +00001369 int rc = 0;
1370 char *ts_name;
Harald Welte (local)daef6062009-08-14 11:41:12 +02001371 u_int8_t sapi = rllh->link_id & 7;
Harald Welte8470bf22008-12-25 23:28:35 +00001372
1373 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001374 ts_name = gsm_lchan_name(msg->lchan);
Harald Welte5b8ed432009-12-24 12:20:20 +01001375 DEBUGP(DRLL, "%s SAPI=%u ", ts_name, sapi);
Harald Welte52b1f982008-12-23 20:25:15 +00001376
1377 switch (rllh->c.msg_type) {
1378 case RSL_MT_DATA_IND:
Harald Weltef325eb42009-02-19 17:07:39 +00001379 DEBUGPC(DRLL, "DATA INDICATION\n");
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001380 if (msgb_l2len(msg) >
Harald Welte4a543e82009-02-28 13:17:55 +00001381 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1382 rllh->data[0] == RSL_IE_L3_INFO) {
1383 msg->l3h = &rllh->data[3];
Harald Welte (local)daef6062009-08-14 11:41:12 +02001384 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte4a543e82009-02-28 13:17:55 +00001385 }
Harald Welte52b1f982008-12-23 20:25:15 +00001386 break;
1387 case RSL_MT_EST_IND:
Harald Weltef325eb42009-02-19 17:07:39 +00001388 DEBUGPC(DRLL, "ESTABLISH INDICATION\n");
Harald Welteb7e81162009-08-10 00:26:10 +02001389 /* lchan is established, stop T3101 */
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001390 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_MS;
Harald Welteb7e81162009-08-10 00:26:10 +02001391 bsc_del_timer(&msg->lchan->T3101);
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001392 if (msgb_l2len(msg) >
Harald Welte4a543e82009-02-28 13:17:55 +00001393 sizeof(struct abis_rsl_common_hdr) + sizeof(*rllh) &&
1394 rllh->data[0] == RSL_IE_L3_INFO) {
1395 msg->l3h = &rllh->data[3];
Harald Welte (local)daef6062009-08-14 11:41:12 +02001396 return gsm0408_rcvmsg(msg, rllh->link_id);
Harald Welte4a543e82009-02-28 13:17:55 +00001397 }
Harald Welte52b1f982008-12-23 20:25:15 +00001398 break;
Harald Welteedcc5272009-08-09 13:47:35 +02001399 case RSL_MT_EST_CONF:
Harald Welte1c409272009-08-09 14:13:58 +02001400 DEBUGPC(DRLL, "ESTABLISH CONFIRM\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001401 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_NET;
Harald Welteedcc5272009-08-09 13:47:35 +02001402 rll_indication(msg->lchan, rllh->link_id,
1403 BSC_RLLR_IND_EST_CONF);
1404 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001405 case RSL_MT_REL_IND:
Harald Welted2dc1de2009-08-08 13:15:07 +02001406 /* BTS informs us of having received DISC from MS */
Harald Welte602f2b82009-08-04 02:50:21 +02001407 DEBUGPC(DRLL, "RELEASE INDICATION\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001408 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Harald Welteedcc5272009-08-09 13:47:35 +02001409 rll_indication(msg->lchan, rllh->link_id,
1410 BSC_RLLR_IND_REL_IND);
Holger Hans Peter Freytherdbc5fae2010-04-08 22:39:34 +02001411 rsl_handle_release(msg->lchan);
Harald Welte2d5b6382008-12-27 19:46:06 +00001412 break;
1413 case RSL_MT_REL_CONF:
Harald Welted2dc1de2009-08-08 13:15:07 +02001414 /* BTS informs us of having received UA from MS,
1415 * in response to DISC that we've sent earlier */
Harald Welte602f2b82009-08-04 02:50:21 +02001416 DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +01001417 msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
Holger Hans Peter Freytherdbc5fae2010-04-08 22:39:34 +02001418 rsl_handle_release(msg->lchan);
Harald Welte4b634542008-12-27 01:55:51 +00001419 break;
1420 case RSL_MT_ERROR_IND:
1421 rc = rsl_rx_rll_err_ind(msg);
1422 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001423 case RSL_MT_UNIT_DATA_IND:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001424 LOGP(DRLL, LOGL_NOTICE, "unimplemented Abis RLL message "
1425 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001426 break;
1427 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001428 LOGP(DRLL, LOGL_NOTICE, "unknown Abis RLL message "
1429 "type 0x%02x\n", rllh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001430 }
Harald Welte8470bf22008-12-25 23:28:35 +00001431 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001432}
1433
Harald Welte0603c9d2009-12-02 01:58:23 +05301434static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
Harald Weltef4e79f22009-07-28 18:11:56 +02001435{
Harald Welte0603c9d2009-12-02 01:58:23 +05301436 switch (lchan->tch_mode) {
Harald Weltef4e79f22009-07-28 18:11:56 +02001437 case GSM48_CMODE_SPEECH_V1:
Harald Welte0603c9d2009-12-02 01:58:23 +05301438 switch (lchan->type) {
1439 case GSM_LCHAN_TCH_F:
1440 return 0x00;
1441 case GSM_LCHAN_TCH_H:
1442 return 0x03;
1443 default:
1444 break;
1445 }
Harald Weltef4e79f22009-07-28 18:11:56 +02001446 case GSM48_CMODE_SPEECH_EFR:
Harald Welte0603c9d2009-12-02 01:58:23 +05301447 switch (lchan->type) {
1448 case GSM_LCHAN_TCH_F:
1449 return 0x01;
1450 /* there's no half-rate EFR */
1451 default:
1452 break;
1453 }
Harald Weltef4e79f22009-07-28 18:11:56 +02001454 case GSM48_CMODE_SPEECH_AMR:
Harald Welte0603c9d2009-12-02 01:58:23 +05301455 switch (lchan->type) {
1456 case GSM_LCHAN_TCH_F:
1457 return 0x02;
1458 case GSM_LCHAN_TCH_H:
1459 return 0x05;
1460 default:
1461 break;
1462 }
1463 default:
1464 break;
Harald Weltef4e79f22009-07-28 18:11:56 +02001465 }
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001466 LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access speech mode for "
Harald Welte0603c9d2009-12-02 01:58:23 +05301467 "tch_mode == 0x%02x\n", lchan->tch_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001468 return 0;
Harald Weltef4e79f22009-07-28 18:11:56 +02001469}
1470
Sylvain Munautb54dda42009-12-20 22:06:40 +01001471static u_int8_t ipa_rtp_pt_for_lchan(struct gsm_lchan *lchan)
1472{
1473 switch (lchan->tch_mode) {
1474 case GSM48_CMODE_SPEECH_V1:
1475 switch (lchan->type) {
1476 case GSM_LCHAN_TCH_F:
1477 return RTP_PT_GSM_FULL;
1478 case GSM_LCHAN_TCH_H:
1479 return RTP_PT_GSM_HALF;
1480 default:
1481 break;
1482 }
1483 case GSM48_CMODE_SPEECH_EFR:
1484 switch (lchan->type) {
1485 case GSM_LCHAN_TCH_F:
1486 return RTP_PT_GSM_EFR;
1487 /* there's no half-rate EFR */
1488 default:
1489 break;
1490 }
1491 case GSM48_CMODE_SPEECH_AMR:
1492 switch (lchan->type) {
1493 case GSM_LCHAN_TCH_F:
1494 return RTP_PT_AMR_FULL;
1495 case GSM_LCHAN_TCH_H:
1496 return RTP_PT_AMR_HALF;
1497 default:
1498 break;
1499 }
1500 default:
1501 break;
1502 }
1503 LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access rtp payload type for "
1504 "tch_mode == 0x%02x\n & lchan_type == %d",
1505 lchan->tch_mode, lchan->type);
1506 return 0;
1507}
1508
Harald Welte75099262009-02-16 21:12:08 +00001509/* ip.access specific RSL extensions */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001510static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
1511{
1512 struct in_addr ip;
1513 u_int16_t port, conn_id;
1514
1515 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_IP)) {
1516 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_IP));
1517 DEBUGPC(DRSL, "LOCAL_IP=%s ", inet_ntoa(ip));
1518 lchan->abis_ip.bound_ip = ntohl(ip.s_addr);
1519 }
1520
1521 if (TLVP_PRESENT(tv, RSL_IE_IPAC_LOCAL_PORT)) {
1522 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_LOCAL_PORT));
1523 port = ntohs(port);
1524 DEBUGPC(DRSL, "LOCAL_PORT=%u ", port);
1525 lchan->abis_ip.bound_port = port;
1526 }
1527
1528 if (TLVP_PRESENT(tv, RSL_IE_IPAC_CONN_ID)) {
1529 conn_id = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_CONN_ID));
1530 conn_id = ntohs(conn_id);
1531 DEBUGPC(DRSL, "CON_ID=%u ", conn_id);
1532 lchan->abis_ip.conn_id = conn_id;
1533 }
1534
1535 if (TLVP_PRESENT(tv, RSL_IE_IPAC_RTP_PAYLOAD2)) {
1536 lchan->abis_ip.rtp_payload2 =
1537 *TLVP_VAL(tv, RSL_IE_IPAC_RTP_PAYLOAD2);
1538 DEBUGPC(DRSL, "RTP_PAYLOAD2=0x%02x ",
1539 lchan->abis_ip.rtp_payload2);
1540 }
1541
1542 if (TLVP_PRESENT(tv, RSL_IE_IPAC_SPEECH_MODE)) {
1543 lchan->abis_ip.speech_mode =
1544 *TLVP_VAL(tv, RSL_IE_IPAC_SPEECH_MODE);
1545 DEBUGPC(DRSL, "speech_mode=0x%02x ",
1546 lchan->abis_ip.speech_mode);
1547 }
1548
1549 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_IP)) {
1550 ip.s_addr = *((u_int32_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_IP));
1551 DEBUGPC(DRSL, "REMOTE_IP=%s ", inet_ntoa(ip));
1552 lchan->abis_ip.connect_ip = ntohl(ip.s_addr);
1553 }
1554
1555 if (TLVP_PRESENT(tv, RSL_IE_IPAC_REMOTE_PORT)) {
1556 port = *((u_int16_t *) TLVP_VAL(tv, RSL_IE_IPAC_REMOTE_PORT));
1557 port = ntohs(port);
1558 DEBUGPC(DRSL, "REMOTE_PORT=%u ", port);
1559 lchan->abis_ip.connect_port = port;
1560 }
1561}
1562
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001563int rsl_ipacc_crcx(struct gsm_lchan *lchan)
Harald Welte75099262009-02-16 21:12:08 +00001564{
1565 struct msgb *msg = rsl_msgb_alloc();
1566 struct abis_rsl_dchan_hdr *dh;
1567
1568 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001569 init_dchan_hdr(dh, RSL_MT_IPAC_CRCX);
Harald Welte75099262009-02-16 21:12:08 +00001570 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1571 dh->chan_nr = lchan2chan_nr(lchan);
1572
Harald Weltef4e79f22009-07-28 18:11:56 +02001573 /* 0x1- == receive-only, 0x-1 == EFR codec */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001574 lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
Sylvain Munautb54dda42009-12-20 22:06:40 +01001575 lchan->abis_ip.rtp_payload = ipa_rtp_pt_for_lchan(lchan);
Harald Welte5e3d91b2009-12-19 16:42:06 +01001576 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Sylvain Munautb54dda42009-12-20 22:06:40 +01001577 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD, lchan->abis_ip.rtp_payload);
Harald Weltef4e79f22009-07-28 18:11:56 +02001578
Sylvain Munautb54dda42009-12-20 22:06:40 +01001579 DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x RTP_PAYLOAD=%d\n",
1580 gsm_lchan_name(lchan), lchan->abis_ip.speech_mode,
1581 lchan->abis_ip.rtp_payload);
Harald Weltef4e79f22009-07-28 18:11:56 +02001582
Harald Welte75099262009-02-16 21:12:08 +00001583 msg->trx = lchan->ts->trx;
1584
1585 return abis_rsl_sendmsg(msg);
1586}
1587
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001588int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
Harald Welte5e3d91b2009-12-19 16:42:06 +01001589 u_int8_t rtp_payload2)
Harald Welte75099262009-02-16 21:12:08 +00001590{
1591 struct msgb *msg = rsl_msgb_alloc();
1592 struct abis_rsl_dchan_hdr *dh;
Harald Welte5e3d91b2009-12-19 16:42:06 +01001593 u_int32_t *att_ip;
Harald Weltef4e79f22009-07-28 18:11:56 +02001594 struct in_addr ia;
Harald Welte75099262009-02-16 21:12:08 +00001595
1596 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001597 init_dchan_hdr(dh, RSL_MT_IPAC_MDCX);
Harald Welte75099262009-02-16 21:12:08 +00001598 dh->c.msg_discr = ABIS_RSL_MDISC_IPACCESS;
1599 dh->chan_nr = lchan2chan_nr(lchan);
1600
Harald Welte5e3d91b2009-12-19 16:42:06 +01001601 /* we need to store these now as MDCX_ACK does not return them :( */
1602 lchan->abis_ip.rtp_payload2 = rtp_payload2;
1603 lchan->abis_ip.connect_port = port;
1604 lchan->abis_ip.connect_ip = ip;
1605
Harald Welte58ca5b72009-07-29 12:12:18 +02001606 /* 0x0- == both directions, 0x-1 == EFR codec */
Harald Welte5e3d91b2009-12-19 16:42:06 +01001607 lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
Sylvain Munautb54dda42009-12-20 22:06:40 +01001608 lchan->abis_ip.rtp_payload = ipa_rtp_pt_for_lchan(lchan);
Harald Welte58ca5b72009-07-29 12:12:18 +02001609
Harald Weltef4e79f22009-07-28 18:11:56 +02001610 ia.s_addr = htonl(ip);
Sylvain Munautb54dda42009-12-20 22:06:40 +01001611 DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD=%d RTP_PAYLOAD2=%d "
1612 "CONN_ID=%d speech_mode=0x%02x\n", gsm_lchan_name(lchan),
1613 inet_ntoa(ia), port, lchan->abis_ip.rtp_payload, rtp_payload2,
1614 lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
Harald Weltef4e79f22009-07-28 18:11:56 +02001615
Harald Welte5e3d91b2009-12-19 16:42:06 +01001616 msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
1617 msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
1618 att_ip = (u_int32_t *) msgb_put(msg, sizeof(ip));
1619 *att_ip = ia.s_addr;
1620 msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
1621 msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
Sylvain Munautb54dda42009-12-20 22:06:40 +01001622 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD, lchan->abis_ip.rtp_payload);
Harald Weltef4e79f22009-07-28 18:11:56 +02001623 if (rtp_payload2)
1624 msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
1625
Harald Welte75099262009-02-16 21:12:08 +00001626 msg->trx = lchan->ts->trx;
1627
1628 return abis_rsl_sendmsg(msg);
1629}
1630
Harald Weltea72273e2009-12-20 16:51:09 +01001631/* tell BTS to connect RTP stream to our local RTP socket */
1632int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan)
1633{
1634 struct rtp_socket *rs = lchan->abis_ip.rtp_socket;
1635 int rc;
1636
1637 rc = rsl_ipacc_mdcx(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr),
1638 ntohs(rs->rtp.sin_local.sin_port),
1639 /* FIXME: use RTP payload of bound socket, not BTS*/
1640 lchan->abis_ip.rtp_payload2);
1641
1642 return rc;
1643}
1644
Harald Welte4563eab2010-03-28 14:42:09 +08001645int rsl_ipacc_pdch_activate(struct gsm_lchan *lchan, int act)
Harald Welte9c880c92009-10-24 10:29:22 +02001646{
1647 struct msgb *msg = rsl_msgb_alloc();
1648 struct abis_rsl_dchan_hdr *dh;
Harald Welte4563eab2010-03-28 14:42:09 +08001649 u_int8_t msg_type;
1650
1651 if (act)
1652 msg_type = RSL_MT_IPAC_PDCH_ACT;
1653 else
1654 msg_type = RSL_MT_IPAC_PDCH_DEACT;
Harald Welte9c880c92009-10-24 10:29:22 +02001655
1656 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
Harald Welte4563eab2010-03-28 14:42:09 +08001657 init_dchan_hdr(dh, msg_type);
Harald Welte9c880c92009-10-24 10:29:22 +02001658 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
1659 dh->chan_nr = lchan2chan_nr(lchan);
1660
Harald Welte4563eab2010-03-28 14:42:09 +08001661 DEBUGP(DRSL, "%s IPAC_PDCH_%sACT\n", gsm_lchan_name(lchan),
1662 act ? "" : "DE");
Harald Welte9c880c92009-10-24 10:29:22 +02001663
1664 msg->trx = lchan->ts->trx;
1665
1666 return abis_rsl_sendmsg(msg);
1667}
1668
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001669static int abis_rsl_rx_ipacc_crcx_ack(struct msgb *msg)
Harald Welte75099262009-02-16 21:12:08 +00001670{
1671 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1672 struct tlv_parsed tv;
Harald Welte2c828992009-12-02 01:56:49 +05301673 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75099262009-02-16 21:12:08 +00001674
1675 /* the BTS has acknowledged a local bind, it now tells us the IP
1676 * address and port number to which it has bound the given logical
1677 * channel */
1678
1679 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1680 if (!TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_PORT) ||
1681 !TLVP_PRESENT(&tv, RSL_IE_IPAC_LOCAL_IP) ||
Harald Welte86c162d2009-07-12 09:45:05 +02001682 !TLVP_PRESENT(&tv, RSL_IE_IPAC_CONN_ID)) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001683 LOGP(DRSL, LOGL_NOTICE, "mandatory IE missing");
Harald Welte75099262009-02-16 21:12:08 +00001684 return -EINVAL;
1685 }
Harald Welte17f5bf62009-12-20 15:42:44 +01001686
Harald Welte5e3d91b2009-12-19 16:42:06 +01001687 ipac_parse_rtp(lchan, &tv);
Harald Welte17f5bf62009-12-20 15:42:44 +01001688
1689 /* in case we don't use direct BTS-to-BTS RTP */
1690 if (!ipacc_rtp_direct) {
1691 int rc;
1692 /* the BTS has successfully bound a TCH to a local ip/port,
1693 * which means we can connect our UDP socket to it */
1694 if (lchan->abis_ip.rtp_socket) {
1695 rtp_socket_free(lchan->abis_ip.rtp_socket);
1696 lchan->abis_ip.rtp_socket = NULL;
1697 }
1698
1699 lchan->abis_ip.rtp_socket = rtp_socket_create();
1700 if (!lchan->abis_ip.rtp_socket)
1701 goto out_err;
1702
1703 rc = rtp_socket_connect(lchan->abis_ip.rtp_socket,
1704 lchan->abis_ip.bound_ip,
1705 lchan->abis_ip.bound_port);
1706 if (rc < 0)
1707 goto out_err;
1708 }
1709
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001710 dispatch_signal(SS_ABISIP, S_ABISIP_CRCX_ACK, msg->lchan);
Harald Welte167df882009-02-17 14:35:45 +00001711
Harald Welte75099262009-02-16 21:12:08 +00001712 return 0;
Harald Welte17f5bf62009-12-20 15:42:44 +01001713out_err:
1714 return -EIO;
Harald Welte75099262009-02-16 21:12:08 +00001715}
1716
Harald Welte5e3d91b2009-12-19 16:42:06 +01001717static int abis_rsl_rx_ipacc_mdcx_ack(struct msgb *msg)
1718{
1719 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1720 struct tlv_parsed tv;
1721 struct gsm_lchan *lchan = msg->lchan;
1722
1723 /* the BTS has acknowledged a remote connect request and
1724 * it now tells us the IP address and port number to which it has
1725 * connected the given logical channel */
1726
1727 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
1728 ipac_parse_rtp(lchan, &tv);
1729 dispatch_signal(SS_ABISIP, S_ABISIP_MDCX_ACK, msg->lchan);
1730
1731 return 0;
1732}
1733
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001734static int abis_rsl_rx_ipacc_dlcx_ind(struct msgb *msg)
Harald Welte75099262009-02-16 21:12:08 +00001735{
1736 struct abis_rsl_dchan_hdr *dh = msgb_l2(msg);
1737 struct tlv_parsed tv;
Harald Welte17f5bf62009-12-20 15:42:44 +01001738 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75099262009-02-16 21:12:08 +00001739
1740 rsl_tlv_parse(&tv, dh->data, msgb_l2len(msg)-sizeof(*dh));
Harald Welte75099262009-02-16 21:12:08 +00001741
Harald Welte8830e072009-07-28 17:58:09 +02001742 if (TLVP_PRESENT(&tv, RSL_IE_CAUSE))
Harald Welte5b8ed432009-12-24 12:20:20 +01001743 print_rsl_cause(LOGL_DEBUG, TLVP_VAL(&tv, RSL_IE_CAUSE),
Harald Welte8830e072009-07-28 17:58:09 +02001744 TLVP_LEN(&tv, RSL_IE_CAUSE));
Harald Welte75099262009-02-16 21:12:08 +00001745
Harald Welte17f5bf62009-12-20 15:42:44 +01001746 /* the BTS tells us a RTP stream has been disconnected */
1747 if (lchan->abis_ip.rtp_socket) {
1748 rtp_socket_free(lchan->abis_ip.rtp_socket);
1749 lchan->abis_ip.rtp_socket = NULL;
1750 }
1751
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001752 dispatch_signal(SS_ABISIP, S_ABISIP_DLCX_IND, msg->lchan);
Harald Welte888b1142009-07-28 18:02:05 +02001753
Harald Welte75099262009-02-16 21:12:08 +00001754 return 0;
1755}
1756
1757static int abis_rsl_rx_ipacc(struct msgb *msg)
1758{
1759 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Welte5b8ed432009-12-24 12:20:20 +01001760 char *ts_name;
Harald Welte75099262009-02-16 21:12:08 +00001761 int rc = 0;
1762
1763 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte (local)19ef62a2009-12-27 18:16:36 +01001764 ts_name = gsm_lchan_name(msg->lchan);
Harald Welte75099262009-02-16 21:12:08 +00001765
1766 switch (rllh->c.msg_type) {
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001767 case RSL_MT_IPAC_CRCX_ACK:
Harald Welte5b8ed432009-12-24 12:20:20 +01001768 DEBUGP(DRSL, "%s IPAC_CRCX_ACK ", ts_name);
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001769 rc = abis_rsl_rx_ipacc_crcx_ack(msg);
Harald Welte75099262009-02-16 21:12:08 +00001770 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001771 case RSL_MT_IPAC_CRCX_NACK:
Harald Welte75099262009-02-16 21:12:08 +00001772 /* somehow the BTS was unable to bind the lchan to its local
1773 * port?!? */
Harald Welte5b8ed432009-12-24 12:20:20 +01001774 LOGP(DRSL, LOGL_ERROR, "%s IPAC_CRCX_NACK\n", ts_name);
Harald Welte75099262009-02-16 21:12:08 +00001775 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001776 case RSL_MT_IPAC_MDCX_ACK:
Harald Welte75099262009-02-16 21:12:08 +00001777 /* the BTS tells us that a connect operation was successful */
Harald Welte5b8ed432009-12-24 12:20:20 +01001778 DEBUGP(DRSL, "%s IPAC_MDCX_ACK ", ts_name);
Harald Welte5e3d91b2009-12-19 16:42:06 +01001779 rc = abis_rsl_rx_ipacc_mdcx_ack(msg);
Harald Welte75099262009-02-16 21:12:08 +00001780 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001781 case RSL_MT_IPAC_MDCX_NACK:
Harald Welte75099262009-02-16 21:12:08 +00001782 /* somehow the BTS was unable to connect the lchan to a remote
1783 * port */
Harald Welte5b8ed432009-12-24 12:20:20 +01001784 LOGP(DRSL, LOGL_ERROR, "%s IPAC_MDCX_NACK\n", ts_name);
Harald Welte75099262009-02-16 21:12:08 +00001785 break;
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001786 case RSL_MT_IPAC_DLCX_IND:
Harald Welte5b8ed432009-12-24 12:20:20 +01001787 DEBUGP(DRSL, "%s IPAC_DLCX_IND ", ts_name);
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001788 rc = abis_rsl_rx_ipacc_dlcx_ind(msg);
Harald Welte75099262009-02-16 21:12:08 +00001789 break;
1790 default:
Harald Welte5b8ed432009-12-24 12:20:20 +01001791 LOGP(DRSL, LOGL_NOTICE, "Unknown ip.access msg_type 0x%02x\n",
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001792 rllh->c.msg_type);
Harald Welte75099262009-02-16 21:12:08 +00001793 break;
1794 }
Harald Welte6dab0552009-05-01 17:21:37 +00001795 DEBUGPC(DRSL, "\n");
Harald Welte75099262009-02-16 21:12:08 +00001796
1797 return rc;
1798}
1799
1800
Harald Welte52b1f982008-12-23 20:25:15 +00001801/* Entry-point where L2 RSL from BTS enters */
Harald Welte8470bf22008-12-25 23:28:35 +00001802int abis_rsl_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001803{
Holger Hans Peter Freyther19bab732009-11-20 15:14:01 +01001804 struct abis_rsl_common_hdr *rslh;
Harald Welte8f5e2392009-02-03 12:57:37 +00001805 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001806
Holger Hans Peter Freyther19bab732009-11-20 15:14:01 +01001807 if (!msg) {
1808 DEBUGP(DRSL, "Empty RSL msg?..\n");
1809 return -1;
1810 }
1811
1812 if (msgb_l2len(msg) < sizeof(*rslh)) {
1813 DEBUGP(DRSL, "Truncated RSL message with l2len: %u\n", msgb_l2len(msg));
1814 return -1;
1815 }
1816
1817 rslh = msgb_l2(msg);
1818
Harald Welte52b1f982008-12-23 20:25:15 +00001819 switch (rslh->msg_discr & 0xfe) {
1820 case ABIS_RSL_MDISC_RLL:
1821 rc = abis_rsl_rx_rll(msg);
1822 break;
1823 case ABIS_RSL_MDISC_DED_CHAN:
1824 rc = abis_rsl_rx_dchan(msg);
1825 break;
1826 case ABIS_RSL_MDISC_COM_CHAN:
Harald Welte52b1f982008-12-23 20:25:15 +00001827 rc = abis_rsl_rx_cchan(msg);
1828 break;
Harald Welte8470bf22008-12-25 23:28:35 +00001829 case ABIS_RSL_MDISC_TRX:
1830 rc = abis_rsl_rx_trx(msg);
1831 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001832 case ABIS_RSL_MDISC_LOC:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001833 LOGP(DRSL, LOGL_NOTICE, "unimplemented RSL msg disc 0x%02x\n",
Harald Welte8f5e2392009-02-03 12:57:37 +00001834 rslh->msg_discr);
1835 break;
Harald Welte75099262009-02-16 21:12:08 +00001836 case ABIS_RSL_MDISC_IPACCESS:
1837 rc = abis_rsl_rx_ipacc(msg);
1838 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001839 default:
Harald Welteb1d4c8e2009-12-17 23:10:46 +01001840 LOGP(DRSL, LOGL_NOTICE, "unknown RSL message discriminator "
1841 "0x%02x\n", rslh->msg_discr);
Harald Welte52b1f982008-12-23 20:25:15 +00001842 return -EINVAL;
1843 }
Harald Welte4f4a3902008-12-26 00:04:49 +00001844 msgb_free(msg);
Harald Welte8470bf22008-12-25 23:28:35 +00001845 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001846}
Holger Freyther3b72a892009-02-04 00:31:39 +00001847
Holger Freyther3b72a892009-02-04 00:31:39 +00001848/* From Table 10.5.33 of GSM 04.08 */
1849int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
1850{
Harald Weltea43f7892009-12-01 18:04:30 +05301851 if (bts->si_common.chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
1852 return MAX(1, (3 - bts->si_common.chan_desc.bs_ag_blks_res))
1853 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +00001854 } else {
Harald Weltea43f7892009-12-01 18:04:30 +05301855 return (9 - bts->si_common.chan_desc.bs_ag_blks_res)
1856 * (bts->si_common.chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +00001857 }
1858}