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