blob: 8ee95f9f18935151317201584da89e769bd5521c [file] [log] [blame]
Harald Weltea43f7892009-12-01 18:04:30 +05301/* GSM 04.08 System Information (SI) encoding and decoding
2 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
Harald Welte7401ae62010-06-15 16:44:12 +02004/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Harald Weltea43f7892009-12-01 18:04:30 +05305 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <errno.h>
25#include <string.h>
Harald Welte6c40def2009-12-14 22:07:14 +010026#include <stdio.h>
Harald Weltea43f7892009-12-01 18:04:30 +053027#include <sys/types.h>
28#include <netinet/in.h>
29
30#include <openbsc/gsm_04_08.h>
31#include <openbsc/gsm_data.h>
32#include <openbsc/abis_rsl.h>
33#include <openbsc/rest_octets.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010034#include <osmocore/bitvec.h>
Harald Welte7401ae62010-06-15 16:44:12 +020035#include <osmocore/utils.h>
Harald Welte152b6262009-12-16 11:57:48 +010036#include <openbsc/debug.h>
Harald Weltea43f7892009-12-01 18:04:30 +053037
38#define GSM48_CELL_CHAN_DESC_SIZE 16
Harald Weltea43f7892009-12-01 18:04:30 +053039#define GSM_MACBLOCK_PADDING 0x2b
40
Holger Hans Peter Freytherb91a1062010-01-06 06:38:14 +010041/* verify the sizes of the system information type structs */
42
43/* rest octets are not part of the struct */
44static_assert(sizeof(struct gsm48_system_information_type_header) == 3, _si_header_size);
45static_assert(sizeof(struct gsm48_rach_control) == 3, _si_rach_control);
46static_assert(sizeof(struct gsm48_system_information_type_1) == 22, _si1_size);
47static_assert(sizeof(struct gsm48_system_information_type_2) == 23, _si2_size);
48static_assert(sizeof(struct gsm48_system_information_type_3) == 19, _si3_size);
49static_assert(sizeof(struct gsm48_system_information_type_4) == 13, _si4_size);
50
51/* bs11 forgot the l2 len, 0-6 rest octets */
52static_assert(sizeof(struct gsm48_system_information_type_5) == 18, _si5_size);
53static_assert(sizeof(struct gsm48_system_information_type_6) == 11, _si6_size);
54
55static_assert(sizeof(struct gsm48_system_information_type_13) == 3, _si13_size);
56
Harald Welteda760d32009-12-14 20:25:05 +010057/* Frequency Lists as per TS 04.08 10.5.2.13 */
58
59/* 10.5.2.13.2: Bit map 0 format */
Harald Welte6c40def2009-12-14 22:07:14 +010060static int freq_list_bm0_set_arfcn(u_int8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +053061{
62 unsigned int byte, bit;
63
Harald Welteb1d4c8e2009-12-17 23:10:46 +010064 if (arfcn > 124 || arfcn < 1) {
65 LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n");
Harald Weltea43f7892009-12-01 18:04:30 +053066 return -EINVAL;
Harald Welteb1d4c8e2009-12-17 23:10:46 +010067 }
Harald Weltea43f7892009-12-01 18:04:30 +053068
Harald Welteda760d32009-12-14 20:25:05 +010069 /* the bitmask is from 1..124, not from 0..123 */
70 arfcn--;
71
Harald Weltea43f7892009-12-01 18:04:30 +053072 byte = arfcn / 8;
73 bit = arfcn % 8;
74
Harald Welteda760d32009-12-14 20:25:05 +010075 chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit);
Harald Weltea43f7892009-12-01 18:04:30 +053076
77 return 0;
78}
79
Harald Welteda760d32009-12-14 20:25:05 +010080/* 10.5.2.13.7: Variable bit map format */
Harald Welte6c40def2009-12-14 22:07:14 +010081static int freq_list_bmrel_set_arfcn(u_int8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +053082{
83 unsigned int byte, bit;
84 unsigned int min_arfcn;
85 unsigned int bitno;
86
87 min_arfcn = (chan_list[0] & 1) << 9;
88 min_arfcn |= chan_list[1] << 1;
89 min_arfcn |= (chan_list[2] >> 7) & 1;
90
91 /* The lower end of our bitmaks is always implicitly included */
92 if (arfcn == min_arfcn)
93 return 0;
94
Harald Welte152b6262009-12-16 11:57:48 +010095 if (arfcn < min_arfcn) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +010096 LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +053097 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +010098 }
99 if (arfcn > min_arfcn + 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100100 LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +0530101 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +0100102 }
Harald Weltea43f7892009-12-01 18:04:30 +0530103
104 bitno = (arfcn - min_arfcn);
105 byte = bitno / 8;
106 bit = bitno % 8;
107
108 chan_list[2 + byte] |= 1 << (7 - bit);
109
110 return 0;
111}
112
113/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Harald Welte6c40def2009-12-14 22:07:14 +0100114static int bitvec2freq_list(u_int8_t *chan_list, struct bitvec *bv,
115 const struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530116{
Sylvain Munaut42a56522009-12-24 14:20:19 +0100117 int i, rc, min = 1024, max = -1;
Harald Weltea43f7892009-12-01 18:04:30 +0530118
119 memset(chan_list, 0, 16);
120
121 /* GSM900-only handsets only support 'bit map 0 format' */
122 if (bts->band == GSM_BAND_900) {
123 chan_list[0] = 0;
Harald Welte6c40def2009-12-14 22:07:14 +0100124
125 for (i = 0; i < bv->data_len*8; i++) {
126 if (bitvec_get_bit_pos(bv, i)) {
127 rc = freq_list_bm0_set_arfcn(chan_list, i);
128 if (rc < 0)
129 return rc;
130 }
Harald Weltea43f7892009-12-01 18:04:30 +0530131 }
132 return 0;
133 }
134
135 /* We currently only support the 'Variable bitmap format' */
136 chan_list[0] = 0x8e;
137
Harald Welte6c40def2009-12-14 22:07:14 +0100138 for (i = 0; i < bv->data_len*8; i++) {
139 if (bitvec_get_bit_pos(bv, i)) {
140 if (i < min)
141 min = i;
142 if (i > max)
143 max = i;
144 }
Harald Weltea43f7892009-12-01 18:04:30 +0530145 }
146
Sylvain Munaut42a56522009-12-24 14:20:19 +0100147 if (max == -1) {
148 /* Empty set, use 'bit map 0 format' */
149 chan_list[0] = 0;
150 return 0;
151 }
152
Harald Welte152b6262009-12-16 11:57:48 +0100153 if ((max - min) > 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100154 LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, "
155 "distance > 111\n", min, max);
Harald Weltea43f7892009-12-01 18:04:30 +0530156 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +0100157 }
Harald Weltea43f7892009-12-01 18:04:30 +0530158
159 chan_list[0] |= (min >> 9) & 1;
160 chan_list[1] = (min >> 1);
161 chan_list[2] = (min & 1) << 7;
162
Harald Welte6c40def2009-12-14 22:07:14 +0100163 for (i = 0; i < bv->data_len*8; i++) {
Harald Welte152b6262009-12-16 11:57:48 +0100164 if (bitvec_get_bit_pos(bv, i)) {
165 rc = freq_list_bmrel_set_arfcn(chan_list, i);
166 if (rc < 0)
167 return rc;
168 }
Harald Weltea43f7892009-12-01 18:04:30 +0530169 }
170
171 return 0;
172}
173
174/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Harald Welte6c40def2009-12-14 22:07:14 +0100175static int generate_cell_chan_list(u_int8_t *chan_list, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530176{
Harald Weltea43f7892009-12-01 18:04:30 +0530177 struct gsm_bts_trx *trx;
Harald Welte6c40def2009-12-14 22:07:14 +0100178 struct bitvec *bv = &bts->si_common.cell_alloc;
Harald Weltea43f7892009-12-01 18:04:30 +0530179
Harald Weltea39b0f22010-06-14 22:26:10 +0200180 /* Zero-initialize the bit-vector */
Harald Weltec8794b52010-06-16 11:09:18 +0200181 memset(bv->data, 0, bv->data_len);
Harald Weltea39b0f22010-06-14 22:26:10 +0200182
Harald Welte6c40def2009-12-14 22:07:14 +0100183 /* first we generate a bitvec of all TRX ARFCN's in our BTS */
Harald Weltea39b0f22010-06-14 22:26:10 +0200184 llist_for_each_entry(trx, &bts->trx_list, list) {
185 unsigned int i, j;
186 /* Always add the TRX's ARFCN */
Harald Welte6c40def2009-12-14 22:07:14 +0100187 bitvec_set_bit_pos(bv, trx->arfcn, 1);
Harald Weltea39b0f22010-06-14 22:26:10 +0200188 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
189 struct gsm_bts_trx_ts *ts = &trx->ts[i];
190 /* Add any ARFCNs present in hopping channels */
191 for (j = 0; j < 1024; j++) {
192 if (bitvec_get_bit_pos(&ts->hopping.arfcns, j))
193 bitvec_set_bit_pos(bv, j, 1);
194 }
195 }
196 }
Harald Weltea43f7892009-12-01 18:04:30 +0530197
Harald Welte6c40def2009-12-14 22:07:14 +0100198 /* then we generate a GSM 04.08 frequency list from the bitvec */
199 return bitvec2freq_list(chan_list, bv, bts);
Harald Weltea43f7892009-12-01 18:04:30 +0530200}
201
Harald Welte6c40def2009-12-14 22:07:14 +0100202/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
203static int generate_bcch_chan_list(u_int8_t *chan_list, struct gsm_bts *bts)
204{
205 struct gsm_bts *cur_bts;
206 struct bitvec *bv = &bts->si_common.neigh_list;
207
Harald Weltea39b0f22010-06-14 22:26:10 +0200208 /* Zero-initialize the bit-vector */
Harald Weltec8794b52010-06-16 11:09:18 +0200209 memset(bv->data, 0, bv->data_len);
Harald Weltea39b0f22010-06-14 22:26:10 +0200210
Harald Welte6c40def2009-12-14 22:07:14 +0100211 /* first we generate a bitvec of the BCCH ARFCN's in our BSC */
212 llist_for_each_entry(cur_bts, &bts->network->bts_list, list) {
213 if (cur_bts == bts)
214 continue;
215 bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1);
216 }
217
218 /* then we generate a GSM 04.08 frequency list from the bitvec */
219 return bitvec2freq_list(chan_list, bv, bts);
220}
221
222static int generate_si1(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530223{
224 int rc;
225 struct gsm48_system_information_type_1 *si1 =
226 (struct gsm48_system_information_type_1 *) output;
227
228 memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
229
230 si1->header.l2_plen = (21 << 2) | 1;
231 si1->header.rr_protocol_discriminator = GSM48_PDISC_RR;
232 si1->header.skip_indicator = 0;
233 si1->header.system_information = GSM48_MT_RR_SYSINFO_1;
234
235 rc = generate_cell_chan_list(si1->cell_channel_description, bts);
236 if (rc < 0)
237 return rc;
238
239 si1->rach_control = bts->si_common.rach_control;
240
241 /* SI1 Rest Octets (10.5.2.32), contains NCH position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100242 rc = rest_octets_si1(si1->rest_octets, NULL);
Harald Welte7401ae62010-06-15 16:44:12 +0200243
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100244 return sizeof(*si1) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530245}
246
Harald Welte6c40def2009-12-14 22:07:14 +0100247static int generate_si2(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530248{
249 int rc;
250 struct gsm48_system_information_type_2 *si2 =
251 (struct gsm48_system_information_type_2 *) output;
252
253 memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
254
255 si2->header.l2_plen = (22 << 2) | 1;
256 si2->header.rr_protocol_discriminator = GSM48_PDISC_RR;
257 si2->header.skip_indicator = 0;
258 si2->header.system_information = GSM48_MT_RR_SYSINFO_2;
259
260 rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts);
261 if (rc < 0)
262 return rc;
263
264 si2->ncc_permitted = bts->si_common.ncc_permitted;
265 si2->rach_control = bts->si_common.rach_control;
266
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100267 return sizeof(*si2);
Harald Weltea43f7892009-12-01 18:04:30 +0530268}
269
Harald Welte1f893292010-03-14 23:46:48 +0800270static struct gsm48_si_ro_info si_info = {
Harald Weltea43f7892009-12-01 18:04:30 +0530271 .selection_params = {
272 .present = 0,
273 },
274 .power_offset = {
275 .present = 0,
276 },
277 .si2ter_indicator = 0,
278 .early_cm_ctrl = 1,
279 .scheduling = {
280 .present = 0,
281 },
282 .gprs_ind = {
283 .si13_position = 0,
284 .ra_colour = 0,
Harald Welte97a282b2010-03-14 15:37:43 +0800285 .present = 1,
Harald Weltea43f7892009-12-01 18:04:30 +0530286 },
287 .lsa_params = {
288 .present = 0,
289 },
290 .cell_id = 0, /* FIXME: doesn't the bts have this? */
291 .break_ind = 0,
292};
293
Harald Welte6c40def2009-12-14 22:07:14 +0100294static int generate_si3(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530295{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100296 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530297 struct gsm48_system_information_type_3 *si3 =
298 (struct gsm48_system_information_type_3 *) output;
299
300 memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
301
302 si3->header.l2_plen = (18 << 2) | 1;
303 si3->header.rr_protocol_discriminator = GSM48_PDISC_RR;
304 si3->header.skip_indicator = 0;
305 si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
306
307 si3->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +0100308 gsm48_generate_lai(&si3->lai, bts->network->country_code,
309 bts->network->network_code,
310 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530311 si3->control_channel_desc = bts->si_common.chan_desc;
312 si3->cell_options = bts->si_common.cell_options;
313 si3->cell_sel_par = bts->si_common.cell_sel_par;
314 si3->rach_control = bts->si_common.rach_control;
315
316 /* SI3 Rest Octets (10.5.2.34), containing
317 CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME
318 Power Offset, 2ter Indicator, Early Classmark Sending,
319 Scheduling if and WHERE, GPRS Indicator, SI13 position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100320 rc = rest_octets_si3(si3->rest_octets, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530321
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100322 return sizeof(*si3) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530323}
324
Harald Welte6c40def2009-12-14 22:07:14 +0100325static int generate_si4(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530326{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100327 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530328 struct gsm48_system_information_type_4 *si4 =
329 (struct gsm48_system_information_type_4 *) output;
330
331 /* length of all IEs present except SI4 rest octets and l2_plen */
332 int l2_plen = sizeof(*si4) - 1;
333
334 memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
335
336 si4->header.rr_protocol_discriminator = GSM48_PDISC_RR;
337 si4->header.skip_indicator = 0;
338 si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
339
Harald Welteafedeab2010-03-04 10:55:40 +0100340 gsm48_generate_lai(&si4->lai, bts->network->country_code,
341 bts->network->network_code,
342 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530343 si4->cell_sel_par = bts->si_common.cell_sel_par;
344 si4->rach_control = bts->si_common.rach_control;
345
346 /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
347
348 si4->header.l2_plen = (l2_plen << 2) | 1;
349
350 /* SI4 Rest Octets (10.5.2.35), containing
351 Optional Power offset, GPRS Indicator,
352 Cell Identity, LSA ID, Selection Parameter */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100353 rc = rest_octets_si4(si4->data, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530354
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100355 return sizeof(*si4) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530356}
357
Harald Welte6c40def2009-12-14 22:07:14 +0100358static int generate_si5(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530359{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100360 struct gsm48_system_information_type_5 *si5;
361 int rc, l2_plen = 18;
Harald Weltea43f7892009-12-01 18:04:30 +0530362
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100363 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
364
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100365 /* ip.access nanoBTS needs l2_plen!! */
366 if (is_ipaccess_bts(bts)) {
367 *output++ = (l2_plen << 2) | 1;
368 l2_plen++;
369 }
370
371 si5 = (struct gsm48_system_information_type_5 *) output;
Harald Weltea43f7892009-12-01 18:04:30 +0530372
373 /* l2 pseudo length, not part of msg: 18 */
374 si5->rr_protocol_discriminator = GSM48_PDISC_RR;
375 si5->skip_indicator = 0;
376 si5->system_information = GSM48_MT_RR_SYSINFO_5;
377 rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts);
378 if (rc < 0)
379 return rc;
380
381 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100382 return l2_plen;
Harald Weltea43f7892009-12-01 18:04:30 +0530383}
384
Harald Welte6c40def2009-12-14 22:07:14 +0100385static int generate_si6(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530386{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100387 struct gsm48_system_information_type_6 *si6;
388 int l2_plen = 11;
Harald Weltea43f7892009-12-01 18:04:30 +0530389
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100390 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
391
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100392 /* ip.access nanoBTS needs l2_plen!! */
393 if (is_ipaccess_bts(bts)) {
394 *output++ = (l2_plen << 2) | 1;
395 l2_plen++;
396 }
397
398 si6 = (struct gsm48_system_information_type_6 *) output;
Harald Weltea43f7892009-12-01 18:04:30 +0530399
400 /* l2 pseudo length, not part of msg: 11 */
401 si6->rr_protocol_discriminator = GSM48_PDISC_RR;
402 si6->skip_indicator = 0;
403 si6->system_information = GSM48_MT_RR_SYSINFO_6;
404 si6->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +0100405 gsm48_generate_lai(&si6->lai, bts->network->country_code,
406 bts->network->network_code,
407 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530408 si6->cell_options = bts->si_common.cell_options;
409 si6->ncc_permitted = bts->si_common.ncc_permitted;
410
411 /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */
412
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100413 return l2_plen;
Harald Weltea43f7892009-12-01 18:04:30 +0530414}
415
416static struct gsm48_si13_info si13_default = {
417 .cell_opts = {
Harald Welte85849182010-06-02 12:19:21 +0200418 .nmo = GPRS_NMO_II,
Harald Weltea4b16652010-05-31 12:54:23 +0200419 .t3168 = 2000,
420 .t3192 = 200,
Harald Welte97a282b2010-03-14 15:37:43 +0800421 .drx_timer_max = 3,
Harald Weltea43f7892009-12-01 18:04:30 +0530422 .bs_cv_max = 15,
Harald Weltea4b16652010-05-31 12:54:23 +0200423 .ext_info_present = 1,
Harald Welteda0586a2010-04-18 14:49:05 +0200424 .ext_info = {
425 /* The values below are just guesses ! */
Harald Weltea06fea02010-04-18 15:53:40 +0200426 .egprs_supported = 0,
Harald Welteda0586a2010-04-18 14:49:05 +0200427 .use_egprs_p_ch_req = 1,
Harald Weltea4b16652010-05-31 12:54:23 +0200428 .bep_period = 5,
Harald Welteda0586a2010-04-18 14:49:05 +0200429 .pfc_supported = 0,
430 .dtm_supported = 0,
431 .bss_paging_coordination = 0,
432 },
Harald Weltea43f7892009-12-01 18:04:30 +0530433 },
434 .pwr_ctrl_pars = {
435 .alpha = 10, /* a = 1.0 */
Harald Weltea4b16652010-05-31 12:54:23 +0200436 .t_avg_w = 16,
437 .t_avg_t = 16,
Harald Weltea43f7892009-12-01 18:04:30 +0530438 .pc_meas_chan = 0, /* downling measured on CCCH */
Harald Weltea4b16652010-05-31 12:54:23 +0200439 .n_avg_i = 8,
Harald Weltea43f7892009-12-01 18:04:30 +0530440 },
Harald Welte97a282b2010-03-14 15:37:43 +0800441 .bcch_change_mark = 1,
Harald Weltea43f7892009-12-01 18:04:30 +0530442 .si_change_field = 0,
443 .pbcch_present = 0,
444 {
445 .no_pbcch = {
Harald Welte97a282b2010-03-14 15:37:43 +0800446 .rac = 0, /* needs to be patched */
Harald Weltea43f7892009-12-01 18:04:30 +0530447 .spgc_ccch_sup = 0,
448 .net_ctrl_ord = 0,
Harald Welte97a282b2010-03-14 15:37:43 +0800449 .prio_acc_thr = 6,
Harald Weltea43f7892009-12-01 18:04:30 +0530450 },
451 },
452};
453
Harald Welte6c40def2009-12-14 22:07:14 +0100454static int generate_si13(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530455{
456 struct gsm48_system_information_type_13 *si13 =
457 (struct gsm48_system_information_type_13 *) output;
458 int ret;
459
460 memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
461
462 si13->header.rr_protocol_discriminator = GSM48_PDISC_RR;
463 si13->header.skip_indicator = 0;
464 si13->header.system_information = GSM48_MT_RR_SYSINFO_13;
465
Harald Welte97a282b2010-03-14 15:37:43 +0800466 si13_default.no_pbcch.rac = bts->gprs.rac;
467
Harald Weltea43f7892009-12-01 18:04:30 +0530468 ret = rest_octets_si13(si13->rest_octets, &si13_default);
469 if (ret < 0)
470 return ret;
471
Holger Hans Peter Freyther1c6f3942010-06-16 12:05:56 +0800472 /* length is coded in bit 2 an up */
473 si13->header.l2_plen = 0x01;
Harald Weltea43f7892009-12-01 18:04:30 +0530474
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100475 return sizeof (*si13) + ret;
Harald Weltea43f7892009-12-01 18:04:30 +0530476}
477
Harald Welte7401ae62010-06-15 16:44:12 +0200478static const uint8_t sitype2rsl[_MAX_SYSINFO_TYPE] = {
479 [SYSINFO_TYPE_1] = RSL_SYSTEM_INFO_1,
480 [SYSINFO_TYPE_2] = RSL_SYSTEM_INFO_2,
481 [SYSINFO_TYPE_3] = RSL_SYSTEM_INFO_3,
482 [SYSINFO_TYPE_4] = RSL_SYSTEM_INFO_4,
483 [SYSINFO_TYPE_5] = RSL_SYSTEM_INFO_5,
484 [SYSINFO_TYPE_6] = RSL_SYSTEM_INFO_6,
485 [SYSINFO_TYPE_7] = RSL_SYSTEM_INFO_7,
486 [SYSINFO_TYPE_8] = RSL_SYSTEM_INFO_8,
487 [SYSINFO_TYPE_9] = RSL_SYSTEM_INFO_9,
488 [SYSINFO_TYPE_10] = RSL_SYSTEM_INFO_10,
489 [SYSINFO_TYPE_13] = RSL_SYSTEM_INFO_13,
490 [SYSINFO_TYPE_16] = RSL_SYSTEM_INFO_16,
491 [SYSINFO_TYPE_17] = RSL_SYSTEM_INFO_17,
492 [SYSINFO_TYPE_18] = RSL_SYSTEM_INFO_18,
493 [SYSINFO_TYPE_19] = RSL_SYSTEM_INFO_19,
494 [SYSINFO_TYPE_20] = RSL_SYSTEM_INFO_20,
495 [SYSINFO_TYPE_2bis] = RSL_SYSTEM_INFO_2bis,
496 [SYSINFO_TYPE_2ter] = RSL_SYSTEM_INFO_2ter,
497 [SYSINFO_TYPE_2quater] = RSL_SYSTEM_INFO_2quater,
498 [SYSINFO_TYPE_5bis] = RSL_SYSTEM_INFO_5bis,
499 [SYSINFO_TYPE_5ter] = RSL_SYSTEM_INFO_5ter,
500};
501
502static const uint8_t rsl2sitype[0xff] = {
503 [RSL_SYSTEM_INFO_1] = SYSINFO_TYPE_1,
504 [RSL_SYSTEM_INFO_2] = SYSINFO_TYPE_2,
505 [RSL_SYSTEM_INFO_3] = SYSINFO_TYPE_3,
506 [RSL_SYSTEM_INFO_4] = SYSINFO_TYPE_4,
507 [RSL_SYSTEM_INFO_5] = SYSINFO_TYPE_5,
508 [RSL_SYSTEM_INFO_6] = SYSINFO_TYPE_6,
Harald Welte5f827f42010-07-30 11:11:38 +0200509 [RSL_SYSTEM_INFO_7] = SYSINFO_TYPE_7,
510 [RSL_SYSTEM_INFO_8] = SYSINFO_TYPE_8,
511 [RSL_SYSTEM_INFO_9] = SYSINFO_TYPE_9,
512 [RSL_SYSTEM_INFO_10] = SYSINFO_TYPE_10,
Harald Welte7401ae62010-06-15 16:44:12 +0200513 [RSL_SYSTEM_INFO_13] = SYSINFO_TYPE_13,
Harald Welte5f827f42010-07-30 11:11:38 +0200514 [RSL_SYSTEM_INFO_16] = SYSINFO_TYPE_16,
515 [RSL_SYSTEM_INFO_17] = SYSINFO_TYPE_17,
516 [RSL_SYSTEM_INFO_18] = SYSINFO_TYPE_18,
517 [RSL_SYSTEM_INFO_19] = SYSINFO_TYPE_19,
518 [RSL_SYSTEM_INFO_20] = SYSINFO_TYPE_20,
519 [RSL_SYSTEM_INFO_2bis] = SYSINFO_TYPE_2bis,
520 [RSL_SYSTEM_INFO_2ter] = SYSINFO_TYPE_2ter,
521 [RSL_SYSTEM_INFO_2quater] = SYSINFO_TYPE_2quater,
522 [RSL_SYSTEM_INFO_5bis] = SYSINFO_TYPE_5bis,
523 [RSL_SYSTEM_INFO_5ter] = SYSINFO_TYPE_5ter,
Harald Welte7401ae62010-06-15 16:44:12 +0200524};
525
526typedef int (*gen_si_fn_t)(uint8_t *output, struct gsm_bts *bts);
527
528static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = {
529 [SYSINFO_TYPE_1] = &generate_si1,
530 [SYSINFO_TYPE_2] = &generate_si2,
531 [SYSINFO_TYPE_3] = &generate_si3,
532 [SYSINFO_TYPE_4] = &generate_si4,
533 [SYSINFO_TYPE_5] = &generate_si5,
534 [SYSINFO_TYPE_6] = &generate_si6,
535 [SYSINFO_TYPE_13] = &generate_si13,
536};
537
Harald Welte5f827f42010-07-30 11:11:38 +0200538const struct value_string osmo_sitype_strs[_MAX_SYSINFO_TYPE] = {
Harald Welte7401ae62010-06-15 16:44:12 +0200539 { SYSINFO_TYPE_1, "1" },
540 { SYSINFO_TYPE_2, "2" },
541 { SYSINFO_TYPE_3, "3" },
542 { SYSINFO_TYPE_4, "4" },
543 { SYSINFO_TYPE_5, "5" },
544 { SYSINFO_TYPE_6, "6" },
545 { SYSINFO_TYPE_7, "7" },
546 { SYSINFO_TYPE_8, "8" },
547 { SYSINFO_TYPE_9, "9" },
548 { SYSINFO_TYPE_10, "10" },
549 { SYSINFO_TYPE_13, "13" },
550 { SYSINFO_TYPE_16, "16" },
551 { SYSINFO_TYPE_17, "17" },
552 { SYSINFO_TYPE_18, "18" },
553 { SYSINFO_TYPE_19, "19" },
554 { SYSINFO_TYPE_20, "20" },
555 { SYSINFO_TYPE_2bis, "2bis" },
556 { SYSINFO_TYPE_2ter, "2ter" },
557 { SYSINFO_TYPE_2quater, "2quater" },
558 { SYSINFO_TYPE_5bis, "5bis" },
559 { SYSINFO_TYPE_5ter, "5ter" },
560 { 0, NULL }
561};
562
563uint8_t gsm_sitype2rsl(enum osmo_sysinfo_type si_type)
Harald Weltea43f7892009-12-01 18:04:30 +0530564{
Harald Welte7401ae62010-06-15 16:44:12 +0200565 return sitype2rsl[si_type];
566}
567
568const char *gsm_sitype_name(enum osmo_sysinfo_type si_type)
569{
Harald Welte5f827f42010-07-30 11:11:38 +0200570 return get_value_string(osmo_sitype_strs, si_type);
Harald Welte7401ae62010-06-15 16:44:12 +0200571}
572
573int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
574{
575 gen_si_fn_t gen_si;
576
Harald Welte4511d892010-04-18 15:51:20 +0200577 switch (bts->gprs.mode) {
578 case BTS_GPRS_EGPRS:
Harald Weltea06fea02010-04-18 15:53:40 +0200579 si13_default.cell_opts.ext_info_present = 1;
580 si13_default.cell_opts.ext_info.egprs_supported = 1;
581 /* fallthrough */
Harald Welte4511d892010-04-18 15:51:20 +0200582 case BTS_GPRS_GPRS:
583 si_info.gprs_ind.present = 1;
584 break;
585 case BTS_GPRS_NONE:
586 si_info.gprs_ind.present = 0;
587 break;
588 }
Harald Welte1f893292010-03-14 23:46:48 +0800589
Sylvain Munaute0b06b02010-11-28 18:17:28 +0100590 memcpy(&si_info.selection_params,
591 &bts->si_common.cell_ro_sel_par,
592 sizeof(struct gsm48_si_selection_params));
593
Harald Welte7401ae62010-06-15 16:44:12 +0200594 gen_si = gen_si_fn[si_type];
595 if (!gen_si)
Harald Weltea43f7892009-12-01 18:04:30 +0530596 return -EINVAL;
Harald Weltea43f7892009-12-01 18:04:30 +0530597
Harald Welte7401ae62010-06-15 16:44:12 +0200598 return gen_si(bts->si_buf[si_type], bts);
Harald Weltea43f7892009-12-01 18:04:30 +0530599}