blob: 0cae7168754c7a6a549ed1a710dfd01efe9e8b17 [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 <sys/types.h>
27#include <netinet/in.h>
28
29#include <openbsc/gsm_04_08.h>
30#include <openbsc/gsm_data.h>
31#include <openbsc/abis_rsl.h>
32#include <openbsc/rest_octets.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/bitvec.h>
34#include <osmocom/core/utils.h>
Harald Welte152b6262009-12-16 11:57:48 +010035#include <openbsc/debug.h>
Harald Weltea43f7892009-12-01 18:04:30 +053036
37#define GSM48_CELL_CHAN_DESC_SIZE 16
Harald Weltea43f7892009-12-01 18:04:30 +053038#define GSM_MACBLOCK_PADDING 0x2b
39
Holger Hans Peter Freytherb91a1062010-01-06 06:38:14 +010040/* verify the sizes of the system information type structs */
41
42/* rest octets are not part of the struct */
43static_assert(sizeof(struct gsm48_system_information_type_header) == 3, _si_header_size);
44static_assert(sizeof(struct gsm48_rach_control) == 3, _si_rach_control);
45static_assert(sizeof(struct gsm48_system_information_type_1) == 22, _si1_size);
46static_assert(sizeof(struct gsm48_system_information_type_2) == 23, _si2_size);
47static_assert(sizeof(struct gsm48_system_information_type_3) == 19, _si3_size);
48static_assert(sizeof(struct gsm48_system_information_type_4) == 13, _si4_size);
49
50/* bs11 forgot the l2 len, 0-6 rest octets */
51static_assert(sizeof(struct gsm48_system_information_type_5) == 18, _si5_size);
52static_assert(sizeof(struct gsm48_system_information_type_6) == 11, _si6_size);
53
54static_assert(sizeof(struct gsm48_system_information_type_13) == 3, _si13_size);
55
Harald Welteda760d32009-12-14 20:25:05 +010056/* Frequency Lists as per TS 04.08 10.5.2.13 */
57
58/* 10.5.2.13.2: Bit map 0 format */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020059static int freq_list_bm0_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +053060{
61 unsigned int byte, bit;
62
Harald Welteb1d4c8e2009-12-17 23:10:46 +010063 if (arfcn > 124 || arfcn < 1) {
64 LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n");
Harald Weltea43f7892009-12-01 18:04:30 +053065 return -EINVAL;
Harald Welteb1d4c8e2009-12-17 23:10:46 +010066 }
Harald Weltea43f7892009-12-01 18:04:30 +053067
Harald Welteda760d32009-12-14 20:25:05 +010068 /* the bitmask is from 1..124, not from 0..123 */
69 arfcn--;
70
Harald Weltea43f7892009-12-01 18:04:30 +053071 byte = arfcn / 8;
72 bit = arfcn % 8;
73
Harald Welteda760d32009-12-14 20:25:05 +010074 chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit);
Harald Weltea43f7892009-12-01 18:04:30 +053075
76 return 0;
77}
78
Harald Welteda760d32009-12-14 20:25:05 +010079/* 10.5.2.13.7: Variable bit map format */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020080static int freq_list_bmrel_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +053081{
82 unsigned int byte, bit;
83 unsigned int min_arfcn;
84 unsigned int bitno;
85
86 min_arfcn = (chan_list[0] & 1) << 9;
87 min_arfcn |= chan_list[1] << 1;
88 min_arfcn |= (chan_list[2] >> 7) & 1;
89
90 /* The lower end of our bitmaks is always implicitly included */
91 if (arfcn == min_arfcn)
92 return 0;
93
Harald Welte152b6262009-12-16 11:57:48 +010094 if (arfcn < min_arfcn) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +010095 LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +053096 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +010097 }
98 if (arfcn > min_arfcn + 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +010099 LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +0530100 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +0100101 }
Harald Weltea43f7892009-12-01 18:04:30 +0530102
103 bitno = (arfcn - min_arfcn);
104 byte = bitno / 8;
105 bit = bitno % 8;
106
107 chan_list[2 + byte] |= 1 << (7 - bit);
108
109 return 0;
110}
111
112/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200113static int bitvec2freq_list(uint8_t *chan_list, struct bitvec *bv,
Harald Welte6c40def2009-12-14 22:07:14 +0100114 const struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530115{
Sylvain Munaut42a56522009-12-24 14:20:19 +0100116 int i, rc, min = 1024, max = -1;
Harald Weltea43f7892009-12-01 18:04:30 +0530117
118 memset(chan_list, 0, 16);
119
120 /* GSM900-only handsets only support 'bit map 0 format' */
121 if (bts->band == GSM_BAND_900) {
122 chan_list[0] = 0;
Harald Welte6c40def2009-12-14 22:07:14 +0100123
124 for (i = 0; i < bv->data_len*8; i++) {
125 if (bitvec_get_bit_pos(bv, i)) {
126 rc = freq_list_bm0_set_arfcn(chan_list, i);
127 if (rc < 0)
128 return rc;
129 }
Harald Weltea43f7892009-12-01 18:04:30 +0530130 }
131 return 0;
132 }
133
134 /* We currently only support the 'Variable bitmap format' */
135 chan_list[0] = 0x8e;
136
Harald Welte6c40def2009-12-14 22:07:14 +0100137 for (i = 0; i < bv->data_len*8; i++) {
138 if (bitvec_get_bit_pos(bv, i)) {
139 if (i < min)
140 min = i;
141 if (i > max)
142 max = i;
143 }
Harald Weltea43f7892009-12-01 18:04:30 +0530144 }
145
Sylvain Munaut42a56522009-12-24 14:20:19 +0100146 if (max == -1) {
147 /* Empty set, use 'bit map 0 format' */
148 chan_list[0] = 0;
149 return 0;
150 }
151
Harald Welte152b6262009-12-16 11:57:48 +0100152 if ((max - min) > 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100153 LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, "
154 "distance > 111\n", min, max);
Harald Weltea43f7892009-12-01 18:04:30 +0530155 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +0100156 }
Harald Weltea43f7892009-12-01 18:04:30 +0530157
158 chan_list[0] |= (min >> 9) & 1;
159 chan_list[1] = (min >> 1);
160 chan_list[2] = (min & 1) << 7;
161
Harald Welte6c40def2009-12-14 22:07:14 +0100162 for (i = 0; i < bv->data_len*8; i++) {
Harald Welte152b6262009-12-16 11:57:48 +0100163 if (bitvec_get_bit_pos(bv, i)) {
164 rc = freq_list_bmrel_set_arfcn(chan_list, i);
165 if (rc < 0)
166 return rc;
167 }
Harald Weltea43f7892009-12-01 18:04:30 +0530168 }
169
170 return 0;
171}
172
173/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200174static int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530175{
Harald Weltea43f7892009-12-01 18:04:30 +0530176 struct gsm_bts_trx *trx;
Harald Welte6c40def2009-12-14 22:07:14 +0100177 struct bitvec *bv = &bts->si_common.cell_alloc;
Harald Weltea43f7892009-12-01 18:04:30 +0530178
Harald Weltea39b0f22010-06-14 22:26:10 +0200179 /* Zero-initialize the bit-vector */
Harald Weltec8794b52010-06-16 11:09:18 +0200180 memset(bv->data, 0, bv->data_len);
Harald Weltea39b0f22010-06-14 22:26:10 +0200181
Harald Welte6c40def2009-12-14 22:07:14 +0100182 /* first we generate a bitvec of all TRX ARFCN's in our BTS */
Harald Weltea39b0f22010-06-14 22:26:10 +0200183 llist_for_each_entry(trx, &bts->trx_list, list) {
184 unsigned int i, j;
185 /* Always add the TRX's ARFCN */
Harald Welte6c40def2009-12-14 22:07:14 +0100186 bitvec_set_bit_pos(bv, trx->arfcn, 1);
Harald Weltea39b0f22010-06-14 22:26:10 +0200187 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
188 struct gsm_bts_trx_ts *ts = &trx->ts[i];
189 /* Add any ARFCNs present in hopping channels */
190 for (j = 0; j < 1024; j++) {
191 if (bitvec_get_bit_pos(&ts->hopping.arfcns, j))
192 bitvec_set_bit_pos(bv, j, 1);
193 }
194 }
195 }
Harald Weltea43f7892009-12-01 18:04:30 +0530196
Harald Welte6c40def2009-12-14 22:07:14 +0100197 /* then we generate a GSM 04.08 frequency list from the bitvec */
198 return bitvec2freq_list(chan_list, bv, bts);
Harald Weltea43f7892009-12-01 18:04:30 +0530199}
200
Harald Welte6c40def2009-12-14 22:07:14 +0100201/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200202static int generate_bcch_chan_list(uint8_t *chan_list, struct gsm_bts *bts, int si5)
Harald Welte6c40def2009-12-14 22:07:14 +0100203{
204 struct gsm_bts *cur_bts;
Harald Welte64c07d22011-02-15 11:43:27 +0100205 struct bitvec *bv;
206
207 if (si5 && bts->neigh_list_manual_mode == NL_MODE_MANUAL_SI5SEP)
208 bv = &bts->si_common.si5_neigh_list;
209 else
210 bv = &bts->si_common.neigh_list;
Harald Welte6c40def2009-12-14 22:07:14 +0100211
Harald Welte32c09622011-01-11 23:44:56 +0100212 /* Generate list of neighbor cells if we are in automatic mode */
Harald Welte64c07d22011-02-15 11:43:27 +0100213 if (bts->neigh_list_manual_mode == NL_MODE_AUTOMATIC) {
Harald Welte21bbda22011-02-19 20:43:37 +0100214 /* Zero-initialize the bit-vector */
215 memset(bv->data, 0, bv->data_len);
216
Harald Welte32c09622011-01-11 23:44:56 +0100217 /* first we generate a bitvec of the BCCH ARFCN's in our BSC */
218 llist_for_each_entry(cur_bts, &bts->network->bts_list, list) {
219 if (cur_bts == bts)
220 continue;
221 bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1);
222 }
Harald Welte6c40def2009-12-14 22:07:14 +0100223 }
224
225 /* then we generate a GSM 04.08 frequency list from the bitvec */
226 return bitvec2freq_list(chan_list, bv, bts);
227}
228
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200229static int generate_si1(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530230{
231 int rc;
232 struct gsm48_system_information_type_1 *si1 =
233 (struct gsm48_system_information_type_1 *) output;
234
235 memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
236
237 si1->header.l2_plen = (21 << 2) | 1;
238 si1->header.rr_protocol_discriminator = GSM48_PDISC_RR;
239 si1->header.skip_indicator = 0;
240 si1->header.system_information = GSM48_MT_RR_SYSINFO_1;
241
242 rc = generate_cell_chan_list(si1->cell_channel_description, bts);
243 if (rc < 0)
244 return rc;
245
246 si1->rach_control = bts->si_common.rach_control;
247
248 /* SI1 Rest Octets (10.5.2.32), contains NCH position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100249 rc = rest_octets_si1(si1->rest_octets, NULL);
Harald Welte7401ae62010-06-15 16:44:12 +0200250
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100251 return sizeof(*si1) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530252}
253
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200254static int generate_si2(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530255{
256 int rc;
257 struct gsm48_system_information_type_2 *si2 =
258 (struct gsm48_system_information_type_2 *) output;
259
260 memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
261
262 si2->header.l2_plen = (22 << 2) | 1;
263 si2->header.rr_protocol_discriminator = GSM48_PDISC_RR;
264 si2->header.skip_indicator = 0;
265 si2->header.system_information = GSM48_MT_RR_SYSINFO_2;
266
Harald Welte64c07d22011-02-15 11:43:27 +0100267 rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts, 0);
Harald Weltea43f7892009-12-01 18:04:30 +0530268 if (rc < 0)
269 return rc;
270
271 si2->ncc_permitted = bts->si_common.ncc_permitted;
272 si2->rach_control = bts->si_common.rach_control;
273
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100274 return sizeof(*si2);
Harald Weltea43f7892009-12-01 18:04:30 +0530275}
276
Harald Welte1f893292010-03-14 23:46:48 +0800277static struct gsm48_si_ro_info si_info = {
Harald Weltea43f7892009-12-01 18:04:30 +0530278 .selection_params = {
279 .present = 0,
280 },
281 .power_offset = {
282 .present = 0,
283 },
284 .si2ter_indicator = 0,
285 .early_cm_ctrl = 1,
286 .scheduling = {
287 .present = 0,
288 },
289 .gprs_ind = {
290 .si13_position = 0,
291 .ra_colour = 0,
Harald Welte97a282b2010-03-14 15:37:43 +0800292 .present = 1,
Harald Weltea43f7892009-12-01 18:04:30 +0530293 },
294 .lsa_params = {
295 .present = 0,
296 },
297 .cell_id = 0, /* FIXME: doesn't the bts have this? */
298 .break_ind = 0,
299};
300
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200301static int generate_si3(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530302{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100303 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530304 struct gsm48_system_information_type_3 *si3 =
305 (struct gsm48_system_information_type_3 *) output;
306
307 memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
308
309 si3->header.l2_plen = (18 << 2) | 1;
310 si3->header.rr_protocol_discriminator = GSM48_PDISC_RR;
311 si3->header.skip_indicator = 0;
312 si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
313
314 si3->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +0100315 gsm48_generate_lai(&si3->lai, bts->network->country_code,
316 bts->network->network_code,
317 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530318 si3->control_channel_desc = bts->si_common.chan_desc;
319 si3->cell_options = bts->si_common.cell_options;
320 si3->cell_sel_par = bts->si_common.cell_sel_par;
321 si3->rach_control = bts->si_common.rach_control;
322
323 /* SI3 Rest Octets (10.5.2.34), containing
324 CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME
325 Power Offset, 2ter Indicator, Early Classmark Sending,
326 Scheduling if and WHERE, GPRS Indicator, SI13 position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100327 rc = rest_octets_si3(si3->rest_octets, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530328
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100329 return sizeof(*si3) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530330}
331
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200332static int generate_si4(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530333{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100334 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530335 struct gsm48_system_information_type_4 *si4 =
336 (struct gsm48_system_information_type_4 *) output;
337
338 /* length of all IEs present except SI4 rest octets and l2_plen */
339 int l2_plen = sizeof(*si4) - 1;
340
341 memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
342
343 si4->header.rr_protocol_discriminator = GSM48_PDISC_RR;
344 si4->header.skip_indicator = 0;
345 si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
346
Harald Welteafedeab2010-03-04 10:55:40 +0100347 gsm48_generate_lai(&si4->lai, bts->network->country_code,
348 bts->network->network_code,
349 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530350 si4->cell_sel_par = bts->si_common.cell_sel_par;
351 si4->rach_control = bts->si_common.rach_control;
352
353 /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
354
355 si4->header.l2_plen = (l2_plen << 2) | 1;
356
357 /* SI4 Rest Octets (10.5.2.35), containing
358 Optional Power offset, GPRS Indicator,
359 Cell Identity, LSA ID, Selection Parameter */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100360 rc = rest_octets_si4(si4->data, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530361
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100362 return sizeof(*si4) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530363}
364
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200365static int generate_si5(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530366{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100367 struct gsm48_system_information_type_5 *si5;
368 int rc, l2_plen = 18;
Harald Weltea43f7892009-12-01 18:04:30 +0530369
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100370 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
371
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100372 /* ip.access nanoBTS needs l2_plen!! */
Harald Weltefd355a32011-03-04 13:41:31 +0100373 switch (bts->type) {
374 case GSM_BTS_TYPE_NANOBTS:
375 case GSM_BTS_TYPE_HSL_FEMTO:
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100376 *output++ = (l2_plen << 2) | 1;
377 l2_plen++;
Harald Weltefd355a32011-03-04 13:41:31 +0100378 break;
379 default:
380 break;
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100381 }
382
383 si5 = (struct gsm48_system_information_type_5 *) output;
Harald Weltea43f7892009-12-01 18:04:30 +0530384
385 /* l2 pseudo length, not part of msg: 18 */
386 si5->rr_protocol_discriminator = GSM48_PDISC_RR;
387 si5->skip_indicator = 0;
388 si5->system_information = GSM48_MT_RR_SYSINFO_5;
Harald Welte64c07d22011-02-15 11:43:27 +0100389 rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts, 1);
Harald Weltea43f7892009-12-01 18:04:30 +0530390 if (rc < 0)
391 return rc;
392
393 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100394 return l2_plen;
Harald Weltea43f7892009-12-01 18:04:30 +0530395}
396
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200397static int generate_si6(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530398{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100399 struct gsm48_system_information_type_6 *si6;
400 int l2_plen = 11;
Harald Weltea43f7892009-12-01 18:04:30 +0530401
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100402 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
403
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100404 /* ip.access nanoBTS needs l2_plen!! */
Harald Weltefd355a32011-03-04 13:41:31 +0100405 switch (bts->type) {
406 case GSM_BTS_TYPE_NANOBTS:
407 case GSM_BTS_TYPE_HSL_FEMTO:
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100408 *output++ = (l2_plen << 2) | 1;
409 l2_plen++;
Harald Weltefd355a32011-03-04 13:41:31 +0100410 break;
411 default:
412 break;
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100413 }
414
415 si6 = (struct gsm48_system_information_type_6 *) output;
Harald Weltea43f7892009-12-01 18:04:30 +0530416
417 /* l2 pseudo length, not part of msg: 11 */
418 si6->rr_protocol_discriminator = GSM48_PDISC_RR;
419 si6->skip_indicator = 0;
420 si6->system_information = GSM48_MT_RR_SYSINFO_6;
421 si6->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +0100422 gsm48_generate_lai(&si6->lai, bts->network->country_code,
423 bts->network->network_code,
424 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530425 si6->cell_options = bts->si_common.cell_options;
426 si6->ncc_permitted = bts->si_common.ncc_permitted;
427
428 /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */
429
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100430 return l2_plen;
Harald Weltea43f7892009-12-01 18:04:30 +0530431}
432
433static struct gsm48_si13_info si13_default = {
434 .cell_opts = {
Harald Welte85849182010-06-02 12:19:21 +0200435 .nmo = GPRS_NMO_II,
Harald Weltea4b16652010-05-31 12:54:23 +0200436 .t3168 = 2000,
437 .t3192 = 200,
Harald Welte97a282b2010-03-14 15:37:43 +0800438 .drx_timer_max = 3,
Harald Weltea43f7892009-12-01 18:04:30 +0530439 .bs_cv_max = 15,
Harald Weltea4b16652010-05-31 12:54:23 +0200440 .ext_info_present = 1,
Harald Welteda0586a2010-04-18 14:49:05 +0200441 .ext_info = {
442 /* The values below are just guesses ! */
Harald Weltea06fea02010-04-18 15:53:40 +0200443 .egprs_supported = 0,
Harald Welteda0586a2010-04-18 14:49:05 +0200444 .use_egprs_p_ch_req = 1,
Harald Weltea4b16652010-05-31 12:54:23 +0200445 .bep_period = 5,
Harald Welteda0586a2010-04-18 14:49:05 +0200446 .pfc_supported = 0,
447 .dtm_supported = 0,
448 .bss_paging_coordination = 0,
449 },
Harald Weltea43f7892009-12-01 18:04:30 +0530450 },
451 .pwr_ctrl_pars = {
452 .alpha = 10, /* a = 1.0 */
Harald Weltea4b16652010-05-31 12:54:23 +0200453 .t_avg_w = 16,
454 .t_avg_t = 16,
Harald Weltea43f7892009-12-01 18:04:30 +0530455 .pc_meas_chan = 0, /* downling measured on CCCH */
Harald Weltea4b16652010-05-31 12:54:23 +0200456 .n_avg_i = 8,
Harald Weltea43f7892009-12-01 18:04:30 +0530457 },
Harald Welte97a282b2010-03-14 15:37:43 +0800458 .bcch_change_mark = 1,
Harald Weltea43f7892009-12-01 18:04:30 +0530459 .si_change_field = 0,
460 .pbcch_present = 0,
461 {
462 .no_pbcch = {
Harald Welte97a282b2010-03-14 15:37:43 +0800463 .rac = 0, /* needs to be patched */
Harald Weltea43f7892009-12-01 18:04:30 +0530464 .spgc_ccch_sup = 0,
465 .net_ctrl_ord = 0,
Harald Welte97a282b2010-03-14 15:37:43 +0800466 .prio_acc_thr = 6,
Harald Weltea43f7892009-12-01 18:04:30 +0530467 },
468 },
469};
470
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200471static int generate_si13(uint8_t *output, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530472{
473 struct gsm48_system_information_type_13 *si13 =
474 (struct gsm48_system_information_type_13 *) output;
475 int ret;
476
477 memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
478
479 si13->header.rr_protocol_discriminator = GSM48_PDISC_RR;
480 si13->header.skip_indicator = 0;
481 si13->header.system_information = GSM48_MT_RR_SYSINFO_13;
482
Harald Welte97a282b2010-03-14 15:37:43 +0800483 si13_default.no_pbcch.rac = bts->gprs.rac;
484
Harald Weltea43f7892009-12-01 18:04:30 +0530485 ret = rest_octets_si13(si13->rest_octets, &si13_default);
486 if (ret < 0)
487 return ret;
488
Holger Hans Peter Freyther1c6f3942010-06-16 12:05:56 +0800489 /* length is coded in bit 2 an up */
490 si13->header.l2_plen = 0x01;
Harald Weltea43f7892009-12-01 18:04:30 +0530491
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100492 return sizeof (*si13) + ret;
Harald Weltea43f7892009-12-01 18:04:30 +0530493}
494
Harald Welte7401ae62010-06-15 16:44:12 +0200495static const uint8_t sitype2rsl[_MAX_SYSINFO_TYPE] = {
496 [SYSINFO_TYPE_1] = RSL_SYSTEM_INFO_1,
497 [SYSINFO_TYPE_2] = RSL_SYSTEM_INFO_2,
498 [SYSINFO_TYPE_3] = RSL_SYSTEM_INFO_3,
499 [SYSINFO_TYPE_4] = RSL_SYSTEM_INFO_4,
500 [SYSINFO_TYPE_5] = RSL_SYSTEM_INFO_5,
501 [SYSINFO_TYPE_6] = RSL_SYSTEM_INFO_6,
502 [SYSINFO_TYPE_7] = RSL_SYSTEM_INFO_7,
503 [SYSINFO_TYPE_8] = RSL_SYSTEM_INFO_8,
504 [SYSINFO_TYPE_9] = RSL_SYSTEM_INFO_9,
505 [SYSINFO_TYPE_10] = RSL_SYSTEM_INFO_10,
506 [SYSINFO_TYPE_13] = RSL_SYSTEM_INFO_13,
507 [SYSINFO_TYPE_16] = RSL_SYSTEM_INFO_16,
508 [SYSINFO_TYPE_17] = RSL_SYSTEM_INFO_17,
509 [SYSINFO_TYPE_18] = RSL_SYSTEM_INFO_18,
510 [SYSINFO_TYPE_19] = RSL_SYSTEM_INFO_19,
511 [SYSINFO_TYPE_20] = RSL_SYSTEM_INFO_20,
512 [SYSINFO_TYPE_2bis] = RSL_SYSTEM_INFO_2bis,
513 [SYSINFO_TYPE_2ter] = RSL_SYSTEM_INFO_2ter,
514 [SYSINFO_TYPE_2quater] = RSL_SYSTEM_INFO_2quater,
515 [SYSINFO_TYPE_5bis] = RSL_SYSTEM_INFO_5bis,
516 [SYSINFO_TYPE_5ter] = RSL_SYSTEM_INFO_5ter,
517};
518
519static const uint8_t rsl2sitype[0xff] = {
520 [RSL_SYSTEM_INFO_1] = SYSINFO_TYPE_1,
521 [RSL_SYSTEM_INFO_2] = SYSINFO_TYPE_2,
522 [RSL_SYSTEM_INFO_3] = SYSINFO_TYPE_3,
523 [RSL_SYSTEM_INFO_4] = SYSINFO_TYPE_4,
524 [RSL_SYSTEM_INFO_5] = SYSINFO_TYPE_5,
525 [RSL_SYSTEM_INFO_6] = SYSINFO_TYPE_6,
Harald Welte5f827f42010-07-30 11:11:38 +0200526 [RSL_SYSTEM_INFO_7] = SYSINFO_TYPE_7,
527 [RSL_SYSTEM_INFO_8] = SYSINFO_TYPE_8,
528 [RSL_SYSTEM_INFO_9] = SYSINFO_TYPE_9,
529 [RSL_SYSTEM_INFO_10] = SYSINFO_TYPE_10,
Harald Welte7401ae62010-06-15 16:44:12 +0200530 [RSL_SYSTEM_INFO_13] = SYSINFO_TYPE_13,
Harald Welte5f827f42010-07-30 11:11:38 +0200531 [RSL_SYSTEM_INFO_16] = SYSINFO_TYPE_16,
532 [RSL_SYSTEM_INFO_17] = SYSINFO_TYPE_17,
533 [RSL_SYSTEM_INFO_18] = SYSINFO_TYPE_18,
534 [RSL_SYSTEM_INFO_19] = SYSINFO_TYPE_19,
535 [RSL_SYSTEM_INFO_20] = SYSINFO_TYPE_20,
536 [RSL_SYSTEM_INFO_2bis] = SYSINFO_TYPE_2bis,
537 [RSL_SYSTEM_INFO_2ter] = SYSINFO_TYPE_2ter,
538 [RSL_SYSTEM_INFO_2quater] = SYSINFO_TYPE_2quater,
539 [RSL_SYSTEM_INFO_5bis] = SYSINFO_TYPE_5bis,
540 [RSL_SYSTEM_INFO_5ter] = SYSINFO_TYPE_5ter,
Harald Welte7401ae62010-06-15 16:44:12 +0200541};
542
543typedef int (*gen_si_fn_t)(uint8_t *output, struct gsm_bts *bts);
544
545static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = {
546 [SYSINFO_TYPE_1] = &generate_si1,
547 [SYSINFO_TYPE_2] = &generate_si2,
548 [SYSINFO_TYPE_3] = &generate_si3,
549 [SYSINFO_TYPE_4] = &generate_si4,
550 [SYSINFO_TYPE_5] = &generate_si5,
551 [SYSINFO_TYPE_6] = &generate_si6,
552 [SYSINFO_TYPE_13] = &generate_si13,
553};
554
Harald Welte5f827f42010-07-30 11:11:38 +0200555const struct value_string osmo_sitype_strs[_MAX_SYSINFO_TYPE] = {
Harald Welte7401ae62010-06-15 16:44:12 +0200556 { SYSINFO_TYPE_1, "1" },
557 { SYSINFO_TYPE_2, "2" },
558 { SYSINFO_TYPE_3, "3" },
559 { SYSINFO_TYPE_4, "4" },
560 { SYSINFO_TYPE_5, "5" },
561 { SYSINFO_TYPE_6, "6" },
562 { SYSINFO_TYPE_7, "7" },
563 { SYSINFO_TYPE_8, "8" },
564 { SYSINFO_TYPE_9, "9" },
565 { SYSINFO_TYPE_10, "10" },
566 { SYSINFO_TYPE_13, "13" },
567 { SYSINFO_TYPE_16, "16" },
568 { SYSINFO_TYPE_17, "17" },
569 { SYSINFO_TYPE_18, "18" },
570 { SYSINFO_TYPE_19, "19" },
571 { SYSINFO_TYPE_20, "20" },
572 { SYSINFO_TYPE_2bis, "2bis" },
573 { SYSINFO_TYPE_2ter, "2ter" },
574 { SYSINFO_TYPE_2quater, "2quater" },
575 { SYSINFO_TYPE_5bis, "5bis" },
576 { SYSINFO_TYPE_5ter, "5ter" },
577 { 0, NULL }
578};
579
580uint8_t gsm_sitype2rsl(enum osmo_sysinfo_type si_type)
Harald Weltea43f7892009-12-01 18:04:30 +0530581{
Harald Welte7401ae62010-06-15 16:44:12 +0200582 return sitype2rsl[si_type];
583}
584
585const char *gsm_sitype_name(enum osmo_sysinfo_type si_type)
586{
Harald Welte5f827f42010-07-30 11:11:38 +0200587 return get_value_string(osmo_sitype_strs, si_type);
Harald Welte7401ae62010-06-15 16:44:12 +0200588}
589
590int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
591{
592 gen_si_fn_t gen_si;
593
Harald Welte4511d892010-04-18 15:51:20 +0200594 switch (bts->gprs.mode) {
595 case BTS_GPRS_EGPRS:
Harald Weltea06fea02010-04-18 15:53:40 +0200596 si13_default.cell_opts.ext_info_present = 1;
597 si13_default.cell_opts.ext_info.egprs_supported = 1;
598 /* fallthrough */
Harald Welte4511d892010-04-18 15:51:20 +0200599 case BTS_GPRS_GPRS:
600 si_info.gprs_ind.present = 1;
601 break;
602 case BTS_GPRS_NONE:
603 si_info.gprs_ind.present = 0;
604 break;
605 }
Harald Welte1f893292010-03-14 23:46:48 +0800606
Sylvain Munaute0b06b02010-11-28 18:17:28 +0100607 memcpy(&si_info.selection_params,
608 &bts->si_common.cell_ro_sel_par,
609 sizeof(struct gsm48_si_selection_params));
610
Harald Welte7401ae62010-06-15 16:44:12 +0200611 gen_si = gen_si_fn[si_type];
612 if (!gen_si)
Harald Weltea43f7892009-12-01 18:04:30 +0530613 return -EINVAL;
Harald Weltea43f7892009-12-01 18:04:30 +0530614
Harald Welte7401ae62010-06-15 16:44:12 +0200615 return gen_si(bts->si_buf[si_type], bts);
Harald Weltea43f7892009-12-01 18:04:30 +0530616}