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