blob: 113af5ca9f53c40bf50ba321c358eede97a5166b [file] [log] [blame]
Harald Weltea43f7892009-12-01 18:04:30 +05301/* 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 Welte9af6ddf2011-01-01 15:25:50 +010010 * 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 Weltea43f7892009-12-01 18:04:30 +053012 * (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 Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Harald Weltea43f7892009-12-01 18:04:30 +053018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * 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 Weltea43f7892009-12-01 18:04:30 +053021 *
22 */
23
24#include <string.h>
25#include <stdlib.h>
26#include <errno.h>
Max59a1bf32016-04-15 16:04:46 +020027#include <stdbool.h>
Harald Weltea43f7892009-12-01 18:04:30 +053028
Max59a1bf32016-04-15 16:04:46 +020029#include <openbsc/debug.h>
Harald Weltea43f7892009-12-01 18:04:30 +053030#include <openbsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010031#include <osmocom/core/bitvec.h>
Harald Weltea43f7892009-12-01 18:04:30 +053032#include <openbsc/rest_octets.h>
Max59a1bf32016-04-15 16:04:46 +020033#include <openbsc/arfcn_range_encode.h>
34
35#define SI2Q_MAX_LEN 160
Harald Weltea43f7892009-12-01 18:04:30 +053036
37/* generate SI1 rest octets */
Holger Hans Peter Freytherf876c392013-03-06 12:02:33 +010038int rest_octets_si1(uint8_t *data, uint8_t *nch_pos, int is1800_net)
Harald Weltea43f7892009-12-01 18:04:30 +053039{
40 struct bitvec bv;
41
42 memset(&bv, 0, sizeof(bv));
43 bv.data = data;
Holger Hans Peter Freyther4cffc452010-01-06 06:44:37 +010044 bv.data_len = 1;
Harald Weltea43f7892009-12-01 18:04:30 +053045
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 Freytherf876c392013-03-06 12:02:33 +010052 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 Freythercaa14862010-01-06 07:49:58 +010058 return bv.data_len;
Harald Weltea43f7892009-12-01 18:04:30 +053059}
60
Max59a1bf32016-04-15 16:04:46 +020061/* Append Repeated E-UTRAN Neighbour Cell to bitvec:
62 * see 3GPP TS 44.018 Table 10.5.2.33b.1
63 */
64static 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
111static inline int append_earfcn_size(const struct osmo_earfcn_si2q *e)
112{
113 if (!e)
114 return -EFAULT;
115 /* account for all the constant bits */
116 return 25 + osmo_earfcn_bit_size(e);
117}
118
119static inline void append_earfcn(struct bitvec *bv,
120 const struct osmo_earfcn_si2q *e)
121{
122 /* Additions in Rel-5: */
123 bitvec_set_bit(bv, H);
124 /* No 3G Additional Measurement Param. Descr. */
125 bitvec_set_bit(bv, 0);
126 /* No 3G ADDITIONAL MEASUREMENT Param. Descr. 2 */
127 bitvec_set_bit(bv, 0);
128 /* Additions in Rel-6: */
129 bitvec_set_bit(bv, H);
130 /* 3G_CCN_ACTIVE */
131 bitvec_set_bit(bv, 0);
132 /* Additions in Rel-7: */
133 bitvec_set_bit(bv, H);
134 /* No 700_REPORTING_OFFSET */
135 bitvec_set_bit(bv, 0);
136 /* No 810_REPORTING_OFFSET */
137 bitvec_set_bit(bv, 0);
138 /* Additions in Rel-8: */
139 bitvec_set_bit(bv, H);
140
141 /* Priority and E-UTRAN Parameters Description */
142 bitvec_set_bit(bv, 1);
143
144 /* No Serving Cell Priority Parameters Descr. */
145 bitvec_set_bit(bv, 0);
146 /* No 3G Priority Parameters Description */
147 bitvec_set_bit(bv, 0);
148 /* E-UTRAN Parameters Description */
149 bitvec_set_bit(bv, 1);
150
151 /* E-UTRAN_CCN_ACTIVE */
152 bitvec_set_bit(bv, 0);
153 /* E-UTRAN_Start: 9.1.54 */
154 bitvec_set_bit(bv, 1);
155 /* E-UTRAN_Stop: 9.1.54 */
156 bitvec_set_bit(bv, 1);
157
158 /* No E-UTRAN Measurement Parameters Descr. */
159 bitvec_set_bit(bv, 0);
160 /* No GPRS E-UTRAN Measurement Param. Descr. */
161 bitvec_set_bit(bv, 0);
162
163 /* Note: each of next 3 "repeated" structures might be repeated any
164 (0, 1, 2...) times - we only support 1 and 0 */
165
166 /* Repeated E-UTRAN Neighbour Cells */
167 bitvec_set_bit(bv, 1);
168
169 /* Note: we don't support different EARFCN arrays each with different
170 priority, threshold etc. */
171 append_eutran_neib_cell(bv, e);
172
173 /* stop bit - end of Repeated E-UTRAN Neighbour Cells sequence: */
174 bitvec_set_bit(bv, 0);
175
176 /* Note: following 2 repeated structs are not supported ATM */
177 /* stop bit - end of Repeated E-UTRAN Not Allowed Cells sequence: */
178 bitvec_set_bit(bv, 0);
179 /* stop bit - end of Repeated E-UTRAN PCID to TA mapping sequence: */
180 bitvec_set_bit(bv, 0);
181
182 /* Priority and E-UTRAN Parameters Description ends here */
183 /* No 3G CSG Description */
184 bitvec_set_bit(bv, 0);
185 /* No E-UTRAN CSG Description */
186 bitvec_set_bit(bv, 0);
187 /* No Additions in Rel-9: */
188 bitvec_set_bit(bv, L);
189}
190
191/* generate SI2quater rest octets: 3GPP TS 44.018 § 10.5.2.33b */
192int rest_octets_si2quater(uint8_t *data, const struct osmo_earfcn_si2q *e,
193 bool uarfcn, bool earfcn)
194{
195 int rc;
196 struct bitvec bv;
197 bv.data = data;
198 bv.data_len = 20;
199 bitvec_zero(&bv);
200
201 /* BA_IND */
202 bitvec_set_bit(&bv, 1);
203 /* 3G_BA_IND */
204 bitvec_set_bit(&bv, 1);
205 /* MP_CHANGE_MARK */
206 bitvec_set_bit(&bv, 0);
207
208 /* we do not support multiple si2quater messages at the moment: */
209 /* SI2quater_INDEX */
210 bitvec_set_uint(&bv, 0, 4);
211 /* SI2quater_COUNT */
212 bitvec_set_uint(&bv, 0, 4);
213
214 /* No Measurement_Parameters Description */
215 bitvec_set_bit(&bv, 0);
216 /* No GPRS_Real Time Difference Description */
217 bitvec_set_bit(&bv, 0);
218 /* No GPRS_BSIC Description */
219 bitvec_set_bit(&bv, 0);
220 /* No GPRS_REPORT PRIORITY Description */
221 bitvec_set_bit(&bv, 0);
222 /* No GPRS_MEASUREMENT_Parameters Description */
223 bitvec_set_bit(&bv, 0);
224 /* No NC Measurement Parameters */
225 bitvec_set_bit(&bv, 0);
226 /* No extension (length) */
227 bitvec_set_bit(&bv, 0);
228
229 if (uarfcn) {
230
231 } else { /* No 3G Neighbour Cell Description */
232 bitvec_set_bit(&bv, 0);
233 }
234
235 /* No 3G Measurement Parameters Description */
236 bitvec_set_bit(&bv, 0);
237 /* No GPRS_3G_MEASUREMENT Parameters Descr. */
238 bitvec_set_bit(&bv, 0);
239
240 if (earfcn) {
241 rc = append_earfcn_size(e);
242 if (rc < 0)
243 return rc;
244 if (rc + bv.cur_bit > SI2Q_MAX_LEN)
245 return -ENOMEM;
246 append_earfcn(&bv, e);
247 } else {
248 /* No Additions in Rel-5: */
249 bitvec_set_bit(&bv, L);
250 }
251
252 bitvec_spare_padding(&bv, (bv.data_len * 8) - 1);
253 return bv.data_len;
254}
255
Harald Weltea43f7892009-12-01 18:04:30 +0530256/* Append selection parameters to bitvec */
257static void append_selection_params(struct bitvec *bv,
258 const struct gsm48_si_selection_params *sp)
259{
260 if (sp->present) {
261 bitvec_set_bit(bv, H);
262 bitvec_set_bit(bv, sp->cbq);
263 bitvec_set_uint(bv, sp->cell_resel_off, 6);
264 bitvec_set_uint(bv, sp->temp_offs, 3);
265 bitvec_set_uint(bv, sp->penalty_time, 5);
266 } else
267 bitvec_set_bit(bv, L);
268}
269
270/* Append power offset to bitvec */
271static void append_power_offset(struct bitvec *bv,
272 const struct gsm48_si_power_offset *po)
273{
274 if (po->present) {
275 bitvec_set_bit(bv, H);
276 bitvec_set_uint(bv, po->power_offset, 2);
277 } else
278 bitvec_set_bit(bv, L);
279}
280
281/* Append GPRS indicator to bitvec */
282static void append_gprs_ind(struct bitvec *bv,
283 const struct gsm48_si3_gprs_ind *gi)
284{
285 if (gi->present) {
286 bitvec_set_bit(bv, H);
287 bitvec_set_uint(bv, gi->ra_colour, 3);
288 /* 0 == SI13 in BCCH Norm, 1 == SI13 sent on BCCH Ext */
289 bitvec_set_bit(bv, gi->si13_position);
290 } else
291 bitvec_set_bit(bv, L);
292}
293
294
295/* Generate SI3 Rest Octests (Chapter 10.5.2.34 / Table 10.4.72) */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200296int rest_octets_si3(uint8_t *data, const struct gsm48_si_ro_info *si3)
Harald Weltea43f7892009-12-01 18:04:30 +0530297{
298 struct bitvec bv;
299
300 memset(&bv, 0, sizeof(bv));
301 bv.data = data;
Holger Hans Peter Freyther4cffc452010-01-06 06:44:37 +0100302 bv.data_len = 4;
Harald Weltea43f7892009-12-01 18:04:30 +0530303
304 /* Optional Selection Parameters */
305 append_selection_params(&bv, &si3->selection_params);
306
307 /* Optional Power Offset */
308 append_power_offset(&bv, &si3->power_offset);
309
310 /* Do we have a SI2ter on the BCCH? */
311 if (si3->si2ter_indicator)
312 bitvec_set_bit(&bv, H);
313 else
314 bitvec_set_bit(&bv, L);
315
316 /* Early Classmark Sending Control */
317 if (si3->early_cm_ctrl)
318 bitvec_set_bit(&bv, H);
319 else
320 bitvec_set_bit(&bv, L);
321
322 /* Do we have a SI Type 9 on the BCCH? */
323 if (si3->scheduling.present) {
324 bitvec_set_bit(&bv, H);
325 bitvec_set_uint(&bv, si3->scheduling.where, 3);
326 } else
327 bitvec_set_bit(&bv, L);
328
329 /* GPRS Indicator */
330 append_gprs_ind(&bv, &si3->gprs_ind);
331
Maxf3f35052016-04-15 16:04:44 +0200332 /* 3G Early Classmark Sending Restriction controlled by
333 * early_cm_ctrl above */
334 bitvec_set_bit(&bv, H);
335
336 if (si3->si2quater_indicator) {
337 bitvec_set_bit(&bv, H); /* indicator struct present */
338 bitvec_set_uint(&bv, 0, 1); /* message is sent on BCCH Norm */
339 }
340
Holger Hans Peter Freythercaa14862010-01-06 07:49:58 +0100341 bitvec_spare_padding(&bv, (bv.data_len*8)-1);
342 return bv.data_len;
Harald Weltea43f7892009-12-01 18:04:30 +0530343}
344
345static int append_lsa_params(struct bitvec *bv,
346 const struct gsm48_lsa_params *lsa_params)
347{
348 /* FIXME */
Holger Hans Peter Freytherae80f922010-04-10 00:05:16 +0200349 return -1;
Harald Weltea43f7892009-12-01 18:04:30 +0530350}
351
352/* Generate SI4 Rest Octets (Chapter 10.5.2.35) */
Holger Hans Peter Freyther7ff77ec2010-12-29 23:06:22 +0100353int rest_octets_si4(uint8_t *data, const struct gsm48_si_ro_info *si4, int len)
Harald Weltea43f7892009-12-01 18:04:30 +0530354{
355 struct bitvec bv;
356
357 memset(&bv, 0, sizeof(bv));
358 bv.data = data;
Holger Hans Peter Freyther7ff77ec2010-12-29 23:06:22 +0100359 bv.data_len = len;
Harald Weltea43f7892009-12-01 18:04:30 +0530360
361 /* SI4 Rest Octets O */
362 append_selection_params(&bv, &si4->selection_params);
363 append_power_offset(&bv, &si4->power_offset);
364 append_gprs_ind(&bv, &si4->gprs_ind);
365
366 if (0 /* FIXME */) {
367 /* H and SI4 Rest Octets S */
368 bitvec_set_bit(&bv, H);
369
370 /* LSA Parameters */
371 if (si4->lsa_params.present) {
372 bitvec_set_bit(&bv, H);
373 append_lsa_params(&bv, &si4->lsa_params);
374 } else
375 bitvec_set_bit(&bv, L);
376
377 /* Cell Identity */
378 if (1) {
379 bitvec_set_bit(&bv, H);
380 bitvec_set_uint(&bv, si4->cell_id, 16);
381 } else
382 bitvec_set_bit(&bv, L);
383
384 /* LSA ID Information */
385 if (0) {
386 bitvec_set_bit(&bv, H);
387 /* FIXME */
388 } else
389 bitvec_set_bit(&bv, L);
390 } else {
391 /* L and break indicator */
392 bitvec_set_bit(&bv, L);
393 bitvec_set_bit(&bv, si4->break_ind ? H : L);
394 }
395
Holger Hans Peter Freythercaa14862010-01-06 07:49:58 +0100396 return bv.data_len;
Harald Weltea43f7892009-12-01 18:04:30 +0530397}
398
399/* GPRS Mobile Allocation as per TS 04.60 Chapter 12.10a:
400 < GPRS Mobile Allocation IE > ::=
401 < HSN : bit (6) >
402 { 0 | 1 < RFL number list : < RFL number list struct > > }
403 { 0 < MA_LENGTH : bit (6) >
404 < MA_BITMAP: bit (val(MA_LENGTH) + 1) >
405 | 1 { 0 | 1 <ARFCN index list : < ARFCN index list struct > > } } ;
406
407 < RFL number list struct > :: =
408 < RFL_NUMBER : bit (4) >
409 { 0 | 1 < RFL number list struct > } ;
410 < ARFCN index list struct > ::=
411 < ARFCN_INDEX : bit(6) >
412 { 0 | 1 < ARFCN index list struct > } ;
413 */
414static int append_gprs_mobile_alloc(struct bitvec *bv)
415{
416 /* Hopping Sequence Number */
417 bitvec_set_uint(bv, 0, 6);
418
419 if (0) {
420 /* We want to use a RFL number list */
421 bitvec_set_bit(bv, 1);
422 /* FIXME: RFL number list */
423 } else
424 bitvec_set_bit(bv, 0);
425
426 if (0) {
427 /* We want to use a MA_BITMAP */
428 bitvec_set_bit(bv, 0);
429 /* FIXME: MA_LENGTH, MA_BITMAP, ... */
430 } else {
431 bitvec_set_bit(bv, 1);
432 if (0) {
433 /* We want to provide an ARFCN index list */
434 bitvec_set_bit(bv, 1);
435 /* FIXME */
436 } else
437 bitvec_set_bit(bv, 0);
438 }
439 return 0;
440}
441
442static int encode_t3192(unsigned int t3192)
443{
444 if (t3192 == 0)
445 return 3;
446 else if (t3192 <= 80)
447 return 4;
448 else if (t3192 <= 120)
449 return 5;
450 else if (t3192 <= 160)
451 return 6;
452 else if (t3192 <= 200)
453 return 7;
454 else if (t3192 <= 500)
455 return 0;
456 else if (t3192 <= 1000)
457 return 1;
458 else if (t3192 <= 1500)
459 return 2;
460 else
461 return -EINVAL;
462}
463
464static int encode_drx_timer(unsigned int drx)
465{
466 if (drx == 0)
467 return 0;
468 else if (drx == 1)
469 return 1;
470 else if (drx == 2)
471 return 2;
472 else if (drx <= 4)
473 return 3;
474 else if (drx <= 8)
475 return 4;
476 else if (drx <= 16)
477 return 5;
478 else if (drx <= 32)
479 return 6;
480 else if (drx <= 64)
481 return 7;
482 else
483 return -EINVAL;
484}
485
486/* GPRS Cell Options as per TS 04.60 Chapter 12.24
487 < GPRS Cell Options IE > ::=
488 < NMO : bit(2) >
489 < T3168 : bit(3) >
490 < T3192 : bit(3) >
491 < DRX_TIMER_MAX: bit(3) >
492 < ACCESS_BURST_TYPE: bit >
493 < CONTROL_ACK_TYPE : bit >
494 < BS_CV_MAX: bit(4) >
495 { 0 | 1 < PAN_DEC : bit(3) >
496 < PAN_INC : bit(3) >
497 < PAN_MAX : bit(3) >
498 { 0 | 1 < Extension Length : bit(6) >
499 < bit (val(Extension Length) + 1
500 & { < Extension Information > ! { bit ** = <no string> } } ;
501 < Extension Information > ::=
502 { 0 | 1 < EGPRS_PACKET_CHANNEL_REQUEST : bit >
503 < BEP_PERIOD : bit(4) > }
504 < PFC_FEATURE_MODE : bit >
505 < DTM_SUPPORT : bit >
506 <BSS_PAGING_COORDINATION: bit >
507 <spare bit > ** ;
508 */
Harald Weltea4e2d042009-12-20 17:08:22 +0100509static int append_gprs_cell_opt(struct bitvec *bv,
510 const struct gprs_cell_options *gco)
Harald Weltea43f7892009-12-01 18:04:30 +0530511{
512 int t3192, drx_timer_max;
513
514 t3192 = encode_t3192(gco->t3192);
515 if (t3192 < 0)
516 return t3192;
517
518 drx_timer_max = encode_drx_timer(gco->drx_timer_max);
519 if (drx_timer_max < 0)
520 return drx_timer_max;
521
522 bitvec_set_uint(bv, gco->nmo, 2);
523 bitvec_set_uint(bv, gco->t3168 / 500, 3);
524 bitvec_set_uint(bv, t3192, 3);
525 bitvec_set_uint(bv, drx_timer_max, 3);
526 /* ACCESS_BURST_TYPE: Hard-code 8bit */
527 bitvec_set_bit(bv, 0);
528 /* CONTROL_ACK_TYPE: Hard-code to RLC/MAC control block */
529 bitvec_set_bit(bv, 1);
530 bitvec_set_uint(bv, gco->bs_cv_max, 4);
531
Harald Weltea4b16652010-05-31 12:54:23 +0200532 if (0) {
533 /* hard-code no PAN_{DEC,INC,MAX} */
534 bitvec_set_bit(bv, 0);
535 } else {
536 /* copied from ip.access BSC protocol trace */
537 bitvec_set_bit(bv, 1);
538 bitvec_set_uint(bv, 1, 3); /* DEC */
539 bitvec_set_uint(bv, 1, 3); /* INC */
540 bitvec_set_uint(bv, 15, 3); /* MAX */
541 }
Harald Weltea43f7892009-12-01 18:04:30 +0530542
Harald Welteda0586a2010-04-18 14:49:05 +0200543 if (!gco->ext_info_present) {
544 /* no extension information */
545 bitvec_set_bit(bv, 0);
546 } else {
547 /* extension information */
548 bitvec_set_bit(bv, 1);
549 if (!gco->ext_info.egprs_supported) {
550 /* 6bit length of extension */
Harald Welte39608dc2010-04-18 22:47:22 +0200551 bitvec_set_uint(bv, (1 + 3)-1, 6);
Harald Welteda0586a2010-04-18 14:49:05 +0200552 /* EGPRS supported in the cell */
553 bitvec_set_bit(bv, 0);
554 } else {
555 /* 6bit length of extension */
Harald Welte39608dc2010-04-18 22:47:22 +0200556 bitvec_set_uint(bv, (1 + 5 + 3)-1, 6);
Harald Welteda0586a2010-04-18 14:49:05 +0200557 /* EGPRS supported in the cell */
558 bitvec_set_bit(bv, 1);
559 /* 1bit EGPRS PACKET CHANNEL REQUEST */
560 bitvec_set_bit(bv, gco->ext_info.use_egprs_p_ch_req);
561 /* 4bit BEP PERIOD */
562 bitvec_set_uint(bv, gco->ext_info.bep_period, 4);
563 }
564 bitvec_set_bit(bv, gco->ext_info.pfc_supported);
565 bitvec_set_bit(bv, gco->ext_info.dtm_supported);
566 bitvec_set_bit(bv, gco->ext_info.bss_paging_coordination);
567 }
Harald Weltea43f7892009-12-01 18:04:30 +0530568
569 return 0;
570}
571
572static void append_gprs_pwr_ctrl_pars(struct bitvec *bv,
Harald Weltea4e2d042009-12-20 17:08:22 +0100573 const struct gprs_power_ctrl_pars *pcp)
Harald Weltea43f7892009-12-01 18:04:30 +0530574{
575 bitvec_set_uint(bv, pcp->alpha, 4);
576 bitvec_set_uint(bv, pcp->t_avg_w, 5);
577 bitvec_set_uint(bv, pcp->t_avg_t, 5);
578 bitvec_set_uint(bv, pcp->pc_meas_chan, 1);
579 bitvec_set_uint(bv, pcp->n_avg_i, 4);
580}
581
Harald Welte5fda9082010-04-18 22:41:01 +0200582/* Generate SI13 Rest Octests (04.08 Chapter 10.5.2.37b) */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200583int rest_octets_si13(uint8_t *data, const struct gsm48_si13_info *si13)
Harald Weltea43f7892009-12-01 18:04:30 +0530584{
585 struct bitvec bv;
586
587 memset(&bv, 0, sizeof(bv));
588 bv.data = data;
Holger Hans Peter Freyther4cffc452010-01-06 06:44:37 +0100589 bv.data_len = 20;
Harald Weltea43f7892009-12-01 18:04:30 +0530590
591 if (0) {
592 /* No rest octets */
593 bitvec_set_bit(&bv, L);
594 } else {
595 bitvec_set_bit(&bv, H);
596 bitvec_set_uint(&bv, si13->bcch_change_mark, 3);
597 bitvec_set_uint(&bv, si13->si_change_field, 4);
Harald Welte97a282b2010-03-14 15:37:43 +0800598 if (1) {
Harald Weltea43f7892009-12-01 18:04:30 +0530599 bitvec_set_bit(&bv, 0);
600 } else {
601 bitvec_set_bit(&bv, 1);
602 bitvec_set_uint(&bv, si13->bcch_change_mark, 2);
603 append_gprs_mobile_alloc(&bv);
604 }
605 if (!si13->pbcch_present) {
606 /* PBCCH not present in cell */
607 bitvec_set_bit(&bv, 0);
608 bitvec_set_uint(&bv, si13->no_pbcch.rac, 8);
609 bitvec_set_bit(&bv, si13->no_pbcch.spgc_ccch_sup);
610 bitvec_set_uint(&bv, si13->no_pbcch.prio_acc_thr, 3);
611 bitvec_set_uint(&bv, si13->no_pbcch.net_ctrl_ord, 2);
612 append_gprs_cell_opt(&bv, &si13->cell_opts);
613 append_gprs_pwr_ctrl_pars(&bv, &si13->pwr_ctrl_pars);
614 } else {
615 /* PBCCH present in cell */
616 bitvec_set_bit(&bv, 1);
617 bitvec_set_uint(&bv, si13->pbcch.psi1_rep_per, 4);
618 /* PBCCH Descripiton */
619 bitvec_set_uint(&bv, si13->pbcch.pb, 4);
620 bitvec_set_uint(&bv, si13->pbcch.tsc, 3);
621 bitvec_set_uint(&bv, si13->pbcch.tn, 3);
622 switch (si13->pbcch.carrier_type) {
623 case PBCCH_BCCH:
624 bitvec_set_bit(&bv, 0);
625 bitvec_set_bit(&bv, 0);
626 break;
627 case PBCCH_ARFCN:
628 bitvec_set_bit(&bv, 0);
629 bitvec_set_bit(&bv, 1);
630 bitvec_set_uint(&bv, si13->pbcch.arfcn, 10);
631 break;
632 case PBCCH_MAIO:
633 bitvec_set_bit(&bv, 1);
634 bitvec_set_uint(&bv, si13->pbcch.maio, 6);
635 break;
636 }
637 }
Harald Welte5fda9082010-04-18 22:41:01 +0200638 /* 3GPP TS 44.018 Release 6 / 10.5.2.37b */
639 bitvec_set_bit(&bv, H); /* added Release 99 */
640 /* claim our SGSN is compatible with Release 99, as EDGE and EGPRS
641 * was only added in this Release */
642 bitvec_set_bit(&bv, 1);
Harald Weltea43f7892009-12-01 18:04:30 +0530643 }
Holger Hans Peter Freythercaa14862010-01-06 07:49:58 +0100644 bitvec_spare_padding(&bv, (bv.data_len*8)-1);
645 return bv.data_len;
Harald Weltea43f7892009-12-01 18:04:30 +0530646}