Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface, |
| 2 | * rest octet handling according to |
| 3 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 4 | |
| 5 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 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 <string.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <errno.h> |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 27 | #include <stdbool.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 28 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 29 | #include <openbsc/debug.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 30 | #include <openbsc/gsm_data.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 31 | #include <osmocom/core/bitvec.h> |
Max | e01f505 | 2016-04-23 18:00:18 +0200 | [diff] [blame] | 32 | #include <osmocom/gsm/bitvec_gsm.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 33 | #include <openbsc/rest_octets.h> |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 34 | #include <openbsc/arfcn_range_encode.h> |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 35 | #include <openbsc/system_information.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 36 | |
| 37 | /* generate SI1 rest octets */ |
Holger Hans Peter Freyther | f876c39 | 2013-03-06 12:02:33 +0100 | [diff] [blame] | 38 | int rest_octets_si1(uint8_t *data, uint8_t *nch_pos, int is1800_net) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 39 | { |
| 40 | struct bitvec bv; |
| 41 | |
| 42 | memset(&bv, 0, sizeof(bv)); |
| 43 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 44 | bv.data_len = 1; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 45 | |
| 46 | if (nch_pos) { |
| 47 | bitvec_set_bit(&bv, H); |
| 48 | bitvec_set_uint(&bv, *nch_pos, 5); |
| 49 | } else |
| 50 | bitvec_set_bit(&bv, L); |
| 51 | |
Holger Hans Peter Freyther | f876c39 | 2013-03-06 12:02:33 +0100 | [diff] [blame] | 52 | if (is1800_net) |
| 53 | bitvec_set_bit(&bv, L); |
| 54 | else |
| 55 | bitvec_set_bit(&bv, H); |
| 56 | |
| 57 | bitvec_spare_padding(&bv, 6); |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 58 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 59 | } |
| 60 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 61 | /* Append Repeated E-UTRAN Neighbour Cell to bitvec: |
| 62 | * see 3GPP TS 44.018 Table 10.5.2.33b.1 |
| 63 | */ |
| 64 | static inline void append_eutran_neib_cell(struct bitvec *bv, |
| 65 | const struct osmo_earfcn_si2q *e) |
| 66 | { |
| 67 | unsigned i; |
| 68 | for (i = 0; i < e->length; i++) { |
| 69 | if (e->arfcn[i] != OSMO_EARFCN_INVALID) { |
| 70 | bitvec_set_bit(bv, 1); /* EARFCN: */ |
| 71 | bitvec_set_uint(bv, e->arfcn[i], 16); |
| 72 | |
| 73 | if (OSMO_EARFCN_MEAS_INVALID == e->meas_bw[i]) |
| 74 | bitvec_set_bit(bv, 0); |
| 75 | else { |
| 76 | /* Measurement Bandwidth: 9.1.54 */ |
| 77 | bitvec_set_bit(bv, 1); |
| 78 | bitvec_set_uint(bv, e->meas_bw[i], 3); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /* stop bit - end of EARFCN + Measurement Bandwidth sequence */ |
| 84 | bitvec_set_bit(bv, 0); |
| 85 | |
| 86 | if (e->prio_valid) { |
| 87 | /* E-UTRAN_PRIORITY: 3GPP TS 45.008*/ |
| 88 | bitvec_set_bit(bv, 1); |
| 89 | bitvec_set_uint(bv, e->prio, 3); |
| 90 | } else |
| 91 | bitvec_set_bit(bv, 0); |
| 92 | |
| 93 | /* THRESH_E-UTRAN_high */ |
| 94 | bitvec_set_uint(bv, e->thresh_hi, 5); |
| 95 | |
| 96 | if (e->thresh_lo_valid) { |
| 97 | /* THRESH_E-UTRAN_low: */ |
| 98 | bitvec_set_bit(bv, 1); |
| 99 | bitvec_set_uint(bv, e->thresh_lo, 5); |
| 100 | } else |
| 101 | bitvec_set_bit(bv, 0); |
| 102 | |
| 103 | if (e->qrxlm_valid) { |
| 104 | /* E-UTRAN_QRXLEVMIN: */ |
| 105 | bitvec_set_bit(bv, 1); |
| 106 | bitvec_set_uint(bv, e->qrxlm, 5); |
| 107 | } else |
| 108 | bitvec_set_bit(bv, 0); |
| 109 | } |
| 110 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 111 | static inline void append_earfcn(struct bitvec *bv, |
| 112 | const struct osmo_earfcn_si2q *e) |
| 113 | { |
| 114 | /* Additions in Rel-5: */ |
| 115 | bitvec_set_bit(bv, H); |
| 116 | /* No 3G Additional Measurement Param. Descr. */ |
| 117 | bitvec_set_bit(bv, 0); |
| 118 | /* No 3G ADDITIONAL MEASUREMENT Param. Descr. 2 */ |
| 119 | bitvec_set_bit(bv, 0); |
| 120 | /* Additions in Rel-6: */ |
| 121 | bitvec_set_bit(bv, H); |
| 122 | /* 3G_CCN_ACTIVE */ |
| 123 | bitvec_set_bit(bv, 0); |
| 124 | /* Additions in Rel-7: */ |
| 125 | bitvec_set_bit(bv, H); |
| 126 | /* No 700_REPORTING_OFFSET */ |
| 127 | bitvec_set_bit(bv, 0); |
| 128 | /* No 810_REPORTING_OFFSET */ |
| 129 | bitvec_set_bit(bv, 0); |
| 130 | /* Additions in Rel-8: */ |
| 131 | bitvec_set_bit(bv, H); |
| 132 | |
| 133 | /* Priority and E-UTRAN Parameters Description */ |
| 134 | bitvec_set_bit(bv, 1); |
| 135 | |
| 136 | /* No Serving Cell Priority Parameters Descr. */ |
| 137 | bitvec_set_bit(bv, 0); |
| 138 | /* No 3G Priority Parameters Description */ |
| 139 | bitvec_set_bit(bv, 0); |
| 140 | /* E-UTRAN Parameters Description */ |
| 141 | bitvec_set_bit(bv, 1); |
| 142 | |
| 143 | /* E-UTRAN_CCN_ACTIVE */ |
| 144 | bitvec_set_bit(bv, 0); |
| 145 | /* E-UTRAN_Start: 9.1.54 */ |
| 146 | bitvec_set_bit(bv, 1); |
| 147 | /* E-UTRAN_Stop: 9.1.54 */ |
| 148 | bitvec_set_bit(bv, 1); |
| 149 | |
| 150 | /* No E-UTRAN Measurement Parameters Descr. */ |
| 151 | bitvec_set_bit(bv, 0); |
| 152 | /* No GPRS E-UTRAN Measurement Param. Descr. */ |
| 153 | bitvec_set_bit(bv, 0); |
| 154 | |
| 155 | /* Note: each of next 3 "repeated" structures might be repeated any |
| 156 | (0, 1, 2...) times - we only support 1 and 0 */ |
| 157 | |
| 158 | /* Repeated E-UTRAN Neighbour Cells */ |
| 159 | bitvec_set_bit(bv, 1); |
| 160 | |
| 161 | /* Note: we don't support different EARFCN arrays each with different |
| 162 | priority, threshold etc. */ |
| 163 | append_eutran_neib_cell(bv, e); |
| 164 | |
| 165 | /* stop bit - end of Repeated E-UTRAN Neighbour Cells sequence: */ |
| 166 | bitvec_set_bit(bv, 0); |
| 167 | |
| 168 | /* Note: following 2 repeated structs are not supported ATM */ |
| 169 | /* stop bit - end of Repeated E-UTRAN Not Allowed Cells sequence: */ |
| 170 | bitvec_set_bit(bv, 0); |
| 171 | /* stop bit - end of Repeated E-UTRAN PCID to TA mapping sequence: */ |
| 172 | bitvec_set_bit(bv, 0); |
| 173 | |
| 174 | /* Priority and E-UTRAN Parameters Description ends here */ |
| 175 | /* No 3G CSG Description */ |
| 176 | bitvec_set_bit(bv, 0); |
| 177 | /* No E-UTRAN CSG Description */ |
| 178 | bitvec_set_bit(bv, 0); |
| 179 | /* No Additions in Rel-9: */ |
| 180 | bitvec_set_bit(bv, L); |
| 181 | } |
| 182 | |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 183 | static inline void append_uarfcn(struct bitvec *bv, const uint16_t *u, |
| 184 | const uint16_t *sc, size_t length) |
| 185 | { |
| 186 | int f0_inc, i, arfcns_used, w[RANGE_ENC_MAX_ARFCNS], a[length]; |
| 187 | uint8_t chan_list[16] = {0}; |
| 188 | |
| 189 | /* 3G Neighbour Cell Description */ |
| 190 | bitvec_set_bit(bv, 1); |
| 191 | /* No Index_Start_3G */ |
| 192 | bitvec_set_bit(bv, 0); |
| 193 | /* No Absolute_Index_Start_EMR */ |
| 194 | bitvec_set_bit(bv, 0); |
| 195 | |
| 196 | /* UTRAN FDD Description */ |
| 197 | bitvec_set_bit(bv, 1); |
| 198 | /* No Bandwidth_FDD */ |
| 199 | bitvec_set_bit(bv, 0); |
| 200 | |
| 201 | memset(w, 0, sizeof(w)); |
| 202 | for (i = 0; i < length; i++) |
| 203 | a[i] = sc[i]; |
| 204 | |
| 205 | /* Note: we do not support repeating Neighbour Cells ATM */ |
| 206 | /* Repeated UTRAN FDD Neighbour Cells */ |
| 207 | bitvec_set_bit(bv, 1); |
| 208 | |
| 209 | /* FDD-ARFCN */ |
| 210 | bitvec_set_bit(bv, 0); |
| 211 | /* Note: we do not support multiple UARFCN values ATM: */ |
| 212 | bitvec_set_uint(bv, u[0], 14); |
| 213 | |
| 214 | arfcns_used = range_enc_filter_arfcns(a, length, 0, &f0_inc); |
| 215 | range_enc_arfcns(ARFCN_RANGE_1024, a, arfcns_used, w, 0); |
| 216 | range_enc_range1024(chan_list, 0, f0_inc, w); |
| 217 | |
| 218 | /* FDD_Indic0: parameter value '0000000000' is not a member of the set */ |
| 219 | bitvec_set_bit(bv, f0_inc); |
| 220 | /* NR_OF_FDD_CELLS */ |
| 221 | bitvec_set_uint(bv, length, 5); |
| 222 | |
| 223 | i = bv->cur_bit; |
| 224 | bitvec_add_range1024(bv, (struct gsm48_range_1024 *)chan_list); |
| 225 | bv->cur_bit = i + range1024_p(length); |
| 226 | |
| 227 | /* stop bit - end of Repeated UTRAN FDD Neighbour Cells */ |
| 228 | bitvec_set_bit(bv, 0); |
| 229 | |
| 230 | /* UTRAN TDD Description */ |
| 231 | bitvec_set_bit(bv, 0); |
| 232 | } |
| 233 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 234 | /* generate SI2quater rest octets: 3GPP TS 44.018 § 10.5.2.33b */ |
| 235 | int rest_octets_si2quater(uint8_t *data, const struct osmo_earfcn_si2q *e, |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 236 | const uint16_t *u, const uint16_t *sc, size_t u_len) |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 237 | { |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 238 | unsigned sz; |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 239 | struct bitvec bv; |
| 240 | bv.data = data; |
| 241 | bv.data_len = 20; |
| 242 | bitvec_zero(&bv); |
| 243 | |
| 244 | /* BA_IND */ |
| 245 | bitvec_set_bit(&bv, 1); |
| 246 | /* 3G_BA_IND */ |
| 247 | bitvec_set_bit(&bv, 1); |
| 248 | /* MP_CHANGE_MARK */ |
| 249 | bitvec_set_bit(&bv, 0); |
| 250 | |
| 251 | /* we do not support multiple si2quater messages at the moment: */ |
| 252 | /* SI2quater_INDEX */ |
| 253 | bitvec_set_uint(&bv, 0, 4); |
| 254 | /* SI2quater_COUNT */ |
| 255 | bitvec_set_uint(&bv, 0, 4); |
| 256 | |
| 257 | /* No Measurement_Parameters Description */ |
| 258 | bitvec_set_bit(&bv, 0); |
| 259 | /* No GPRS_Real Time Difference Description */ |
| 260 | bitvec_set_bit(&bv, 0); |
| 261 | /* No GPRS_BSIC Description */ |
| 262 | bitvec_set_bit(&bv, 0); |
| 263 | /* No GPRS_REPORT PRIORITY Description */ |
| 264 | bitvec_set_bit(&bv, 0); |
| 265 | /* No GPRS_MEASUREMENT_Parameters Description */ |
| 266 | bitvec_set_bit(&bv, 0); |
| 267 | /* No NC Measurement Parameters */ |
| 268 | bitvec_set_bit(&bv, 0); |
| 269 | /* No extension (length) */ |
| 270 | bitvec_set_bit(&bv, 0); |
| 271 | |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 272 | if (u_len) { |
| 273 | sz = uarfcn_size(u, sc, u_len); |
| 274 | /* Even if we do not append EARFCN we still need to set 3 bits */ |
| 275 | if (sz + bv.cur_bit + 3 > SI2Q_MAX_LEN) { |
| 276 | LOGP(DRR, LOGL_ERROR, "SI2quater: not enough memory to " |
| 277 | "add UARFCNs bits, current %u + required %u + " |
| 278 | "reminder %u > max %u\n", bv.cur_bit, sz, 3, |
| 279 | SI2Q_MAX_LEN); |
| 280 | return -ENOMEM; |
| 281 | } |
| 282 | append_uarfcn(&bv, u, sc, u_len); |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 283 | } else { /* No 3G Neighbour Cell Description */ |
| 284 | bitvec_set_bit(&bv, 0); |
| 285 | } |
| 286 | |
| 287 | /* No 3G Measurement Parameters Description */ |
| 288 | bitvec_set_bit(&bv, 0); |
| 289 | /* No GPRS_3G_MEASUREMENT Parameters Descr. */ |
| 290 | bitvec_set_bit(&bv, 0); |
| 291 | |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 292 | if (e) { |
| 293 | sz = earfcn_size(e); |
| 294 | if (sz + bv.cur_bit > SI2Q_MAX_LEN) { |
| 295 | LOGP(DRR, LOGL_ERROR, "SI2quater: not enough memory to " |
| 296 | "add EARFCNs bits, current %u + required %u > max " |
| 297 | "%u\n", bv.cur_bit, sz, SI2Q_MAX_LEN); |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 298 | return -ENOMEM; |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 299 | } |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 300 | append_earfcn(&bv, e); |
| 301 | } else { |
| 302 | /* No Additions in Rel-5: */ |
| 303 | bitvec_set_bit(&bv, L); |
| 304 | } |
| 305 | |
| 306 | bitvec_spare_padding(&bv, (bv.data_len * 8) - 1); |
| 307 | return bv.data_len; |
| 308 | } |
| 309 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 310 | /* Append selection parameters to bitvec */ |
| 311 | static void append_selection_params(struct bitvec *bv, |
| 312 | const struct gsm48_si_selection_params *sp) |
| 313 | { |
| 314 | if (sp->present) { |
| 315 | bitvec_set_bit(bv, H); |
| 316 | bitvec_set_bit(bv, sp->cbq); |
| 317 | bitvec_set_uint(bv, sp->cell_resel_off, 6); |
| 318 | bitvec_set_uint(bv, sp->temp_offs, 3); |
| 319 | bitvec_set_uint(bv, sp->penalty_time, 5); |
| 320 | } else |
| 321 | bitvec_set_bit(bv, L); |
| 322 | } |
| 323 | |
| 324 | /* Append power offset to bitvec */ |
| 325 | static void append_power_offset(struct bitvec *bv, |
| 326 | const struct gsm48_si_power_offset *po) |
| 327 | { |
| 328 | if (po->present) { |
| 329 | bitvec_set_bit(bv, H); |
| 330 | bitvec_set_uint(bv, po->power_offset, 2); |
| 331 | } else |
| 332 | bitvec_set_bit(bv, L); |
| 333 | } |
| 334 | |
| 335 | /* Append GPRS indicator to bitvec */ |
| 336 | static void append_gprs_ind(struct bitvec *bv, |
| 337 | const struct gsm48_si3_gprs_ind *gi) |
| 338 | { |
| 339 | if (gi->present) { |
| 340 | bitvec_set_bit(bv, H); |
| 341 | bitvec_set_uint(bv, gi->ra_colour, 3); |
| 342 | /* 0 == SI13 in BCCH Norm, 1 == SI13 sent on BCCH Ext */ |
| 343 | bitvec_set_bit(bv, gi->si13_position); |
| 344 | } else |
| 345 | bitvec_set_bit(bv, L); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | /* Generate SI3 Rest Octests (Chapter 10.5.2.34 / Table 10.4.72) */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 350 | int rest_octets_si3(uint8_t *data, const struct gsm48_si_ro_info *si3) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 351 | { |
| 352 | struct bitvec bv; |
| 353 | |
| 354 | memset(&bv, 0, sizeof(bv)); |
| 355 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 356 | bv.data_len = 4; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 357 | |
| 358 | /* Optional Selection Parameters */ |
| 359 | append_selection_params(&bv, &si3->selection_params); |
| 360 | |
| 361 | /* Optional Power Offset */ |
| 362 | append_power_offset(&bv, &si3->power_offset); |
| 363 | |
| 364 | /* Do we have a SI2ter on the BCCH? */ |
| 365 | if (si3->si2ter_indicator) |
| 366 | bitvec_set_bit(&bv, H); |
| 367 | else |
| 368 | bitvec_set_bit(&bv, L); |
| 369 | |
| 370 | /* Early Classmark Sending Control */ |
| 371 | if (si3->early_cm_ctrl) |
| 372 | bitvec_set_bit(&bv, H); |
| 373 | else |
| 374 | bitvec_set_bit(&bv, L); |
| 375 | |
| 376 | /* Do we have a SI Type 9 on the BCCH? */ |
| 377 | if (si3->scheduling.present) { |
| 378 | bitvec_set_bit(&bv, H); |
| 379 | bitvec_set_uint(&bv, si3->scheduling.where, 3); |
| 380 | } else |
| 381 | bitvec_set_bit(&bv, L); |
| 382 | |
| 383 | /* GPRS Indicator */ |
| 384 | append_gprs_ind(&bv, &si3->gprs_ind); |
| 385 | |
Max | f3f3505 | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 386 | /* 3G Early Classmark Sending Restriction controlled by |
| 387 | * early_cm_ctrl above */ |
| 388 | bitvec_set_bit(&bv, H); |
| 389 | |
| 390 | if (si3->si2quater_indicator) { |
| 391 | bitvec_set_bit(&bv, H); /* indicator struct present */ |
| 392 | bitvec_set_uint(&bv, 0, 1); /* message is sent on BCCH Norm */ |
| 393 | } |
| 394 | |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 395 | bitvec_spare_padding(&bv, (bv.data_len*8)-1); |
| 396 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static int append_lsa_params(struct bitvec *bv, |
| 400 | const struct gsm48_lsa_params *lsa_params) |
| 401 | { |
| 402 | /* FIXME */ |
Holger Hans Peter Freyther | ae80f92 | 2010-04-10 00:05:16 +0200 | [diff] [blame] | 403 | return -1; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* Generate SI4 Rest Octets (Chapter 10.5.2.35) */ |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 407 | int rest_octets_si4(uint8_t *data, const struct gsm48_si_ro_info *si4, int len) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 408 | { |
| 409 | struct bitvec bv; |
| 410 | |
| 411 | memset(&bv, 0, sizeof(bv)); |
| 412 | bv.data = data; |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 413 | bv.data_len = len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 414 | |
| 415 | /* SI4 Rest Octets O */ |
| 416 | append_selection_params(&bv, &si4->selection_params); |
| 417 | append_power_offset(&bv, &si4->power_offset); |
| 418 | append_gprs_ind(&bv, &si4->gprs_ind); |
| 419 | |
| 420 | if (0 /* FIXME */) { |
| 421 | /* H and SI4 Rest Octets S */ |
| 422 | bitvec_set_bit(&bv, H); |
| 423 | |
| 424 | /* LSA Parameters */ |
| 425 | if (si4->lsa_params.present) { |
| 426 | bitvec_set_bit(&bv, H); |
| 427 | append_lsa_params(&bv, &si4->lsa_params); |
| 428 | } else |
| 429 | bitvec_set_bit(&bv, L); |
| 430 | |
| 431 | /* Cell Identity */ |
| 432 | if (1) { |
| 433 | bitvec_set_bit(&bv, H); |
| 434 | bitvec_set_uint(&bv, si4->cell_id, 16); |
| 435 | } else |
| 436 | bitvec_set_bit(&bv, L); |
| 437 | |
| 438 | /* LSA ID Information */ |
| 439 | if (0) { |
| 440 | bitvec_set_bit(&bv, H); |
| 441 | /* FIXME */ |
| 442 | } else |
| 443 | bitvec_set_bit(&bv, L); |
| 444 | } else { |
| 445 | /* L and break indicator */ |
| 446 | bitvec_set_bit(&bv, L); |
| 447 | bitvec_set_bit(&bv, si4->break_ind ? H : L); |
| 448 | } |
| 449 | |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 450 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* GPRS Mobile Allocation as per TS 04.60 Chapter 12.10a: |
| 454 | < GPRS Mobile Allocation IE > ::= |
| 455 | < HSN : bit (6) > |
| 456 | { 0 | 1 < RFL number list : < RFL number list struct > > } |
| 457 | { 0 < MA_LENGTH : bit (6) > |
| 458 | < MA_BITMAP: bit (val(MA_LENGTH) + 1) > |
| 459 | | 1 { 0 | 1 <ARFCN index list : < ARFCN index list struct > > } } ; |
| 460 | |
| 461 | < RFL number list struct > :: = |
| 462 | < RFL_NUMBER : bit (4) > |
| 463 | { 0 | 1 < RFL number list struct > } ; |
| 464 | < ARFCN index list struct > ::= |
| 465 | < ARFCN_INDEX : bit(6) > |
| 466 | { 0 | 1 < ARFCN index list struct > } ; |
| 467 | */ |
| 468 | static int append_gprs_mobile_alloc(struct bitvec *bv) |
| 469 | { |
| 470 | /* Hopping Sequence Number */ |
| 471 | bitvec_set_uint(bv, 0, 6); |
| 472 | |
| 473 | if (0) { |
| 474 | /* We want to use a RFL number list */ |
| 475 | bitvec_set_bit(bv, 1); |
| 476 | /* FIXME: RFL number list */ |
| 477 | } else |
| 478 | bitvec_set_bit(bv, 0); |
| 479 | |
| 480 | if (0) { |
| 481 | /* We want to use a MA_BITMAP */ |
| 482 | bitvec_set_bit(bv, 0); |
| 483 | /* FIXME: MA_LENGTH, MA_BITMAP, ... */ |
| 484 | } else { |
| 485 | bitvec_set_bit(bv, 1); |
| 486 | if (0) { |
| 487 | /* We want to provide an ARFCN index list */ |
| 488 | bitvec_set_bit(bv, 1); |
| 489 | /* FIXME */ |
| 490 | } else |
| 491 | bitvec_set_bit(bv, 0); |
| 492 | } |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static int encode_t3192(unsigned int t3192) |
| 497 | { |
| 498 | if (t3192 == 0) |
| 499 | return 3; |
| 500 | else if (t3192 <= 80) |
| 501 | return 4; |
| 502 | else if (t3192 <= 120) |
| 503 | return 5; |
| 504 | else if (t3192 <= 160) |
| 505 | return 6; |
| 506 | else if (t3192 <= 200) |
| 507 | return 7; |
| 508 | else if (t3192 <= 500) |
| 509 | return 0; |
| 510 | else if (t3192 <= 1000) |
| 511 | return 1; |
| 512 | else if (t3192 <= 1500) |
| 513 | return 2; |
| 514 | else |
| 515 | return -EINVAL; |
| 516 | } |
| 517 | |
| 518 | static int encode_drx_timer(unsigned int drx) |
| 519 | { |
| 520 | if (drx == 0) |
| 521 | return 0; |
| 522 | else if (drx == 1) |
| 523 | return 1; |
| 524 | else if (drx == 2) |
| 525 | return 2; |
| 526 | else if (drx <= 4) |
| 527 | return 3; |
| 528 | else if (drx <= 8) |
| 529 | return 4; |
| 530 | else if (drx <= 16) |
| 531 | return 5; |
| 532 | else if (drx <= 32) |
| 533 | return 6; |
| 534 | else if (drx <= 64) |
| 535 | return 7; |
| 536 | else |
| 537 | return -EINVAL; |
| 538 | } |
| 539 | |
| 540 | /* GPRS Cell Options as per TS 04.60 Chapter 12.24 |
| 541 | < GPRS Cell Options IE > ::= |
| 542 | < NMO : bit(2) > |
| 543 | < T3168 : bit(3) > |
| 544 | < T3192 : bit(3) > |
| 545 | < DRX_TIMER_MAX: bit(3) > |
| 546 | < ACCESS_BURST_TYPE: bit > |
| 547 | < CONTROL_ACK_TYPE : bit > |
| 548 | < BS_CV_MAX: bit(4) > |
| 549 | { 0 | 1 < PAN_DEC : bit(3) > |
| 550 | < PAN_INC : bit(3) > |
| 551 | < PAN_MAX : bit(3) > |
| 552 | { 0 | 1 < Extension Length : bit(6) > |
| 553 | < bit (val(Extension Length) + 1 |
| 554 | & { < Extension Information > ! { bit ** = <no string> } } ; |
| 555 | < Extension Information > ::= |
| 556 | { 0 | 1 < EGPRS_PACKET_CHANNEL_REQUEST : bit > |
| 557 | < BEP_PERIOD : bit(4) > } |
| 558 | < PFC_FEATURE_MODE : bit > |
| 559 | < DTM_SUPPORT : bit > |
| 560 | <BSS_PAGING_COORDINATION: bit > |
| 561 | <spare bit > ** ; |
| 562 | */ |
Harald Welte | a4e2d04 | 2009-12-20 17:08:22 +0100 | [diff] [blame] | 563 | static int append_gprs_cell_opt(struct bitvec *bv, |
| 564 | const struct gprs_cell_options *gco) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 565 | { |
| 566 | int t3192, drx_timer_max; |
| 567 | |
| 568 | t3192 = encode_t3192(gco->t3192); |
| 569 | if (t3192 < 0) |
| 570 | return t3192; |
| 571 | |
| 572 | drx_timer_max = encode_drx_timer(gco->drx_timer_max); |
| 573 | if (drx_timer_max < 0) |
| 574 | return drx_timer_max; |
| 575 | |
| 576 | bitvec_set_uint(bv, gco->nmo, 2); |
| 577 | bitvec_set_uint(bv, gco->t3168 / 500, 3); |
| 578 | bitvec_set_uint(bv, t3192, 3); |
| 579 | bitvec_set_uint(bv, drx_timer_max, 3); |
| 580 | /* ACCESS_BURST_TYPE: Hard-code 8bit */ |
| 581 | bitvec_set_bit(bv, 0); |
| 582 | /* CONTROL_ACK_TYPE: Hard-code to RLC/MAC control block */ |
| 583 | bitvec_set_bit(bv, 1); |
| 584 | bitvec_set_uint(bv, gco->bs_cv_max, 4); |
| 585 | |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 586 | if (0) { |
| 587 | /* hard-code no PAN_{DEC,INC,MAX} */ |
| 588 | bitvec_set_bit(bv, 0); |
| 589 | } else { |
| 590 | /* copied from ip.access BSC protocol trace */ |
| 591 | bitvec_set_bit(bv, 1); |
| 592 | bitvec_set_uint(bv, 1, 3); /* DEC */ |
| 593 | bitvec_set_uint(bv, 1, 3); /* INC */ |
| 594 | bitvec_set_uint(bv, 15, 3); /* MAX */ |
| 595 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 596 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 597 | if (!gco->ext_info_present) { |
| 598 | /* no extension information */ |
| 599 | bitvec_set_bit(bv, 0); |
| 600 | } else { |
| 601 | /* extension information */ |
| 602 | bitvec_set_bit(bv, 1); |
| 603 | if (!gco->ext_info.egprs_supported) { |
| 604 | /* 6bit length of extension */ |
Harald Welte | 39608dc | 2010-04-18 22:47:22 +0200 | [diff] [blame] | 605 | bitvec_set_uint(bv, (1 + 3)-1, 6); |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 606 | /* EGPRS supported in the cell */ |
| 607 | bitvec_set_bit(bv, 0); |
| 608 | } else { |
| 609 | /* 6bit length of extension */ |
Harald Welte | 39608dc | 2010-04-18 22:47:22 +0200 | [diff] [blame] | 610 | bitvec_set_uint(bv, (1 + 5 + 3)-1, 6); |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 611 | /* EGPRS supported in the cell */ |
| 612 | bitvec_set_bit(bv, 1); |
| 613 | /* 1bit EGPRS PACKET CHANNEL REQUEST */ |
| 614 | bitvec_set_bit(bv, gco->ext_info.use_egprs_p_ch_req); |
| 615 | /* 4bit BEP PERIOD */ |
| 616 | bitvec_set_uint(bv, gco->ext_info.bep_period, 4); |
| 617 | } |
| 618 | bitvec_set_bit(bv, gco->ext_info.pfc_supported); |
| 619 | bitvec_set_bit(bv, gco->ext_info.dtm_supported); |
| 620 | bitvec_set_bit(bv, gco->ext_info.bss_paging_coordination); |
| 621 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | static void append_gprs_pwr_ctrl_pars(struct bitvec *bv, |
Harald Welte | a4e2d04 | 2009-12-20 17:08:22 +0100 | [diff] [blame] | 627 | const struct gprs_power_ctrl_pars *pcp) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 628 | { |
| 629 | bitvec_set_uint(bv, pcp->alpha, 4); |
| 630 | bitvec_set_uint(bv, pcp->t_avg_w, 5); |
| 631 | bitvec_set_uint(bv, pcp->t_avg_t, 5); |
| 632 | bitvec_set_uint(bv, pcp->pc_meas_chan, 1); |
| 633 | bitvec_set_uint(bv, pcp->n_avg_i, 4); |
| 634 | } |
| 635 | |
Harald Welte | 5fda908 | 2010-04-18 22:41:01 +0200 | [diff] [blame] | 636 | /* Generate SI13 Rest Octests (04.08 Chapter 10.5.2.37b) */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 637 | int rest_octets_si13(uint8_t *data, const struct gsm48_si13_info *si13) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 638 | { |
| 639 | struct bitvec bv; |
| 640 | |
| 641 | memset(&bv, 0, sizeof(bv)); |
| 642 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 643 | bv.data_len = 20; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 644 | |
| 645 | if (0) { |
| 646 | /* No rest octets */ |
| 647 | bitvec_set_bit(&bv, L); |
| 648 | } else { |
| 649 | bitvec_set_bit(&bv, H); |
| 650 | bitvec_set_uint(&bv, si13->bcch_change_mark, 3); |
| 651 | bitvec_set_uint(&bv, si13->si_change_field, 4); |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 652 | if (1) { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 653 | bitvec_set_bit(&bv, 0); |
| 654 | } else { |
| 655 | bitvec_set_bit(&bv, 1); |
| 656 | bitvec_set_uint(&bv, si13->bcch_change_mark, 2); |
| 657 | append_gprs_mobile_alloc(&bv); |
| 658 | } |
| 659 | if (!si13->pbcch_present) { |
| 660 | /* PBCCH not present in cell */ |
| 661 | bitvec_set_bit(&bv, 0); |
| 662 | bitvec_set_uint(&bv, si13->no_pbcch.rac, 8); |
| 663 | bitvec_set_bit(&bv, si13->no_pbcch.spgc_ccch_sup); |
| 664 | bitvec_set_uint(&bv, si13->no_pbcch.prio_acc_thr, 3); |
| 665 | bitvec_set_uint(&bv, si13->no_pbcch.net_ctrl_ord, 2); |
| 666 | append_gprs_cell_opt(&bv, &si13->cell_opts); |
| 667 | append_gprs_pwr_ctrl_pars(&bv, &si13->pwr_ctrl_pars); |
| 668 | } else { |
| 669 | /* PBCCH present in cell */ |
| 670 | bitvec_set_bit(&bv, 1); |
| 671 | bitvec_set_uint(&bv, si13->pbcch.psi1_rep_per, 4); |
| 672 | /* PBCCH Descripiton */ |
| 673 | bitvec_set_uint(&bv, si13->pbcch.pb, 4); |
| 674 | bitvec_set_uint(&bv, si13->pbcch.tsc, 3); |
| 675 | bitvec_set_uint(&bv, si13->pbcch.tn, 3); |
| 676 | switch (si13->pbcch.carrier_type) { |
| 677 | case PBCCH_BCCH: |
| 678 | bitvec_set_bit(&bv, 0); |
| 679 | bitvec_set_bit(&bv, 0); |
| 680 | break; |
| 681 | case PBCCH_ARFCN: |
| 682 | bitvec_set_bit(&bv, 0); |
| 683 | bitvec_set_bit(&bv, 1); |
| 684 | bitvec_set_uint(&bv, si13->pbcch.arfcn, 10); |
| 685 | break; |
| 686 | case PBCCH_MAIO: |
| 687 | bitvec_set_bit(&bv, 1); |
| 688 | bitvec_set_uint(&bv, si13->pbcch.maio, 6); |
| 689 | break; |
| 690 | } |
| 691 | } |
Harald Welte | 5fda908 | 2010-04-18 22:41:01 +0200 | [diff] [blame] | 692 | /* 3GPP TS 44.018 Release 6 / 10.5.2.37b */ |
| 693 | bitvec_set_bit(&bv, H); /* added Release 99 */ |
| 694 | /* claim our SGSN is compatible with Release 99, as EDGE and EGPRS |
| 695 | * was only added in this Release */ |
| 696 | bitvec_set_bit(&bv, 1); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 697 | } |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 698 | bitvec_spare_padding(&bv, (bv.data_len*8)-1); |
| 699 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 700 | } |