blob: 1b0f5c9bc3eb7f498da574d590916564353cb99a [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
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
Harald Weltea43f7892009-12-01 18:04:30 +053011 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Harald Weltea43f7892009-12-01 18:04:30 +053017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Weltea43f7892009-12-01 18:04:30 +053020 *
21 */
22
23#include <errno.h>
24#include <string.h>
Harald Welte6c40def2009-12-14 22:07:14 +010025#include <stdio.h>
Harald Weltea43f7892009-12-01 18:04:30 +053026#include <netinet/in.h>
27
Harald Welte80cffaf2011-05-24 15:02:20 +020028#include <osmocom/core/bitvec.h>
29#include <osmocom/core/utils.h>
30#include <osmocom/gsm/sysinfo.h>
31
32#include <openbsc/debug.h>
Harald Weltea43f7892009-12-01 18:04:30 +053033#include <openbsc/gsm_04_08.h>
34#include <openbsc/gsm_data.h>
35#include <openbsc/abis_rsl.h>
36#include <openbsc/rest_octets.h>
37
Holger Hans Peter Freytherb91a1062010-01-06 06:38:14 +010038
Harald Welteda760d32009-12-14 20:25:05 +010039/* Frequency Lists as per TS 04.08 10.5.2.13 */
40
41/* 10.5.2.13.2: Bit map 0 format */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020042static int freq_list_bm0_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +053043{
44 unsigned int byte, bit;
45
Harald Welteb1d4c8e2009-12-17 23:10:46 +010046 if (arfcn > 124 || arfcn < 1) {
47 LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n");
Harald Weltea43f7892009-12-01 18:04:30 +053048 return -EINVAL;
Harald Welteb1d4c8e2009-12-17 23:10:46 +010049 }
Harald Weltea43f7892009-12-01 18:04:30 +053050
Harald Welteda760d32009-12-14 20:25:05 +010051 /* the bitmask is from 1..124, not from 0..123 */
52 arfcn--;
53
Harald Weltea43f7892009-12-01 18:04:30 +053054 byte = arfcn / 8;
55 bit = arfcn % 8;
56
Harald Welteda760d32009-12-14 20:25:05 +010057 chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit);
Harald Weltea43f7892009-12-01 18:04:30 +053058
59 return 0;
60}
61
Harald Welteda760d32009-12-14 20:25:05 +010062/* 10.5.2.13.7: Variable bit map format */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020063static int freq_list_bmrel_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +053064{
65 unsigned int byte, bit;
66 unsigned int min_arfcn;
67 unsigned int bitno;
68
69 min_arfcn = (chan_list[0] & 1) << 9;
70 min_arfcn |= chan_list[1] << 1;
71 min_arfcn |= (chan_list[2] >> 7) & 1;
72
73 /* The lower end of our bitmaks is always implicitly included */
74 if (arfcn == min_arfcn)
75 return 0;
76
Harald Welte152b6262009-12-16 11:57:48 +010077 if (arfcn < min_arfcn) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +010078 LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +053079 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +010080 }
81 if (arfcn > min_arfcn + 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +010082 LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +053083 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +010084 }
Harald Weltea43f7892009-12-01 18:04:30 +053085
86 bitno = (arfcn - min_arfcn);
87 byte = bitno / 8;
88 bit = bitno % 8;
89
90 chan_list[2 + byte] |= 1 << (7 - bit);
91
92 return 0;
93}
94
95/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020096static int bitvec2freq_list(uint8_t *chan_list, struct bitvec *bv,
Harald Welte6c40def2009-12-14 22:07:14 +010097 const struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +053098{
Sylvain Munaut42a56522009-12-24 14:20:19 +010099 int i, rc, min = 1024, max = -1;
Harald Weltea43f7892009-12-01 18:04:30 +0530100
101 memset(chan_list, 0, 16);
102
103 /* GSM900-only handsets only support 'bit map 0 format' */
104 if (bts->band == GSM_BAND_900) {
105 chan_list[0] = 0;
Harald Welte6c40def2009-12-14 22:07:14 +0100106
107 for (i = 0; i < bv->data_len*8; i++) {
108 if (bitvec_get_bit_pos(bv, i)) {
109 rc = freq_list_bm0_set_arfcn(chan_list, i);
110 if (rc < 0)
111 return rc;
112 }
Harald Weltea43f7892009-12-01 18:04:30 +0530113 }
114 return 0;
115 }
116
117 /* We currently only support the 'Variable bitmap format' */
118 chan_list[0] = 0x8e;
119
Harald Welte6c40def2009-12-14 22:07:14 +0100120 for (i = 0; i < bv->data_len*8; i++) {
121 if (bitvec_get_bit_pos(bv, i)) {
122 if (i < min)
123 min = i;
124 if (i > max)
125 max = i;
126 }
Harald Weltea43f7892009-12-01 18:04:30 +0530127 }
128
Sylvain Munaut42a56522009-12-24 14:20:19 +0100129 if (max == -1) {
130 /* Empty set, use 'bit map 0 format' */
131 chan_list[0] = 0;
132 return 0;
133 }
134
Harald Welte152b6262009-12-16 11:57:48 +0100135 if ((max - min) > 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100136 LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, "
137 "distance > 111\n", min, max);
Harald Weltea43f7892009-12-01 18:04:30 +0530138 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +0100139 }
Harald Weltea43f7892009-12-01 18:04:30 +0530140
141 chan_list[0] |= (min >> 9) & 1;
142 chan_list[1] = (min >> 1);
143 chan_list[2] = (min & 1) << 7;
144
Harald Welte6c40def2009-12-14 22:07:14 +0100145 for (i = 0; i < bv->data_len*8; i++) {
Harald Welte152b6262009-12-16 11:57:48 +0100146 if (bitvec_get_bit_pos(bv, i)) {
147 rc = freq_list_bmrel_set_arfcn(chan_list, i);
148 if (rc < 0)
149 return rc;
150 }
Harald Weltea43f7892009-12-01 18:04:30 +0530151 }
152
153 return 0;
154}
155
156/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Dieter Spaar16646022011-07-28 00:01:50 +0200157/* static*/ int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530158{
Harald Weltea43f7892009-12-01 18:04:30 +0530159 struct gsm_bts_trx *trx;
Harald Welte6c40def2009-12-14 22:07:14 +0100160 struct bitvec *bv = &bts->si_common.cell_alloc;
Harald Weltea43f7892009-12-01 18:04:30 +0530161
Harald Weltea39b0f22010-06-14 22:26:10 +0200162 /* Zero-initialize the bit-vector */
Harald Weltec8794b52010-06-16 11:09:18 +0200163 memset(bv->data, 0, bv->data_len);
Harald Weltea39b0f22010-06-14 22:26:10 +0200164
Harald Welte6c40def2009-12-14 22:07:14 +0100165 /* first we generate a bitvec of all TRX ARFCN's in our BTS */
Harald Weltea39b0f22010-06-14 22:26:10 +0200166 llist_for_each_entry(trx, &bts->trx_list, list) {
167 unsigned int i, j;
168 /* Always add the TRX's ARFCN */
Harald Welte6c40def2009-12-14 22:07:14 +0100169 bitvec_set_bit_pos(bv, trx->arfcn, 1);
Harald Weltea39b0f22010-06-14 22:26:10 +0200170 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
171 struct gsm_bts_trx_ts *ts = &trx->ts[i];
172 /* Add any ARFCNs present in hopping channels */
173 for (j = 0; j < 1024; j++) {
174 if (bitvec_get_bit_pos(&ts->hopping.arfcns, j))
175 bitvec_set_bit_pos(bv, j, 1);
176 }
177 }
178 }
Harald Weltea43f7892009-12-01 18:04:30 +0530179
Harald Welte6c40def2009-12-14 22:07:14 +0100180 /* then we generate a GSM 04.08 frequency list from the bitvec */
181 return bitvec2freq_list(chan_list, bv, bts);
Harald Weltea43f7892009-12-01 18:04:30 +0530182}
183
Harald Welte6c40def2009-12-14 22:07:14 +0100184/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200185static int generate_bcch_chan_list(uint8_t *chan_list, struct gsm_bts *bts, int si5)
Harald Welte6c40def2009-12-14 22:07:14 +0100186{
187 struct gsm_bts *cur_bts;
Harald Welte64c07d22011-02-15 11:43:27 +0100188 struct bitvec *bv;
189
190 if (si5 && bts->neigh_list_manual_mode == NL_MODE_MANUAL_SI5SEP)
191 bv = &bts->si_common.si5_neigh_list;
192 else
193 bv = &bts->si_common.neigh_list;
Harald Welte6c40def2009-12-14 22:07:14 +0100194
Harald Welte32c09622011-01-11 23:44:56 +0100195 /* Generate list of neighbor cells if we are in automatic mode */
Harald Welte64c07d22011-02-15 11:43:27 +0100196 if (bts->neigh_list_manual_mode == NL_MODE_AUTOMATIC) {
Harald Welte21bbda22011-02-19 20:43:37 +0100197 /* Zero-initialize the bit-vector */
198 memset(bv->data, 0, bv->data_len);
199
Harald Welte32c09622011-01-11 23:44:56 +0100200 /* first we generate a bitvec of the BCCH ARFCN's in our BSC */
201 llist_for_each_entry(cur_bts, &bts->network->bts_list, list) {
202 if (cur_bts == bts)
203 continue;
204 bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1);
205 }
Harald Welte6c40def2009-12-14 22:07:14 +0100206 }
207
208 /* then we generate a GSM 04.08 frequency list from the bitvec */
209 return bitvec2freq_list(chan_list, bv, bts);
210}
211
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200212static int generate_si1(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530213{
214 int rc;
215 struct gsm48_system_information_type_1 *si1 =
216 (struct gsm48_system_information_type_1 *) output;
217
218 memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
219
220 si1->header.l2_plen = (21 << 2) | 1;
221 si1->header.rr_protocol_discriminator = GSM48_PDISC_RR;
222 si1->header.skip_indicator = 0;
223 si1->header.system_information = GSM48_MT_RR_SYSINFO_1;
224
225 rc = generate_cell_chan_list(si1->cell_channel_description, bts);
226 if (rc < 0)
227 return rc;
228
229 si1->rach_control = bts->si_common.rach_control;
230
231 /* SI1 Rest Octets (10.5.2.32), contains NCH position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100232 rc = rest_octets_si1(si1->rest_octets, NULL);
Harald Welte7401ae62010-06-15 16:44:12 +0200233
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100234 return sizeof(*si1) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530235}
236
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200237static int generate_si2(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530238{
239 int rc;
240 struct gsm48_system_information_type_2 *si2 =
241 (struct gsm48_system_information_type_2 *) output;
242
243 memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
244
245 si2->header.l2_plen = (22 << 2) | 1;
246 si2->header.rr_protocol_discriminator = GSM48_PDISC_RR;
247 si2->header.skip_indicator = 0;
248 si2->header.system_information = GSM48_MT_RR_SYSINFO_2;
249
Harald Welte64c07d22011-02-15 11:43:27 +0100250 rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts, 0);
Harald Weltea43f7892009-12-01 18:04:30 +0530251 if (rc < 0)
252 return rc;
253
254 si2->ncc_permitted = bts->si_common.ncc_permitted;
255 si2->rach_control = bts->si_common.rach_control;
256
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100257 return sizeof(*si2);
Harald Weltea43f7892009-12-01 18:04:30 +0530258}
259
Harald Welte1f893292010-03-14 23:46:48 +0800260static struct gsm48_si_ro_info si_info = {
Harald Weltea43f7892009-12-01 18:04:30 +0530261 .selection_params = {
262 .present = 0,
263 },
264 .power_offset = {
265 .present = 0,
266 },
267 .si2ter_indicator = 0,
268 .early_cm_ctrl = 1,
269 .scheduling = {
270 .present = 0,
271 },
272 .gprs_ind = {
273 .si13_position = 0,
274 .ra_colour = 0,
Harald Welte97a282b2010-03-14 15:37:43 +0800275 .present = 1,
Harald Weltea43f7892009-12-01 18:04:30 +0530276 },
277 .lsa_params = {
278 .present = 0,
279 },
280 .cell_id = 0, /* FIXME: doesn't the bts have this? */
281 .break_ind = 0,
282};
283
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200284static int generate_si3(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530285{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100286 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530287 struct gsm48_system_information_type_3 *si3 =
288 (struct gsm48_system_information_type_3 *) output;
289
290 memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
291
292 si3->header.l2_plen = (18 << 2) | 1;
293 si3->header.rr_protocol_discriminator = GSM48_PDISC_RR;
294 si3->header.skip_indicator = 0;
295 si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
296
297 si3->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +0100298 gsm48_generate_lai(&si3->lai, bts->network->country_code,
299 bts->network->network_code,
300 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530301 si3->control_channel_desc = bts->si_common.chan_desc;
302 si3->cell_options = bts->si_common.cell_options;
303 si3->cell_sel_par = bts->si_common.cell_sel_par;
304 si3->rach_control = bts->si_common.rach_control;
305
306 /* SI3 Rest Octets (10.5.2.34), containing
307 CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME
308 Power Offset, 2ter Indicator, Early Classmark Sending,
309 Scheduling if and WHERE, GPRS Indicator, SI13 position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100310 rc = rest_octets_si3(si3->rest_octets, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530311
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100312 return sizeof(*si3) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530313}
314
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200315static int generate_si4(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530316{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100317 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530318 struct gsm48_system_information_type_4 *si4 =
319 (struct gsm48_system_information_type_4 *) output;
320
321 /* length of all IEs present except SI4 rest octets and l2_plen */
322 int l2_plen = sizeof(*si4) - 1;
323
324 memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
325
326 si4->header.rr_protocol_discriminator = GSM48_PDISC_RR;
327 si4->header.skip_indicator = 0;
328 si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
329
Harald Welteafedeab2010-03-04 10:55:40 +0100330 gsm48_generate_lai(&si4->lai, bts->network->country_code,
331 bts->network->network_code,
332 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530333 si4->cell_sel_par = bts->si_common.cell_sel_par;
334 si4->rach_control = bts->si_common.rach_control;
335
336 /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
337
338 si4->header.l2_plen = (l2_plen << 2) | 1;
339
340 /* SI4 Rest Octets (10.5.2.35), containing
341 Optional Power offset, GPRS Indicator,
342 Cell Identity, LSA ID, Selection Parameter */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100343 rc = rest_octets_si4(si4->data, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530344
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100345 return sizeof(*si4) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530346}
347
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200348static int generate_si5(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530349{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100350 struct gsm48_system_information_type_5 *si5;
351 int rc, l2_plen = 18;
Harald Weltea43f7892009-12-01 18:04:30 +0530352
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100353 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
354
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100355 /* ip.access nanoBTS needs l2_plen!! */
Harald Weltefd355a32011-03-04 13:41:31 +0100356 switch (bts->type) {
357 case GSM_BTS_TYPE_NANOBTS:
358 case GSM_BTS_TYPE_HSL_FEMTO:
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100359 *output++ = (l2_plen << 2) | 1;
360 l2_plen++;
Harald Weltefd355a32011-03-04 13:41:31 +0100361 break;
362 default:
363 break;
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100364 }
365
366 si5 = (struct gsm48_system_information_type_5 *) output;
Harald Weltea43f7892009-12-01 18:04:30 +0530367
368 /* l2 pseudo length, not part of msg: 18 */
369 si5->rr_protocol_discriminator = GSM48_PDISC_RR;
370 si5->skip_indicator = 0;
371 si5->system_information = GSM48_MT_RR_SYSINFO_5;
Harald Welte64c07d22011-02-15 11:43:27 +0100372 rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts, 1);
Harald Weltea43f7892009-12-01 18:04:30 +0530373 if (rc < 0)
374 return rc;
375
376 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100377 return l2_plen;
Harald Weltea43f7892009-12-01 18:04:30 +0530378}
379
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200380static int generate_si6(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530381{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100382 struct gsm48_system_information_type_6 *si6;
383 int l2_plen = 11;
Harald Weltea43f7892009-12-01 18:04:30 +0530384
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100385 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
386
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100387 /* ip.access nanoBTS needs l2_plen!! */
Harald Weltefd355a32011-03-04 13:41:31 +0100388 switch (bts->type) {
389 case GSM_BTS_TYPE_NANOBTS:
390 case GSM_BTS_TYPE_HSL_FEMTO:
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100391 *output++ = (l2_plen << 2) | 1;
392 l2_plen++;
Harald Weltefd355a32011-03-04 13:41:31 +0100393 break;
394 default:
395 break;
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100396 }
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,
Sylvain Munaut851f1202011-10-17 13:56:02 +0200423 .ext_info_present = 0,
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
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200454static int generate_si13(uint8_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 +0200478typedef int (*gen_si_fn_t)(uint8_t *output, struct gsm_bts *bts);
479
480static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = {
481 [SYSINFO_TYPE_1] = &generate_si1,
482 [SYSINFO_TYPE_2] = &generate_si2,
483 [SYSINFO_TYPE_3] = &generate_si3,
484 [SYSINFO_TYPE_4] = &generate_si4,
485 [SYSINFO_TYPE_5] = &generate_si5,
486 [SYSINFO_TYPE_6] = &generate_si6,
487 [SYSINFO_TYPE_13] = &generate_si13,
488};
489
Harald Welte7401ae62010-06-15 16:44:12 +0200490int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
491{
492 gen_si_fn_t gen_si;
493
Harald Welte4511d892010-04-18 15:51:20 +0200494 switch (bts->gprs.mode) {
495 case BTS_GPRS_EGPRS:
Harald Weltea06fea02010-04-18 15:53:40 +0200496 si13_default.cell_opts.ext_info_present = 1;
497 si13_default.cell_opts.ext_info.egprs_supported = 1;
498 /* fallthrough */
Harald Welte4511d892010-04-18 15:51:20 +0200499 case BTS_GPRS_GPRS:
500 si_info.gprs_ind.present = 1;
501 break;
502 case BTS_GPRS_NONE:
503 si_info.gprs_ind.present = 0;
504 break;
505 }
Harald Welte1f893292010-03-14 23:46:48 +0800506
Sylvain Munaute0b06b02010-11-28 18:17:28 +0100507 memcpy(&si_info.selection_params,
508 &bts->si_common.cell_ro_sel_par,
509 sizeof(struct gsm48_si_selection_params));
510
Harald Welte7401ae62010-06-15 16:44:12 +0200511 gen_si = gen_si_fn[si_type];
512 if (!gen_si)
Harald Weltea43f7892009-12-01 18:04:30 +0530513 return -EINVAL;
Harald Weltea43f7892009-12-01 18:04:30 +0530514
Harald Welte7401ae62010-06-15 16:44:12 +0200515 return gen_si(bts->si_buf[si_type], bts);
Harald Weltea43f7892009-12-01 18:04:30 +0530516}