Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1 | /* 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 Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 4 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 5 | * (C) 2012 Holger Hans Peter Freyther |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * 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 Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 12 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * 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 Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <string.h> |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 26 | #include <stdio.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 27 | #include <netinet/in.h> |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 28 | #include <stdbool.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 29 | |
Harald Welte | 80cffaf | 2011-05-24 15:02:20 +0200 | [diff] [blame] | 30 | #include <osmocom/core/bitvec.h> |
| 31 | #include <osmocom/core/utils.h> |
| 32 | #include <osmocom/gsm/sysinfo.h> |
| 33 | |
| 34 | #include <openbsc/debug.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 35 | #include <openbsc/gsm_04_08.h> |
| 36 | #include <openbsc/gsm_data.h> |
| 37 | #include <openbsc/abis_rsl.h> |
| 38 | #include <openbsc/rest_octets.h> |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 39 | #include <openbsc/arfcn_range_encode.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 40 | |
Holger Hans Peter Freyther | d4d1d5e | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 41 | /* |
| 42 | * DCS1800 and PCS1900 have overlapping ARFCNs. We would need to set the |
| 43 | * ARFCN_PCS flag on the 1900 ARFCNs but this would increase cell_alloc |
| 44 | * and other arrays to make sure (ARFCN_PCS + 1024)/8 ARFCNs fit into the |
| 45 | * array. DCS1800 and PCS1900 can not be used at the same time so conserve |
| 46 | * memory and do the below. |
| 47 | */ |
| 48 | static int band_compatible(const struct gsm_bts *bts, int arfcn) |
| 49 | { |
| 50 | enum gsm_band band = gsm_arfcn2band(arfcn); |
| 51 | |
| 52 | /* normal case */ |
| 53 | if (band == bts->band) |
| 54 | return 1; |
| 55 | /* deal with ARFCN_PCS not set */ |
| 56 | if (band == GSM_BAND_1800 && bts->band == GSM_BAND_1900) |
| 57 | return 1; |
| 58 | |
| 59 | return 0; |
| 60 | } |
Holger Hans Peter Freyther | b91a106 | 2010-01-06 06:38:14 +0100 | [diff] [blame] | 61 | |
Holger Hans Peter Freyther | f876c39 | 2013-03-06 12:02:33 +0100 | [diff] [blame] | 62 | static int is_dcs_net(const struct gsm_bts *bts) |
| 63 | { |
| 64 | if (bts->band == GSM_BAND_850) |
| 65 | return 0; |
| 66 | if (bts->band == GSM_BAND_1900) |
| 67 | return 0; |
| 68 | return 1; |
| 69 | } |
| 70 | |
Max | 299a999 | 2016-04-28 17:51:15 +0200 | [diff] [blame] | 71 | /* Return p(n) for given NR_OF_TDD_CELLS - see Table 9.1.54.1a, 3GPP TS 44.018 */ |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 72 | unsigned range1024_p(unsigned n) |
| 73 | { |
| 74 | switch (n) { |
| 75 | case 0: return 0; |
| 76 | case 1: return 10; |
| 77 | case 2: return 19; |
| 78 | case 3: return 28; |
| 79 | case 4: return 36; |
| 80 | case 5: return 44; |
| 81 | case 6: return 52; |
| 82 | case 7: return 60; |
| 83 | case 8: return 67; |
| 84 | case 9: return 74; |
| 85 | case 10: return 81; |
| 86 | case 11: return 88; |
| 87 | case 12: return 95; |
| 88 | case 13: return 102; |
| 89 | case 14: return 109; |
| 90 | case 15: return 116; |
| 91 | case 16: return 122; |
| 92 | default: return 0; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* Return q(m) for given NR_OF_TDD_CELLS - see Table 9.1.54.1b, 3GPP TS 44.018 */ |
| 97 | unsigned range512_q(unsigned m) |
| 98 | { |
| 99 | switch (m) { |
| 100 | case 0: return 0; |
| 101 | case 1: return 9; |
| 102 | case 2: return 17; |
| 103 | case 3: return 25; |
| 104 | case 4: return 32; |
| 105 | case 5: return 39; |
| 106 | case 6: return 46; |
| 107 | case 7: return 53; |
| 108 | case 8: return 59; |
| 109 | case 9: return 65; |
| 110 | case 10: return 71; |
| 111 | case 11: return 77; |
| 112 | case 12: return 83; |
| 113 | case 13: return 89; |
| 114 | case 14: return 95; |
| 115 | case 15: return 101; |
| 116 | case 16: return 106; |
| 117 | case 17: return 111; |
| 118 | case 18: return 116; |
| 119 | case 19: return 121; |
| 120 | case 20: return 126; |
| 121 | default: return 0; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | unsigned earfcn_size(const struct osmo_earfcn_si2q *e) |
| 126 | { |
| 127 | /* account for all the constant bits in append_earfcn() */ |
| 128 | return 25 + osmo_earfcn_bit_size(e); |
| 129 | } |
| 130 | |
| 131 | unsigned uarfcn_size(const uint16_t *u, const uint16_t *sc, size_t u_len) |
| 132 | { |
| 133 | /*account for all the constant bits in append_uarfcn() */ |
| 134 | return 29 + range1024_p(u_len); |
| 135 | } |
| 136 | |
Max | aafff96 | 2016-04-20 15:57:14 +0200 | [diff] [blame] | 137 | bool si2q_size_check(const struct gsm_bts *bts) |
| 138 | { |
| 139 | const struct osmo_earfcn_si2q *e = &bts->si_common.si2quater_neigh_list; |
| 140 | const uint16_t *u = bts->si_common.data.uarfcn_list, |
| 141 | *sc = bts->si_common.data.scramble_list; |
| 142 | size_t len = bts->si_common.uarfcn_length; |
| 143 | unsigned e_sz = e ? earfcn_size(e) : 1, |
| 144 | u_sz = len ? uarfcn_size(u, sc, len) : 1; |
| 145 | /* 2 bits are used in between UARFCN and EARFCN structs */ |
| 146 | if (SI2Q_MIN_LEN + u_sz + 2 + e_sz > SI2Q_MAX_LEN) |
| 147 | return false; |
| 148 | return true; |
| 149 | } |
| 150 | |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 151 | /* 3GPP TS 44.018, Table 9.1.54.1 - prepend diversity bit to scrambling code */ |
| 152 | uint16_t encode_fdd(uint16_t scramble, bool diversity) |
| 153 | { |
| 154 | if (diversity) |
| 155 | return scramble | (1 << 9); |
| 156 | return scramble; |
| 157 | } |
| 158 | |
| 159 | int bts_uarfcn_del(struct gsm_bts *bts, uint16_t arfcn, uint16_t scramble) |
| 160 | { |
| 161 | uint16_t sc0 = encode_fdd(scramble, false), sc1 = encode_fdd(scramble, true), |
| 162 | *ual = bts->si_common.data.uarfcn_list, |
| 163 | *scl = bts->si_common.data.scramble_list; |
| 164 | size_t len = bts->si_common.uarfcn_length, i; |
| 165 | for (i = 0; i < len; i++) { |
| 166 | if (arfcn == ual[i] && (sc0 == scl[i] || sc1 == scl[i])) { |
| 167 | /* we rely on the assumption that (uarfcn, scramble) |
| 168 | tuple is unique in the lists */ |
| 169 | if (i != len - 1) { /* move the tail if necessary */ |
| 170 | memmove(ual + i, ual + i + 1, 2 * (len - i + 1)); |
| 171 | memmove(scl + i, scl + i + 1, 2 * (len - i + 1)); |
| 172 | } |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (i == len) |
| 178 | return -EINVAL; |
| 179 | |
| 180 | bts->si_common.uarfcn_length--; |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int bts_uarfcn_add(struct gsm_bts *bts, uint16_t arfcn, uint16_t scramble, |
| 185 | bool diversity) |
| 186 | { |
| 187 | size_t len = bts->si_common.uarfcn_length, i, k; |
| 188 | uint16_t scr, chk, |
| 189 | *ual = bts->si_common.data.uarfcn_list, |
| 190 | *scl = bts->si_common.data.scramble_list, |
| 191 | scramble1 = encode_fdd(scramble, true), |
| 192 | scramble0 = encode_fdd(scramble, false); |
| 193 | |
| 194 | scr = diversity ? scramble1 : scramble0; |
| 195 | chk = diversity ? scramble0 : scramble1; |
| 196 | |
| 197 | if (len == MAX_EARFCN_LIST) |
| 198 | return -ENOMEM; |
| 199 | |
| 200 | for (i = 0, k = 0; i < len; i++) { |
| 201 | if (arfcn == ual[i] && (scr == scl[i] || chk == scl[i])) |
| 202 | return -EADDRINUSE; |
| 203 | if (scr > scl[i]) |
| 204 | k = i + 1; |
| 205 | } |
| 206 | /* we keep lists sorted by scramble code: |
| 207 | insert into appropriate position and move the tail */ |
| 208 | if (len - k) { |
| 209 | memmove(ual + k + 1, ual + k, (len - k) * 2); |
| 210 | memmove(scl + k + 1, scl + k, (len - k) * 2); |
| 211 | } |
| 212 | ual[k] = arfcn; |
| 213 | scl[k] = scr; |
| 214 | bts->si_common.uarfcn_length++; |
Max | aafff96 | 2016-04-20 15:57:14 +0200 | [diff] [blame] | 215 | |
| 216 | if (si2q_size_check(bts)) |
| 217 | return 0; |
| 218 | |
| 219 | bts_uarfcn_del(bts, arfcn, scramble); |
| 220 | return -ENOSPC; |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 223 | static inline int use_arfcn(const struct gsm_bts *bts, const bool bis, const bool ter, |
| 224 | const bool pgsm, const int arfcn) |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 225 | { |
Jacob Erlbeck | 65d114f | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 226 | if (bts->force_combined_si) |
| 227 | return !bis && !ter; |
Holger Hans Peter Freyther | d4d1d5e | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 228 | if (!bis && !ter && band_compatible(bts, arfcn)) |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 229 | return 1; |
Jacob Erlbeck | 65d114f | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 230 | /* Correct but somehow broken with either the nanoBTS or the iPhone5 */ |
Holger Hans Peter Freyther | d4d1d5e | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 231 | if (bis && pgsm && band_compatible(bts, arfcn) && (arfcn < 1 || arfcn > 124)) |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 232 | return 1; |
Holger Hans Peter Freyther | d4d1d5e | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 233 | if (ter && !band_compatible(bts, arfcn)) |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 234 | return 1; |
| 235 | return 0; |
| 236 | } |
| 237 | |
Harald Welte | da760d3 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 238 | /* Frequency Lists as per TS 04.08 10.5.2.13 */ |
| 239 | |
| 240 | /* 10.5.2.13.2: Bit map 0 format */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 241 | static int freq_list_bm0_set_arfcn(uint8_t *chan_list, unsigned int arfcn) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 242 | { |
| 243 | unsigned int byte, bit; |
| 244 | |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 245 | if (arfcn > 124 || arfcn < 1) { |
| 246 | LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n"); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 247 | return -EINVAL; |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 248 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 249 | |
Harald Welte | da760d3 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 250 | /* the bitmask is from 1..124, not from 0..123 */ |
| 251 | arfcn--; |
| 252 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 253 | byte = arfcn / 8; |
| 254 | bit = arfcn % 8; |
| 255 | |
Harald Welte | da760d3 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 256 | chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
Harald Welte | da760d3 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 261 | /* 10.5.2.13.7: Variable bit map format */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 262 | static int freq_list_bmrel_set_arfcn(uint8_t *chan_list, unsigned int arfcn) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 263 | { |
| 264 | unsigned int byte, bit; |
| 265 | unsigned int min_arfcn; |
| 266 | unsigned int bitno; |
| 267 | |
| 268 | min_arfcn = (chan_list[0] & 1) << 9; |
| 269 | min_arfcn |= chan_list[1] << 1; |
| 270 | min_arfcn |= (chan_list[2] >> 7) & 1; |
| 271 | |
| 272 | /* The lower end of our bitmaks is always implicitly included */ |
| 273 | if (arfcn == min_arfcn) |
| 274 | return 0; |
| 275 | |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 276 | if (((arfcn - min_arfcn) & 1023) > 111) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 277 | LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 278 | return -EINVAL; |
Harald Welte | 152b626 | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 279 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 280 | |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 281 | bitno = (arfcn - min_arfcn) & 1023; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 282 | byte = bitno / 8; |
| 283 | bit = bitno % 8; |
| 284 | |
| 285 | chan_list[2 + byte] |= 1 << (7 - bit); |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 290 | /* generate a variable bitmap */ |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 291 | static inline int enc_freq_lst_var_bitmap(uint8_t *chan_list, |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 292 | struct bitvec *bv, const struct gsm_bts *bts, |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 293 | bool bis, bool ter, int min, bool pgsm) |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 294 | { |
| 295 | int i; |
| 296 | |
| 297 | /* set it to 'Variable bitmap format' */ |
| 298 | chan_list[0] = 0x8e; |
| 299 | |
| 300 | chan_list[0] |= (min >> 9) & 1; |
| 301 | chan_list[1] = (min >> 1); |
| 302 | chan_list[2] = (min & 1) << 7; |
| 303 | |
| 304 | for (i = 0; i < bv->data_len*8; i++) { |
| 305 | /* see notes in bitvec2freq_list */ |
| 306 | if (bitvec_get_bit_pos(bv, i) |
Harald Welte | e18f78e | 2015-09-04 06:21:32 +0200 | [diff] [blame] | 307 | && ((!bis && !ter && band_compatible(bts,i)) |
| 308 | || (bis && pgsm && band_compatible(bts,i) && (i < 1 || i > 124)) |
| 309 | || (ter && !band_compatible(bts, i)))) { |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 310 | int rc = freq_list_bmrel_set_arfcn(chan_list, i); |
| 311 | if (rc < 0) |
| 312 | return rc; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /* generate a frequency list with the range 512 format */ |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 320 | static inline int enc_freq_lst_range(uint8_t *chan_list, |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 321 | struct bitvec *bv, const struct gsm_bts *bts, |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 322 | bool bis, bool ter, bool pgsm) |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 323 | { |
| 324 | int arfcns[RANGE_ENC_MAX_ARFCNS]; |
| 325 | int w[RANGE_ENC_MAX_ARFCNS]; |
| 326 | int f0_included = 0; |
| 327 | int arfcns_used = 0; |
| 328 | int i, rc, range, f0; |
| 329 | |
| 330 | /* |
| 331 | * Select ARFCNs according to the rules in bitvec2freq_list |
| 332 | */ |
| 333 | for (i = 0; i < bv->data_len * 8; ++i) { |
| 334 | /* More ARFCNs than the maximum */ |
| 335 | if (arfcns_used > ARRAY_SIZE(arfcns)) |
| 336 | return -1; |
| 337 | /* Check if we can select it? */ |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 338 | if (bitvec_get_bit_pos(bv, i) && use_arfcn(bts, bis, ter, pgsm, i)) |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 339 | arfcns[arfcns_used++] = i; |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* |
| 343 | * Check if the given list of ARFCNs can be encoded. |
| 344 | */ |
| 345 | range = range_enc_determine_range(arfcns, arfcns_used, &f0); |
| 346 | if (range == ARFCN_RANGE_INVALID) |
| 347 | return -2; |
| 348 | |
| 349 | /* |
| 350 | * Manipulate the ARFCN list according to the rules in J4 depending |
| 351 | * on the selected range. |
| 352 | */ |
Jacob Erlbeck | 45014a0 | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 353 | arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used, |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 354 | f0, &f0_included); |
| 355 | |
| 356 | memset(w, 0, sizeof(w)); |
| 357 | rc = range_enc_arfcns(range, arfcns, arfcns_used, w, 0); |
| 358 | if (rc != 0) |
| 359 | return -3; |
| 360 | |
| 361 | /* Select the range and the amount of bits needed */ |
| 362 | switch (range) { |
| 363 | case ARFCN_RANGE_128: |
| 364 | return range_enc_range128(chan_list, f0, w); |
| 365 | break; |
| 366 | case ARFCN_RANGE_256: |
| 367 | return range_enc_range256(chan_list, f0, w); |
| 368 | break; |
| 369 | case ARFCN_RANGE_512: |
| 370 | return range_enc_range512(chan_list, f0, w); |
| 371 | break; |
| 372 | case ARFCN_RANGE_1024: |
| 373 | return range_enc_range1024(chan_list, f0, f0_included, w); |
| 374 | break; |
| 375 | default: |
| 376 | return -4; |
| 377 | }; |
| 378 | } |
| 379 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 380 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 381 | static int bitvec2freq_list(uint8_t *chan_list, struct bitvec *bv, |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 382 | const struct gsm_bts *bts, bool bis, bool ter) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 383 | { |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 384 | int i, rc, min = -1, max = -1, arfcns = 0; |
| 385 | bool pgsm = false; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 386 | memset(chan_list, 0, 16); |
| 387 | |
Harald Welte | 2935034 | 2012-02-17 15:58:23 +0100 | [diff] [blame] | 388 | if (bts->band == GSM_BAND_900 |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 389 | && bts->c0->arfcn >= 1 && bts->c0->arfcn <= 124) |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 390 | pgsm = true; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 391 | /* P-GSM-only handsets only support 'bit map 0 format' */ |
| 392 | if (!bis && !ter && pgsm) { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 393 | chan_list[0] = 0; |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 394 | |
| 395 | for (i = 0; i < bv->data_len*8; i++) { |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 396 | if (i >= 1 && i <= 124 |
| 397 | && bitvec_get_bit_pos(bv, i)) { |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 398 | rc = freq_list_bm0_set_arfcn(chan_list, i); |
| 399 | if (rc < 0) |
| 400 | return rc; |
| 401 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 406 | for (i = 0; i < bv->data_len*8; i++) { |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 407 | /* in case of SI2 or SI5 allow all neighbours in same band |
| 408 | * in case of SI*bis, allow neighbours in same band ouside pgsm |
| 409 | * in case of SI*ter, allow neighbours in different bands |
| 410 | */ |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 411 | if (!bitvec_get_bit_pos(bv, i)) |
| 412 | continue; |
| 413 | if (!use_arfcn(bts, bis, ter, pgsm, i)) |
| 414 | continue; |
| 415 | /* count the arfcns we want to carry */ |
| 416 | arfcns += 1; |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 417 | |
Holger Hans Peter Freyther | 9e1952a | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 418 | /* 955..1023 < 0..885 */ |
| 419 | if (min < 0) |
| 420 | min = i; |
| 421 | if (i >= 955 && min < 955) |
| 422 | min = i; |
| 423 | if (i >= 955 && min >= 955 && i < min) |
| 424 | min = i; |
| 425 | if (i < 955 && min < 955 && i < min) |
| 426 | min = i; |
| 427 | if (max < 0) |
| 428 | max = i; |
| 429 | if (i < 955 && max >= 955) |
| 430 | max = i; |
| 431 | if (i >= 955 && max >= 955 && i > max) |
| 432 | max = i; |
| 433 | if (i < 955 && max < 955 && i > max) |
| 434 | max = i; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 435 | } |
| 436 | |
Sylvain Munaut | 42a5652 | 2009-12-24 14:20:19 +0100 | [diff] [blame] | 437 | if (max == -1) { |
| 438 | /* Empty set, use 'bit map 0 format' */ |
| 439 | chan_list[0] = 0; |
| 440 | return 0; |
| 441 | } |
| 442 | |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 443 | /* Now find the best encoding */ |
| 444 | if (((max - min) & 1023) <= 111) |
| 445 | return enc_freq_lst_var_bitmap(chan_list, bv, bts, bis, |
| 446 | ter, min, pgsm); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 447 | |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 448 | /* Attempt to do the range encoding */ |
| 449 | rc = enc_freq_lst_range(chan_list, bv, bts, bis, ter, pgsm); |
| 450 | if (rc == 0) |
| 451 | return 0; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 452 | |
Holger Hans Peter Freyther | 511f9c3 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 453 | LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, arfcns=%d " |
| 454 | "can not generate ARFCN list", min, max, arfcns); |
| 455 | return -EINVAL; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Dieter Spaar | 1664602 | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 459 | /* static*/ int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 460 | { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 461 | struct gsm_bts_trx *trx; |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 462 | struct bitvec *bv = &bts->si_common.cell_alloc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 463 | |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 464 | /* Zero-initialize the bit-vector */ |
Harald Welte | c8794b5 | 2010-06-16 11:09:18 +0200 | [diff] [blame] | 465 | memset(bv->data, 0, bv->data_len); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 466 | |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 467 | /* first we generate a bitvec of all TRX ARFCN's in our BTS */ |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 468 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 469 | unsigned int i, j; |
| 470 | /* Always add the TRX's ARFCN */ |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 471 | bitvec_set_bit_pos(bv, trx->arfcn, 1); |
Harald Welte | a39b0f2 | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 472 | for (i = 0; i < ARRAY_SIZE(trx->ts); i++) { |
| 473 | struct gsm_bts_trx_ts *ts = &trx->ts[i]; |
| 474 | /* Add any ARFCNs present in hopping channels */ |
| 475 | for (j = 0; j < 1024; j++) { |
| 476 | if (bitvec_get_bit_pos(&ts->hopping.arfcns, j)) |
| 477 | bitvec_set_bit_pos(bv, j, 1); |
| 478 | } |
| 479 | } |
| 480 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 481 | |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 482 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 483 | return bitvec2freq_list(chan_list, bv, bts, false, false); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 484 | } |
| 485 | |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 486 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 487 | static int generate_bcch_chan_list(uint8_t *chan_list, struct gsm_bts *bts, |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 488 | bool si5, bool bis, bool ter) |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 489 | { |
| 490 | struct gsm_bts *cur_bts; |
Harald Welte | 64c07d2 | 2011-02-15 11:43:27 +0100 | [diff] [blame] | 491 | struct bitvec *bv; |
| 492 | |
| 493 | if (si5 && bts->neigh_list_manual_mode == NL_MODE_MANUAL_SI5SEP) |
| 494 | bv = &bts->si_common.si5_neigh_list; |
| 495 | else |
| 496 | bv = &bts->si_common.neigh_list; |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 497 | |
Harald Welte | 32c0962 | 2011-01-11 23:44:56 +0100 | [diff] [blame] | 498 | /* Generate list of neighbor cells if we are in automatic mode */ |
Harald Welte | 64c07d2 | 2011-02-15 11:43:27 +0100 | [diff] [blame] | 499 | if (bts->neigh_list_manual_mode == NL_MODE_AUTOMATIC) { |
Harald Welte | 21bbda2 | 2011-02-19 20:43:37 +0100 | [diff] [blame] | 500 | /* Zero-initialize the bit-vector */ |
| 501 | memset(bv->data, 0, bv->data_len); |
| 502 | |
Harald Welte | 32c0962 | 2011-01-11 23:44:56 +0100 | [diff] [blame] | 503 | /* first we generate a bitvec of the BCCH ARFCN's in our BSC */ |
| 504 | llist_for_each_entry(cur_bts, &bts->network->bts_list, list) { |
| 505 | if (cur_bts == bts) |
| 506 | continue; |
| 507 | bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1); |
| 508 | } |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 512 | return bitvec2freq_list(chan_list, bv, bts, bis, ter); |
| 513 | } |
| 514 | |
| 515 | static int list_arfcn(uint8_t *chan_list, uint8_t mask, char *text) |
| 516 | { |
| 517 | int n = 0, i; |
| 518 | struct gsm_sysinfo_freq freq[1024]; |
| 519 | |
| 520 | memset(freq, 0, sizeof(freq)); |
| 521 | gsm48_decode_freq_list(freq, chan_list, 16, 0xce, 1); |
| 522 | for (i = 0; i < 1024; i++) { |
| 523 | if (freq[i].mask) { |
| 524 | if (!n) |
| 525 | LOGP(DRR, LOGL_INFO, "%s", text); |
| 526 | LOGPC(DRR, LOGL_INFO, " %d", i); |
| 527 | n++; |
| 528 | } |
| 529 | } |
| 530 | if (n) |
| 531 | LOGPC(DRR, LOGL_INFO, "\n"); |
| 532 | |
| 533 | return n; |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 534 | } |
| 535 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 536 | static int generate_si1(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 537 | { |
| 538 | int rc; |
| 539 | struct gsm48_system_information_type_1 *si1 = |
| 540 | (struct gsm48_system_information_type_1 *) output; |
| 541 | |
| 542 | memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 543 | |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 544 | si1->header.l2_plen = GSM48_LEN2PLEN(21); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 545 | si1->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 546 | si1->header.skip_indicator = 0; |
| 547 | si1->header.system_information = GSM48_MT_RR_SYSINFO_1; |
| 548 | |
| 549 | rc = generate_cell_chan_list(si1->cell_channel_description, bts); |
| 550 | if (rc < 0) |
| 551 | return rc; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 552 | list_arfcn(si1->cell_channel_description, 0xce, "Serving cell:"); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 553 | |
| 554 | si1->rach_control = bts->si_common.rach_control; |
| 555 | |
Holger Hans Peter Freyther | f876c39 | 2013-03-06 12:02:33 +0100 | [diff] [blame] | 556 | /* |
| 557 | * SI1 Rest Octets (10.5.2.32), contains NCH position and band |
| 558 | * indicator but that is not in the 04.08. |
| 559 | */ |
| 560 | rc = rest_octets_si1(si1->rest_octets, NULL, is_dcs_net(bts)); |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 561 | |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 562 | return sizeof(*si1) + rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 563 | } |
| 564 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 565 | static int generate_si2(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 566 | { |
| 567 | int rc; |
| 568 | struct gsm48_system_information_type_2 *si2 = |
| 569 | (struct gsm48_system_information_type_2 *) output; |
| 570 | |
| 571 | memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 572 | |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 573 | si2->header.l2_plen = GSM48_LEN2PLEN(22); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 574 | si2->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 575 | si2->header.skip_indicator = 0; |
| 576 | si2->header.system_information = GSM48_MT_RR_SYSINFO_2; |
| 577 | |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 578 | rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts, false, false, false); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 579 | if (rc < 0) |
| 580 | return rc; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 581 | list_arfcn(si2->bcch_frequency_list, 0xce, |
Harald Welte | e5ba92e | 2015-09-04 06:22:46 +0200 | [diff] [blame] | 582 | "SI2 Neighbour cells in same band:"); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 583 | |
| 584 | si2->ncc_permitted = bts->si_common.ncc_permitted; |
| 585 | si2->rach_control = bts->si_common.rach_control; |
| 586 | |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 587 | return sizeof(*si2); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 588 | } |
| 589 | |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 590 | static int generate_si2bis(uint8_t *output, struct gsm_bts *bts) |
| 591 | { |
| 592 | int rc; |
| 593 | struct gsm48_system_information_type_2bis *si2b = |
| 594 | (struct gsm48_system_information_type_2bis *) output; |
| 595 | int n; |
| 596 | |
| 597 | memset(si2b, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 598 | |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 599 | si2b->header.l2_plen = GSM48_LEN2PLEN(22); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 600 | si2b->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 601 | si2b->header.skip_indicator = 0; |
| 602 | si2b->header.system_information = GSM48_MT_RR_SYSINFO_2bis; |
| 603 | |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 604 | rc = generate_bcch_chan_list(si2b->bcch_frequency_list, bts, false, true, false); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 605 | if (rc < 0) |
| 606 | return rc; |
| 607 | n = list_arfcn(si2b->bcch_frequency_list, 0xce, |
| 608 | "Neighbour cells in same band, but outside P-GSM:"); |
| 609 | if (n) { |
| 610 | /* indicate in SI2 and SI2bis: there is an extension */ |
| 611 | struct gsm48_system_information_type_2 *si2 = |
| 612 | (struct gsm48_system_information_type_2 *) |
| 613 | bts->si_buf[SYSINFO_TYPE_2]; |
| 614 | si2->bcch_frequency_list[0] |= 0x20; |
| 615 | si2b->bcch_frequency_list[0] |= 0x20; |
| 616 | } else |
| 617 | bts->si_valid &= ~(1 << SYSINFO_TYPE_2bis); |
| 618 | |
| 619 | si2b->rach_control = bts->si_common.rach_control; |
| 620 | |
| 621 | return sizeof(*si2b); |
| 622 | } |
| 623 | |
| 624 | static int generate_si2ter(uint8_t *output, struct gsm_bts *bts) |
| 625 | { |
| 626 | int rc; |
| 627 | struct gsm48_system_information_type_2ter *si2t = |
| 628 | (struct gsm48_system_information_type_2ter *) output; |
| 629 | int n; |
| 630 | |
| 631 | memset(si2t, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 632 | |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 633 | si2t->header.l2_plen = GSM48_LEN2PLEN(22); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 634 | si2t->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 635 | si2t->header.skip_indicator = 0; |
| 636 | si2t->header.system_information = GSM48_MT_RR_SYSINFO_2ter; |
| 637 | |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 638 | rc = generate_bcch_chan_list(si2t->ext_bcch_frequency_list, bts, false, false, true); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 639 | if (rc < 0) |
| 640 | return rc; |
| 641 | n = list_arfcn(si2t->ext_bcch_frequency_list, 0x8e, |
| 642 | "Neighbour cells in different band:"); |
| 643 | if (!n) |
| 644 | bts->si_valid &= ~(1 << SYSINFO_TYPE_2ter); |
| 645 | |
| 646 | return sizeof(*si2t); |
| 647 | } |
| 648 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 649 | static int generate_si2quater(uint8_t *output, struct gsm_bts *bts) |
| 650 | { |
Max | 69e9c0d | 2016-05-18 13:04:47 +0200 | [diff] [blame] | 651 | int rc, i = MAX_EARFCN_LIST; |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 652 | struct gsm48_system_information_type_2quater *si2q = |
| 653 | (struct gsm48_system_information_type_2quater *) output; |
| 654 | |
| 655 | memset(si2q, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 656 | |
| 657 | si2q->header.l2_plen = GSM48_LEN2PLEN(22); |
| 658 | si2q->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 659 | si2q->header.skip_indicator = 0; |
| 660 | si2q->header.system_information = GSM48_MT_RR_SYSINFO_2quater; |
| 661 | |
| 662 | rc = rest_octets_si2quater(si2q->rest_octets, |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 663 | &bts->si_common.si2quater_neigh_list, |
| 664 | bts->si_common.data.uarfcn_list, |
| 665 | bts->si_common.data.scramble_list, |
| 666 | bts->si_common.uarfcn_length); |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 667 | if (rc < 0) |
| 668 | return rc; |
| 669 | |
Max | 69e9c0d | 2016-05-18 13:04:47 +0200 | [diff] [blame] | 670 | if (bts->si_common.si2quater_neigh_list.arfcn) |
| 671 | for (i = 0; i < MAX_EARFCN_LIST; i++) |
| 672 | if (bts->si_common.si2quater_neigh_list.arfcn[i] != |
| 673 | OSMO_EARFCN_INVALID) |
| 674 | break; |
| 675 | if (!bts->si_common.uarfcn_length && i == MAX_EARFCN_LIST) |
| 676 | bts->si_valid &= ~(1 << SYSINFO_TYPE_2quater); |
| 677 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 678 | return sizeof(*si2q) + rc; |
| 679 | } |
| 680 | |
Harald Welte | 1f89329 | 2010-03-14 23:46:48 +0800 | [diff] [blame] | 681 | static struct gsm48_si_ro_info si_info = { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 682 | .selection_params = { |
| 683 | .present = 0, |
| 684 | }, |
| 685 | .power_offset = { |
| 686 | .present = 0, |
| 687 | }, |
| 688 | .si2ter_indicator = 0, |
| 689 | .early_cm_ctrl = 1, |
| 690 | .scheduling = { |
| 691 | .present = 0, |
| 692 | }, |
| 693 | .gprs_ind = { |
| 694 | .si13_position = 0, |
| 695 | .ra_colour = 0, |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 696 | .present = 1, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 697 | }, |
Max | f3f3505 | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 698 | .si2quater_indicator = 0, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 699 | .lsa_params = { |
| 700 | .present = 0, |
| 701 | }, |
| 702 | .cell_id = 0, /* FIXME: doesn't the bts have this? */ |
| 703 | .break_ind = 0, |
| 704 | }; |
| 705 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 706 | static int generate_si3(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 707 | { |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 708 | int rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 709 | struct gsm48_system_information_type_3 *si3 = |
| 710 | (struct gsm48_system_information_type_3 *) output; |
| 711 | |
| 712 | memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 713 | |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 714 | si3->header.l2_plen = GSM48_LEN2PLEN(18); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 715 | si3->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 716 | si3->header.skip_indicator = 0; |
| 717 | si3->header.system_information = GSM48_MT_RR_SYSINFO_3; |
| 718 | |
| 719 | si3->cell_identity = htons(bts->cell_identity); |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 720 | gsm48_generate_lai(&si3->lai, bts->network->country_code, |
| 721 | bts->network->network_code, |
| 722 | bts->location_area_code); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 723 | si3->control_channel_desc = bts->si_common.chan_desc; |
| 724 | si3->cell_options = bts->si_common.cell_options; |
| 725 | si3->cell_sel_par = bts->si_common.cell_sel_par; |
| 726 | si3->rach_control = bts->si_common.rach_control; |
| 727 | |
Max | c08ee71 | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 728 | /* allow/disallow DTXu */ |
| 729 | gsm48_set_dtx(&si3->cell_options, bts->dtxu, bts->dtxu, true); |
| 730 | |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 731 | if ((bts->si_valid & (1 << SYSINFO_TYPE_2ter))) { |
| 732 | LOGP(DRR, LOGL_INFO, "SI 2ter is included.\n"); |
| 733 | si_info.si2ter_indicator = 1; |
| 734 | } else { |
| 735 | si_info.si2ter_indicator = 0; |
| 736 | } |
Max | f3f3505 | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 737 | if ((bts->si_valid & (1 << SYSINFO_TYPE_2quater))) { |
| 738 | LOGP(DRR, LOGL_INFO, "SI 2quater is included.\n"); |
| 739 | si_info.si2quater_indicator = 1; |
| 740 | } else { |
| 741 | si_info.si2quater_indicator = 0; |
| 742 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 743 | /* SI3 Rest Octets (10.5.2.34), containing |
| 744 | CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME |
| 745 | Power Offset, 2ter Indicator, Early Classmark Sending, |
| 746 | Scheduling if and WHERE, GPRS Indicator, SI13 position */ |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 747 | rc = rest_octets_si3(si3->rest_octets, &si_info); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 748 | |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 749 | return sizeof(*si3) + rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 750 | } |
| 751 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 752 | static int generate_si4(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 753 | { |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 754 | int rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 755 | struct gsm48_system_information_type_4 *si4 = |
| 756 | (struct gsm48_system_information_type_4 *) output; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 757 | struct gsm_lchan *cbch_lchan; |
| 758 | uint8_t *restoct = si4->data; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 759 | |
| 760 | /* length of all IEs present except SI4 rest octets and l2_plen */ |
| 761 | int l2_plen = sizeof(*si4) - 1; |
| 762 | |
| 763 | memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 764 | |
| 765 | si4->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 766 | si4->header.skip_indicator = 0; |
| 767 | si4->header.system_information = GSM48_MT_RR_SYSINFO_4; |
| 768 | |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 769 | gsm48_generate_lai(&si4->lai, bts->network->country_code, |
| 770 | bts->network->network_code, |
| 771 | bts->location_area_code); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 772 | si4->cell_sel_par = bts->si_common.cell_sel_par; |
| 773 | si4->rach_control = bts->si_common.rach_control; |
| 774 | |
| 775 | /* Optional: CBCH Channel Description + CBCH Mobile Allocation */ |
Harald Welte | 142d12d | 2014-12-29 17:47:08 +0100 | [diff] [blame] | 776 | cbch_lchan = gsm_bts_get_cbch(bts); |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 777 | if (cbch_lchan) { |
| 778 | struct gsm48_chan_desc cd; |
| 779 | gsm48_lchan2chan_desc(&cd, cbch_lchan); |
Daniel Willmann | 695675f | 2014-12-30 12:10:25 +0100 | [diff] [blame] | 780 | tv_fixed_put(si4->data, GSM48_IE_CBCH_CHAN_DESC, 3, |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 781 | (uint8_t *) &cd); |
Daniel Willmann | 695675f | 2014-12-30 12:10:25 +0100 | [diff] [blame] | 782 | l2_plen += 3 + 1; |
| 783 | restoct += 3 + 1; |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 784 | /* we don't use hopping and thus don't need a CBCH MA */ |
| 785 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 786 | |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 787 | si4->header.l2_plen = GSM48_LEN2PLEN(l2_plen); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 788 | |
| 789 | /* SI4 Rest Octets (10.5.2.35), containing |
| 790 | Optional Power offset, GPRS Indicator, |
| 791 | Cell Identity, LSA ID, Selection Parameter */ |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 792 | rc = rest_octets_si4(restoct, &si_info, output + GSM_MACBLOCK_LEN - restoct); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 793 | |
Harald Welte | 30f1f37 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 794 | return l2_plen + 1 + rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 795 | } |
| 796 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 797 | static int generate_si5(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 798 | { |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 799 | struct gsm48_system_information_type_5 *si5; |
| 800 | int rc, l2_plen = 18; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 801 | |
Holger Hans Peter Freyther | 17d81e2 | 2010-01-06 07:52:55 +0100 | [diff] [blame] | 802 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 803 | |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 804 | /* ip.access nanoBTS needs l2_plen!! */ |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 805 | switch (bts->type) { |
| 806 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 807 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 808 | *output++ = GSM48_LEN2PLEN(l2_plen); |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 809 | l2_plen++; |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 810 | break; |
| 811 | default: |
| 812 | break; |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | si5 = (struct gsm48_system_information_type_5 *) output; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 816 | |
| 817 | /* l2 pseudo length, not part of msg: 18 */ |
| 818 | si5->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 819 | si5->skip_indicator = 0; |
| 820 | si5->system_information = GSM48_MT_RR_SYSINFO_5; |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 821 | rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts, true, false, false); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 822 | if (rc < 0) |
| 823 | return rc; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 824 | list_arfcn(si5->bcch_frequency_list, 0xce, |
Harald Welte | e5ba92e | 2015-09-04 06:22:46 +0200 | [diff] [blame] | 825 | "SI5 Neighbour cells in same band:"); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 826 | |
| 827 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
| 828 | return l2_plen; |
| 829 | } |
| 830 | |
| 831 | static int generate_si5bis(uint8_t *output, struct gsm_bts *bts) |
| 832 | { |
| 833 | struct gsm48_system_information_type_5bis *si5b; |
| 834 | int rc, l2_plen = 18; |
| 835 | int n; |
| 836 | |
| 837 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 838 | |
| 839 | /* ip.access nanoBTS needs l2_plen!! */ |
| 840 | switch (bts->type) { |
| 841 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 842 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 843 | *output++ = GSM48_LEN2PLEN(l2_plen); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 844 | l2_plen++; |
| 845 | break; |
| 846 | default: |
| 847 | break; |
| 848 | } |
| 849 | |
| 850 | si5b = (struct gsm48_system_information_type_5bis *) output; |
| 851 | |
| 852 | /* l2 pseudo length, not part of msg: 18 */ |
| 853 | si5b->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 854 | si5b->skip_indicator = 0; |
| 855 | si5b->system_information = GSM48_MT_RR_SYSINFO_5bis; |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 856 | rc = generate_bcch_chan_list(si5b->bcch_frequency_list, bts, true, true, false); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 857 | if (rc < 0) |
| 858 | return rc; |
| 859 | n = list_arfcn(si5b->bcch_frequency_list, 0xce, |
| 860 | "Neighbour cells in same band, but outside P-GSM:"); |
| 861 | if (n) { |
| 862 | /* indicate in SI5 and SI5bis: there is an extension */ |
| 863 | struct gsm48_system_information_type_5 *si5 = |
| 864 | (struct gsm48_system_information_type_5 *) |
| 865 | bts->si_buf[SYSINFO_TYPE_5]; |
| 866 | si5->bcch_frequency_list[0] |= 0x20; |
| 867 | si5b->bcch_frequency_list[0] |= 0x20; |
| 868 | } else |
| 869 | bts->si_valid &= ~(1 << SYSINFO_TYPE_5bis); |
| 870 | |
| 871 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
| 872 | return l2_plen; |
| 873 | } |
| 874 | |
| 875 | static int generate_si5ter(uint8_t *output, struct gsm_bts *bts) |
| 876 | { |
| 877 | struct gsm48_system_information_type_5ter *si5t; |
| 878 | int rc, l2_plen = 18; |
| 879 | int n; |
| 880 | |
| 881 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 882 | |
| 883 | /* ip.access nanoBTS needs l2_plen!! */ |
| 884 | switch (bts->type) { |
| 885 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 886 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 887 | *output++ = GSM48_LEN2PLEN(l2_plen); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 888 | l2_plen++; |
| 889 | break; |
| 890 | default: |
| 891 | break; |
| 892 | } |
| 893 | |
| 894 | si5t = (struct gsm48_system_information_type_5ter *) output; |
| 895 | |
| 896 | /* l2 pseudo length, not part of msg: 18 */ |
| 897 | si5t->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 898 | si5t->skip_indicator = 0; |
| 899 | si5t->system_information = GSM48_MT_RR_SYSINFO_5ter; |
Max | 5fa7e36 | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 900 | rc = generate_bcch_chan_list(si5t->bcch_frequency_list, bts, true, false, true); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 901 | if (rc < 0) |
| 902 | return rc; |
| 903 | n = list_arfcn(si5t->bcch_frequency_list, 0x8e, |
| 904 | "Neighbour cells in different band:"); |
| 905 | if (!n) |
| 906 | bts->si_valid &= ~(1 << SYSINFO_TYPE_5ter); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 907 | |
| 908 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 909 | return l2_plen; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 910 | } |
| 911 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 912 | static int generate_si6(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 913 | { |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 914 | struct gsm48_system_information_type_6 *si6; |
| 915 | int l2_plen = 11; |
Holger Hans Peter Freyther | 82dd983 | 2016-05-17 23:20:03 +0200 | [diff] [blame] | 916 | int rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 917 | |
Holger Hans Peter Freyther | 17d81e2 | 2010-01-06 07:52:55 +0100 | [diff] [blame] | 918 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 919 | |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 920 | /* ip.access nanoBTS needs l2_plen!! */ |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 921 | switch (bts->type) { |
| 922 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | f383aa1 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 923 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Max | 2440f49 | 2016-12-07 18:03:03 +0100 | [diff] [blame] | 924 | *output++ = GSM48_LEN2PLEN(l2_plen); |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 925 | l2_plen++; |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 926 | break; |
| 927 | default: |
| 928 | break; |
Harald Welte | e2d0d5f | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | si6 = (struct gsm48_system_information_type_6 *) output; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 932 | |
| 933 | /* l2 pseudo length, not part of msg: 11 */ |
| 934 | si6->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 935 | si6->skip_indicator = 0; |
| 936 | si6->system_information = GSM48_MT_RR_SYSINFO_6; |
| 937 | si6->cell_identity = htons(bts->cell_identity); |
Harald Welte | afedeab | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 938 | gsm48_generate_lai(&si6->lai, bts->network->country_code, |
| 939 | bts->network->network_code, |
| 940 | bts->location_area_code); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 941 | si6->cell_options = bts->si_common.cell_options; |
| 942 | si6->ncc_permitted = bts->si_common.ncc_permitted; |
Max | c08ee71 | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 943 | /* allow/disallow DTXu */ |
Max | ea8e983 | 2016-05-23 17:28:13 +0200 | [diff] [blame] | 944 | gsm48_set_dtx(&si6->cell_options, bts->dtxu, bts->dtxu, false); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 945 | |
| 946 | /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */ |
Holger Hans Peter Freyther | 82dd983 | 2016-05-17 23:20:03 +0200 | [diff] [blame] | 947 | rc = rest_octets_si6(si6->rest_octets, is_dcs_net(bts)); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 948 | |
Holger Hans Peter Freyther | 82dd983 | 2016-05-17 23:20:03 +0200 | [diff] [blame] | 949 | return l2_plen + rc; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static struct gsm48_si13_info si13_default = { |
| 953 | .cell_opts = { |
Harald Welte | 8584918 | 2010-06-02 12:19:21 +0200 | [diff] [blame] | 954 | .nmo = GPRS_NMO_II, |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 955 | .t3168 = 2000, |
Andreas Eversberg | becc89a | 2012-09-23 08:14:51 +0200 | [diff] [blame] | 956 | .t3192 = 1500, |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 957 | .drx_timer_max = 3, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 958 | .bs_cv_max = 15, |
Max | 292ec58 | 2016-07-28 11:55:37 +0200 | [diff] [blame] | 959 | .ctrl_ack_type_use_block = true, |
Sylvain Munaut | 851f120 | 2011-10-17 13:56:02 +0200 | [diff] [blame] | 960 | .ext_info_present = 0, |
bhargava | 350533c | 2016-07-21 11:14:34 +0530 | [diff] [blame] | 961 | .supports_egprs_11bit_rach = 0, |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 962 | .ext_info = { |
| 963 | /* The values below are just guesses ! */ |
Harald Welte | a06fea0 | 2010-04-18 15:53:40 +0200 | [diff] [blame] | 964 | .egprs_supported = 0, |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 965 | .use_egprs_p_ch_req = 1, |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 966 | .bep_period = 5, |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 967 | .pfc_supported = 0, |
| 968 | .dtm_supported = 0, |
| 969 | .bss_paging_coordination = 0, |
| 970 | }, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 971 | }, |
| 972 | .pwr_ctrl_pars = { |
Harald Welte | c15d0ac | 2012-10-08 21:22:08 +0200 | [diff] [blame] | 973 | .alpha = 0, /* a = 0.0 */ |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 974 | .t_avg_w = 16, |
| 975 | .t_avg_t = 16, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 976 | .pc_meas_chan = 0, /* downling measured on CCCH */ |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 977 | .n_avg_i = 8, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 978 | }, |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 979 | .bcch_change_mark = 1, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 980 | .si_change_field = 0, |
| 981 | .pbcch_present = 0, |
| 982 | { |
| 983 | .no_pbcch = { |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 984 | .rac = 0, /* needs to be patched */ |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 985 | .spgc_ccch_sup = 0, |
| 986 | .net_ctrl_ord = 0, |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 987 | .prio_acc_thr = 6, |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 988 | }, |
| 989 | }, |
| 990 | }; |
| 991 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 992 | static int generate_si13(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 993 | { |
| 994 | struct gsm48_system_information_type_13 *si13 = |
| 995 | (struct gsm48_system_information_type_13 *) output; |
| 996 | int ret; |
| 997 | |
| 998 | memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 999 | |
| 1000 | si13->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 1001 | si13->header.skip_indicator = 0; |
| 1002 | si13->header.system_information = GSM48_MT_RR_SYSINFO_13; |
| 1003 | |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 1004 | si13_default.no_pbcch.rac = bts->gprs.rac; |
Andreas Eversberg | 0c8f9ca | 2013-03-16 16:31:26 +0100 | [diff] [blame] | 1005 | si13_default.no_pbcch.net_ctrl_ord = bts->gprs.net_ctrl_ord; |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 1006 | |
Max | 292ec58 | 2016-07-28 11:55:37 +0200 | [diff] [blame] | 1007 | si13_default.cell_opts.ctrl_ack_type_use_block = |
| 1008 | bts->gprs.ctrl_ack_type_use_block; |
| 1009 | |
Holger Hans Peter Freyther | b92a538 | 2014-11-21 10:00:39 +0100 | [diff] [blame] | 1010 | /* Information about the other SIs */ |
| 1011 | si13_default.bcch_change_mark = bts->bcch_change_mark; |
bhargava | 350533c | 2016-07-21 11:14:34 +0530 | [diff] [blame] | 1012 | si13_default.cell_opts.supports_egprs_11bit_rach = |
| 1013 | bts->gprs.supports_egprs_11bit_rach; |
Holger Hans Peter Freyther | b92a538 | 2014-11-21 10:00:39 +0100 | [diff] [blame] | 1014 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1015 | ret = rest_octets_si13(si13->rest_octets, &si13_default); |
| 1016 | if (ret < 0) |
| 1017 | return ret; |
| 1018 | |
Holger Hans Peter Freyther | 1c6f394 | 2010-06-16 12:05:56 +0800 | [diff] [blame] | 1019 | /* length is coded in bit 2 an up */ |
| 1020 | si13->header.l2_plen = 0x01; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1021 | |
Holger Hans Peter Freyther | 7ec448d | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 1022 | return sizeof (*si13) + ret; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1023 | } |
| 1024 | |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 1025 | typedef int (*gen_si_fn_t)(uint8_t *output, struct gsm_bts *bts); |
| 1026 | |
| 1027 | static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = { |
| 1028 | [SYSINFO_TYPE_1] = &generate_si1, |
| 1029 | [SYSINFO_TYPE_2] = &generate_si2, |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 1030 | [SYSINFO_TYPE_2bis] = &generate_si2bis, |
| 1031 | [SYSINFO_TYPE_2ter] = &generate_si2ter, |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 1032 | [SYSINFO_TYPE_2quater] = &generate_si2quater, |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 1033 | [SYSINFO_TYPE_3] = &generate_si3, |
| 1034 | [SYSINFO_TYPE_4] = &generate_si4, |
| 1035 | [SYSINFO_TYPE_5] = &generate_si5, |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 1036 | [SYSINFO_TYPE_5bis] = &generate_si5bis, |
| 1037 | [SYSINFO_TYPE_5ter] = &generate_si5ter, |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 1038 | [SYSINFO_TYPE_6] = &generate_si6, |
| 1039 | [SYSINFO_TYPE_13] = &generate_si13, |
| 1040 | }; |
| 1041 | |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 1042 | int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type) |
| 1043 | { |
| 1044 | gen_si_fn_t gen_si; |
| 1045 | |
Harald Welte | 4511d89 | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 1046 | switch (bts->gprs.mode) { |
| 1047 | case BTS_GPRS_EGPRS: |
Harald Welte | a06fea0 | 2010-04-18 15:53:40 +0200 | [diff] [blame] | 1048 | si13_default.cell_opts.ext_info_present = 1; |
| 1049 | si13_default.cell_opts.ext_info.egprs_supported = 1; |
| 1050 | /* fallthrough */ |
Harald Welte | 4511d89 | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 1051 | case BTS_GPRS_GPRS: |
| 1052 | si_info.gprs_ind.present = 1; |
| 1053 | break; |
| 1054 | case BTS_GPRS_NONE: |
| 1055 | si_info.gprs_ind.present = 0; |
| 1056 | break; |
| 1057 | } |
Harald Welte | 1f89329 | 2010-03-14 23:46:48 +0800 | [diff] [blame] | 1058 | |
Sylvain Munaut | e0b06b0 | 2010-11-28 18:17:28 +0100 | [diff] [blame] | 1059 | memcpy(&si_info.selection_params, |
| 1060 | &bts->si_common.cell_ro_sel_par, |
| 1061 | sizeof(struct gsm48_si_selection_params)); |
| 1062 | |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 1063 | gen_si = gen_si_fn[si_type]; |
| 1064 | if (!gen_si) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1065 | return -EINVAL; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1066 | |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 1067 | return gen_si(bts->si_buf[si_type], bts); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1068 | } |