summaryrefslogtreecommitdiffstats
path: root/library/RLCMAC_Templates.ttcn
blob: 1774197bdeb1d94f3a32e85cee3bbb9b2b3ab127 (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
/* TITAN REW encode/decode definitions for 3GPP TS 44.060 RLC/MAC Blocks */

/* (C) 2017-2018 Harald Welte <laforge@gnumonks.org>
 * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * 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 RLCMAC_Templates {
	import from General_Types all;
	import from Osmocom_Types all;
	import from GSM_Types all;
	import from RLCMAC_CSN1_Types all;
	import from RLCMAC_CSN1_Templates all;
	import from RLCMAC_Types all;

	/* TS 44.060 10.4.5 */
	function f_rrbp_fn_delay(MacRrbp rrbp) return uint32_t {
		select (rrbp) {
		case (RRBP_Nplus13_mod_2715648) { return 13; }
		case (RRBP_Nplus17_or_18_mod_2715648) { return 17; }
		case (RRBP_Nplus21_or_22_mod_2715648) { return 21;  }
		case (RRBP_Nplus26_mod_2715648) { return 26; }
		}
		return 0;
	}

	function f_rrbp_ack_fn(uint32_t current_fn, MacRrbp rrbp)
	return uint32_t {
		return (current_fn + f_rrbp_fn_delay(rrbp)) mod 2715648;
	}

	function f_rlcmac_mcs2headertype(CodingScheme mcs) return EgprsHeaderType {
		select (mcs) {
		case (MCS_0) { return RLCMAC_HDR_TYPE_3; }
		case (MCS_1) { return RLCMAC_HDR_TYPE_3; }
		case (MCS_2) { return RLCMAC_HDR_TYPE_3; }
		case (MCS_3) { return RLCMAC_HDR_TYPE_3; }
		case (MCS_4) { return RLCMAC_HDR_TYPE_3; }
		case (MCS_5) { return RLCMAC_HDR_TYPE_2; }
		case (MCS_6) { return RLCMAC_HDR_TYPE_2; }
		case (MCS_7) { return RLCMAC_HDR_TYPE_1; }
		case (MCS_8) { return RLCMAC_HDR_TYPE_1; }
		case (MCS_9) { return RLCMAC_HDR_TYPE_1; }
		}
		return RLCMAC_HDR_TYPE_3;
	}

	function f_rlcmac_cs_mcs2block_len(CodingScheme cs_mcs) return uint32_t {
		select (cs_mcs) {
		case (CS_1) { return 23; }
		case (CS_2) { return 34; }
		case (CS_3) { return 40; }
		case (CS_4) { return 54; }
		case (MCS_1) { return 27; }
		case (MCS_2) { return 33; }
		case (MCS_3) { return 42; }
		case (MCS_4) { return 49; }
		case (MCS_5) { return 61; }
		case (MCS_6) { return 79; }
		case (MCS_7) { return 119; }
		case (MCS_8) { return 143; }
		case (MCS_9) { return 155; }
		}
		return 0;
	}

	function f_rlcmac_block_len2cs_mcs(uint32_t len) return CodingScheme {
		select (len) {
			case (23) { return CS_1; }
			case (34) { return CS_2; }
			case (40) { return CS_3; }
			case (54) { return CS_4; }
			case (27) { return MCS_1; }
			case (33) { return MCS_2; }
			case (42) { return MCS_3; }
			case (49) { return MCS_4; }
			case (60) { return MCS_5; }
			case (61) { return MCS_5; }
			case (78) { return MCS_6; }
			case (79) { return MCS_6; }
			case (118) { return MCS_7; }
			case (119) { return MCS_7; }
			case (142) { return MCS_8; }
			case (143) { return MCS_8; }
			case (154) { return MCS_9; }
			case (155) { return MCS_9; }
		}
		return CS_1;
	}

	function f_rlcmac_block_ChCodingCommand2cs_mcs(ChCodingCommand chcc) return CodingScheme {
		select (chcc) {
			case (CH_CODING_CS1) { return CS_1; }
			case (CH_CODING_CS2) { return CS_2; }
			case (CH_CODING_CS3) { return CS_3; }
			case (CH_CODING_CS4) { return CS_4; }
		}
		return CS_1;
	}

	function f_rlcmac_block_EgprsChCodingCommand2cs_mcs(EgprsChCodingCommand echcc) return CodingScheme {
		select (echcc) {
			case (CH_CODING_MCS1) { return MCS_1; }
			case (CH_CODING_MCS2) { return MCS_2; }
			case (CH_CODING_MCS3) { return MCS_3; }
			case (CH_CODING_MCS4) { return MCS_4; }
			case (CH_CODING_MCS5) { return MCS_5; }
			case (CH_CODING_MCS6) { return MCS_6; }
			case (CH_CODING_MCS7) { return MCS_7; }
			case (CH_CODING_MCS8) { return MCS_8; }
			case (CH_CODING_MCS9) { return MCS_9; }
			/* CH_CODING_MCS5_7 */
			/* CH_CODING_MCS6_9 */
		}
		return MCS_1;
	}

	/* 1 -> CS_1 / MCS_1, 2 -> CS_2 / MCS_2, etc. */
	function f_rlcmac_block_int2cs_mcs(integer n, boolean is_mcs) return CodingScheme {
		var CodingScheme cs_mcs;
		if (not is_mcs) {
			int2enum(n - 1, cs_mcs);
			return cs_mcs;
		} else {
			cs_mcs := MCS_0;
			int2enum(enum2int(cs_mcs) + n, cs_mcs);
			return cs_mcs;
		}
	}

	/* Coding and Puncturing Scheme indicator field for Header type 1 in EGPRS TBF or EC TBF or downlink EGPRS2 TBF */
	function f_rlcmac_cps_htype1_to_mcs(uint3_t cps) return CodingScheme {
		var CodingSchemeArray egprs_Header_type1_coding_puncturing_scheme_to_mcs := {
			MCS_9 /* 0x00, "(MCS-9/P1 ; MCS-9/P1)" */,
			MCS_9 /* 0x01, "(MCS-9/P1 ; MCS-9/P2)" */,
			MCS_9 /* 0x02, "(MCS-9/P1 ; MCS-9/P3)" */,
			MCS_0 /* 0x03, "reserved" */,
			MCS_9 /* 0x04, "(MCS-9/P2 ; MCS-9/P1)" */,
			MCS_9 /* 0x05, "(MCS-9/P2 ; MCS-9/P2)" */,
			MCS_9 /* 0x06, "(MCS-9/P2 ; MCS-9/P3)" */,
			MCS_0 /* 0x07, "reserved" */,
			MCS_9 /* 0x08, "(MCS-9/P3 ; MCS-9/P1)" */,
			MCS_9 /* 0x09, "(MCS-9/P3 ; MCS-9/P2)" */,
			MCS_9 /* 0x0A, "(MCS-9/P3 ; MCS-9/P3)" */,
			MCS_8 /* 0x0B, "(MCS-8/P1 ; MCS-8/P1)" */,
			MCS_8 /* 0x0C, "(MCS-8/P1 ; MCS-8/P2)" */,
			MCS_8 /* 0x0D, "(MCS-8/P1 ; MCS-8/P3)" */,
			MCS_8 /* 0x0E, "(MCS-8/P2 ; MCS-8/P1)" */,
			MCS_8 /* 0x0F, "(MCS-8/P2 ; MCS-8/P2)" */,
			MCS_8 /* 0x10, "(MCS-8/P2 ; MCS-8/P3)" */,
			MCS_8 /* 0x11, "(MCS-8/P3 ; MCS-8/P1)" */,
			MCS_8 /* 0x12, "(MCS-8/P3 ; MCS-8/P2)" */,
			MCS_8 /* 0x13, "(MCS-8/P3 ; MCS-8/P3)" */,
			MCS_7 /* 0x14, "(MCS-7/P1 ; MCS-7/P1)" */,
			MCS_7 /* 0x15, "(MCS-7/P1 ; MCS-7/P2)" */,
			MCS_7 /* 0x16, "(MCS-7/P1 ; MCS-7/P3)" */,
			MCS_7 /* 0x17, "(MCS-7/P2 ; MCS-7/P1)" */,
			MCS_7 /* 0x18, "(MCS-7/P2 ; MCS-7/P2)" */,
			MCS_7 /* 0x19, "(MCS-7/P2 ; MCS-7/P3)" */,
			MCS_7 /* 0x1A, "(MCS-7/P3 ; MCS-7/P1)" */,
			MCS_7 /* 0x1B, "(MCS-7/P3 ; MCS-7/P2)" */,
			MCS_7 /* 0x1C, "(MCS-7/P3 ; MCS-7/P3)" */,
			MCS_0 /* 0x1D, "reserved" */,
			MCS_0 /* 0x1E, "reserved" */,
			MCS_0 /* 0x1F, "reserved" */
		};
		return egprs_Header_type1_coding_puncturing_scheme_to_mcs[cps];
	}

	/* Coding and Puncturing Scheme indicator field for Header type 2 in (EC-)EGPRS TBF or uplink EGPRS2-A TBF */
	function f_rlcmac_cps_htype2_to_mcs(uint3_t cps) return CodingScheme {
		var CodingSchemeArray egprs_Header_type2_coding_puncturing_scheme_to_mcs := {
			MCS_6 /* {0x00, "MCS-6/P1"} */,
			MCS_6 /* {0x01, "MCS-6/P2"} */,
			MCS_6 /* {0x02, "MCS-6/P1 with 6 octet padding"} */,
			MCS_6 /* {0x03, "MCS-6/P2 with 6 octet padding "} */,
			MCS_5 /* {0x04, "MCS-5/P1"} */,
			MCS_5 /* {0x05, "MCS-5/P2"} */,
			MCS_5 /* {0x06, "MCS-6/P1 with 10 octet padding "} */,
			MCS_5 /* {0x07, "MCS-6/P2 with 10 octet padding "} */
		 };
		 return egprs_Header_type2_coding_puncturing_scheme_to_mcs[cps];
	}

	/* Coding and Puncturing Scheme indicator field for Header type 3 */
	function f_rlcmac_cps_htype3_to_mcs(uint3_t cps) return CodingScheme {
		var CodingSchemeArray egprs_Header_type3_coding_puncturing_scheme_to_mcs := {
			MCS_4 /* {0x00, "MCS-4/P1"} */,
			MCS_4 /* {0x01, "MCS-4/P2"} */,
			MCS_4 /* {0x02, "MCS-4/P3"} */,
			MCS_3 /* {0x03, "MCS-3/P1"} */,
			MCS_3 /* {0x04, "MCS-3/P2"} */,
			MCS_3 /* {0x05, "MCS-3/P3"} */,
			MCS_3 /* {0x06, "MCS-3/P1 with padding"} */,
			MCS_3 /* {0x07, "MCS-3/P2 with padding"} */,
			MCS_3 /* {0x08, "MCS-3/P3 with padding"} */,
			MCS_2 /* {0x09, "MCS-2/P1"} */,
			MCS_2 /* {0x0A, "MCS-2/P2"} */,
			MCS_1 /* {0x0B, "MCS-1/P1"} */,
			MCS_1 /* {0x0C, "MCS-1/P2"} */,
			MCS_2 /* {0x0D, "MCS-2/P1 with padding"} */,
			MCS_2 /* {0x0E, "MCS-2/P2 with padding"} */,
			MCS_0 /* {0x0F, "MCS-0"} */
		};
		return egprs_Header_type3_coding_puncturing_scheme_to_mcs[cps];
	}

	function f_rlcmac_cps_htype_to_mcs(uint3_t cps, EgprsHeaderType htype) return CodingScheme {
		select (htype) {
		case (RLCMAC_HDR_TYPE_1) { return f_rlcmac_cps_htype1_to_mcs(cps); }
		case (RLCMAC_HDR_TYPE_2) { return f_rlcmac_cps_htype2_to_mcs(cps); }
		case (RLCMAC_HDR_TYPE_3) { return f_rlcmac_cps_htype3_to_mcs(cps); }
		}
		//TODO: return error here.
		return CS_1;
	}

	function f_rlcmac_mcs_to_cps_htype1(CodingScheme mcs, uint2_t part, boolean with_padding) return uint5_t {
		//TODO: implement similar to f_rlcmac_mcs_to_cps_htype3()
		//TODO: return error here.
		return 0;
	}

	function f_rlcmac_mcs_to_cps_htype2(CodingScheme mcs, uint2_t part, boolean with_padding) return uint5_t {
		//TODO: implement similar to f_rlcmac_mcs_to_cps_htype3()
		//TODO: return error here.
		return 0;
	}

	function f_rlcmac_mcs_to_cps_htype3(CodingScheme mcs, uint2_t part, boolean with_padding) return uint5_t {
		select (mcs) {
		case (MCS_4) {
				select (part) {
				case (1) { return 0; /* {0x00, "MCS-4/P1"} */ }
				case (2) { return 1; /* {0x01, "MCS-4/P2"} */ }
				case (3) { return 2; /* {0x01, "MCS-4/P2"} */ }
				}
			}
		case (MCS_3) {
				if (not with_padding) {
					select (part) {
					case (1) { return 3; /* {0x03, "MCS-3/P1"} */ }
					case (2) { return 4; /* {0x04, "MCS-3/P2"} */ }
					case (3) { return 5; /* {0x05, "MCS-3/P3"} */ }
					}
				} else {
					select (part) {
					case (1) { return 6; /* {0x06, "MCS-3/P1 with padding"} */ }
					case (2) { return 7; /* {0x07, "MCS-3/P2 with padding"} */ }
					case (3) { return 8; /* {0x08, "MCS-3/P3 with padding"} */ }
					}
				}
			}
		case (MCS_2) {
				if (not with_padding) {
					select (part) {
					case (1) { return 9; /* {0x09, "MCS-2/P1"} */ }
					case (2) { return 10; /* {0x0A, "MCS-2/P2"} */ }
					}
				} else {
					select (part) {
					case (1) { return 13; /* {0x0D, "MCS-2/P1 with padding"} */ }
					case (2) { return 14; /* {0x0E, "MCS-2/P2 with padding"} */}
					}
				}
			}
		case (MCS_1) {
				select (part) {
				case (1) { return 11; /* {0x0B, "MCS-1/P1"} */ }
				case (2) { return 12; /* {0x0C, "MCS-1/P2"} */ }
				}
			}
		case (MCS_0) { return 15;  /* {0x0F, "MCS-0"} */ }
		}
		//TODO: return error here.
		return 0;
	}

	function f_rlcmac_mcs_to_cps(CodingScheme mcs, uint2_t part, boolean with_padding := false) return uint5_t {

		var EgprsHeaderType htype := f_rlcmac_mcs2headertype(mcs);
		select (htype) {
		case (RLCMAC_HDR_TYPE_1) { return f_rlcmac_mcs_to_cps_htype1(mcs, part, with_padding); }
		case (RLCMAC_HDR_TYPE_2) { return f_rlcmac_mcs_to_cps_htype2(mcs, part, with_padding); }
		case (RLCMAC_HDR_TYPE_3) { return f_rlcmac_mcs_to_cps_htype3(mcs, part, with_padding); }
		}
		//TODO: return error here.
		return 0;
	}

	template (value) RlcmacUlBlock ts_RLC_UL_CTRL_ACK(RlcmacUlCtrlMsg ctrl,
							MacPayloadType pt := MAC_PT_RLCMAC_NO_OPT,
							boolean retry := false) := {
		ctrl := {
			mac_hdr := {
				payload_type := pt,
				spare := '00000'B,
				retry := retry
			},
			payload := ctrl
		}
	}

	/* Send Template for Downlink ACK/NACK */
	template RlcmacUlBlock ts_RLCMAC_DL_ACK_NACK(template uint5_t tfi, AckNackDescription andesc, boolean retry := false) := {
		ctrl := {
			mac_hdr := {
				payload_type := MAC_PT_RLCMAC_NO_OPT,
				spare := '00000'B,
				retry := retry
			},
			payload := {
				msg_type := PACKET_DL_ACK_NACK,
				u := {
					dl_ack_nack := {
						dl_tfi := tfi,
						ack_nack_desc := andesc,
						chreq_desc_presence := '0'B,
						chreq_desc := omit,
						ch_qual_rep := c_ChQualRep_default
					}
				}
			}
		}
	}

	/* Template for uplink Data block */
	template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
						template LlcBlocks blocks := {}, template boolean stall := false) := {
		data := {
			mac_hdr := {
				payload_type := MAC_PT_RLC_DATA,
				countdown := cv,
				stall_ind := false,
				retry := false,
				spare := '0'B,
				pfi_ind := false,
				tfi := tfi,
				tlli_ind := false,
				bsn := bsn,
				e := false
			},
			tlli := omit,
			pfi := omit,
			blocks := blocks
		}
	}
	template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
						     template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) := {
		data := {
			mac_hdr := {
				payload_type := MAC_PT_RLC_DATA,
				countdown := cv,
				stall_ind := false,
				retry := false,
				spare := '0'B,
				pfi_ind := false,
				tfi := tfi,
				tlli_ind := true,
				bsn := bsn,
				e := false
			},
			tlli := tlli,
			pfi := omit,
			blocks := blocks
		}
	}

	/* Template for uplink Data block */
	template RlcmacUlBlock t_RLCMAC_UL_EGPRS_DATA(CodingScheme mcs,
						      template uint5_t tfi, template uint4_t cv,
						      template uint11_t bsn1, template EgprsLlcBlocks blocks := {}) := {
		data_egprs := {
			mac_hdr := {
				header_type := f_rlcmac_mcs2headertype(mcs),
				tfi := tfi,
				countdown := cv,
				foi_si := '0'B,
				r_ri := '0'B,
				bsn1 := bsn1,
				cps := f_rlcmac_mcs_to_cps(mcs, 1, false),
				pfi_ind := false,
				rsb := '0'B,
				spb := '00'B
			},
			tlli_ind := false,
			e := false,
			tlli := omit,
			pfi := omit,
			blocks := blocks
		}
	}

	template DlMacHeader t_RLCMAC_DlMacH(template (present) MacPayloadType pt,
					     template (present) boolean rrbp_valid,
					     template (present) MacRrbp rrbp,
					     template (present) uint3_t usf) := {
		payload_type := pt,
		rrbp := rrbp,
		rrbp_valid := rrbp_valid,
		usf := usf
	}

	template RlcmacDlBlock tr_RLCMAC_DUMMY_CTRL(template uint3_t usf := ?, template PageMode page_mode := ?) := {
		ctrl := {
			mac_hdr := {
				payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
				rrbp:= ?,
				rrbp_valid := ?,
				usf := usf
			},
			opt := *,
			payload := {
				msg_type := PACKET_DL_DUMMY_CTRL,
				u := {
					dl_dummy := {
						page_mode := page_mode,
						persistence_levels_present := ?,
						persistence_levels := *
					}
				}
			}
		}
	}

	template RlcmacDlBlock tr_RLCMAC_DL_PACKET_ASS(template uint3_t usf := ?) := {
		ctrl := {
			mac_hdr := {
				payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
				rrbp:= ?,
				rrbp_valid := ?,
				usf := usf
			},
			opt := *,
			payload := {
				msg_type := PACKET_DL_ASSIGNMENT,
				u := {
					dl_assignment := {
						page_mode := ?,
						pres1 := ?,
						persistence_levels := *,
						tfi_or_tlli := ?
					}
				}
			}
		}
	}

	template RlcmacDlBlock tr_RLCMAC_UL_PACKET_ASS(template uint3_t usf := ?) := {
		ctrl := {
			mac_hdr := {
				payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
				rrbp:= ?,
				rrbp_valid := ?,
				usf := usf
			},
			opt := *,
			payload := {
				msg_type := PACKET_UL_ASSIGNMENT,
				u := {
					ul_assignment := {
						page_mode := ?,
						persistence_levels_present := ?,
						persistence_levels := *,
						identity := ?,
						is_egprs := ?,  /* msg escape */
						gprs := *,
						egprs := *
					}
				}
			}
		}
	}

	template RlcmacDlBlock tr_RLCMAC_UL_PACKET_ASS_GPRS(template uint3_t usf := ?, template PktUlAssGprs gprs := ?)
		modifies tr_RLCMAC_UL_PACKET_ASS := {
		ctrl := {
			payload := {
				u := {
					ul_assignment := {
						is_egprs := '0'B,
						gprs := gprs,
						egprs := omit
					}
				}
			}
		}
	}

	template RlcmacDlBlock tr_RLCMAC_UL_PACKET_ASS_EGPRS(template uint3_t usf := ?, template PktUlAssEgprs egprs := ?)
		modifies tr_RLCMAC_UL_PACKET_ASS := {
		ctrl := {
			payload := {
				u := {
					ul_assignment := {
						is_egprs := '1'B,
						gprs := omit,
						egprs := egprs
					}
				}
			}
		}
	}

	/* Receive Template for Uplink ACK/NACK */
	template RlcmacDlBlock tr_RLCMAC_UL_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := {
		ctrl := {
			mac_hdr := {
				payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
				rrbp:= ?,
				rrbp_valid := ?,
				usf := ?
			},
			opt := *,
			payload := {
				msg_type := PACKET_UL_ACK_NACK,
				u := {
					ul_ack_nack := {
						page_mode := ?,
						msg_excape := ?,
						uplink_tfi := ul_tfi,
						is_egprs := '0'B,
						gprs := {
							ch_coding_cmd := ?,
							ack_nack_desc := ?,
							cont_res_tlli_present := ?,
							cont_res_tlli := tlli,
							pkt_ta_present := ?,
							pkt_ta := *,
							pwr_ctrl_present := ?,
							pwr_ctrl := *
						}
					}
				}
			}
		}
	}

	template RlcmacDlBlock tr_RLCMAC_PACKET_PAG_REQ(template uint3_t usf := ?) := {
		ctrl := {
			mac_hdr := {
				payload_type := MAC_PT_RLCMAC_NO_OPT,
				rrbp:= ?,
				rrbp_valid := ?,
				usf := usf
			},
			opt := *,
			payload := {
				msg_type := PACKET_PAGING_REQUEST,
				u := {
					paging := {
						page_mode := ?,
						persistence_levels_present := ?,
						persistence_levels := *,
						nln_present := ?,
						nln := *,
						repeated_pageinfo_present := ?,
						repeated_pageinfo := *
					}
				}
			}
		}
	}

	/* Either GPRS or EGPRS data block with arbitrary contents */
	template RlcmacDlBlock tr_RLCMAC_DATA := (tr_RLCMAC_DATA_GPRS, tr_RLCMAC_DATA_EGPRS);

	template RlcmacDlBlock tr_RLCMAC_DATA_GPRS(template (present) boolean rrbp_valid := ?,
						   template (present) MacRrbp rrbp := ?,
						   template (present) uint3_t usf := ?) := {
		data := {
			mac_hdr := {
				mac_hdr := {
					payload_type := MAC_PT_RLC_DATA,
					rrbp := rrbp,
					rrbp_valid := rrbp_valid,
					usf := usf
				},
				hdr_ext := ?
			},
			blocks := ?
		}
	}

	template RlcmacDlBlock tr_RLCMAC_DATA_EGPRS := {
		data_egprs := {
			mac_hdr := ?,
			fbi := ?,
			e := ?,
			blocks := ?
		}
	}

	/* Template for Uplink MAC Control Header */
	template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := {
		payload_type := pt,
		spare := '00000'B,
		retry := retry
	}

	/* Template for Uplink Control ACK */
	template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := {
		ctrl := {
			mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT),
			payload := {
				msg_type := PACKET_CONTROL_ACK,
				u := {
					ctrl_ack := {
						tlli := tlli,
						ctrl_ack := ack
					}
				}
			}
		}
	}

	/* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */
	template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, boolean more := false, boolean e := true) := {
		/* let encoder figure out the header */
		hdr := omit,
		payload := data
	}

	/* Template for a LlcBlock (part of a LLC frame inside RlcMacEgprs?lDataBlock */
	template EgprsLlcBlock t_RLCMAC_LLCBLOCK_EGPRS(octetstring data, boolean e := true) := {
		/* let encoder figure out the header */
		hdr := omit,
		payload := data
	}

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