blob: 508787d402ce7493f9682b8deb546d1609ce282d [file] [log] [blame]
Harald Weltea54a2bb2009-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
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
5 *
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 Welte6ae64672009-12-14 22:07:14 +010026#include <stdio.h>
Harald Weltea54a2bb2009-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 Weltef4625b12010-02-20 16:24:02 +010034#include <osmocore/bitvec.h>
Harald Weltee285bad2009-12-16 11:57:48 +010035#include <openbsc/debug.h>
Harald Weltea54a2bb2009-12-01 18:04:30 +053036
37#define GSM48_CELL_CHAN_DESC_SIZE 16
38#define GSM_MACBLOCK_LEN 23
39#define GSM_MACBLOCK_PADDING 0x2b
40
Holger Hans Peter Freyther8526b152010-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 Weltebc479662009-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 Welte6ae64672009-12-14 22:07:14 +010060static int freq_list_bm0_set_arfcn(u_int8_t *chan_list, unsigned int arfcn)
Harald Weltea54a2bb2009-12-01 18:04:30 +053061{
62 unsigned int byte, bit;
63
Harald Weltecf2ec4a2009-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 Weltea54a2bb2009-12-01 18:04:30 +053066 return -EINVAL;
Harald Weltecf2ec4a2009-12-17 23:10:46 +010067 }
Harald Weltea54a2bb2009-12-01 18:04:30 +053068
Harald Weltebc479662009-12-14 20:25:05 +010069 /* the bitmask is from 1..124, not from 0..123 */
70 arfcn--;
71
Harald Weltea54a2bb2009-12-01 18:04:30 +053072 byte = arfcn / 8;
73 bit = arfcn % 8;
74
Harald Weltebc479662009-12-14 20:25:05 +010075 chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit);
Harald Weltea54a2bb2009-12-01 18:04:30 +053076
77 return 0;
78}
79
Harald Weltebc479662009-12-14 20:25:05 +010080/* 10.5.2.13.7: Variable bit map format */
Harald Welte6ae64672009-12-14 22:07:14 +010081static int freq_list_bmrel_set_arfcn(u_int8_t *chan_list, unsigned int arfcn)
Harald Weltea54a2bb2009-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 Weltee285bad2009-12-16 11:57:48 +010095 if (arfcn < min_arfcn) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +010096 LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn);
Harald Weltea54a2bb2009-12-01 18:04:30 +053097 return -EINVAL;
Harald Weltee285bad2009-12-16 11:57:48 +010098 }
99 if (arfcn > min_arfcn + 111) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100100 LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530101 return -EINVAL;
Harald Weltee285bad2009-12-16 11:57:48 +0100102 }
Harald Weltea54a2bb2009-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 Welte6ae64672009-12-14 22:07:14 +0100114static int bitvec2freq_list(u_int8_t *chan_list, struct bitvec *bv,
115 const struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530116{
Sylvain Munaut40f84a92009-12-24 14:20:19 +0100117 int i, rc, min = 1024, max = -1;
Harald Weltea54a2bb2009-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 Welte6ae64672009-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 Weltea54a2bb2009-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 Welte6ae64672009-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 Weltea54a2bb2009-12-01 18:04:30 +0530145 }
146
Sylvain Munaut40f84a92009-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 Weltee285bad2009-12-16 11:57:48 +0100153 if ((max - min) > 111) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100154 LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, "
155 "distance > 111\n", min, max);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530156 return -EINVAL;
Harald Weltee285bad2009-12-16 11:57:48 +0100157 }
Harald Weltea54a2bb2009-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 Welte6ae64672009-12-14 22:07:14 +0100163 for (i = 0; i < bv->data_len*8; i++) {
Harald Weltee285bad2009-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 Weltea54a2bb2009-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 Welte6ae64672009-12-14 22:07:14 +0100175static int generate_cell_chan_list(u_int8_t *chan_list, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530176{
Harald Weltea54a2bb2009-12-01 18:04:30 +0530177 struct gsm_bts_trx *trx;
Harald Welte6ae64672009-12-14 22:07:14 +0100178 struct bitvec *bv = &bts->si_common.cell_alloc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530179
Harald Weltea42a93f2010-06-14 22:26:10 +0200180 /* Zero-initialize the bit-vector */
181 memset(&bv->data, 0, bv->data_len);
182
Harald Welte6ae64672009-12-14 22:07:14 +0100183 /* first we generate a bitvec of all TRX ARFCN's in our BTS */
Harald Weltea42a93f2010-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 Welte6ae64672009-12-14 22:07:14 +0100187 bitvec_set_bit_pos(bv, trx->arfcn, 1);
Harald Weltea42a93f2010-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 Weltea54a2bb2009-12-01 18:04:30 +0530197
Harald Welte6ae64672009-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 Weltea54a2bb2009-12-01 18:04:30 +0530200}
201
Harald Welte6ae64672009-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 Weltea42a93f2010-06-14 22:26:10 +0200208 /* Zero-initialize the bit-vector */
209 memset(&bv->data, 0, bv->data_len);
210
Harald Welte6ae64672009-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 Weltea54a2bb2009-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 Freyther02c608c2010-01-06 07:52:31 +0100242 rc = rest_octets_si1(si1->rest_octets, NULL);
243 return sizeof(*si1) + rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530244}
245
Harald Welte6ae64672009-12-14 22:07:14 +0100246static int generate_si2(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530247{
248 int rc;
249 struct gsm48_system_information_type_2 *si2 =
250 (struct gsm48_system_information_type_2 *) output;
251
252 memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
253
254 si2->header.l2_plen = (22 << 2) | 1;
255 si2->header.rr_protocol_discriminator = GSM48_PDISC_RR;
256 si2->header.skip_indicator = 0;
257 si2->header.system_information = GSM48_MT_RR_SYSINFO_2;
258
259 rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts);
260 if (rc < 0)
261 return rc;
262
263 si2->ncc_permitted = bts->si_common.ncc_permitted;
264 si2->rach_control = bts->si_common.rach_control;
265
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100266 return sizeof(*si2);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530267}
268
Harald Weltee0500102010-03-14 23:46:48 +0800269static struct gsm48_si_ro_info si_info = {
Harald Weltea54a2bb2009-12-01 18:04:30 +0530270 .selection_params = {
271 .present = 0,
272 },
273 .power_offset = {
274 .present = 0,
275 },
276 .si2ter_indicator = 0,
277 .early_cm_ctrl = 1,
278 .scheduling = {
279 .present = 0,
280 },
281 .gprs_ind = {
282 .si13_position = 0,
283 .ra_colour = 0,
Harald Welte3055e332010-03-14 15:37:43 +0800284 .present = 1,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530285 },
286 .lsa_params = {
287 .present = 0,
288 },
289 .cell_id = 0, /* FIXME: doesn't the bts have this? */
290 .break_ind = 0,
291};
292
Harald Welte6ae64672009-12-14 22:07:14 +0100293static int generate_si3(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530294{
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100295 int rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530296 struct gsm48_system_information_type_3 *si3 =
297 (struct gsm48_system_information_type_3 *) output;
298
299 memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
300
301 si3->header.l2_plen = (18 << 2) | 1;
302 si3->header.rr_protocol_discriminator = GSM48_PDISC_RR;
303 si3->header.skip_indicator = 0;
304 si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
305
306 si3->cell_identity = htons(bts->cell_identity);
Harald Welted8493ac2010-03-04 10:55:40 +0100307 gsm48_generate_lai(&si3->lai, bts->network->country_code,
308 bts->network->network_code,
309 bts->location_area_code);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530310 si3->control_channel_desc = bts->si_common.chan_desc;
311 si3->cell_options = bts->si_common.cell_options;
312 si3->cell_sel_par = bts->si_common.cell_sel_par;
313 si3->rach_control = bts->si_common.rach_control;
314
315 /* SI3 Rest Octets (10.5.2.34), containing
316 CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME
317 Power Offset, 2ter Indicator, Early Classmark Sending,
318 Scheduling if and WHERE, GPRS Indicator, SI13 position */
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100319 rc = rest_octets_si3(si3->rest_octets, &si_info);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530320
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100321 return sizeof(*si3) + rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530322}
323
Harald Welte6ae64672009-12-14 22:07:14 +0100324static int generate_si4(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530325{
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100326 int rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530327 struct gsm48_system_information_type_4 *si4 =
328 (struct gsm48_system_information_type_4 *) output;
329
330 /* length of all IEs present except SI4 rest octets and l2_plen */
331 int l2_plen = sizeof(*si4) - 1;
332
333 memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
334
335 si4->header.rr_protocol_discriminator = GSM48_PDISC_RR;
336 si4->header.skip_indicator = 0;
337 si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
338
Harald Welted8493ac2010-03-04 10:55:40 +0100339 gsm48_generate_lai(&si4->lai, bts->network->country_code,
340 bts->network->network_code,
341 bts->location_area_code);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530342 si4->cell_sel_par = bts->si_common.cell_sel_par;
343 si4->rach_control = bts->si_common.rach_control;
344
345 /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
346
347 si4->header.l2_plen = (l2_plen << 2) | 1;
348
349 /* SI4 Rest Octets (10.5.2.35), containing
350 Optional Power offset, GPRS Indicator,
351 Cell Identity, LSA ID, Selection Parameter */
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100352 rc = rest_octets_si4(si4->data, &si_info);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530353
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100354 return sizeof(*si4) + rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530355}
356
Harald Welte6ae64672009-12-14 22:07:14 +0100357static int generate_si5(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530358{
Harald Welte2a92a712009-12-19 21:26:54 +0100359 struct gsm48_system_information_type_5 *si5;
360 int rc, l2_plen = 18;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530361
Holger Hans Peter Freyther4f2ace42010-01-06 07:52:55 +0100362 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
363
Harald Welte2a92a712009-12-19 21:26:54 +0100364 /* ip.access nanoBTS needs l2_plen!! */
365 if (is_ipaccess_bts(bts)) {
366 *output++ = (l2_plen << 2) | 1;
367 l2_plen++;
368 }
369
370 si5 = (struct gsm48_system_information_type_5 *) output;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530371
372 /* l2 pseudo length, not part of msg: 18 */
373 si5->rr_protocol_discriminator = GSM48_PDISC_RR;
374 si5->skip_indicator = 0;
375 si5->system_information = GSM48_MT_RR_SYSINFO_5;
376 rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts);
377 if (rc < 0)
378 return rc;
379
380 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
Harald Welte2a92a712009-12-19 21:26:54 +0100381 return l2_plen;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530382}
383
Harald Welte6ae64672009-12-14 22:07:14 +0100384static int generate_si6(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530385{
Harald Welte2a92a712009-12-19 21:26:54 +0100386 struct gsm48_system_information_type_6 *si6;
387 int l2_plen = 11;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530388
Holger Hans Peter Freyther4f2ace42010-01-06 07:52:55 +0100389 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
390
Harald Welte2a92a712009-12-19 21:26:54 +0100391 /* ip.access nanoBTS needs l2_plen!! */
392 if (is_ipaccess_bts(bts)) {
393 *output++ = (l2_plen << 2) | 1;
394 l2_plen++;
395 }
396
397 si6 = (struct gsm48_system_information_type_6 *) output;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530398
399 /* l2 pseudo length, not part of msg: 11 */
400 si6->rr_protocol_discriminator = GSM48_PDISC_RR;
401 si6->skip_indicator = 0;
402 si6->system_information = GSM48_MT_RR_SYSINFO_6;
403 si6->cell_identity = htons(bts->cell_identity);
Harald Welted8493ac2010-03-04 10:55:40 +0100404 gsm48_generate_lai(&si6->lai, bts->network->country_code,
405 bts->network->network_code,
406 bts->location_area_code);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530407 si6->cell_options = bts->si_common.cell_options;
408 si6->ncc_permitted = bts->si_common.ncc_permitted;
409
410 /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */
411
Harald Welte2a92a712009-12-19 21:26:54 +0100412 return l2_plen;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530413}
414
415static struct gsm48_si13_info si13_default = {
416 .cell_opts = {
Harald Welteb0644712010-06-02 12:19:21 +0200417 .nmo = GPRS_NMO_II,
Harald Weltea9713bf2010-05-31 12:54:23 +0200418 .t3168 = 2000,
419 .t3192 = 200,
Harald Welte3055e332010-03-14 15:37:43 +0800420 .drx_timer_max = 3,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530421 .bs_cv_max = 15,
Harald Weltea9713bf2010-05-31 12:54:23 +0200422 .ext_info_present = 1,
Harald Welte3ce9a0d2010-04-18 14:49:05 +0200423 .ext_info = {
424 /* The values below are just guesses ! */
Harald Welte09faa062010-04-18 15:53:40 +0200425 .egprs_supported = 0,
Harald Welte3ce9a0d2010-04-18 14:49:05 +0200426 .use_egprs_p_ch_req = 1,
Harald Weltea9713bf2010-05-31 12:54:23 +0200427 .bep_period = 5,
Harald Welte3ce9a0d2010-04-18 14:49:05 +0200428 .pfc_supported = 0,
429 .dtm_supported = 0,
430 .bss_paging_coordination = 0,
431 },
Harald Weltea54a2bb2009-12-01 18:04:30 +0530432 },
433 .pwr_ctrl_pars = {
434 .alpha = 10, /* a = 1.0 */
Harald Weltea9713bf2010-05-31 12:54:23 +0200435 .t_avg_w = 16,
436 .t_avg_t = 16,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530437 .pc_meas_chan = 0, /* downling measured on CCCH */
Harald Weltea9713bf2010-05-31 12:54:23 +0200438 .n_avg_i = 8,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530439 },
Harald Welte3055e332010-03-14 15:37:43 +0800440 .bcch_change_mark = 1,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530441 .si_change_field = 0,
442 .pbcch_present = 0,
443 {
444 .no_pbcch = {
Harald Welte3055e332010-03-14 15:37:43 +0800445 .rac = 0, /* needs to be patched */
Harald Weltea54a2bb2009-12-01 18:04:30 +0530446 .spgc_ccch_sup = 0,
447 .net_ctrl_ord = 0,
Harald Welte3055e332010-03-14 15:37:43 +0800448 .prio_acc_thr = 6,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530449 },
450 },
451};
452
Harald Welte6ae64672009-12-14 22:07:14 +0100453static int generate_si13(u_int8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530454{
455 struct gsm48_system_information_type_13 *si13 =
456 (struct gsm48_system_information_type_13 *) output;
457 int ret;
458
459 memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
460
461 si13->header.rr_protocol_discriminator = GSM48_PDISC_RR;
462 si13->header.skip_indicator = 0;
463 si13->header.system_information = GSM48_MT_RR_SYSINFO_13;
464
Harald Welte3055e332010-03-14 15:37:43 +0800465 si13_default.no_pbcch.rac = bts->gprs.rac;
466
Harald Weltea54a2bb2009-12-01 18:04:30 +0530467 ret = rest_octets_si13(si13->rest_octets, &si13_default);
468 if (ret < 0)
469 return ret;
470
Holger Hans Peter Freyther6c84d702010-06-16 12:05:56 +0800471 /* length is coded in bit 2 an up */
472 si13->header.l2_plen = 0x01;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530473
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100474 return sizeof (*si13) + ret;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530475}
476
477int gsm_generate_si(u_int8_t *output, struct gsm_bts *bts, int type)
478{
Harald Weltecb20b7a2010-04-18 15:51:20 +0200479 switch (bts->gprs.mode) {
480 case BTS_GPRS_EGPRS:
Harald Welte09faa062010-04-18 15:53:40 +0200481 si13_default.cell_opts.ext_info_present = 1;
482 si13_default.cell_opts.ext_info.egprs_supported = 1;
483 /* fallthrough */
Harald Weltecb20b7a2010-04-18 15:51:20 +0200484 case BTS_GPRS_GPRS:
485 si_info.gprs_ind.present = 1;
486 break;
487 case BTS_GPRS_NONE:
488 si_info.gprs_ind.present = 0;
489 break;
490 }
Harald Weltee0500102010-03-14 23:46:48 +0800491
Harald Weltea54a2bb2009-12-01 18:04:30 +0530492 switch (type) {
493 case RSL_SYSTEM_INFO_1:
494 return generate_si1(output, bts);
495 case RSL_SYSTEM_INFO_2:
496 return generate_si2(output, bts);
497 case RSL_SYSTEM_INFO_3:
498 return generate_si3(output, bts);
499 case RSL_SYSTEM_INFO_4:
500 return generate_si4(output, bts);
501 case RSL_SYSTEM_INFO_5:
502 return generate_si5(output, bts);
503 case RSL_SYSTEM_INFO_6:
504 return generate_si6(output, bts);
505 case RSL_SYSTEM_INFO_13:
506 return generate_si13(output, bts);
507 default:
508 return -EINVAL;
509 }
510
511 return 0;
512}