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