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