blob: 94f9cc961389d37887b2070f724a7a4f5b4d3add [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* GSM Radio Signalling Link messages on the A-bis interface
2 * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */
3
Harald Welte8f5e2392009-02-03 12:57:37 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdio.h>
Harald Welte8470bf22008-12-25 23:28:35 +000025#include <stdlib.h>
Harald Welte52b1f982008-12-23 20:25:15 +000026#include <errno.h>
27#include <sys/types.h>
28
Harald Welte8470bf22008-12-25 23:28:35 +000029#include <openbsc/gsm_data.h>
30#include <openbsc/gsm_04_08.h>
31#include <openbsc/abis_rsl.h>
32#include <openbsc/chan_alloc.h>
33#include <openbsc/debug.h>
34#include <openbsc/tlv.h>
Holger Freyther392209c2009-02-10 00:06:19 +000035#include <openbsc/paging.h>
Harald Welte52b1f982008-12-23 20:25:15 +000036
Harald Welte8470bf22008-12-25 23:28:35 +000037#define RSL_ALLOC_SIZE 1024
38#define RSL_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000039
Holger Freyther3b72a892009-02-04 00:31:39 +000040#define MAX(a, b) (a) >= (b) ? (a) : (b)
41
Harald Welte52b1f982008-12-23 20:25:15 +000042static u_int8_t mdisc_by_msgtype(u_int8_t msg_type)
43{
44 /* mask off the transparent bit ? */
45 msg_type &= 0xfe;
46
Harald Welte8470bf22008-12-25 23:28:35 +000047 if ((msg_type & 0xf0) == 0x00)
Harald Welte52b1f982008-12-23 20:25:15 +000048 return ABIS_RSL_MDISC_RLL;
Harald Welte8470bf22008-12-25 23:28:35 +000049 if ((msg_type & 0xf0) == 0x10) {
Harald Welte52b1f982008-12-23 20:25:15 +000050 if (msg_type >= 0x19 && msg_type <= 0x22)
51 return ABIS_RSL_MDISC_TRX;
52 else
53 return ABIS_RSL_MDISC_COM_CHAN;
54 }
Harald Welte2d5b6382008-12-27 19:46:06 +000055 if ((msg_type & 0xe0) == 0x20)
Harald Welte52b1f982008-12-23 20:25:15 +000056 return ABIS_RSL_MDISC_DED_CHAN;
57
58 return ABIS_RSL_MDISC_LOC;
59}
60
61static inline void init_dchan_hdr(struct abis_rsl_dchan_hdr *dh,
62 u_int8_t msg_type)
63{
64 dh->c.msg_discr = mdisc_by_msgtype(msg_type);
65 dh->c.msg_type = msg_type;
66 dh->ie_chan = RSL_IE_CHAN_NR;
67}
68
69static inline void init_llm_hdr(struct abis_rsl_rll_hdr *dh,
70 u_int8_t msg_type)
71{
72 /* dh->c.msg_discr = mdisc_by_msgtype(msg_type); */
73 dh->c.msg_discr = ABIS_RSL_MDISC_RLL;
74 dh->c.msg_type = msg_type;
75 dh->ie_chan = RSL_IE_CHAN_NR;
76 dh->ie_link_id = RSL_IE_LINK_IDENT;
77}
78
79
80/* encode channel number as per Section 9.3.1 */
81u_int8_t rsl_enc_chan_nr(u_int8_t type, u_int8_t subch, u_int8_t timeslot)
82{
83 u_int8_t ret;
84
85 ret = (timeslot & 0x07) | type;
86
87 switch (type) {
88 case RSL_CHAN_Lm_ACCHs:
89 subch &= 0x01;
90 break;
91 case RSL_CHAN_SDCCH4_ACCH:
92 subch &= 0x07;
93 break;
94 case RSL_CHAN_SDCCH8_ACCH:
95 subch &= 0x07;
96 break;
97 default:
98 /* no subchannels allowed */
99 subch = 0x00;
100 break;
101 }
102 ret |= (subch << 3);
103
104 return ret;
105}
106
Harald Welte8470bf22008-12-25 23:28:35 +0000107/* determine logical channel based on TRX and channel number IE */
108struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, u_int8_t chan_nr)
109{
110 struct gsm_lchan *lchan;
111 u_int8_t ts_nr = chan_nr & 0x07;
112 u_int8_t cbits = chan_nr >> 3;
113 u_int8_t lch_idx;
114 struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
115
116 if (cbits == 0x01) {
117 lch_idx = 0; /* TCH/F */
118 if (ts->pchan != GSM_PCHAN_TCH_F)
119 fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n",
120 chan_nr, ts->pchan);
121 } else if ((cbits & 0x1e) == 0x02) {
122 lch_idx = cbits & 0x1; /* TCH/H */
123 if (ts->pchan != GSM_PCHAN_TCH_H)
124 fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n",
125 chan_nr, ts->pchan);
126 } else if ((cbits & 0x1c) == 0x04) {
127 lch_idx = cbits & 0x3; /* SDCCH/4 */
128 if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
129 fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n",
130 chan_nr, ts->pchan);
131 } else if ((cbits & 0x18) == 0x08) {
132 lch_idx = cbits & 0x7; /* SDCCH/8 */
133 if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C)
134 fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n",
135 chan_nr, ts->pchan);
136 } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
137 lch_idx = 0;
138 if (ts->pchan != GSM_PCHAN_CCCH &&
139 ts->pchan != GSM_PCHAN_CCCH_SDCCH4)
140 fprintf(stderr, "chan_nr=0x%02x but pchan=%u\n",
141 chan_nr, ts->pchan);
142 /* FIXME: we should not return first sdcch4 !!! */
143 } else {
144 fprintf(stderr, "unknown chan_nr=0x%02x\n", chan_nr);
145 return NULL;
146 }
147
148 lchan = &ts->lchan[lch_idx];
149
150 return lchan;
151}
152
153u_int8_t lchan2chan_nr(struct gsm_lchan *lchan)
154{
155 struct gsm_bts_trx_ts *ts = lchan->ts;
156 u_int8_t cbits, chan_nr;
157
158 switch (ts->pchan) {
159 case GSM_PCHAN_TCH_F:
160 cbits = 0x01;
161 break;
162 case GSM_PCHAN_TCH_H:
163 cbits = 0x02;
164 cbits += lchan->nr;
165 break;
166 case GSM_PCHAN_CCCH_SDCCH4:
167 cbits = 0x04;
168 cbits += lchan->nr;
169 break;
170 case GSM_PCHAN_SDCCH8_SACCH8C:
171 cbits = 0x08;
172 cbits += lchan->nr;
173 break;
174 default:
175 case GSM_PCHAN_CCCH:
176 cbits = 0x10;
177 break;
178 }
179
180 chan_nr = (cbits << 3) | (ts->nr & 0x7);
181
182 return chan_nr;
183}
184
Harald Welte52b1f982008-12-23 20:25:15 +0000185/* As per TS 03.03 Section 2.2, the IMSI has 'not more than 15 digits' */
186u_int64_t str_to_imsi(const char *imsi_str)
187{
188 u_int64_t ret;
189
190 ret = strtoull(imsi_str, NULL, 10);
191
192 return ret;
193}
194
195/* Table 5 Clause 7 TS 05.02 */
196unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res)
197{
198 if (!bs_ccch_sdcch_comb)
199 return 9 - bs_ag_blks_res;
200 else
201 return 3 - bs_ag_blks_res;
202}
203
204/* Chapter 6.5.2 of TS 05.02 */
205unsigned int get_ccch_group(u_int64_t imsi, unsigned int bs_cc_chans,
206 unsigned int n_pag_blocks)
207{
208 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks;
209}
210
211/* Chapter 6.5.2 of TS 05.02 */
212unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
213 int n_pag_blocks)
214{
215 return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks;
216}
217
Harald Welte8470bf22008-12-25 23:28:35 +0000218static struct msgb *rsl_msgb_alloc(void)
219{
220 return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM);
221}
222
Harald Welte362322e2009-02-15 14:36:38 +0000223#define MACBLOCK_SIZE 23
224static void pad_macblock(u_int8_t *out, const u_int8_t *in, int len)
225{
226 memcpy(out, in, len);
227
228 if (len < MACBLOCK_SIZE)
229 memset(out+len, 0x2b, MACBLOCK_SIZE-len);
230}
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
Harald Weltee79769b2009-02-07 00:48:17 +0000251int 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
269/* Chapter 8.4.1 */
Harald Weltee79769b2009-02-07 00:48:17 +0000270int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
Harald Welte52b1f982008-12-23 20:25:15 +0000271 u_int8_t act_type,
272 struct rsl_ie_chan_mode *chan_mode,
273 struct rsl_ie_chan_ident *chan_ident,
274 u_int8_t bs_power, u_int8_t ms_power,
275 u_int8_t ta)
276{
277 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000278 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000279
280 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
281 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
282 dh->chan_nr = chan_nr;
283
284 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
285 /* For compatibility with Phase 1 */
286 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode),
287 (u_int8_t *) chan_mode);
288 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
Harald Welte702d8702008-12-26 20:25:35 +0000289 (u_int8_t *) chan_ident);
Harald Welte52b1f982008-12-23 20:25:15 +0000290 /* FIXME: this shoould be optional */
Harald Welte702d8702008-12-26 20:25:35 +0000291#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000292 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
293 (u_int8_t *) &encr_info);
294 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
Harald Welte702d8702008-12-26 20:25:35 +0000295#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000296 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
297 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
298
Harald Weltee79769b2009-02-07 00:48:17 +0000299 msg->trx = trx;
300
Harald Welte8470bf22008-12-25 23:28:35 +0000301 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000302}
303
304#define TSC 7
305
Harald Welte8f5e2392009-02-03 12:57:37 +0000306int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
307 u_int8_t ta)
Harald Welte4b634542008-12-27 01:55:51 +0000308{
309 struct abis_rsl_dchan_hdr *dh;
310 struct msgb *msg = rsl_msgb_alloc();
311 /* FXIME: don't hardcode these!! */
Harald Welte4b634542008-12-27 01:55:51 +0000312 u_int8_t ms_power = 0x0f;
Harald Welte4b634542008-12-27 01:55:51 +0000313
314 u_int8_t chan_nr = lchan2chan_nr(lchan);
315 u_int16_t arfcn = lchan->ts->trx->arfcn;
316 struct rsl_ie_chan_mode cm;
317 struct rsl_ie_chan_ident ci;
318
319 /* FIXME: what to do with data calls ? */
320 cm.dtx_dtu = 0x00;
321 switch (lchan->type) {
322 case GSM_LCHAN_SDCCH:
323 cm.spd_ind = RSL_CMOD_SPD_SIGN;
324 cm.chan_rt = RSL_CMOD_CRT_SDCCH;
325 cm.chan_rate = 0x00;
326 break;
327 case GSM_LCHAN_TCH_F:
328 cm.spd_ind = RSL_CMOD_SPD_SPEECH;
329 cm.chan_rt = RSL_CMOD_CRT_TCH_Bm;
330 cm.chan_rate = 0x11; /* speech coding alg version 2*/
331 break;
Holger Freytherca362a62009-01-04 21:05:01 +0000332 case GSM_LCHAN_TCH_H:
Harald Welte8f5e2392009-02-03 12:57:37 +0000333 DEBUGP(DRSL, "Unimplemented TCH_H activation\n");
Holger Freytherca362a62009-01-04 21:05:01 +0000334 return -1;
335 case GSM_LCHAN_UNKNOWN:
336 case GSM_LCHAN_NONE:
337 return -1;
Harald Welte4b634542008-12-27 01:55:51 +0000338 }
339
340 ci.chan_desc.iei = 0x64;
341 ci.chan_desc.chan_nr = chan_nr;
342 ci.chan_desc.oct3 = (TSC << 5) | ((arfcn & 0x3ff) >> 8);
343 ci.chan_desc.oct4 = arfcn & 0xff;
344
345 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
346 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
347 dh->chan_nr = chan_nr;
348
349 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
350 /* For compatibility with Phase 1 */
351 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
352 (u_int8_t *) &cm);
353 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
354 (u_int8_t *) &ci);
Holger Freytherca362a62009-01-04 21:05:01 +0000355 /* FIXME: this should be optional */
Harald Welte4b634542008-12-27 01:55:51 +0000356#if 0
357 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
358 (u_int8_t *) &encr_info);
359 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
360#endif
361 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
362 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
363
Harald Weltee79769b2009-02-07 00:48:17 +0000364 msg->trx = lchan->ts->trx;
365
Harald Welte4b634542008-12-27 01:55:51 +0000366 return abis_rsl_sendmsg(msg);
367}
368
Holger Freyther36cbeff2008-12-30 19:15:20 +0000369/* Chapter 9.1.7 of 04.08 */
Harald Welte8470bf22008-12-25 23:28:35 +0000370int rsl_chan_release(struct gsm_lchan *lchan)
Harald Welte52b1f982008-12-23 20:25:15 +0000371{
372 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000373 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000374
375 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
376 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
Harald Welte8470bf22008-12-25 23:28:35 +0000377 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000378
Harald Welte8470bf22008-12-25 23:28:35 +0000379 msg->lchan = lchan;
380 msg->trx = lchan->ts->trx;
381
Harald Welte2d5b6382008-12-27 19:46:06 +0000382 DEBUGP(DRSL, "Channel Release CMD, chan_nr=0x%02x\n", dh->chan_nr);
383
Harald Welte8470bf22008-12-25 23:28:35 +0000384 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000385}
386
387int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
388 u_int8_t *ms_ident, u_int8_t chan_needed)
389{
390 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000391 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000392
393 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
394 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
395 dh->chan_nr = RSL_CHAN_PCH_AGCH;
396
397 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
Harald Welte255539c2008-12-28 02:26:27 +0000398 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
Harald Welte52b1f982008-12-23 20:25:15 +0000399 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
400
Harald Welte8470bf22008-12-25 23:28:35 +0000401 msg->trx = bts->c0;
402
403 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000404}
405
Holger Freyther7448a532009-01-04 20:18:23 +0000406int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
407 struct gsm_subscriber *subscr)
408{
Holger Freytherca362a62009-01-04 21:05:01 +0000409#if 0
Holger Freyther7448a532009-01-04 20:18:23 +0000410 u_int8_t mi[128];
411 unsigned int mi_len;
412 u_int8_t paging_group;
Holger Freytherca362a62009-01-04 21:05:01 +0000413#endif
Holger Freyther7448a532009-01-04 20:18:23 +0000414
415 return -1;
416}
417
Harald Welte52b1f982008-12-23 20:25:15 +0000418int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
419{
420 int i, len = strlen(str_in);
421
422 for (i = 0; i < len; i++) {
423 int num = str_in[i] - 0x30;
424 if (num < 0 || num > 9)
425 return -1;
426 if (i % 2 == 0)
427 bcd_out[i/2] = num;
428 else
429 bcd_out[i/2] |= (num << 4);
430 }
431
432 return 0;
433}
434
Harald Welte702d8702008-12-26 20:25:35 +0000435/* Chapter 8.5.6 */
Harald Welte52b1f982008-12-23 20:25:15 +0000436int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
437{
Harald Welte8470bf22008-12-25 23:28:35 +0000438 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000439 struct abis_rsl_dchan_hdr *dh;
Harald Welte362322e2009-02-15 14:36:38 +0000440 u_int8_t buf[MACBLOCK_SIZE];
Harald Welte52b1f982008-12-23 20:25:15 +0000441
442 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
443 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
444 dh->chan_nr = RSL_CHAN_PCH_AGCH;
445
Harald Welte362322e2009-02-15 14:36:38 +0000446 switch (bts->type) {
447 case GSM_BTS_TYPE_BS11:
448 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
449 break;
450 default:
451 /* If phase 2, construct a FULL_IMM_ASS_INFO */
452 pad_macblock(buf, val, len);
453 msgb_tlv_put(msg, RSL_IE_FULL_IMM_ASS_INFO, MACBLOCK_SIZE, buf);
454 break;
455 }
Harald Welte52b1f982008-12-23 20:25:15 +0000456
Harald Welte8470bf22008-12-25 23:28:35 +0000457 msg->trx = bts->c0;
458
459 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000460}
461
Harald Welte8470bf22008-12-25 23:28:35 +0000462/* Send "DATA REQUEST" message with given L3 Info payload */
Harald Welte52b1f982008-12-23 20:25:15 +0000463/* Chapter 8.3.1 */
Harald Welte8470bf22008-12-25 23:28:35 +0000464int rsl_data_request(struct msgb *msg, u_int8_t link_id)
Harald Welte52b1f982008-12-23 20:25:15 +0000465{
Harald Welte8470bf22008-12-25 23:28:35 +0000466 u_int8_t l3_len = msg->tail - (u_int8_t *)msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000467 struct abis_rsl_rll_hdr *rh;
468
Harald Welte8470bf22008-12-25 23:28:35 +0000469 if (msg->lchan == NULL) {
470 fprintf(stderr, "cannot send DATA REQUEST to unknown lchan\n");
471 return -EINVAL;
472 }
Harald Welte52b1f982008-12-23 20:25:15 +0000473
Harald Welte8470bf22008-12-25 23:28:35 +0000474 /* First push the L3 IE tag and length */
Harald Welte4b634542008-12-27 01:55:51 +0000475 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
Harald Welte8470bf22008-12-25 23:28:35 +0000476
477 /* Then push the RSL header */
Harald Welte52b1f982008-12-23 20:25:15 +0000478 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
479 init_llm_hdr(rh, RSL_MT_DATA_REQ);
Harald Welte8470bf22008-12-25 23:28:35 +0000480 rh->chan_nr = lchan2chan_nr(msg->lchan);
481 rh->link_id = link_id;
Harald Welte52b1f982008-12-23 20:25:15 +0000482
Harald Welte8470bf22008-12-25 23:28:35 +0000483 msg->trx = msg->lchan->ts->trx;
484
485 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000486}
487
Harald Welte702d8702008-12-26 20:25:35 +0000488/* Chapter 8.4.2: Channel Activate Acknowledge */
489static int rsl_rx_chan_act_ack(struct msgb *msg)
490{
491 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
492
493 /* BTS has confirmed channel activation, we now need
494 * to assign the activated channel to the MS */
Harald Welte4b634542008-12-27 01:55:51 +0000495 if (rslh->ie_chan != RSL_IE_CHAN_NR)
496 return -EINVAL;
497
498 DEBUGP(DRSL, "Channel Activate ACK Channel 0x%02x\n", rslh->chan_nr);
Harald Welte702d8702008-12-26 20:25:35 +0000499
Harald Welte4b634542008-12-27 01:55:51 +0000500 return 0;
501}
Harald Welte702d8702008-12-26 20:25:35 +0000502
Harald Welte4b634542008-12-27 01:55:51 +0000503/* Chapter 8.4.3: Channel Activate NACK */
504static int rsl_rx_chan_act_nack(struct msgb *msg)
505{
506 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
507
508 /* BTS has confirmed channel activation, we now need
509 * to assign the activated channel to the MS */
510 if (rslh->ie_chan != RSL_IE_CHAN_NR)
511 return -EINVAL;
512
513 DEBUGP(DRSL, "Channel Activate NACK Channel 0x%02x\n", rslh->chan_nr);
514
515 return 0;
Harald Welte702d8702008-12-26 20:25:35 +0000516}
517
Harald Welte52b1f982008-12-23 20:25:15 +0000518static int abis_rsl_rx_dchan(struct msgb *msg)
519{
Harald Welte8470bf22008-12-25 23:28:35 +0000520 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
521 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000522
Harald Welte8470bf22008-12-25 23:28:35 +0000523 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
524
525 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +0000526 case RSL_MT_CHAN_ACTIV_ACK:
Harald Welte4b634542008-12-27 01:55:51 +0000527 rc = rsl_rx_chan_act_ack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000528 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000529 case RSL_MT_CHAN_ACTIV_NACK:
Harald Welte4b634542008-12-27 01:55:51 +0000530 rc = rsl_rx_chan_act_nack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000531 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000532 case RSL_MT_CONN_FAIL:
Harald Welte2d5b6382008-12-27 19:46:06 +0000533 DEBUGP(DRSL, "Connection Fail, release channel\n");
Harald Welte14537e52008-12-27 10:29:08 +0000534 rc = rsl_chan_release(msg->lchan);
Harald Welte2d5b6382008-12-27 19:46:06 +0000535 /* only free it after channel release ACK */
Harald Welte8470bf22008-12-25 23:28:35 +0000536 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000537 case RSL_MT_MEAS_RES:
Harald Welte2d5b6382008-12-27 19:46:06 +0000538 DEBUGP(DRSL, "Measurement Result\n");
539 break;
540 case RSL_MT_RF_CHAN_REL_ACK:
Harald Welte8f5e2392009-02-03 12:57:37 +0000541 DEBUGP(DRSL, "RF CHANNEL RELEASE ACK chan_nr=0x%02x\n",
542 rslh->chan_nr);
Harald Welte2d5b6382008-12-27 19:46:06 +0000543 lchan_free(msg->lchan);
Harald Welte8470bf22008-12-25 23:28:35 +0000544 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000545 case RSL_MT_MODE_MODIFY_ACK:
546 case RSL_MT_MODE_MODIFY_NACK:
547 case RSL_MT_PHY_CONTEXT_CONF:
548 case RSL_MT_PREPROC_MEAS_RES:
Harald Welte52b1f982008-12-23 20:25:15 +0000549 case RSL_MT_TALKER_DET:
550 case RSL_MT_LISTENER_DET:
551 case RSL_MT_REMOTE_CODEC_CONF_REP:
552 case RSL_MT_MR_CODEC_MOD_ACK:
553 case RSL_MT_MR_CODEC_MOD_NACK:
554 case RSL_MT_MR_CODEC_MOD_PER:
555 fprintf(stderr, "Unimplemented Abis RSL DChan msg 0x%02x\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000556 rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000557 break;
558 default:
559 fprintf(stderr, "unknown Abis RSL DChan msg 0x%02x\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000560 rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000561 return -EINVAL;
562 }
Harald Welte8470bf22008-12-25 23:28:35 +0000563 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000564}
565
Harald Welte702d8702008-12-26 20:25:35 +0000566static int rsl_rx_error_rep(struct msgb *msg)
567{
568 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
569 u_int8_t cause_len;
570
571 if (rslh->data[0] != RSL_IE_CAUSE)
572 return -EINVAL;
573
574 cause_len = rslh->data[1];
Harald Welte4b634542008-12-27 01:55:51 +0000575 fprintf(stdout, "RSL ERROR REPORT, Cause ");
Harald Welte702d8702008-12-26 20:25:35 +0000576 hexdump(&rslh->data[2], cause_len);
577
578 return 0;
579}
580
Harald Welte52b1f982008-12-23 20:25:15 +0000581static int abis_rsl_rx_trx(struct msgb *msg)
582{
Harald Welte702d8702008-12-26 20:25:35 +0000583 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000584 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000585
586 switch (rslh->msg_type) {
Harald Welte702d8702008-12-26 20:25:35 +0000587 case RSL_MT_ERROR_REPORT:
588 rc = rsl_rx_error_rep(msg);
589 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000590 case RSL_MT_RF_RES_IND:
591 /* interference on idle channels of TRX */
Harald Welte8f5e2392009-02-03 12:57:37 +0000592 fprintf(stderr, "RSL TRX: RF Interference Indication\n");
593 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000594 case RSL_MT_OVERLOAD:
595 /* indicate CCCH / ACCH / processor overload */
Harald Welte8f5e2392009-02-03 12:57:37 +0000596 fprintf(stderr, "RSL TRX: CCCH/ACCH/CPU Overload\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000597 break;
598 default:
599 fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n",
600 rslh->msg_type);
601 return -EINVAL;
602 }
Harald Welte8470bf22008-12-25 23:28:35 +0000603 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000604}
605
Harald Welte8470bf22008-12-25 23:28:35 +0000606/* MS has requested a channel on the RACH */
Harald Welte52b1f982008-12-23 20:25:15 +0000607static int rsl_rx_chan_rqd(struct msgb *msg)
608{
Harald Welte702d8702008-12-26 20:25:35 +0000609 struct gsm_bts *bts = msg->trx->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000610 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
611 struct gsm48_req_ref *rqd_ref;
Harald Welte52b1f982008-12-23 20:25:15 +0000612 struct gsm48_imm_ass ia;
Harald Welte8470bf22008-12-25 23:28:35 +0000613 enum gsm_chan_t lctype;
Harald Welte2cbe0922008-12-29 04:09:31 +0000614 enum gsm_chreq_reason_t chreq_reason;
Harald Welte8470bf22008-12-25 23:28:35 +0000615 struct gsm_lchan *lchan;
616 u_int8_t rqd_ta;
Holger Freyther3186bf22008-12-29 06:23:49 +0000617 int ret;
Harald Welte8470bf22008-12-25 23:28:35 +0000618
Harald Welte52b1f982008-12-23 20:25:15 +0000619 u_int16_t arfcn;
620 u_int8_t ts_number, subch;
621
Harald Welte8470bf22008-12-25 23:28:35 +0000622 /* parse request reference to be used in immediate assign */
623 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
624 return -EINVAL;
625
626 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
627
628 /* parse access delay and use as TA */
629 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
630 return -EINVAL;
631 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
632
633 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
634 * request reference RA */
635 lctype = get_ctype_by_chreq(bts, rqd_ref->ra);
Harald Welte2cbe0922008-12-29 04:09:31 +0000636 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra);
637
Harald Welte8470bf22008-12-25 23:28:35 +0000638 /* check availability / allocate channel */
639 lchan = lchan_alloc(bts, lctype);
640 if (!lchan) {
641 fprintf(stderr, "CHAN RQD: no resources\n");
642 /* FIXME: send some kind of reject ?!? */
643 return -ENOMEM;
644 }
645
646 ts_number = lchan->ts->nr;
647 arfcn = lchan->ts->trx->arfcn;
648 subch = lchan->nr;
Harald Welte52b1f982008-12-23 20:25:15 +0000649
Harald Welte4b634542008-12-27 01:55:51 +0000650 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta);
Harald Welte52b1f982008-12-23 20:25:15 +0000651
652 /* create IMMEDIATE ASSIGN 04.08 messge */
653 memset(&ia, 0, sizeof(ia));
654 ia.l2_plen = 0x2d;
655 ia.proto_discr = GSM48_PDISC_RR;
656 ia.msg_type = GSM48_MT_RR_IMM_ASS;
Harald Welte2d5b6382008-12-27 19:46:06 +0000657 ia.page_mode = GSM48_PM_SAME;
Harald Welte4b634542008-12-27 01:55:51 +0000658 ia.chan_desc.chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000659 ia.chan_desc.h0.h = 0;
660 ia.chan_desc.h0.arfcn_high = arfcn >> 8;
661 ia.chan_desc.h0.arfcn_low = arfcn & 0xff;
662 ia.chan_desc.h0.tsc = 7;
Harald Welte8470bf22008-12-25 23:28:35 +0000663 /* use request reference extracted from CHAN_RQD */
664 memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref));
665 ia.timing_advance = rqd_ta;
Harald Welte52b1f982008-12-23 20:25:15 +0000666 ia.mob_alloc_len = 0;
667
Harald Welte8f5e2392009-02-03 12:57:37 +0000668 DEBUGP(DRSL, "Activating ARFCN(%u) TS(%u) SS(%u) lctype %s "
669 "chan_nr=0x%02x r=%s\n",
Harald Welteca64da92009-01-04 16:54:12 +0000670 arfcn, ts_number, subch, gsm_lchan_name(lchan->type),
671 ia.chan_desc.chan_nr, gsm_chreq_name(chreq_reason));
Harald Welte75a983f2008-12-27 21:34:06 +0000672
Holger Freyther3186bf22008-12-29 06:23:49 +0000673
Harald Welte52b1f982008-12-23 20:25:15 +0000674 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
Holger Freyther3186bf22008-12-29 06:23:49 +0000675 ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia);
676
Harald Welte817f3c82008-12-30 14:57:59 +0000677 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000678}
679
Harald Welteea280442009-02-02 22:29:56 +0000680/* MS has requested a channel on the RACH */
681static int rsl_rx_ccch_load(struct msgb *msg)
682{
683 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
684 u_int16_t pg_buf_space;
Holger Freyther8c563cf2009-02-03 20:08:51 +0000685 u_int16_t rach_slot_count = -1;
686 u_int16_t rach_busy_count = -1;
687 u_int16_t rach_access_count = -1;
Harald Welteea280442009-02-02 22:29:56 +0000688
689 switch (rslh->data[0]) {
690 case RSL_IE_PAGING_LOAD:
691 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
Holger Freyther392209c2009-02-10 00:06:19 +0000692 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
Harald Welteea280442009-02-02 22:29:56 +0000693 break;
694 case RSL_IE_RACH_LOAD:
Holger Freyther8c563cf2009-02-03 20:08:51 +0000695 if (msg->data_len >= 7) {
696 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
697 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
698 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
699 }
Harald Welteea280442009-02-02 22:29:56 +0000700 break;
701 default:
702 break;
703 }
704
705 return 0;
706}
707
Harald Welte52b1f982008-12-23 20:25:15 +0000708static int abis_rsl_rx_cchan(struct msgb *msg)
709{
Harald Welteea280442009-02-02 22:29:56 +0000710 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000711 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000712
Harald Welte8470bf22008-12-25 23:28:35 +0000713 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
714
715 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +0000716 case RSL_MT_CHAN_RQD:
717 /* MS has requested a channel on the RACH */
718 rc = rsl_rx_chan_rqd(msg);
719 break;
Harald Welteea280442009-02-02 22:29:56 +0000720 case RSL_MT_CCCH_LOAD_IND:
721 /* current load on the CCCH */
722 rc = rsl_rx_ccch_load(msg);
723 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000724 case RSL_MT_DELETE_IND:
725 /* CCCH overloaded, IMM_ASSIGN was dropped */
726 case RSL_MT_CBCH_LOAD_IND:
727 /* current load on the CBCH */
Harald Welte8f5e2392009-02-03 12:57:37 +0000728 fprintf(stderr, "Unimplemented Abis RSL TRX message type "
729 "0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000730 break;
731 default:
732 fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000733 rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000734 return -EINVAL;
735 }
Harald Welte8470bf22008-12-25 23:28:35 +0000736
737 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000738}
739
Harald Welte4b634542008-12-27 01:55:51 +0000740static int rsl_rx_rll_err_ind(struct msgb *msg)
741{
742 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
743 u_int8_t *rlm_cause = rllh->data;
744
745 DEBUGP(DRLL, "RLL ERROR INDICATION: chan_nr=0x%02x cause=0x%02x\n",
746 rllh->chan_nr, rlm_cause[1]);
747
748 return 0;
749}
Harald Welte52b1f982008-12-23 20:25:15 +0000750/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
751 0x02, 0x06,
752 0x01, 0x20,
753 0x02, 0x00,
754 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
755
756static int abis_rsl_rx_rll(struct msgb *msg)
757{
758 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
759 int rc;
Harald Welte8470bf22008-12-25 23:28:35 +0000760
761 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte52b1f982008-12-23 20:25:15 +0000762
763 switch (rllh->c.msg_type) {
764 case RSL_MT_DATA_IND:
Harald Welte4b634542008-12-27 01:55:51 +0000765 DEBUGP(DRLL, "DATA INDICATION chan_nr=0x%02x\n", rllh->chan_nr);
Harald Welte8470bf22008-12-25 23:28:35 +0000766 /* FIXME: Verify L3 info element */
Harald Welte702d8702008-12-26 20:25:35 +0000767 msg->l3h = &rllh->data[3];
Harald Welte52b1f982008-12-23 20:25:15 +0000768 rc = gsm0408_rcvmsg(msg);
769 break;
770 case RSL_MT_EST_IND:
Harald Welte8f5e2392009-02-03 12:57:37 +0000771 DEBUGP(DRLL, "ESTABLISH INDICATION chan_nr=0x%02x\n",
772 rllh->chan_nr);
Harald Welte8470bf22008-12-25 23:28:35 +0000773 /* FIXME: Verify L3 info element */
Harald Welte702d8702008-12-26 20:25:35 +0000774 msg->l3h = &rllh->data[3];
Harald Welte52b1f982008-12-23 20:25:15 +0000775 rc = gsm0408_rcvmsg(msg);
776 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000777 case RSL_MT_REL_IND:
Harald Welte8f5e2392009-02-03 12:57:37 +0000778 DEBUGP(DRLL, "RELEASE INDICATION chan_nr=0x%02x\n",
779 rllh->chan_nr);
Harald Welte2d5b6382008-12-27 19:46:06 +0000780 break;
781 case RSL_MT_REL_CONF:
Harald Welte8f5e2392009-02-03 12:57:37 +0000782 DEBUGP(DRLL, "RELEASE CONFIRMATION chan_nr=0x%02x\n",
783 rllh->chan_nr);
Harald Welte4b634542008-12-27 01:55:51 +0000784 break;
785 case RSL_MT_ERROR_IND:
786 rc = rsl_rx_rll_err_ind(msg);
787 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000788 case RSL_MT_UNIT_DATA_IND:
789 fprintf(stderr, "unimplemented Abis RLL message type 0x%02x\n",
790 rllh->c.msg_type);
791 break;
792 default:
793 fprintf(stderr, "unknown Abis RLL message type 0x%02x\n",
794 rllh->c.msg_type);
795 }
Harald Welte8470bf22008-12-25 23:28:35 +0000796 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000797}
798
799/* Entry-point where L2 RSL from BTS enters */
Harald Welte8470bf22008-12-25 23:28:35 +0000800int abis_rsl_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000801{
802 struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
Harald Welte8f5e2392009-02-03 12:57:37 +0000803 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000804
805 switch (rslh->msg_discr & 0xfe) {
806 case ABIS_RSL_MDISC_RLL:
807 rc = abis_rsl_rx_rll(msg);
808 break;
809 case ABIS_RSL_MDISC_DED_CHAN:
810 rc = abis_rsl_rx_dchan(msg);
811 break;
812 case ABIS_RSL_MDISC_COM_CHAN:
Harald Welte52b1f982008-12-23 20:25:15 +0000813 rc = abis_rsl_rx_cchan(msg);
814 break;
Harald Welte8470bf22008-12-25 23:28:35 +0000815 case ABIS_RSL_MDISC_TRX:
816 rc = abis_rsl_rx_trx(msg);
817 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000818 case ABIS_RSL_MDISC_LOC:
Harald Welte8f5e2392009-02-03 12:57:37 +0000819 fprintf(stderr, "unimplemented RSL msg disc 0x%02x\n",
820 rslh->msg_discr);
821 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000822 default:
823 fprintf(stderr, "unknown RSL message discriminator 0x%02x\n",
824 rslh->msg_discr);
825 return -EINVAL;
826 }
Harald Welte4f4a3902008-12-26 00:04:49 +0000827 msgb_free(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000828 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000829}
Holger Freyther3b72a892009-02-04 00:31:39 +0000830
831
832/* Section 3.3.2.3 . I think this looks like a table */
833int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
834{
835 switch (ccch_conf) {
836 case RSL_BCCH_CCCH_CONF_1_NC:
837 return 1;
838 case RSL_BCCH_CCCH_CONF_1_C:
839 return 1;
840 case RSL_BCCH_CCCH_CONF_2_NC:
841 return 2;
842 case RSL_BCCH_CCCH_CONF_3_NC:
843 return 3;
844 case RSL_BCCH_CCCH_CONF_4_NC:
845 return 4;
846 default:
847 return -1;
848 }
849}
850
851int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
852{
853 switch (ccch_conf) {
854 case RSL_BCCH_CCCH_CONF_1_NC:
855 return 0;
856 case RSL_BCCH_CCCH_CONF_1_C:
857 return 1;
858 case RSL_BCCH_CCCH_CONF_2_NC:
859 return 0;
860 case RSL_BCCH_CCCH_CONF_3_NC:
861 return 0;
862 case RSL_BCCH_CCCH_CONF_4_NC:
863 return 0;
864 default:
865 return -1;
866 }
867}
868
869/* From Table 10.5.33 of GSM 04.08 */
870int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
871{
872 if (bts->chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
873 return MAX(1, (3 - bts->chan_desc.bs_ag_blks_res))
Holger Freyther3aa8d6c2009-02-04 02:14:45 +0000874 * (bts->chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +0000875 } else {
876 return (9 - bts->chan_desc.bs_ag_blks_res)
Holger Freyther3aa8d6c2009-02-04 02:14:45 +0000877 * (bts->chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +0000878 }
879}