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