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 | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 61 | /* Append Repeated E-UTRAN Neighbour Cell to bitvec: see 3GPP TS 44.018 Table 10.5.2.33b.1 */ |
| 62 | static inline void append_eutran_neib_cell(struct bitvec *bv, struct gsm_bts *bts, uint8_t budget) |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 63 | { |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 64 | const struct osmo_earfcn_si2q *e = &bts->si_common.si2quater_neigh_list; |
| 65 | unsigned i, skip = 0; |
| 66 | size_t offset = bts->e_offset; |
| 67 | uint8_t rem = budget - 6, earfcn_budget; /* account for mandatory stop bit and THRESH_E-UTRAN_high */ |
| 68 | /* first we have to properly adjust budget requirements */ |
| 69 | if (e->prio_valid) /* E-UTRAN_PRIORITY: 3GPP TS 45.008*/ |
| 70 | rem -= 4; |
| 71 | else |
| 72 | rem--; |
| 73 | |
| 74 | if (e->thresh_lo_valid) /* THRESH_E-UTRAN_low: */ |
| 75 | rem -= 6; |
| 76 | else |
| 77 | rem--; |
| 78 | |
| 79 | if (e->qrxlm_valid) /* E-UTRAN_QRXLEVMIN: */ |
| 80 | rem -= 6; |
| 81 | else |
| 82 | rem--; |
| 83 | |
| 84 | /* now we can proceed with actually adding EARFCNs within adjusted budget limit */ |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 85 | for (i = 0; i < e->length; i++) { |
| 86 | if (e->arfcn[i] != OSMO_EARFCN_INVALID) { |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 87 | if (skip < offset) { |
| 88 | skip++; /* ignore EARFCNs added on previous calls */ |
| 89 | } else { |
| 90 | earfcn_budget = 17; /* computer budget per-EARFCN */ |
| 91 | if (OSMO_EARFCN_MEAS_INVALID == e->meas_bw[i]) |
| 92 | earfcn_budget++; |
| 93 | else |
| 94 | earfcn_budget += 4; |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 95 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 96 | if (rem - earfcn_budget < 0) { |
| 97 | break; |
| 98 | } else { |
| 99 | bts->e_offset++; |
| 100 | bitvec_set_bit(bv, 1); /* EARFCN: */ |
| 101 | bitvec_set_uint(bv, e->arfcn[i], 16); |
| 102 | |
| 103 | if (OSMO_EARFCN_MEAS_INVALID == e->meas_bw[i]) |
| 104 | bitvec_set_bit(bv, 0); |
| 105 | else { /* Measurement Bandwidth: 9.1.54 */ |
| 106 | bitvec_set_bit(bv, 1); |
| 107 | bitvec_set_uint(bv, e->meas_bw[i], 3); |
| 108 | } |
| 109 | } |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /* stop bit - end of EARFCN + Measurement Bandwidth sequence */ |
| 115 | bitvec_set_bit(bv, 0); |
| 116 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 117 | /* Note: we don't support different EARFCN arrays each with different priority, threshold etc. */ |
| 118 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 119 | if (e->prio_valid) { |
| 120 | /* E-UTRAN_PRIORITY: 3GPP TS 45.008*/ |
| 121 | bitvec_set_bit(bv, 1); |
| 122 | bitvec_set_uint(bv, e->prio, 3); |
| 123 | } else |
| 124 | bitvec_set_bit(bv, 0); |
| 125 | |
| 126 | /* THRESH_E-UTRAN_high */ |
| 127 | bitvec_set_uint(bv, e->thresh_hi, 5); |
| 128 | |
| 129 | if (e->thresh_lo_valid) { |
| 130 | /* THRESH_E-UTRAN_low: */ |
| 131 | bitvec_set_bit(bv, 1); |
| 132 | bitvec_set_uint(bv, e->thresh_lo, 5); |
| 133 | } else |
| 134 | bitvec_set_bit(bv, 0); |
| 135 | |
| 136 | if (e->qrxlm_valid) { |
| 137 | /* E-UTRAN_QRXLEVMIN: */ |
| 138 | bitvec_set_bit(bv, 1); |
| 139 | bitvec_set_uint(bv, e->qrxlm, 5); |
| 140 | } else |
| 141 | bitvec_set_bit(bv, 0); |
| 142 | } |
| 143 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 144 | static inline void append_earfcn(struct bitvec *bv, struct gsm_bts *bts, uint8_t budget) |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 145 | { |
| 146 | /* Additions in Rel-5: */ |
| 147 | bitvec_set_bit(bv, H); |
| 148 | /* No 3G Additional Measurement Param. Descr. */ |
| 149 | bitvec_set_bit(bv, 0); |
| 150 | /* No 3G ADDITIONAL MEASUREMENT Param. Descr. 2 */ |
| 151 | bitvec_set_bit(bv, 0); |
| 152 | /* Additions in Rel-6: */ |
| 153 | bitvec_set_bit(bv, H); |
| 154 | /* 3G_CCN_ACTIVE */ |
| 155 | bitvec_set_bit(bv, 0); |
| 156 | /* Additions in Rel-7: */ |
| 157 | bitvec_set_bit(bv, H); |
| 158 | /* No 700_REPORTING_OFFSET */ |
| 159 | bitvec_set_bit(bv, 0); |
| 160 | /* No 810_REPORTING_OFFSET */ |
| 161 | bitvec_set_bit(bv, 0); |
| 162 | /* Additions in Rel-8: */ |
| 163 | bitvec_set_bit(bv, H); |
| 164 | |
| 165 | /* Priority and E-UTRAN Parameters Description */ |
| 166 | bitvec_set_bit(bv, 1); |
| 167 | |
| 168 | /* No Serving Cell Priority Parameters Descr. */ |
| 169 | bitvec_set_bit(bv, 0); |
| 170 | /* No 3G Priority Parameters Description */ |
| 171 | bitvec_set_bit(bv, 0); |
| 172 | /* E-UTRAN Parameters Description */ |
| 173 | bitvec_set_bit(bv, 1); |
| 174 | |
| 175 | /* E-UTRAN_CCN_ACTIVE */ |
| 176 | bitvec_set_bit(bv, 0); |
| 177 | /* E-UTRAN_Start: 9.1.54 */ |
| 178 | bitvec_set_bit(bv, 1); |
| 179 | /* E-UTRAN_Stop: 9.1.54 */ |
| 180 | bitvec_set_bit(bv, 1); |
| 181 | |
| 182 | /* No E-UTRAN Measurement Parameters Descr. */ |
| 183 | bitvec_set_bit(bv, 0); |
| 184 | /* No GPRS E-UTRAN Measurement Param. Descr. */ |
| 185 | bitvec_set_bit(bv, 0); |
| 186 | |
| 187 | /* Note: each of next 3 "repeated" structures might be repeated any |
| 188 | (0, 1, 2...) times - we only support 1 and 0 */ |
| 189 | |
| 190 | /* Repeated E-UTRAN Neighbour Cells */ |
| 191 | bitvec_set_bit(bv, 1); |
| 192 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 193 | /* N. B: 25 bits are set in append_earfcn() - keep it in sync with budget adjustment below: */ |
| 194 | append_eutran_neib_cell(bv, bts, budget - 25); |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 195 | |
| 196 | /* stop bit - end of Repeated E-UTRAN Neighbour Cells sequence: */ |
| 197 | bitvec_set_bit(bv, 0); |
| 198 | |
| 199 | /* Note: following 2 repeated structs are not supported ATM */ |
| 200 | /* stop bit - end of Repeated E-UTRAN Not Allowed Cells sequence: */ |
| 201 | bitvec_set_bit(bv, 0); |
| 202 | /* stop bit - end of Repeated E-UTRAN PCID to TA mapping sequence: */ |
| 203 | bitvec_set_bit(bv, 0); |
| 204 | |
| 205 | /* Priority and E-UTRAN Parameters Description ends here */ |
| 206 | /* No 3G CSG Description */ |
| 207 | bitvec_set_bit(bv, 0); |
| 208 | /* No E-UTRAN CSG Description */ |
| 209 | bitvec_set_bit(bv, 0); |
| 210 | /* No Additions in Rel-9: */ |
| 211 | bitvec_set_bit(bv, L); |
| 212 | } |
| 213 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 214 | static inline int f0_helper(int *sc, size_t length, uint8_t *chan_list) |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 215 | { |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 216 | int w[RANGE_ENC_MAX_ARFCNS] = { 0 }; |
| 217 | |
| 218 | return range_encode(ARFCN_RANGE_1024, sc, length, w, 0, chan_list); |
| 219 | } |
| 220 | |
| 221 | /* Estimate how many bits it'll take to append single FDD UARFCN */ |
| 222 | static inline int append_utran_fdd_length(uint16_t u, int *sc, size_t sc_len, size_t length) |
| 223 | { |
| 224 | uint8_t chan_list[16] = { 0 }; |
| 225 | int tmp[sc_len], f0; |
| 226 | |
| 227 | memcpy(tmp, sc, sizeof(tmp)); |
| 228 | |
| 229 | f0 = f0_helper(tmp, length, chan_list); |
| 230 | if (f0 < 0) |
| 231 | return f0; |
| 232 | |
| 233 | return 21 + range1024_p(length); |
| 234 | } |
| 235 | |
| 236 | /* Append single FDD UARFCN */ |
| 237 | static inline int append_utran_fdd(struct bitvec *bv, uint16_t u, int *sc, size_t length) |
| 238 | { |
| 239 | uint8_t chan_list[16] = { 0 }; |
| 240 | int f0 = f0_helper(sc, length, chan_list); |
| 241 | |
| 242 | if (f0 < 0) |
| 243 | return f0; |
| 244 | |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 245 | /* Repeated UTRAN FDD Neighbour Cells */ |
| 246 | bitvec_set_bit(bv, 1); |
| 247 | |
| 248 | /* FDD-ARFCN */ |
| 249 | bitvec_set_bit(bv, 0); |
| 250 | bitvec_set_uint(bv, u, 14); |
| 251 | |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 252 | /* FDD_Indic0: parameter value '0000000000' is a member of the set? */ |
| 253 | bitvec_set_bit(bv, f0); |
| 254 | /* NR_OF_FDD_CELLS */ |
| 255 | bitvec_set_uint(bv, length, 5); |
| 256 | |
| 257 | f0 = bv->cur_bit; |
| 258 | bitvec_add_range1024(bv, (struct gsm48_range_1024 *)chan_list); |
| 259 | bv->cur_bit = f0 + range1024_p(length); |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 260 | |
| 261 | return 21 + range1024_p(length); |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* Append multiple FDD UARFCNs */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 265 | static inline int append_uarfcns(struct bitvec *bv, struct gsm_bts *bts, uint8_t budget) |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 266 | { |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 267 | const uint16_t *u = bts->si_common.data.uarfcn_list, *sc = bts->si_common.data.scramble_list; |
| 268 | int i, j, k, rc, st = 0, a[bts->si_common.uarfcn_length]; |
| 269 | uint16_t cu = u[bts->u_offset]; /* caller ensures that length is positive */ |
| 270 | uint8_t rem = budget - 7; /* account for constant bits right away */ |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 271 | |
| 272 | /* 3G Neighbour Cell Description */ |
| 273 | bitvec_set_bit(bv, 1); |
| 274 | /* No Index_Start_3G */ |
| 275 | bitvec_set_bit(bv, 0); |
| 276 | /* No Absolute_Index_Start_EMR */ |
| 277 | bitvec_set_bit(bv, 0); |
| 278 | |
| 279 | /* UTRAN FDD Description */ |
| 280 | bitvec_set_bit(bv, 1); |
| 281 | /* No Bandwidth_FDD */ |
| 282 | bitvec_set_bit(bv, 0); |
| 283 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 284 | for (i = bts->u_offset; i < bts->si_common.uarfcn_length; i++) { |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 285 | for (j = st, k = 0; j < i; j++) |
| 286 | a[k++] = sc[j]; /* copy corresponding SCs */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 287 | |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 288 | if (u[i] != cu) { /* we've reached new UARFCN */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 289 | rc = append_utran_fdd_length(cu, a, bts->si_common.uarfcn_length, k); |
| 290 | if (rc < 0) { /* estimate bit length requirements */ |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 291 | return rc; |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if (rem - rc < 0) { |
| 295 | break; /* we have ran out of budget in current SI2q */ |
| 296 | } else { |
| 297 | rem -= append_utran_fdd(bv, cu, a, k); |
| 298 | bts->u_offset++; |
| 299 | } |
Max | e610e70 | 2016-12-19 13:41:48 +0100 | [diff] [blame] | 300 | cu = u[i]; |
| 301 | st = i; /* update start position */ |
| 302 | } |
| 303 | } |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 304 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 305 | if (rem > 22) { /* add last UARFCN not covered by previous cycle if it could possibly fit into budget */ |
| 306 | for (i = st, k = 0; i < bts->si_common.uarfcn_length; i++) |
| 307 | a[k++] = sc[i]; |
| 308 | |
| 309 | rc = append_utran_fdd_length(cu, a, bts->si_common.uarfcn_length, k); |
| 310 | if (rc < 0) { |
| 311 | return rc; |
| 312 | } |
| 313 | |
| 314 | if (rem - rc >= 0) { |
| 315 | rem -= append_utran_fdd(bv, cu, a, k); |
| 316 | bts->u_offset++; |
| 317 | } |
| 318 | } |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 319 | |
| 320 | /* stop bit - end of Repeated UTRAN FDD Neighbour Cells */ |
| 321 | bitvec_set_bit(bv, 0); |
| 322 | |
| 323 | /* UTRAN TDD Description */ |
| 324 | bitvec_set_bit(bv, 0); |
Max | 881064e | 2016-12-14 14:51:40 +0100 | [diff] [blame] | 325 | |
| 326 | return 0; |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 329 | /* generate SI2quater rest octets: 3GPP TS 44.018 § 10.5.2.33b */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 330 | int rest_octets_si2quater(uint8_t *data, struct gsm_bts *bts) |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 331 | { |
Max | 881064e | 2016-12-14 14:51:40 +0100 | [diff] [blame] | 332 | int rc; |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 333 | struct bitvec bv; |
| 334 | bv.data = data; |
| 335 | bv.data_len = 20; |
| 336 | bitvec_zero(&bv); |
| 337 | |
| 338 | /* BA_IND */ |
| 339 | bitvec_set_bit(&bv, 1); |
| 340 | /* 3G_BA_IND */ |
| 341 | bitvec_set_bit(&bv, 1); |
| 342 | /* MP_CHANGE_MARK */ |
| 343 | bitvec_set_bit(&bv, 0); |
| 344 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 345 | /* SI2quater_INDEX */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 346 | bitvec_set_uint(&bv, bts->si2q_index, 4); |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 347 | /* SI2quater_COUNT */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 348 | bitvec_set_uint(&bv, bts->si2q_count, 4); |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 349 | |
| 350 | /* No Measurement_Parameters Description */ |
| 351 | bitvec_set_bit(&bv, 0); |
| 352 | /* No GPRS_Real Time Difference Description */ |
| 353 | bitvec_set_bit(&bv, 0); |
| 354 | /* No GPRS_BSIC Description */ |
| 355 | bitvec_set_bit(&bv, 0); |
| 356 | /* No GPRS_REPORT PRIORITY Description */ |
| 357 | bitvec_set_bit(&bv, 0); |
| 358 | /* No GPRS_MEASUREMENT_Parameters Description */ |
| 359 | bitvec_set_bit(&bv, 0); |
| 360 | /* No NC Measurement Parameters */ |
| 361 | bitvec_set_bit(&bv, 0); |
| 362 | /* No extension (length) */ |
| 363 | bitvec_set_bit(&bv, 0); |
| 364 | |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 365 | if (bts->si_common.uarfcn_length) { |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 366 | /* Even if we do not append EARFCN we still need to set 3 bits */ |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 367 | rc = append_uarfcns(&bv, bts, SI2Q_MAX_LEN - (bv.cur_bit + 3)); |
Max | 881064e | 2016-12-14 14:51:40 +0100 | [diff] [blame] | 368 | if (rc < 0) { |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 369 | LOGP(DRR, LOGL_ERROR, "SI2quater: failed to append %zu UARFCNs due to range encoding failure: %s\n", |
| 370 | bts->si_common.uarfcn_length, strerror(-rc)); |
Max | 881064e | 2016-12-14 14:51:40 +0100 | [diff] [blame] | 371 | return rc; |
| 372 | } |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 373 | } else { /* No 3G Neighbour Cell Description */ |
| 374 | bitvec_set_bit(&bv, 0); |
| 375 | } |
| 376 | |
| 377 | /* No 3G Measurement Parameters Description */ |
| 378 | bitvec_set_bit(&bv, 0); |
| 379 | /* No GPRS_3G_MEASUREMENT Parameters Descr. */ |
| 380 | bitvec_set_bit(&bv, 0); |
| 381 | |
Max | 845a3a4 | 2017-05-15 12:02:29 +0200 | [diff] [blame] | 382 | if (si2q_earfcn_count(&bts->si_common.si2quater_neigh_list)) { |
Max | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame] | 383 | append_earfcn(&bv, bts, SI2Q_MAX_LEN - bv.cur_bit); |
| 384 | |
| 385 | /* FIXME: remove following check once multiple SI2q are properly supported */ |
| 386 | if ((bts->e_offset != si2q_earfcn_count(&bts->si_common.si2quater_neigh_list)) || |
| 387 | si2q_earfcn_count(&bts->si_common.si2quater_neigh_list) > 5) |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 388 | return -ENOMEM; |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 389 | } else { |
| 390 | /* No Additions in Rel-5: */ |
| 391 | bitvec_set_bit(&bv, L); |
| 392 | } |
| 393 | |
| 394 | bitvec_spare_padding(&bv, (bv.data_len * 8) - 1); |
| 395 | return bv.data_len; |
| 396 | } |
| 397 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 398 | /* Append selection parameters to bitvec */ |
| 399 | static void append_selection_params(struct bitvec *bv, |
| 400 | const struct gsm48_si_selection_params *sp) |
| 401 | { |
| 402 | if (sp->present) { |
| 403 | bitvec_set_bit(bv, H); |
| 404 | bitvec_set_bit(bv, sp->cbq); |
| 405 | bitvec_set_uint(bv, sp->cell_resel_off, 6); |
| 406 | bitvec_set_uint(bv, sp->temp_offs, 3); |
| 407 | bitvec_set_uint(bv, sp->penalty_time, 5); |
| 408 | } else |
| 409 | bitvec_set_bit(bv, L); |
| 410 | } |
| 411 | |
| 412 | /* Append power offset to bitvec */ |
| 413 | static void append_power_offset(struct bitvec *bv, |
| 414 | const struct gsm48_si_power_offset *po) |
| 415 | { |
| 416 | if (po->present) { |
| 417 | bitvec_set_bit(bv, H); |
| 418 | bitvec_set_uint(bv, po->power_offset, 2); |
| 419 | } else |
| 420 | bitvec_set_bit(bv, L); |
| 421 | } |
| 422 | |
| 423 | /* Append GPRS indicator to bitvec */ |
| 424 | static void append_gprs_ind(struct bitvec *bv, |
| 425 | const struct gsm48_si3_gprs_ind *gi) |
| 426 | { |
| 427 | if (gi->present) { |
| 428 | bitvec_set_bit(bv, H); |
| 429 | bitvec_set_uint(bv, gi->ra_colour, 3); |
| 430 | /* 0 == SI13 in BCCH Norm, 1 == SI13 sent on BCCH Ext */ |
| 431 | bitvec_set_bit(bv, gi->si13_position); |
| 432 | } else |
| 433 | bitvec_set_bit(bv, L); |
| 434 | } |
| 435 | |
| 436 | |
| 437 | /* 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] | 438 | 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] | 439 | { |
| 440 | struct bitvec bv; |
| 441 | |
| 442 | memset(&bv, 0, sizeof(bv)); |
| 443 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 444 | bv.data_len = 4; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 445 | |
| 446 | /* Optional Selection Parameters */ |
| 447 | append_selection_params(&bv, &si3->selection_params); |
| 448 | |
| 449 | /* Optional Power Offset */ |
| 450 | append_power_offset(&bv, &si3->power_offset); |
| 451 | |
| 452 | /* Do we have a SI2ter on the BCCH? */ |
| 453 | if (si3->si2ter_indicator) |
| 454 | bitvec_set_bit(&bv, H); |
| 455 | else |
| 456 | bitvec_set_bit(&bv, L); |
| 457 | |
| 458 | /* Early Classmark Sending Control */ |
| 459 | if (si3->early_cm_ctrl) |
| 460 | bitvec_set_bit(&bv, H); |
| 461 | else |
| 462 | bitvec_set_bit(&bv, L); |
| 463 | |
| 464 | /* Do we have a SI Type 9 on the BCCH? */ |
| 465 | if (si3->scheduling.present) { |
| 466 | bitvec_set_bit(&bv, H); |
| 467 | bitvec_set_uint(&bv, si3->scheduling.where, 3); |
| 468 | } else |
| 469 | bitvec_set_bit(&bv, L); |
| 470 | |
| 471 | /* GPRS Indicator */ |
| 472 | append_gprs_ind(&bv, &si3->gprs_ind); |
| 473 | |
Max | f3f3505 | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 474 | /* 3G Early Classmark Sending Restriction controlled by |
| 475 | * early_cm_ctrl above */ |
| 476 | bitvec_set_bit(&bv, H); |
| 477 | |
| 478 | if (si3->si2quater_indicator) { |
| 479 | bitvec_set_bit(&bv, H); /* indicator struct present */ |
| 480 | bitvec_set_uint(&bv, 0, 1); /* message is sent on BCCH Norm */ |
| 481 | } |
| 482 | |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 483 | bitvec_spare_padding(&bv, (bv.data_len*8)-1); |
| 484 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static int append_lsa_params(struct bitvec *bv, |
| 488 | const struct gsm48_lsa_params *lsa_params) |
| 489 | { |
| 490 | /* FIXME */ |
Holger Hans Peter Freyther | ae80f92 | 2010-04-10 00:05:16 +0200 | [diff] [blame] | 491 | return -1; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* Generate SI4 Rest Octets (Chapter 10.5.2.35) */ |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 495 | 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] | 496 | { |
| 497 | struct bitvec bv; |
| 498 | |
| 499 | memset(&bv, 0, sizeof(bv)); |
| 500 | bv.data = data; |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 501 | bv.data_len = len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 502 | |
| 503 | /* SI4 Rest Octets O */ |
| 504 | append_selection_params(&bv, &si4->selection_params); |
| 505 | append_power_offset(&bv, &si4->power_offset); |
| 506 | append_gprs_ind(&bv, &si4->gprs_ind); |
| 507 | |
| 508 | if (0 /* FIXME */) { |
| 509 | /* H and SI4 Rest Octets S */ |
| 510 | bitvec_set_bit(&bv, H); |
| 511 | |
| 512 | /* LSA Parameters */ |
| 513 | if (si4->lsa_params.present) { |
| 514 | bitvec_set_bit(&bv, H); |
| 515 | append_lsa_params(&bv, &si4->lsa_params); |
| 516 | } else |
| 517 | bitvec_set_bit(&bv, L); |
| 518 | |
| 519 | /* Cell Identity */ |
| 520 | if (1) { |
| 521 | bitvec_set_bit(&bv, H); |
| 522 | bitvec_set_uint(&bv, si4->cell_id, 16); |
| 523 | } else |
| 524 | bitvec_set_bit(&bv, L); |
| 525 | |
| 526 | /* LSA ID Information */ |
| 527 | if (0) { |
| 528 | bitvec_set_bit(&bv, H); |
| 529 | /* FIXME */ |
| 530 | } else |
| 531 | bitvec_set_bit(&bv, L); |
| 532 | } else { |
| 533 | /* L and break indicator */ |
| 534 | bitvec_set_bit(&bv, L); |
| 535 | bitvec_set_bit(&bv, si4->break_ind ? H : L); |
| 536 | } |
| 537 | |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 538 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 539 | } |
| 540 | |
Holger Hans Peter Freyther | 82dd983 | 2016-05-17 23:20:03 +0200 | [diff] [blame] | 541 | |
| 542 | /* GSM 04.18 ETSI TS 101 503 V8.27.0 (2006-05) |
| 543 | |
| 544 | <SI6 rest octets> ::= |
| 545 | {L | H <PCH and NCH info>} |
| 546 | {L | H <VBS/VGCS options : bit(2)>} |
| 547 | { < DTM_support : bit == L > I < DTM_support : bit == H > |
| 548 | < RAC : bit (8) > |
| 549 | < MAX_LAPDm : bit (3) > } |
| 550 | < Band indicator > |
| 551 | { L | H < GPRS_MS_TXPWR_MAX_CCH : bit (5) > } |
| 552 | <implicit spare >; |
| 553 | */ |
| 554 | int rest_octets_si6(uint8_t *data, bool is1800_net) |
| 555 | { |
| 556 | struct bitvec bv; |
| 557 | |
| 558 | memset(&bv, 0, sizeof(bv)); |
| 559 | bv.data = data; |
| 560 | bv.data_len = 1; |
| 561 | |
| 562 | /* no PCH/NCH info */ |
| 563 | bitvec_set_bit(&bv, L); |
| 564 | /* no VBS/VGCS options */ |
| 565 | bitvec_set_bit(&bv, L); |
| 566 | /* no DTM_support */ |
| 567 | bitvec_set_bit(&bv, L); |
| 568 | /* band indicator */ |
| 569 | if (is1800_net) |
| 570 | bitvec_set_bit(&bv, L); |
| 571 | else |
| 572 | bitvec_set_bit(&bv, H); |
| 573 | /* no GPRS_MS_TXPWR_MAX_CCH */ |
| 574 | bitvec_set_bit(&bv, L); |
| 575 | |
| 576 | bitvec_spare_padding(&bv, (bv.data_len * 8) - 1); |
| 577 | return bv.data_len; |
| 578 | } |
| 579 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 580 | /* GPRS Mobile Allocation as per TS 04.60 Chapter 12.10a: |
| 581 | < GPRS Mobile Allocation IE > ::= |
| 582 | < HSN : bit (6) > |
| 583 | { 0 | 1 < RFL number list : < RFL number list struct > > } |
| 584 | { 0 < MA_LENGTH : bit (6) > |
| 585 | < MA_BITMAP: bit (val(MA_LENGTH) + 1) > |
| 586 | | 1 { 0 | 1 <ARFCN index list : < ARFCN index list struct > > } } ; |
| 587 | |
| 588 | < RFL number list struct > :: = |
| 589 | < RFL_NUMBER : bit (4) > |
| 590 | { 0 | 1 < RFL number list struct > } ; |
| 591 | < ARFCN index list struct > ::= |
| 592 | < ARFCN_INDEX : bit(6) > |
| 593 | { 0 | 1 < ARFCN index list struct > } ; |
| 594 | */ |
| 595 | static int append_gprs_mobile_alloc(struct bitvec *bv) |
| 596 | { |
| 597 | /* Hopping Sequence Number */ |
| 598 | bitvec_set_uint(bv, 0, 6); |
| 599 | |
| 600 | if (0) { |
| 601 | /* We want to use a RFL number list */ |
| 602 | bitvec_set_bit(bv, 1); |
| 603 | /* FIXME: RFL number list */ |
| 604 | } else |
| 605 | bitvec_set_bit(bv, 0); |
| 606 | |
| 607 | if (0) { |
| 608 | /* We want to use a MA_BITMAP */ |
| 609 | bitvec_set_bit(bv, 0); |
| 610 | /* FIXME: MA_LENGTH, MA_BITMAP, ... */ |
| 611 | } else { |
| 612 | bitvec_set_bit(bv, 1); |
| 613 | if (0) { |
| 614 | /* We want to provide an ARFCN index list */ |
| 615 | bitvec_set_bit(bv, 1); |
| 616 | /* FIXME */ |
| 617 | } else |
| 618 | bitvec_set_bit(bv, 0); |
| 619 | } |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int encode_t3192(unsigned int t3192) |
| 624 | { |
Philipp Maier | 3d6cb33 | 2016-12-20 14:23:45 +0100 | [diff] [blame] | 625 | /* See also 3GPP TS 44.060 |
| 626 | Table 12.24.2: GPRS Cell Options information element details */ |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 627 | if (t3192 == 0) |
| 628 | return 3; |
| 629 | else if (t3192 <= 80) |
| 630 | return 4; |
| 631 | else if (t3192 <= 120) |
| 632 | return 5; |
| 633 | else if (t3192 <= 160) |
| 634 | return 6; |
| 635 | else if (t3192 <= 200) |
| 636 | return 7; |
| 637 | else if (t3192 <= 500) |
| 638 | return 0; |
| 639 | else if (t3192 <= 1000) |
| 640 | return 1; |
| 641 | else if (t3192 <= 1500) |
| 642 | return 2; |
| 643 | else |
| 644 | return -EINVAL; |
| 645 | } |
| 646 | |
| 647 | static int encode_drx_timer(unsigned int drx) |
| 648 | { |
| 649 | if (drx == 0) |
| 650 | return 0; |
| 651 | else if (drx == 1) |
| 652 | return 1; |
| 653 | else if (drx == 2) |
| 654 | return 2; |
| 655 | else if (drx <= 4) |
| 656 | return 3; |
| 657 | else if (drx <= 8) |
| 658 | return 4; |
| 659 | else if (drx <= 16) |
| 660 | return 5; |
| 661 | else if (drx <= 32) |
| 662 | return 6; |
| 663 | else if (drx <= 64) |
| 664 | return 7; |
| 665 | else |
| 666 | return -EINVAL; |
| 667 | } |
| 668 | |
| 669 | /* GPRS Cell Options as per TS 04.60 Chapter 12.24 |
| 670 | < GPRS Cell Options IE > ::= |
| 671 | < NMO : bit(2) > |
| 672 | < T3168 : bit(3) > |
| 673 | < T3192 : bit(3) > |
| 674 | < DRX_TIMER_MAX: bit(3) > |
| 675 | < ACCESS_BURST_TYPE: bit > |
| 676 | < CONTROL_ACK_TYPE : bit > |
| 677 | < BS_CV_MAX: bit(4) > |
| 678 | { 0 | 1 < PAN_DEC : bit(3) > |
| 679 | < PAN_INC : bit(3) > |
| 680 | < PAN_MAX : bit(3) > |
| 681 | { 0 | 1 < Extension Length : bit(6) > |
| 682 | < bit (val(Extension Length) + 1 |
| 683 | & { < Extension Information > ! { bit ** = <no string> } } ; |
| 684 | < Extension Information > ::= |
| 685 | { 0 | 1 < EGPRS_PACKET_CHANNEL_REQUEST : bit > |
| 686 | < BEP_PERIOD : bit(4) > } |
| 687 | < PFC_FEATURE_MODE : bit > |
| 688 | < DTM_SUPPORT : bit > |
| 689 | <BSS_PAGING_COORDINATION: bit > |
| 690 | <spare bit > ** ; |
| 691 | */ |
Harald Welte | a4e2d04 | 2009-12-20 17:08:22 +0100 | [diff] [blame] | 692 | static int append_gprs_cell_opt(struct bitvec *bv, |
| 693 | const struct gprs_cell_options *gco) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 694 | { |
| 695 | int t3192, drx_timer_max; |
| 696 | |
| 697 | t3192 = encode_t3192(gco->t3192); |
| 698 | if (t3192 < 0) |
| 699 | return t3192; |
| 700 | |
| 701 | drx_timer_max = encode_drx_timer(gco->drx_timer_max); |
| 702 | if (drx_timer_max < 0) |
| 703 | return drx_timer_max; |
| 704 | |
| 705 | bitvec_set_uint(bv, gco->nmo, 2); |
Philipp Maier | 3d6cb33 | 2016-12-20 14:23:45 +0100 | [diff] [blame] | 706 | |
| 707 | /* See also 3GPP TS 44.060 |
| 708 | Table 12.24.2: GPRS Cell Options information element details */ |
| 709 | bitvec_set_uint(bv, gco->t3168 / 500 - 1, 3); |
| 710 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 711 | bitvec_set_uint(bv, t3192, 3); |
| 712 | bitvec_set_uint(bv, drx_timer_max, 3); |
| 713 | /* ACCESS_BURST_TYPE: Hard-code 8bit */ |
| 714 | bitvec_set_bit(bv, 0); |
Max | 292ec58 | 2016-07-28 11:55:37 +0200 | [diff] [blame] | 715 | /* CONTROL_ACK_TYPE: */ |
| 716 | bitvec_set_bit(bv, gco->ctrl_ack_type_use_block); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 717 | bitvec_set_uint(bv, gco->bs_cv_max, 4); |
| 718 | |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 719 | if (0) { |
| 720 | /* hard-code no PAN_{DEC,INC,MAX} */ |
| 721 | bitvec_set_bit(bv, 0); |
| 722 | } else { |
| 723 | /* copied from ip.access BSC protocol trace */ |
| 724 | bitvec_set_bit(bv, 1); |
| 725 | bitvec_set_uint(bv, 1, 3); /* DEC */ |
| 726 | bitvec_set_uint(bv, 1, 3); /* INC */ |
| 727 | bitvec_set_uint(bv, 15, 3); /* MAX */ |
| 728 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 729 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 730 | if (!gco->ext_info_present) { |
| 731 | /* no extension information */ |
| 732 | bitvec_set_bit(bv, 0); |
| 733 | } else { |
| 734 | /* extension information */ |
| 735 | bitvec_set_bit(bv, 1); |
| 736 | if (!gco->ext_info.egprs_supported) { |
| 737 | /* 6bit length of extension */ |
Harald Welte | 39608dc | 2010-04-18 22:47:22 +0200 | [diff] [blame] | 738 | bitvec_set_uint(bv, (1 + 3)-1, 6); |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 739 | /* EGPRS supported in the cell */ |
| 740 | bitvec_set_bit(bv, 0); |
| 741 | } else { |
| 742 | /* 6bit length of extension */ |
Harald Welte | 39608dc | 2010-04-18 22:47:22 +0200 | [diff] [blame] | 743 | bitvec_set_uint(bv, (1 + 5 + 3)-1, 6); |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 744 | /* EGPRS supported in the cell */ |
| 745 | bitvec_set_bit(bv, 1); |
bhargava | 350533c | 2016-07-21 11:14:34 +0530 | [diff] [blame] | 746 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 747 | /* 1bit EGPRS PACKET CHANNEL REQUEST */ |
bhargava | 350533c | 2016-07-21 11:14:34 +0530 | [diff] [blame] | 748 | if (gco->supports_egprs_11bit_rach == 0) { |
| 749 | bitvec_set_bit(bv, |
| 750 | gco->ext_info.use_egprs_p_ch_req); |
| 751 | } else { |
| 752 | bitvec_set_bit(bv, 0); |
| 753 | } |
| 754 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 755 | /* 4bit BEP PERIOD */ |
| 756 | bitvec_set_uint(bv, gco->ext_info.bep_period, 4); |
| 757 | } |
| 758 | bitvec_set_bit(bv, gco->ext_info.pfc_supported); |
| 759 | bitvec_set_bit(bv, gco->ext_info.dtm_supported); |
| 760 | bitvec_set_bit(bv, gco->ext_info.bss_paging_coordination); |
| 761 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static void append_gprs_pwr_ctrl_pars(struct bitvec *bv, |
Harald Welte | a4e2d04 | 2009-12-20 17:08:22 +0100 | [diff] [blame] | 767 | const struct gprs_power_ctrl_pars *pcp) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 768 | { |
| 769 | bitvec_set_uint(bv, pcp->alpha, 4); |
| 770 | bitvec_set_uint(bv, pcp->t_avg_w, 5); |
| 771 | bitvec_set_uint(bv, pcp->t_avg_t, 5); |
| 772 | bitvec_set_uint(bv, pcp->pc_meas_chan, 1); |
| 773 | bitvec_set_uint(bv, pcp->n_avg_i, 4); |
| 774 | } |
| 775 | |
Harald Welte | 5fda908 | 2010-04-18 22:41:01 +0200 | [diff] [blame] | 776 | /* 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] | 777 | 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] | 778 | { |
| 779 | struct bitvec bv; |
| 780 | |
| 781 | memset(&bv, 0, sizeof(bv)); |
| 782 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 783 | bv.data_len = 20; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 784 | |
| 785 | if (0) { |
| 786 | /* No rest octets */ |
| 787 | bitvec_set_bit(&bv, L); |
| 788 | } else { |
| 789 | bitvec_set_bit(&bv, H); |
| 790 | bitvec_set_uint(&bv, si13->bcch_change_mark, 3); |
| 791 | bitvec_set_uint(&bv, si13->si_change_field, 4); |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 792 | if (1) { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 793 | bitvec_set_bit(&bv, 0); |
| 794 | } else { |
| 795 | bitvec_set_bit(&bv, 1); |
| 796 | bitvec_set_uint(&bv, si13->bcch_change_mark, 2); |
| 797 | append_gprs_mobile_alloc(&bv); |
| 798 | } |
| 799 | if (!si13->pbcch_present) { |
| 800 | /* PBCCH not present in cell */ |
| 801 | bitvec_set_bit(&bv, 0); |
| 802 | bitvec_set_uint(&bv, si13->no_pbcch.rac, 8); |
| 803 | bitvec_set_bit(&bv, si13->no_pbcch.spgc_ccch_sup); |
| 804 | bitvec_set_uint(&bv, si13->no_pbcch.prio_acc_thr, 3); |
| 805 | bitvec_set_uint(&bv, si13->no_pbcch.net_ctrl_ord, 2); |
| 806 | append_gprs_cell_opt(&bv, &si13->cell_opts); |
| 807 | append_gprs_pwr_ctrl_pars(&bv, &si13->pwr_ctrl_pars); |
| 808 | } else { |
| 809 | /* PBCCH present in cell */ |
| 810 | bitvec_set_bit(&bv, 1); |
| 811 | bitvec_set_uint(&bv, si13->pbcch.psi1_rep_per, 4); |
| 812 | /* PBCCH Descripiton */ |
| 813 | bitvec_set_uint(&bv, si13->pbcch.pb, 4); |
| 814 | bitvec_set_uint(&bv, si13->pbcch.tsc, 3); |
| 815 | bitvec_set_uint(&bv, si13->pbcch.tn, 3); |
| 816 | switch (si13->pbcch.carrier_type) { |
| 817 | case PBCCH_BCCH: |
| 818 | bitvec_set_bit(&bv, 0); |
| 819 | bitvec_set_bit(&bv, 0); |
| 820 | break; |
| 821 | case PBCCH_ARFCN: |
| 822 | bitvec_set_bit(&bv, 0); |
| 823 | bitvec_set_bit(&bv, 1); |
| 824 | bitvec_set_uint(&bv, si13->pbcch.arfcn, 10); |
| 825 | break; |
| 826 | case PBCCH_MAIO: |
| 827 | bitvec_set_bit(&bv, 1); |
| 828 | bitvec_set_uint(&bv, si13->pbcch.maio, 6); |
| 829 | break; |
| 830 | } |
| 831 | } |
Harald Welte | 5fda908 | 2010-04-18 22:41:01 +0200 | [diff] [blame] | 832 | /* 3GPP TS 44.018 Release 6 / 10.5.2.37b */ |
| 833 | bitvec_set_bit(&bv, H); /* added Release 99 */ |
| 834 | /* claim our SGSN is compatible with Release 99, as EDGE and EGPRS |
| 835 | * was only added in this Release */ |
| 836 | bitvec_set_bit(&bv, 1); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 837 | } |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 838 | bitvec_spare_padding(&bv, (bv.data_len*8)-1); |
| 839 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 840 | } |