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 | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame^] | 382 | if (&bts->si_common.si2quater_neigh_list) { /* FIXME: use si2q_earfcn_count() in if */ |
| 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 | f39d03a | 2017-05-12 17:00:30 +0200 | [diff] [blame^] | 389 | |
Max | 59a1bf3 | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 390 | } else { |
| 391 | /* No Additions in Rel-5: */ |
| 392 | bitvec_set_bit(&bv, L); |
| 393 | } |
| 394 | |
| 395 | bitvec_spare_padding(&bv, (bv.data_len * 8) - 1); |
| 396 | return bv.data_len; |
| 397 | } |
| 398 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 399 | /* Append selection parameters to bitvec */ |
| 400 | static void append_selection_params(struct bitvec *bv, |
| 401 | const struct gsm48_si_selection_params *sp) |
| 402 | { |
| 403 | if (sp->present) { |
| 404 | bitvec_set_bit(bv, H); |
| 405 | bitvec_set_bit(bv, sp->cbq); |
| 406 | bitvec_set_uint(bv, sp->cell_resel_off, 6); |
| 407 | bitvec_set_uint(bv, sp->temp_offs, 3); |
| 408 | bitvec_set_uint(bv, sp->penalty_time, 5); |
| 409 | } else |
| 410 | bitvec_set_bit(bv, L); |
| 411 | } |
| 412 | |
| 413 | /* Append power offset to bitvec */ |
| 414 | static void append_power_offset(struct bitvec *bv, |
| 415 | const struct gsm48_si_power_offset *po) |
| 416 | { |
| 417 | if (po->present) { |
| 418 | bitvec_set_bit(bv, H); |
| 419 | bitvec_set_uint(bv, po->power_offset, 2); |
| 420 | } else |
| 421 | bitvec_set_bit(bv, L); |
| 422 | } |
| 423 | |
| 424 | /* Append GPRS indicator to bitvec */ |
| 425 | static void append_gprs_ind(struct bitvec *bv, |
| 426 | const struct gsm48_si3_gprs_ind *gi) |
| 427 | { |
| 428 | if (gi->present) { |
| 429 | bitvec_set_bit(bv, H); |
| 430 | bitvec_set_uint(bv, gi->ra_colour, 3); |
| 431 | /* 0 == SI13 in BCCH Norm, 1 == SI13 sent on BCCH Ext */ |
| 432 | bitvec_set_bit(bv, gi->si13_position); |
| 433 | } else |
| 434 | bitvec_set_bit(bv, L); |
| 435 | } |
| 436 | |
| 437 | |
| 438 | /* 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] | 439 | 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] | 440 | { |
| 441 | struct bitvec bv; |
| 442 | |
| 443 | memset(&bv, 0, sizeof(bv)); |
| 444 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 445 | bv.data_len = 4; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 446 | |
| 447 | /* Optional Selection Parameters */ |
| 448 | append_selection_params(&bv, &si3->selection_params); |
| 449 | |
| 450 | /* Optional Power Offset */ |
| 451 | append_power_offset(&bv, &si3->power_offset); |
| 452 | |
| 453 | /* Do we have a SI2ter on the BCCH? */ |
| 454 | if (si3->si2ter_indicator) |
| 455 | bitvec_set_bit(&bv, H); |
| 456 | else |
| 457 | bitvec_set_bit(&bv, L); |
| 458 | |
| 459 | /* Early Classmark Sending Control */ |
| 460 | if (si3->early_cm_ctrl) |
| 461 | bitvec_set_bit(&bv, H); |
| 462 | else |
| 463 | bitvec_set_bit(&bv, L); |
| 464 | |
| 465 | /* Do we have a SI Type 9 on the BCCH? */ |
| 466 | if (si3->scheduling.present) { |
| 467 | bitvec_set_bit(&bv, H); |
| 468 | bitvec_set_uint(&bv, si3->scheduling.where, 3); |
| 469 | } else |
| 470 | bitvec_set_bit(&bv, L); |
| 471 | |
| 472 | /* GPRS Indicator */ |
| 473 | append_gprs_ind(&bv, &si3->gprs_ind); |
| 474 | |
Max | f3f3505 | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 475 | /* 3G Early Classmark Sending Restriction controlled by |
| 476 | * early_cm_ctrl above */ |
| 477 | bitvec_set_bit(&bv, H); |
| 478 | |
| 479 | if (si3->si2quater_indicator) { |
| 480 | bitvec_set_bit(&bv, H); /* indicator struct present */ |
| 481 | bitvec_set_uint(&bv, 0, 1); /* message is sent on BCCH Norm */ |
| 482 | } |
| 483 | |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 484 | bitvec_spare_padding(&bv, (bv.data_len*8)-1); |
| 485 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static int append_lsa_params(struct bitvec *bv, |
| 489 | const struct gsm48_lsa_params *lsa_params) |
| 490 | { |
| 491 | /* FIXME */ |
Holger Hans Peter Freyther | ae80f92 | 2010-04-10 00:05:16 +0200 | [diff] [blame] | 492 | return -1; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* Generate SI4 Rest Octets (Chapter 10.5.2.35) */ |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 496 | 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] | 497 | { |
| 498 | struct bitvec bv; |
| 499 | |
| 500 | memset(&bv, 0, sizeof(bv)); |
| 501 | bv.data = data; |
Holger Hans Peter Freyther | 7ff77ec | 2010-12-29 23:06:22 +0100 | [diff] [blame] | 502 | bv.data_len = len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 503 | |
| 504 | /* SI4 Rest Octets O */ |
| 505 | append_selection_params(&bv, &si4->selection_params); |
| 506 | append_power_offset(&bv, &si4->power_offset); |
| 507 | append_gprs_ind(&bv, &si4->gprs_ind); |
| 508 | |
| 509 | if (0 /* FIXME */) { |
| 510 | /* H and SI4 Rest Octets S */ |
| 511 | bitvec_set_bit(&bv, H); |
| 512 | |
| 513 | /* LSA Parameters */ |
| 514 | if (si4->lsa_params.present) { |
| 515 | bitvec_set_bit(&bv, H); |
| 516 | append_lsa_params(&bv, &si4->lsa_params); |
| 517 | } else |
| 518 | bitvec_set_bit(&bv, L); |
| 519 | |
| 520 | /* Cell Identity */ |
| 521 | if (1) { |
| 522 | bitvec_set_bit(&bv, H); |
| 523 | bitvec_set_uint(&bv, si4->cell_id, 16); |
| 524 | } else |
| 525 | bitvec_set_bit(&bv, L); |
| 526 | |
| 527 | /* LSA ID Information */ |
| 528 | if (0) { |
| 529 | bitvec_set_bit(&bv, H); |
| 530 | /* FIXME */ |
| 531 | } else |
| 532 | bitvec_set_bit(&bv, L); |
| 533 | } else { |
| 534 | /* L and break indicator */ |
| 535 | bitvec_set_bit(&bv, L); |
| 536 | bitvec_set_bit(&bv, si4->break_ind ? H : L); |
| 537 | } |
| 538 | |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 539 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 540 | } |
| 541 | |
Holger Hans Peter Freyther | 82dd983 | 2016-05-17 23:20:03 +0200 | [diff] [blame] | 542 | |
| 543 | /* GSM 04.18 ETSI TS 101 503 V8.27.0 (2006-05) |
| 544 | |
| 545 | <SI6 rest octets> ::= |
| 546 | {L | H <PCH and NCH info>} |
| 547 | {L | H <VBS/VGCS options : bit(2)>} |
| 548 | { < DTM_support : bit == L > I < DTM_support : bit == H > |
| 549 | < RAC : bit (8) > |
| 550 | < MAX_LAPDm : bit (3) > } |
| 551 | < Band indicator > |
| 552 | { L | H < GPRS_MS_TXPWR_MAX_CCH : bit (5) > } |
| 553 | <implicit spare >; |
| 554 | */ |
| 555 | int rest_octets_si6(uint8_t *data, bool is1800_net) |
| 556 | { |
| 557 | struct bitvec bv; |
| 558 | |
| 559 | memset(&bv, 0, sizeof(bv)); |
| 560 | bv.data = data; |
| 561 | bv.data_len = 1; |
| 562 | |
| 563 | /* no PCH/NCH info */ |
| 564 | bitvec_set_bit(&bv, L); |
| 565 | /* no VBS/VGCS options */ |
| 566 | bitvec_set_bit(&bv, L); |
| 567 | /* no DTM_support */ |
| 568 | bitvec_set_bit(&bv, L); |
| 569 | /* band indicator */ |
| 570 | if (is1800_net) |
| 571 | bitvec_set_bit(&bv, L); |
| 572 | else |
| 573 | bitvec_set_bit(&bv, H); |
| 574 | /* no GPRS_MS_TXPWR_MAX_CCH */ |
| 575 | bitvec_set_bit(&bv, L); |
| 576 | |
| 577 | bitvec_spare_padding(&bv, (bv.data_len * 8) - 1); |
| 578 | return bv.data_len; |
| 579 | } |
| 580 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 581 | /* GPRS Mobile Allocation as per TS 04.60 Chapter 12.10a: |
| 582 | < GPRS Mobile Allocation IE > ::= |
| 583 | < HSN : bit (6) > |
| 584 | { 0 | 1 < RFL number list : < RFL number list struct > > } |
| 585 | { 0 < MA_LENGTH : bit (6) > |
| 586 | < MA_BITMAP: bit (val(MA_LENGTH) + 1) > |
| 587 | | 1 { 0 | 1 <ARFCN index list : < ARFCN index list struct > > } } ; |
| 588 | |
| 589 | < RFL number list struct > :: = |
| 590 | < RFL_NUMBER : bit (4) > |
| 591 | { 0 | 1 < RFL number list struct > } ; |
| 592 | < ARFCN index list struct > ::= |
| 593 | < ARFCN_INDEX : bit(6) > |
| 594 | { 0 | 1 < ARFCN index list struct > } ; |
| 595 | */ |
| 596 | static int append_gprs_mobile_alloc(struct bitvec *bv) |
| 597 | { |
| 598 | /* Hopping Sequence Number */ |
| 599 | bitvec_set_uint(bv, 0, 6); |
| 600 | |
| 601 | if (0) { |
| 602 | /* We want to use a RFL number list */ |
| 603 | bitvec_set_bit(bv, 1); |
| 604 | /* FIXME: RFL number list */ |
| 605 | } else |
| 606 | bitvec_set_bit(bv, 0); |
| 607 | |
| 608 | if (0) { |
| 609 | /* We want to use a MA_BITMAP */ |
| 610 | bitvec_set_bit(bv, 0); |
| 611 | /* FIXME: MA_LENGTH, MA_BITMAP, ... */ |
| 612 | } else { |
| 613 | bitvec_set_bit(bv, 1); |
| 614 | if (0) { |
| 615 | /* We want to provide an ARFCN index list */ |
| 616 | bitvec_set_bit(bv, 1); |
| 617 | /* FIXME */ |
| 618 | } else |
| 619 | bitvec_set_bit(bv, 0); |
| 620 | } |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | static int encode_t3192(unsigned int t3192) |
| 625 | { |
Philipp Maier | 3d6cb33 | 2016-12-20 14:23:45 +0100 | [diff] [blame] | 626 | /* See also 3GPP TS 44.060 |
| 627 | Table 12.24.2: GPRS Cell Options information element details */ |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 628 | if (t3192 == 0) |
| 629 | return 3; |
| 630 | else if (t3192 <= 80) |
| 631 | return 4; |
| 632 | else if (t3192 <= 120) |
| 633 | return 5; |
| 634 | else if (t3192 <= 160) |
| 635 | return 6; |
| 636 | else if (t3192 <= 200) |
| 637 | return 7; |
| 638 | else if (t3192 <= 500) |
| 639 | return 0; |
| 640 | else if (t3192 <= 1000) |
| 641 | return 1; |
| 642 | else if (t3192 <= 1500) |
| 643 | return 2; |
| 644 | else |
| 645 | return -EINVAL; |
| 646 | } |
| 647 | |
| 648 | static int encode_drx_timer(unsigned int drx) |
| 649 | { |
| 650 | if (drx == 0) |
| 651 | return 0; |
| 652 | else if (drx == 1) |
| 653 | return 1; |
| 654 | else if (drx == 2) |
| 655 | return 2; |
| 656 | else if (drx <= 4) |
| 657 | return 3; |
| 658 | else if (drx <= 8) |
| 659 | return 4; |
| 660 | else if (drx <= 16) |
| 661 | return 5; |
| 662 | else if (drx <= 32) |
| 663 | return 6; |
| 664 | else if (drx <= 64) |
| 665 | return 7; |
| 666 | else |
| 667 | return -EINVAL; |
| 668 | } |
| 669 | |
| 670 | /* GPRS Cell Options as per TS 04.60 Chapter 12.24 |
| 671 | < GPRS Cell Options IE > ::= |
| 672 | < NMO : bit(2) > |
| 673 | < T3168 : bit(3) > |
| 674 | < T3192 : bit(3) > |
| 675 | < DRX_TIMER_MAX: bit(3) > |
| 676 | < ACCESS_BURST_TYPE: bit > |
| 677 | < CONTROL_ACK_TYPE : bit > |
| 678 | < BS_CV_MAX: bit(4) > |
| 679 | { 0 | 1 < PAN_DEC : bit(3) > |
| 680 | < PAN_INC : bit(3) > |
| 681 | < PAN_MAX : bit(3) > |
| 682 | { 0 | 1 < Extension Length : bit(6) > |
| 683 | < bit (val(Extension Length) + 1 |
| 684 | & { < Extension Information > ! { bit ** = <no string> } } ; |
| 685 | < Extension Information > ::= |
| 686 | { 0 | 1 < EGPRS_PACKET_CHANNEL_REQUEST : bit > |
| 687 | < BEP_PERIOD : bit(4) > } |
| 688 | < PFC_FEATURE_MODE : bit > |
| 689 | < DTM_SUPPORT : bit > |
| 690 | <BSS_PAGING_COORDINATION: bit > |
| 691 | <spare bit > ** ; |
| 692 | */ |
Harald Welte | a4e2d04 | 2009-12-20 17:08:22 +0100 | [diff] [blame] | 693 | static int append_gprs_cell_opt(struct bitvec *bv, |
| 694 | const struct gprs_cell_options *gco) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 695 | { |
| 696 | int t3192, drx_timer_max; |
| 697 | |
| 698 | t3192 = encode_t3192(gco->t3192); |
| 699 | if (t3192 < 0) |
| 700 | return t3192; |
| 701 | |
| 702 | drx_timer_max = encode_drx_timer(gco->drx_timer_max); |
| 703 | if (drx_timer_max < 0) |
| 704 | return drx_timer_max; |
| 705 | |
| 706 | bitvec_set_uint(bv, gco->nmo, 2); |
Philipp Maier | 3d6cb33 | 2016-12-20 14:23:45 +0100 | [diff] [blame] | 707 | |
| 708 | /* See also 3GPP TS 44.060 |
| 709 | Table 12.24.2: GPRS Cell Options information element details */ |
| 710 | bitvec_set_uint(bv, gco->t3168 / 500 - 1, 3); |
| 711 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 712 | bitvec_set_uint(bv, t3192, 3); |
| 713 | bitvec_set_uint(bv, drx_timer_max, 3); |
| 714 | /* ACCESS_BURST_TYPE: Hard-code 8bit */ |
| 715 | bitvec_set_bit(bv, 0); |
Max | 292ec58 | 2016-07-28 11:55:37 +0200 | [diff] [blame] | 716 | /* CONTROL_ACK_TYPE: */ |
| 717 | bitvec_set_bit(bv, gco->ctrl_ack_type_use_block); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 718 | bitvec_set_uint(bv, gco->bs_cv_max, 4); |
| 719 | |
Harald Welte | a4b1665 | 2010-05-31 12:54:23 +0200 | [diff] [blame] | 720 | if (0) { |
| 721 | /* hard-code no PAN_{DEC,INC,MAX} */ |
| 722 | bitvec_set_bit(bv, 0); |
| 723 | } else { |
| 724 | /* copied from ip.access BSC protocol trace */ |
| 725 | bitvec_set_bit(bv, 1); |
| 726 | bitvec_set_uint(bv, 1, 3); /* DEC */ |
| 727 | bitvec_set_uint(bv, 1, 3); /* INC */ |
| 728 | bitvec_set_uint(bv, 15, 3); /* MAX */ |
| 729 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 730 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 731 | if (!gco->ext_info_present) { |
| 732 | /* no extension information */ |
| 733 | bitvec_set_bit(bv, 0); |
| 734 | } else { |
| 735 | /* extension information */ |
| 736 | bitvec_set_bit(bv, 1); |
| 737 | if (!gco->ext_info.egprs_supported) { |
| 738 | /* 6bit length of extension */ |
Harald Welte | 39608dc | 2010-04-18 22:47:22 +0200 | [diff] [blame] | 739 | bitvec_set_uint(bv, (1 + 3)-1, 6); |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 740 | /* EGPRS supported in the cell */ |
| 741 | bitvec_set_bit(bv, 0); |
| 742 | } else { |
| 743 | /* 6bit length of extension */ |
Harald Welte | 39608dc | 2010-04-18 22:47:22 +0200 | [diff] [blame] | 744 | bitvec_set_uint(bv, (1 + 5 + 3)-1, 6); |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 745 | /* EGPRS supported in the cell */ |
| 746 | bitvec_set_bit(bv, 1); |
bhargava | 350533c | 2016-07-21 11:14:34 +0530 | [diff] [blame] | 747 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 748 | /* 1bit EGPRS PACKET CHANNEL REQUEST */ |
bhargava | 350533c | 2016-07-21 11:14:34 +0530 | [diff] [blame] | 749 | if (gco->supports_egprs_11bit_rach == 0) { |
| 750 | bitvec_set_bit(bv, |
| 751 | gco->ext_info.use_egprs_p_ch_req); |
| 752 | } else { |
| 753 | bitvec_set_bit(bv, 0); |
| 754 | } |
| 755 | |
Harald Welte | da0586a | 2010-04-18 14:49:05 +0200 | [diff] [blame] | 756 | /* 4bit BEP PERIOD */ |
| 757 | bitvec_set_uint(bv, gco->ext_info.bep_period, 4); |
| 758 | } |
| 759 | bitvec_set_bit(bv, gco->ext_info.pfc_supported); |
| 760 | bitvec_set_bit(bv, gco->ext_info.dtm_supported); |
| 761 | bitvec_set_bit(bv, gco->ext_info.bss_paging_coordination); |
| 762 | } |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | static void append_gprs_pwr_ctrl_pars(struct bitvec *bv, |
Harald Welte | a4e2d04 | 2009-12-20 17:08:22 +0100 | [diff] [blame] | 768 | const struct gprs_power_ctrl_pars *pcp) |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 769 | { |
| 770 | bitvec_set_uint(bv, pcp->alpha, 4); |
| 771 | bitvec_set_uint(bv, pcp->t_avg_w, 5); |
| 772 | bitvec_set_uint(bv, pcp->t_avg_t, 5); |
| 773 | bitvec_set_uint(bv, pcp->pc_meas_chan, 1); |
| 774 | bitvec_set_uint(bv, pcp->n_avg_i, 4); |
| 775 | } |
| 776 | |
Harald Welte | 5fda908 | 2010-04-18 22:41:01 +0200 | [diff] [blame] | 777 | /* 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] | 778 | 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] | 779 | { |
| 780 | struct bitvec bv; |
| 781 | |
| 782 | memset(&bv, 0, sizeof(bv)); |
| 783 | bv.data = data; |
Holger Hans Peter Freyther | 4cffc45 | 2010-01-06 06:44:37 +0100 | [diff] [blame] | 784 | bv.data_len = 20; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 785 | |
| 786 | if (0) { |
| 787 | /* No rest octets */ |
| 788 | bitvec_set_bit(&bv, L); |
| 789 | } else { |
| 790 | bitvec_set_bit(&bv, H); |
| 791 | bitvec_set_uint(&bv, si13->bcch_change_mark, 3); |
| 792 | bitvec_set_uint(&bv, si13->si_change_field, 4); |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 793 | if (1) { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 794 | bitvec_set_bit(&bv, 0); |
| 795 | } else { |
| 796 | bitvec_set_bit(&bv, 1); |
| 797 | bitvec_set_uint(&bv, si13->bcch_change_mark, 2); |
| 798 | append_gprs_mobile_alloc(&bv); |
| 799 | } |
| 800 | if (!si13->pbcch_present) { |
| 801 | /* PBCCH not present in cell */ |
| 802 | bitvec_set_bit(&bv, 0); |
| 803 | bitvec_set_uint(&bv, si13->no_pbcch.rac, 8); |
| 804 | bitvec_set_bit(&bv, si13->no_pbcch.spgc_ccch_sup); |
| 805 | bitvec_set_uint(&bv, si13->no_pbcch.prio_acc_thr, 3); |
| 806 | bitvec_set_uint(&bv, si13->no_pbcch.net_ctrl_ord, 2); |
| 807 | append_gprs_cell_opt(&bv, &si13->cell_opts); |
| 808 | append_gprs_pwr_ctrl_pars(&bv, &si13->pwr_ctrl_pars); |
| 809 | } else { |
| 810 | /* PBCCH present in cell */ |
| 811 | bitvec_set_bit(&bv, 1); |
| 812 | bitvec_set_uint(&bv, si13->pbcch.psi1_rep_per, 4); |
| 813 | /* PBCCH Descripiton */ |
| 814 | bitvec_set_uint(&bv, si13->pbcch.pb, 4); |
| 815 | bitvec_set_uint(&bv, si13->pbcch.tsc, 3); |
| 816 | bitvec_set_uint(&bv, si13->pbcch.tn, 3); |
| 817 | switch (si13->pbcch.carrier_type) { |
| 818 | case PBCCH_BCCH: |
| 819 | bitvec_set_bit(&bv, 0); |
| 820 | bitvec_set_bit(&bv, 0); |
| 821 | break; |
| 822 | case PBCCH_ARFCN: |
| 823 | bitvec_set_bit(&bv, 0); |
| 824 | bitvec_set_bit(&bv, 1); |
| 825 | bitvec_set_uint(&bv, si13->pbcch.arfcn, 10); |
| 826 | break; |
| 827 | case PBCCH_MAIO: |
| 828 | bitvec_set_bit(&bv, 1); |
| 829 | bitvec_set_uint(&bv, si13->pbcch.maio, 6); |
| 830 | break; |
| 831 | } |
| 832 | } |
Harald Welte | 5fda908 | 2010-04-18 22:41:01 +0200 | [diff] [blame] | 833 | /* 3GPP TS 44.018 Release 6 / 10.5.2.37b */ |
| 834 | bitvec_set_bit(&bv, H); /* added Release 99 */ |
| 835 | /* claim our SGSN is compatible with Release 99, as EDGE and EGPRS |
| 836 | * was only added in this Release */ |
| 837 | bitvec_set_bit(&bv, 1); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 838 | } |
Holger Hans Peter Freyther | caa1486 | 2010-01-06 07:49:58 +0100 | [diff] [blame] | 839 | bitvec_spare_padding(&bv, (bv.data_len*8)-1); |
| 840 | return bv.data_len; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 841 | } |