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

/* (C) 2017-2018 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 RLCMAC_Types {
	import from General_Types all;
	import from Osmocom_Types all;
	import from GSM_Types all;
	import from RLCMAC_CSN1_Types all;

	/* TS 44.060 10.4.7 */
	type enumerated MacPayloadType {
		MAC_PT_RLC_DATA			('00'B),
		MAC_PT_RLCMAC_NO_OPT		('01'B),
		MAC_PT_RLCMAC_OPT		('10'B),
		MAC_PT_RESERVED			('11'B)
	} with { variant "FIELDLENGTH(2)" };

	/* TS 44.060 10.4.5 */
	type enumerated MacRrbp {
		RRBP_Nplus13_mod_2715648	('00'B),
		RRBP_Nplus17_or_18_mod_2715648	('01'B),
		RRBP_Nplus21_or_22_mod_2715648	('10'B),
		RRBP_Nplus26_mod_2715648	('11'B)
	} with { variant "FIELDLENGTH(2)" };

	type enumerated EgprsHeaderType {
		RLCMAC_HDR_TYPE_1,
		RLCMAC_HDR_TYPE_2,
		RLCMAC_HDR_TYPE_3
	};

	type enumerated CodingScheme {
		CS_1,
		CS_2,
		CS_3,
		CS_4,
		MCS_0,
		MCS_1,
		MCS_2,
		MCS_3,
		MCS_4,
		MCS_5,
		MCS_6,
		MCS_7,
		MCS_8,
		MCS_9
		//MCS5_7, ?
		// MCS6_9 ?
	};

	/* Partof DL RLC data block and DL RLC/MAC ctrl block */
	type record DlMacHeader {
		MacPayloadType	payload_type,
		MacRrbp		rrbp,
		boolean		rrbp_valid,
		uint3_t		usf
	} with {
		variant (rrbp_valid) "FIELDLENGTH(1)"
	};

	/* TS 44.060 10.4.10a */
	type enumerated PowerReduction {
		PWR_RED_0_to_3dB		('00'B),
		PWR_RED_3_to_7dB		('01'B),
		PWR_RED_7_to_10dB		('10'B),
		PWR_RED_RESERVED		('11'B)
	} with { variant "FIELDLENGTH(2)" };

	/* TS 44.060 10.4.9d */
	type enumerated DirectionBit {
		DIR_UPLINK_TBF		('0'B),
		DIR_DOWNLINK_TBF	('1'B)
	} with { variant "FIELDLENGTH(1)" };

	type record TfiOctet {
		/* PR, TFI, D */
		PowerReduction	pr,
		uint5_t		tfi,
		DirectionBit	d
	} with { variant "" };

	type record RbsnExtOctet {
		uint3_t		rbsn_e,
		BIT1		fs_e,
		BIT4		spare
	} with { variant "" };

	type record DlCtrlOptOctets {
		/* RBSN, RTI, FS, AC (optional, depending on mac_hdr.payload_type) */
		BIT1		rbsn,
		uint5_t		rti,
		boolean		fs,
		boolean		tfi_octet_present,
		TfiOctet	tfi optional,
		RbsnExtOctet	rbsn_ext optional
	} with {
		variant (fs) "FIELDLENGTH(1)"
		variant (tfi_octet_present) "FIELDLENGTH(1)"
		variant (tfi) "PRESENCE(tfi_octet_present = true)"
		variant (rbsn_ext) "PRESENCE(rbsn='1'B, fs=false)"
	};

	/* TS 44.060 10.3.1 Downlink RLC/MAC control block */
	type record RlcmacDlCtrlBlock {
		DlMacHeader		mac_hdr,
		DlCtrlOptOctets		opt optional,
		RlcmacDlCtrlMsg		payload
	} with {
		variant (opt) "PRESENCE(mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
	};

	external function enc_RlcmacDlCtrlBlock(in RlcmacDlCtrlBlock si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_RlcmacDlCtrlBlock(in octetstring stream) return RlcmacDlCtrlBlock
		with { extension "prototype(convert) decode(RAW)" };

	type record UlMacCtrlHeader {
		MacPayloadType		payload_type,
		BIT5			spare,
		boolean			retry
	} with { variant (retry) "FIELDLENGTH(1)" };

	/* TS 44.060 10.3.2 UplinkRLC/MAC control block */
	type record RlcmacUlCtrlBlock {
		UlMacCtrlHeader		mac_hdr,
		RlcmacUlCtrlMsg		payload
	} with { variant "" };

	external function enc_RlcmacUlCtrlBlock(in RlcmacUlCtrlBlock si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_RlcmacUlCtrlBlock(in octetstring stream) return RlcmacUlCtrlBlock
		with { extension "prototype(convert) decode(RAW)" };

	/* a single RLC block / LLC-segment */
	type record LlcBlockHdr {
		uint6_t		length_ind,
		/* 1 = new LLC PDU starts */
		boolean		more,
		/* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
		boolean		e
	} with {
		variant (e) "FIELDLENGTH(1)"
		encode "RAW"
	};

	external function enc_LlcBlockHdr(in LlcBlockHdr si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_LlcBlockHdr(in octetstring stream) return LlcBlockHdr
		with { extension "prototype(convert) decode(RAW)" };

	type record LlcBlock {
		/* Header is only present if LI field was present */
		LlcBlockHdr	hdr optional,
		octetstring 	payload
	} with { variant "" };
	type record of LlcBlock LlcBlocks;

	/* TS 44.060 10.2.1 Downlink RLC data block */
	type record DlMacHdrDataExt {
		/* Octet 1 */
		PowerReduction		pr,
		BIT1			spare,
		uint4_t			tfi, /* 3 or 4? */
		boolean			fbi,
		/* Octet 2 */
		uint7_t			bsn,
		boolean			e
	} with {
		variant (e) "FIELDLENGTH(1)"
	};
	type record DlMacDataHeader {
		DlMacHeader		mac_hdr,
		DlMacHdrDataExt		hdr_ext
	} with { variant "" };
	type record RlcmacDlDataBlock {
		DlMacDataHeader		mac_hdr,
		/* Octet 3..M / N: manual C++ Decoder */
		LlcBlocks		blocks
	} with {
		variant ""
	};

	external function enc_RlcmacDlDataBlock(in RlcmacDlDataBlock si) return octetstring;
	external function dec_RlcmacDlDataBlock(in octetstring stream) return RlcmacDlDataBlock;


	/* a single RLC block / LLC-segment */
	type record EgprsLlcBlockHdr {
		uint7_t		length_ind,
		/* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
		boolean		e
	} with {
		variant (e) "FIELDLENGTH(1)"
		encode "RAW"
	};

	external function enc_EgprsLlcBlockHdr(in EgprsLlcBlockHdr si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_EgprsLlcBlockHdr(in octetstring stream) return EgprsLlcBlockHdr
		with { extension "prototype(convert) decode(RAW)" };

	type record EgprsLlcBlock {
		/* Header is only present if LI field was present */
		EgprsLlcBlockHdr	hdr optional,
		octetstring 		payload
	} with { variant "" };
	type record of EgprsLlcBlock EgprsLlcBlocks;

	/* TS 44.060 10.3a.1.1 EGPRS downlink RLC data block, manual c++ encoder/decoder */
	type record EgprsDlMacDataHeader {
		EgprsHeaderType	header_type, /* Set internally by decoder */
		uint5_t		tfi,
		MacRrbp		rrbp,
		BIT2		esp,
		uint3_t		usf,
		uint14_t	bsn1,
		uint8_t		bsn2_offset,
		uint2_t		pr, /* power reduction */
		uint2_t		spb,
		uint4_t		cps
	} with { variant "" };
	/* Manual C++ Decoder: */
	type record RlcmacDlEgprsDataBlock {
		EgprsDlMacDataHeader	mac_hdr,
		boolean			fbi,
		boolean			e,
		EgprsLlcBlocks		blocks
	} with {
		variant (fbi) "FIELDLENGTH(1)"
		variant (e) "FIELDLENGTH(1)"
	};

	/* TS 44.060 10.2.2 */
	type record UlMacDataHeader {
		/* Octet 0 */
		MacPayloadType		payload_type,
		uint4_t			countdown,
		boolean			stall_ind,
		boolean			retry,
		/* Octet 1 */
		BIT1			spare,
		boolean			pfi_ind,
		uint5_t			tfi,
		boolean			tlli_ind,
		/* Octet 2 */
		uint7_t			bsn,
		boolean			e
	} with {
		variant (stall_ind)	"FIELDLENGTH(1)"
		variant (retry)		"FIELDLENGTH(1)"
		variant (pfi_ind)	"FIELDLENGTH(1)"
		variant (tlli_ind)	"FIELDLENGTH(1)"
		variant (e)		"FIELDLENGTH(1)"
	};

	type record RlcMacUlPfi {
		uint7_t			pfi,
		boolean			m
	} with {
		variant (m) "FIELDLENGTH(1)"
	};

	/* TS 44.060 10.3a.1.1 10.3a.4 EGPRS Uplink RLC/MAC header, manual c++ encoder/decoder */
	type record EgprsUlMacDataHeader {
		EgprsHeaderType	header_type, /* Set internally by decoder */
		uint5_t		tfi,
		uint4_t		countdown,
		BIT1		foi_si,
		BIT1		r_ri,
		uint11_t	bsn1,
		uint4_t		cps,
		boolean		pfi_ind,
		BIT1		rsb,
		BIT2		spb
	} with {
		variant (pfi_ind) "FIELDLENGTH(1)"
	};
	/* Manual C++ Decoder:  10.3a.2.1 EGPRS Uplink RLC data block */
	type record RlcmacUlEgprsDataBlock {
		EgprsUlMacDataHeader	mac_hdr,
		boolean			tlli_ind,
		boolean			e,
		/* Octet 3 ... M (optional): manual C++ Decoder */
		GprsTlli		tlli optional,
		RlcMacUlPfi		pfi optional,
		EgprsLlcBlocks		blocks
	} with {
		variant (tlli_ind) "FIELDLENGTH(1)"
		variant (e) "FIELDLENGTH(1)"
	};

	/* TS 44.060 10.2.2 */
	type record RlcmacUlDataBlock {
		/* MAC header */
		UlMacDataHeader		mac_hdr,
		/* Octet 3 ... M (optional): manual C++ Decoder */
		GprsTlli		tlli optional,
		RlcMacUlPfi		pfi optional,
		LlcBlocks		blocks
	} with {
		variant (tlli) "PRESENCE(mac_hdr.tlli_ind = true)"
		variant (pfi) "PRESENCE(mac_hdr.pfi_ind = true)"
	};

	external function enc_RlcmacUlDataBlock(in RlcmacUlDataBlock si) return octetstring;
	external function dec_RlcmacUlDataBlock(in octetstring stream) return RlcmacUlDataBlock;

	type union RlcmacUlBlock {
		RlcmacUlDataBlock	data,
		RlcmacUlEgprsDataBlock	data_egprs,
		RlcmacUlCtrlBlock	ctrl
	} with {
		variant "TAG(data, mac_hdr.payload_type = MAC_PT_RLC_DATA;
			     ctrl, {mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT,
				    mac_hdr.payload_type = MAC_PT_RLCMAC_OPT};
			     data_egprs, {mac_hdr.header_type = RLCMAC_HDR_TYPE_1,
					  mac_hdr.header_type = RLCMAC_HDR_TYPE_2,
					  mac_hdr.header_type = RLCMAC_HDR_TYPE_3}
			     )"
	};

	/* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
	 * use auto-generated functions here, as they would decode those sub-types
	 * based on the RAW coder, not baed on the manual C++ functions */
	external function enc_RlcmacUlBlock(in RlcmacUlBlock si) return octetstring;
	external function dec_RlcmacUlBlock(in octetstring stream) return RlcmacUlBlock;

	type union RlcmacDlBlock {
		RlcmacDlDataBlock	data,
		RlcmacDlEgprsDataBlock	data_egprs,
		RlcmacDlCtrlBlock	ctrl
	} with {
		variant "TAG(data, mac_hdr.mac_hdr.payload_type = MAC_PT_RLC_DATA;
			     ctrl, {mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT,
				    mac_hdr.payload_type = MAC_PT_RLCMAC_OPT};
			     data_egprs, {mac_hdr.header_type = RLCMAC_HDR_TYPE_1,
					  mac_hdr.header_type = RLCMAC_HDR_TYPE_2,
					  mac_hdr.header_type = RLCMAC_HDR_TYPE_3}
			     )"
	};

	/* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
	 * use auto-generated functions here, as they would decode those sub-types
	 * based on the RAW coder, not baed on the manual C++ functions */
	external function enc_RlcmacDlBlock(in RlcmacDlBlock si) return octetstring;
	external function dec_RlcmacDlBlock(in octetstring stream) return RlcmacDlBlock;

/************************
 * PTCCH/D (Packet Timing Advance Control Channel) message.
 * TODO: add a spec. reference to the message format definition.
 *************************/
	type record PTCCHTimingAdvanceIE {
		BIT1			spare ('0'B),
		uint7_t			ta_val
	} with { variant "" };
	type record of PTCCHTimingAdvanceIE PTCCHTimingAdvanceIEs;
	type record PTCCHDownlinkMsg {
		PTCCHTimingAdvanceIEs	ta_idx length(16),
		octetstring		padding length(7)
	} with { variant "" };

	external function enc_PTCCHDownlinkMsg(in PTCCHDownlinkMsg si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_PTCCHDownlinkMsg(in octetstring stream) return PTCCHDownlinkMsg
		with { extension "prototype(convert) decode(RAW)" };

	template PTCCHDownlinkMsg tr_PTCCHDownlinkMsg(
		template (present) uint7_t tai0_ta := ?,
		template (present) uint7_t tai1_ta := ?,
		template (present) uint7_t tai2_ta := ?,
		template (present) uint7_t tai3_ta := ?,
		template (present) uint7_t tai4_ta := ?,
		template (present) uint7_t tai5_ta := ?,
		template (present) uint7_t tai6_ta := ?,
		template (present) uint7_t tai7_ta := ?,
		template (present) uint7_t tai8_ta := ?,
		template (present) uint7_t tai9_ta := ?,
		template (present) uint7_t tai10_ta := ?,
		template (present) uint7_t tai11_ta := ?,
		template (present) uint7_t tai12_ta := ?,
		template (present) uint7_t tai13_ta := ?,
		template (present) uint7_t tai14_ta := ?,
		template (present) uint7_t tai15_ta := ?
	) := {
		ta_idx := {
			{ spare := '0'B, ta_val := tai0_ta },
			{ spare := '0'B, ta_val := tai1_ta },
			{ spare := '0'B, ta_val := tai2_ta },
			{ spare := '0'B, ta_val := tai3_ta },
			{ spare := '0'B, ta_val := tai4_ta },
			{ spare := '0'B, ta_val := tai5_ta },
			{ spare := '0'B, ta_val := tai6_ta },
			{ spare := '0'B, ta_val := tai7_ta },
			{ spare := '0'B, ta_val := tai8_ta },
			{ spare := '0'B, ta_val := tai9_ta },
			{ spare := '0'B, ta_val := tai10_ta },
			{ spare := '0'B, ta_val := tai11_ta },
			{ spare := '0'B, ta_val := tai12_ta },
			{ spare := '0'B, ta_val := tai13_ta },
			{ spare := '0'B, ta_val := tai14_ta },
			{ spare := '0'B, ta_val := tai15_ta }
		},
		padding := '2B2B2B2B2B2B2B'O
	}


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