blob: 76aeb22e562476d7b9675cc2d23a020b3528107d [file] [log] [blame]
Harald Welte484160b2017-07-28 13:30:24 +02001/* TITAN REW encode/decode definitions for 3GPP TS 44.060 RLC/MAC Blocks */
Harald Welte34b5a952019-05-27 11:54:11 +02002
3/* (C) 2017-2018 Harald Welte <laforge@gnumonks.org>
4 * All rights reserved.
5 *
6 * Released under the terms of GNU General Public License, Version 2 or
7 * (at your option) any later version.
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
Harald Welte484160b2017-07-28 13:30:24 +020012module RLCMAC_Types {
13 import from General_Types all;
14 import from Osmocom_Types all;
15 import from GSM_Types all;
Harald Welte9d348522017-08-01 00:27:39 +020016 import from RLCMAC_CSN1_Types all;
Harald Welte484160b2017-07-28 13:30:24 +020017
18 /* TS 44.060 10.4.7 */
19 type enumerated MacPayloadType {
20 MAC_PT_RLC_DATA ('00'B),
21 MAC_PT_RLCMAC_NO_OPT ('01'B),
22 MAC_PT_RLCMAC_OPT ('10'B),
23 MAC_PT_RESERVED ('11'B)
24 } with { variant "FIELDLENGTH(2)" };
25
26 /* TS 44.060 10.4.5 */
27 type enumerated MacRrbp {
28 RRBP_Nplus13_mod_2715648 ('00'B),
29 RRBP_Nplus17_or_18_mod_2715648 ('01'B),
Harald Welte1cd673d2018-03-02 21:41:31 +010030 RRBP_Nplus21_or_22_mod_2715648 ('10'B),
Harald Welte484160b2017-07-28 13:30:24 +020031 RRBP_Nplus26_mod_2715648 ('11'B)
32 } with { variant "FIELDLENGTH(2)" };
33
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +020034 type enumerated EgprsHeaderType {
35 RLCMAC_HDR_TYPE_1,
36 RLCMAC_HDR_TYPE_2,
37 RLCMAC_HDR_TYPE_3
38 };
39
Pau Espin Pedroldc9666f2020-03-18 20:30:16 +010040 type enumerated CodingScheme {
41 CS_1,
42 CS_2,
43 CS_3,
44 CS_4,
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +020045 MCS_0,
Pau Espin Pedroldc9666f2020-03-18 20:30:16 +010046 MCS_1,
47 MCS_2,
48 MCS_3,
49 MCS_4,
50 MCS_5,
51 MCS_6,
52 MCS_7,
53 MCS_8,
54 MCS_9
55 //MCS5_7, ?
56 // MCS6_9 ?
57 };
Pau Espin Pedrol27d6af52020-04-30 20:13:32 +020058 type record of CodingScheme CodingSchemeArray;
Pau Espin Pedroldc9666f2020-03-18 20:30:16 +010059
Harald Welte484160b2017-07-28 13:30:24 +020060 /* Partof DL RLC data block and DL RLC/MAC ctrl block */
61 type record DlMacHeader {
62 MacPayloadType payload_type,
63 MacRrbp rrbp,
64 boolean rrbp_valid,
65 uint3_t usf
66 } with {
67 variant (rrbp_valid) "FIELDLENGTH(1)"
68 };
69
70 /* TS 44.060 10.4.10a */
71 type enumerated PowerReduction {
72 PWR_RED_0_to_3dB ('00'B),
73 PWR_RED_3_to_7dB ('01'B),
74 PWR_RED_7_to_10dB ('10'B),
75 PWR_RED_RESERVED ('11'B)
76 } with { variant "FIELDLENGTH(2)" };
77
78 /* TS 44.060 10.4.9d */
79 type enumerated DirectionBit {
80 DIR_UPLINK_TBF ('0'B),
81 DIR_DOWNLINK_TBF ('1'B)
82 } with { variant "FIELDLENGTH(1)" };
83
84 type record TfiOctet {
85 /* PR, TFI, D */
86 PowerReduction pr,
87 uint5_t tfi,
88 DirectionBit d
89 } with { variant "" };
90
91 type record RbsnExtOctet {
92 uint3_t rbsn_e,
93 BIT1 fs_e,
94 BIT4 spare
95 } with { variant "" };
96
97 type record DlCtrlOptOctets {
98 /* RBSN, RTI, FS, AC (optional, depending on mac_hdr.payload_type) */
99 BIT1 rbsn,
100 uint5_t rti,
101 boolean fs,
102 boolean tfi_octet_present,
103 TfiOctet tfi optional,
104 RbsnExtOctet rbsn_ext optional
105 } with {
106 variant (fs) "FIELDLENGTH(1)"
107 variant (tfi_octet_present) "FIELDLENGTH(1)"
108 variant (tfi) "PRESENCE(tfi_octet_present = true)"
109 variant (rbsn_ext) "PRESENCE(rbsn='1'B, fs=false)"
110 };
111
112 /* TS 44.060 10.3.1 Downlink RLC/MAC control block */
113 type record RlcmacDlCtrlBlock {
114 DlMacHeader mac_hdr,
115 DlCtrlOptOctets opt optional,
Harald Welte9d348522017-08-01 00:27:39 +0200116 RlcmacDlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +0200117 } with {
Pau Espin Pedrolcb00c522020-11-06 19:52:05 +0100118 /* Automatic padding by RAW encoder seems to causing problems
119 * due to padding sequence 2b inserted shifted from octet
120 * boundary on some messags. See UL CTRL blocks in TC_t3193.
121 * See 3GPP TS 44.060 Figure 11.1 (below)
122 * variant "PADDING(184), PADDING_PATTERN('00101011'B)" */
Harald Welte484160b2017-07-28 13:30:24 +0200123 variant (opt) "PRESENCE(mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
124 };
125
126 external function enc_RlcmacDlCtrlBlock(in RlcmacDlCtrlBlock si) return octetstring
127 with { extension "prototype(convert) encode(RAW)" };
128 external function dec_RlcmacDlCtrlBlock(in octetstring stream) return RlcmacDlCtrlBlock
129 with { extension "prototype(convert) decode(RAW)" };
130
131 type record UlMacCtrlHeader {
Harald Welteefbc2fc2017-07-31 00:05:23 +0200132 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200133 BIT5 spare,
134 boolean retry
135 } with { variant (retry) "FIELDLENGTH(1)" };
136
137 /* TS 44.060 10.3.2 UplinkRLC/MAC control block */
138 type record RlcmacUlCtrlBlock {
139 UlMacCtrlHeader mac_hdr,
Harald Welte9d348522017-08-01 00:27:39 +0200140 RlcmacUlCtrlMsg payload
Pau Espin Pedrolcb00c522020-11-06 19:52:05 +0100141 } with {
142 /* Automatic padding by RAW encoder seems to causing problems
143 * due to padding sequence 2b inserted shifted from octet
144 * boundary on some messags. See UL CTRL blocks in TC_t3193.
145 * See 3GPP TS 44.060 Figure 11.1 (below)
146 * variant "PADDING(184), PADDING_PATTERN('00101011'B)" */
147 variant ""
148 };
Harald Welte484160b2017-07-28 13:30:24 +0200149
150 external function enc_RlcmacUlCtrlBlock(in RlcmacUlCtrlBlock si) return octetstring
151 with { extension "prototype(convert) encode(RAW)" };
152 external function dec_RlcmacUlCtrlBlock(in octetstring stream) return RlcmacUlCtrlBlock
153 with { extension "prototype(convert) decode(RAW)" };
154
155 /* a single RLC block / LLC-segment */
Harald Welte43e060a2017-07-30 22:38:03 +0200156 type record LlcBlockHdr {
Harald Welte484160b2017-07-28 13:30:24 +0200157 uint6_t length_ind,
158 /* 1 = new LLC PDU starts */
Harald Welte060e27a2018-03-03 20:38:19 +0100159 boolean more,
Harald Welte484160b2017-07-28 13:30:24 +0200160 /* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
Harald Welte43e060a2017-07-30 22:38:03 +0200161 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200162 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200163 variant (e) "FIELDLENGTH(1)"
Harald Weltecc5c1152018-03-09 12:54:01 +0100164 encode "RAW"
Harald Welte484160b2017-07-28 13:30:24 +0200165 };
Harald Weltecc5c1152018-03-09 12:54:01 +0100166
167 external function enc_LlcBlockHdr(in LlcBlockHdr si) return octetstring
168 with { extension "prototype(convert) encode(RAW)" };
169 external function dec_LlcBlockHdr(in octetstring stream) return LlcBlockHdr
170 with { extension "prototype(convert) decode(RAW)" };
171
Harald Welte43e060a2017-07-30 22:38:03 +0200172 type record LlcBlock {
173 /* Header is only present if LI field was present */
Harald Welte060e27a2018-03-03 20:38:19 +0100174 LlcBlockHdr hdr optional,
Harald Welte43e060a2017-07-30 22:38:03 +0200175 octetstring payload
176 } with { variant "" };
177 type record of LlcBlock LlcBlocks;
Harald Welte484160b2017-07-28 13:30:24 +0200178
179 /* TS 44.060 10.2.1 Downlink RLC data block */
Harald Welte43e060a2017-07-30 22:38:03 +0200180 type record DlMacHdrDataExt {
Harald Welte484160b2017-07-28 13:30:24 +0200181 /* Octet 1 */
Harald Welte484160b2017-07-28 13:30:24 +0200182 PowerReduction pr,
183 BIT1 spare,
184 uint4_t tfi, /* 3 or 4? */
185 boolean fbi,
Harald Welte43e060a2017-07-30 22:38:03 +0200186 /* Octet 2 */
Harald Welte484160b2017-07-28 13:30:24 +0200187 uint7_t bsn,
Harald Welte43e060a2017-07-30 22:38:03 +0200188 boolean e
189 } with {
190 variant (e) "FIELDLENGTH(1)"
191 };
192 type record DlMacDataHeader {
193 DlMacHeader mac_hdr,
194 DlMacHdrDataExt hdr_ext
Harald Welte484160b2017-07-28 13:30:24 +0200195 } with { variant "" };
Harald Welte43e060a2017-07-30 22:38:03 +0200196 type record RlcmacDlDataBlock {
Pau Espin Pedrol5abfded2020-11-03 17:30:44 +0100197 CodingScheme cs, /* Provided by C++ Decoder */
Harald Welte43e060a2017-07-30 22:38:03 +0200198 DlMacDataHeader mac_hdr,
199 /* Octet 3..M / N: manual C++ Decoder */
200 LlcBlocks blocks
201 } with {
202 variant ""
203 };
Harald Welte484160b2017-07-28 13:30:24 +0200204
Harald Welte43e060a2017-07-30 22:38:03 +0200205 external function enc_RlcmacDlDataBlock(in RlcmacDlDataBlock si) return octetstring;
206 external function dec_RlcmacDlDataBlock(in octetstring stream) return RlcmacDlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200207
208
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200209 /* a single RLC block / LLC-segment */
210 type record EgprsLlcBlockHdr {
211 uint7_t length_ind,
212 /* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
213 boolean e
214 } with {
215 variant (e) "FIELDLENGTH(1)"
216 encode "RAW"
217 };
218
219 external function enc_EgprsLlcBlockHdr(in EgprsLlcBlockHdr si) return octetstring
220 with { extension "prototype(convert) encode(RAW)" };
221 external function dec_EgprsLlcBlockHdr(in octetstring stream) return EgprsLlcBlockHdr
222 with { extension "prototype(convert) decode(RAW)" };
223
224 type record EgprsLlcBlock {
225 /* Header is only present if LI field was present */
226 EgprsLlcBlockHdr hdr optional,
227 octetstring payload
228 } with { variant "" };
229 type record of EgprsLlcBlock EgprsLlcBlocks;
230
231 /* TS 44.060 10.3a.1.1 EGPRS downlink RLC data block, manual c++ encoder/decoder */
232 type record EgprsDlMacDataHeader {
233 EgprsHeaderType header_type, /* Set internally by decoder */
234 uint5_t tfi,
235 MacRrbp rrbp,
236 BIT2 esp,
237 uint3_t usf,
Pau Espin Pedrol081b1682020-11-06 17:15:52 +0100238 uint11_t bsn1,
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200239 uint8_t bsn2_offset,
240 uint2_t pr, /* power reduction */
Pau Espin Pedrol4f9a48f2021-02-04 19:25:33 +0100241 uint2_t spb optional,
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200242 uint4_t cps
Pau Espin Pedrol4f9a48f2021-02-04 19:25:33 +0100243 } with { variant (spb) "PRESENCE(header_type=RLCMAC_HDR_TYPE_3)" };
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200244 /* Manual C++ Decoder: */
245 type record RlcmacDlEgprsDataBlock {
Pau Espin Pedrol5abfded2020-11-03 17:30:44 +0100246 CodingScheme mcs, /* Provided by C++ Decoder */
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200247 EgprsDlMacDataHeader mac_hdr,
248 boolean fbi,
249 boolean e,
250 EgprsLlcBlocks blocks
251 } with {
252 variant (fbi) "FIELDLENGTH(1)"
253 variant (e) "FIELDLENGTH(1)"
254 };
255
Harald Welte484160b2017-07-28 13:30:24 +0200256 /* TS 44.060 10.2.2 */
257 type record UlMacDataHeader {
Harald Welte43e060a2017-07-30 22:38:03 +0200258 /* Octet 0 */
Harald Welteefbc2fc2017-07-31 00:05:23 +0200259 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200260 uint4_t countdown,
261 boolean stall_ind,
Harald Welte43e060a2017-07-30 22:38:03 +0200262 boolean retry,
263 /* Octet 1 */
264 BIT1 spare,
265 boolean pfi_ind,
266 uint5_t tfi,
267 boolean tlli_ind,
268 /* Octet 2 */
269 uint7_t bsn,
270 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200271 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200272 variant (stall_ind) "FIELDLENGTH(1)"
273 variant (retry) "FIELDLENGTH(1)"
274 variant (pfi_ind) "FIELDLENGTH(1)"
275 variant (tlli_ind) "FIELDLENGTH(1)"
276 variant (e) "FIELDLENGTH(1)"
Harald Welte484160b2017-07-28 13:30:24 +0200277 };
278
Harald Welte484160b2017-07-28 13:30:24 +0200279 type record RlcMacUlPfi {
280 uint7_t pfi,
281 boolean m
282 } with {
283 variant (m) "FIELDLENGTH(1)"
284 };
285
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200286 /* TS 44.060 10.3a.1.1 10.3a.4 EGPRS Uplink RLC/MAC header, manual c++ encoder/decoder */
287 type record EgprsUlMacDataHeader {
288 EgprsHeaderType header_type, /* Set internally by decoder */
289 uint5_t tfi,
290 uint4_t countdown,
291 BIT1 foi_si,
292 BIT1 r_ri,
293 uint11_t bsn1,
Pau Espin Pedrol081b1682020-11-06 17:15:52 +0100294 uint8_t bsn2_offset,
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200295 uint4_t cps,
296 boolean pfi_ind,
297 BIT1 rsb,
Pau Espin Pedrol4f9a48f2021-02-04 19:25:33 +0100298 BIT2 spb optional
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200299 } with {
300 variant (pfi_ind) "FIELDLENGTH(1)"
Pau Espin Pedrol4f9a48f2021-02-04 19:25:33 +0100301 variant (spb) "PRESENCE(header_type=RLCMAC_HDR_TYPE_3)"
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200302 };
303 /* Manual C++ Decoder: 10.3a.2.1 EGPRS Uplink RLC data block */
304 type record RlcmacUlEgprsDataBlock {
Pau Espin Pedrol5abfded2020-11-03 17:30:44 +0100305 CodingScheme mcs, /* Provided by C++ Decoder */
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200306 EgprsUlMacDataHeader mac_hdr,
307 boolean tlli_ind,
308 boolean e,
309 /* Octet 3 ... M (optional): manual C++ Decoder */
310 GprsTlli tlli optional,
311 RlcMacUlPfi pfi optional,
312 EgprsLlcBlocks blocks
313 } with {
314 variant (tlli_ind) "FIELDLENGTH(1)"
315 variant (e) "FIELDLENGTH(1)"
316 };
317
Harald Welte484160b2017-07-28 13:30:24 +0200318 /* TS 44.060 10.2.2 */
319 type record RlcmacUlDataBlock {
Pau Espin Pedrol5abfded2020-11-03 17:30:44 +0100320 CodingScheme cs, /* Provided by C++ Decoder */
Harald Welte484160b2017-07-28 13:30:24 +0200321 /* MAC header */
322 UlMacDataHeader mac_hdr,
Harald Welte43e060a2017-07-30 22:38:03 +0200323 /* Octet 3 ... M (optional): manual C++ Decoder */
324 GprsTlli tlli optional,
325 RlcMacUlPfi pfi optional,
326 LlcBlocks blocks
Harald Welte484160b2017-07-28 13:30:24 +0200327 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200328 variant (tlli) "PRESENCE(mac_hdr.tlli_ind = true)"
329 variant (pfi) "PRESENCE(mac_hdr.pfi_ind = true)"
Harald Welte484160b2017-07-28 13:30:24 +0200330 };
331
Harald Welte43e060a2017-07-30 22:38:03 +0200332 external function enc_RlcmacUlDataBlock(in RlcmacUlDataBlock si) return octetstring;
333 external function dec_RlcmacUlDataBlock(in octetstring stream) return RlcmacUlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200334
Harald Welteefbc2fc2017-07-31 00:05:23 +0200335 type union RlcmacUlBlock {
336 RlcmacUlDataBlock data,
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200337 RlcmacUlEgprsDataBlock data_egprs,
Harald Welteefbc2fc2017-07-31 00:05:23 +0200338 RlcmacUlCtrlBlock ctrl
339 } with {
340 variant "TAG(data, mac_hdr.payload_type = MAC_PT_RLC_DATA;
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200341 ctrl, {mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT,
342 mac_hdr.payload_type = MAC_PT_RLCMAC_OPT};
343 data_egprs, {mac_hdr.header_type = RLCMAC_HDR_TYPE_1,
344 mac_hdr.header_type = RLCMAC_HDR_TYPE_2,
345 mac_hdr.header_type = RLCMAC_HDR_TYPE_3}
346 )"
Harald Welteefbc2fc2017-07-31 00:05:23 +0200347 };
348
Harald Welte78a1af62017-07-31 17:33:56 +0200349 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
350 * use auto-generated functions here, as they would decode those sub-types
351 * based on the RAW coder, not baed on the manual C++ functions */
352 external function enc_RlcmacUlBlock(in RlcmacUlBlock si) return octetstring;
353 external function dec_RlcmacUlBlock(in octetstring stream) return RlcmacUlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200354
355 type union RlcmacDlBlock {
356 RlcmacDlDataBlock data,
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200357 RlcmacDlEgprsDataBlock data_egprs,
Harald Welteefbc2fc2017-07-31 00:05:23 +0200358 RlcmacDlCtrlBlock ctrl
359 } with {
360 variant "TAG(data, mac_hdr.mac_hdr.payload_type = MAC_PT_RLC_DATA;
Pau Espin Pedrol372af7a2020-04-27 17:32:01 +0200361 ctrl, {mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT,
362 mac_hdr.payload_type = MAC_PT_RLCMAC_OPT};
363 data_egprs, {mac_hdr.header_type = RLCMAC_HDR_TYPE_1,
364 mac_hdr.header_type = RLCMAC_HDR_TYPE_2,
365 mac_hdr.header_type = RLCMAC_HDR_TYPE_3}
366 )"
Harald Welteefbc2fc2017-07-31 00:05:23 +0200367 };
368
Harald Welte78a1af62017-07-31 17:33:56 +0200369 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
370 * use auto-generated functions here, as they would decode those sub-types
371 * based on the RAW coder, not baed on the manual C++ functions */
372 external function enc_RlcmacDlBlock(in RlcmacDlBlock si) return octetstring;
373 external function dec_RlcmacDlBlock(in octetstring stream) return RlcmacDlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200374
Vadim Yanitskiye94d9e92022-11-16 01:35:23 +0700375 /* PTCCH (Packet Timing Advance Control Channel) downlink block format.
376 * See 3GPP TS 44.004, section 7.8. */
Vadim Yanitskiy1bd8ec52019-10-01 05:44:52 +0700377 type record PTCCHTimingAdvanceIE {
378 BIT1 spare ('0'B),
379 uint7_t ta_val
380 } with { variant "" };
381 type record of PTCCHTimingAdvanceIE PTCCHTimingAdvanceIEs;
382 type record PTCCHDownlinkMsg {
383 PTCCHTimingAdvanceIEs ta_idx length(16),
384 octetstring padding length(7)
385 } with { variant "" };
386
387 external function enc_PTCCHDownlinkMsg(in PTCCHDownlinkMsg si) return octetstring
388 with { extension "prototype(convert) encode(RAW)" };
389 external function dec_PTCCHDownlinkMsg(in octetstring stream) return PTCCHDownlinkMsg
390 with { extension "prototype(convert) decode(RAW)" };
391
Harald Welte484160b2017-07-28 13:30:24 +0200392} with { encode "RAW"; variant "FIELDORDER(msb)" }