Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1 | /* GSM 04.08 System Information (SI) encoding and decoding |
| 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
| 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <string.h> |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 26 | #include <stdio.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 27 | #include <sys/types.h> |
| 28 | #include <netinet/in.h> |
| 29 | |
| 30 | #include <openbsc/gsm_04_08.h> |
| 31 | #include <openbsc/gsm_data.h> |
| 32 | #include <openbsc/abis_rsl.h> |
| 33 | #include <openbsc/rest_octets.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 34 | #include <osmocore/bitvec.h> |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 35 | #include <openbsc/debug.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 36 | |
| 37 | #define GSM48_CELL_CHAN_DESC_SIZE 16 |
| 38 | #define GSM_MACBLOCK_LEN 23 |
| 39 | #define GSM_MACBLOCK_PADDING 0x2b |
| 40 | |
Holger Hans Peter Freyther | 8526b15 | 2010-01-06 06:38:14 +0100 | [diff] [blame] | 41 | /* verify the sizes of the system information type structs */ |
| 42 | |
| 43 | /* rest octets are not part of the struct */ |
| 44 | static_assert(sizeof(struct gsm48_system_information_type_header) == 3, _si_header_size); |
| 45 | static_assert(sizeof(struct gsm48_rach_control) == 3, _si_rach_control); |
| 46 | static_assert(sizeof(struct gsm48_system_information_type_1) == 22, _si1_size); |
| 47 | static_assert(sizeof(struct gsm48_system_information_type_2) == 23, _si2_size); |
| 48 | static_assert(sizeof(struct gsm48_system_information_type_3) == 19, _si3_size); |
| 49 | static_assert(sizeof(struct gsm48_system_information_type_4) == 13, _si4_size); |
| 50 | |
| 51 | /* bs11 forgot the l2 len, 0-6 rest octets */ |
| 52 | static_assert(sizeof(struct gsm48_system_information_type_5) == 18, _si5_size); |
| 53 | static_assert(sizeof(struct gsm48_system_information_type_6) == 11, _si6_size); |
| 54 | |
| 55 | static_assert(sizeof(struct gsm48_system_information_type_13) == 3, _si13_size); |
| 56 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 57 | /* Frequency Lists as per TS 04.08 10.5.2.13 */ |
| 58 | |
| 59 | /* 10.5.2.13.2: Bit map 0 format */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 60 | static int freq_list_bm0_set_arfcn(u_int8_t *chan_list, unsigned int arfcn) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 61 | { |
| 62 | unsigned int byte, bit; |
| 63 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 64 | if (arfcn > 124 || arfcn < 1) { |
| 65 | LOGP(DRR, LOGL_ERROR, "Bitmap 0 only supports ARFCN 1...124\n"); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 66 | return -EINVAL; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 67 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 68 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 69 | /* the bitmask is from 1..124, not from 0..123 */ |
| 70 | arfcn--; |
| 71 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 72 | byte = arfcn / 8; |
| 73 | bit = arfcn % 8; |
| 74 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 75 | chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 80 | /* 10.5.2.13.7: Variable bit map format */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 81 | static int freq_list_bmrel_set_arfcn(u_int8_t *chan_list, unsigned int arfcn) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 82 | { |
| 83 | unsigned int byte, bit; |
| 84 | unsigned int min_arfcn; |
| 85 | unsigned int bitno; |
| 86 | |
| 87 | min_arfcn = (chan_list[0] & 1) << 9; |
| 88 | min_arfcn |= chan_list[1] << 1; |
| 89 | min_arfcn |= (chan_list[2] >> 7) & 1; |
| 90 | |
| 91 | /* The lower end of our bitmaks is always implicitly included */ |
| 92 | if (arfcn == min_arfcn) |
| 93 | return 0; |
| 94 | |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 95 | if (arfcn < min_arfcn) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 96 | LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 97 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 98 | } |
| 99 | if (arfcn > min_arfcn + 111) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 100 | LOGP(DRR, LOGL_ERROR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 101 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 102 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 103 | |
| 104 | bitno = (arfcn - min_arfcn); |
| 105 | byte = bitno / 8; |
| 106 | bit = bitno % 8; |
| 107 | |
| 108 | chan_list[2 + byte] |= 1 << (7 - bit); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 114 | static int bitvec2freq_list(u_int8_t *chan_list, struct bitvec *bv, |
| 115 | const struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 116 | { |
Sylvain Munaut | 40f84a9 | 2009-12-24 14:20:19 +0100 | [diff] [blame] | 117 | int i, rc, min = 1024, max = -1; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 118 | |
| 119 | memset(chan_list, 0, 16); |
| 120 | |
| 121 | /* GSM900-only handsets only support 'bit map 0 format' */ |
| 122 | if (bts->band == GSM_BAND_900) { |
| 123 | chan_list[0] = 0; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 124 | |
| 125 | for (i = 0; i < bv->data_len*8; i++) { |
| 126 | if (bitvec_get_bit_pos(bv, i)) { |
| 127 | rc = freq_list_bm0_set_arfcn(chan_list, i); |
| 128 | if (rc < 0) |
| 129 | return rc; |
| 130 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 131 | } |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* We currently only support the 'Variable bitmap format' */ |
| 136 | chan_list[0] = 0x8e; |
| 137 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 138 | for (i = 0; i < bv->data_len*8; i++) { |
| 139 | if (bitvec_get_bit_pos(bv, i)) { |
| 140 | if (i < min) |
| 141 | min = i; |
| 142 | if (i > max) |
| 143 | max = i; |
| 144 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 145 | } |
| 146 | |
Sylvain Munaut | 40f84a9 | 2009-12-24 14:20:19 +0100 | [diff] [blame] | 147 | if (max == -1) { |
| 148 | /* Empty set, use 'bit map 0 format' */ |
| 149 | chan_list[0] = 0; |
| 150 | return 0; |
| 151 | } |
| 152 | |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 153 | if ((max - min) > 111) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 154 | LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, " |
| 155 | "distance > 111\n", min, max); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 156 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 157 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 158 | |
| 159 | chan_list[0] |= (min >> 9) & 1; |
| 160 | chan_list[1] = (min >> 1); |
| 161 | chan_list[2] = (min & 1) << 7; |
| 162 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 163 | for (i = 0; i < bv->data_len*8; i++) { |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 164 | if (bitvec_get_bit_pos(bv, i)) { |
| 165 | rc = freq_list_bmrel_set_arfcn(chan_list, i); |
| 166 | if (rc < 0) |
| 167 | return rc; |
| 168 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 175 | static int generate_cell_chan_list(u_int8_t *chan_list, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 176 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 177 | struct gsm_bts_trx *trx; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 178 | struct bitvec *bv = &bts->si_common.cell_alloc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 179 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 180 | /* first we generate a bitvec of all TRX ARFCN's in our BTS */ |
| 181 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 182 | bitvec_set_bit_pos(bv, trx->arfcn, 1); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 183 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 184 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
| 185 | return bitvec2freq_list(chan_list, bv, bts); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 186 | } |
| 187 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 188 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
| 189 | static int generate_bcch_chan_list(u_int8_t *chan_list, struct gsm_bts *bts) |
| 190 | { |
| 191 | struct gsm_bts *cur_bts; |
| 192 | struct bitvec *bv = &bts->si_common.neigh_list; |
| 193 | |
| 194 | /* first we generate a bitvec of the BCCH ARFCN's in our BSC */ |
| 195 | llist_for_each_entry(cur_bts, &bts->network->bts_list, list) { |
| 196 | if (cur_bts == bts) |
| 197 | continue; |
| 198 | bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1); |
| 199 | } |
| 200 | |
| 201 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
| 202 | return bitvec2freq_list(chan_list, bv, bts); |
| 203 | } |
| 204 | |
| 205 | static int generate_si1(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 206 | { |
| 207 | int rc; |
| 208 | struct gsm48_system_information_type_1 *si1 = |
| 209 | (struct gsm48_system_information_type_1 *) output; |
| 210 | |
| 211 | memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 212 | |
| 213 | si1->header.l2_plen = (21 << 2) | 1; |
| 214 | si1->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 215 | si1->header.skip_indicator = 0; |
| 216 | si1->header.system_information = GSM48_MT_RR_SYSINFO_1; |
| 217 | |
| 218 | rc = generate_cell_chan_list(si1->cell_channel_description, bts); |
| 219 | if (rc < 0) |
| 220 | return rc; |
| 221 | |
| 222 | si1->rach_control = bts->si_common.rach_control; |
| 223 | |
| 224 | /* SI1 Rest Octets (10.5.2.32), contains NCH position */ |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 225 | rc = rest_octets_si1(si1->rest_octets, NULL); |
| 226 | return sizeof(*si1) + rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 227 | } |
| 228 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 229 | static int generate_si2(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 230 | { |
| 231 | int rc; |
| 232 | struct gsm48_system_information_type_2 *si2 = |
| 233 | (struct gsm48_system_information_type_2 *) output; |
| 234 | |
| 235 | memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 236 | |
| 237 | si2->header.l2_plen = (22 << 2) | 1; |
| 238 | si2->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 239 | si2->header.skip_indicator = 0; |
| 240 | si2->header.system_information = GSM48_MT_RR_SYSINFO_2; |
| 241 | |
| 242 | rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts); |
| 243 | if (rc < 0) |
| 244 | return rc; |
| 245 | |
| 246 | si2->ncc_permitted = bts->si_common.ncc_permitted; |
| 247 | si2->rach_control = bts->si_common.rach_control; |
| 248 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 249 | return sizeof(*si2); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 250 | } |
| 251 | |
Harald Welte | e050010 | 2010-03-14 23:46:48 +0800 | [diff] [blame] | 252 | static struct gsm48_si_ro_info si_info = { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 253 | .selection_params = { |
| 254 | .present = 0, |
| 255 | }, |
| 256 | .power_offset = { |
| 257 | .present = 0, |
| 258 | }, |
| 259 | .si2ter_indicator = 0, |
| 260 | .early_cm_ctrl = 1, |
| 261 | .scheduling = { |
| 262 | .present = 0, |
| 263 | }, |
| 264 | .gprs_ind = { |
| 265 | .si13_position = 0, |
| 266 | .ra_colour = 0, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 267 | .present = 1, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 268 | }, |
| 269 | .lsa_params = { |
| 270 | .present = 0, |
| 271 | }, |
| 272 | .cell_id = 0, /* FIXME: doesn't the bts have this? */ |
| 273 | .break_ind = 0, |
| 274 | }; |
| 275 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 276 | static int generate_si3(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 277 | { |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 278 | int rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 279 | struct gsm48_system_information_type_3 *si3 = |
| 280 | (struct gsm48_system_information_type_3 *) output; |
| 281 | |
| 282 | memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 283 | |
| 284 | si3->header.l2_plen = (18 << 2) | 1; |
| 285 | si3->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 286 | si3->header.skip_indicator = 0; |
| 287 | si3->header.system_information = GSM48_MT_RR_SYSINFO_3; |
| 288 | |
| 289 | si3->cell_identity = htons(bts->cell_identity); |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 290 | gsm48_generate_lai(&si3->lai, bts->network->country_code, |
| 291 | bts->network->network_code, |
| 292 | bts->location_area_code); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 293 | si3->control_channel_desc = bts->si_common.chan_desc; |
| 294 | si3->cell_options = bts->si_common.cell_options; |
| 295 | si3->cell_sel_par = bts->si_common.cell_sel_par; |
| 296 | si3->rach_control = bts->si_common.rach_control; |
| 297 | |
| 298 | /* SI3 Rest Octets (10.5.2.34), containing |
| 299 | CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME |
| 300 | Power Offset, 2ter Indicator, Early Classmark Sending, |
| 301 | Scheduling if and WHERE, GPRS Indicator, SI13 position */ |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 302 | rc = rest_octets_si3(si3->rest_octets, &si_info); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 303 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 304 | return sizeof(*si3) + rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 305 | } |
| 306 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 307 | static int generate_si4(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 308 | { |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 309 | int rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 310 | struct gsm48_system_information_type_4 *si4 = |
| 311 | (struct gsm48_system_information_type_4 *) output; |
| 312 | |
| 313 | /* length of all IEs present except SI4 rest octets and l2_plen */ |
| 314 | int l2_plen = sizeof(*si4) - 1; |
| 315 | |
| 316 | memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 317 | |
| 318 | si4->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 319 | si4->header.skip_indicator = 0; |
| 320 | si4->header.system_information = GSM48_MT_RR_SYSINFO_4; |
| 321 | |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 322 | gsm48_generate_lai(&si4->lai, bts->network->country_code, |
| 323 | bts->network->network_code, |
| 324 | bts->location_area_code); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 325 | si4->cell_sel_par = bts->si_common.cell_sel_par; |
| 326 | si4->rach_control = bts->si_common.rach_control; |
| 327 | |
| 328 | /* Optional: CBCH Channel Description + CBCH Mobile Allocation */ |
| 329 | |
| 330 | si4->header.l2_plen = (l2_plen << 2) | 1; |
| 331 | |
| 332 | /* SI4 Rest Octets (10.5.2.35), containing |
| 333 | Optional Power offset, GPRS Indicator, |
| 334 | Cell Identity, LSA ID, Selection Parameter */ |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 335 | rc = rest_octets_si4(si4->data, &si_info); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 336 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 337 | return sizeof(*si4) + rc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 338 | } |
| 339 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 340 | static int generate_si5(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 341 | { |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 342 | struct gsm48_system_information_type_5 *si5; |
| 343 | int rc, l2_plen = 18; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 344 | |
Holger Hans Peter Freyther | 4f2ace4 | 2010-01-06 07:52:55 +0100 | [diff] [blame] | 345 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 346 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 347 | /* ip.access nanoBTS needs l2_plen!! */ |
| 348 | if (is_ipaccess_bts(bts)) { |
| 349 | *output++ = (l2_plen << 2) | 1; |
| 350 | l2_plen++; |
| 351 | } |
| 352 | |
| 353 | si5 = (struct gsm48_system_information_type_5 *) output; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 354 | |
| 355 | /* l2 pseudo length, not part of msg: 18 */ |
| 356 | si5->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 357 | si5->skip_indicator = 0; |
| 358 | si5->system_information = GSM48_MT_RR_SYSINFO_5; |
| 359 | rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts); |
| 360 | if (rc < 0) |
| 361 | return rc; |
| 362 | |
| 363 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 364 | return l2_plen; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 365 | } |
| 366 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 367 | static int generate_si6(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 368 | { |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 369 | struct gsm48_system_information_type_6 *si6; |
| 370 | int l2_plen = 11; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 371 | |
Holger Hans Peter Freyther | 4f2ace4 | 2010-01-06 07:52:55 +0100 | [diff] [blame] | 372 | memset(output, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 373 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 374 | /* ip.access nanoBTS needs l2_plen!! */ |
| 375 | if (is_ipaccess_bts(bts)) { |
| 376 | *output++ = (l2_plen << 2) | 1; |
| 377 | l2_plen++; |
| 378 | } |
| 379 | |
| 380 | si6 = (struct gsm48_system_information_type_6 *) output; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 381 | |
| 382 | /* l2 pseudo length, not part of msg: 11 */ |
| 383 | si6->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 384 | si6->skip_indicator = 0; |
| 385 | si6->system_information = GSM48_MT_RR_SYSINFO_6; |
| 386 | si6->cell_identity = htons(bts->cell_identity); |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 387 | gsm48_generate_lai(&si6->lai, bts->network->country_code, |
| 388 | bts->network->network_code, |
| 389 | bts->location_area_code); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 390 | si6->cell_options = bts->si_common.cell_options; |
| 391 | si6->ncc_permitted = bts->si_common.ncc_permitted; |
| 392 | |
| 393 | /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */ |
| 394 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 395 | return l2_plen; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static struct gsm48_si13_info si13_default = { |
| 399 | .cell_opts = { |
| 400 | .nmo = GPRS_NMO_III, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 401 | .t3168 = 1500, |
| 402 | .t3192 = 500, |
| 403 | .drx_timer_max = 3, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 404 | .bs_cv_max = 15, |
Harald Welte | 3ce9a0d | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 405 | .ext_info_present = 0, |
| 406 | .ext_info = { |
| 407 | /* The values below are just guesses ! */ |
Harald Welte | 09faa06 | 2010-04-18 15:53:40 +0200 | [diff] [blame] | 408 | .egprs_supported = 0, |
Harald Welte | 3ce9a0d | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 409 | .use_egprs_p_ch_req = 1, |
| 410 | .bep_period = 4, |
| 411 | .pfc_supported = 0, |
| 412 | .dtm_supported = 0, |
| 413 | .bss_paging_coordination = 0, |
| 414 | }, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 415 | }, |
| 416 | .pwr_ctrl_pars = { |
| 417 | .alpha = 10, /* a = 1.0 */ |
| 418 | .t_avg_w = 25, |
| 419 | .t_avg_t = 25, |
| 420 | .pc_meas_chan = 0, /* downling measured on CCCH */ |
| 421 | .n_avg_i = 15, |
| 422 | }, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 423 | .bcch_change_mark = 1, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 424 | .si_change_field = 0, |
| 425 | .pbcch_present = 0, |
| 426 | { |
| 427 | .no_pbcch = { |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 428 | .rac = 0, /* needs to be patched */ |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 429 | .spgc_ccch_sup = 0, |
| 430 | .net_ctrl_ord = 0, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 431 | .prio_acc_thr = 6, |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 432 | }, |
| 433 | }, |
| 434 | }; |
| 435 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 436 | static int generate_si13(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 437 | { |
| 438 | struct gsm48_system_information_type_13 *si13 = |
| 439 | (struct gsm48_system_information_type_13 *) output; |
| 440 | int ret; |
| 441 | |
| 442 | memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 443 | |
| 444 | si13->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 445 | si13->header.skip_indicator = 0; |
| 446 | si13->header.system_information = GSM48_MT_RR_SYSINFO_13; |
| 447 | |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 448 | si13_default.no_pbcch.rac = bts->gprs.rac; |
| 449 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 450 | ret = rest_octets_si13(si13->rest_octets, &si13_default); |
| 451 | if (ret < 0) |
| 452 | return ret; |
| 453 | |
| 454 | si13->header.l2_plen = ret & 0xff; |
| 455 | |
Holger Hans Peter Freyther | 02c608c | 2010-01-06 07:52:31 +0100 | [diff] [blame] | 456 | return sizeof (*si13) + ret; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | int gsm_generate_si(u_int8_t *output, struct gsm_bts *bts, int type) |
| 460 | { |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 461 | switch (bts->gprs.mode) { |
| 462 | case BTS_GPRS_EGPRS: |
Harald Welte | 09faa06 | 2010-04-18 15:53:40 +0200 | [diff] [blame] | 463 | si13_default.cell_opts.ext_info_present = 1; |
| 464 | si13_default.cell_opts.ext_info.egprs_supported = 1; |
| 465 | /* fallthrough */ |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 466 | case BTS_GPRS_GPRS: |
| 467 | si_info.gprs_ind.present = 1; |
| 468 | break; |
| 469 | case BTS_GPRS_NONE: |
| 470 | si_info.gprs_ind.present = 0; |
| 471 | break; |
| 472 | } |
Harald Welte | e050010 | 2010-03-14 23:46:48 +0800 | [diff] [blame] | 473 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 474 | switch (type) { |
| 475 | case RSL_SYSTEM_INFO_1: |
| 476 | return generate_si1(output, bts); |
| 477 | case RSL_SYSTEM_INFO_2: |
| 478 | return generate_si2(output, bts); |
| 479 | case RSL_SYSTEM_INFO_3: |
| 480 | return generate_si3(output, bts); |
| 481 | case RSL_SYSTEM_INFO_4: |
| 482 | return generate_si4(output, bts); |
| 483 | case RSL_SYSTEM_INFO_5: |
| 484 | return generate_si5(output, bts); |
| 485 | case RSL_SYSTEM_INFO_6: |
| 486 | return generate_si6(output, bts); |
| 487 | case RSL_SYSTEM_INFO_13: |
| 488 | return generate_si13(output, bts); |
| 489 | default: |
| 490 | return -EINVAL; |
| 491 | } |
| 492 | |
| 493 | return 0; |
| 494 | } |