blob: ad869f4db50ead0af9be66ff07439f82f268308f [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 Welte52b1f982008-12-23 20:25:15 +0000223/* Send a BCCH_INFO message as per Chapter 8.5.1 */
Harald Weltee79769b2009-02-07 00:48:17 +0000224int rsl_bcch_info(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000225 const u_int8_t *data, int len)
226{
227 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000228 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000229
230 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof*dh);
231 init_dchan_hdr(dh, RSL_MT_BCCH_INFO);
232 dh->chan_nr = RSL_CHAN_BCCH;
233
234 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
235 msgb_tlv_put(msg, RSL_IE_FULL_BCCH_INFO, len, data);
236
Harald Weltee79769b2009-02-07 00:48:17 +0000237 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000238
239 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000240}
241
Harald Weltee79769b2009-02-07 00:48:17 +0000242int rsl_sacch_filling(struct gsm_bts_trx *trx, u_int8_t type,
Harald Welte52b1f982008-12-23 20:25:15 +0000243 const u_int8_t *data, int len)
244{
245 struct abis_rsl_common_hdr *ch;
Harald Welte8470bf22008-12-25 23:28:35 +0000246 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000247
248 ch = (struct abis_rsl_common_hdr *) msgb_put(msg, sizeof(*ch));
249 ch->msg_discr = ABIS_RSL_MDISC_TRX;
250 ch->msg_type = RSL_MT_SACCH_FILL;
251
252 msgb_tv_put(msg, RSL_IE_SYSINFO_TYPE, type);
Harald Welte702d8702008-12-26 20:25:35 +0000253 msgb_tl16v_put(msg, RSL_IE_L3_INFO, len, data);
Harald Welte52b1f982008-12-23 20:25:15 +0000254
Harald Weltee79769b2009-02-07 00:48:17 +0000255 msg->trx = trx;
Harald Welte8470bf22008-12-25 23:28:35 +0000256
257 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000258}
259
260/* Chapter 8.4.1 */
Harald Weltee79769b2009-02-07 00:48:17 +0000261int rsl_chan_activate(struct gsm_bts_trx *trx, u_int8_t chan_nr,
Harald Welte52b1f982008-12-23 20:25:15 +0000262 u_int8_t act_type,
263 struct rsl_ie_chan_mode *chan_mode,
264 struct rsl_ie_chan_ident *chan_ident,
265 u_int8_t bs_power, u_int8_t ms_power,
266 u_int8_t ta)
267{
268 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000269 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000270
271 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
272 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
273 dh->chan_nr = chan_nr;
274
275 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
276 /* For compatibility with Phase 1 */
277 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(*chan_mode),
278 (u_int8_t *) chan_mode);
279 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
Harald Welte702d8702008-12-26 20:25:35 +0000280 (u_int8_t *) chan_ident);
Harald Welte52b1f982008-12-23 20:25:15 +0000281 /* FIXME: this shoould be optional */
Harald Welte702d8702008-12-26 20:25:35 +0000282#if 0
Harald Welte52b1f982008-12-23 20:25:15 +0000283 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
284 (u_int8_t *) &encr_info);
285 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
Harald Welte702d8702008-12-26 20:25:35 +0000286#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000287 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
288 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
289
Harald Weltee79769b2009-02-07 00:48:17 +0000290 msg->trx = trx;
291
Harald Welte8470bf22008-12-25 23:28:35 +0000292 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000293}
294
295#define TSC 7
296
Harald Welte8f5e2392009-02-03 12:57:37 +0000297int rsl_chan_activate_lchan(struct gsm_lchan *lchan, u_int8_t act_type,
298 u_int8_t ta)
Harald Welte4b634542008-12-27 01:55:51 +0000299{
300 struct abis_rsl_dchan_hdr *dh;
301 struct msgb *msg = rsl_msgb_alloc();
302 /* FXIME: don't hardcode these!! */
Harald Welte4b634542008-12-27 01:55:51 +0000303 u_int8_t ms_power = 0x0f;
Harald Welte4b634542008-12-27 01:55:51 +0000304
305 u_int8_t chan_nr = lchan2chan_nr(lchan);
306 u_int16_t arfcn = lchan->ts->trx->arfcn;
307 struct rsl_ie_chan_mode cm;
308 struct rsl_ie_chan_ident ci;
309
310 /* FIXME: what to do with data calls ? */
311 cm.dtx_dtu = 0x00;
312 switch (lchan->type) {
313 case GSM_LCHAN_SDCCH:
314 cm.spd_ind = RSL_CMOD_SPD_SIGN;
315 cm.chan_rt = RSL_CMOD_CRT_SDCCH;
316 cm.chan_rate = 0x00;
317 break;
318 case GSM_LCHAN_TCH_F:
319 cm.spd_ind = RSL_CMOD_SPD_SPEECH;
320 cm.chan_rt = RSL_CMOD_CRT_TCH_Bm;
321 cm.chan_rate = 0x11; /* speech coding alg version 2*/
322 break;
Holger Freytherca362a62009-01-04 21:05:01 +0000323 case GSM_LCHAN_TCH_H:
Harald Welte8f5e2392009-02-03 12:57:37 +0000324 DEBUGP(DRSL, "Unimplemented TCH_H activation\n");
Holger Freytherca362a62009-01-04 21:05:01 +0000325 return -1;
326 case GSM_LCHAN_UNKNOWN:
327 case GSM_LCHAN_NONE:
328 return -1;
Harald Welte4b634542008-12-27 01:55:51 +0000329 }
330
331 ci.chan_desc.iei = 0x64;
332 ci.chan_desc.chan_nr = chan_nr;
333 ci.chan_desc.oct3 = (TSC << 5) | ((arfcn & 0x3ff) >> 8);
334 ci.chan_desc.oct4 = arfcn & 0xff;
335
336 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
337 init_dchan_hdr(dh, RSL_MT_CHAN_ACTIV);
338 dh->chan_nr = chan_nr;
339
340 msgb_tv_put(msg, RSL_IE_ACT_TYPE, act_type);
341 /* For compatibility with Phase 1 */
342 msgb_tlv_put(msg, RSL_IE_CHAN_MODE, sizeof(cm),
343 (u_int8_t *) &cm);
344 msgb_tlv_put(msg, RSL_IE_CHAN_IDENT, 4,
345 (u_int8_t *) &ci);
Holger Freytherca362a62009-01-04 21:05:01 +0000346 /* FIXME: this should be optional */
Harald Welte4b634542008-12-27 01:55:51 +0000347#if 0
348 msgb_tlv_put(msg, RSL_IE_ENCR_INFO, 1,
349 (u_int8_t *) &encr_info);
350 msgb_tv_put(msg, RSL_IE_BS_POWER, bs_power);
351#endif
352 msgb_tv_put(msg, RSL_IE_MS_POWER, ms_power);
353 msgb_tv_put(msg, RSL_IE_TIMING_ADVANCE, ta);
354
Harald Weltee79769b2009-02-07 00:48:17 +0000355 msg->trx = lchan->ts->trx;
356
Harald Welte4b634542008-12-27 01:55:51 +0000357 return abis_rsl_sendmsg(msg);
358}
359
Holger Freyther36cbeff2008-12-30 19:15:20 +0000360/* Chapter 9.1.7 of 04.08 */
Harald Welte8470bf22008-12-25 23:28:35 +0000361int rsl_chan_release(struct gsm_lchan *lchan)
Harald Welte52b1f982008-12-23 20:25:15 +0000362{
363 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000364 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000365
366 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
367 init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
Harald Welte8470bf22008-12-25 23:28:35 +0000368 dh->chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000369
Harald Welte8470bf22008-12-25 23:28:35 +0000370 msg->lchan = lchan;
371 msg->trx = lchan->ts->trx;
372
Harald Welte2d5b6382008-12-27 19:46:06 +0000373 DEBUGP(DRSL, "Channel Release CMD, chan_nr=0x%02x\n", dh->chan_nr);
374
Harald Welte8470bf22008-12-25 23:28:35 +0000375 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000376}
377
378int rsl_paging_cmd(struct gsm_bts *bts, u_int8_t paging_group, u_int8_t len,
379 u_int8_t *ms_ident, u_int8_t chan_needed)
380{
381 struct abis_rsl_dchan_hdr *dh;
Harald Welte8470bf22008-12-25 23:28:35 +0000382 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000383
384 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
385 init_dchan_hdr(dh, RSL_MT_PAGING_CMD);
386 dh->chan_nr = RSL_CHAN_PCH_AGCH;
387
388 msgb_tv_put(msg, RSL_IE_PAGING_GROUP, paging_group);
Harald Welte255539c2008-12-28 02:26:27 +0000389 msgb_tlv_put(msg, RSL_IE_MS_IDENTITY, len-2, ms_ident+2);
Harald Welte52b1f982008-12-23 20:25:15 +0000390 msgb_tv_put(msg, RSL_IE_CHAN_NEEDED, chan_needed);
391
Harald Welte8470bf22008-12-25 23:28:35 +0000392 msg->trx = bts->c0;
393
394 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000395}
396
Holger Freyther7448a532009-01-04 20:18:23 +0000397int rsl_paging_cmd_subscr(struct gsm_bts *bts, u_int8_t chan_need,
398 struct gsm_subscriber *subscr)
399{
Holger Freytherca362a62009-01-04 21:05:01 +0000400#if 0
Holger Freyther7448a532009-01-04 20:18:23 +0000401 u_int8_t mi[128];
402 unsigned int mi_len;
403 u_int8_t paging_group;
Holger Freytherca362a62009-01-04 21:05:01 +0000404#endif
Holger Freyther7448a532009-01-04 20:18:23 +0000405
406 return -1;
407}
408
Harald Welte52b1f982008-12-23 20:25:15 +0000409int imsi_str2bcd(u_int8_t *bcd_out, const char *str_in)
410{
411 int i, len = strlen(str_in);
412
413 for (i = 0; i < len; i++) {
414 int num = str_in[i] - 0x30;
415 if (num < 0 || num > 9)
416 return -1;
417 if (i % 2 == 0)
418 bcd_out[i/2] = num;
419 else
420 bcd_out[i/2] |= (num << 4);
421 }
422
423 return 0;
424}
425
Harald Welte702d8702008-12-26 20:25:35 +0000426/* Chapter 8.5.6 */
Harald Welte52b1f982008-12-23 20:25:15 +0000427int rsl_imm_assign_cmd(struct gsm_bts *bts, u_int8_t len, u_int8_t *val)
428{
Harald Welte8470bf22008-12-25 23:28:35 +0000429 struct msgb *msg = rsl_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000430 struct abis_rsl_dchan_hdr *dh;
431
432 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
433 init_dchan_hdr(dh, RSL_MT_IMMEDIATE_ASSIGN_CMD);
434 dh->chan_nr = RSL_CHAN_PCH_AGCH;
435
436 /* If phase 2, FULL_IMM_ASS_INFO */
437
438 msgb_tlv_put(msg, RSL_IE_IMM_ASS_INFO, len, val);
439
Harald Welte8470bf22008-12-25 23:28:35 +0000440 msg->trx = bts->c0;
441
442 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000443}
444
Harald Welte8470bf22008-12-25 23:28:35 +0000445/* Send "DATA REQUEST" message with given L3 Info payload */
Harald Welte52b1f982008-12-23 20:25:15 +0000446/* Chapter 8.3.1 */
Harald Welte8470bf22008-12-25 23:28:35 +0000447int rsl_data_request(struct msgb *msg, u_int8_t link_id)
Harald Welte52b1f982008-12-23 20:25:15 +0000448{
Harald Welte8470bf22008-12-25 23:28:35 +0000449 u_int8_t l3_len = msg->tail - (u_int8_t *)msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000450 struct abis_rsl_rll_hdr *rh;
451
Harald Welte8470bf22008-12-25 23:28:35 +0000452 if (msg->lchan == NULL) {
453 fprintf(stderr, "cannot send DATA REQUEST to unknown lchan\n");
454 return -EINVAL;
455 }
Harald Welte52b1f982008-12-23 20:25:15 +0000456
Harald Welte8470bf22008-12-25 23:28:35 +0000457 /* First push the L3 IE tag and length */
Harald Welte4b634542008-12-27 01:55:51 +0000458 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
Harald Welte8470bf22008-12-25 23:28:35 +0000459
460 /* Then push the RSL header */
Harald Welte52b1f982008-12-23 20:25:15 +0000461 rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
462 init_llm_hdr(rh, RSL_MT_DATA_REQ);
Harald Welte8470bf22008-12-25 23:28:35 +0000463 rh->chan_nr = lchan2chan_nr(msg->lchan);
464 rh->link_id = link_id;
Harald Welte52b1f982008-12-23 20:25:15 +0000465
Harald Welte8470bf22008-12-25 23:28:35 +0000466 msg->trx = msg->lchan->ts->trx;
467
468 return abis_rsl_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000469}
470
Harald Welte702d8702008-12-26 20:25:35 +0000471/* Chapter 8.4.2: Channel Activate Acknowledge */
472static int rsl_rx_chan_act_ack(struct msgb *msg)
473{
474 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
475
476 /* BTS has confirmed channel activation, we now need
477 * to assign the activated channel to the MS */
Harald Welte4b634542008-12-27 01:55:51 +0000478 if (rslh->ie_chan != RSL_IE_CHAN_NR)
479 return -EINVAL;
480
481 DEBUGP(DRSL, "Channel Activate ACK Channel 0x%02x\n", rslh->chan_nr);
Harald Welte702d8702008-12-26 20:25:35 +0000482
Harald Welte4b634542008-12-27 01:55:51 +0000483 return 0;
484}
Harald Welte702d8702008-12-26 20:25:35 +0000485
Harald Welte4b634542008-12-27 01:55:51 +0000486/* Chapter 8.4.3: Channel Activate NACK */
487static int rsl_rx_chan_act_nack(struct msgb *msg)
488{
489 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
490
491 /* BTS has confirmed channel activation, we now need
492 * to assign the activated channel to the MS */
493 if (rslh->ie_chan != RSL_IE_CHAN_NR)
494 return -EINVAL;
495
496 DEBUGP(DRSL, "Channel Activate NACK Channel 0x%02x\n", rslh->chan_nr);
497
498 return 0;
Harald Welte702d8702008-12-26 20:25:35 +0000499}
500
Harald Welte52b1f982008-12-23 20:25:15 +0000501static int abis_rsl_rx_dchan(struct msgb *msg)
502{
Harald Welte8470bf22008-12-25 23:28:35 +0000503 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
504 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000505
Harald Welte8470bf22008-12-25 23:28:35 +0000506 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
507
508 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +0000509 case RSL_MT_CHAN_ACTIV_ACK:
Harald Welte4b634542008-12-27 01:55:51 +0000510 rc = rsl_rx_chan_act_ack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000511 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000512 case RSL_MT_CHAN_ACTIV_NACK:
Harald Welte4b634542008-12-27 01:55:51 +0000513 rc = rsl_rx_chan_act_nack(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000514 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000515 case RSL_MT_CONN_FAIL:
Harald Welte2d5b6382008-12-27 19:46:06 +0000516 DEBUGP(DRSL, "Connection Fail, release channel\n");
Harald Welte14537e52008-12-27 10:29:08 +0000517 rc = rsl_chan_release(msg->lchan);
Harald Welte2d5b6382008-12-27 19:46:06 +0000518 /* only free it after channel release ACK */
Harald Welte8470bf22008-12-25 23:28:35 +0000519 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000520 case RSL_MT_MEAS_RES:
Harald Welte2d5b6382008-12-27 19:46:06 +0000521 DEBUGP(DRSL, "Measurement Result\n");
522 break;
523 case RSL_MT_RF_CHAN_REL_ACK:
Harald Welte8f5e2392009-02-03 12:57:37 +0000524 DEBUGP(DRSL, "RF CHANNEL RELEASE ACK chan_nr=0x%02x\n",
525 rslh->chan_nr);
Harald Welte2d5b6382008-12-27 19:46:06 +0000526 lchan_free(msg->lchan);
Harald Welte8470bf22008-12-25 23:28:35 +0000527 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000528 case RSL_MT_MODE_MODIFY_ACK:
529 case RSL_MT_MODE_MODIFY_NACK:
530 case RSL_MT_PHY_CONTEXT_CONF:
531 case RSL_MT_PREPROC_MEAS_RES:
Harald Welte52b1f982008-12-23 20:25:15 +0000532 case RSL_MT_TALKER_DET:
533 case RSL_MT_LISTENER_DET:
534 case RSL_MT_REMOTE_CODEC_CONF_REP:
535 case RSL_MT_MR_CODEC_MOD_ACK:
536 case RSL_MT_MR_CODEC_MOD_NACK:
537 case RSL_MT_MR_CODEC_MOD_PER:
538 fprintf(stderr, "Unimplemented Abis RSL DChan msg 0x%02x\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000539 rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000540 break;
541 default:
542 fprintf(stderr, "unknown Abis RSL DChan msg 0x%02x\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000543 rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000544 return -EINVAL;
545 }
Harald Welte8470bf22008-12-25 23:28:35 +0000546 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000547}
548
Harald Welte702d8702008-12-26 20:25:35 +0000549static int rsl_rx_error_rep(struct msgb *msg)
550{
551 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
552 u_int8_t cause_len;
553
554 if (rslh->data[0] != RSL_IE_CAUSE)
555 return -EINVAL;
556
557 cause_len = rslh->data[1];
Harald Welte4b634542008-12-27 01:55:51 +0000558 fprintf(stdout, "RSL ERROR REPORT, Cause ");
Harald Welte702d8702008-12-26 20:25:35 +0000559 hexdump(&rslh->data[2], cause_len);
560
561 return 0;
562}
563
Harald Welte52b1f982008-12-23 20:25:15 +0000564static int abis_rsl_rx_trx(struct msgb *msg)
565{
Harald Welte702d8702008-12-26 20:25:35 +0000566 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000567 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000568
569 switch (rslh->msg_type) {
Harald Welte702d8702008-12-26 20:25:35 +0000570 case RSL_MT_ERROR_REPORT:
571 rc = rsl_rx_error_rep(msg);
572 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000573 case RSL_MT_RF_RES_IND:
574 /* interference on idle channels of TRX */
Harald Welte8f5e2392009-02-03 12:57:37 +0000575 fprintf(stderr, "RSL TRX: RF Interference Indication\n");
576 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000577 case RSL_MT_OVERLOAD:
578 /* indicate CCCH / ACCH / processor overload */
Harald Welte8f5e2392009-02-03 12:57:37 +0000579 fprintf(stderr, "RSL TRX: CCCH/ACCH/CPU Overload\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000580 break;
581 default:
582 fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n",
583 rslh->msg_type);
584 return -EINVAL;
585 }
Harald Welte8470bf22008-12-25 23:28:35 +0000586 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000587}
588
Harald Welte8470bf22008-12-25 23:28:35 +0000589/* MS has requested a channel on the RACH */
Harald Welte52b1f982008-12-23 20:25:15 +0000590static int rsl_rx_chan_rqd(struct msgb *msg)
591{
Harald Welte702d8702008-12-26 20:25:35 +0000592 struct gsm_bts *bts = msg->trx->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000593 struct abis_rsl_dchan_hdr *rqd_hdr = msgb_l2(msg);
594 struct gsm48_req_ref *rqd_ref;
Harald Welte52b1f982008-12-23 20:25:15 +0000595 struct gsm48_imm_ass ia;
Harald Welte8470bf22008-12-25 23:28:35 +0000596 enum gsm_chan_t lctype;
Harald Welte2cbe0922008-12-29 04:09:31 +0000597 enum gsm_chreq_reason_t chreq_reason;
Harald Welte8470bf22008-12-25 23:28:35 +0000598 struct gsm_lchan *lchan;
599 u_int8_t rqd_ta;
Holger Freyther3186bf22008-12-29 06:23:49 +0000600 int ret;
Harald Welte8470bf22008-12-25 23:28:35 +0000601
Harald Welte52b1f982008-12-23 20:25:15 +0000602 u_int16_t arfcn;
603 u_int8_t ts_number, subch;
604
Harald Welte8470bf22008-12-25 23:28:35 +0000605 /* parse request reference to be used in immediate assign */
606 if (rqd_hdr->data[0] != RSL_IE_REQ_REFERENCE)
607 return -EINVAL;
608
609 rqd_ref = (struct gsm48_req_ref *) &rqd_hdr->data[1];
610
611 /* parse access delay and use as TA */
612 if (rqd_hdr->data[sizeof(struct gsm48_req_ref)+1] != RSL_IE_ACCESS_DELAY)
613 return -EINVAL;
614 rqd_ta = rqd_hdr->data[sizeof(struct gsm48_req_ref)+2];
615
616 /* determine channel type (SDCCH/TCH_F/TCH_H) based on
617 * request reference RA */
618 lctype = get_ctype_by_chreq(bts, rqd_ref->ra);
Harald Welte2cbe0922008-12-29 04:09:31 +0000619 chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra);
620
Harald Welte8470bf22008-12-25 23:28:35 +0000621 /* check availability / allocate channel */
622 lchan = lchan_alloc(bts, lctype);
623 if (!lchan) {
624 fprintf(stderr, "CHAN RQD: no resources\n");
625 /* FIXME: send some kind of reject ?!? */
626 return -ENOMEM;
627 }
628
629 ts_number = lchan->ts->nr;
630 arfcn = lchan->ts->trx->arfcn;
631 subch = lchan->nr;
Harald Welte52b1f982008-12-23 20:25:15 +0000632
Harald Welte4b634542008-12-27 01:55:51 +0000633 rsl_chan_activate_lchan(lchan, 0x00, rqd_ta);
Harald Welte52b1f982008-12-23 20:25:15 +0000634
635 /* create IMMEDIATE ASSIGN 04.08 messge */
636 memset(&ia, 0, sizeof(ia));
637 ia.l2_plen = 0x2d;
638 ia.proto_discr = GSM48_PDISC_RR;
639 ia.msg_type = GSM48_MT_RR_IMM_ASS;
Harald Welte2d5b6382008-12-27 19:46:06 +0000640 ia.page_mode = GSM48_PM_SAME;
Harald Welte4b634542008-12-27 01:55:51 +0000641 ia.chan_desc.chan_nr = lchan2chan_nr(lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000642 ia.chan_desc.h0.h = 0;
643 ia.chan_desc.h0.arfcn_high = arfcn >> 8;
644 ia.chan_desc.h0.arfcn_low = arfcn & 0xff;
645 ia.chan_desc.h0.tsc = 7;
Harald Welte8470bf22008-12-25 23:28:35 +0000646 /* use request reference extracted from CHAN_RQD */
647 memcpy(&ia.req_ref, rqd_ref, sizeof(ia.req_ref));
648 ia.timing_advance = rqd_ta;
Harald Welte52b1f982008-12-23 20:25:15 +0000649 ia.mob_alloc_len = 0;
650
Harald Welte8f5e2392009-02-03 12:57:37 +0000651 DEBUGP(DRSL, "Activating ARFCN(%u) TS(%u) SS(%u) lctype %s "
652 "chan_nr=0x%02x r=%s\n",
Harald Welteca64da92009-01-04 16:54:12 +0000653 arfcn, ts_number, subch, gsm_lchan_name(lchan->type),
654 ia.chan_desc.chan_nr, gsm_chreq_name(chreq_reason));
Harald Welte75a983f2008-12-27 21:34:06 +0000655
Holger Freyther3186bf22008-12-29 06:23:49 +0000656
Harald Welte52b1f982008-12-23 20:25:15 +0000657 /* send IMMEDIATE ASSIGN CMD on RSL to BTS (to send on CCCH to MS) */
Holger Freyther3186bf22008-12-29 06:23:49 +0000658 ret = rsl_imm_assign_cmd(bts, sizeof(ia), (u_int8_t *) &ia);
659
Harald Welte817f3c82008-12-30 14:57:59 +0000660 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000661}
662
Harald Welteea280442009-02-02 22:29:56 +0000663/* MS has requested a channel on the RACH */
664static int rsl_rx_ccch_load(struct msgb *msg)
665{
666 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
667 u_int16_t pg_buf_space;
Holger Freyther8c563cf2009-02-03 20:08:51 +0000668 u_int16_t rach_slot_count = -1;
669 u_int16_t rach_busy_count = -1;
670 u_int16_t rach_access_count = -1;
Harald Welteea280442009-02-02 22:29:56 +0000671
672 switch (rslh->data[0]) {
673 case RSL_IE_PAGING_LOAD:
674 pg_buf_space = rslh->data[1] << 8 | rslh->data[2];
675 DEBUGP(DRSL, "CCCH LOAD IND, free paging buffer space: %u\n",
676 pg_buf_space);
Holger Freyther392209c2009-02-10 00:06:19 +0000677 paging_update_buffer_space(msg->trx->bts, pg_buf_space);
Harald Welteea280442009-02-02 22:29:56 +0000678 break;
679 case RSL_IE_RACH_LOAD:
Holger Freyther8c563cf2009-02-03 20:08:51 +0000680 if (msg->data_len >= 7) {
681 rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
682 rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
683 rach_access_count = rslh->data[6] << 8 | rslh->data[7];
684 }
685 DEBUGP(DRSL, "CCCH LOAD IND, RACH Load Count: %u Busy: %u Access: %u\n",
686 rach_slot_count, rach_busy_count, rach_access_count);
Harald Welteea280442009-02-02 22:29:56 +0000687 break;
688 default:
689 break;
690 }
691
692 return 0;
693}
694
Harald Welte52b1f982008-12-23 20:25:15 +0000695static int abis_rsl_rx_cchan(struct msgb *msg)
696{
Harald Welteea280442009-02-02 22:29:56 +0000697 struct abis_rsl_dchan_hdr *rslh = msgb_l2(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000698 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000699
Harald Welte8470bf22008-12-25 23:28:35 +0000700 msg->lchan = lchan_lookup(msg->trx, rslh->chan_nr);
701
702 switch (rslh->c.msg_type) {
Harald Welte52b1f982008-12-23 20:25:15 +0000703 case RSL_MT_CHAN_RQD:
704 /* MS has requested a channel on the RACH */
705 rc = rsl_rx_chan_rqd(msg);
706 break;
Harald Welteea280442009-02-02 22:29:56 +0000707 case RSL_MT_CCCH_LOAD_IND:
708 /* current load on the CCCH */
709 rc = rsl_rx_ccch_load(msg);
710 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000711 case RSL_MT_DELETE_IND:
712 /* CCCH overloaded, IMM_ASSIGN was dropped */
713 case RSL_MT_CBCH_LOAD_IND:
714 /* current load on the CBCH */
Harald Welte8f5e2392009-02-03 12:57:37 +0000715 fprintf(stderr, "Unimplemented Abis RSL TRX message type "
716 "0x%02x\n", rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000717 break;
718 default:
719 fprintf(stderr, "Unknown Abis RSL TRX message type 0x%02x\n",
Harald Welte8470bf22008-12-25 23:28:35 +0000720 rslh->c.msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +0000721 return -EINVAL;
722 }
Harald Welte8470bf22008-12-25 23:28:35 +0000723
724 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000725}
726
Harald Welte4b634542008-12-27 01:55:51 +0000727static int rsl_rx_rll_err_ind(struct msgb *msg)
728{
729 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
730 u_int8_t *rlm_cause = rllh->data;
731
732 DEBUGP(DRLL, "RLL ERROR INDICATION: chan_nr=0x%02x cause=0x%02x\n",
733 rllh->chan_nr, rlm_cause[1]);
734
735 return 0;
736}
Harald Welte52b1f982008-12-23 20:25:15 +0000737/* ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
738 0x02, 0x06,
739 0x01, 0x20,
740 0x02, 0x00,
741 0x0b, 0x00, 0x0f, 0x05, 0x08, ... */
742
743static int abis_rsl_rx_rll(struct msgb *msg)
744{
745 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
746 int rc;
Harald Welte8470bf22008-12-25 23:28:35 +0000747
748 msg->lchan = lchan_lookup(msg->trx, rllh->chan_nr);
Harald Welte52b1f982008-12-23 20:25:15 +0000749
750 switch (rllh->c.msg_type) {
751 case RSL_MT_DATA_IND:
Harald Welte4b634542008-12-27 01:55:51 +0000752 DEBUGP(DRLL, "DATA INDICATION chan_nr=0x%02x\n", rllh->chan_nr);
Harald Welte8470bf22008-12-25 23:28:35 +0000753 /* FIXME: Verify L3 info element */
Harald Welte702d8702008-12-26 20:25:35 +0000754 msg->l3h = &rllh->data[3];
Harald Welte52b1f982008-12-23 20:25:15 +0000755 rc = gsm0408_rcvmsg(msg);
756 break;
757 case RSL_MT_EST_IND:
Harald Welte8f5e2392009-02-03 12:57:37 +0000758 DEBUGP(DRLL, "ESTABLISH INDICATION chan_nr=0x%02x\n",
759 rllh->chan_nr);
Harald Welte8470bf22008-12-25 23:28:35 +0000760 /* FIXME: Verify L3 info element */
Harald Welte702d8702008-12-26 20:25:35 +0000761 msg->l3h = &rllh->data[3];
Harald Welte52b1f982008-12-23 20:25:15 +0000762 rc = gsm0408_rcvmsg(msg);
763 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000764 case RSL_MT_REL_IND:
Harald Welte8f5e2392009-02-03 12:57:37 +0000765 DEBUGP(DRLL, "RELEASE INDICATION chan_nr=0x%02x\n",
766 rllh->chan_nr);
Harald Welte2d5b6382008-12-27 19:46:06 +0000767 break;
768 case RSL_MT_REL_CONF:
Harald Welte8f5e2392009-02-03 12:57:37 +0000769 DEBUGP(DRLL, "RELEASE CONFIRMATION chan_nr=0x%02x\n",
770 rllh->chan_nr);
Harald Welte4b634542008-12-27 01:55:51 +0000771 break;
772 case RSL_MT_ERROR_IND:
773 rc = rsl_rx_rll_err_ind(msg);
774 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000775 case RSL_MT_UNIT_DATA_IND:
776 fprintf(stderr, "unimplemented Abis RLL message type 0x%02x\n",
777 rllh->c.msg_type);
778 break;
779 default:
780 fprintf(stderr, "unknown Abis RLL message type 0x%02x\n",
781 rllh->c.msg_type);
782 }
Harald Welte8470bf22008-12-25 23:28:35 +0000783 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000784}
785
786/* Entry-point where L2 RSL from BTS enters */
Harald Welte8470bf22008-12-25 23:28:35 +0000787int abis_rsl_rcvmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000788{
789 struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
Harald Welte8f5e2392009-02-03 12:57:37 +0000790 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000791
792 switch (rslh->msg_discr & 0xfe) {
793 case ABIS_RSL_MDISC_RLL:
794 rc = abis_rsl_rx_rll(msg);
795 break;
796 case ABIS_RSL_MDISC_DED_CHAN:
797 rc = abis_rsl_rx_dchan(msg);
798 break;
799 case ABIS_RSL_MDISC_COM_CHAN:
Harald Welte52b1f982008-12-23 20:25:15 +0000800 rc = abis_rsl_rx_cchan(msg);
801 break;
Harald Welte8470bf22008-12-25 23:28:35 +0000802 case ABIS_RSL_MDISC_TRX:
803 rc = abis_rsl_rx_trx(msg);
804 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000805 case ABIS_RSL_MDISC_LOC:
Harald Welte8f5e2392009-02-03 12:57:37 +0000806 fprintf(stderr, "unimplemented RSL msg disc 0x%02x\n",
807 rslh->msg_discr);
808 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000809 default:
810 fprintf(stderr, "unknown RSL message discriminator 0x%02x\n",
811 rslh->msg_discr);
812 return -EINVAL;
813 }
Harald Welte4f4a3902008-12-26 00:04:49 +0000814 msgb_free(msg);
Harald Welte8470bf22008-12-25 23:28:35 +0000815 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000816}
Holger Freyther3b72a892009-02-04 00:31:39 +0000817
818
819/* Section 3.3.2.3 . I think this looks like a table */
820int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf)
821{
822 switch (ccch_conf) {
823 case RSL_BCCH_CCCH_CONF_1_NC:
824 return 1;
825 case RSL_BCCH_CCCH_CONF_1_C:
826 return 1;
827 case RSL_BCCH_CCCH_CONF_2_NC:
828 return 2;
829 case RSL_BCCH_CCCH_CONF_3_NC:
830 return 3;
831 case RSL_BCCH_CCCH_CONF_4_NC:
832 return 4;
833 default:
834 return -1;
835 }
836}
837
838int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf)
839{
840 switch (ccch_conf) {
841 case RSL_BCCH_CCCH_CONF_1_NC:
842 return 0;
843 case RSL_BCCH_CCCH_CONF_1_C:
844 return 1;
845 case RSL_BCCH_CCCH_CONF_2_NC:
846 return 0;
847 case RSL_BCCH_CCCH_CONF_3_NC:
848 return 0;
849 case RSL_BCCH_CCCH_CONF_4_NC:
850 return 0;
851 default:
852 return -1;
853 }
854}
855
856/* From Table 10.5.33 of GSM 04.08 */
857int rsl_number_of_paging_subchannels(struct gsm_bts *bts)
858{
859 if (bts->chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
860 return MAX(1, (3 - bts->chan_desc.bs_ag_blks_res))
Holger Freyther3aa8d6c2009-02-04 02:14:45 +0000861 * (bts->chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +0000862 } else {
863 return (9 - bts->chan_desc.bs_ag_blks_res)
Holger Freyther3aa8d6c2009-02-04 02:14:45 +0000864 * (bts->chan_desc.bs_pa_mfrms + 2);
Holger Freyther3b72a892009-02-04 00:31:39 +0000865 }
866}