Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1 | /* GSM 04.08 System Information (SI) encoding and decoding |
| 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 4 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 5 | * (C) 2012 Holger Hans Peter Freyther |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 18 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <string.h> |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 26 | #include <stdio.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 27 | #include <netinet/in.h> |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 28 | #include <stdbool.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 29 | |
Harald Welte | 6b77f0f | 2011-05-24 15:02:20 +0200 | [diff] [blame] | 30 | #include <osmocom/core/bitvec.h> |
| 31 | #include <osmocom/core/utils.h> |
| 32 | #include <osmocom/gsm/sysinfo.h> |
| 33 | |
| 34 | #include <openbsc/debug.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 35 | #include <openbsc/gsm_04_08.h> |
| 36 | #include <openbsc/gsm_data.h> |
| 37 | #include <openbsc/abis_rsl.h> |
| 38 | #include <openbsc/rest_octets.h> |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 39 | #include <openbsc/arfcn_range_encode.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 40 | |
Holger Hans Peter Freyther | 59e7f2b | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 41 | /* |
| 42 | * DCS1800 and PCS1900 have overlapping ARFCNs. We would need to set the |
| 43 | * ARFCN_PCS flag on the 1900 ARFCNs but this would increase cell_alloc |
| 44 | * and other arrays to make sure (ARFCN_PCS + 1024)/8 ARFCNs fit into the |
| 45 | * array. DCS1800 and PCS1900 can not be used at the same time so conserve |
| 46 | * memory and do the below. |
| 47 | */ |
| 48 | static int band_compatible(const struct gsm_bts *bts, int arfcn) |
| 49 | { |
| 50 | enum gsm_band band = gsm_arfcn2band(arfcn); |
| 51 | |
| 52 | /* normal case */ |
| 53 | if (band == bts->band) |
| 54 | return 1; |
| 55 | /* deal with ARFCN_PCS not set */ |
| 56 | if (band == GSM_BAND_1800 && bts->band == GSM_BAND_1900) |
| 57 | return 1; |
| 58 | |
| 59 | return 0; |
| 60 | } |
Holger Hans Peter Freyther | 8526b15 | 2010-01-06 06:38:14 +0100 | [diff] [blame] | 61 | |
Holger Hans Peter Freyther | fb8f0b5 | 2013-03-06 12:02:33 +0100 | [diff] [blame] | 62 | static int is_dcs_net(const struct gsm_bts *bts) |
| 63 | { |
| 64 | if (bts->band == GSM_BAND_850) |
| 65 | return 0; |
| 66 | if (bts->band == GSM_BAND_1900) |
| 67 | return 0; |
| 68 | return 1; |
| 69 | } |
| 70 | |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 71 | static inline int use_arfcn(const struct gsm_bts *bts, const bool bis, const bool ter, |
| 72 | const bool pgsm, const int arfcn) |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 73 | { |
Jacob Erlbeck | 8f8e5bf | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 74 | if (bts->force_combined_si) |
| 75 | return !bis && !ter; |
Holger Hans Peter Freyther | 59e7f2b | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 76 | if (!bis && !ter && band_compatible(bts, arfcn)) |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 77 | return 1; |
Jacob Erlbeck | 8f8e5bf | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 78 | /* Correct but somehow broken with either the nanoBTS or the iPhone5 */ |
Holger Hans Peter Freyther | 59e7f2b | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 79 | if (bis && pgsm && band_compatible(bts, arfcn) && (arfcn < 1 || arfcn > 124)) |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 80 | return 1; |
Holger Hans Peter Freyther | 59e7f2b | 2013-01-17 13:49:39 +0100 | [diff] [blame] | 81 | if (ter && !band_compatible(bts, arfcn)) |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 82 | return 1; |
| 83 | return 0; |
| 84 | } |
| 85 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 86 | /* Frequency Lists as per TS 04.08 10.5.2.13 */ |
| 87 | |
| 88 | /* 10.5.2.13.2: Bit map 0 format */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 89 | static int freq_list_bm0_set_arfcn(uint8_t *chan_list, unsigned int arfcn) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 90 | { |
| 91 | unsigned int byte, bit; |
| 92 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 93 | if (arfcn > 124 || arfcn < 1) { |
| 94 | LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n"); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 95 | return -EINVAL; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 96 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 97 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 98 | /* the bitmask is from 1..124, not from 0..123 */ |
| 99 | arfcn--; |
| 100 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 101 | byte = arfcn / 8; |
| 102 | bit = arfcn % 8; |
| 103 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 104 | chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 109 | /* 10.5.2.13.7: Variable bit map format */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 110 | static int freq_list_bmrel_set_arfcn(uint8_t *chan_list, unsigned int arfcn) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 111 | { |
| 112 | unsigned int byte, bit; |
| 113 | unsigned int min_arfcn; |
| 114 | unsigned int bitno; |
| 115 | |
| 116 | min_arfcn = (chan_list[0] & 1) << 9; |
| 117 | min_arfcn |= chan_list[1] << 1; |
| 118 | min_arfcn |= (chan_list[2] >> 7) & 1; |
| 119 | |
| 120 | /* The lower end of our bitmaks is always implicitly included */ |
| 121 | if (arfcn == min_arfcn) |
| 122 | return 0; |
| 123 | |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 124 | if (((arfcn - min_arfcn) & 1023) > 111) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 125 | LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 126 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 127 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 128 | |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 129 | bitno = (arfcn - min_arfcn) & 1023; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 130 | byte = bitno / 8; |
| 131 | bit = bitno % 8; |
| 132 | |
| 133 | chan_list[2 + byte] |= 1 << (7 - bit); |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 138 | /* generate a variable bitmap */ |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 139 | static inline int enc_freq_lst_var_bitmap(uint8_t *chan_list, |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 140 | struct bitvec *bv, const struct gsm_bts *bts, |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 141 | bool bis, bool ter, int min, bool pgsm) |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 142 | { |
| 143 | int i; |
| 144 | |
| 145 | /* set it to 'Variable bitmap format' */ |
| 146 | chan_list[0] = 0x8e; |
| 147 | |
| 148 | chan_list[0] |= (min >> 9) & 1; |
| 149 | chan_list[1] = (min >> 1); |
| 150 | chan_list[2] = (min & 1) << 7; |
| 151 | |
| 152 | for (i = 0; i < bv->data_len*8; i++) { |
| 153 | /* see notes in bitvec2freq_list */ |
| 154 | if (bitvec_get_bit_pos(bv, i) |
Harald Welte | 92e1026 | 2015-09-04 06:21:32 +0200 | [diff] [blame] | 155 | && ((!bis && !ter && band_compatible(bts,i)) |
| 156 | || (bis && pgsm && band_compatible(bts,i) && (i < 1 || i > 124)) |
| 157 | || (ter && !band_compatible(bts, i)))) { |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 158 | int rc = freq_list_bmrel_set_arfcn(chan_list, i); |
| 159 | if (rc < 0) |
| 160 | return rc; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* generate a frequency list with the range 512 format */ |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 168 | static inline int enc_freq_lst_range(uint8_t *chan_list, |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 169 | struct bitvec *bv, const struct gsm_bts *bts, |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 170 | bool bis, bool ter, bool pgsm) |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 171 | { |
| 172 | int arfcns[RANGE_ENC_MAX_ARFCNS]; |
| 173 | int w[RANGE_ENC_MAX_ARFCNS]; |
| 174 | int f0_included = 0; |
| 175 | int arfcns_used = 0; |
| 176 | int i, rc, range, f0; |
| 177 | |
| 178 | /* |
| 179 | * Select ARFCNs according to the rules in bitvec2freq_list |
| 180 | */ |
| 181 | for (i = 0; i < bv->data_len * 8; ++i) { |
| 182 | /* More ARFCNs than the maximum */ |
| 183 | if (arfcns_used > ARRAY_SIZE(arfcns)) |
| 184 | return -1; |
| 185 | /* Check if we can select it? */ |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 186 | if (bitvec_get_bit_pos(bv, i) && use_arfcn(bts, bis, ter, pgsm, i)) |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 187 | arfcns[arfcns_used++] = i; |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Check if the given list of ARFCNs can be encoded. |
| 192 | */ |
| 193 | range = range_enc_determine_range(arfcns, arfcns_used, &f0); |
| 194 | if (range == ARFCN_RANGE_INVALID) |
| 195 | return -2; |
| 196 | |
| 197 | /* |
| 198 | * Manipulate the ARFCN list according to the rules in J4 depending |
| 199 | * on the selected range. |
| 200 | */ |
Jacob Erlbeck | 7be3fea | 2014-01-14 10:42:58 +0100 | [diff] [blame] | 201 | arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used, |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 202 | f0, &f0_included); |
| 203 | |
| 204 | memset(w, 0, sizeof(w)); |
| 205 | rc = range_enc_arfcns(range, arfcns, arfcns_used, w, 0); |
| 206 | if (rc != 0) |
| 207 | return -3; |
| 208 | |
| 209 | /* Select the range and the amount of bits needed */ |
| 210 | switch (range) { |
| 211 | case ARFCN_RANGE_128: |
| 212 | return range_enc_range128(chan_list, f0, w); |
| 213 | break; |
| 214 | case ARFCN_RANGE_256: |
| 215 | return range_enc_range256(chan_list, f0, w); |
| 216 | break; |
| 217 | case ARFCN_RANGE_512: |
| 218 | return range_enc_range512(chan_list, f0, w); |
| 219 | break; |
| 220 | case ARFCN_RANGE_1024: |
| 221 | return range_enc_range1024(chan_list, f0, f0_included, w); |
| 222 | break; |
| 223 | default: |
| 224 | return -4; |
| 225 | }; |
| 226 | } |
| 227 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 228 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 229 | static int bitvec2freq_list(uint8_t *chan_list, struct bitvec *bv, |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 230 | const struct gsm_bts *bts, bool bis, bool ter) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 231 | { |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 232 | int i, rc, min = -1, max = -1, arfcns = 0; |
| 233 | bool pgsm = false; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 234 | memset(chan_list, 0, 16); |
| 235 | |
Harald Welte | a680b13 | 2012-02-17 15:58:23 +0100 | [diff] [blame] | 236 | if (bts->band == GSM_BAND_900 |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 237 | && bts->c0->arfcn >= 1 && bts->c0->arfcn <= 124) |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 238 | pgsm = true; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 239 | /* P-GSM-only handsets only support 'bit map 0 format' */ |
| 240 | if (!bis && !ter && pgsm) { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 241 | chan_list[0] = 0; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 242 | |
| 243 | for (i = 0; i < bv->data_len*8; i++) { |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 244 | if (i >= 1 && i <= 124 |
| 245 | && bitvec_get_bit_pos(bv, i)) { |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 246 | rc = freq_list_bm0_set_arfcn(chan_list, i); |
| 247 | if (rc < 0) |
| 248 | return rc; |
| 249 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 250 | } |
| 251 | return 0; |
| 252 | } |
| 253 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 254 | for (i = 0; i < bv->data_len*8; i++) { |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 255 | /* in case of SI2 or SI5 allow all neighbours in same band |
| 256 | * in case of SI*bis, allow neighbours in same band ouside pgsm |
| 257 | * in case of SI*ter, allow neighbours in different bands |
| 258 | */ |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 259 | if (!bitvec_get_bit_pos(bv, i)) |
| 260 | continue; |
| 261 | if (!use_arfcn(bts, bis, ter, pgsm, i)) |
| 262 | continue; |
| 263 | /* count the arfcns we want to carry */ |
| 264 | arfcns += 1; |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 265 | |
Holger Hans Peter Freyther | 2e778c7 | 2013-01-17 12:04:17 +0100 | [diff] [blame] | 266 | /* 955..1023 < 0..885 */ |
| 267 | if (min < 0) |
| 268 | min = i; |
| 269 | if (i >= 955 && min < 955) |
| 270 | min = i; |
| 271 | if (i >= 955 && min >= 955 && i < min) |
| 272 | min = i; |
| 273 | if (i < 955 && min < 955 && i < min) |
| 274 | min = i; |
| 275 | if (max < 0) |
| 276 | max = i; |
| 277 | if (i < 955 && max >= 955) |
| 278 | max = i; |
| 279 | if (i >= 955 && max >= 955 && i > max) |
| 280 | max = i; |
| 281 | if (i < 955 && max < 955 && i > max) |
| 282 | max = i; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 283 | } |
| 284 | |
Sylvain Munaut | 40f84a9 | 2009-12-24 14:20:19 +0100 | [diff] [blame] | 285 | if (max == -1) { |
| 286 | /* Empty set, use 'bit map 0 format' */ |
| 287 | chan_list[0] = 0; |
| 288 | return 0; |
| 289 | } |
| 290 | |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 291 | /* Now find the best encoding */ |
| 292 | if (((max - min) & 1023) <= 111) |
| 293 | return enc_freq_lst_var_bitmap(chan_list, bv, bts, bis, |
| 294 | ter, min, pgsm); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 295 | |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 296 | /* Attempt to do the range encoding */ |
| 297 | rc = enc_freq_lst_range(chan_list, bv, bts, bis, ter, pgsm); |
| 298 | if (rc == 0) |
| 299 | return 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 300 | |
Holger Hans Peter Freyther | a9e7de6 | 2012-10-13 12:38:54 +0200 | [diff] [blame] | 301 | LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, arfcns=%d " |
| 302 | "can not generate ARFCN list", min, max, arfcns); |
| 303 | return -EINVAL; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 307 | /* static*/ int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 308 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 309 | struct gsm_bts_trx *trx; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 310 | struct bitvec *bv = &bts->si_common.cell_alloc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 311 | |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 312 | /* Zero-initialize the bit-vector */ |
Harald Welte | 439e462 | 2010-06-16 11:09:18 +0200 | [diff] [blame] | 313 | memset(bv->data, 0, bv->data_len); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 314 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 315 | /* first we generate a bitvec of all TRX ARFCN's in our BTS */ |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 316 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 317 | unsigned int i, j; |
| 318 | /* Always add the TRX's ARFCN */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 319 | bitvec_set_bit_pos(bv, trx->arfcn, 1); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 320 | for (i = 0; i < ARRAY_SIZE(trx->ts); i++) { |
| 321 | struct gsm_bts_trx_ts *ts = &trx->ts[i]; |
| 322 | /* Add any ARFCNs present in hopping channels */ |
| 323 | for (j = 0; j < 1024; j++) { |
| 324 | if (bitvec_get_bit_pos(&ts->hopping.arfcns, j)) |
| 325 | bitvec_set_bit_pos(bv, j, 1); |
| 326 | } |
| 327 | } |
| 328 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 329 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 330 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 331 | return bitvec2freq_list(chan_list, bv, bts, false, false); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 332 | } |
| 333 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 334 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 335 | static int generate_bcch_chan_list(uint8_t *chan_list, struct gsm_bts *bts, |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 336 | bool si5, bool bis, bool ter) |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 337 | { |
| 338 | struct gsm_bts *cur_bts; |
Harald Welte | f989b78 | 2011-02-15 11:43:27 +0100 | [diff] [blame] | 339 | struct bitvec *bv; |
| 340 | |
| 341 | if (si5 && bts->neigh_list_manual_mode == NL_MODE_MANUAL_SI5SEP) |
| 342 | bv = &bts->si_common.si5_neigh_list; |
| 343 | else |
| 344 | bv = &bts->si_common.neigh_list; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 345 | |
Harald Welte | ca46eff | 2011-01-11 23:44:56 +0100 | [diff] [blame] | 346 | /* Generate list of neighbor cells if we are in automatic mode */ |
Harald Welte | f989b78 | 2011-02-15 11:43:27 +0100 | [diff] [blame] | 347 | if (bts->neigh_list_manual_mode == NL_MODE_AUTOMATIC) { |
Harald Welte | a72d91c | 2011-02-19 20:43:37 +0100 | [diff] [blame] | 348 | /* Zero-initialize the bit-vector */ |
| 349 | memset(bv->data, 0, bv->data_len); |
| 350 | |
Harald Welte | ca46eff | 2011-01-11 23:44:56 +0100 | [diff] [blame] | 351 | /* first we generate a bitvec of the BCCH ARFCN's in our BSC */ |
| 352 | llist_for_each_entry(cur_bts, &bts->network->bts_list, list) { |
| 353 | if (cur_bts == bts) |
| 354 | continue; |
| 355 | bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1); |
| 356 | } |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 360 | return bitvec2freq_list(chan_list, bv, bts, bis, ter); |
| 361 | } |
| 362 | |
| 363 | static int list_arfcn(uint8_t *chan_list, uint8_t mask, char *text) |
| 364 | { |
| 365 | int n = 0, i; |
| 366 | struct gsm_sysinfo_freq freq[1024]; |
| 367 | |
| 368 | memset(freq, 0, sizeof(freq)); |
| 369 | gsm48_decode_freq_list(freq, chan_list, 16, 0xce, 1); |
| 370 | for (i = 0; i < 1024; i++) { |
| 371 | if (freq[i].mask) { |
| 372 | if (!n) |
| 373 | LOGP(DRR, LOGL_INFO, "%s", text); |
| 374 | LOGPC(DRR, LOGL_INFO, " %d", i); |
| 375 | n++; |
| 376 | } |
| 377 | } |
| 378 | if (n) |
| 379 | LOGPC(DRR, LOGL_INFO, "\n"); |
| 380 | |
| 381 | return n; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 384 | static int generate_si1(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 385 | { |
| 386 | int rc; |
| 387 | struct gsm48_system_information_type_1 *si1 = |
| 388 | (struct gsm48_system_information_type_1 *) output; |
| 389 | |
| 390 | memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 391 | |
| 392 | si1->header.l2_plen = (21 << 2) | 1; |
| 393 | si1->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 394 | si1->header.skip_indicator = 0; |
| 395 | si1->header.system_information = GSM48_MT_RR_SYSINFO_1; |
| 396 | |
| 397 | rc = generate_cell_chan_list(si1->cell_channel_description, bts); |
| 398 | if (rc < 0) |
| 399 | return rc; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 400 | list_arfcn(si1->cell_channel_description, 0xce, "Serving cell:"); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 401 | |
| 402 | si1->rach_control = bts->si_common.rach_control; |
| 403 | |
Holger Hans Peter Freyther | fb8f0b5 | 2013-03-06 12:02:33 +0100 | [diff] [blame] | 404 | /* |
| 405 | * SI1 Rest Octets (10.5.2.32), contains NCH position and band |
| 406 | * indicator but that is not in the 04.08. |
| 407 | */ |
| 408 | rc = rest_octets_si1(si1->rest_octets, NULL, is_dcs_net(bts)); |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 409 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 410 | return sizeof(*si1) + rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 411 | } |
| 412 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 413 | static int generate_si2(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 414 | { |
| 415 | int rc; |
| 416 | struct gsm48_system_information_type_2 *si2 = |
| 417 | (struct gsm48_system_information_type_2 *) output; |
| 418 | |
| 419 | memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 420 | |
| 421 | si2->header.l2_plen = (22 << 2) | 1; |
| 422 | si2->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 423 | si2->header.skip_indicator = 0; |
| 424 | si2->header.system_information = GSM48_MT_RR_SYSINFO_2; |
| 425 | |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 426 | rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts, false, false, false); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 427 | if (rc < 0) |
| 428 | return rc; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 429 | list_arfcn(si2->bcch_frequency_list, 0xce, |
Harald Welte | 1342894 | 2015-09-04 06:22:46 +0200 | [diff] [blame] | 430 | "SI2 Neighbour cells in same band:"); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 431 | |
| 432 | si2->ncc_permitted = bts->si_common.ncc_permitted; |
| 433 | si2->rach_control = bts->si_common.rach_control; |
| 434 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 435 | return sizeof(*si2); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 438 | static int generate_si2bis(uint8_t *output, struct gsm_bts *bts) |
| 439 | { |
| 440 | int rc; |
| 441 | struct gsm48_system_information_type_2bis *si2b = |
| 442 | (struct gsm48_system_information_type_2bis *) output; |
| 443 | int n; |
| 444 | |
| 445 | memset(si2b, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 446 | |
| 447 | si2b->header.l2_plen = (22 << 2) | 1; |
| 448 | si2b->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 449 | si2b->header.skip_indicator = 0; |
| 450 | si2b->header.system_information = GSM48_MT_RR_SYSINFO_2bis; |
| 451 | |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 452 | rc = generate_bcch_chan_list(si2b->bcch_frequency_list, bts, false, true, false); |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 453 | if (rc < 0) |
| 454 | return rc; |
| 455 | n = list_arfcn(si2b->bcch_frequency_list, 0xce, |
| 456 | "Neighbour cells in same band, but outside P-GSM:"); |
| 457 | if (n) { |
| 458 | /* indicate in SI2 and SI2bis: there is an extension */ |
| 459 | struct gsm48_system_information_type_2 *si2 = |
| 460 | (struct gsm48_system_information_type_2 *) |
| 461 | bts->si_buf[SYSINFO_TYPE_2]; |
| 462 | si2->bcch_frequency_list[0] |= 0x20; |
| 463 | si2b->bcch_frequency_list[0] |= 0x20; |
| 464 | } else |
| 465 | bts->si_valid &= ~(1 << SYSINFO_TYPE_2bis); |
| 466 | |
| 467 | si2b->rach_control = bts->si_common.rach_control; |
| 468 | |
| 469 | return sizeof(*si2b); |
| 470 | } |
| 471 | |
| 472 | static int generate_si2ter(uint8_t *output, struct gsm_bts *bts) |
| 473 | { |
| 474 | int rc; |
| 475 | struct gsm48_system_information_type_2ter *si2t = |
| 476 | (struct gsm48_system_information_type_2ter *) output; |
| 477 | int n; |
| 478 | |
| 479 | memset(si2t, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 480 | |
| 481 | si2t->header.l2_plen = (22 << 2) | 1; |
| 482 | si2t->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 483 | si2t->header.skip_indicator = 0; |
| 484 | si2t->header.system_information = GSM48_MT_RR_SYSINFO_2ter; |
| 485 | |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 486 | rc = generate_bcch_chan_list(si2t->ext_bcch_frequency_list, bts, false, false, true); |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 487 | if (rc < 0) |
| 488 | return rc; |
| 489 | n = list_arfcn(si2t->ext_bcch_frequency_list, 0x8e, |
| 490 | "Neighbour cells in different band:"); |
| 491 | if (!n) |
| 492 | bts->si_valid &= ~(1 << SYSINFO_TYPE_2ter); |
| 493 | |
| 494 | return sizeof(*si2t); |
| 495 | } |
| 496 | |
Max | 88ddcaa | 2016-04-15 16:04:46 +0200 | [diff] [blame^] | 497 | static int generate_si2quater(uint8_t *output, struct gsm_bts *bts) |
| 498 | { |
| 499 | int rc; |
| 500 | struct gsm48_system_information_type_2quater *si2q = |
| 501 | (struct gsm48_system_information_type_2quater *) output; |
| 502 | |
| 503 | memset(si2q, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 504 | |
| 505 | si2q->header.l2_plen = GSM48_LEN2PLEN(22); |
| 506 | si2q->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 507 | si2q->header.skip_indicator = 0; |
| 508 | si2q->header.system_information = GSM48_MT_RR_SYSINFO_2quater; |
| 509 | |
| 510 | rc = rest_octets_si2quater(si2q->rest_octets, |
| 511 | &bts->si_common.si2quater_neigh_list, false, |
| 512 | true); |
| 513 | if (rc < 0) |
| 514 | return rc; |
| 515 | |
| 516 | return sizeof(*si2q) + rc; |
| 517 | } |
| 518 | |
Harald Welte | e050010 | 2010-03-14 23:46:48 +0800 | [diff] [blame] | 519 | static struct gsm48_si_ro_info si_info = { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 520 | .selection_params = { |
| 521 | .present = 0, |
| 522 | }, |
| 523 | .power_offset = { |
| 524 | .present = 0, |
| 525 | }, |
| 526 | .si2ter_indicator = 0, |
| 527 | .early_cm_ctrl = 1, |
| 528 | .scheduling = { |
| 529 | .present = 0, |
| 530 | }, |
| 531 | .gprs_ind = { |
| 532 | .si13_position = 0, |
| 533 | .ra_colour = 0, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 534 | .present = 1, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 535 | }, |
Max | cab5beb | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 536 | .si2quater_indicator = 0, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 537 | .lsa_params = { |
| 538 | .present = 0, |
| 539 | }, |
| 540 | .cell_id = 0, /* FIXME: doesn't the bts have this? */ |
| 541 | .break_ind = 0, |
| 542 | }; |
| 543 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 544 | static int generate_si3(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 545 | { |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 546 | int rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 547 | struct gsm48_system_information_type_3 *si3 = |
| 548 | (struct gsm48_system_information_type_3 *) output; |
| 549 | |
| 550 | memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 551 | |
| 552 | si3->header.l2_plen = (18 << 2) | 1; |
| 553 | si3->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 554 | si3->header.skip_indicator = 0; |
| 555 | si3->header.system_information = GSM48_MT_RR_SYSINFO_3; |
| 556 | |
| 557 | si3->cell_identity = htons(bts->cell_identity); |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 558 | gsm48_generate_lai(&si3->lai, bts->network->country_code, |
| 559 | bts->network->network_code, |
| 560 | bts->location_area_code); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 561 | si3->control_channel_desc = bts->si_common.chan_desc; |
| 562 | si3->cell_options = bts->si_common.cell_options; |
| 563 | si3->cell_sel_par = bts->si_common.cell_sel_par; |
| 564 | si3->rach_control = bts->si_common.rach_control; |
| 565 | |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 566 | if ((bts->si_valid & (1 << SYSINFO_TYPE_2ter))) { |
| 567 | LOGP(DRR, LOGL_INFO, "SI 2ter is included.\n"); |
| 568 | si_info.si2ter_indicator = 1; |
| 569 | } else { |
| 570 | si_info.si2ter_indicator = 0; |
| 571 | } |
Max | cab5beb | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 572 | if ((bts->si_valid & (1 << SYSINFO_TYPE_2quater))) { |
| 573 | LOGP(DRR, LOGL_INFO, "SI 2quater is included.\n"); |
| 574 | si_info.si2quater_indicator = 1; |
| 575 | } else { |
| 576 | si_info.si2quater_indicator = 0; |
| 577 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 578 | /* SI3 Rest Octets (10.5.2.34), containing |
| 579 | CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME |
| 580 | Power Offset, 2ter Indicator, Early Classmark Sending, |
| 581 | Scheduling if and WHERE, GPRS Indicator, SI13 position */ |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 582 | rc = rest_octets_si3(si3->rest_octets, &si_info); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 583 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 584 | return sizeof(*si3) + rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 585 | } |
| 586 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 587 | static int generate_si4(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 588 | { |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 589 | int rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 590 | struct gsm48_system_information_type_4 *si4 = |
| 591 | (struct gsm48_system_information_type_4 *) output; |
Harald Welte | bf4ba72 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 592 | struct gsm_lchan *cbch_lchan; |
| 593 | uint8_t *restoct = si4->data; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 594 | |
| 595 | /* length of all IEs present except SI4 rest octets and l2_plen */ |
| 596 | int l2_plen = sizeof(*si4) - 1; |
| 597 | |
| 598 | memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 599 | |
| 600 | si4->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 601 | si4->header.skip_indicator = 0; |
| 602 | si4->header.system_information = GSM48_MT_RR_SYSINFO_4; |
| 603 | |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 604 | gsm48_generate_lai(&si4->lai, bts->network->country_code, |
| 605 | bts->network->network_code, |
| 606 | bts->location_area_code); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 607 | si4->cell_sel_par = bts->si_common.cell_sel_par; |
| 608 | si4->rach_control = bts->si_common.rach_control; |
| 609 | |
| 610 | /* Optional: CBCH Channel Description + CBCH Mobile Allocation */ |
Harald Welte | adbd96f | 2014-12-29 17:47:08 +0100 | [diff] [blame] | 611 | cbch_lchan = gsm_bts_get_cbch(bts); |
Harald Welte | bf4ba72 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 612 | if (cbch_lchan) { |
| 613 | struct gsm48_chan_desc cd; |
| 614 | gsm48_lchan2chan_desc(&cd, cbch_lchan); |
Daniel Willmann | 1415dd1 | 2014-12-30 12:10:25 +0100 | [diff] [blame] | 615 | tv_fixed_put(si4->data, GSM48_IE_CBCH_CHAN_DESC, 3, |
Harald Welte | bf4ba72 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 616 | (uint8_t *) &cd); |
Daniel Willmann | 1415dd1 | 2014-12-30 12:10:25 +0100 | [diff] [blame] | 617 | l2_plen += 3 + 1; |
| 618 | restoct += 3 + 1; |
Harald Welte | bf4ba72 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 619 | /* we don't use hopping and thus don't need a CBCH MA */ |
| 620 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 621 | |
| 622 | si4->header.l2_plen = (l2_plen << 2) | 1; |
| 623 | |
| 624 | /* SI4 Rest Octets (10.5.2.35), containing |
| 625 | Optional Power offset, GPRS Indicator, |
| 626 | Cell Identity, LSA ID, Selection Parameter */ |
Holger Hans Peter Freyther | 667308c | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 627 | rc = rest_octets_si4(restoct, &si_info, output + GSM_MACBLOCK_LEN - restoct); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 628 | |
Harald Welte | bf4ba72 | 2014-12-28 15:00:45 +0100 | [diff] [blame] | 629 | return l2_plen + 1 + rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 630 | } |
| 631 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 632 | static int generate_si5(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 633 | { |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 634 | struct gsm48_system_information_type_5 *si5; |
| 635 | int rc, l2_plen = 18; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 636 | |
Holger Hans Peter Freyther | 4f2ace4 | 2010-01-06 07:52:55 +0100 | [diff] [blame] | 637 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 638 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 639 | /* ip.access nanoBTS needs l2_plen!! */ |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 640 | switch (bts->type) { |
| 641 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 642 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 643 | *output++ = (l2_plen << 2) | 1; |
| 644 | l2_plen++; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 645 | break; |
| 646 | default: |
| 647 | break; |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | si5 = (struct gsm48_system_information_type_5 *) output; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 651 | |
| 652 | /* l2 pseudo length, not part of msg: 18 */ |
| 653 | si5->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 654 | si5->skip_indicator = 0; |
| 655 | si5->system_information = GSM48_MT_RR_SYSINFO_5; |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 656 | rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts, true, false, false); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 657 | if (rc < 0) |
| 658 | return rc; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 659 | list_arfcn(si5->bcch_frequency_list, 0xce, |
Harald Welte | 1342894 | 2015-09-04 06:22:46 +0200 | [diff] [blame] | 660 | "SI5 Neighbour cells in same band:"); |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 661 | |
| 662 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
| 663 | return l2_plen; |
| 664 | } |
| 665 | |
| 666 | static int generate_si5bis(uint8_t *output, struct gsm_bts *bts) |
| 667 | { |
| 668 | struct gsm48_system_information_type_5bis *si5b; |
| 669 | int rc, l2_plen = 18; |
| 670 | int n; |
| 671 | |
| 672 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 673 | |
| 674 | /* ip.access nanoBTS needs l2_plen!! */ |
| 675 | switch (bts->type) { |
| 676 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 677 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 678 | *output++ = (l2_plen << 2) | 1; |
| 679 | l2_plen++; |
| 680 | break; |
| 681 | default: |
| 682 | break; |
| 683 | } |
| 684 | |
| 685 | si5b = (struct gsm48_system_information_type_5bis *) output; |
| 686 | |
| 687 | /* l2 pseudo length, not part of msg: 18 */ |
| 688 | si5b->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 689 | si5b->skip_indicator = 0; |
| 690 | si5b->system_information = GSM48_MT_RR_SYSINFO_5bis; |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 691 | rc = generate_bcch_chan_list(si5b->bcch_frequency_list, bts, true, true, false); |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 692 | if (rc < 0) |
| 693 | return rc; |
| 694 | n = list_arfcn(si5b->bcch_frequency_list, 0xce, |
| 695 | "Neighbour cells in same band, but outside P-GSM:"); |
| 696 | if (n) { |
| 697 | /* indicate in SI5 and SI5bis: there is an extension */ |
| 698 | struct gsm48_system_information_type_5 *si5 = |
| 699 | (struct gsm48_system_information_type_5 *) |
| 700 | bts->si_buf[SYSINFO_TYPE_5]; |
| 701 | si5->bcch_frequency_list[0] |= 0x20; |
| 702 | si5b->bcch_frequency_list[0] |= 0x20; |
| 703 | } else |
| 704 | bts->si_valid &= ~(1 << SYSINFO_TYPE_5bis); |
| 705 | |
| 706 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
| 707 | return l2_plen; |
| 708 | } |
| 709 | |
| 710 | static int generate_si5ter(uint8_t *output, struct gsm_bts *bts) |
| 711 | { |
| 712 | struct gsm48_system_information_type_5ter *si5t; |
| 713 | int rc, l2_plen = 18; |
| 714 | int n; |
| 715 | |
| 716 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 717 | |
| 718 | /* ip.access nanoBTS needs l2_plen!! */ |
| 719 | switch (bts->type) { |
| 720 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 721 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 722 | *output++ = (l2_plen << 2) | 1; |
| 723 | l2_plen++; |
| 724 | break; |
| 725 | default: |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | si5t = (struct gsm48_system_information_type_5ter *) output; |
| 730 | |
| 731 | /* l2 pseudo length, not part of msg: 18 */ |
| 732 | si5t->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 733 | si5t->skip_indicator = 0; |
| 734 | si5t->system_information = GSM48_MT_RR_SYSINFO_5ter; |
Max | 754629f | 2016-04-15 16:04:45 +0200 | [diff] [blame] | 735 | rc = generate_bcch_chan_list(si5t->bcch_frequency_list, bts, true, false, true); |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 736 | if (rc < 0) |
| 737 | return rc; |
| 738 | n = list_arfcn(si5t->bcch_frequency_list, 0x8e, |
| 739 | "Neighbour cells in different band:"); |
| 740 | if (!n) |
| 741 | bts->si_valid &= ~(1 << SYSINFO_TYPE_5ter); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 742 | |
| 743 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 744 | return l2_plen; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 745 | } |
| 746 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 747 | static int generate_si6(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 748 | { |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 749 | struct gsm48_system_information_type_6 *si6; |
| 750 | int l2_plen = 11; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 751 | |
Holger Hans Peter Freyther | 4f2ace4 | 2010-01-06 07:52:55 +0100 | [diff] [blame] | 752 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 753 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 754 | /* ip.access nanoBTS needs l2_plen!! */ |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 755 | switch (bts->type) { |
| 756 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 757 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 758 | *output++ = (l2_plen << 2) | 1; |
| 759 | l2_plen++; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 760 | break; |
| 761 | default: |
| 762 | break; |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | si6 = (struct gsm48_system_information_type_6 *) output; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 766 | |
| 767 | /* l2 pseudo length, not part of msg: 11 */ |
| 768 | si6->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 769 | si6->skip_indicator = 0; |
| 770 | si6->system_information = GSM48_MT_RR_SYSINFO_6; |
| 771 | si6->cell_identity = htons(bts->cell_identity); |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 772 | gsm48_generate_lai(&si6->lai, bts->network->country_code, |
| 773 | bts->network->network_code, |
| 774 | bts->location_area_code); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 775 | si6->cell_options = bts->si_common.cell_options; |
| 776 | si6->ncc_permitted = bts->si_common.ncc_permitted; |
| 777 | |
| 778 | /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */ |
| 779 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 780 | return l2_plen; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | static struct gsm48_si13_info si13_default = { |
| 784 | .cell_opts = { |
Harald Welte | b064471 | 2010-06-02 12:19:21 +0200 | [diff] [blame] | 785 | .nmo = GPRS_NMO_II, |
Harald Welte | a9713bf | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 786 | .t3168 = 2000, |
Andreas Eversberg | f225f2d | 2012-09-23 08:14:51 +0200 | [diff] [blame] | 787 | .t3192 = 1500, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 788 | .drx_timer_max = 3, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 789 | .bs_cv_max = 15, |
Sylvain Munaut | 1fa5239 | 2011-10-17 13:56:02 +0200 | [diff] [blame] | 790 | .ext_info_present = 0, |
Harald Welte | 3ce9a0d | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 791 | .ext_info = { |
| 792 | /* The values below are just guesses ! */ |
Harald Welte | 09faa06 | 2010-04-18 15:53:40 +0200 | [diff] [blame] | 793 | .egprs_supported = 0, |
Harald Welte | 3ce9a0d | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 794 | .use_egprs_p_ch_req = 1, |
Harald Welte | a9713bf | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 795 | .bep_period = 5, |
Harald Welte | 3ce9a0d | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 796 | .pfc_supported = 0, |
| 797 | .dtm_supported = 0, |
| 798 | .bss_paging_coordination = 0, |
| 799 | }, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 800 | }, |
| 801 | .pwr_ctrl_pars = { |
Harald Welte | a4a7c43 | 2012-10-08 21:22:08 +0200 | [diff] [blame] | 802 | .alpha = 0, /* a = 0.0 */ |
Harald Welte | a9713bf | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 803 | .t_avg_w = 16, |
| 804 | .t_avg_t = 16, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 805 | .pc_meas_chan = 0, /* downling measured on CCCH */ |
Harald Welte | a9713bf | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 806 | .n_avg_i = 8, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 807 | }, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 808 | .bcch_change_mark = 1, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 809 | .si_change_field = 0, |
| 810 | .pbcch_present = 0, |
| 811 | { |
| 812 | .no_pbcch = { |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 813 | .rac = 0, /* needs to be patched */ |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 814 | .spgc_ccch_sup = 0, |
| 815 | .net_ctrl_ord = 0, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 816 | .prio_acc_thr = 6, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 817 | }, |
| 818 | }, |
| 819 | }; |
| 820 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 821 | static int generate_si13(uint8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 822 | { |
| 823 | struct gsm48_system_information_type_13 *si13 = |
| 824 | (struct gsm48_system_information_type_13 *) output; |
| 825 | int ret; |
| 826 | |
| 827 | memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 828 | |
| 829 | si13->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 830 | si13->header.skip_indicator = 0; |
| 831 | si13->header.system_information = GSM48_MT_RR_SYSINFO_13; |
| 832 | |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 833 | si13_default.no_pbcch.rac = bts->gprs.rac; |
Andreas Eversberg | a4fa21c | 2013-03-16 16:31:26 +0100 | [diff] [blame] | 834 | si13_default.no_pbcch.net_ctrl_ord = bts->gprs.net_ctrl_ord; |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 835 | |
Holger Hans Peter Freyther | eacb178 | 2014-11-21 10:00:39 +0100 | [diff] [blame] | 836 | /* Information about the other SIs */ |
| 837 | si13_default.bcch_change_mark = bts->bcch_change_mark; |
| 838 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 839 | ret = rest_octets_si13(si13->rest_octets, &si13_default); |
| 840 | if (ret < 0) |
| 841 | return ret; |
| 842 | |
Holger Hans Peter Freyther | 6c84d70 | 2010-06-16 12:05:56 +0800 | [diff] [blame] | 843 | /* length is coded in bit 2 an up */ |
| 844 | si13->header.l2_plen = 0x01; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 845 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 846 | return sizeof (*si13) + ret; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 847 | } |
| 848 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 849 | typedef int (*gen_si_fn_t)(uint8_t *output, struct gsm_bts *bts); |
| 850 | |
| 851 | static const gen_si_fn_t gen_si_fn[_MAX_SYSINFO_TYPE] = { |
| 852 | [SYSINFO_TYPE_1] = &generate_si1, |
| 853 | [SYSINFO_TYPE_2] = &generate_si2, |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 854 | [SYSINFO_TYPE_2bis] = &generate_si2bis, |
| 855 | [SYSINFO_TYPE_2ter] = &generate_si2ter, |
Max | 88ddcaa | 2016-04-15 16:04:46 +0200 | [diff] [blame^] | 856 | [SYSINFO_TYPE_2quater] = &generate_si2quater, |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 857 | [SYSINFO_TYPE_3] = &generate_si3, |
| 858 | [SYSINFO_TYPE_4] = &generate_si4, |
| 859 | [SYSINFO_TYPE_5] = &generate_si5, |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 860 | [SYSINFO_TYPE_5bis] = &generate_si5bis, |
| 861 | [SYSINFO_TYPE_5ter] = &generate_si5ter, |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 862 | [SYSINFO_TYPE_6] = &generate_si6, |
| 863 | [SYSINFO_TYPE_13] = &generate_si13, |
| 864 | }; |
| 865 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 866 | int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type) |
| 867 | { |
| 868 | gen_si_fn_t gen_si; |
| 869 | |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 870 | switch (bts->gprs.mode) { |
| 871 | case BTS_GPRS_EGPRS: |
Harald Welte | 09faa06 | 2010-04-18 15:53:40 +0200 | [diff] [blame] | 872 | si13_default.cell_opts.ext_info_present = 1; |
| 873 | si13_default.cell_opts.ext_info.egprs_supported = 1; |
| 874 | /* fallthrough */ |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 875 | case BTS_GPRS_GPRS: |
| 876 | si_info.gprs_ind.present = 1; |
| 877 | break; |
| 878 | case BTS_GPRS_NONE: |
| 879 | si_info.gprs_ind.present = 0; |
| 880 | break; |
| 881 | } |
Harald Welte | e050010 | 2010-03-14 23:46:48 +0800 | [diff] [blame] | 882 | |
Sylvain Munaut | 00d7146 | 2010-11-28 18:17:28 +0100 | [diff] [blame] | 883 | memcpy(&si_info.selection_params, |
| 884 | &bts->si_common.cell_ro_sel_par, |
| 885 | sizeof(struct gsm48_si_selection_params)); |
| 886 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 887 | gen_si = gen_si_fn[si_type]; |
| 888 | if (!gen_si) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 889 | return -EINVAL; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 890 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 891 | return gen_si(bts->si_buf[si_type], bts); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 892 | } |