blob: 9842a9dfdf1eb539db5a5495cd5069bb29188945 [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
Harald Welte99bed522010-06-15 16:44:12 +02004/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Harald Weltea54a2bb2009-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 Welte0e3e88e2011-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 Weltea54a2bb2009-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 Welte0e3e88e2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Harald Weltea54a2bb2009-12-01 18:04:30 +053017 *
Harald Welte0e3e88e2011-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 Weltea54a2bb2009-12-01 18:04:30 +053020 *
21 */
22
23#include <errno.h>
24#include <string.h>
Harald Welte6ae64672009-12-14 22:07:14 +010025#include <stdio.h>
Harald Weltea54a2bb2009-12-01 18:04:30 +053026#include <netinet/in.h>
27
Harald Welte6b77f0f2011-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 Weltea54a2bb2009-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 Freyther8526b152010-01-06 06:38:14 +010038
Harald Weltebc479662009-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 Freyther7eb8a9a2011-04-18 17:04:00 +020042static int freq_list_bm0_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea54a2bb2009-12-01 18:04:30 +053043{
44 unsigned int byte, bit;
45
Harald Weltecf2ec4a2009-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 Weltea54a2bb2009-12-01 18:04:30 +053048 return -EINVAL;
Harald Weltecf2ec4a2009-12-17 23:10:46 +010049 }
Harald Weltea54a2bb2009-12-01 18:04:30 +053050
Harald Weltebc479662009-12-14 20:25:05 +010051 /* the bitmask is from 1..124, not from 0..123 */
52 arfcn--;
53
Harald Weltea54a2bb2009-12-01 18:04:30 +053054 byte = arfcn / 8;
55 bit = arfcn % 8;
56
Harald Weltebc479662009-12-14 20:25:05 +010057 chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit);
Harald Weltea54a2bb2009-12-01 18:04:30 +053058
59 return 0;
60}
61
Harald Weltebc479662009-12-14 20:25:05 +010062/* 10.5.2.13.7: Variable bit map format */
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +020063static int freq_list_bmrel_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea54a2bb2009-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 Weltee285bad2009-12-16 11:57:48 +010077 if (arfcn < min_arfcn) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +010078 LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn);
Harald Weltea54a2bb2009-12-01 18:04:30 +053079 return -EINVAL;
Harald Weltee285bad2009-12-16 11:57:48 +010080 }
81 if (arfcn > min_arfcn + 111) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +010082 LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
Harald Weltea54a2bb2009-12-01 18:04:30 +053083 return -EINVAL;
Harald Weltee285bad2009-12-16 11:57:48 +010084 }
Harald Weltea54a2bb2009-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 Freyther7eb8a9a2011-04-18 17:04:00 +020096static int bitvec2freq_list(uint8_t *chan_list, struct bitvec *bv,
Harald Welte6ae64672009-12-14 22:07:14 +010097 const struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +053098{
Sylvain Munaut40f84a92009-12-24 14:20:19 +010099 int i, rc, min = 1024, max = -1;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530100
101 memset(chan_list, 0, 16);
102
Harald Weltea680b132012-02-17 15:58:23 +0100103 /* P-GSM-only handsets only support 'bit map 0 format' */
104 if (bts->band == GSM_BAND_900
105 && bts->c0->arfcn >= 1 && bts->c0->arfcn <= 124) {
Harald Weltea54a2bb2009-12-01 18:04:30 +0530106 chan_list[0] = 0;
Harald Welte6ae64672009-12-14 22:07:14 +0100107
108 for (i = 0; i < bv->data_len*8; i++) {
109 if (bitvec_get_bit_pos(bv, i)) {
110 rc = freq_list_bm0_set_arfcn(chan_list, i);
111 if (rc < 0)
112 return rc;
113 }
Harald Weltea54a2bb2009-12-01 18:04:30 +0530114 }
115 return 0;
116 }
117
118 /* We currently only support the 'Variable bitmap format' */
119 chan_list[0] = 0x8e;
120
Harald Welte6ae64672009-12-14 22:07:14 +0100121 for (i = 0; i < bv->data_len*8; i++) {
122 if (bitvec_get_bit_pos(bv, i)) {
123 if (i < min)
124 min = i;
125 if (i > max)
126 max = i;
127 }
Harald Weltea54a2bb2009-12-01 18:04:30 +0530128 }
129
Sylvain Munaut40f84a92009-12-24 14:20:19 +0100130 if (max == -1) {
131 /* Empty set, use 'bit map 0 format' */
132 chan_list[0] = 0;
133 return 0;
134 }
135
Harald Weltee285bad2009-12-16 11:57:48 +0100136 if ((max - min) > 111) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100137 LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, "
138 "distance > 111\n", min, max);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530139 return -EINVAL;
Harald Weltee285bad2009-12-16 11:57:48 +0100140 }
Harald Weltea54a2bb2009-12-01 18:04:30 +0530141
142 chan_list[0] |= (min >> 9) & 1;
143 chan_list[1] = (min >> 1);
144 chan_list[2] = (min & 1) << 7;
145
Harald Welte6ae64672009-12-14 22:07:14 +0100146 for (i = 0; i < bv->data_len*8; i++) {
Harald Weltee285bad2009-12-16 11:57:48 +0100147 if (bitvec_get_bit_pos(bv, i)) {
148 rc = freq_list_bmrel_set_arfcn(chan_list, i);
149 if (rc < 0)
150 return rc;
151 }
Harald Weltea54a2bb2009-12-01 18:04:30 +0530152 }
153
154 return 0;
155}
156
157/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Dieter Spaar49c843e2011-07-28 00:01:50 +0200158/* static*/ int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530159{
Harald Weltea54a2bb2009-12-01 18:04:30 +0530160 struct gsm_bts_trx *trx;
Harald Welte6ae64672009-12-14 22:07:14 +0100161 struct bitvec *bv = &bts->si_common.cell_alloc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530162
Harald Weltea42a93f2010-06-14 22:26:10 +0200163 /* Zero-initialize the bit-vector */
Harald Welte439e4622010-06-16 11:09:18 +0200164 memset(bv->data, 0, bv->data_len);
Harald Weltea42a93f2010-06-14 22:26:10 +0200165
Harald Welte6ae64672009-12-14 22:07:14 +0100166 /* first we generate a bitvec of all TRX ARFCN's in our BTS */
Harald Weltea42a93f2010-06-14 22:26:10 +0200167 llist_for_each_entry(trx, &bts->trx_list, list) {
168 unsigned int i, j;
169 /* Always add the TRX's ARFCN */
Harald Welte6ae64672009-12-14 22:07:14 +0100170 bitvec_set_bit_pos(bv, trx->arfcn, 1);
Harald Weltea42a93f2010-06-14 22:26:10 +0200171 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
172 struct gsm_bts_trx_ts *ts = &trx->ts[i];
173 /* Add any ARFCNs present in hopping channels */
174 for (j = 0; j < 1024; j++) {
175 if (bitvec_get_bit_pos(&ts->hopping.arfcns, j))
176 bitvec_set_bit_pos(bv, j, 1);
177 }
178 }
179 }
Harald Weltea54a2bb2009-12-01 18:04:30 +0530180
Harald Welte6ae64672009-12-14 22:07:14 +0100181 /* then we generate a GSM 04.08 frequency list from the bitvec */
182 return bitvec2freq_list(chan_list, bv, bts);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530183}
184
Harald Welte6ae64672009-12-14 22:07:14 +0100185/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200186static int generate_bcch_chan_list(uint8_t *chan_list, struct gsm_bts *bts, int si5)
Harald Welte6ae64672009-12-14 22:07:14 +0100187{
188 struct gsm_bts *cur_bts;
Harald Weltef989b782011-02-15 11:43:27 +0100189 struct bitvec *bv;
190
191 if (si5 && bts->neigh_list_manual_mode == NL_MODE_MANUAL_SI5SEP)
192 bv = &bts->si_common.si5_neigh_list;
193 else
194 bv = &bts->si_common.neigh_list;
Harald Welte6ae64672009-12-14 22:07:14 +0100195
Harald Welteca46eff2011-01-11 23:44:56 +0100196 /* Generate list of neighbor cells if we are in automatic mode */
Harald Weltef989b782011-02-15 11:43:27 +0100197 if (bts->neigh_list_manual_mode == NL_MODE_AUTOMATIC) {
Harald Weltea72d91c2011-02-19 20:43:37 +0100198 /* Zero-initialize the bit-vector */
199 memset(bv->data, 0, bv->data_len);
200
Harald Welteca46eff2011-01-11 23:44:56 +0100201 /* first we generate a bitvec of the BCCH ARFCN's in our BSC */
202 llist_for_each_entry(cur_bts, &bts->network->bts_list, list) {
203 if (cur_bts == bts)
204 continue;
205 bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1);
206 }
Harald Welte6ae64672009-12-14 22:07:14 +0100207 }
208
209 /* then we generate a GSM 04.08 frequency list from the bitvec */
210 return bitvec2freq_list(chan_list, bv, bts);
211}
212
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200213static int generate_si1(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530214{
215 int rc;
216 struct gsm48_system_information_type_1 *si1 =
217 (struct gsm48_system_information_type_1 *) output;
218
219 memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
220
221 si1->header.l2_plen = (21 << 2) | 1;
222 si1->header.rr_protocol_discriminator = GSM48_PDISC_RR;
223 si1->header.skip_indicator = 0;
224 si1->header.system_information = GSM48_MT_RR_SYSINFO_1;
225
226 rc = generate_cell_chan_list(si1->cell_channel_description, bts);
227 if (rc < 0)
228 return rc;
229
230 si1->rach_control = bts->si_common.rach_control;
231
232 /* SI1 Rest Octets (10.5.2.32), contains NCH position */
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100233 rc = rest_octets_si1(si1->rest_octets, NULL);
Harald Welte99bed522010-06-15 16:44:12 +0200234
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100235 return sizeof(*si1) + rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530236}
237
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200238static int generate_si2(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530239{
240 int rc;
241 struct gsm48_system_information_type_2 *si2 =
242 (struct gsm48_system_information_type_2 *) output;
243
244 memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
245
246 si2->header.l2_plen = (22 << 2) | 1;
247 si2->header.rr_protocol_discriminator = GSM48_PDISC_RR;
248 si2->header.skip_indicator = 0;
249 si2->header.system_information = GSM48_MT_RR_SYSINFO_2;
250
Harald Weltef989b782011-02-15 11:43:27 +0100251 rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts, 0);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530252 if (rc < 0)
253 return rc;
254
255 si2->ncc_permitted = bts->si_common.ncc_permitted;
256 si2->rach_control = bts->si_common.rach_control;
257
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100258 return sizeof(*si2);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530259}
260
Harald Weltee0500102010-03-14 23:46:48 +0800261static struct gsm48_si_ro_info si_info = {
Harald Weltea54a2bb2009-12-01 18:04:30 +0530262 .selection_params = {
263 .present = 0,
264 },
265 .power_offset = {
266 .present = 0,
267 },
268 .si2ter_indicator = 0,
269 .early_cm_ctrl = 1,
270 .scheduling = {
271 .present = 0,
272 },
273 .gprs_ind = {
274 .si13_position = 0,
275 .ra_colour = 0,
Harald Welte3055e332010-03-14 15:37:43 +0800276 .present = 1,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530277 },
278 .lsa_params = {
279 .present = 0,
280 },
281 .cell_id = 0, /* FIXME: doesn't the bts have this? */
282 .break_ind = 0,
283};
284
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200285static int generate_si3(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530286{
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100287 int rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530288 struct gsm48_system_information_type_3 *si3 =
289 (struct gsm48_system_information_type_3 *) output;
290
291 memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
292
293 si3->header.l2_plen = (18 << 2) | 1;
294 si3->header.rr_protocol_discriminator = GSM48_PDISC_RR;
295 si3->header.skip_indicator = 0;
296 si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
297
298 si3->cell_identity = htons(bts->cell_identity);
Harald Welted8493ac2010-03-04 10:55:40 +0100299 gsm48_generate_lai(&si3->lai, bts->network->country_code,
300 bts->network->network_code,
301 bts->location_area_code);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530302 si3->control_channel_desc = bts->si_common.chan_desc;
303 si3->cell_options = bts->si_common.cell_options;
304 si3->cell_sel_par = bts->si_common.cell_sel_par;
305 si3->rach_control = bts->si_common.rach_control;
306
307 /* SI3 Rest Octets (10.5.2.34), containing
308 CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME
309 Power Offset, 2ter Indicator, Early Classmark Sending,
310 Scheduling if and WHERE, GPRS Indicator, SI13 position */
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100311 rc = rest_octets_si3(si3->rest_octets, &si_info);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530312
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100313 return sizeof(*si3) + rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530314}
315
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200316static int generate_si4(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530317{
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100318 int rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530319 struct gsm48_system_information_type_4 *si4 =
320 (struct gsm48_system_information_type_4 *) output;
321
322 /* length of all IEs present except SI4 rest octets and l2_plen */
323 int l2_plen = sizeof(*si4) - 1;
324
325 memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
326
327 si4->header.rr_protocol_discriminator = GSM48_PDISC_RR;
328 si4->header.skip_indicator = 0;
329 si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
330
Harald Welted8493ac2010-03-04 10:55:40 +0100331 gsm48_generate_lai(&si4->lai, bts->network->country_code,
332 bts->network->network_code,
333 bts->location_area_code);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530334 si4->cell_sel_par = bts->si_common.cell_sel_par;
335 si4->rach_control = bts->si_common.rach_control;
336
337 /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
338
339 si4->header.l2_plen = (l2_plen << 2) | 1;
340
341 /* SI4 Rest Octets (10.5.2.35), containing
342 Optional Power offset, GPRS Indicator,
343 Cell Identity, LSA ID, Selection Parameter */
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100344 rc = rest_octets_si4(si4->data, &si_info);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530345
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100346 return sizeof(*si4) + rc;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530347}
348
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200349static int generate_si5(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530350{
Harald Welte2a92a712009-12-19 21:26:54 +0100351 struct gsm48_system_information_type_5 *si5;
352 int rc, l2_plen = 18;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530353
Holger Hans Peter Freyther4f2ace42010-01-06 07:52:55 +0100354 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
355
Harald Welte2a92a712009-12-19 21:26:54 +0100356 /* ip.access nanoBTS needs l2_plen!! */
Harald Welte08011e22011-03-04 13:41:31 +0100357 switch (bts->type) {
358 case GSM_BTS_TYPE_NANOBTS:
359 case GSM_BTS_TYPE_HSL_FEMTO:
Harald Welte2a92a712009-12-19 21:26:54 +0100360 *output++ = (l2_plen << 2) | 1;
361 l2_plen++;
Harald Welte08011e22011-03-04 13:41:31 +0100362 break;
363 default:
364 break;
Harald Welte2a92a712009-12-19 21:26:54 +0100365 }
366
367 si5 = (struct gsm48_system_information_type_5 *) output;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530368
369 /* l2 pseudo length, not part of msg: 18 */
370 si5->rr_protocol_discriminator = GSM48_PDISC_RR;
371 si5->skip_indicator = 0;
372 si5->system_information = GSM48_MT_RR_SYSINFO_5;
Harald Weltef989b782011-02-15 11:43:27 +0100373 rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts, 1);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530374 if (rc < 0)
375 return rc;
376
377 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
Harald Welte2a92a712009-12-19 21:26:54 +0100378 return l2_plen;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530379}
380
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200381static int generate_si6(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530382{
Harald Welte2a92a712009-12-19 21:26:54 +0100383 struct gsm48_system_information_type_6 *si6;
384 int l2_plen = 11;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530385
Holger Hans Peter Freyther4f2ace42010-01-06 07:52:55 +0100386 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
387
Harald Welte2a92a712009-12-19 21:26:54 +0100388 /* ip.access nanoBTS needs l2_plen!! */
Harald Welte08011e22011-03-04 13:41:31 +0100389 switch (bts->type) {
390 case GSM_BTS_TYPE_NANOBTS:
391 case GSM_BTS_TYPE_HSL_FEMTO:
Harald Welte2a92a712009-12-19 21:26:54 +0100392 *output++ = (l2_plen << 2) | 1;
393 l2_plen++;
Harald Welte08011e22011-03-04 13:41:31 +0100394 break;
395 default:
396 break;
Harald Welte2a92a712009-12-19 21:26:54 +0100397 }
398
399 si6 = (struct gsm48_system_information_type_6 *) output;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530400
401 /* l2 pseudo length, not part of msg: 11 */
402 si6->rr_protocol_discriminator = GSM48_PDISC_RR;
403 si6->skip_indicator = 0;
404 si6->system_information = GSM48_MT_RR_SYSINFO_6;
405 si6->cell_identity = htons(bts->cell_identity);
Harald Welted8493ac2010-03-04 10:55:40 +0100406 gsm48_generate_lai(&si6->lai, bts->network->country_code,
407 bts->network->network_code,
408 bts->location_area_code);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530409 si6->cell_options = bts->si_common.cell_options;
410 si6->ncc_permitted = bts->si_common.ncc_permitted;
411
412 /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */
413
Harald Welte2a92a712009-12-19 21:26:54 +0100414 return l2_plen;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530415}
416
417static struct gsm48_si13_info si13_default = {
418 .cell_opts = {
Harald Welteb0644712010-06-02 12:19:21 +0200419 .nmo = GPRS_NMO_II,
Harald Weltea9713bf2010-05-31 12:54:23 +0200420 .t3168 = 2000,
421 .t3192 = 200,
Harald Welte3055e332010-03-14 15:37:43 +0800422 .drx_timer_max = 3,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530423 .bs_cv_max = 15,
Sylvain Munaut1fa52392011-10-17 13:56:02 +0200424 .ext_info_present = 0,
Harald Welte3ce9a0d2010-04-18 14:49:05 +0200425 .ext_info = {
426 /* The values below are just guesses ! */
Harald Welte09faa062010-04-18 15:53:40 +0200427 .egprs_supported = 0,
Harald Welte3ce9a0d2010-04-18 14:49:05 +0200428 .use_egprs_p_ch_req = 1,
Harald Weltea9713bf2010-05-31 12:54:23 +0200429 .bep_period = 5,
Harald Welte3ce9a0d2010-04-18 14:49:05 +0200430 .pfc_supported = 0,
431 .dtm_supported = 0,
432 .bss_paging_coordination = 0,
433 },
Harald Weltea54a2bb2009-12-01 18:04:30 +0530434 },
435 .pwr_ctrl_pars = {
436 .alpha = 10, /* a = 1.0 */
Harald Weltea9713bf2010-05-31 12:54:23 +0200437 .t_avg_w = 16,
438 .t_avg_t = 16,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530439 .pc_meas_chan = 0, /* downling measured on CCCH */
Harald Weltea9713bf2010-05-31 12:54:23 +0200440 .n_avg_i = 8,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530441 },
Harald Welte3055e332010-03-14 15:37:43 +0800442 .bcch_change_mark = 1,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530443 .si_change_field = 0,
444 .pbcch_present = 0,
445 {
446 .no_pbcch = {
Harald Welte3055e332010-03-14 15:37:43 +0800447 .rac = 0, /* needs to be patched */
Harald Weltea54a2bb2009-12-01 18:04:30 +0530448 .spgc_ccch_sup = 0,
449 .net_ctrl_ord = 0,
Harald Welte3055e332010-03-14 15:37:43 +0800450 .prio_acc_thr = 6,
Harald Weltea54a2bb2009-12-01 18:04:30 +0530451 },
452 },
453};
454
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +0200455static int generate_si13(uint8_t *output, struct gsm_bts *bts)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530456{
457 struct gsm48_system_information_type_13 *si13 =
458 (struct gsm48_system_information_type_13 *) output;
459 int ret;
460
461 memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
462
463 si13->header.rr_protocol_discriminator = GSM48_PDISC_RR;
464 si13->header.skip_indicator = 0;
465 si13->header.system_information = GSM48_MT_RR_SYSINFO_13;
466
Harald Welte3055e332010-03-14 15:37:43 +0800467 si13_default.no_pbcch.rac = bts->gprs.rac;
468
Harald Weltea54a2bb2009-12-01 18:04:30 +0530469 ret = rest_octets_si13(si13->rest_octets, &si13_default);
470 if (ret < 0)
471 return ret;
472
Holger Hans Peter Freyther6c84d702010-06-16 12:05:56 +0800473 /* length is coded in bit 2 an up */
474 si13->header.l2_plen = 0x01;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530475
Holger Hans Peter Freyther02c608c2010-01-06 07:52:31 +0100476 return sizeof (*si13) + ret;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530477}
478
Harald Welte99bed522010-06-15 16:44:12 +0200479typedef int (*gen_si_fn_t)(uint8_t *output, struct gsm_bts *bts);
480
481static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = {
482 [SYSINFO_TYPE_1] = &generate_si1,
483 [SYSINFO_TYPE_2] = &generate_si2,
484 [SYSINFO_TYPE_3] = &generate_si3,
485 [SYSINFO_TYPE_4] = &generate_si4,
486 [SYSINFO_TYPE_5] = &generate_si5,
487 [SYSINFO_TYPE_6] = &generate_si6,
488 [SYSINFO_TYPE_13] = &generate_si13,
489};
490
Harald Welte99bed522010-06-15 16:44:12 +0200491int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
492{
493 gen_si_fn_t gen_si;
494
Harald Weltecb20b7a2010-04-18 15:51:20 +0200495 switch (bts->gprs.mode) {
496 case BTS_GPRS_EGPRS:
Harald Welte09faa062010-04-18 15:53:40 +0200497 si13_default.cell_opts.ext_info_present = 1;
498 si13_default.cell_opts.ext_info.egprs_supported = 1;
499 /* fallthrough */
Harald Weltecb20b7a2010-04-18 15:51:20 +0200500 case BTS_GPRS_GPRS:
501 si_info.gprs_ind.present = 1;
502 break;
503 case BTS_GPRS_NONE:
504 si_info.gprs_ind.present = 0;
505 break;
506 }
Harald Weltee0500102010-03-14 23:46:48 +0800507
Sylvain Munaut00d71462010-11-28 18:17:28 +0100508 memcpy(&si_info.selection_params,
509 &bts->si_common.cell_ro_sel_par,
510 sizeof(struct gsm48_si_selection_params));
511
Harald Welte99bed522010-06-15 16:44:12 +0200512 gen_si = gen_si_fn[si_type];
513 if (!gen_si)
Harald Weltea54a2bb2009-12-01 18:04:30 +0530514 return -EINVAL;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530515
Harald Welte99bed522010-06-15 16:44:12 +0200516 return gen_si(bts->si_buf[si_type], bts);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530517}