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 | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 34 | #include <openbsc/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 | |
Harald Welte | bc47966 | 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 */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 44 | 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] | 45 | { |
| 46 | unsigned int byte, bit; |
| 47 | |
Harald Welte | cf2ec4a | 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 | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 50 | return -EINVAL; |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 51 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 52 | |
Harald Welte | bc47966 | 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 | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 56 | byte = arfcn / 8; |
| 57 | bit = arfcn % 8; |
| 58 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 59 | chan_list[GSM48_CELL_CHAN_DESC_SIZE-1-byte] |= (1 << bit); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Harald Welte | bc47966 | 2009-12-14 20:25:05 +0100 | [diff] [blame] | 64 | /* 10.5.2.13.7: Variable bit map format */ |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 65 | 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] | 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 | |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 79 | if (arfcn < min_arfcn) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 80 | LOGP(DRR, LOGL_ERROR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 81 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 82 | } |
| 83 | if (arfcn > min_arfcn + 111) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 84 | 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] | 85 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 86 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 87 | |
| 88 | bitno = (arfcn - min_arfcn); |
| 89 | byte = bitno / 8; |
| 90 | bit = bitno % 8; |
| 91 | |
| 92 | chan_list[2 + byte] |= 1 << (7 - bit); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | /* 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] | 98 | static int bitvec2freq_list(u_int8_t *chan_list, struct bitvec *bv, |
| 99 | const struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 100 | { |
Sylvain Munaut | 40f84a9 | 2009-12-24 14:20:19 +0100 | [diff] [blame] | 101 | int i, rc, min = 1024, max = -1; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 102 | |
| 103 | memset(chan_list, 0, 16); |
| 104 | |
| 105 | /* GSM900-only handsets only support 'bit map 0 format' */ |
| 106 | if (bts->band == GSM_BAND_900) { |
| 107 | chan_list[0] = 0; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 108 | |
| 109 | for (i = 0; i < bv->data_len*8; i++) { |
| 110 | if (bitvec_get_bit_pos(bv, i)) { |
| 111 | rc = freq_list_bm0_set_arfcn(chan_list, i); |
| 112 | if (rc < 0) |
| 113 | return rc; |
| 114 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 115 | } |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | /* We currently only support the 'Variable bitmap format' */ |
| 120 | chan_list[0] = 0x8e; |
| 121 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 122 | for (i = 0; i < bv->data_len*8; i++) { |
| 123 | if (bitvec_get_bit_pos(bv, i)) { |
| 124 | if (i < min) |
| 125 | min = i; |
| 126 | if (i > max) |
| 127 | max = i; |
| 128 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 129 | } |
| 130 | |
Sylvain Munaut | 40f84a9 | 2009-12-24 14:20:19 +0100 | [diff] [blame] | 131 | if (max == -1) { |
| 132 | /* Empty set, use 'bit map 0 format' */ |
| 133 | chan_list[0] = 0; |
| 134 | return 0; |
| 135 | } |
| 136 | |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 137 | if ((max - min) > 111) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 138 | LOGP(DRR, LOGL_ERROR, "min_arfcn=%u, max_arfcn=%u, " |
| 139 | "distance > 111\n", min, max); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 140 | return -EINVAL; |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 141 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 142 | |
| 143 | chan_list[0] |= (min >> 9) & 1; |
| 144 | chan_list[1] = (min >> 1); |
| 145 | chan_list[2] = (min & 1) << 7; |
| 146 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 147 | for (i = 0; i < bv->data_len*8; i++) { |
Harald Welte | e285bad | 2009-12-16 11:57:48 +0100 | [diff] [blame] | 148 | if (bitvec_get_bit_pos(bv, i)) { |
| 149 | rc = freq_list_bmrel_set_arfcn(chan_list, i); |
| 150 | if (rc < 0) |
| 151 | return rc; |
| 152 | } |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* 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] | 159 | 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] | 160 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 161 | struct gsm_bts_trx *trx; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 162 | struct bitvec *bv = &bts->si_common.cell_alloc; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 163 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 164 | /* first we generate a bitvec of all TRX ARFCN's in our BTS */ |
| 165 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 166 | bitvec_set_bit_pos(bv, trx->arfcn, 1); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 167 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 168 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
| 169 | return bitvec2freq_list(chan_list, bv, bts); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 170 | } |
| 171 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 172 | /* generate a cell channel list as per Section 10.5.2.1b of 04.08 */ |
| 173 | static int generate_bcch_chan_list(u_int8_t *chan_list, struct gsm_bts *bts) |
| 174 | { |
| 175 | struct gsm_bts *cur_bts; |
| 176 | struct bitvec *bv = &bts->si_common.neigh_list; |
| 177 | |
| 178 | /* first we generate a bitvec of the BCCH ARFCN's in our BSC */ |
| 179 | llist_for_each_entry(cur_bts, &bts->network->bts_list, list) { |
| 180 | if (cur_bts == bts) |
| 181 | continue; |
| 182 | bitvec_set_bit_pos(bv, cur_bts->c0->arfcn, 1); |
| 183 | } |
| 184 | |
| 185 | /* then we generate a GSM 04.08 frequency list from the bitvec */ |
| 186 | return bitvec2freq_list(chan_list, bv, bts); |
| 187 | } |
| 188 | |
| 189 | static int generate_si1(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 190 | { |
| 191 | int rc; |
| 192 | struct gsm48_system_information_type_1 *si1 = |
| 193 | (struct gsm48_system_information_type_1 *) output; |
| 194 | |
| 195 | memset(si1, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 196 | |
| 197 | si1->header.l2_plen = (21 << 2) | 1; |
| 198 | si1->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 199 | si1->header.skip_indicator = 0; |
| 200 | si1->header.system_information = GSM48_MT_RR_SYSINFO_1; |
| 201 | |
| 202 | rc = generate_cell_chan_list(si1->cell_channel_description, bts); |
| 203 | if (rc < 0) |
| 204 | return rc; |
| 205 | |
| 206 | si1->rach_control = bts->si_common.rach_control; |
| 207 | |
| 208 | /* SI1 Rest Octets (10.5.2.32), contains NCH position */ |
| 209 | rest_octets_si1(si1->rest_octets, NULL); |
| 210 | |
| 211 | return GSM_MACBLOCK_LEN; |
| 212 | } |
| 213 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 214 | static int generate_si2(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 215 | { |
| 216 | int rc; |
| 217 | struct gsm48_system_information_type_2 *si2 = |
| 218 | (struct gsm48_system_information_type_2 *) output; |
| 219 | |
| 220 | memset(si2, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 221 | |
| 222 | si2->header.l2_plen = (22 << 2) | 1; |
| 223 | si2->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 224 | si2->header.skip_indicator = 0; |
| 225 | si2->header.system_information = GSM48_MT_RR_SYSINFO_2; |
| 226 | |
| 227 | rc = generate_bcch_chan_list(si2->bcch_frequency_list, bts); |
| 228 | if (rc < 0) |
| 229 | return rc; |
| 230 | |
| 231 | si2->ncc_permitted = bts->si_common.ncc_permitted; |
| 232 | si2->rach_control = bts->si_common.rach_control; |
| 233 | |
| 234 | return GSM_MACBLOCK_LEN; |
| 235 | } |
| 236 | |
| 237 | struct gsm48_si_ro_info si_info = { |
| 238 | .selection_params = { |
| 239 | .present = 0, |
| 240 | }, |
| 241 | .power_offset = { |
| 242 | .present = 0, |
| 243 | }, |
| 244 | .si2ter_indicator = 0, |
| 245 | .early_cm_ctrl = 1, |
| 246 | .scheduling = { |
| 247 | .present = 0, |
| 248 | }, |
| 249 | .gprs_ind = { |
| 250 | .si13_position = 0, |
| 251 | .ra_colour = 0, |
| 252 | .present = 0, |
| 253 | }, |
| 254 | .lsa_params = { |
| 255 | .present = 0, |
| 256 | }, |
| 257 | .cell_id = 0, /* FIXME: doesn't the bts have this? */ |
| 258 | .break_ind = 0, |
| 259 | }; |
| 260 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 261 | static int generate_si3(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 262 | { |
| 263 | struct gsm48_system_information_type_3 *si3 = |
| 264 | (struct gsm48_system_information_type_3 *) output; |
| 265 | |
| 266 | memset(si3, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 267 | |
| 268 | si3->header.l2_plen = (18 << 2) | 1; |
| 269 | si3->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 270 | si3->header.skip_indicator = 0; |
| 271 | si3->header.system_information = GSM48_MT_RR_SYSINFO_3; |
| 272 | |
| 273 | si3->cell_identity = htons(bts->cell_identity); |
| 274 | gsm0408_generate_lai(&si3->lai, bts->network->country_code, |
| 275 | bts->network->network_code, |
| 276 | bts->location_area_code); |
| 277 | si3->control_channel_desc = bts->si_common.chan_desc; |
| 278 | si3->cell_options = bts->si_common.cell_options; |
| 279 | si3->cell_sel_par = bts->si_common.cell_sel_par; |
| 280 | si3->rach_control = bts->si_common.rach_control; |
| 281 | |
| 282 | /* SI3 Rest Octets (10.5.2.34), containing |
| 283 | CBQ, CELL_RESELECT_OFFSET, TEMPORARY_OFFSET, PENALTY_TIME |
| 284 | Power Offset, 2ter Indicator, Early Classmark Sending, |
| 285 | Scheduling if and WHERE, GPRS Indicator, SI13 position */ |
| 286 | rest_octets_si3(si3->rest_octets, &si_info); |
| 287 | |
| 288 | return GSM_MACBLOCK_LEN; |
| 289 | } |
| 290 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 291 | static int generate_si4(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 292 | { |
| 293 | struct gsm48_system_information_type_4 *si4 = |
| 294 | (struct gsm48_system_information_type_4 *) output; |
| 295 | |
| 296 | /* length of all IEs present except SI4 rest octets and l2_plen */ |
| 297 | int l2_plen = sizeof(*si4) - 1; |
| 298 | |
| 299 | memset(si4, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 300 | |
| 301 | si4->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 302 | si4->header.skip_indicator = 0; |
| 303 | si4->header.system_information = GSM48_MT_RR_SYSINFO_4; |
| 304 | |
| 305 | gsm0408_generate_lai(&si4->lai, bts->network->country_code, |
| 306 | bts->network->network_code, |
| 307 | bts->location_area_code); |
| 308 | si4->cell_sel_par = bts->si_common.cell_sel_par; |
| 309 | si4->rach_control = bts->si_common.rach_control; |
| 310 | |
| 311 | /* Optional: CBCH Channel Description + CBCH Mobile Allocation */ |
| 312 | |
| 313 | si4->header.l2_plen = (l2_plen << 2) | 1; |
| 314 | |
| 315 | /* SI4 Rest Octets (10.5.2.35), containing |
| 316 | Optional Power offset, GPRS Indicator, |
| 317 | Cell Identity, LSA ID, Selection Parameter */ |
| 318 | rest_octets_si4(si4->data, &si_info); |
| 319 | |
| 320 | return GSM_MACBLOCK_LEN; |
| 321 | } |
| 322 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 323 | static int generate_si5(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 324 | { |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 325 | struct gsm48_system_information_type_5 *si5; |
| 326 | int rc, l2_plen = 18; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 327 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 328 | /* ip.access nanoBTS needs l2_plen!! */ |
| 329 | if (is_ipaccess_bts(bts)) { |
| 330 | *output++ = (l2_plen << 2) | 1; |
| 331 | l2_plen++; |
| 332 | } |
| 333 | |
| 334 | si5 = (struct gsm48_system_information_type_5 *) output; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 335 | memset(si5, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 336 | |
| 337 | /* l2 pseudo length, not part of msg: 18 */ |
| 338 | si5->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 339 | si5->skip_indicator = 0; |
| 340 | si5->system_information = GSM48_MT_RR_SYSINFO_5; |
| 341 | rc = generate_bcch_chan_list(si5->bcch_frequency_list, bts); |
| 342 | if (rc < 0) |
| 343 | return rc; |
| 344 | |
| 345 | /* 04.08 9.1.37: L2 Pseudo Length of 18 */ |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 346 | return l2_plen; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 347 | } |
| 348 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 349 | static int generate_si6(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 350 | { |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 351 | struct gsm48_system_information_type_6 *si6; |
| 352 | int l2_plen = 11; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 353 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 354 | /* ip.access nanoBTS needs l2_plen!! */ |
| 355 | if (is_ipaccess_bts(bts)) { |
| 356 | *output++ = (l2_plen << 2) | 1; |
| 357 | l2_plen++; |
| 358 | } |
| 359 | |
| 360 | si6 = (struct gsm48_system_information_type_6 *) output; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 361 | memset(si6, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 362 | |
| 363 | /* l2 pseudo length, not part of msg: 11 */ |
| 364 | si6->rr_protocol_discriminator = GSM48_PDISC_RR; |
| 365 | si6->skip_indicator = 0; |
| 366 | si6->system_information = GSM48_MT_RR_SYSINFO_6; |
| 367 | si6->cell_identity = htons(bts->cell_identity); |
| 368 | gsm0408_generate_lai(&si6->lai, bts->network->country_code, |
| 369 | bts->network->network_code, |
| 370 | bts->location_area_code); |
| 371 | si6->cell_options = bts->si_common.cell_options; |
| 372 | si6->ncc_permitted = bts->si_common.ncc_permitted; |
| 373 | |
| 374 | /* SI6 Rest Octets: 10.5.2.35a: PCH / NCH info, VBS/VGCS options */ |
| 375 | |
Harald Welte | 2a92a71 | 2009-12-19 21:26:54 +0100 | [diff] [blame] | 376 | return l2_plen; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static struct gsm48_si13_info si13_default = { |
| 380 | .cell_opts = { |
| 381 | .nmo = GPRS_NMO_III, |
| 382 | .t3168 = 1000, |
| 383 | .t3192 = 1000, |
| 384 | .drx_timer_max = 1, |
| 385 | .bs_cv_max = 15, |
| 386 | }, |
| 387 | .pwr_ctrl_pars = { |
| 388 | .alpha = 10, /* a = 1.0 */ |
| 389 | .t_avg_w = 25, |
| 390 | .t_avg_t = 25, |
| 391 | .pc_meas_chan = 0, /* downling measured on CCCH */ |
| 392 | .n_avg_i = 15, |
| 393 | }, |
| 394 | .bcch_change_mark = 0, |
| 395 | .si_change_field = 0, |
| 396 | .pbcch_present = 0, |
| 397 | { |
| 398 | .no_pbcch = { |
| 399 | .rac = 0, |
| 400 | .spgc_ccch_sup = 0, |
| 401 | .net_ctrl_ord = 0, |
| 402 | .prio_acc_thr = 0, |
| 403 | }, |
| 404 | }, |
| 405 | }; |
| 406 | |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 407 | static int generate_si13(u_int8_t *output, struct gsm_bts *bts) |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 408 | { |
| 409 | struct gsm48_system_information_type_13 *si13 = |
| 410 | (struct gsm48_system_information_type_13 *) output; |
| 411 | int ret; |
| 412 | |
| 413 | memset(si13, GSM_MACBLOCK_PADDING, GSM_MACBLOCK_LEN); |
| 414 | |
| 415 | si13->header.rr_protocol_discriminator = GSM48_PDISC_RR; |
| 416 | si13->header.skip_indicator = 0; |
| 417 | si13->header.system_information = GSM48_MT_RR_SYSINFO_13; |
| 418 | |
| 419 | ret = rest_octets_si13(si13->rest_octets, &si13_default); |
| 420 | if (ret < 0) |
| 421 | return ret; |
| 422 | |
| 423 | si13->header.l2_plen = ret & 0xff; |
| 424 | |
| 425 | return GSM_MACBLOCK_LEN; |
| 426 | } |
| 427 | |
| 428 | int gsm_generate_si(u_int8_t *output, struct gsm_bts *bts, int type) |
| 429 | { |
| 430 | switch (type) { |
| 431 | case RSL_SYSTEM_INFO_1: |
| 432 | return generate_si1(output, bts); |
| 433 | case RSL_SYSTEM_INFO_2: |
| 434 | return generate_si2(output, bts); |
| 435 | case RSL_SYSTEM_INFO_3: |
| 436 | return generate_si3(output, bts); |
| 437 | case RSL_SYSTEM_INFO_4: |
| 438 | return generate_si4(output, bts); |
| 439 | case RSL_SYSTEM_INFO_5: |
| 440 | return generate_si5(output, bts); |
| 441 | case RSL_SYSTEM_INFO_6: |
| 442 | return generate_si6(output, bts); |
| 443 | case RSL_SYSTEM_INFO_13: |
| 444 | return generate_si13(output, bts); |
| 445 | default: |
| 446 | return -EINVAL; |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |