blob: 70009ac0e554490277d51f75ae1afd6e39d2c9bb [file] [log] [blame]
Harald Welte9419c8a2017-07-30 04:07:05 +02001/* Encoding/Decoding routines for GSM System Information messages
Harald Welte34b5a952019-05-27 11:54:11 +02002 * according to 3GPP TS 44.018 Version 12.3.0 Release 12
3 *
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
Harald Welte9419c8a2017-07-30 04:07:05 +020012
13module GSM_RR_Types {
14
15 import from General_Types all;
16 import from Osmocom_Types all;
17 import from GSM_Types all;
18 import from RLCMAC_CSN1_Types all;
19
20 /* Table 10.4.1 of Section 10.4 / 3GPP TS 44.018 */
21 type enumerated RrMessageType {
22 ADDITIONAL_ASSIGNMENT ('00111011'B),
23 IMMEDIATE_ASSIGNMENT ('00111111'B),
24 IMMEDIATE_ASSIGNMENT_EXTENDED ('00111001'B),
25 IMMEDIATE_ASSIGNMENT_REJECT ('00111010'B),
26 IMMEDIATE_PACKET_ASSIGNMENT ('01101001'B),
27
28 CIPHERING_MODE_COMMAND ('00110101'B),
29 CIPHERING_MODE_COMPLETE ('00110010'B),
30
31 CONFIGURATION_CHANGE_COMMAND ('00110000'B),
32 CONFIGURATION_CHANGE_ACK ('00110001'B),
33 CONFIGURATION_CHANGE_REJECT ('00110011'B),
34
35 ASSIGNMENT_COMMAND ('00101110'B),
36 ASSIGNMENT_COMPLETE ('00101001'B),
37 ASSIGNMENT_FAILURE ('00101111'B),
38 HANDOVER_COMMAND ('00101011'B),
39 HANDOVER_COMPLETE ('00101100'B),
40 HANDOVER_FAILURE ('00101000'B),
41 PHYSICAL_INFORMATION ('00101101'B),
42
43 CHANNEL_RELEASE ('00001101'B),
44 PARTIAL_RELEASE ('00001010'B),
45 PARTIAL_RELEASE_COMPLETE ('00001111'B),
46
47 PAGING_REQUEST_TYPE_1 ('00100001'B),
48 PAGING_REQUEST_TYPE_2 ('00100010'B),
49 PAGING_REQUEST_TYPE_3 ('00100100'B),
50 PAGING_RESPONSE ('00100111'B),
51 NOTIFICATION_NCH ('00100000'B),
52 NOTIFICATION_RESPOSNE ('00100110'B),
53
54 SYSTEM_INFORMATION_TYPE_8 ('00011000'B),
55 SYSTEM_INFORMATION_TYPE_1 ('00011001'B),
56 SYSTEM_INFORMATION_TYPE_2 ('00011010'B),
57 SYSTEM_INFORMATION_TYPE_3 ('00011011'B),
58 SYSTEM_INFORMATION_TYPE_4 ('00011100'B),
59 SYSTEM_INFORMATION_TYPE_5 ('00011101'B),
60 SYSTEM_INFORMATION_TYPE_6 ('00011110'B),
61 SYSTEM_INFORMATION_TYPE_7 ('00011111'B),
62 SYSTEM_INFORMATION_TYPE_2bis ('00000010'B),
63 SYSTEM_INFORMATION_TYPE_2ter ('00000011'B),
64 SYSTEM_INFORMATION_TYPE_2quater ('00000111'B),
65 SYSTEM_INFORMATION_TYPE_5bis ('00000101'B),
66 SYSTEM_INFORMATION_TYPE_5ter ('00000110'B),
67 SYSTEM_INFORMATION_TYPE_9 ('00000100'B),
68 SYSTEM_INFORMATION_TYPE_13 ('00000000'B),
69
70 SYSTEM_INFORMATION_TYPE_16 ('00111101'B),
71 SYSTEM_INFORMATION_TYPE_17 ('00111110'B),
72
73 CHANNEL_MODE_MODIFY ('00010000'B),
74 RR_STATUS ('00010010'B),
75 CHANNEL_MODE_MODIFY_ACKNOWLEDGE ('00010111'B),
76 FREQUENCY_REDEFINITION ('00010100'B),
77 MEASUREMENT_REPORT ('00010101'B),
78 CLASSMARK_CHANGE ('00010110'B),
79 CLASSMARK_ENQUIRY ('00010011'B),
80 EXTENDED_MEASUREMENT_REPORT ('00110110'B),
81 EXTENDED_MEASUREMENT_ORDER ('00110111'B),
82 GPRS_SUSPENSION_REQUEST ('00110100'B),
83 //MBMS_ANNOUNCEMENT ('00010110'B), duplicate?
84 //SERVICE_INFORMATION ('00110110'B), duplicate?
85
86 APPLICATION_INFORMATION ('00111000'B),
87
88 SYSTEM_INFORMATION_TYPE_14 ('00000001'B),
89 SYSTEM_INFORMATION_TYPE_15 ('01000011'B),
90 SYSTEM_INFORMATION_TYPE_18 ('01000000'B),
91 SYSTEM_INFORMATION_TYPE_19 ('01000001'B),
92 SYSTEM_INFORMATION_TYPE_20 ('01000010'B),
93 SYSTEM_INFORMATION_TYPE_13alt ('01000100'B),
94 SYSTEM_INFORMATION_TYPE_2n ('01000101'B),
95 SYSTEM_INFORMATION_TYPE_21 ('01000110'B),
96 SYSTEM_INFORMATION_TYPE_22 ('01000111'B),
97 SYSTEM_INFORMATION_TYPE_23 ('01001111'B),
98
99 DTM_ASSIGNMENT_FAILURE ('01001000'B),
100 DTM_REJECT ('01001001'B),
101 DTM_REQUEST ('01001010'B),
102 PACKET_ASSIGNMENT ('01001011'B),
103 DTM_ASSIGNMENT_COMMAND ('01001100'B),
104 DTM_INFORMATION ('01001101'B),
105 PACKET_INFORMATION ('01001110'B),
106
107 UTRAN_CLASSMARK_CHANGE ('01100000'B),
108 CDMA2000_CLASSMARK_CHANGE ('01100010'B),
109 INTERSYS_TO_UTRAN_HO_CMD ('01100011'B),
110 INTERSYS_TO_CDMA2000_HO_CMD ('01100100'B),
111 GERAN_IU_MODE_CLASSMARK_CHG ('01100101'B),
112 INTERSYS_TO_EUTRAN_HO_CMD ('01100110'B)
113 } with { variant "FIELDLENGTH(8)" };
114
115 type octetstring RestOctets with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };
116 type hexstring GsmBcdString with { variant "HEXORDER(low)" };
117 type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
118
119 type record L2PseudoLength {
120 uint6_t l2_plen,
121 BIT2 zero_one
122 } with { variant "" };
123
Harald Weltef8df4cb2018-03-10 15:15:08 +0100124 template L2PseudoLength tr_L2Pseudolength(template uint6_t len) := {
125 l2_plen := len,
126 zero_one := '01'B
127 };
128
129 template (value) L2PseudoLength ts_L2Pseudolength(uint6_t len) := {
Harald Welte9419c8a2017-07-30 04:07:05 +0200130 l2_plen := len,
131 zero_one := '01'B
132 };
133
134 type record RrHeader {
135 L2PseudoLength l2_plen,
136 uint4_t skip_indicator,
137 uint4_t rr_protocol_discriminator,
138 RrMessageType message_type
139 } with { variant "" };
140
141 template RrHeader t_RrHeader(RrMessageType msg_type, template uint6_t len) := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100142 l2_plen := tr_L2Pseudolength(len),
Harald Welte9419c8a2017-07-30 04:07:05 +0200143 skip_indicator := 0,
144 rr_protocol_discriminator := 6,
145 message_type := msg_type
146 };
147
Harald Weltef8df4cb2018-03-10 15:15:08 +0100148 template (value) RrHeader ts_RrHeader(RrMessageType msg_type, uint6_t len) := {
149 l2_plen := ts_L2Pseudolength(len),
150 skip_indicator := 0,
151 rr_protocol_discriminator := 6,
152 message_type := msg_type
153 };
154
155
Harald Welte9419c8a2017-07-30 04:07:05 +0200156 type record RrL3Header {
157 uint4_t skip_indicator,
158 uint4_t rr_protocol_discriminator,
159 RrMessageType message_type
160 } with { variant "" };
161
Harald Weltecbc947f2018-02-22 00:26:55 +0100162 template RrL3Header t_RrL3Header(RrMessageType msg_type) := {
163 skip_indicator := 0,
164 rr_protocol_discriminator := 6,
165 message_type := msg_type
166 }
167
Pau Espin Pedrol0aad5962018-09-28 16:03:55 +0200168 /* TS 44.004 7.2.1 */
169 type record SacchL1Header {
170 uint2_t reserved,
171 boolean fpc,
172 uint5_t ms_power_lvl,
173 uint8_t actual_ta
174 } with { variant "FIELDORDER(msb)" };
175
176 template (value) SacchL1Header ts_SacchL1Header(uint5_t ms_power_lvl, boolean fpc, uint8_t actual_ta) := {
177 reserved := 0,
178 fpc := fpc,
179 ms_power_lvl := ms_power_lvl,
180 actual_ta := actual_ta
181 };
182
Harald Welte9419c8a2017-07-30 04:07:05 +0200183 type record MaioHsn {
184 } with { variant "" };
185
186 /* TS 24.008 10.5.1.1 */
187 type uint16_t CellIdentity;
188
189 /* TS 24.008 10.5.1.2 */
190 type uint4_t CipheringKeySeqNr (0..7);
191
192 /* 24.008 10.5.1.3 */
193 type record LocationAreaIdentification {
194 BcdMccMnc mcc_mnc,
195 uint16_t lac
196 } with { variant "" };
197
198 /* TS 24.008 10.5.1.4 */
199 type enumerated MobileIdentityType {
200 MI_TYPE_NONE (0),
201 MI_TYPE_IMSI,
202 MI_TYPE_IMEI,
203 MI_TYPE_IMEISV,
204 MI_TYPE_TMSI,
205 MI_TYPE_TMGI
206 } with { variant "FIELDLENGTH(3)" };
207
208 type record MobileIdentityBCD {
209 MobileIdentityType mi_type (MI_TYPE_IMSI, MI_TYPE_IMEI, MI_TYPE_IMEISV),
210 boolean odd,
211 hexstring digits
212 } with { variant "FIELDORDER(lsb)" };
213
214 type record MobileIdentityTMSI {
215 BIT4 pad ('1111'B),
216 boolean odd (false),
217 MobileIdentityType mi_type (MI_TYPE_TMSI),
218 GsmTmsi tmsi
219 } with { variant "FIELDORDER(lsb)" };
220
221 type record MobileIdentityNone {
222 BIT4 pad ('1111'B),
223 boolean odd (false),
224 MobileIdentityType mi_type (MI_TYPE_NONE)
225 } with { variant "FIELDORDER(lsb)" };
226
227 type union MobileIdentity {
228 MobileIdentityBCD imsi,
229 MobileIdentityBCD imei,
230 MobileIdentityBCD imeisv,
231 MobileIdentityTMSI tmsi,
232 MobileIdentityNone unused
233 } with { variant "TAG(imsi, mi_type = MI_TYPE_IMSI;
234 imei, mi_type = MI_TYPE_IMEI;
235 imeisv, mi_type = MI_TYPE_IMEISV;
236 tmsi, mi_type = MI_TYPE_TMSI;
237 unused, mi_type = MI_TYPE_NONE)"
238 variant "FIELDORDER(lsb)"
239 };
240
Stefan Sperling59c15d62018-10-10 11:09:25 +0200241 /* TS 24.008 10.5.1.4 "Mobile Identity" */
Harald Welte9419c8a2017-07-30 04:07:05 +0200242 type record MobileIdentityLV {
243 uint8_t len,
244 MobileIdentity mi
245 } with { variant (len) "LENGTHTO(mi)" };
246
247 type record MobileIdentityTLV {
248 uint8_t tag,
249 uint8_t len,
250 MobileIdentity mi
251 } with { variant (len) "LENGTHTO(mi)" };
252
253 /* TS 24.008 10.5.1.5 */
254 type record MsClassmark1 {
255 BIT1 spare,
256 uint2_t rev_level,
257 boolean es_ind,
258 boolean a51,
259 uint3_t rf_pwr_cap
260 } with { variant "" };
261
262 /* TS 24.008 10.5.1.6 */
263 type record MsClassmark2 {
264 BIT1 spare,
265 uint2_t rev_level,
266 boolean es_ind,
267 boolean a51,
268 uint3_t rf_pwr_cap,
269 BIT1 spare1,
270 boolean ps_cap,
271 uint2_t ss_screen_ind,
272 boolean sm_cap,
273 boolean vbs,
274 boolean vgcs,
275 boolean fc,
276 boolean cm3,
277 BIT1 spare2,
278 boolean lcsva_cap,
279 boolean ucs2,
280 boolean solsa,
281 boolean cmsp,
282 boolean a53,
283 boolean a52
284 } with { variant "" };
285 type record MsClassmark2LV {
286 uint8_t len,
287 MsClassmark2 cm2
288 } with { variant (len) "LENGTHTO(cm2)" };
289
290
291 /* 44.018 10.5.2.5 */
292 type record ChannelDescription {
293 RslChannelNr chan_nr,
294 uint3_t tsc,
295 boolean h,
296 uint12_t arfcn optional,
297 MaioHsn maio_hsn optional
298 } with { variant (arfcn) "PRESENCE(h = false)"
299 variant (maio_hsn) "PRESENCE(h = true)" };
300
301 type record ChannelDescriptionTV {
302 OCT1 iei,
303 ChannelDescription v
304 } with { variant "" };
305
306 /* 10.5.2.21 */
307 type record MobileAllocation {
308 uint8_t len,
309 bitstring ma
310 } with { variant (len) "LENGTHTO(ma)" };
311
312 /* 10.5.2.25a */
Harald Welte1b9b7702017-07-30 04:19:14 +0200313 type record PktChDesc0Ind {
314 uint6_t maio,
315 BIT1 ma_number_ind,
316 BIT1 change_mark1_valid,
317 BIT2 change_mark1
318 } with { variant "" };
319 type record PktChDesc0 {
320 BIT1 hopping,
321 BIT1 spare ('0'B),
322 uint10_t arfcn optional,
323 PktChDesc0Ind indirect optional
324 } with {
325 variant (arfcn) "PRESENCE(hopping = '0'B)"
326 variant (indirect) "PRESENCE(hopping = '1'B)"
327 };
328 type record PktChDesc1 {
329 uint6_t maio,
330 uint6_t hsn
331 } with { variant "" };
332 type record PacketChannelDescription {
333 uint5_t channel_Type_spare,
334 uint3_t tn,
335 uint3_t tsc,
336 BIT1 presence,
337 PktChDesc0 zero optional,
338 PktChDesc1 one optional
339 } with {
340 variant (zero) "PRESENCE(presence = '0'B)"
341 variant (one) "PRESENCE(presence = '1'B)"
342 };
Harald Welte9419c8a2017-07-30 04:07:05 +0200343
344 /* 10.5.2.25b */
345 type record DedicatedModeOrTbf {
346 BIT1 spare,
347 boolean tma,
348 boolean downlink,
349 boolean tbf
350 } with { variant "" };
351
352 /* 10.5.2.26 */
353 type enumerated PageMode {
354 PAGE_MODE_NORMAL,
355 PAGE_MODE_EXTENDED,
356 PAGE_MODE_REORGANIZATION,
357 PAGE_MODE_SAME_AS_BEFORE
358 } with { variant "FIELDLENGTH(4)" };
359
360 /* 10.5.2.30 */
361 type record RequestReference {
362 bitstring ra length(8),
363 uint5_t t1p,
364 uint6_t t3,
365 uint5_t t2
366 } with { variant "" };
367
368 template RequestReference t_RequestReference(template bitstring ra, template uint5_t t1p, template uint6_t t3, template uint5_t t2) := {
369 ra := ra,
370 t1p := t1p,
371 t3 := t3,
372 t2 := t2
373 }
374
375 /* compute the expected request reference for given RA + FN */
376 function f_compute_ReqRef(uint8_t ra, GsmFrameNumber fn) return RequestReference {
377 var RequestReference req_ref := { ra := int2bit(ra, 8) };
378 req_ref.t1p := (fn / 1326) mod 32;
379 req_ref.t2 := fn mod 26;
380 req_ref.t3 := fn mod 51;
381 return req_ref
382 }
Harald Weltee8d750e2018-06-10 21:41:35 +0200383 function tr_compute_ReqRef(template uint8_t ra, template GsmFrameNumber fn)
384 return template RequestReference {
385 var template RequestReference req_ref;
386 if (istemplatekind(ra, "?")) {
387 req_ref.ra := ?;
388 } else {
389 req_ref.ra := int2bit(valueof(ra), 8);
390 }
391 if (istemplatekind(fn, "?")) {
392 req_ref.t1p := ?;
393 req_ref.t2 := ?;
394 req_ref.t3 := ?;
395 } else {
396 var GsmFrameNumber fn_v := valueof(fn);
397 req_ref.t1p := (fn_v / 1326) mod 32;
398 req_ref.t2 := fn_v mod 26;
399 req_ref.t3 := fn_v mod 51;
400 }
401 return req_ref;
402 }
Harald Welte9419c8a2017-07-30 04:07:05 +0200403
404 /* 10.5.2.40 */
405 type integer TimingAdvance (0..219);
406
407 /* 10.5.2.43 */
408 type uint8_t WaitIndication;
409
410 /* 10.5.2.76 */
411 type record FeatureIndicator {
412 BIT2 spare,
413 boolean cs_ir,
414 boolean ps_ir
415 } with { variant "" };
416
417 /* 24.008 10.5.5.6 */
418 type record DrxParameter {
419 uint8_t split_pg_cycle_code,
420 uint4_t drx_cycle_len_coeff,
421 boolean split_on_ccch,
422 uint3_t non_drx_timer
423 } with { variant "" };
424
425 /* 24.008 10.5.5.15 */
426 type record RoutingAreaIdentification {
427 LocationAreaIdentification lai,
428 uint8_t rac
429 } with { variant "" };
430
Harald Welteb16516c2019-03-21 21:31:41 +0100431 external function enc_RoutingAreaIdentification(RoutingAreaIdentification rai) return octetstring
432 with { extension "prototype(convert)" extension "encode(RAW)" }
433
Harald Welte9419c8a2017-07-30 04:07:05 +0200434 /* 44.018 10.5.2.16 */
435 type record IaRestOctHL {
436 uint6_t freq_par_len,
437 BIT2 padding ('00'B) optional,
438 uint6_t maio optional,
439 octetstring mobile_allocation optional
440 } with {
441 variant (freq_par_len) "LENGTHTO(mobile_allocation,maio,padding)"
442/*
443 variant (padding) "PRESENCE(freq_par_len != 0)"
444 variant (maio) "PRESENCE(freq_par_len != 0)"
445 variant (mobile_allocation) "PRESENCE(freq_par_len != 0)"
446*/
447 };
Vadim Yanitskiy7091e8d2019-09-09 01:07:37 +0200448 type record SecondPartAssign {
449 BIT1 r99, /* H / L */
450 BIT1 presence optional,
451 BIT5 ext_ra optional
Harald Welte9419c8a2017-07-30 04:07:05 +0200452 } with {
Vadim Yanitskiy7091e8d2019-09-09 01:07:37 +0200453 /* TODO: use 'CSN.1 L/H' attribute here */
454 variant (presence) "PRESENCE(r99 = '1'B)" /* H */
455 variant (ext_ra) "PRESENCE(presence = '1'B)"
456 };
457 type union PacketUlDlAssignUnion {
458 PacketUlAssign ul,
459 PacketDlAssign dl
460 };
461 type record PacketUlDlAssign {
462 BIT1 ass_disc,
463 PacketUlDlAssignUnion ass
464 } with {
465 variant (ass) "CROSSTAG(dl, ass_disc = '1'B; ul, ass_disc = '0'B)"
466 };
467 type union PacketAssignUnion {
468 SecondPartAssign spa,
469 PacketUlDlAssign uldl
470 };
471 type record IaRestOctHH {
472 /* Packet Assignment discriminator:
473 * Packet Uplink / Downlink Assignment (0)
474 * Second Part Packet Assignment (1) */
475 BIT1 pa_disc,
476 PacketAssignUnion pa
477 } with {
478 variant (pa) "CROSSTAG(spa, pa_disc = '1'B; uldl, pa_disc = '0'B)"
Harald Welte9419c8a2017-07-30 04:07:05 +0200479 };
480 type record PacketUlAssignDyn {
481 uint5_t tfi_assignment,
482 BIT1 polling,
483 BIT1 spare ('0'B),
484 uint3_t usf,
485 BIT1 usf_granularity,
486 BIT1 p0_present,
487 uint4_t p0 optional,
488 BIT1 pr_mode optional,
489 ChCodingCommand ch_coding_cmd,
490 BIT1 tlli_block_chan_coding,
491 BIT1 alpha_present,
492 uint4_t alpha optional,
493 uint5_t gamma,
494 BIT1 ta_index_present,
495 uint4_t ta_index optional,
496 BIT1 tbf_starting_time_present,
497 uint16_t tbf_starting_time optional
498 } with {
499 variant (p0) "PRESENCE(p0_present = '1'B)"
500 variant (pr_mode) "PRESENCE(p0_present = '1'B)"
501 variant (alpha) "PRESENCE(alpha_present = '1'B)"
502 variant (ta_index) "PRESENCE(ta_index_present = '1'B)"
503 variant (tbf_starting_time) "PRESENCE(tbf_starting_time_present = '1'B)"
504 };
505 type record PacketUlAssignSgl {
506 BIT1 alpha_present,
507 uint4_t alpha optional,
508 uint5_t gamma,
509 BIT2 padding ('01'B),
510 uint16_t tbf_starting_time
511 /* TODO: P0 / PR_MODE */
512 } with {
513 variant (alpha) "PRESENCE(alpha_present = '1'B)"
514 };
515 type record PacketUlAssign {
516 BIT1 presence,
517 PacketUlAssignDyn dynamic optional,
518 PacketUlAssignSgl single optional
519 /* TODO: Estended RA, PFI */
520 } with {
521 variant (dynamic) "PRESENCE(presence = '1'B)"
522 variant (single) "PRESENCE(presence = '0'B)"
523 };
524 type record PacketDlAssG1 {
525 uint5_t tfi_assignment,
526 BIT1 rlc_mode,
527 BIT1 alpha_present,
528 uint4_t alpha optional,
529 uint5_t gamma,
530 BIT1 polling,
531 BIT1 ta_valid
532 } with { variant "" };
533 type record PacketDlAssign {
534 GprsTlli tlli,
535 BIT1 group1_present,
536 PacketDlAssG1 group1 optional,
537 BIT1 ta_index_present,
538 uint4_t ta_index optional,
539 BIT1 tbf_starting_time_present,
540 uint16_t tbf_starting_time optional,
541 BIT1 p0_present,
542 uint4_t p0 optional,
543 BIT1 pr_mode optional
544 /* TODO: EGPRS window size, etc. */
545 } with {
546 variant (group1) "PRESENCE(group1_present = '1'B)"
547 variant (ta_index) "PRESENCE(ta_index_present = '1'B)"
548 variant (tbf_starting_time) "PRESENCE(tbf_starting_time_present = '1'B)"
549 variant (p0) "PRESENCE(p0_present = '1'B)"
550 variant (pr_mode) "PRESENCE(p0_present = '1'B)"
551 };
552 type record IaRestOctLL {
553 BIT1 compressed_irat_ho_info_ind
554 } with { variant "" };
555 type octetstring EgprsUlAss; /* TODO */
556 type octetstring MblkDlAss; /* TODO */
557 type record IaRestOctLH {
558 BIT2 presence,
559 EgprsUlAss egprs_ul optional,
560 MblkDlAss multiblock_dl_ass optional
561 } with {
562 variant (egprs_ul) "PRESENCE(presence = '00'B)"
563 variant (multiblock_dl_ass) "PRESENCE(presence = '01'B)"
564 };
565 type record IaRestOctets {
566 BIT2 presence,
567 IaRestOctLL ll optional,
568 IaRestOctLH lh optional,
569 IaRestOctHL hl optional,
Vadim Yanitskiy9b2a3e82019-09-08 15:37:15 +0200570 IaRestOctHH hh optional
Harald Welte9419c8a2017-07-30 04:07:05 +0200571 } with {
572 variant (ll) "PRESENCE(presence = '00'B)"
573 variant (lh) "PRESENCE(presence = '01'B)"
574 variant (hl) "PRESENCE(presence = '10'B)"
575 variant (hh) "PRESENCE(presence = '11'B)"
Vadim Yanitskiy9b2a3e82019-09-08 15:37:15 +0200576 variant "PADDING(yes), PADDING_PATTERN('00101011'B)"
Harald Welte9419c8a2017-07-30 04:07:05 +0200577 };
578
Harald Weltecbc947f2018-02-22 00:26:55 +0100579 type record MeasurementResults {
580 BIT1 ba_used,
581 BIT1 dtx_used,
582 uint6_t rxlev_full_srv_cell,
583 BIT1 threeg_ba_used,
584 BIT1 meas_valid,
585 uint6_t rxlev_sub_srv_cell,
586 BIT1 si23_ba_used,
587 uint3_t rxqual_full_srv_cell,
588 uint3_t rxqual_sub_srv_cell,
589 uint3_t no_ncell_m,
590 NcellReports ncell_reports optional
591 } with { variant (no_ncell_m) "LENGTHTO(ncell_reports)"
592 variant (no_ncell_m) "UNIT(elements)"
593 variant "PADDING(yes)"
594 variant "FIELDLENGTH(16)"
595 };
596
597 type record NcellReport {
598 uint6_t rxlev,
599 uint5_t bcch_freq,
600 uint6_t bsic
601 } with { variant ""};
602 type record of NcellReport NcellReports;
603
Harald Welte9419c8a2017-07-30 04:07:05 +0200604
605 /* 9.1.18 */
606 type record ImmediateAssignment {
607 DedicatedModeOrTbf ded_or_tbf,
608 PageMode page_mode,
609 ChannelDescription chan_desc optional,
610 PacketChannelDescription pkt_chan_desc optional,
611 RequestReference req_ref,
612 TimingAdvance timing_advance,
613 MobileAllocation mobile_allocation,
614 /* TODO: starting time TLV */
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200615 IaRestOctets rest_octets
Harald Welte9419c8a2017-07-30 04:07:05 +0200616 } with { variant (chan_desc) "PRESENCE(ded_or_tbf.tbf = false)"
Vadim Yanitskiya4aacc22019-09-09 04:41:12 +0200617 variant (pkt_chan_desc) "PRESENCE(ded_or_tbf.tbf = true)" };
Harald Welte9419c8a2017-07-30 04:07:05 +0200618
619 /* 9.1.20 */
620 type record ReqRefWaitInd {
621 RequestReference req_ref,
622 WaitIndication wait_ind
623 } with { variant "" };
624 type record length(4) of ReqRefWaitInd ReqRefWaitInd4;
625 type record ImmediateAssignmentReject {
626 FeatureIndicator feature_ind,
627 PageMode page_mode,
628 ReqRefWaitInd4 payload
629 } with { variant "" };
630
Harald Weltecbc947f2018-02-22 00:26:55 +0100631 /* 9.1.21 */
632 type record MeasurementReport {
633 MeasurementResults meas_res
634 } with { variant "" };
635
Harald Welte9419c8a2017-07-30 04:07:05 +0200636 /* 9.1.22 */
637 type record PagingRequestType1 {
638 ChannelNeeded12 chan_needed,
639 PageMode page_mode,
640 MobileIdentityLV mi1,
641 MobileIdentityTLV mi2 optional,
642 RestOctets rest_octets
643 } with { variant "TAG(mi2, tag = 23)" };
644
645 /* 9.1.23 */
646 type record PagingRequestType2 {
647 ChannelNeeded12 chan_needed,
648 PageMode page_mode,
649 GsmTmsi mi1,
650 GsmTmsi mi2,
651 MobileIdentityTLV mi3 optional,
652 RestOctets rest_octets
653 } with { variant "TAG(mi3, tag = 23)" };
654
655 /* 9.1.24 */
656 type record length(4) of GsmTmsi GsmTmsi4;
657 type record PagingRequestType3 {
658 ChannelNeeded12 chan_needed,
659 PageMode page_mode,
660 GsmTmsi4 mi,
661 RestOctets rest_octets
662 } with { variant "" };
663
Harald Welte9419c8a2017-07-30 04:07:05 +0200664 type union RrUnion {
665/*
666 SystemInformationType1 si1,
667 SystemInformationType2 si2,
668 SystemInformationType2bis si2bis,
669 SystemInformationType2ter si2ter,
Harald Welte82ccef72018-02-25 16:17:33 +0100670 SystemInformationType3 si3,
Harald Welte9419c8a2017-07-30 04:07:05 +0200671 SystemInformationType4 si4,
672 SystemInformationType5 si5,
673 SystemInformationType5bis si5bis,
674 SystemInformationType5ter si5ter,
675 SystemInformationType6 si6,
676*/
677 ImmediateAssignment imm_ass,
678 ImmediateAssignmentReject imm_ass_rej,
679 PagingRequestType1 pag_req_1,
680 PagingRequestType2 pag_req_2,
681 PagingRequestType3 pag_req_3,
682 octetstring other
683 } with { variant "" };
684
685 /* Special RR Message on BCCH / CCCH Dowlink */
686
687 type record GsmRrMessage {
688 RrHeader header,
689 RrUnion payload
690 } with { variant (payload) "CROSSTAG(
691/*
692 si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
693 si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
694 si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
695 si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
696 si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
697 si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
698 si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
699 si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
700 si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
701 si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
702*/
703 imm_ass, header.message_type = IMMEDIATE_ASSIGNMENT;
704 imm_ass_rej, header.message_type = IMMEDIATE_ASSIGNMENT_REJECT;
705 pag_req_1, header.message_type = PAGING_REQUEST_TYPE_1;
706 pag_req_2, header.message_type = PAGING_REQUEST_TYPE_2;
707 pag_req_3, header.message_type = PAGING_REQUEST_TYPE_3;
708 other, OTHERWISE;
Vadim Yanitskiya4aacc22019-09-09 04:41:12 +0200709 )"
710 /* Total message length: 184 = 23 * 8. Pad spare bits with '2B'O. */
711 variant "PADDING(184), PADDING_PATTERN('00101011'B)"
712 };
Harald Welte9419c8a2017-07-30 04:07:05 +0200713
714 external function enc_GsmRrMessage(in GsmRrMessage msg) return octetstring
715 with { extension "prototype(convert) encode(RAW)" };
716 external function dec_GsmRrMessage(in octetstring stream) return GsmRrMessage
717 with { extension "prototype(convert) decode(RAW)" };
718
719 /* Normal L3 Message on Dedicated Channel */
720
721 /* 9.1.25 Paging Response */
722 type record PagingResponse {
723 uint4_t spare_half_octet,
724 CipheringKeySeqNr cksn,
725 MsClassmark2LV cm2,
726 MobileIdentityLV mi,
727 uint8_t addl_upd_par optional
728 } with { variant "" };
729
730 type union RrL3Union {
731 PagingResponse paging_response,
Harald Weltecbc947f2018-02-22 00:26:55 +0100732 MeasurementReport meas_rep,
Harald Welte9419c8a2017-07-30 04:07:05 +0200733 octetstring other
734 };
735
736 type record GsmRrL3Message {
737 RrL3Header header,
738 RrL3Union payload
739 } with { variant (payload) "CROSSTAG(
740 paging_response, header.message_type = PAGING_RESPONSE;
Harald Weltecbc947f2018-02-22 00:26:55 +0100741 meas_rep, header.message_type = MEASUREMENT_REPORT;
Harald Welte9419c8a2017-07-30 04:07:05 +0200742 other, OTHERWISE;
743 )" }
744
Harald Weltecbc947f2018-02-22 00:26:55 +0100745 external function enc_GsmRrL3Message(in GsmRrL3Message msg) return octetstring
746 with { extension "prototype(convert) encode(RAW)" };
747 external function dec_GsmRrL3Message(in octetstring stream) return GsmRrL3Message
748 with { extension "prototype(convert) decode(RAW)" };
749
750
Vadim Yanitskiy7091e8d2019-09-09 01:07:37 +0200751 template PacketDlAssign tr_PacketDlAssign(template GprsTlli tlli) := {
752 tlli := tlli,
753 group1_present := ?,
754 group1 := *,
755 ta_index_present := ?,
756 ta_index := *,
757 tbf_starting_time_present := ?,
758 tbf_starting_time := *,
759 p0_present := ?,
760 p0 := *,
761 pr_mode := *
762 };
763
764 template IaRestOctets tr_IaRestOctets_DLAss(template PacketDlAssign dl_ass) := {
765 presence := '11'B, /* HH */
766 ll := omit, lh := omit, hl := omit,
767 hh := {
768 pa_disc := '0'B, /* Packet Assignment (0) */
769 pa := {
770 uldl := {
771 ass_disc := '1'B, /* Downlink Assignment (1) */
772 ass := { dl := dl_ass }
773 }
774 }
775 }
776 };
777
778 template PacketUlAssign tr_PacketUlDynAssign(template uint5_t tfi := ?,
779 template BIT1 polling := ?,
780 template uint3_t usf := ?,
781 template BIT1 usf_granularity := ?,
782 template ChCodingCommand cs := ?) := {
783 presence := '1'B, /* Dynamic Assignment */
784 dynamic := {
785 tfi_assignment := tfi,
786 polling := polling,
787 spare := '0'B, /* Dynamic Assignment (mandatory after Rel-4) */
788 usf := usf,
789 usf_granularity := usf_granularity,
790 p0_present := ?,
791 p0 := *,
792 pr_mode := *,
793 ch_coding_cmd := cs,
794 tlli_block_chan_coding := ?,
795 alpha_present := ?,
796 alpha := *,
797 gamma := ?,
798 /* TODO: add to parameters */
799 ta_index_present := ?,
800 ta_index := *,
801 tbf_starting_time_present := ?,
802 tbf_starting_time := *
803 },
804 single := omit
805 };
806
807 template PacketUlAssign tr_PacketUlSglAssign := {
808 presence := '1'B, /* Single Block Assignment */
809 dynamic := omit,
810 single := {
811 alpha_present := ?,
812 alpha := *,
813 gamma := ?,
814 padding := '01'B,
815 tbf_starting_time := ?
816 }
817 };
818
819 template IaRestOctets tr_IaRestOctets_ULAss(template PacketUlAssign ul_ass) := {
820 presence := '11'B, /* HH */
821 ll := omit, lh := omit, hl := omit,
822 hh := {
823 pa_disc := '0'B, /* Packet Assignment (0) */
824 pa := {
825 uldl := {
826 ass_disc := '0'B, /* Uplink Assignment (0) */
827 ass := { ul := ul_ass }
828 }
829 }
830 }
831 };
832
Harald Weltee8d750e2018-06-10 21:41:35 +0200833 template (value) GsmRrMessage ts_IMM_ASS(uint8_t ra, GsmFrameNumber fn, TimingAdvance ta,
Harald Weltecbc947f2018-02-22 00:26:55 +0100834 ChannelDescription ch_desc, MobileAllocation ma) := {
835 header := t_RrHeader(IMMEDIATE_ASSIGNMENT, 0),
836 payload := {
837 imm_ass := {
838 ded_or_tbf := {
839 spare := '0'B,
840 tma := false,
841 downlink := false,
842 tbf := false
843 },
844 page_mode := PAGE_MODE_NORMAL,
845 chan_desc := ch_desc,
846 pkt_chan_desc := omit,
847 req_ref := f_compute_ReqRef(ra, fn),
848 timing_advance := ta,
849 mobile_allocation := ma,
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200850 rest_octets := {
851 presence := '00'B, /* LL */
852 ll := {
853 /* Compressed INTER RAT HO INFO: shall not be used (L)
854 * TODO: use variant "CSN.1 L/H" to avoid confusion. */
855 compressed_irat_ho_info_ind := '1'B
Vadim Yanitskiy9b2a3e82019-09-08 15:37:15 +0200856 },
857 lh := omit, hl := omit, hh := omit
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200858 }
Harald Weltecbc947f2018-02-22 00:26:55 +0100859 }
860 }
861 };
862
Harald Weltee8d750e2018-06-10 21:41:35 +0200863 template GsmRrMessage tr_IMM_ASS(template uint8_t ra := ?, template GsmFrameNumber fn := ?,
864 template TimingAdvance ta := ?,
865 template ChannelDescription ch_desc := ?,
866 template MobileAllocation ma := ?) := {
Vadim Yanitskiyd4205c32019-09-09 16:15:37 +0200867 header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
Harald Weltee8d750e2018-06-10 21:41:35 +0200868 payload := {
869 imm_ass := {
870 ded_or_tbf := {
871 spare := '0'B,
872 tma := false,
873 downlink := false,
874 tbf := false
875 },
876 page_mode := PAGE_MODE_NORMAL,
877 chan_desc := ch_desc,
878 pkt_chan_desc := omit,
879 req_ref := tr_compute_ReqRef(ra, fn),
880 timing_advance := ta,
881 mobile_allocation := ma,
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200882 rest_octets := ?
Harald Weltee8d750e2018-06-10 21:41:35 +0200883 }
884 }
885 };
886
Vadim Yanitskiy6edd4f52019-09-09 01:51:09 +0200887 /* TODO: implement send version of this template */
888 template GsmRrMessage tr_IMM_TBF_ASS(template boolean dl := ?,
889 template uint8_t ra := ?,
890 template GsmFrameNumber fn := ?,
891 template TimingAdvance ta := ?,
892 template PacketChannelDescription ch_desc := ?,
893 template IaRestOctets rest := ?) := {
894 header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
895 payload := {
896 imm_ass := {
897 ded_or_tbf := {
898 spare := ?,
899 tma := ?,
900 downlink := dl,
901 tbf := true
902 },
903 page_mode := ?,
904 chan_desc := omit,
905 pkt_chan_desc := ch_desc,
906 req_ref := tr_compute_ReqRef(ra, fn),
907 timing_advance := ta,
908 mobile_allocation := ?,
909 rest_octets := rest
910 }
911 }
912 };
Harald Weltee8d750e2018-06-10 21:41:35 +0200913
Harald Weltecbc947f2018-02-22 00:26:55 +0100914 template (value) GsmRrL3Message ts_MEAS_REP(boolean valid, uint6_t rxl_f, uint6_t rxl_s,
915 uint3_t rxq_f, uint3_t rxq_s,
916 template (omit) NcellReports reps) := {
917 header := t_RrL3Header(MEASUREMENT_REPORT),
918 payload := {
919 meas_rep := {
920 meas_res := {
921 ba_used := '0'B,
922 dtx_used := '0'B,
923 rxlev_full_srv_cell := rxl_f,
924 threeg_ba_used := '0'B,
Harald Welteeb1e6812018-02-22 18:43:48 +0100925 meas_valid := bool2bit(not valid),
Harald Weltecbc947f2018-02-22 00:26:55 +0100926 rxlev_sub_srv_cell := rxl_s,
927 si23_ba_used := '0'B,
928 rxqual_full_srv_cell := rxq_f,
929 rxqual_sub_srv_cell := rxq_s,
930 no_ncell_m := 0,
931 ncell_reports := reps
932 }
933 }
934 }
935 };
936
Harald Welte9419c8a2017-07-30 04:07:05 +0200937} with { encode "RAW" ; variant "FIELDORDER(msb)" }