blob: 761e8482b6da458a40a8c392244f8db080ad8037 [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>
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +02005 * (C) 2012 Holger Hans Peter Freyther
Harald Weltea43f7892009-12-01 18:04:30 +05306 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Harald Weltea43f7892009-12-01 18:04:30 +053012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Harald Weltea43f7892009-12-01 18:04:30 +053018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Weltea43f7892009-12-01 18:04:30 +053021 *
22 */
23
24#include <errno.h>
25#include <string.h>
Harald Welte6c40def2009-12-14 22:07:14 +010026#include <stdio.h>
Harald Weltea43f7892009-12-01 18:04:30 +053027#include <netinet/in.h>
Max5fa7e362016-04-15 16:04:45 +020028#include <stdbool.h>
Harald Weltea43f7892009-12-01 18:04:30 +053029
Harald Welte80cffaf2011-05-24 15:02:20 +020030#include <osmocom/core/bitvec.h>
31#include <osmocom/core/utils.h>
32#include <osmocom/gsm/sysinfo.h>
Neels Hofmeyr7b656882017-07-09 22:09:18 +020033#include <osmocom/gsm/gsm48_ie.h>
34#include <osmocom/gsm/gsm48.h>
Harald Welte80cffaf2011-05-24 15:02:20 +020035
Neels Hofmeyrc0164792017-09-04 15:15:32 +020036#include <osmocom/bsc/debug.h>
37#include <osmocom/bsc/gsm_data.h>
38#include <osmocom/bsc/abis_rsl.h>
39#include <osmocom/bsc/rest_octets.h>
40#include <osmocom/bsc/arfcn_range_encode.h>
41#include <osmocom/bsc/gsm_04_08_utils.h>
Harald Weltea43f7892009-12-01 18:04:30 +053042
Holger Hans Peter Freytherd4d1d5e2013-01-17 13:49:39 +010043/*
44 * DCS1800 and PCS1900 have overlapping ARFCNs. We would need to set the
45 * ARFCN_PCS flag on the 1900 ARFCNs but this would increase cell_alloc
46 * and other arrays to make sure (ARFCN_PCS + 1024)/8 ARFCNs fit into the
47 * array. DCS1800 and PCS1900 can not be used at the same time so conserve
48 * memory and do the below.
49 */
50static int band_compatible(const struct gsm_bts *bts, int arfcn)
51{
52 enum gsm_band band = gsm_arfcn2band(arfcn);
53
54 /* normal case */
55 if (band == bts->band)
56 return 1;
57 /* deal with ARFCN_PCS not set */
58 if (band == GSM_BAND_1800 && bts->band == GSM_BAND_1900)
59 return 1;
60
61 return 0;
62}
Holger Hans Peter Freytherb91a1062010-01-06 06:38:14 +010063
Holger Hans Peter Freytherf876c392013-03-06 12:02:33 +010064static int is_dcs_net(const struct gsm_bts *bts)
65{
66 if (bts->band == GSM_BAND_850)
67 return 0;
68 if (bts->band == GSM_BAND_1900)
69 return 0;
70 return 1;
71}
72
Max299a9992016-04-28 17:51:15 +020073/* Return p(n) for given NR_OF_TDD_CELLS - see Table 9.1.54.1a, 3GPP TS 44.018 */
Max26679e02016-04-20 15:57:13 +020074unsigned range1024_p(unsigned n)
75{
76 switch (n) {
77 case 0: return 0;
78 case 1: return 10;
79 case 2: return 19;
80 case 3: return 28;
81 case 4: return 36;
82 case 5: return 44;
83 case 6: return 52;
84 case 7: return 60;
85 case 8: return 67;
86 case 9: return 74;
87 case 10: return 81;
88 case 11: return 88;
89 case 12: return 95;
90 case 13: return 102;
91 case 14: return 109;
92 case 15: return 116;
93 case 16: return 122;
94 default: return 0;
95 }
96}
97
98/* Return q(m) for given NR_OF_TDD_CELLS - see Table 9.1.54.1b, 3GPP TS 44.018 */
99unsigned range512_q(unsigned m)
100{
101 switch (m) {
102 case 0: return 0;
103 case 1: return 9;
104 case 2: return 17;
105 case 3: return 25;
106 case 4: return 32;
107 case 5: return 39;
108 case 6: return 46;
109 case 7: return 53;
110 case 8: return 59;
111 case 9: return 65;
112 case 10: return 71;
113 case 11: return 77;
114 case 12: return 83;
115 case 13: return 89;
116 case 14: return 95;
117 case 15: return 101;
118 case 16: return 106;
119 case 17: return 111;
120 case 18: return 116;
121 case 19: return 121;
122 case 20: return 126;
123 default: return 0;
124 }
125}
126
Max70fdd242017-06-15 15:10:53 +0200127size_t si2q_earfcn_count(const struct osmo_earfcn_si2q *e)
Max26679e02016-04-20 15:57:13 +0200128{
Max70fdd242017-06-15 15:10:53 +0200129 unsigned i, ret = 0;
Maxf39d03a2017-05-12 17:00:30 +0200130
Max70fdd242017-06-15 15:10:53 +0200131 if (!e)
132 return 0;
133
134 for (i = 0; i < e->length; i++)
135 if (e->arfcn[i] != OSMO_EARFCN_INVALID)
136 ret++;
137
138 return ret;
Max26679e02016-04-20 15:57:13 +0200139}
140
Max70fdd242017-06-15 15:10:53 +0200141/* generate SI2quater messages, return rest octets length of last generated message or negative error code */
142static int make_si2quaters(struct gsm_bts *bts, bool counting)
Max26679e02016-04-20 15:57:13 +0200143{
Max70fdd242017-06-15 15:10:53 +0200144 int rc;
145 bool memory_exceeded = true;
146 struct gsm48_system_information_type_2quater *si2q;
Maxe610e702016-12-19 13:41:48 +0100147
Max70fdd242017-06-15 15:10:53 +0200148 for (bts->si2q_index = 0; bts->si2q_index < SI2Q_MAX_NUM; bts->si2q_index++) {
149 si2q = GSM_BTS_SI2Q(bts, bts->si2q_index);
150 if (counting) { /* that's legitimate if we're called for counting purpose: */
151 if (bts->si2q_count < bts->si2q_index)
152 bts->si2q_count = bts->si2q_index;
153 } else {
154 memset(si2q, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
155
156 si2q->header.l2_plen = GSM48_LEN2PLEN(22);
157 si2q->header.rr_protocol_discriminator = GSM48_PDISC_RR;
158 si2q->header.skip_indicator = 0;
159 si2q->header.system_information = GSM48_MT_RR_SYSINFO_2quater;
160 }
161
162 rc = rest_octets_si2quater(si2q->rest_octets, bts);
163 if (rc < 0)
164 return rc;
165
166 if (bts->u_offset >= bts->si_common.uarfcn_length &&
167 bts->e_offset >= si2q_earfcn_count(&bts->si_common.si2quater_neigh_list)) {
168 memory_exceeded = false;
169 break;
Maxe610e702016-12-19 13:41:48 +0100170 }
171 }
172
Max70fdd242017-06-15 15:10:53 +0200173 if (memory_exceeded)
174 return -ENOMEM;
Maxe610e702016-12-19 13:41:48 +0100175
Max70fdd242017-06-15 15:10:53 +0200176 return rc;
Max26679e02016-04-20 15:57:13 +0200177}
178
Max70fdd242017-06-15 15:10:53 +0200179/* we generate SI2q rest octets twice to get proper estimation but it's one time cost anyway */
Maxf39d03a2017-05-12 17:00:30 +0200180uint8_t si2q_num(struct gsm_bts *bts)
Maxaafff962016-04-20 15:57:14 +0200181{
Max70fdd242017-06-15 15:10:53 +0200182 int rc = make_si2quaters(bts, true);
183 uint8_t num = bts->si2q_index + 1; /* number of SI2quater messages */
Maxf39d03a2017-05-12 17:00:30 +0200184
Max081ceba2017-09-29 14:10:24 +0200185 /* N. B: si2q_num() should NEVER be called during actual SI2q rest octets generation
Max70fdd242017-06-15 15:10:53 +0200186 we're not re-entrant because of the following code: */
187 bts->u_offset = 0;
188 bts->e_offset = 0;
Maxf39d03a2017-05-12 17:00:30 +0200189
Max70fdd242017-06-15 15:10:53 +0200190 if (rc < 0)
191 return 0xFF; /* return impossible index as an indicator of error in generating SI2quater */
Maxf39d03a2017-05-12 17:00:30 +0200192
Max70fdd242017-06-15 15:10:53 +0200193 return num;
Maxaafff962016-04-20 15:57:14 +0200194}
195
Max26679e02016-04-20 15:57:13 +0200196/* 3GPP TS 44.018, Table 9.1.54.1 - prepend diversity bit to scrambling code */
Max34be86b2016-12-16 18:45:51 +0100197static inline uint16_t encode_fdd(uint16_t scramble, bool diversity)
Max26679e02016-04-20 15:57:13 +0200198{
199 if (diversity)
200 return scramble | (1 << 9);
201 return scramble;
202}
203
Max70fdd242017-06-15 15:10:53 +0200204int bts_earfcn_add(struct gsm_bts *bts, uint16_t earfcn, uint8_t thresh_hi, uint8_t thresh_lo, uint8_t prio,
205 uint8_t qrx, uint8_t meas_bw)
206{
207 struct osmo_earfcn_si2q *e = &bts->si_common.si2quater_neigh_list;
208 int r = osmo_earfcn_add(e, earfcn, (meas_bw < EARFCN_MEAS_BW_INVALID) ? meas_bw : OSMO_EARFCN_MEAS_INVALID);
209
210 if (r < 0)
211 return r;
212
213 if (e->thresh_hi && thresh_hi != e->thresh_hi)
214 r = 1;
215
216 e->thresh_hi = thresh_hi;
217
218 if (thresh_lo != EARFCN_THRESH_LOW_INVALID) {
219 if (e->thresh_lo_valid && e->thresh_lo != thresh_lo)
220 r = EARFCN_THRESH_LOW_INVALID;
221 e->thresh_lo = thresh_lo;
222 e->thresh_lo_valid = true;
223 }
224
225 if (qrx != EARFCN_QRXLV_INVALID) {
226 if (e->qrxlm_valid && e->qrxlm != qrx)
227 r = EARFCN_QRXLV_INVALID + 1;
228 e->qrxlm = qrx;
229 e->qrxlm_valid = true;
230 }
231
232 if (prio != EARFCN_PRIO_INVALID) {
233 if (e->prio_valid && e->prio != prio)
234 r = EARFCN_PRIO_INVALID;
235 e->prio = prio;
236 e->prio_valid = true;
237 }
238
239 return r;
240}
241
Max081ceba2017-09-29 14:10:24 +0200242/* Scrambling Code as defined in 3GPP TS 25.213 is 9 bit long so number below is unreacheable upper bound */
243#define SC_BOUND 600
244
245/* Find position for a given UARFCN (take SC into consideration if it's available) in a sorted list
246 N. B: we rely on the assumption that (uarfcn, scramble) tuple is unique in the lists */
247static int uarfcn_sc_pos(const struct gsm_bts *bts, uint16_t uarfcn, uint16_t scramble)
248{
249 const uint16_t *sc = bts->si_common.data.scramble_list;
250 uint16_t i, scramble0 = encode_fdd(scramble, false), scramble1 = encode_fdd(scramble, true);
251 for (i = 0; i < bts->si_common.uarfcn_length; i++)
252 if (uarfcn == bts->si_common.data.uarfcn_list[i]) {
253 if (scramble < SC_BOUND) {
254 if (scramble0 == sc[i] || scramble1 == sc[i])
255 return i;
256 } else
257 return i;
258 }
259
260 return -1;
261}
262
Max26679e02016-04-20 15:57:13 +0200263int bts_uarfcn_del(struct gsm_bts *bts, uint16_t arfcn, uint16_t scramble)
264{
Max081ceba2017-09-29 14:10:24 +0200265 uint16_t *ual = bts->si_common.data.uarfcn_list, *scl = bts->si_common.data.scramble_list;
266 size_t len = bts->si_common.uarfcn_length;
267 int pos = uarfcn_sc_pos(bts, arfcn, scramble);
Max26679e02016-04-20 15:57:13 +0200268
Max081ceba2017-09-29 14:10:24 +0200269 if (pos < 0)
Max26679e02016-04-20 15:57:13 +0200270 return -EINVAL;
271
Max081ceba2017-09-29 14:10:24 +0200272 if (pos != len - 1) { /* move the tail if necessary */
273 memmove(ual + pos, ual + pos + 1, 2 * (len - pos + 1));
274 memmove(scl + pos, scl + pos + 1, 2 * (len - pos + 1));
275 }
276
Max26679e02016-04-20 15:57:13 +0200277 bts->si_common.uarfcn_length--;
278 return 0;
279}
280
Maxf39d03a2017-05-12 17:00:30 +0200281int bts_uarfcn_add(struct gsm_bts *bts, uint16_t arfcn, uint16_t scramble, bool diversity)
Max26679e02016-04-20 15:57:13 +0200282{
Maxe610e702016-12-19 13:41:48 +0100283 size_t len = bts->si_common.uarfcn_length, i, k = 0;
Max081ceba2017-09-29 14:10:24 +0200284 uint8_t si2q;
285 int pos = uarfcn_sc_pos(bts, arfcn, scramble);
286 uint16_t scr = diversity ? encode_fdd(scramble, true) : encode_fdd(scramble, false),
Max26679e02016-04-20 15:57:13 +0200287 *ual = bts->si_common.data.uarfcn_list,
Max081ceba2017-09-29 14:10:24 +0200288 *scl = bts->si_common.data.scramble_list;
Max26679e02016-04-20 15:57:13 +0200289
290 if (len == MAX_EARFCN_LIST)
291 return -ENOMEM;
292
Max081ceba2017-09-29 14:10:24 +0200293 if (pos >= 0)
294 return -EADDRINUSE;
Maxe610e702016-12-19 13:41:48 +0100295
Max081ceba2017-09-29 14:10:24 +0200296 /* find the suitable position for arfcn if any */
297 pos = uarfcn_sc_pos(bts, arfcn, SC_BOUND);
298 i = (pos < 0) ? len : pos;
299
300 for (k = 0; i < len; i++)
Max26679e02016-04-20 15:57:13 +0200301 if (scr > scl[i])
302 k = i + 1;
Max081ceba2017-09-29 14:10:24 +0200303
304 /* we keep lists sorted by scramble code of a given UARFCN:
Max26679e02016-04-20 15:57:13 +0200305 insert into appropriate position and move the tail */
306 if (len - k) {
307 memmove(ual + k + 1, ual + k, (len - k) * 2);
308 memmove(scl + k + 1, scl + k, (len - k) * 2);
309 }
Maxe610e702016-12-19 13:41:48 +0100310
Max26679e02016-04-20 15:57:13 +0200311 ual[k] = arfcn;
312 scl[k] = scr;
313 bts->si_common.uarfcn_length++;
Max081ceba2017-09-29 14:10:24 +0200314 si2q = si2q_num(bts);
Maxaafff962016-04-20 15:57:14 +0200315
Max081ceba2017-09-29 14:10:24 +0200316 if (si2q <= SI2Q_MAX_NUM) {
317 bts->si2q_count = si2q - 1;
Maxaafff962016-04-20 15:57:14 +0200318 return 0;
Max70fdd242017-06-15 15:10:53 +0200319 }
Maxaafff962016-04-20 15:57:14 +0200320
321 bts_uarfcn_del(bts, arfcn, scramble);
322 return -ENOSPC;
Max26679e02016-04-20 15:57:13 +0200323}
324
Max5fa7e362016-04-15 16:04:45 +0200325static inline int use_arfcn(const struct gsm_bts *bts, const bool bis, const bool ter,
326 const bool pgsm, const int arfcn)
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100327{
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100328 if (bts->force_combined_si)
329 return !bis && !ter;
Holger Hans Peter Freytherd4d1d5e2013-01-17 13:49:39 +0100330 if (!bis && !ter && band_compatible(bts, arfcn))
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100331 return 1;
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100332 /* Correct but somehow broken with either the nanoBTS or the iPhone5 */
Holger Hans Peter Freytherd4d1d5e2013-01-17 13:49:39 +0100333 if (bis && pgsm && band_compatible(bts, arfcn) && (arfcn < 1 || arfcn > 124))
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100334 return 1;
Holger Hans Peter Freytherd4d1d5e2013-01-17 13:49:39 +0100335 if (ter && !band_compatible(bts, arfcn))
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100336 return 1;
337 return 0;
338}
339
Harald Welteda760d32009-12-14 20:25:05 +0100340/* Frequency Lists as per TS 04.08 10.5.2.13 */
341
342/* 10.5.2.13.2: Bit map 0 format */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200343static int freq_list_bm0_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +0530344{
345 unsigned int byte, bit;
346
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100347 if (arfcn > 124 || arfcn < 1) {
348 LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n");
Harald Weltea43f7892009-12-01 18:04:30 +0530349 return -EINVAL;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100350 }
Harald Weltea43f7892009-12-01 18:04:30 +0530351
Harald Welteda760d32009-12-14 20:25:05 +0100352 /* the bitmask is from 1..124, not from 0..123 */
353 arfcn--;
354
Harald Weltea43f7892009-12-01 18:04:30 +0530355 byte = arfcn / 8;
356 bit = arfcn % 8;
357
Harald Welteda760d32009-12-14 20:25:05 +0100358 chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit);
Harald Weltea43f7892009-12-01 18:04:30 +0530359
360 return 0;
361}
362
Harald Welteda760d32009-12-14 20:25:05 +0100363/* 10.5.2.13.7: Variable bit map format */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200364static int freq_list_bmrel_set_arfcn(uint8_t *chan_list, unsigned int arfcn)
Harald Weltea43f7892009-12-01 18:04:30 +0530365{
366 unsigned int byte, bit;
367 unsigned int min_arfcn;
368 unsigned int bitno;
369
370 min_arfcn = (chan_list[0] & 1) << 9;
371 min_arfcn |= chan_list[1] << 1;
372 min_arfcn |= (chan_list[2] >> 7) & 1;
373
374 /* The lower end of our bitmaks is always implicitly included */
375 if (arfcn == min_arfcn)
376 return 0;
377
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100378 if (((arfcn - min_arfcn) & 1023) > 111) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100379 LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
Harald Weltea43f7892009-12-01 18:04:30 +0530380 return -EINVAL;
Harald Welte152b6262009-12-16 11:57:48 +0100381 }
Harald Weltea43f7892009-12-01 18:04:30 +0530382
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100383 bitno = (arfcn - min_arfcn) & 1023;
Harald Weltea43f7892009-12-01 18:04:30 +0530384 byte = bitno / 8;
385 bit = bitno % 8;
386
387 chan_list[2 + byte] |= 1 << (7 - bit);
388
389 return 0;
390}
391
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200392/* generate a variable bitmap */
Max5fa7e362016-04-15 16:04:45 +0200393static inline int enc_freq_lst_var_bitmap(uint8_t *chan_list,
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200394 struct bitvec *bv, const struct gsm_bts *bts,
Max5fa7e362016-04-15 16:04:45 +0200395 bool bis, bool ter, int min, bool pgsm)
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200396{
397 int i;
398
399 /* set it to 'Variable bitmap format' */
400 chan_list[0] = 0x8e;
401
402 chan_list[0] |= (min >> 9) & 1;
403 chan_list[1] = (min >> 1);
404 chan_list[2] = (min & 1) << 7;
405
406 for (i = 0; i < bv->data_len*8; i++) {
407 /* see notes in bitvec2freq_list */
408 if (bitvec_get_bit_pos(bv, i)
Harald Weltee18f78e2015-09-04 06:21:32 +0200409 && ((!bis && !ter && band_compatible(bts,i))
410 || (bis && pgsm && band_compatible(bts,i) && (i < 1 || i > 124))
411 || (ter && !band_compatible(bts, i)))) {
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200412 int rc = freq_list_bmrel_set_arfcn(chan_list, i);
413 if (rc < 0)
414 return rc;
415 }
416 }
417
418 return 0;
419}
420
Max881064e2016-12-14 14:51:40 +0100421int range_encode(enum gsm48_range r, int *arfcns, int arfcns_used, int *w,
422 int f0, uint8_t *chan_list)
423{
424 /*
425 * Manipulate the ARFCN list according to the rules in J4 depending
426 * on the selected range.
427 */
428 int rc, f0_included;
429
430 range_enc_filter_arfcns(arfcns, arfcns_used, f0, &f0_included);
431
432 rc = range_enc_arfcns(r, arfcns, arfcns_used, w, 0);
433 if (rc < 0)
434 return rc;
435
436 /* Select the range and the amount of bits needed */
437 switch (r) {
438 case ARFCN_RANGE_128:
439 return range_enc_range128(chan_list, f0, w);
440 case ARFCN_RANGE_256:
441 return range_enc_range256(chan_list, f0, w);
442 case ARFCN_RANGE_512:
443 return range_enc_range512(chan_list, f0, w);
444 case ARFCN_RANGE_1024:
445 return range_enc_range1024(chan_list, f0, f0_included, w);
446 default:
447 return -ERANGE;
448 };
449
450 return f0_included;
451}
452
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200453/* generate a frequency list with the range 512 format */
Max5fa7e362016-04-15 16:04:45 +0200454static inline int enc_freq_lst_range(uint8_t *chan_list,
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200455 struct bitvec *bv, const struct gsm_bts *bts,
Max5fa7e362016-04-15 16:04:45 +0200456 bool bis, bool ter, bool pgsm)
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200457{
458 int arfcns[RANGE_ENC_MAX_ARFCNS];
459 int w[RANGE_ENC_MAX_ARFCNS];
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200460 int arfcns_used = 0;
Max881064e2016-12-14 14:51:40 +0100461 int i, range, f0;
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200462
463 /*
464 * Select ARFCNs according to the rules in bitvec2freq_list
465 */
466 for (i = 0; i < bv->data_len * 8; ++i) {
467 /* More ARFCNs than the maximum */
468 if (arfcns_used > ARRAY_SIZE(arfcns))
469 return -1;
470 /* Check if we can select it? */
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100471 if (bitvec_get_bit_pos(bv, i) && use_arfcn(bts, bis, ter, pgsm, i))
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200472 arfcns[arfcns_used++] = i;
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200473 }
474
475 /*
476 * Check if the given list of ARFCNs can be encoded.
477 */
478 range = range_enc_determine_range(arfcns, arfcns_used, &f0);
479 if (range == ARFCN_RANGE_INVALID)
480 return -2;
481
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200482 memset(w, 0, sizeof(w));
Max881064e2016-12-14 14:51:40 +0100483 return range_encode(range, arfcns, arfcns_used, w, f0, chan_list);
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200484}
485
Harald Weltea43f7892009-12-01 18:04:30 +0530486/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200487static int bitvec2freq_list(uint8_t *chan_list, struct bitvec *bv,
Max5fa7e362016-04-15 16:04:45 +0200488 const struct gsm_bts *bts, bool bis, bool ter)
Harald Weltea43f7892009-12-01 18:04:30 +0530489{
Max5fa7e362016-04-15 16:04:45 +0200490 int i, rc, min = -1, max = -1, arfcns = 0;
491 bool pgsm = false;
Harald Weltea43f7892009-12-01 18:04:30 +0530492 memset(chan_list, 0, 16);
493
Harald Welte29350342012-02-17 15:58:23 +0100494 if (bts->band == GSM_BAND_900
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100495 && bts->c0->arfcn >= 1 && bts->c0->arfcn <= 124)
Max5fa7e362016-04-15 16:04:45 +0200496 pgsm = true;
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100497 /* P-GSM-only handsets only support 'bit map 0 format' */
498 if (!bis && !ter && pgsm) {
Harald Weltea43f7892009-12-01 18:04:30 +0530499 chan_list[0] = 0;
Harald Welte6c40def2009-12-14 22:07:14 +0100500
501 for (i = 0; i < bv->data_len*8; i++) {
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100502 if (i >= 1 && i <= 124
503 && bitvec_get_bit_pos(bv, i)) {
Harald Welte6c40def2009-12-14 22:07:14 +0100504 rc = freq_list_bm0_set_arfcn(chan_list, i);
505 if (rc < 0)
506 return rc;
507 }
Harald Weltea43f7892009-12-01 18:04:30 +0530508 }
509 return 0;
510 }
511
Harald Welte6c40def2009-12-14 22:07:14 +0100512 for (i = 0; i < bv->data_len*8; i++) {
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100513 /* in case of SI2 or SI5 allow all neighbours in same band
514 * in case of SI*bis, allow neighbours in same band ouside pgsm
515 * in case of SI*ter, allow neighbours in different bands
516 */
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100517 if (!bitvec_get_bit_pos(bv, i))
518 continue;
519 if (!use_arfcn(bts, bis, ter, pgsm, i))
520 continue;
521 /* count the arfcns we want to carry */
522 arfcns += 1;
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200523
Holger Hans Peter Freyther9e1952a2013-01-17 12:04:17 +0100524 /* 955..1023 < 0..885 */
525 if (min < 0)
526 min = i;
527 if (i >= 955 && min < 955)
528 min = i;
529 if (i >= 955 && min >= 955 && i < min)
530 min = i;
531 if (i < 955 && min < 955 && i < min)
532 min = i;
533 if (max < 0)
534 max = i;
535 if (i < 955 && max >= 955)
536 max = i;
537 if (i >= 955 && max >= 955 && i > max)
538 max = i;
539 if (i < 955 && max < 955 && i > max)
540 max = i;
Harald Weltea43f7892009-12-01 18:04:30 +0530541 }
542
Sylvain Munaut42a56522009-12-24 14:20:19 +0100543 if (max == -1) {
544 /* Empty set, use 'bit map 0 format' */
545 chan_list[0] = 0;
546 return 0;
547 }
548
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200549 /* Now find the best encoding */
550 if (((max - min) & 1023) <= 111)
551 return enc_freq_lst_var_bitmap(chan_list, bv, bts, bis,
552 ter, min, pgsm);
Harald Weltea43f7892009-12-01 18:04:30 +0530553
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200554 /* Attempt to do the range encoding */
555 rc = enc_freq_lst_range(chan_list, bv, bts, bis, ter, pgsm);
Max881064e2016-12-14 14:51:40 +0100556 if (rc >= 0)
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200557 return 0;
Harald Weltea43f7892009-12-01 18:04:30 +0530558
Holger Hans Peter Freyther511f9c32012-10-13 12:38:54 +0200559 LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, arfcns=%d "
560 "can not generate ARFCN list", min, max, arfcns);
561 return -EINVAL;
Harald Weltea43f7892009-12-01 18:04:30 +0530562}
563
564/* generate a cell channel list as per Section 10.5.2.1b of 04.08 */
Dieter Spaar16646022011-07-28 00:01:50 +0200565/* static*/ int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530566{
Harald Weltea43f7892009-12-01 18:04:30 +0530567 struct gsm_bts_trx *trx;
Harald Welte6c40def2009-12-14 22:07:14 +0100568 struct bitvec *bv = &bts->si_common.cell_alloc;
Harald Weltea43f7892009-12-01 18:04:30 +0530569
Harald Weltea39b0f22010-06-14 22:26:10 +0200570 /* Zero-initialize the bit-vector */
Harald Weltec8794b52010-06-16 11:09:18 +0200571 memset(bv->data, 0, bv->data_len);
Harald Weltea39b0f22010-06-14 22:26:10 +0200572
Harald Welte6c40def2009-12-14 22:07:14 +0100573 /* first we generate a bitvec of all TRX ARFCN's in our BTS */
Harald Weltea39b0f22010-06-14 22:26:10 +0200574 llist_for_each_entry(trx, &bts->trx_list, list) {
575 unsigned int i, j;
576 /* Always add the TRX's ARFCN */
Harald Welte6c40def2009-12-14 22:07:14 +0100577 bitvec_set_bit_pos(bv, trx->arfcn, 1);
Harald Weltea39b0f22010-06-14 22:26:10 +0200578 for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
579 struct gsm_bts_trx_ts *ts = &trx->ts[i];
580 /* Add any ARFCNs present in hopping channels */
581 for (j = 0; j < 1024; j++) {
582 if (bitvec_get_bit_pos(&ts->hopping.arfcns, j))
583 bitvec_set_bit_pos(bv, j, 1);
584 }
585 }
586 }
Harald Weltea43f7892009-12-01 18:04:30 +0530587
Harald Welte6c40def2009-12-14 22:07:14 +0100588 /* then we generate a GSM 04.08 frequency list from the bitvec */
Max5fa7e362016-04-15 16:04:45 +0200589 return bitvec2freq_list(chan_list, bv, bts, false, false);
Harald Weltea43f7892009-12-01 18:04:30 +0530590}
591
Harald Welted6a52e92017-09-30 09:22:14 +0800592/*! generate a cell channel list as per Section 10.5.2.22 of 04.08
593 * \param[out] chan_list caller-provided output buffer
594 * \param[in] bts BTS descriptor used for input data
595 * \param[in] si5 Are we generating SI5xxx (true) or SI2xxx (false)
596 * \param[in] bis Are we generating SIXbis (true) or not (false)
597 * \param[in] ter Are we generating SIXter (true) or not (false)
598 */
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100599static int generate_bcch_chan_list(uint8_t *chan_list, struct gsm_bts *bts,
Max5fa7e362016-04-15 16:04:45 +0200600 bool si5, bool bis, bool ter)
Harald Welte6c40def2009-12-14 22:07:14 +0100601{
602 struct gsm_bts *cur_bts;
Harald Welte64c07d22011-02-15 11:43:27 +0100603 struct bitvec *bv;
Harald Welteaa70d9d2017-09-30 09:22:30 +0800604 int rc;
Harald Welte64c07d22011-02-15 11:43:27 +0100605
606 if (si5 && bts->neigh_list_manual_mode == NL_MODE_MANUAL_SI5SEP)
607 bv = &bts->si_common.si5_neigh_list;
608 else
609 bv = &bts->si_common.neigh_list;
Harald Welte6c40def2009-12-14 22:07:14 +0100610
Harald Welte32c09622011-01-11 23:44:56 +0100611 /* Generate list of neighbor cells if we are in automatic mode */
Harald Welte64c07d22011-02-15 11:43:27 +0100612 if (bts->neigh_list_manual_mode == NL_MODE_AUTOMATIC) {
Harald Welte21bbda22011-02-19 20:43:37 +0100613 /* Zero-initialize the bit-vector */
614 memset(bv->data, 0, bv->data_len);
615
Harald Welte32c09622011-01-11 23:44:56 +0100616 /* first we generate a bitvec of the BCCH ARFCN's in our BSC */
617 llist_for_each_entry(cur_bts, &bts->network->bts_list, list) {
618 if (cur_bts == bts)
619 continue;
620 bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1);
621 }
Harald Welte6c40def2009-12-14 22:07:14 +0100622 }
623
624 /* then we generate a GSM 04.08 frequency list from the bitvec */
Harald Welteaa70d9d2017-09-30 09:22:30 +0800625 rc = bitvec2freq_list(chan_list, bv, bts, bis, ter);
626 if (rc < 0)
627 return rc;
628
629 /* Set BA-IND depending on whether we're generating SI2 or SI5.
630 * The point here is to be able to correlate whether a given MS
631 * measurement report was using the neighbor cells advertised in
632 * SI2 or in SI5, as those two could very well be different */
633 if (si5)
634 chan_list[0] |= 0x10;
635 else
636 chan_list[0] &= ~0x10;
637
638 return rc;
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100639}
640
641static int list_arfcn(uint8_t *chan_list, uint8_t mask, char *text)
642{
643 int n = 0, i;
644 struct gsm_sysinfo_freq freq[1024];
645
646 memset(freq, 0, sizeof(freq));
647 gsm48_decode_freq_list(freq, chan_list, 16, 0xce, 1);
648 for (i = 0; i < 1024; i++) {
649 if (freq[i].mask) {
650 if (!n)
651 LOGP(DRR, LOGL_INFO, "%s", text);
652 LOGPC(DRR, LOGL_INFO, " %d", i);
653 n++;
654 }
655 }
656 if (n)
657 LOGPC(DRR, LOGL_INFO, "\n");
658
659 return n;
Harald Welte6c40def2009-12-14 22:07:14 +0100660}
661
Max6f0e50c2017-04-12 15:30:54 +0200662static int generate_si1(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530663{
664 int rc;
Max6f0e50c2017-04-12 15:30:54 +0200665 struct gsm48_system_information_type_1 *si1 = (struct gsm48_system_information_type_1 *) GSM_BTS_SI(bts, t);
Harald Weltea43f7892009-12-01 18:04:30 +0530666
667 memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
668
Max2440f492016-12-07 18:03:03 +0100669 si1->header.l2_plen = GSM48_LEN2PLEN(21);
Harald Weltea43f7892009-12-01 18:04:30 +0530670 si1->header.rr_protocol_discriminator = GSM48_PDISC_RR;
671 si1->header.skip_indicator = 0;
672 si1->header.system_information = GSM48_MT_RR_SYSINFO_1;
673
674 rc = generate_cell_chan_list(si1->cell_channel_description, bts);
675 if (rc < 0)
676 return rc;
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100677 list_arfcn(si1->cell_channel_description, 0xce, "Serving cell:");
Harald Weltea43f7892009-12-01 18:04:30 +0530678
679 si1->rach_control = bts->si_common.rach_control;
680
Holger Hans Peter Freytherf876c392013-03-06 12:02:33 +0100681 /*
682 * SI1 Rest Octets (10.5.2.32), contains NCH position and band
683 * indicator but that is not in the 04.08.
684 */
685 rc = rest_octets_si1(si1->rest_octets, NULL, is_dcs_net(bts));
Harald Welte7401ae62010-06-15 16:44:12 +0200686
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100687 return sizeof(*si1) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530688}
689
Max6f0e50c2017-04-12 15:30:54 +0200690static int generate_si2(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530691{
692 int rc;
Max6f0e50c2017-04-12 15:30:54 +0200693 struct gsm48_system_information_type_2 *si2 = (struct gsm48_system_information_type_2 *) GSM_BTS_SI(bts, t);
Harald Weltea43f7892009-12-01 18:04:30 +0530694
695 memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
696
Max2440f492016-12-07 18:03:03 +0100697 si2->header.l2_plen = GSM48_LEN2PLEN(22);
Harald Weltea43f7892009-12-01 18:04:30 +0530698 si2->header.rr_protocol_discriminator = GSM48_PDISC_RR;
699 si2->header.skip_indicator = 0;
700 si2->header.system_information = GSM48_MT_RR_SYSINFO_2;
701
Max5fa7e362016-04-15 16:04:45 +0200702 rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts, false, false, false);
Harald Weltea43f7892009-12-01 18:04:30 +0530703 if (rc < 0)
704 return rc;
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100705 list_arfcn(si2->bcch_frequency_list, 0xce,
Harald Weltee5ba92e2015-09-04 06:22:46 +0200706 "SI2 Neighbour cells in same band:");
Harald Weltea43f7892009-12-01 18:04:30 +0530707
708 si2->ncc_permitted = bts->si_common.ncc_permitted;
709 si2->rach_control = bts->si_common.rach_control;
710
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100711 return sizeof(*si2);
Harald Weltea43f7892009-12-01 18:04:30 +0530712}
713
Max6f0e50c2017-04-12 15:30:54 +0200714static int generate_si2bis(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100715{
716 int rc;
717 struct gsm48_system_information_type_2bis *si2b =
Max6f0e50c2017-04-12 15:30:54 +0200718 (struct gsm48_system_information_type_2bis *) GSM_BTS_SI(bts, t);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100719 int n;
720
721 memset(si2b, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
722
Max2440f492016-12-07 18:03:03 +0100723 si2b->header.l2_plen = GSM48_LEN2PLEN(22);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100724 si2b->header.rr_protocol_discriminator = GSM48_PDISC_RR;
725 si2b->header.skip_indicator = 0;
726 si2b->header.system_information = GSM48_MT_RR_SYSINFO_2bis;
727
Max5fa7e362016-04-15 16:04:45 +0200728 rc = generate_bcch_chan_list(si2b->bcch_frequency_list, bts, false, true, false);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100729 if (rc < 0)
730 return rc;
731 n = list_arfcn(si2b->bcch_frequency_list, 0xce,
732 "Neighbour cells in same band, but outside P-GSM:");
733 if (n) {
734 /* indicate in SI2 and SI2bis: there is an extension */
735 struct gsm48_system_information_type_2 *si2 =
Max6f0e50c2017-04-12 15:30:54 +0200736 (struct gsm48_system_information_type_2 *) GSM_BTS_SI(bts, SYSINFO_TYPE_2);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100737 si2->bcch_frequency_list[0] |= 0x20;
738 si2b->bcch_frequency_list[0] |= 0x20;
739 } else
740 bts->si_valid &= ~(1 << SYSINFO_TYPE_2bis);
741
742 si2b->rach_control = bts->si_common.rach_control;
743
744 return sizeof(*si2b);
745}
746
Max6f0e50c2017-04-12 15:30:54 +0200747static int generate_si2ter(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100748{
749 int rc;
750 struct gsm48_system_information_type_2ter *si2t =
Max6f0e50c2017-04-12 15:30:54 +0200751 (struct gsm48_system_information_type_2ter *) GSM_BTS_SI(bts, t);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100752 int n;
753
754 memset(si2t, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
755
Max2440f492016-12-07 18:03:03 +0100756 si2t->header.l2_plen = GSM48_LEN2PLEN(22);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100757 si2t->header.rr_protocol_discriminator = GSM48_PDISC_RR;
758 si2t->header.skip_indicator = 0;
759 si2t->header.system_information = GSM48_MT_RR_SYSINFO_2ter;
760
Max5fa7e362016-04-15 16:04:45 +0200761 rc = generate_bcch_chan_list(si2t->ext_bcch_frequency_list, bts, false, false, true);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100762 if (rc < 0)
763 return rc;
764 n = list_arfcn(si2t->ext_bcch_frequency_list, 0x8e,
765 "Neighbour cells in different band:");
766 if (!n)
767 bts->si_valid &= ~(1 << SYSINFO_TYPE_2ter);
768
769 return sizeof(*si2t);
770}
771
Maxf39d03a2017-05-12 17:00:30 +0200772/* SI2quater messages are optional - we only generate them when neighbor UARFCNs or EARFCNs are configured */
773static inline bool si2quater_not_needed(struct gsm_bts *bts)
774{
775 unsigned i = MAX_EARFCN_LIST;
776
777 if (bts->si_common.si2quater_neigh_list.arfcn)
778 for (i = 0; i < MAX_EARFCN_LIST; i++)
779 if (bts->si_common.si2quater_neigh_list.arfcn[i] != OSMO_EARFCN_INVALID)
780 break;
781
782 if (!bts->si_common.uarfcn_length && i == MAX_EARFCN_LIST) {
783 bts->si_valid &= ~(1 << SYSINFO_TYPE_2quater); /* mark SI2q as invalid if no (E|U)ARFCNs are present */
784 return true;
785 }
786
787 return false;
788}
789
Max6f0e50c2017-04-12 15:30:54 +0200790static int generate_si2quater(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Max59a1bf32016-04-15 16:04:46 +0200791{
Maxf39d03a2017-05-12 17:00:30 +0200792 int rc;
Max70fdd242017-06-15 15:10:53 +0200793 struct gsm48_system_information_type_2quater *si2q;
Maxf39d03a2017-05-12 17:00:30 +0200794
795 if (si2quater_not_needed(bts)) /* generate rest_octets for SI2q only when necessary */
796 return GSM_MACBLOCK_LEN;
Max59a1bf32016-04-15 16:04:46 +0200797
Max70fdd242017-06-15 15:10:53 +0200798 bts->u_offset = 0;
799 bts->e_offset = 0;
800 bts->si2q_index = 0;
801 bts->si2q_count = si2q_num(bts) - 1;
Max59a1bf32016-04-15 16:04:46 +0200802
Max70fdd242017-06-15 15:10:53 +0200803 rc = make_si2quaters(bts, false);
Max59a1bf32016-04-15 16:04:46 +0200804 if (rc < 0)
805 return rc;
806
Max70fdd242017-06-15 15:10:53 +0200807 OSMO_ASSERT(bts->si2q_count == bts->si2q_index);
808 OSMO_ASSERT(bts->si2q_count <= SI2Q_MAX_NUM);
809
Max59a1bf32016-04-15 16:04:46 +0200810 return sizeof(*si2q) + rc;
811}
812
Harald Welte1f893292010-03-14 23:46:48 +0800813static struct gsm48_si_ro_info si_info = {
Harald Weltea43f7892009-12-01 18:04:30 +0530814 .selection_params = {
815 .present = 0,
816 },
817 .power_offset = {
818 .present = 0,
819 },
820 .si2ter_indicator = 0,
821 .early_cm_ctrl = 1,
822 .scheduling = {
823 .present = 0,
824 },
825 .gprs_ind = {
826 .si13_position = 0,
827 .ra_colour = 0,
Harald Welte97a282b2010-03-14 15:37:43 +0800828 .present = 1,
Harald Weltea43f7892009-12-01 18:04:30 +0530829 },
Maxf3f35052016-04-15 16:04:44 +0200830 .si2quater_indicator = 0,
Harald Weltea43f7892009-12-01 18:04:30 +0530831 .lsa_params = {
832 .present = 0,
833 },
834 .cell_id = 0, /* FIXME: doesn't the bts have this? */
835 .break_ind = 0,
836};
837
Max6f0e50c2017-04-12 15:30:54 +0200838static int generate_si3(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530839{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100840 int rc;
Max6f0e50c2017-04-12 15:30:54 +0200841 struct gsm48_system_information_type_3 *si3 = (struct gsm48_system_information_type_3 *) GSM_BTS_SI(bts, t);
Harald Weltea43f7892009-12-01 18:04:30 +0530842
843 memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
844
Max2440f492016-12-07 18:03:03 +0100845 si3->header.l2_plen = GSM48_LEN2PLEN(18);
Harald Weltea43f7892009-12-01 18:04:30 +0530846 si3->header.rr_protocol_discriminator = GSM48_PDISC_RR;
847 si3->header.skip_indicator = 0;
848 si3->header.system_information = GSM48_MT_RR_SYSINFO_3;
849
850 si3->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +0100851 gsm48_generate_lai(&si3->lai, bts->network->country_code,
852 bts->network->network_code,
853 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530854 si3->control_channel_desc = bts->si_common.chan_desc;
855 si3->cell_options = bts->si_common.cell_options;
856 si3->cell_sel_par = bts->si_common.cell_sel_par;
857 si3->rach_control = bts->si_common.rach_control;
858
Maxc08ee712016-05-11 12:45:13 +0200859 /* allow/disallow DTXu */
860 gsm48_set_dtx(&si3->cell_options, bts->dtxu, bts->dtxu, true);
861
Max9b97b002017-06-02 10:58:26 +0200862 if (GSM_BTS_HAS_SI(bts, SYSINFO_TYPE_2ter)) {
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100863 LOGP(DRR, LOGL_INFO, "SI 2ter is included.\n");
864 si_info.si2ter_indicator = 1;
865 } else {
866 si_info.si2ter_indicator = 0;
867 }
Max9b97b002017-06-02 10:58:26 +0200868 if (GSM_BTS_HAS_SI(bts, SYSINFO_TYPE_2quater)) {
Max845a3a42017-05-15 12:02:29 +0200869 LOGP(DRR, LOGL_INFO, "SI 2quater is included, based on %zu EARFCNs and %zu UARFCNs.\n",
870 si2q_earfcn_count(&bts->si_common.si2quater_neigh_list), bts->si_common.uarfcn_length);
Maxf3f35052016-04-15 16:04:44 +0200871 si_info.si2quater_indicator = 1;
872 } else {
873 si_info.si2quater_indicator = 0;
874 }
Harald Welte42def722017-01-13 00:10:32 +0100875 si_info.early_cm_ctrl = bts->early_classmark_allowed;
876
Harald Weltea43f7892009-12-01 18:04:30 +0530877 /* SI3 Rest Octets (10.5.2.34), containing
878 CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME
879 Power Offset, 2ter Indicator, Early Classmark Sending,
880 Scheduling if and WHERE, GPRS Indicator, SI13 position */
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100881 rc = rest_octets_si3(si3->rest_octets, &si_info);
Harald Weltea43f7892009-12-01 18:04:30 +0530882
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100883 return sizeof(*si3) + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530884}
885
Max6f0e50c2017-04-12 15:30:54 +0200886static int generate_si4(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530887{
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +0100888 int rc;
Max6f0e50c2017-04-12 15:30:54 +0200889 struct gsm48_system_information_type_4 *si4 = (struct gsm48_system_information_type_4 *) GSM_BTS_SI(bts, t);
Harald Welte30f1f372014-12-28 15:00:45 +0100890 struct gsm_lchan *cbch_lchan;
891 uint8_t *restoct = si4->data;
Harald Weltea43f7892009-12-01 18:04:30 +0530892
893 /* length of all IEs present except SI4 rest octets and l2_plen */
894 int l2_plen = sizeof(*si4) - 1;
895
896 memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
897
898 si4->header.rr_protocol_discriminator = GSM48_PDISC_RR;
899 si4->header.skip_indicator = 0;
900 si4->header.system_information = GSM48_MT_RR_SYSINFO_4;
901
Harald Welteafedeab2010-03-04 10:55:40 +0100902 gsm48_generate_lai(&si4->lai, bts->network->country_code,
903 bts->network->network_code,
904 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +0530905 si4->cell_sel_par = bts->si_common.cell_sel_par;
906 si4->rach_control = bts->si_common.rach_control;
907
908 /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
Harald Welte142d12d2014-12-29 17:47:08 +0100909 cbch_lchan = gsm_bts_get_cbch(bts);
Harald Welte30f1f372014-12-28 15:00:45 +0100910 if (cbch_lchan) {
911 struct gsm48_chan_desc cd;
912 gsm48_lchan2chan_desc(&cd, cbch_lchan);
Daniel Willmann695675f2014-12-30 12:10:25 +0100913 tv_fixed_put(si4->data, GSM48_IE_CBCH_CHAN_DESC, 3,
Harald Welte30f1f372014-12-28 15:00:45 +0100914 (uint8_t *) &cd);
Daniel Willmann695675f2014-12-30 12:10:25 +0100915 l2_plen += 3 + 1;
916 restoct += 3 + 1;
Harald Welte30f1f372014-12-28 15:00:45 +0100917 /* we don't use hopping and thus don't need a CBCH MA */
918 }
Harald Weltea43f7892009-12-01 18:04:30 +0530919
Max2440f492016-12-07 18:03:03 +0100920 si4->header.l2_plen = GSM48_LEN2PLEN(l2_plen);
Harald Weltea43f7892009-12-01 18:04:30 +0530921
922 /* SI4 Rest Octets (10.5.2.35), containing
923 Optional Power offset, GPRS Indicator,
924 Cell Identity, LSA ID, Selection Parameter */
Max6f0e50c2017-04-12 15:30:54 +0200925 rc = rest_octets_si4(restoct, &si_info, (uint8_t *)GSM_BTS_SI(bts, t) + GSM_MACBLOCK_LEN - restoct);
Harald Weltea43f7892009-12-01 18:04:30 +0530926
Harald Welte30f1f372014-12-28 15:00:45 +0100927 return l2_plen + 1 + rc;
Harald Weltea43f7892009-12-01 18:04:30 +0530928}
929
Max6f0e50c2017-04-12 15:30:54 +0200930static int generate_si5(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +0530931{
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100932 struct gsm48_system_information_type_5 *si5;
Max6f0e50c2017-04-12 15:30:54 +0200933 uint8_t *output = GSM_BTS_SI(bts, t);
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100934 int rc, l2_plen = 18;
Harald Weltea43f7892009-12-01 18:04:30 +0530935
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +0100936 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
937
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100938 /* ip.access nanoBTS needs l2_plen!! */
Harald Weltefd355a32011-03-04 13:41:31 +0100939 switch (bts->type) {
940 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100941 case GSM_BTS_TYPE_OSMOBTS:
Max2440f492016-12-07 18:03:03 +0100942 *output++ = GSM48_LEN2PLEN(l2_plen);
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100943 l2_plen++;
Harald Weltefd355a32011-03-04 13:41:31 +0100944 break;
945 default:
946 break;
Harald Weltee2d0d5f2009-12-19 21:26:54 +0100947 }
948
Max6f0e50c2017-04-12 15:30:54 +0200949 si5 = (struct gsm48_system_information_type_5 *) GSM_BTS_SI(bts, t);
Harald Weltea43f7892009-12-01 18:04:30 +0530950
951 /* l2 pseudo length, not part of msg: 18 */
952 si5->rr_protocol_discriminator = GSM48_PDISC_RR;
953 si5->skip_indicator = 0;
954 si5->system_information = GSM48_MT_RR_SYSINFO_5;
Max5fa7e362016-04-15 16:04:45 +0200955 rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts, true, false, false);
Harald Weltea43f7892009-12-01 18:04:30 +0530956 if (rc < 0)
957 return rc;
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100958 list_arfcn(si5->bcch_frequency_list, 0xce,
Harald Weltee5ba92e2015-09-04 06:22:46 +0200959 "SI5 Neighbour cells in same band:");
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100960
961 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
962 return l2_plen;
963}
964
Max6f0e50c2017-04-12 15:30:54 +0200965static int generate_si5bis(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100966{
967 struct gsm48_system_information_type_5bis *si5b;
Max6f0e50c2017-04-12 15:30:54 +0200968 uint8_t *output = GSM_BTS_SI(bts, t);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100969 int rc, l2_plen = 18;
970 int n;
971
972 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
973
974 /* ip.access nanoBTS needs l2_plen!! */
975 switch (bts->type) {
976 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100977 case GSM_BTS_TYPE_OSMOBTS:
Max2440f492016-12-07 18:03:03 +0100978 *output++ = GSM48_LEN2PLEN(l2_plen);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100979 l2_plen++;
980 break;
981 default:
982 break;
983 }
984
Max6f0e50c2017-04-12 15:30:54 +0200985 si5b = (struct gsm48_system_information_type_5bis *) GSM_BTS_SI(bts, t);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100986
987 /* l2 pseudo length, not part of msg: 18 */
988 si5b->rr_protocol_discriminator = GSM48_PDISC_RR;
989 si5b->skip_indicator = 0;
990 si5b->system_information = GSM48_MT_RR_SYSINFO_5bis;
Max5fa7e362016-04-15 16:04:45 +0200991 rc = generate_bcch_chan_list(si5b->bcch_frequency_list, bts, true, true, false);
Andreas Eversbergc50543b2012-02-29 09:04:07 +0100992 if (rc < 0)
993 return rc;
994 n = list_arfcn(si5b->bcch_frequency_list, 0xce,
995 "Neighbour cells in same band, but outside P-GSM:");
996 if (n) {
997 /* indicate in SI5 and SI5bis: there is an extension */
998 struct gsm48_system_information_type_5 *si5 =
Max6f0e50c2017-04-12 15:30:54 +0200999 (struct gsm48_system_information_type_5 *) GSM_BTS_SI(bts, SYSINFO_TYPE_5);
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001000 si5->bcch_frequency_list[0] |= 0x20;
1001 si5b->bcch_frequency_list[0] |= 0x20;
1002 } else
1003 bts->si_valid &= ~(1 << SYSINFO_TYPE_5bis);
1004
1005 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
1006 return l2_plen;
1007}
1008
Max6f0e50c2017-04-12 15:30:54 +02001009static int generate_si5ter(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001010{
1011 struct gsm48_system_information_type_5ter *si5t;
Max6f0e50c2017-04-12 15:30:54 +02001012 uint8_t *output = GSM_BTS_SI(bts, t);
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001013 int rc, l2_plen = 18;
1014 int n;
1015
1016 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
1017
1018 /* ip.access nanoBTS needs l2_plen!! */
1019 switch (bts->type) {
1020 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001021 case GSM_BTS_TYPE_OSMOBTS:
Max2440f492016-12-07 18:03:03 +01001022 *output++ = GSM48_LEN2PLEN(l2_plen);
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001023 l2_plen++;
1024 break;
1025 default:
1026 break;
1027 }
1028
Max6f0e50c2017-04-12 15:30:54 +02001029 si5t = (struct gsm48_system_information_type_5ter *) GSM_BTS_SI(bts, t);
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001030
1031 /* l2 pseudo length, not part of msg: 18 */
1032 si5t->rr_protocol_discriminator = GSM48_PDISC_RR;
1033 si5t->skip_indicator = 0;
1034 si5t->system_information = GSM48_MT_RR_SYSINFO_5ter;
Max5fa7e362016-04-15 16:04:45 +02001035 rc = generate_bcch_chan_list(si5t->bcch_frequency_list, bts, true, false, true);
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001036 if (rc < 0)
1037 return rc;
1038 n = list_arfcn(si5t->bcch_frequency_list, 0x8e,
1039 "Neighbour cells in different band:");
1040 if (!n)
1041 bts->si_valid &= ~(1 << SYSINFO_TYPE_5ter);
Harald Weltea43f7892009-12-01 18:04:30 +05301042
1043 /* 04.08 9.1.37: L2 Pseudo Length of 18 */
Harald Weltee2d0d5f2009-12-19 21:26:54 +01001044 return l2_plen;
Harald Weltea43f7892009-12-01 18:04:30 +05301045}
1046
Max6f0e50c2017-04-12 15:30:54 +02001047static int generate_si6(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +05301048{
Harald Weltee2d0d5f2009-12-19 21:26:54 +01001049 struct gsm48_system_information_type_6 *si6;
Max6f0e50c2017-04-12 15:30:54 +02001050 uint8_t *output = GSM_BTS_SI(bts, t);
Harald Weltee2d0d5f2009-12-19 21:26:54 +01001051 int l2_plen = 11;
Holger Hans Peter Freyther82dd9832016-05-17 23:20:03 +02001052 int rc;
Harald Weltea43f7892009-12-01 18:04:30 +05301053
Holger Hans Peter Freyther17d81e22010-01-06 07:52:55 +01001054 memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
1055
Harald Weltee2d0d5f2009-12-19 21:26:54 +01001056 /* ip.access nanoBTS needs l2_plen!! */
Harald Weltefd355a32011-03-04 13:41:31 +01001057 switch (bts->type) {
1058 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +01001059 case GSM_BTS_TYPE_OSMOBTS:
Max2440f492016-12-07 18:03:03 +01001060 *output++ = GSM48_LEN2PLEN(l2_plen);
Harald Weltee2d0d5f2009-12-19 21:26:54 +01001061 l2_plen++;
Harald Weltefd355a32011-03-04 13:41:31 +01001062 break;
1063 default:
1064 break;
Harald Weltee2d0d5f2009-12-19 21:26:54 +01001065 }
1066
Max6f0e50c2017-04-12 15:30:54 +02001067 si6 = (struct gsm48_system_information_type_6 *) GSM_BTS_SI(bts, t);
Harald Weltea43f7892009-12-01 18:04:30 +05301068
1069 /* l2 pseudo length, not part of msg: 11 */
1070 si6->rr_protocol_discriminator = GSM48_PDISC_RR;
1071 si6->skip_indicator = 0;
1072 si6->system_information = GSM48_MT_RR_SYSINFO_6;
1073 si6->cell_identity = htons(bts->cell_identity);
Harald Welteafedeab2010-03-04 10:55:40 +01001074 gsm48_generate_lai(&si6->lai, bts->network->country_code,
1075 bts->network->network_code,
1076 bts->location_area_code);
Harald Weltea43f7892009-12-01 18:04:30 +05301077 si6->cell_options = bts->si_common.cell_options;
1078 si6->ncc_permitted = bts->si_common.ncc_permitted;
Maxc08ee712016-05-11 12:45:13 +02001079 /* allow/disallow DTXu */
Maxea8e9832016-05-23 17:28:13 +02001080 gsm48_set_dtx(&si6->cell_options, bts->dtxu, bts->dtxu, false);
Harald Weltea43f7892009-12-01 18:04:30 +05301081
1082 /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */
Holger Hans Peter Freyther82dd9832016-05-17 23:20:03 +02001083 rc = rest_octets_si6(si6->rest_octets, is_dcs_net(bts));
Harald Weltea43f7892009-12-01 18:04:30 +05301084
Holger Hans Peter Freyther82dd9832016-05-17 23:20:03 +02001085 return l2_plen + rc;
Harald Weltea43f7892009-12-01 18:04:30 +05301086}
1087
1088static struct gsm48_si13_info si13_default = {
1089 .cell_opts = {
Harald Welte85849182010-06-02 12:19:21 +02001090 .nmo = GPRS_NMO_II,
Harald Weltea4b16652010-05-31 12:54:23 +02001091 .t3168 = 2000,
Andreas Eversbergbecc89a2012-09-23 08:14:51 +02001092 .t3192 = 1500,
Harald Welte97a282b2010-03-14 15:37:43 +08001093 .drx_timer_max = 3,
Harald Weltea43f7892009-12-01 18:04:30 +05301094 .bs_cv_max = 15,
Max292ec582016-07-28 11:55:37 +02001095 .ctrl_ack_type_use_block = true,
Sylvain Munaut851f1202011-10-17 13:56:02 +02001096 .ext_info_present = 0,
bhargava350533c2016-07-21 11:14:34 +05301097 .supports_egprs_11bit_rach = 0,
Harald Welteda0586a2010-04-18 14:49:05 +02001098 .ext_info = {
1099 /* The values below are just guesses ! */
Harald Weltea06fea02010-04-18 15:53:40 +02001100 .egprs_supported = 0,
Harald Welteda0586a2010-04-18 14:49:05 +02001101 .use_egprs_p_ch_req = 1,
Harald Weltea4b16652010-05-31 12:54:23 +02001102 .bep_period = 5,
Harald Welteda0586a2010-04-18 14:49:05 +02001103 .pfc_supported = 0,
1104 .dtm_supported = 0,
1105 .bss_paging_coordination = 0,
1106 },
Harald Weltea43f7892009-12-01 18:04:30 +05301107 },
1108 .pwr_ctrl_pars = {
Harald Weltec15d0ac2012-10-08 21:22:08 +02001109 .alpha = 0, /* a = 0.0 */
Harald Weltea4b16652010-05-31 12:54:23 +02001110 .t_avg_w = 16,
1111 .t_avg_t = 16,
Harald Weltea43f7892009-12-01 18:04:30 +05301112 .pc_meas_chan = 0, /* downling measured on CCCH */
Harald Weltea4b16652010-05-31 12:54:23 +02001113 .n_avg_i = 8,
Harald Weltea43f7892009-12-01 18:04:30 +05301114 },
Harald Welte97a282b2010-03-14 15:37:43 +08001115 .bcch_change_mark = 1,
Harald Weltea43f7892009-12-01 18:04:30 +05301116 .si_change_field = 0,
Max72fbc952017-08-29 13:14:24 +02001117 .rac = 0, /* needs to be patched */
1118 .spgc_ccch_sup = 0,
1119 .net_ctrl_ord = 0,
1120 .prio_acc_thr = 6,
Harald Weltea43f7892009-12-01 18:04:30 +05301121};
1122
Max6f0e50c2017-04-12 15:30:54 +02001123static int generate_si13(enum osmo_sysinfo_type t, struct gsm_bts *bts)
Harald Weltea43f7892009-12-01 18:04:30 +05301124{
1125 struct gsm48_system_information_type_13 *si13 =
Max6f0e50c2017-04-12 15:30:54 +02001126 (struct gsm48_system_information_type_13 *) GSM_BTS_SI(bts, t);
Harald Weltea43f7892009-12-01 18:04:30 +05301127 int ret;
1128
1129 memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN);
1130
1131 si13->header.rr_protocol_discriminator = GSM48_PDISC_RR;
1132 si13->header.skip_indicator = 0;
1133 si13->header.system_information = GSM48_MT_RR_SYSINFO_13;
1134
Max72fbc952017-08-29 13:14:24 +02001135 si13_default.rac = bts->gprs.rac;
1136 si13_default.net_ctrl_ord = bts->gprs.net_ctrl_ord;
Harald Welte97a282b2010-03-14 15:37:43 +08001137
Max292ec582016-07-28 11:55:37 +02001138 si13_default.cell_opts.ctrl_ack_type_use_block =
1139 bts->gprs.ctrl_ack_type_use_block;
1140
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +01001141 /* Information about the other SIs */
1142 si13_default.bcch_change_mark = bts->bcch_change_mark;
bhargava350533c2016-07-21 11:14:34 +05301143 si13_default.cell_opts.supports_egprs_11bit_rach =
1144 bts->gprs.supports_egprs_11bit_rach;
Holger Hans Peter Freytherb92a5382014-11-21 10:00:39 +01001145
Harald Weltea43f7892009-12-01 18:04:30 +05301146 ret = rest_octets_si13(si13->rest_octets, &si13_default);
1147 if (ret < 0)
1148 return ret;
1149
Holger Hans Peter Freyther1c6f3942010-06-16 12:05:56 +08001150 /* length is coded in bit 2 an up */
1151 si13->header.l2_plen = 0x01;
Harald Weltea43f7892009-12-01 18:04:30 +05301152
Holger Hans Peter Freyther7ec448d2010-01-06 07:52:31 +01001153 return sizeof (*si13) + ret;
Harald Weltea43f7892009-12-01 18:04:30 +05301154}
1155
Max6f0e50c2017-04-12 15:30:54 +02001156typedef int (*gen_si_fn_t)(enum osmo_sysinfo_type t, struct gsm_bts *bts);
Harald Welte7401ae62010-06-15 16:44:12 +02001157
1158static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = {
1159 [SYSINFO_TYPE_1] = &generate_si1,
1160 [SYSINFO_TYPE_2] = &generate_si2,
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001161 [SYSINFO_TYPE_2bis] = &generate_si2bis,
1162 [SYSINFO_TYPE_2ter] = &generate_si2ter,
Max59a1bf32016-04-15 16:04:46 +02001163 [SYSINFO_TYPE_2quater] = &generate_si2quater,
Harald Welte7401ae62010-06-15 16:44:12 +02001164 [SYSINFO_TYPE_3] = &generate_si3,
1165 [SYSINFO_TYPE_4] = &generate_si4,
1166 [SYSINFO_TYPE_5] = &generate_si5,
Andreas Eversbergc50543b2012-02-29 09:04:07 +01001167 [SYSINFO_TYPE_5bis] = &generate_si5bis,
1168 [SYSINFO_TYPE_5ter] = &generate_si5ter,
Harald Welte7401ae62010-06-15 16:44:12 +02001169 [SYSINFO_TYPE_6] = &generate_si6,
1170 [SYSINFO_TYPE_13] = &generate_si13,
1171};
1172
Harald Welte7401ae62010-06-15 16:44:12 +02001173int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type)
1174{
1175 gen_si_fn_t gen_si;
1176
Harald Welte4511d892010-04-18 15:51:20 +02001177 switch (bts->gprs.mode) {
1178 case BTS_GPRS_EGPRS:
Harald Weltea06fea02010-04-18 15:53:40 +02001179 si13_default.cell_opts.ext_info_present = 1;
1180 si13_default.cell_opts.ext_info.egprs_supported = 1;
1181 /* fallthrough */
Harald Welte4511d892010-04-18 15:51:20 +02001182 case BTS_GPRS_GPRS:
1183 si_info.gprs_ind.present = 1;
1184 break;
1185 case BTS_GPRS_NONE:
1186 si_info.gprs_ind.present = 0;
1187 break;
1188 }
Harald Welte1f893292010-03-14 23:46:48 +08001189
Sylvain Munaute0b06b02010-11-28 18:17:28 +01001190 memcpy(&si_info.selection_params,
1191 &bts->si_common.cell_ro_sel_par,
1192 sizeof(struct gsm48_si_selection_params));
1193
Harald Welte7401ae62010-06-15 16:44:12 +02001194 gen_si = gen_si_fn[si_type];
1195 if (!gen_si)
Harald Weltea43f7892009-12-01 18:04:30 +05301196 return -EINVAL;
Harald Weltea43f7892009-12-01 18:04:30 +05301197
Max6f0e50c2017-04-12 15:30:54 +02001198 return gen_si(si_type, bts);
Harald Weltea43f7892009-12-01 18:04:30 +05301199}