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