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