summaryrefslogtreecommitdiffstats
path: root/library/GSM_RR_Types.ttcn
blob: b7e02ec4a1f019526fb105c5554e9a18c85306ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
/* Encoding/Decoding routines for GSM System Information messages
 * according to 3GPP TS 44.018 Version 12.3.0 Release 12
 *
 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

module GSM_RR_Types {

	import from General_Types all;
	import from Osmocom_Types all;
	import from GSM_Types all;
	import from RLCMAC_CSN1_Types all;
	import from MobileL3_CommonIE_Types all;
	import from MobileL3_RRM_Types all;

	/* Table 10.4.1 of Section 10.4 / 3GPP TS 44.018 */
	type enumerated RrMessageType {
		ADDITIONAL_ASSIGNMENT		('00111011'B),
		IMMEDIATE_ASSIGNMENT		('00111111'B),
		IMMEDIATE_ASSIGNMENT_EXTENDED	('00111001'B),
		IMMEDIATE_ASSIGNMENT_REJECT	('00111010'B),
		IMMEDIATE_PACKET_ASSIGNMENT	('01101001'B),

		CIPHERING_MODE_COMMAND		('00110101'B),
		CIPHERING_MODE_COMPLETE		('00110010'B),

		CONFIGURATION_CHANGE_COMMAND	('00110000'B),
		CONFIGURATION_CHANGE_ACK	('00110001'B),
		CONFIGURATION_CHANGE_REJECT	('00110011'B),

		ASSIGNMENT_COMMAND		('00101110'B),
		ASSIGNMENT_COMPLETE		('00101001'B),
		ASSIGNMENT_FAILURE		('00101111'B),
		HANDOVER_COMMAND		('00101011'B),
		HANDOVER_COMPLETE		('00101100'B),
		HANDOVER_FAILURE		('00101000'B),
		PHYSICAL_INFORMATION		('00101101'B),

		CHANNEL_RELEASE			('00001101'B),
		PARTIAL_RELEASE			('00001010'B),
		PARTIAL_RELEASE_COMPLETE	('00001111'B),

		PAGING_REQUEST_TYPE_1		('00100001'B),
		PAGING_REQUEST_TYPE_2		('00100010'B),
		PAGING_REQUEST_TYPE_3		('00100100'B),
		PAGING_RESPONSE			('00100111'B),
		NOTIFICATION_NCH		('00100000'B),
		NOTIFICATION_RESPOSNE		('00100110'B),

		SYSTEM_INFORMATION_TYPE_8	('00011000'B),
		SYSTEM_INFORMATION_TYPE_1	('00011001'B),
		SYSTEM_INFORMATION_TYPE_2	('00011010'B),
		SYSTEM_INFORMATION_TYPE_3	('00011011'B),
		SYSTEM_INFORMATION_TYPE_4	('00011100'B),
		SYSTEM_INFORMATION_TYPE_5	('00011101'B),
		SYSTEM_INFORMATION_TYPE_6	('00011110'B),
		SYSTEM_INFORMATION_TYPE_7	('00011111'B),
		SYSTEM_INFORMATION_TYPE_2bis	('00000010'B),
		SYSTEM_INFORMATION_TYPE_2ter	('00000011'B),
		SYSTEM_INFORMATION_TYPE_2quater	('00000111'B),
		SYSTEM_INFORMATION_TYPE_5bis	('00000101'B),
		SYSTEM_INFORMATION_TYPE_5ter	('00000110'B),
		SYSTEM_INFORMATION_TYPE_9	('00000100'B),
		SYSTEM_INFORMATION_TYPE_13	('00000000'B),

		SYSTEM_INFORMATION_TYPE_16	('00111101'B),
		SYSTEM_INFORMATION_TYPE_17	('00111110'B),

		CHANNEL_MODE_MODIFY		('00010000'B),
		RR_STATUS			('00010010'B),
		CHANNEL_MODE_MODIFY_ACKNOWLEDGE	('00010111'B),
		FREQUENCY_REDEFINITION		('00010100'B),
		MEASUREMENT_REPORT		('00010101'B),
		CLASSMARK_CHANGE		('00010110'B),
		CLASSMARK_ENQUIRY		('00010011'B),
		EXTENDED_MEASUREMENT_REPORT	('00110110'B),
		EXTENDED_MEASUREMENT_ORDER	('00110111'B),
		GPRS_SUSPENSION_REQUEST		('00110100'B),
		//MBMS_ANNOUNCEMENT		('00010110'B), duplicate?
		//SERVICE_INFORMATION		('00110110'B), duplicate?

		APPLICATION_INFORMATION		('00111000'B),

		SYSTEM_INFORMATION_TYPE_14	('00000001'B),
		SYSTEM_INFORMATION_TYPE_15	('01000011'B),
		SYSTEM_INFORMATION_TYPE_18	('01000000'B),
		SYSTEM_INFORMATION_TYPE_19	('01000001'B),
		SYSTEM_INFORMATION_TYPE_20	('01000010'B),
		SYSTEM_INFORMATION_TYPE_13alt	('01000100'B),
		SYSTEM_INFORMATION_TYPE_2n	('01000101'B),
		SYSTEM_INFORMATION_TYPE_21	('01000110'B),
		SYSTEM_INFORMATION_TYPE_22	('01000111'B),
		SYSTEM_INFORMATION_TYPE_23	('01001111'B),

		DTM_ASSIGNMENT_FAILURE		('01001000'B),
		DTM_REJECT			('01001001'B),
		DTM_REQUEST			('01001010'B),
		PACKET_ASSIGNMENT		('01001011'B),
		DTM_ASSIGNMENT_COMMAND		('01001100'B),
		DTM_INFORMATION			('01001101'B),
		PACKET_INFORMATION		('01001110'B),

		UTRAN_CLASSMARK_CHANGE		('01100000'B),
		CDMA2000_CLASSMARK_CHANGE	('01100010'B),
		INTERSYS_TO_UTRAN_HO_CMD	('01100011'B),
		INTERSYS_TO_CDMA2000_HO_CMD	('01100100'B),
		GERAN_IU_MODE_CLASSMARK_CHG	('01100101'B),
		INTERSYS_TO_EUTRAN_HO_CMD	('01100110'B)
	} with { variant "FIELDLENGTH(8)" };

	type enumerated RR_Cause {
		GSM48_RR_CAUSE_NORMAL		('00'O),
		GSM48_RR_CAUSE_ABNORMAL_UNSPEC	('01'O),
		GSM48_RR_CAUSE_ABNORMAL_UNACCT	('02'O),
		GSM48_RR_CAUSE_ABNORMAL_TIMER	('03'O),
		GSM48_RR_CAUSE_ABNORMAL_NOACT	('04'O),
		GSM48_RR_CAUSE_PREMPTIVE_REL	('05'O),
		GSM48_RR_CAUSE_HNDOVER_IMP	('08'O),
		GSM48_RR_CAUSE_CHAN_MODE_UNACCT	('09'O),
		GSM48_RR_CAUSE_FREQ_NOT_IMPL	('0a'O),
		GSM48_RR_CAUSE_CALL_CLEARED	('41'O),
		GSM48_RR_CAUSE_SEMANT_INCORR	('5f'O),
		GSM48_RR_CAUSE_INVALID_MAND_INF ('60'O),
		GSM48_RR_CAUSE_MSG_TYPE_N	('61'O),
		GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT('62'O),
		GSM48_RR_CAUSE_COND_IE_ERROR	('64'O),
		GSM48_RR_CAUSE_NO_CELL_ALLOC_A	('65'O),
		GSM48_RR_CAUSE_PROT_ERROR_UNSPC ('6f'O)
	} with { variant "FIELDLENGTH(8)" };

	type octetstring RestOctets  with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };

	type record L2PseudoLength {
		uint6_t		l2_plen,
		BIT2		zero_one
	} with { variant "" };

	template L2PseudoLength tr_L2Pseudolength(template uint6_t len) := {
		l2_plen := len,
		zero_one := '01'B
	};

	template (value) L2PseudoLength ts_L2Pseudolength(uint6_t len) := {
		l2_plen := len,
		zero_one := '01'B
	};

	type record RrHeader {
		L2PseudoLength	l2_plen,
		uint4_t		skip_indicator,
		uint4_t		rr_protocol_discriminator,
		RrMessageType	message_type
	} with { variant "" };

	template RrHeader t_RrHeader(RrMessageType msg_type, template uint6_t len) := {
		l2_plen := tr_L2Pseudolength(len),
		skip_indicator := 0,
		rr_protocol_discriminator := 6,
		message_type := msg_type
	};

	template (value) RrHeader ts_RrHeader(RrMessageType msg_type, uint6_t len) := {
		l2_plen := ts_L2Pseudolength(len),
		skip_indicator := 0,
		rr_protocol_discriminator := 6,
		message_type := msg_type
	};


	type record RrL3Header {
		uint4_t		skip_indicator,
		uint4_t		rr_protocol_discriminator,
		RrMessageType	message_type
	} with { variant "" };

	template RrL3Header t_RrL3Header(RrMessageType msg_type) := {
		skip_indicator := 0,
		rr_protocol_discriminator := 6,
		message_type := msg_type
	}

	/* TS 44.004 7.2.1 */
	type record SacchL1Header {
		uint2_t		reserved,
		boolean		fpc,
		uint5_t		ms_power_lvl,
		uint8_t		actual_ta
	} with { variant "FIELDORDER(msb)" };

	template (value) SacchL1Header ts_SacchL1Header(uint5_t ms_power_lvl, boolean fpc, uint8_t actual_ta) := {
		reserved := 0,
		fpc := fpc,
		ms_power_lvl := ms_power_lvl,
		actual_ta := actual_ta
	};

	type record MaioHsn {
		uint6_t		maio,
		uint6_t		hsn
	} with { variant "" };

	/* It's more handy to pass HSN first, so the arguments' order is reversed. */
	template (value) MaioHsn ts_HsnMaio(template (value) uint6_t hsn,
					    template (value) uint6_t maio) := {
		maio := maio,
		hsn := hsn
	};
	template MaioHsn tr_HsnMaio(template (present) uint6_t hsn,
				    template (present) uint6_t maio) := {
		maio := maio,
		hsn := hsn
	};

	/* TS 24.008 10.5.1.2 */
	type uint4_t CipheringKeySeqNr (0..7);

	/* TS 24.008 10.5.1.4 */
	type enumerated MobileIdentityType {
		MI_TYPE_NONE	(0),
		MI_TYPE_IMSI,
		MI_TYPE_IMEI,
		MI_TYPE_IMEISV,
		MI_TYPE_TMSI,
		MI_TYPE_TMGI
	} with { variant "FIELDLENGTH(3)" };

	/* TS 24.008 10.5.1.5 */
	type record MsClassmark1 {
		BIT1		spare,
		uint2_t		rev_level,
		boolean		es_ind,
		boolean		a51,
		uint3_t		rf_pwr_cap
	} with { variant "" };

	/* TS 24.008 10.5.1.6 */
	type record MsClassmark2 {
		BIT1		spare,
		uint2_t		rev_level,
		boolean		es_ind,
		boolean		a51,
		uint3_t		rf_pwr_cap,
		BIT1		spare1,
		boolean		ps_cap,
		uint2_t		ss_screen_ind,
		boolean		sm_cap,
		boolean		vbs,
		boolean		vgcs,
		boolean		fc,
		boolean		cm3,
		BIT1		spare2,
		boolean		lcsva_cap,
		boolean		ucs2,
		boolean		solsa,
		boolean		cmsp,
		boolean		a53,
		boolean		a52
	} with { variant "" };
	type record MsClassmark2LV {
		uint8_t		len,
		MsClassmark2	cm2
	} with { variant (len) "LENGTHTO(cm2)" };


	/* 44.018 10.5.2.5 */
	type record ChannelDescription {
		RslChannelNr	chan_nr,
		uint3_t		tsc,
		boolean		h,
		uint12_t	arfcn optional,
		MaioHsn		maio_hsn optional
	} with { variant (arfcn) "PRESENCE(h = false)"
		 variant (maio_hsn) "PRESENCE(h = true)" };

	type record ChannelDescriptionTV {
		OCT1		iei,
		ChannelDescription v
	} with { variant "" };

	/* 10.5.2.21 */
	type record MobileAllocationLV {
		uint8_t 	len,
		bitstring	ma length (0..64)
	} with {
		variant (len) "LENGTHTO(ma)"
		variant (ma) "BYTEORDER(first), BITORDER(msb)"
	};

	type record MobileAllocationTLV {
		OCT1			iei ('72'O),
		MobileAllocationLV	v
	} with { variant "" };

	/* 10.5.2.25a */
	type record PktChDesc0Ind {
		uint6_t		maio,
		BIT1		ma_number_ind,
		BIT1		change_mark1_valid,
		BIT2		change_mark1
	} with { variant "" };
	type record PktChDesc0 {
		BIT1		hopping,
		BIT1		spare ('0'B),
		uint10_t	arfcn optional,
		PktChDesc0Ind	indirect optional
	} with {
		variant (arfcn) "PRESENCE(hopping = '0'B)"
		variant (indirect) "PRESENCE(hopping = '1'B)"
	};
	type record PktChDesc1 {
		uint6_t		maio,
		uint6_t		hsn
	} with { variant "" };
	type record PacketChannelDescription {
		uint5_t		channel_Type_spare,
		uint3_t		tn,
		uint3_t		tsc,
		BIT1		presence,
		PktChDesc0	zero optional,
		PktChDesc1	one optional
	} with {
		variant (zero)	"PRESENCE(presence = '0'B)"
		variant (one)	"PRESENCE(presence = '1'B)"
	};

	/* 10.5.2.25b */
	type record DedicatedModeOrTbf {
		BIT1	spare,
		boolean	tma,
		boolean	downlink,
		boolean tbf
	} with { variant "" };

	/* 10.5.2.26 */
	type enumerated PageMode {
		PAGE_MODE_NORMAL,
		PAGE_MODE_EXTENDED,
		PAGE_MODE_REORGANIZATION,
		PAGE_MODE_SAME_AS_BEFORE
	} with { variant "FIELDLENGTH(4)" };

	/* 10.5.2.30 */
	type record RequestReference {
		bitstring	ra length(8),
		uint5_t 	t1p,
		uint6_t 	t3,
		uint5_t		t2
	} with { variant "" };

	template RequestReference t_RequestReference(template bitstring ra, template uint5_t t1p, template uint6_t t3, template uint5_t t2) := {
		ra := ra,
		t1p := t1p,
		t3 := t3,
		t2 := t2
	}

	/* compute the expected request reference for given RA + FN */
	function f_compute_ReqRef(uint8_t ra, GsmFrameNumber fn) return RequestReference {
		var RequestReference req_ref := { ra := int2bit(ra, 8) };
		req_ref.t1p := (fn / 1326) mod 32;
		req_ref.t2 := fn mod 26;
		req_ref.t3 := fn mod 51;
		return req_ref
	}
	function tr_compute_ReqRef(template uint8_t ra, template GsmFrameNumber fn)
	return template RequestReference {
		var template RequestReference req_ref;
		if (istemplatekind(ra, "?")) {
			req_ref.ra := ?;
		} else {
			req_ref.ra := int2bit(valueof(ra), 8);
		}
		if (istemplatekind(fn, "?")) {
			req_ref.t1p := ?;
			req_ref.t2 := ?;
			req_ref.t3 := ?;
		} else {
			var GsmFrameNumber fn_v := valueof(fn);
			req_ref.t1p := (fn_v / 1326) mod 32;
			req_ref.t2 := fn_v mod 26;
			req_ref.t3 := fn_v mod 51;
		}
		return req_ref;
	}

	/* 10.5.2.40 */
	type integer TimingAdvance (0..219);

	/* 10.5.2.43 */
	type uint8_t WaitIndication;

	/* 10.5.2.76 */
	type record FeatureIndicator {
		BIT2		peo_bcch_change_mark,
		boolean		cs_ir,
		boolean		ps_ir
	} with {
		variant (cs_ir) "FIELDLENGTH(1)"
		variant (ps_ir) "FIELDLENGTH(1)"
	};

	/* 24.008 10.5.5.6 */
	type record DrxParameter {
		uint8_t		split_pg_cycle_code,
		uint4_t		drx_cycle_len_coeff,
		boolean		split_on_ccch,
		uint3_t		non_drx_timer
	} with { variant "" };

	/* 44.018 10.5.2.16 */
	type record IaRestOctHL {
		uint6_t		freq_par_len,
		BIT2		padding ('00'B) optional,
		uint6_t		maio optional,
		octetstring	mobile_allocation optional
	} with {
		variant (freq_par_len)	"LENGTHTO(mobile_allocation,maio,padding)"
/*
		variant (padding)	"PRESENCE(freq_par_len != 0)"
		variant (maio)		"PRESENCE(freq_par_len != 0)"
		variant (mobile_allocation) "PRESENCE(freq_par_len != 0)"
*/
	};
	type record SecondPartAssign {
		BIT1		r99, /* L / H */
		BIT1		presence optional,
		BIT5		ext_ra optional
	} with {
		variant (r99) "CSN.1 L/H"
		variant (presence) "PRESENCE(r99 = '1'B)" /* H */
		variant (ext_ra) "PRESENCE(presence = '1'B)"
		/* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=562488 */
		variant (ext_ra) "BYTEORDER(last)" // FIXME: should be first
	};
	type union PacketUlDlAssignUnion {
		PacketUlAssign		ul,
		PacketDlAssign		dl
	};
	type record PacketUlDlAssign {
		BIT1			ass_disc,
		PacketUlDlAssignUnion	ass
	} with {
		variant (ass) "CROSSTAG(dl, ass_disc = '1'B; ul, ass_disc = '0'B)"
	};
	type union PacketAssignUnion {
		SecondPartAssign	spa,
		PacketUlDlAssign	uldl
	};
	type record IaRestOctHH {
		/* Packet Assignment discriminator:
		 * Packet Uplink / Downlink Assignment (0)
		 * Second Part Packet Assignment (1) */
		BIT1			pa_disc,
		PacketAssignUnion	pa
	} with {
		variant (pa) "CROSSTAG(spa, pa_disc = '1'B; uldl, pa_disc = '0'B)"
	};
	type record PacketUlAssignDyn {
		uint5_t		tfi_assignment,
		BIT1		polling,
		BIT1		spare ('0'B),
		uint3_t		usf,
		BIT1		usf_granularity,
		BIT1		p0_present,
		uint4_t		p0 optional,
		BIT1		pr_mode optional,
		ChCodingCommand	ch_coding_cmd,
		BIT1		tlli_block_chan_coding,
		BIT1		alpha_present,
		uint4_t		alpha optional,
		uint5_t		gamma,
		BIT1		ta_index_present,
		uint4_t		ta_index optional,
		BIT1		tbf_starting_time_present,
		uint16_t	tbf_starting_time optional
	} with {
		variant (p0)		"PRESENCE(p0_present = '1'B)"
		variant (pr_mode)	"PRESENCE(p0_present = '1'B)"
		variant (alpha)		"PRESENCE(alpha_present = '1'B)"
		variant (ta_index)	"PRESENCE(ta_index_present = '1'B)"
		variant (tbf_starting_time)	"PRESENCE(tbf_starting_time_present = '1'B)"
	};
	type record PacketUlAssignSgl {
		BIT1		alpha_present,
		uint4_t		alpha optional,
		uint5_t		gamma,
		BIT2		padding ('01'B),
		uint16_t	tbf_starting_time
		/* TODO: P0 / PR_MODE */
	} with {
		variant (alpha)		"PRESENCE(alpha_present = '1'B)"
	};
	type record PacketUlAssign {
		BIT1			presence,
		PacketUlAssignDyn	dynamic optional,
		PacketUlAssignSgl	single optional
		/* TODO: Estended RA, PFI */
	} with {
		variant (dynamic)	"PRESENCE(presence = '1'B)"
		variant (single)	"PRESENCE(presence = '0'B)"
	};
	type record PacketDlAssG1 {
		uint5_t		tfi_assignment,
		BIT1		rlc_mode,
		BIT1		alpha_present,
		uint4_t		alpha optional,
		uint5_t		gamma,
		BIT1		polling,
		BIT1		ta_valid
	} with { variant "" };
	type record PacketDlAssign {
		GprsTlli	tlli,
		BIT1		group1_present,
		PacketDlAssG1	group1 optional,
		BIT1		ta_index_present,
		uint4_t		ta_index optional,
		BIT1		tbf_starting_time_present,
		uint16_t	tbf_starting_time optional,
		BIT1		p0_present,
		uint4_t		p0 optional,
		BIT1		pr_mode optional
		/* TODO: EGPRS window size, etc. */
	} with {
		variant (group1)	"PRESENCE(group1_present = '1'B)"
		variant (ta_index)	"PRESENCE(ta_index_present = '1'B)"
		variant (tbf_starting_time)	"PRESENCE(tbf_starting_time_present = '1'B)"
		variant (p0)		"PRESENCE(p0_present = '1'B)"
		variant (pr_mode)	"PRESENCE(p0_present = '1'B)"
	};
	type record IaRestOctLL {
		BIT1		compressed_irat_ho_info_ind
	} with {
		variant (compressed_irat_ho_info_ind) "CSN.1 L/H"
	};
	type record EgprsUlAssignDyn {
		uint5_t		tfi_assignment,
		BIT1		polling,
		BIT1		spare ('0'B),
		uint3_t		usf,
		BIT1		usf_granularity,
		BIT1		p0_present,
		uint4_t		p0 optional,
		BIT1		pr_mode optional,
		EgprsChCodingCommand	egprs_ch_coding_cmd,
		BIT1		tlli_block_chan_coding,
		BIT1		bep_period2_present,
		BIT4		bep_period2 optional,
		BIT1		resegment,
		EgprsWindowSize	egprs_window_size,
		BIT1		alpha_present,
		uint4_t		alpha optional,
		uint5_t		gamma,
		BIT1		ta_index_present,
		uint4_t		ta_index optional,
		BIT1		tbf_starting_time_present,
		uint16_t	tbf_starting_time optional
		/* TODO: Additions for Rel-7 */
	} with {
		variant (p0)		"PRESENCE(p0_present = '1'B)"
		variant (pr_mode)	"PRESENCE(p0_present = '1'B)"
		variant (bep_period2)	"PRESENCE(bep_period2_present = '1'B)"
		variant (alpha)		"PRESENCE(alpha_present = '1'B)"
		variant (ta_index)	"PRESENCE(ta_index_present = '1'B)"
		variant (tbf_starting_time)	"PRESENCE(tbf_starting_time_present = '1'B)"
	};
	type record EgprsUlAssignMultiblock {
		BIT1		alpha_present,
		uint4_t		alpha optional,
		uint5_t		gamma,
		uint16_t	tbf_starting_time,
		BIT2		nr_radio_blocks_allocated,
		BIT1		p0_present,
		uint4_t		p0 optional,
		BIT1		spare ('0'B) optional,
		BIT1		pr_mode optional
		/* TDO: Additions for Rel-6 */
	} with {
		variant (alpha)		"PRESENCE(alpha_present = '1'B)"
		variant (p0)		"PRESENCE(p0_present = '1'B)"
		variant (spare)		"PRESENCE(p0_present = '1'B)"
		variant (pr_mode)	"PRESENCE(p0_present = '1'B)"
	};
	/* 3GPP TS 44.018 version 13.3.2 10.5.2.16, "EGPRS Packet Uplink Assignment" */
	type record EgprsUlAss {
		BIT5 ext_ra,
		BIT1 ats_present,
		AccessTechnologiesRequestRepetition ats optional,
		BIT1			presence,
		EgprsUlAssignDyn	dynamic optional,
		EgprsUlAssignMultiblock	multiblock optional
	} with {
		variant (ats)	"PRESENCE(ats_present = '1'B)"
		variant (dynamic)	"PRESENCE(presence = '1'B)"
		variant (multiblock)	"PRESENCE(presence = '0'B)"
		/* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=562488 */
		variant (ext_ra) "BYTEORDER(last)" // FIXME: should be first
	};

	type octetstring MblkDlAss;	/* TODO */
	type record IaRestOctLH {
		BIT2		presence,
		EgprsUlAss	egprs_ul optional,
		MblkDlAss	multiblock_dl_ass optional
	} with {
		variant (egprs_ul) "PRESENCE(presence = '00'B)"
		variant (multiblock_dl_ass) "PRESENCE(presence = '01'B)"
	};
	type record IaRestOctets {
		BIT2		presence,
		IaRestOctLL	ll optional,
		IaRestOctLH	lh optional,
		IaRestOctHL	hl optional,
		IaRestOctHH	hh optional
	} with {
		variant (presence) "CSN.1 L/H"
		variant (ll) "PRESENCE(presence = '00'B)"
		variant (lh) "PRESENCE(presence = '01'B)"
		variant (hl) "PRESENCE(presence = '10'B)"
		variant (hh) "PRESENCE(presence = '11'B)"
		variant "PADDING(yes), PADDING_PATTERN('00101011'B)"
	};

	type record MeasurementResults {
		BIT1		ba_used,
		BIT1		dtx_used,
		uint6_t		rxlev_full_srv_cell,
		BIT1		threeg_ba_used,
		BIT1		meas_valid,
		uint6_t		rxlev_sub_srv_cell,
		BIT1		si23_ba_used,
		uint3_t		rxqual_full_srv_cell,
		uint3_t		rxqual_sub_srv_cell,
		uint3_t		no_ncell_m,
		NcellReports	ncell_reports optional
	} with { variant (no_ncell_m) "LENGTHTO(ncell_reports)"
		 variant (no_ncell_m) "UNIT(elements)"
		 variant "PADDING(yes)"
		 variant "FIELDLENGTH(16)"
	};

	type record NcellReport {
		uint6_t		rxlev,
		uint5_t		bcch_freq,
		uint6_t		bsic
	} with { variant ""};
	type record of NcellReport NcellReports;


	/* 3GPP TS 44.018, section 9.1.2 (minimalistic implementation) */
	type record AssignmentCommand {
		ChannelDescription		chan_desc,
		PowerCommand_V			power_cmd,
		FrequencyList_TLV		freq_list_at optional,
		CellChannelDescription_TV	cell_chan_desc optional,
		/* TODO: Multislot Allocation IE */
		ChannelMode_TV			chan1_mode optional,
		ChannelMode_TV			chan2_mode optional,
		/* TODO: Mode of Channel Set 3..8 IE */
		MobileAllocationTLV		mobile_allocation optional
		/* TODO: more optional IEs... */
	} with {
		variant "TAG(
			freq_list_at,		elementIdentifier = '05'O;
			cell_chan_desc,		elementIdentifier = '62'O;
			chan1_mode,		elementIdentifier = '63'O;
			chan2_mode,		elementIdentifier = '11'O;
			mobile_allocation,	iei = '72'O;
		)"
	};

	/* 3GPP TS 44.018, section 9.1.15 (minimalistic implementation) */
	type record HandoverCommand {
		CellDescriptionV		cell_desc,
		ChannelDescription		chan_desc,
		OCT1				ho_ref,
		PowerCommandAndAccesstype_V	power_cmd_acc_type,
		FrequencyList_TLV		freq_list_at optional,
		CellChannelDescription_TV	cell_chan_desc optional,
		ChannelMode_TV			chan1_mode optional,
		ChannelMode_TV			chan2_mode optional,
		/* TODO: Mode of Channel Set 3..8 IE */
		MobileAllocationTLV		mobile_allocation optional
		/* TODO: more optional IEs... */
	} with {
		variant "TAG(
			freq_list_at,		elementIdentifier = '05'O;
			cell_chan_desc,		elementIdentifier = '62'O;
			chan1_mode,		elementIdentifier = '63'O;
			chan2_mode,		elementIdentifier = '11'O;
			mobile_allocation,	iei = '72'O;
		)"
	};

	/* 10.5.2.2 Cell Description IE */
	type record CellDescriptionV {
		uint3_t				bcc, /* PLMN colour code */
		uint3_t				ncc, /* BS colour code */
		uint10_t			bcch_arfcn
	} with { variant "FIELDORDER(lsb)" };


	/* 9.1.18 */
	type record ImmediateAssignment {
		DedicatedModeOrTbf		ded_or_tbf,
		PageMode			page_mode,
		ChannelDescription		chan_desc optional,
		PacketChannelDescription	pkt_chan_desc optional,
		RequestReference		req_ref,
		TimingAdvance			timing_advance,
		MobileAllocationLV		mobile_allocation,
		/* TODO: starting time TLV */
		IaRestOctets			rest_octets
	} with { variant (chan_desc) "PRESENCE(ded_or_tbf.tbf = false)"
		 variant (pkt_chan_desc) "PRESENCE(ded_or_tbf.tbf = true)" };

	/* 9.1.20 */
	type record ReqRefWaitInd {
		RequestReference		req_ref,
		WaitIndication			wait_ind
	} with { variant "" };
	type record length(4) of ReqRefWaitInd ReqRefWaitInd4;
	type record ImmediateAssignmentReject {
		FeatureIndicator		feature_ind,
		PageMode			page_mode,
		ReqRefWaitInd4			payload,
		IARRestOctets			rest_octets
	} with { variant "" };

	/* 10.5.2.17 IAR (Immediate Assignment Reject) Rest Octets */
	type record IARRestOctets {
		ExtRAList		ext_ra_list,
		BIT1			rel13_ind, // L/H
		uint3_t			rcc optional
		/* Addition in Rel-15: PEO IMM Cell Group Details struct */
	} with {
		variant (rel13_ind) "CSN.1 L/H"
		variant (rcc) "PRESENCE(rel13_ind = '1'B)"

		/* The TITAN's RAW encoder generates an octet-aligned octetstring,
		 * so we should make sure that unused bits contain proper padding. */
		variant "PADDING(yes), PADDING_PATTERN('00101011'B)"
	};

	/* Optional extended RA: 0 | 1 < Extended RA 1 : bit (5) > */
	type record ExtRAOpt {
		BIT1			presence, // L/H
		BIT5			ext_ra optional
	} with {
		variant (presence) "CSN.1 L/H"
		variant (ext_ra) "PRESENCE(presence = '1'B)"
		/* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=562488 */
		variant (ext_ra) "BYTEORDER(last)"
	};

	type record length(4) of ExtRAOpt ExtRAList;

	/* 9.1.21 */
	type record MeasurementReport {
		MeasurementResults		meas_res
	} with { variant "" };

	/* 9.1.22 */
	type record PagingRequestType1 {
		ChannelNeeded12			chan_needed,
		PageMode			page_mode,
		MobileIdentityLV		mi1,
		MobileIdentityTLV		mi2 optional,
		RestOctets			rest_octets
	} with { variant "TAG(mi2, elementIdentifier = '0010111'B)" };

	/* 9.1.23 */
	type record PagingRequestType2 {
		ChannelNeeded12			chan_needed,
		PageMode			page_mode,
		GsmTmsi				mi1,
		GsmTmsi				mi2,
		MobileIdentityTLV		mi3 optional,
		RestOctets			rest_octets
	} with { variant "TAG(mi3, elementIdentifier = '0010111'B)" };

	/* 9.1.24 */
	type record length(4) of GsmTmsi GsmTmsi4;
	type record PagingRequestType3 {
		ChannelNeeded12			chan_needed,
		PageMode			page_mode,
		GsmTmsi4			mi,
		RestOctets			rest_octets
	} with { variant "" };

	type union RrUnion {
/*
		SystemInformationType1		si1,
		SystemInformationType2		si2,
		SystemInformationType2bis	si2bis,
		SystemInformationType2ter	si2ter,
		SystemInformationType3		si3,
		SystemInformationType4		si4,
		SystemInformationType5		si5,
		SystemInformationType5bis	si5bis,
		SystemInformationType5ter	si5ter,
		SystemInformationType6		si6,
*/
		ImmediateAssignment		imm_ass,
		ImmediateAssignmentReject	imm_ass_rej,
		PagingRequestType1		pag_req_1,
		PagingRequestType2		pag_req_2,
		PagingRequestType3		pag_req_3,
		octetstring			other
	} with { variant "" };

	/* Special RR Message on BCCH / CCCH Dowlink */

	type record GsmRrMessage {
		RrHeader	header,
		RrUnion		payload
	} with { variant (payload) "CROSSTAG(
/*
			      si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
			      si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
			      si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
			      si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
			      si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
			      si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
			      si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
			      si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
			      si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
			      si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
*/
				imm_ass, header.message_type = IMMEDIATE_ASSIGNMENT;
				imm_ass_rej, header.message_type = IMMEDIATE_ASSIGNMENT_REJECT;
				pag_req_1, header.message_type = PAGING_REQUEST_TYPE_1;
				pag_req_2, header.message_type = PAGING_REQUEST_TYPE_2;
				pag_req_3, header.message_type = PAGING_REQUEST_TYPE_3;
			      other, OTHERWISE;
			)"
		 /* Total message length: 184 = 23 * 8. Pad spare bits with '2B'O. */
		 variant "PADDING(184), PADDING_PATTERN('00101011'B)"
	};

	external function enc_GsmRrMessage(in GsmRrMessage msg) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_GsmRrMessage(in octetstring stream) return GsmRrMessage
		with { extension "prototype(convert) decode(RAW)" };

	/* Normal L3 Message on Dedicated Channel */

	/* 9.1.25 Paging Response */
	type record PagingResponse {
		uint4_t			spare_half_octet,
		CipheringKeySeqNr	cksn,
		MsClassmark2LV		cm2,
		MobileIdentityLV	mi,
		uint8_t			addl_upd_par optional
	} with { variant "" };

	type union RrL3Union {
		PagingResponse		paging_response,
		MeasurementReport	meas_rep,
		AssignmentCommand	ass_cmd,
		HandoverCommand		ho_cmd,
		octetstring		other
	};

	type record GsmRrL3Message {
		RrL3Header	header,
		RrL3Union	payload
	} with { variant (payload) "CROSSTAG(
				paging_response, header.message_type = PAGING_RESPONSE;
				meas_rep, header.message_type = MEASUREMENT_REPORT;
				ass_cmd, header.message_type = ASSIGNMENT_COMMAND;
				ho_cmd, header.message_type = HANDOVER_COMMAND;
				other, OTHERWISE;
		)" }

	external function enc_GsmRrL3Message(in GsmRrL3Message msg) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_GsmRrL3Message(in octetstring stream) return GsmRrL3Message
		with { extension "prototype(convert) decode(RAW)" };


	template PacketDlAssign tr_PacketDlAssign(template GprsTlli tlli) := {
		tlli := tlli,
		group1_present := ?,
		group1 := *,
		ta_index_present := ?,
		ta_index := *,
		tbf_starting_time_present := ?,
		tbf_starting_time := *,
		p0_present := ?,
		p0 := *,
		pr_mode := *
	};

	template IaRestOctets tr_IaRestOctets_DLAss(template PacketDlAssign dl_ass) := {
		presence := '11'B, /* HH */
		ll := omit, lh := omit, hl := omit,
		hh := {
			pa_disc := '0'B, /* Packet Assignment (0) */
			pa := {
				uldl := {
					ass_disc := '1'B, /* Downlink Assignment (1) */
					ass := { dl := dl_ass }
				}
			}
		}
	};

	template PacketUlAssign tr_PacketUlDynAssign(template uint5_t tfi := ?,
						     template BIT1 polling := ?,
						     template uint3_t usf := ?,
						     template BIT1 usf_granularity := ?,
						     template ChCodingCommand cs := ?) := {
		presence := '1'B, /* Dynamic Block Allocation */
		dynamic := {
			tfi_assignment := tfi,
			polling := polling,
			spare := '0'B, /* Dynamic Block Allocation (mandatory after Rel-4) */
			usf := usf,
			usf_granularity := usf_granularity,
			p0_present := ?,
			p0 := *,
			pr_mode := *,
			ch_coding_cmd := cs,
			tlli_block_chan_coding := ?,
			alpha_present := ?,
			alpha := *,
			gamma := ?,
			/* TODO: add to parameters */
			ta_index_present := ?,
			ta_index := *,
			tbf_starting_time_present := ?,
			tbf_starting_time := *
		},
		single := omit
	};

	template PacketUlAssign tr_PacketUlSglAssign := {
		presence := '0'B, /* Single Block Allocation */
		dynamic := omit,
		single := {
			alpha_present := ?,
			alpha := *,
			gamma := ?,
			padding := '01'B,
			tbf_starting_time := ?
		}
	};

	template IaRestOctets tr_IaRestOctets_ULAss(template PacketUlAssign ul_ass) := {
		presence := '11'B, /* HH */
		ll := omit, lh := omit, hl := omit,
		hh := {
			pa_disc := '0'B, /* Packet Assignment (0) */
			pa := {
				uldl := {
					ass_disc := '0'B, /* Uplink Assignment (0) */
					ass := { ul := ul_ass }
				}
			}
		}
	};

	template EgprsUlAss tr_EgprsUlAssDynamic(template (present) BIT5 ext_ra := ?,
						 template EgprsUlAssignDyn dyn_ass := ?) := {
		ext_ra := ext_ra,
		ats_present := ?,
		ats := *,
		presence := '1'B,
		dynamic := dyn_ass,
		multiblock := omit
	};
	template EgprsUlAss tr_EgprsUlAssMultiblock(template (present) BIT5 ext_ra := ?,
						    template EgprsUlAssignMultiblock mb_ass := ?) := {
		ext_ra := ext_ra,
		ats_present := ?,
		ats := *,
		presence := '0'B,
		dynamic := omit,
		multiblock := mb_ass
	};

	template IaRestOctets tr_IaRestOctets_EGPRSULAss(template EgprsUlAss ul_ass) := {
		presence := '01'B, /* LH */
		ll := omit,
		lh := {
			presence := '00'B,
			egprs_ul := ul_ass,
			multiblock_dl_ass := omit
		},
		hl := omit,
		hh := omit
	};

	template (value) GsmRrMessage ts_IMM_ASS(uint8_t ra, GsmFrameNumber fn, TimingAdvance ta,
						ChannelDescription ch_desc, MobileAllocationLV ma) := {
		header := ts_RrHeader(IMMEDIATE_ASSIGNMENT, 0),
		payload := {
			imm_ass := {
				ded_or_tbf := {
					spare := '0'B,
					tma := false,
					downlink := false,
					tbf := false
				},
				page_mode := PAGE_MODE_NORMAL,
				chan_desc := ch_desc,
				pkt_chan_desc := omit,
				req_ref := f_compute_ReqRef(ra, fn),
				timing_advance := ta,
				mobile_allocation := ma,
				rest_octets := {
					presence := '00'B, /* LL */
					ll := {
						compressed_irat_ho_info_ind := '0'B /* L */
					},
					lh := omit, hl := omit, hh := omit
				}
			}
		}
	};

	template GsmRrMessage tr_IMM_ASS(template uint8_t ra := ?, template GsmFrameNumber fn := ?,
					 template TimingAdvance ta := ?,
					 template ChannelDescription ch_desc := ?,
					 template MobileAllocationLV ma := ?) := {
		header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
		payload := {
			imm_ass := {
				ded_or_tbf := {
					spare := '0'B,
					tma := false,
					downlink := false,
					tbf := false
				},
				page_mode := PAGE_MODE_NORMAL,
				chan_desc := ch_desc,
				pkt_chan_desc := omit,
				req_ref := tr_compute_ReqRef(ra, fn),
				timing_advance := ta,
				mobile_allocation := ma,
				rest_octets := ?
			}
		}
	};

	/* TODO: implement send version of this template */
	template GsmRrMessage tr_IMM_TBF_ASS(template boolean dl := ?,
					     template uint8_t ra := ?,
					     template GsmFrameNumber fn := ?,
					     template TimingAdvance ta := ?,
					     template PacketChannelDescription ch_desc := ?,
					     template MobileAllocationLV ma := ?,
					     template IaRestOctets rest := ?) := {
		header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
		payload := {
			imm_ass := {
				ded_or_tbf := {
					spare := ?,
					tma := ?,
					downlink := dl,
					tbf := true
				},
				page_mode := ?,
				chan_desc := omit,
				pkt_chan_desc := ch_desc,
				req_ref := tr_compute_ReqRef(ra, fn),
				timing_advance := ta,
				mobile_allocation := ma,
				rest_octets := rest
			}
		}
	};

	template GsmRrMessage tr_PAG_REQ1(template MobileIdentityLV mi1 := ?,
					  template MobileIdentityTLV mi2 := omit) := {
		header := t_RrHeader(PAGING_REQUEST_TYPE_1, ?),
		payload := {
			pag_req_1 := {
				chan_needed := {
					second := ?,
					first := ?
				},
				page_mode := PAGE_MODE_NORMAL,
				mi1 := mi1,
				mi2 := mi2,
				rest_octets := ?
			}
		}
	};

	template (value) GsmRrL3Message ts_MEAS_REP(boolean valid, uint6_t rxl_f, uint6_t rxl_s,
						  uint3_t rxq_f, uint3_t rxq_s,
						  template (omit) NcellReports reps) := {
		header := t_RrL3Header(MEASUREMENT_REPORT),
		payload := {
			meas_rep := {
				meas_res := {
					ba_used := '0'B,
					dtx_used := '0'B,
					rxlev_full_srv_cell := rxl_f,
					threeg_ba_used := '0'B,
					meas_valid := bool2bit(not valid),
					rxlev_sub_srv_cell := rxl_s,
					si23_ba_used := '0'B,
					rxqual_full_srv_cell := rxq_f,
					rxqual_sub_srv_cell := rxq_s,
					no_ncell_m := 0,
					ncell_reports := reps
				}
			}
		}
	};

	template GsmRrMessage tr_IMM_ASS_REJ(template FeatureIndicator feature_ind := ?,
					     template ReqRefWaitInd4 rr_wi_list := ?,
					     template IARRestOctets rest_octets := ?) := {
		header := t_RrHeader(IMMEDIATE_ASSIGNMENT_REJECT, ?),
		payload := {
			imm_ass_rej := {
				feature_ind := feature_ind,
				page_mode := ?,
				payload := rr_wi_list,
				rest_octets := rest_octets
			}
		}
	};

	template ReqRefWaitInd tr_ReqRefWaitInd(template RequestReference ref := ?,
						template WaitIndication wi := ?) := {
		req_ref := ref,
		wait_ind := wi
	};

	template IARRestOctets tr_IARRestOctets(template ExtRAList ext_ra_list := ?,
						template uint3_t rcc := ?) := {
		ext_ra_list := ext_ra_list,
		rel13_ind := ?,
		rcc := rcc ifpresent
	};

	template ExtRAOpt tr_ExtRAOpt(template BIT5 ext_ra := ?) := {
		presence := '1'B, // L/H
		ext_ra := ext_ra
	};

	template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr,
							  template (value) uint12_t arfcn,
							  template (value) uint3_t tsc := 7) := {
		chan_nr := chan_nr,
		tsc := tsc,
		h := false,
		arfcn := arfcn,
		maio_hsn := omit
	}
	template ChannelDescription tr_ChanDescH0(template (present) RslChannelNr chan_nr := ?,
						  template (present) uint12_t arfcn := ?,
						  template (present) uint3_t tsc := ?) := {
		chan_nr := chan_nr,
		tsc := tsc,
		h := false,
		arfcn := arfcn,
		maio_hsn := omit
	}

	template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr,
							  template (value) MaioHsn maio_hsn,
							  template (value) uint3_t tsc := 7) := {
		chan_nr := chan_nr,
		tsc := tsc,
		h := true,
		arfcn := omit,
		maio_hsn := maio_hsn
	}
	template ChannelDescription tr_ChanDescH1(template (present) RslChannelNr chan_nr := ?,
						  template (present) MaioHsn maio_hsn := ?,
						  template (present) uint3_t tsc := ?) := {
		chan_nr := chan_nr,
		tsc := tsc,
		h := true,
		arfcn := omit,
		maio_hsn := maio_hsn
	}


	/* Templates for the RR Channel Release message's "Cell selection indicator after release of all TCH and SDCCH" IE.
	 * See 3GPP TS 44.018 9.1.7 and 10.5.2.1e */

	/* 3GPP TS 44.018 10.5.2.1e, Cell Selection Indicator after release of all TCH and SDCCH value part */
	type record CellSelIndValue {
		BIT3         discr,
		CellSelIndValueEnum value_list,
		BIT1         value_list_term ('0'B)
	} with {
		variant (value_list) "CROSSTAG(
		  gsm, discr='000'B;
		  utran_fdd, discr='001'B;
		  utran_tdd, discr='010'B;
		  eutran, discr='011'B;
		)"
	};

	/* 3GPP TS 44.018 10.5.2.1e, Cell Selection Indicator after release of all TCH and SDCCH value part */
	private type union CellSelIndValueEnum {
		CellSelIndValue_GSM_Descrs gsm,
		CellSelIndValue_UTRAN_Descrs utran_fdd,
		CellSelIndValue_UTRAN_Descrs utran_tdd,
		CellSelIndValue_EUTRAN_Descrs eutran
	} with { variant "" };

	type record of CellSelIndValue_GSM_Descr CellSelIndValue_GSM_Descrs;
	/* 3GPP TS 44.018 10.5.2.1e, GSM Description struct */
	type record CellSelIndValue_GSM_Descr {
		BIT1        item_ind ('1'B),
		BIT1        band_indicator,
		uint10_t    arfcn,
		uint6_t     bsic
	} with {
		variant "PRESENCE(item_ind = '1'B)"
	};

	type record of CellSelIndValue_UTRAN_Descr CellSelIndValue_UTRAN_Descrs;
	/* 3GPP TS 44.018 10.5.2.1e, UTRAN {FDD,TDD} Description struct */
	type record CellSelIndValue_UTRAN_Descr {
		BIT1        item_ind ('1'B),
		BIT1        bandwidth_presence,
		uint3_t     bandwidth optional,
		uint14_t    arfcn,
		BIT1        cell_info_presence,
		UTRAN_CellInfo cell_info optional
	} with {
		variant "PRESENCE(item_ind = '1'B)"
		variant (bandwidth) "PRESENCE(bandwidth_presence = '1'B)"
		variant (cell_info) "PRESENCE(cell_info_presence = '1'B)"
	};
	type record UTRAN_CellInfo {
		BIT1        indic0,
		uint5_t     nr_of_cells,
		// TODO: define cell_information_field
		octetstring cell_information_field
	} with { variant "" };

	type record of CellSelIndValue_EUTRAN_Descr CellSelIndValue_EUTRAN_Descrs;
	/* 3GPP TS 44.018 10.5.2.1e, E-UTRAN Description struct */
	type record CellSelIndValue_EUTRAN_Descr {
		BIT1        item_ind ('1'B),
		uint16_t    earfcn,
		BIT1        meas_bw_presence,
		uint3_t     meas_bw optional,
		BIT1        not_allowed_cells_presence,
		// define not_allowed_cells
		octetstring not_allowed_cells optional,
		BIT1        target_pcid_presence,
		uint9_t     target_pcid optional
	} with {
		variant "PRESENCE(item_ind = '1'B)"
		variant (meas_bw) "PRESENCE(meas_bw_presence = '1'B)"
		variant (not_allowed_cells) "PRESENCE(not_allowed_cells_presence = '1'B)"
		variant (target_pcid) "PRESENCE(target_pcid_presence = '1'B)"
	};

	template CellSelIndValue tr_CellSelIndValue_EUTRAN(
			template CellSelIndValue_EUTRAN_Descrs cells := {})
	:= {
		discr := '011'B,
		value_list := {
			eutran := cells
		},
		value_list_term := '0'B
	};

	template CellSelIndValue_EUTRAN_Descr tr_CellSelIndValue_EUTRAN_Descr(
			template (present) uint16_t earfcn,
			template (present) BIT1 meas_bw_presence := ?,
			template uint3_t meas_bw := *)
	:= {
		item_ind := '1'B,
		earfcn := earfcn,
		meas_bw_presence := meas_bw_presence,
		meas_bw := meas_bw,
		not_allowed_cells_presence := '0'B,
		not_allowed_cells := omit,
		target_pcid_presence := '0'B,
		target_pcid := omit
	};

	external function enc_CellSelIndValue(in CellSelIndValue ro) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_CellSelIndValue(in octetstring stream) return CellSelIndValue
		with { extension "prototype(convert) decode(RAW)" };

} with { encode "RAW" ; variant "FIELDORDER(msb)" }