aboutsummaryrefslogtreecommitdiffstats
path: root/library/L1CTL_Types.ttcn
blob: 192091ef8893d0eae07abf23c2393d451ffb918d (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
/* Data Types / Encoding / Decoding for OsmocomBB L1CTL interface */
/* (C) 2017 by Harald Welte <laforge@gnumonks.org>, derived from l1ctl_proto.h
 * which is (C) 2010 by Harald Welte + Holger Hans Peter Freyther
 * 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 L1CTL_Types {

	import from General_Types all;
	import from GSM_Types all;
	import from GSM_RR_Types all;
	import from Osmocom_Types all;

	type enumerated L1ctlMsgType {
		L1CTL_NONE,
		L1CTL_FBSB_REQ,
		L1CTL_FBSB_CONF,
		L1CTL_DATA_IND,
		L1CTL_RACH_REQ,
		L1CTL_DM_EST_REQ,
		L1CTL_DATA_REQ,
		L1CTL_RESET_IND,
		L1CTL_PM_REQ,		/* power measurement */
		L1CTL_PM_CONF,		/* power measurement */
		L1CTL_ECHO_REQ,
		L1CTL_ECHO_CONF,
		L1CTL_RACH_CONF,
		L1CTL_RESET_REQ,
		L1CTL_RESET_CONF,
		L1CTL_DATA_CONF,
		L1CTL_CCCH_MODE_REQ,
		L1CTL_CCCH_MODE_CONF,
		L1CTL_DM_REL_REQ,
		L1CTL_PARAM_REQ,
		L1CTL_DM_FREQ_REQ,
		L1CTL_CRYPTO_REQ,
		L1CTL_SIM_REQ,
		L1CTL_SIM_CONF,
		L1CTL_TCH_MODE_REQ,
		L1CTL_TCH_MODE_CONF,
		L1CTL_NEIGH_PM_REQ,
		L1CTL_NEIGH_PM_IND,
		L1CTL_TRAFFIC_REQ,
		L1CTL_TRAFFIC_CONF,
		L1CTL_TRAFFIC_IND,
		L1CTL_BURST_IND,
		L1CTL_GPRS_UL_TBF_CFG_REQ,
		L1CTL_GPRS_DL_TBF_CFG_REQ,
		L1CTL_GPRS_UL_BLOCK_REQ,
		L1CTL_GPRS_DL_BLOCK_IND,
		L1CTL_EXT_RACH_REQ
	} with { variant "FIELDLENGTH(8)" };

	type enumerated L1ctlCcchMode {
		CCCH_MODE_NONE (0),
		CCCH_MODE_NON_COMBINED,
		CCCH_MODE_COMBINED,
		CCCH_MODE_COMBINED_CBCH
	} with { variant "FIELDLENGTH(8)" };

	type enumerated L1ctlNeighMode {
		NEIGH_MODE_NONE (0),
		NEIGH_MODE_PM,
		NEIGH_MODE_SB
	} with { variant "FIELDLENGTH(8)" };

	type enumerated L1ctlResetType {
		L1CTL_RES_T_BOOT (0),
		L1CTL_RES_T_FULL,
		L1CTL_RES_T_SCHED
	} with { variant "FIELDLENGTH(8)" };

	type record L1ctlHdrFlags {
		BIT7	padding,
		boolean f_done
	} with { variant "" };

	type record L1ctlHeader {
		L1ctlMsgType	msg_type,
		L1ctlHdrFlags	flags,
		OCT2		padding
	} with { variant "" };

	template L1ctlHeader
	tr_L1ctlHeader(template (present) L1ctlMsgType msg_type) := {
		msg_type := msg_type,
		flags := ?,
		padding := ?
	};

	template (value) L1ctlHeader
	ts_L1ctlHeader(template (value) L1ctlMsgType msg_type) := {
		msg_type := msg_type,
		flags := { padding := '0000000'B, f_done := false },
		padding := '0000'O
	};

	type record L1ctlDlInfo {
		RslChannelNr	chan_nr,
		RslLinkId	link_id,
		GsmBandArfcn	arfcn,
		uint32_t	frame_nr,
		GsmRxLev	rx_level,
		uint8_t		snr,
		uint8_t		num_biterr,
		uint8_t		fire_crc
	} with { variant "" };

	type record L1ctlFbsbConf {
		int16_t		initial_freq_err,
		uint8_t		result,
		uint8_t		bsic
	} with { variant "" };

	type record L1ctlCcchModeConf {
		L1ctlCcchMode	ccch_mode,
		OCT3		padding
	} with { variant "" };

	/* gsm48_chan_mode */
	type enumerated L1ctlTchMode {
		L1CTL_CHAN_MODE_SIGN		('00000000'B),	/* Signalling */
		L1CTL_CHAN_MODE_SPEECH_V1	('00000001'B),	/* FR or HR codec */
		L1CTL_CHAN_MODE_SPEECH_V2	('00100001'B),	/* EFR codec */
		L1CTL_CHAN_MODE_SPEECH_V3	('01000001'B)	/* AMR codec */
		/* Other modes are not supported for now */
	} with { variant "FIELDLENGTH(8)" };

	type enumerated L1ctlLoopMode {
		L1CTL_LOOP_MODE_OPEN		('00000000'B),
		L1CTL_LOOP_MODE_A		('00000001'B),
		L1CTL_LOOP_MODE_B		('00000010'B),
		L1CTL_LOOP_MODE_C		('00000011'B),
		L1CTL_LOOP_MODE_D		('00000100'B),
		L1CTL_LOOP_MODE_E		('00000101'B),
		L1CTL_LOOP_MODE_F		('00000110'B),
		L1CTL_LOOP_MODE_I		('00000111'B)
	} with { variant "FIELDLENGTH(8)" };

	type record L1ctlAudioMode {
		BIT4		padding,
		boolean		tx_microphone,
		boolean		tx_traffic_req,
		boolean		rx_speaker,
		boolean		rx_traffic_ind
	} with { variant "" };

	template (value) L1ctlAudioMode t_L1CTL_AudioModeNone := { '0000'B, false, false, false, false };

	/* Traffic forwarding mode (see TRAFFIC.{req,cnf,ind} messages) */
	template (value) L1ctlAudioMode t_L1CTL_AudioModeFwd
	modifies t_L1CTL_AudioModeNone := {
		tx_traffic_req := true,
		rx_traffic_ind := true
	};

	type record L1ctlTchModeConf {
		L1ctlTchMode	tch_mode,
		L1ctlAudioMode	audio_mode,
		record {
			uint8_t	start_codec,
			BIT8	codecs_bitmask
		} amr
	} with { variant "" };

	type record L1ctlDataInd {
		octetstring	payload
	} with {
		variant (payload) "BYTEORDER(first)"
	};


	type record L1ctlUlInfo {
		RslChannelNr	chan_nr,
		RslLinkId	link_id,
		OCT2		padding
	} with { variant "" };

	type record L1ctlFbsbFlags {
		BIT5		padding,
		boolean		sb,
		boolean		fb1,
		boolean		fb0
	} with { variant "FIELDORDER(msb)" };

	template (value) L1ctlFbsbFlags t_L1CTL_FBSB_F_ALL := {
		padding := '00000'B,
		sb := true,
		fb1 := true,
		fb0 := true
	};

	type record L1ctlFbsbReq {
		GsmBandArfcn	arfcn,
		uint16_t	timeout_tdma_frames,
		uint16_t	freq_err_thresh1,
		uint16_t	freq_err_thresh2,
		uint8_t		num_freqerr_avg,
		L1ctlFbsbFlags	flags,
		uint8_t		sync_info_idx,
		L1ctlCcchMode	ccch_mode,
		GsmRxLev	rxlev_exp
	} with { variant "" };

	type record L1ctlCcchModeReq {
		L1ctlCcchMode	ccch_mode,
		OCT3		padding
	} with { variant "" };

	type record L1ctlTchModeReq {
		L1ctlTchMode	tch_mode,
		L1ctlAudioMode	audio_mode,
		L1ctlLoopMode	loop_mode,
		record {
			uint8_t	start_codec,
			BIT8	codecs_bitmask
		} amr
	} with { variant "" };

	type record L1ctlRachReq {
		uint8_t		ra,
		uint8_t		combined,
		uint16_t	offset
	} with { variant "" };

	type enumerated L1ctlRachSynchSeq {
		RACH_SYNCH_SEQ_TS0 (0),
		RACH_SYNCH_SEQ_TS1,
		RACH_SYNCH_SEQ_TS2
	} with { variant "FIELDLENGTH(8)" };

	type record L1ctlExtRachReq {
		uint16_t		ra11,
		L1ctlRachSynchSeq	synch_seq,
		uint8_t			combined,
		uint16_t		offset
	} with { variant "" };

	type record L1ctlParReq {
		int8_t		ta,
		uint8_t		tx_power,
		OCT2		padding
	} with { variant "" };

	type record L1ctlDataReq {
		SacchL1Header	l1header optional,
		octetstring	l2_payload
	} with { variant "" };

	type record L1ctlH0 {
		uint8_t		h,
		GsmBandArfcn	arfcn,
		octetstring	padding length(130)
	} with { variant "" };

	type record length(0..64) of GsmBandArfcn L1ctlMA;
	type record L1ctlH1 {
		uint8_t		h,
		uint8_t		hsn,
		uint8_t		maio,
		uint8_t		n,
		OCT1		spare,
		L1ctlMA		ma,
		octetstring	padding
	} with {
		variant (n) "LENGTHTO(ma)"
		variant (n) "UNIT(elements)"
		/* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=562849.
		 * TL;DR The reference point of the PADDING attribute is the beginning
		 * of the message, not the beginning of the type/field it's applied on.
		 * Therefore we cannot use it here, and have to add padding manually.
		 * variant (ma) "PADDING(128)" */
	};

	type union L1ctlH0H1 {
		L1ctlH0		h0,
		L1ctlH1		h1
	} with { variant "TAG(h0, h = 0; h1, h = 1)" };

	type record L1ctlDmEstReq {
		GsmTsc		tsc,
		L1ctlH0H1	h0h1,
		L1ctlTchMode	tch_mode,
		L1ctlAudioMode	audio_mode
	} with { variant "" };

	type record L1ctlReset {
		L1ctlResetType	reset_type,
		OCT3		padding
	} with { variant "" };

	type record L1CtlCryptoReq {
		uint8_t		algo,
		uint8_t		key_len,
		octetstring	key
	} with { variant (key_len) "LENGTHTO(key)" };


	type record L1ctlTrafficReq {
		octetstring	data
	} with {
		variant (data) "BYTEORDER(first)"
	}


	/* payload of L1CTL_GPRS_UL_TBF_CFG_REQ */
	type record L1ctlGprsUlTbfCfgReq {
		uint8_t			tbf_ref,
		BIT8			slotmask,
		OCT2			pad ('0000'O)
	} with { variant (slotmask) "BITORDER(msb)" };

	/* payload of L1CTL_GPRS_DL_TBF_CFG_REQ */
	type record L1ctlGprsDlTbfCfgReq {
		uint8_t			tbf_ref,
		BIT8			slotmask,
		uint8_t			dl_tfi,
		OCT1			pad ('00'O)
	} with { variant (slotmask) "BITORDER(msb)" };

	/* part of L1CTL_GPRS_{UL,DL}_BLOCK_{REQ,IND} */
	type record L1ctlGprsBlockHdr {
		uint32_t		fn,
		uint8_t			tn,
		OCT3			pad ('000000'O)
	} with { variant "" };

	/* payload of L1CTL_GPRS_UL_BLOCK_REQ */
	type record L1ctlGprsUlBlockReq {
		L1ctlGprsBlockHdr	hdr,
		octetstring		data
	} with { variant (data) "BYTEORDER(first)" };

	/* payload of L1CTL_GPRS_DL_BLOCK_IND */
	type record L1ctlGprsDlBlockInd {
		L1ctlGprsBlockHdr	hdr,
		record {
			uint16_t	ber10k,		/* Bit Error Rate */
			int16_t		ci_cb,		/* C/I in centiBels */
			uint8_t		rx_level	/* RxLev 0..63 */
		} meas,
		uint8_t			usf,
		octetstring		data
	} with { variant (data) "BYTEORDER(first)" };


	type union L1ctlMsgPayload {
		L1ctlFbsbReq		fbsb_req,
		L1ctlFbsbConf		fbsb_conf,
		L1ctlDataInd		data_ind,
		L1ctlRachReq		rach_req,
		L1ctlDmEstReq		dm_est_req,
		L1ctlDataReq		data_req,
		/* TODO: L1CTL_RESET_IND */
		/* TODO: L1CTL_PM_REQ */
		/* TODO: L1CTL_PM_CONF */
		L1ctlReset		reset_req,
		L1ctlCcchModeReq	ccch_mode_req,
		L1ctlCcchModeConf	ccch_mode_conf,
		L1ctlParReq		par_req,
		/* TODO: L1CTL_DM_FREQ_REQ */
		L1CtlCryptoReq		crypto_req,
		/* TODO: L1CTL_SIM_REQ */
		/* TODO: L1CTL_SIM_CONF */
		L1ctlTchModeReq		tch_mode_req,
		L1ctlTchModeConf	tch_mode_conf,
		/* TODO: L1CTL_NEIGH_PM_REQ */
		/* TODO: L1CTL_NEIGH_PM_IND */
		L1ctlTrafficReq		traffic_req,
		L1ctlTrafficReq		traffic_ind,
		/* TODO: L1CTL_BURST_IND */
		L1ctlGprsUlTbfCfgReq	ul_tbf_cfg_req,
		L1ctlGprsDlTbfCfgReq	dl_tbf_cfg_req,
		L1ctlGprsUlBlockReq	ul_block_req,
		L1ctlGprsDlBlockInd	dl_block_ind,
		L1ctlExtRachReq		ext_rach_req,
		octetstring		other
	} with {
		variant (other) "BYTEORDER(first)"
	};

	type record L1ctlMessage {
		L1ctlHeader	header,
		L1ctlUlInfo	ul_info optional,
		L1ctlDlInfo	dl_info optional,
		L1ctlMsgPayload	payload optional
	} with { variant (ul_info) "PRESENCE(header.msg_type = L1CTL_RACH_REQ,
					     header.msg_type = L1CTL_EXT_RACH_REQ,
					     header.msg_type = L1CTL_PARAM_REQ,
					     header.msg_type = L1CTL_CRYPTO_REQ,
					     header.msg_type = L1CTL_DATA_REQ,
					     header.msg_type = L1CTL_DM_EST_REQ,
					     header.msg_type = L1CTL_DM_FREQ_REQ,
					     header.msg_type = L1CTL_DM_REL_REQ,
					     header.msg_type = L1CTL_TRAFFIC_REQ)"
		 variant (dl_info) "PRESENCE(header.msg_type = L1CTL_FBSB_CONF,
					     header.msg_type = L1CTL_RACH_CONF,
					     header.msg_type = L1CTL_DATA_IND,
					     header.msg_type = L1CTL_DATA_CONF,
					     header.msg_type = L1CTL_TRAFFIC_IND,
					     header.msg_type = L1CTL_TRAFFIC_CONF)"
		 variant (payload) "CROSSTAG(fbsb_req, header.msg_type = L1CTL_FBSB_REQ;
					     fbsb_conf, header.msg_type = L1CTL_FBSB_CONF;
					     data_ind, header.msg_type = L1CTL_DATA_IND;
					     rach_req, header.msg_type = L1CTL_RACH_REQ;
					     dm_est_req, header.msg_type = L1CTL_DM_EST_REQ;
					     data_req, header.msg_type = L1CTL_DATA_REQ;
					     /* TODO: reset_ind, header.msg_type = L1CTL_RESET_IND */
					     /* TODO: pm_req, header.msg_type = L1CTL_PM_REQ */
					     /* TODO: pm_conf, header.msg_type = L1CTL_PM_CONF */
					     reset_req, header.msg_type = L1CTL_RESET_REQ;
					     ccch_mode_req, header.msg_type = L1CTL_CCCH_MODE_REQ;
					     ccch_mode_conf, header.msg_type = L1CTL_CCCH_MODE_CONF;
					     par_req, header.msg_type = L1CTL_PARAM_REQ;
					     /* TODO: freq_req, header.msg_type = L1CTL_DM_FREQ_REQ */
					     crypto_req, header.msg_type = L1CTL_CRYPTO_REQ;
					     /* TODO: sim_req, header.msg_type = L1CTL_SIM_REQ */
					     /* TODO: sim_conf, header.msg_type = L1CTL_SIM_CONF */
					     tch_mode_req, header.msg_type = L1CTL_TCH_MODE_REQ;
					     tch_mode_conf, header.msg_type = L1CTL_TCH_MODE_CONF;
					     /* TODO: neigh_pm_req, header.msg_type = L1CTL_NEIGH_PM_REQ */
					     /* TODO: neigh_pm_ind, header.msg_type = L1CTL_NEIGH_PM_IND */
					     traffic_req, header.msg_type = L1CTL_TRAFFIC_REQ;
					     traffic_ind, header.msg_type = L1CTL_TRAFFIC_IND;
					     /* TODO: burst_ind, header.msg_type = L1CTL_BURST_IND */
					     ul_tbf_cfg_req, header.msg_type = L1CTL_GPRS_UL_TBF_CFG_REQ;
					     dl_tbf_cfg_req, header.msg_type = L1CTL_GPRS_DL_TBF_CFG_REQ;
					     ul_block_req, header.msg_type = L1CTL_GPRS_UL_BLOCK_REQ;
					     dl_block_ind, header.msg_type = L1CTL_GPRS_DL_BLOCK_IND;
					     ext_rach_req, header.msg_type = L1CTL_EXT_RACH_REQ;
					     other, OTHERWISE;
				)" };

	external function enc_L1ctlMessage(in L1ctlMessage msg) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_L1ctlMessage(in octetstring stream) return L1ctlMessage
		with { extension "prototype(convert) decode(RAW)" };

	type record L1ctlMessageLV {
		uint16_t	len,
		L1ctlMessage	msg
	} with { variant (len) "LENGTHTO(msg)" };

	external function enc_L1ctlMessageLV(in L1ctlMessageLV msg) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_L1ctlMessageLV(in octetstring stream) return L1ctlMessageLV
		with { extension "prototype(convert) decode(RAW)" };



	/* for generating RESET_REQ */
	template (value) L1ctlMessage
	t_L1ctlResetReq(template (value) L1ctlResetType rst_type) := {
		header := ts_L1ctlHeader(L1CTL_RESET_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			reset_req := {
				reset_type := rst_type,
				padding := '000000'O
			}
		}
	};

	/* for generating FBSB_REQ */
	template (value) L1ctlMessage
	ts_L1CTL_FBSB_REQ(template (value) GsmBandArfcn arfcn,
			  template (value) L1ctlFbsbFlags flags,
			  template (value) uint8_t sync_info_idx,
			  template (value) L1ctlCcchMode ccch_mode,
			  template (value) GsmRxLev rxlev_exp) := {
		header := ts_L1ctlHeader(L1CTL_FBSB_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			fbsb_req := {
				arfcn := arfcn,
				timeout_tdma_frames := 250, /* about 1s */
				freq_err_thresh1 := 10000,
				freq_err_thresh2 := 800,
				num_freqerr_avg := 3,
				flags := flags,
				sync_info_idx := sync_info_idx,
				ccch_mode := ccch_mode,
				rxlev_exp := rxlev_exp
			}
		}
	};

	/* for matching against incoming FBSB_CONF */
	template L1ctlMessage
	tr_L1CTL_FBSB_CONF(template (present) uint8_t result) := {
		header := tr_L1ctlHeader(L1CTL_FBSB_CONF),
		ul_info := omit,
		dl_info := ?,
		payload := {
			fbsb_conf := {
				initial_freq_err := ?,
				result := result,
				bsic := ?
			}
		}
	};

	template (value) L1ctlMessage
	ts_L1CTL_CCCH_MODE_REQ(template (value) L1ctlCcchMode ccch_mode) := {
		header := ts_L1ctlHeader(L1CTL_CCCH_MODE_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			ccch_mode_req := {
				ccch_mode := ccch_mode,
				padding := '000000'O
			}
		}
	};

	template (value) L1ctlMessage
	ts_L1CTL_TCH_MODE_REQ(template (value) L1ctlTchMode tch_mode := L1CTL_CHAN_MODE_SIGN,
			      template (value) L1ctlAudioMode audio_mode := t_L1CTL_AudioModeFwd,
			      template (value) L1ctlLoopMode loop_mode := L1CTL_LOOP_MODE_OPEN,
			      template (value) uint8_t amr_start_codec := 0,
			      template (value) BIT8 amr_codecs_bitmask := '00000000'B) := {
		header := ts_L1ctlHeader(L1CTL_TCH_MODE_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			tch_mode_req := {
				tch_mode := tch_mode,
				audio_mode := audio_mode,
				loop_mode := loop_mode,
				amr := {
					start_codec := amr_start_codec,
					codecs_bitmask := amr_codecs_bitmask
				}
			}
		}
	};


	template L1ctlMessage
	tr_L1CTL_MsgType(template (present) L1ctlMsgType msg_type) := {
		header := tr_L1ctlHeader(msg_type),
		ul_info := *,
		dl_info := *,
		payload := *
	}

	template L1ctlMessage tr_L1CTL_CCCH_MODE_CONF := tr_L1CTL_MsgType(L1CTL_CCCH_MODE_CONF);

	template (value) L1ctlMessage
	ts_L1CTL_RACH_REQ(template (value) uint8_t ra,
			  template (value) uint8_t combined,
			  template (value) uint16_t offset,
			  template (value) RslChannelNr chan_nr := ts_RslChanNr_RACH(0),
			  template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0)) := {
		header := ts_L1ctlHeader(L1CTL_RACH_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			rach_req := {
				ra := ra,
				combined := combined,
				offset := offset
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_EXT_RACH_REQ(template (value) uint16_t ra11,
			      template (value) L1ctlRachSynchSeq seq,
			      template (value) uint8_t combined,
			      template (value) uint16_t offset) := {
		header := ts_L1ctlHeader(L1CTL_EXT_RACH_REQ),
		ul_info := {
			/* FIXME: both RSL chan_nr and link_id should be configurable */
			chan_nr := ts_RslChanNr_RACH(0),
			link_id := ts_RslLinkID_DCCH(0),
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			ext_rach_req := {
				ra11 := ra11,
				synch_seq := seq,
				combined := combined,
				offset := offset
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_PAR_REQ(template (value) uint8_t ta,
			 template (value) uint8_t tx_power) := {
		header := ts_L1ctlHeader(L1CTL_PARAM_REQ),
		ul_info := {
			chan_nr := ts_RslChanNr_RACH(0),
			link_id := ts_RslLinkID_DCCH(0),
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			par_req := {
				ta := ta,
				tx_power := tx_power,
				padding := '0000'O
			}
		}
	}

	/* Base template to be inherited by ts_L1CTL_DM_EST_REQ_H0 and ts_L1CTL_DM_EST_REQ_H1 */
	private template (value) L1ctlMessage
	ts_L1CTL_DM_EST_REQ(template (value) RslChannelNr chan_nr,
			    template (value) GsmTsc tsc) := {
		header := ts_L1ctlHeader(L1CTL_DM_EST_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := ts_RslLinkID_DCCH(0),
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			dm_est_req := {
				tsc := tsc,
				h0h1 := -,
				tch_mode := L1CTL_CHAN_MODE_SIGN,
				audio_mode := t_L1CTL_AudioModeFwd
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_DM_EST_REQ_H0(template (value) RslChannelNr chan_nr,
			       template (value) GsmTsc tsc,
			       template (value) GsmArfcn arfcn)
	modifies ts_L1CTL_DM_EST_REQ := {
		payload := {
			dm_est_req := {
				h0h1 := {
					h0 := {
						h := 0,
						arfcn := ts_GsmBandArfcn(arfcn),
						padding := f_pad_oct(''O, 130, '00'O)
					}
				}
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_DM_EST_REQ_H1(template (value) RslChannelNr chan_nr,
			       template (value) GsmTsc tsc,
			       template (value) uint6_t hsn,
			       template (value) uint6_t maio,
			       template (value) L1ctlMA ma)
	modifies ts_L1CTL_DM_EST_REQ := {
		payload := {
			dm_est_req := {
				h0h1 := {
					h1 := {
						h := 1,
						hsn := hsn,
						maio := maio,
						n := sizeof(ma),
						spare := '00'O,
						ma := ma,
						/* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=562849 */
						padding := f_pad_oct(''O, (64 - sizeof(ma)) * 2, '00'O)
					}
				}
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_DM_REL_REQ(template (value) RslChannelNr chan_nr) := {
		header := ts_L1ctlHeader(L1CTL_DM_REL_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := ts_RslLinkID_DCCH(0),
			padding := '0000'O
		},
		dl_info := omit,
		payload := omit
	}

	template (value) L1ctlMessage
	ts_L1CTL_DATA_REQ(template (value) RslChannelNr chan_nr,
			  template (value) RslLinkId link_id,
			  octetstring l2_data) := {
		header := ts_L1ctlHeader(L1CTL_DATA_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			data_req := {
				l1header := omit,
				l2_payload := l2_data
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_DATA_REQ_SACCH(template (value) RslChannelNr chan_nr,
				template (value) RslLinkId link_id,
				template (value) SacchL1Header l1h,
				octetstring l2_data) := {
		header := ts_L1ctlHeader(L1CTL_DATA_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			data_req := {
				l1header := l1h,
				l2_payload := l2_data
			}
		}
	}

	template (value) L1ctlMessage
	ts_L1CTL_TRAFFIC_REQ(template (value) RslChannelNr chan_nr,
			     template (value) RslLinkId link_id,
			     octetstring frame) := {
		header := ts_L1ctlHeader(L1CTL_TRAFFIC_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			traffic_req := {
				data := frame
			}
		}
	};

	/* for matching against incoming RACH_CONF */
	template L1ctlMessage tr_L1CTL_RACH_CONF := {
		header := tr_L1ctlHeader(L1CTL_RACH_CONF),
		ul_info := omit,
		dl_info := ?,
		payload := *
	};

	/* for sending and matching L1CTL_DATA_IND */
	template (value) L1ctlMessage
	ts_L1CTL_DATA_IND(template (value) RslChannelNr chan_nr,
			  template (value) RslLinkId link_id,
			  template (value) octetstring l2_data,
			  template (value) GsmBandArfcn arfcn,
			  template (value) uint32_t fn := 1337,
			  template (value) GsmRxLev rx_level := 63,
			  template (value) uint8_t num_biterr := 0,
			  template (value) uint8_t fire_crc := 0) := {
		header := ts_L1ctlHeader(L1CTL_DATA_IND),
		ul_info := omit,
		dl_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			arfcn := arfcn,
			frame_nr := fn,
			rx_level := rx_level,
			snr := 0,
			num_biterr := num_biterr,
			fire_crc := fire_crc
		},
		payload := {
			data_ind := {
				payload := l2_data
			}
		}
	};
	template L1ctlMessage
	tr_L1CTL_DATA_IND(template (present) RslChannelNr chan_nr,
			  template (present) RslLinkId link_id := ?,
			  template (present) octetstring l2_data := ?,
			  template (present) uint8_t num_biterr := 0,
			  template (present) uint8_t fire_crc := 0) := {
		header := tr_L1ctlHeader(L1CTL_DATA_IND),
		ul_info := omit,
		dl_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			arfcn := ?,
			frame_nr := ?,
			rx_level := ?,
			snr := ?,
			num_biterr := num_biterr,
			fire_crc := fire_crc
		},
		payload := {
			data_ind := {
				payload := l2_data
			}
		}
	};

	/* for matching against incoming TRAFFIC_IND */
	template L1ctlMessage
	tr_L1CTL_TRAFFIC_IND(template (present) RslChannelNr chan_nr,
			     template (present) RslLinkId link_id := ?,
			     template (present) octetstring frame := ?,
			     template (present) uint8_t num_biterr := ?,
			     template (present) uint8_t fire_crc := ?) := {
		header := tr_L1ctlHeader(L1CTL_TRAFFIC_IND),
		ul_info := omit,
		dl_info := {
			chan_nr := chan_nr,
			link_id := link_id,
			arfcn := ?,
			frame_nr := ?,
			rx_level := ?,
			snr := ?,
			num_biterr := num_biterr,
			fire_crc := fire_crc
		},
		payload := {
			traffic_ind := {
				data := frame
			}
		}
	};

	template (value) L1ctlMessage
	ts_L1CTL_CRYPTO_REQ(template (value) RslChannelNr chan_nr,
			    template (value) uint8_t algo,
			    template (value) octetstring key) := {
		header := ts_L1ctlHeader(L1CTL_CRYPTO_REQ),
		ul_info := {
			chan_nr := chan_nr,
			link_id := ts_RslLinkID_DCCH(0),
			padding := '0000'O
		},
		dl_info := omit,
		payload := {
			crypto_req := {
				algo := algo,
				key_len := 0, /* overwritten */
				key := key
			}
		}
	};


	template (value) L1ctlMessage
	ts_L1CTL_GPRS_UL_TBF_CFG_REQ(template (value) uint8_t tbf_ref,
				     template (value) BIT8 slotmask := '00000000'B) := {
		header := ts_L1ctlHeader(L1CTL_GPRS_UL_TBF_CFG_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			ul_tbf_cfg_req := {
				tbf_ref := tbf_ref,
				slotmask := slotmask,
				pad := '0000'O
			}
		}
	};
	template L1ctlMessage
	tr_L1CTL_GPRS_UL_TBF_CFG_REQ(template (present) uint8_t tbf_ref := ?,
				     template (present) BIT8 slotmask := ?) := {
		header := tr_L1ctlHeader(L1CTL_GPRS_UL_TBF_CFG_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			ul_tbf_cfg_req := {
				tbf_ref := tbf_ref,
				slotmask := slotmask,
				pad := ?
			}
		}
	};

	template (value) L1ctlMessage
	ts_L1CTL_GPRS_DL_TBF_CFG_REQ(template (value) uint8_t tbf_ref,
				     template (value) BIT8 slotmask := '00000000'B,
				     template (value) uint5_t dl_tfi := 0) := {
		header := ts_L1ctlHeader(L1CTL_GPRS_DL_TBF_CFG_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			dl_tbf_cfg_req := {
				tbf_ref := tbf_ref,
				slotmask := slotmask,
				dl_tfi := dl_tfi,
				pad := '00'O
			}
		}
	};
	template L1ctlMessage
	tr_L1CTL_GPRS_DL_TBF_CFG_REQ(template (present) uint8_t tbf_ref := ?,
				     template (present) BIT8 slotmask := ?,
				     template (present) uint5_t dl_tfi := ?) := {
		header := tr_L1ctlHeader(L1CTL_GPRS_DL_TBF_CFG_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			dl_tbf_cfg_req := {
				tbf_ref := tbf_ref,
				slotmask := slotmask,
				dl_tfi := dl_tfi,
				pad := ?
			}
		}
	};

	template (value) L1ctlMessage
	ts_L1CTL_GPRS_UL_BLOCK_REQ(template (value) GsmFrameNumber fn,
				   template (value) uint3_t tn,
				   template (value) octetstring data) := {
		header := ts_L1ctlHeader(L1CTL_GPRS_UL_BLOCK_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			ul_block_req := {
				hdr := {
					fn := fn,
					tn := tn,
					pad := '000000'O
				},
				data := data
			}
		}
	};
	template L1ctlMessage
	tr_L1CTL_GPRS_UL_BLOCK_REQ(template (present) GsmFrameNumber fn := ?,
				   template (present) uint3_t tn := ?,
				   template (present) octetstring data := ?) := {
		header := tr_L1ctlHeader(L1CTL_GPRS_UL_BLOCK_REQ),
		ul_info := omit,
		dl_info := omit,
		payload := {
			ul_block_req := {
				hdr := {
					fn := fn,
					tn := tn,
					pad := ?
				},
				data := data
			}
		}
	};

	template (value) L1ctlMessage
	ts_L1CTL_GPRS_DL_BLOCK_IND(template (value) GsmFrameNumber fn,
				   template (value) uint3_t tn,
				   template (value) uint3_t usf,
				   template (value) octetstring data,
				   template (value) uint16_t ber10k := 0,
				   template (value) int16_t ci_cb := 180 /* 18 dB */,
				   template (value) GsmRxLev rx_level := 63) := {
		header := ts_L1ctlHeader(L1CTL_GPRS_DL_BLOCK_IND),
		ul_info := omit,
		dl_info := omit,
		payload := {
			dl_block_ind := {
				hdr := {
					fn := fn,
					tn := tn,
					pad := '000000'O
				},
				meas := {
					ber10k := ber10k,
					ci_cb := ci_cb,
					rx_level := rx_level
				},
				usf := usf,
				data := data
			}
		}
	};
	template L1ctlMessage
	tr_L1CTL_GPRS_DL_BLOCK_IND(template (present) GsmFrameNumber fn := ?,
				   template (present) uint3_t tn := ?,
				   template (present) uint3_t usf := ?,
				   template (present) octetstring data := ?,
				   template (present) uint16_t ber10k := ?,
				   template (present) int16_t ci_cb := ?,
				   template (present) GsmRxLev rx_level := ?) := {
		header := tr_L1ctlHeader(L1CTL_GPRS_DL_BLOCK_IND),
		ul_info := omit,
		dl_info := omit,
		payload := {
			dl_block_ind := {
				hdr := {
					fn := fn,
					tn := tn,
					pad := ?
				},
				meas := {
					ber10k := ber10k,
					ci_cb := ci_cb,
					rx_level := rx_level
				},
				usf := usf,
				data := data
			}
		}
	};

	const octetstring c_DummyUI := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;

/* We use "BYTEORDER(last)" so we get little-endian integers.  Unfortuantely, this also
   switches the byte ordering in octet strings, so we need to explicitly annotate them :/ */
} with { encode "RAW" };