blob: f3deafc250a9561aa411c37e5b22715db272894f [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
34 /* Partof DL RLC data block and DL RLC/MAC ctrl block */
35 type record DlMacHeader {
36 MacPayloadType payload_type,
37 MacRrbp rrbp,
38 boolean rrbp_valid,
39 uint3_t usf
40 } with {
41 variant (rrbp_valid) "FIELDLENGTH(1)"
42 };
43
44 /* TS 44.060 10.4.10a */
45 type enumerated PowerReduction {
46 PWR_RED_0_to_3dB ('00'B),
47 PWR_RED_3_to_7dB ('01'B),
48 PWR_RED_7_to_10dB ('10'B),
49 PWR_RED_RESERVED ('11'B)
50 } with { variant "FIELDLENGTH(2)" };
51
52 /* TS 44.060 10.4.9d */
53 type enumerated DirectionBit {
54 DIR_UPLINK_TBF ('0'B),
55 DIR_DOWNLINK_TBF ('1'B)
56 } with { variant "FIELDLENGTH(1)" };
57
58 type record TfiOctet {
59 /* PR, TFI, D */
60 PowerReduction pr,
61 uint5_t tfi,
62 DirectionBit d
63 } with { variant "" };
64
65 type record RbsnExtOctet {
66 uint3_t rbsn_e,
67 BIT1 fs_e,
68 BIT4 spare
69 } with { variant "" };
70
71 type record DlCtrlOptOctets {
72 /* RBSN, RTI, FS, AC (optional, depending on mac_hdr.payload_type) */
73 BIT1 rbsn,
74 uint5_t rti,
75 boolean fs,
76 boolean tfi_octet_present,
77 TfiOctet tfi optional,
78 RbsnExtOctet rbsn_ext optional
79 } with {
80 variant (fs) "FIELDLENGTH(1)"
81 variant (tfi_octet_present) "FIELDLENGTH(1)"
82 variant (tfi) "PRESENCE(tfi_octet_present = true)"
83 variant (rbsn_ext) "PRESENCE(rbsn='1'B, fs=false)"
84 };
85
86 /* TS 44.060 10.3.1 Downlink RLC/MAC control block */
87 type record RlcmacDlCtrlBlock {
88 DlMacHeader mac_hdr,
89 DlCtrlOptOctets opt optional,
Harald Welte9d348522017-08-01 00:27:39 +020090 RlcmacDlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +020091 } with {
92 variant (opt) "PRESENCE(mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
93 };
94
95 external function enc_RlcmacDlCtrlBlock(in RlcmacDlCtrlBlock si) return octetstring
96 with { extension "prototype(convert) encode(RAW)" };
97 external function dec_RlcmacDlCtrlBlock(in octetstring stream) return RlcmacDlCtrlBlock
98 with { extension "prototype(convert) decode(RAW)" };
99
100 type record UlMacCtrlHeader {
Harald Welteefbc2fc2017-07-31 00:05:23 +0200101 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200102 BIT5 spare,
103 boolean retry
104 } with { variant (retry) "FIELDLENGTH(1)" };
105
106 /* TS 44.060 10.3.2 UplinkRLC/MAC control block */
107 type record RlcmacUlCtrlBlock {
108 UlMacCtrlHeader mac_hdr,
Harald Welte9d348522017-08-01 00:27:39 +0200109 RlcmacUlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +0200110 } with { variant "" };
111
112 external function enc_RlcmacUlCtrlBlock(in RlcmacUlCtrlBlock si) return octetstring
113 with { extension "prototype(convert) encode(RAW)" };
114 external function dec_RlcmacUlCtrlBlock(in octetstring stream) return RlcmacUlCtrlBlock
115 with { extension "prototype(convert) decode(RAW)" };
116
117 /* a single RLC block / LLC-segment */
Harald Welte43e060a2017-07-30 22:38:03 +0200118 type record LlcBlockHdr {
Harald Welte484160b2017-07-28 13:30:24 +0200119 uint6_t length_ind,
120 /* 1 = new LLC PDU starts */
Harald Welte060e27a2018-03-03 20:38:19 +0100121 boolean more,
Harald Welte484160b2017-07-28 13:30:24 +0200122 /* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
Harald Welte43e060a2017-07-30 22:38:03 +0200123 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200124 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200125 variant (e) "FIELDLENGTH(1)"
Harald Weltecc5c1152018-03-09 12:54:01 +0100126 encode "RAW"
Harald Welte484160b2017-07-28 13:30:24 +0200127 };
Harald Weltecc5c1152018-03-09 12:54:01 +0100128
129 external function enc_LlcBlockHdr(in LlcBlockHdr si) return octetstring
130 with { extension "prototype(convert) encode(RAW)" };
131 external function dec_LlcBlockHdr(in octetstring stream) return LlcBlockHdr
132 with { extension "prototype(convert) decode(RAW)" };
133
Harald Welte43e060a2017-07-30 22:38:03 +0200134 type record LlcBlock {
135 /* Header is only present if LI field was present */
Harald Welte060e27a2018-03-03 20:38:19 +0100136 LlcBlockHdr hdr optional,
Harald Welte43e060a2017-07-30 22:38:03 +0200137 octetstring payload
138 } with { variant "" };
139 type record of LlcBlock LlcBlocks;
Harald Welte484160b2017-07-28 13:30:24 +0200140
141 /* TS 44.060 10.2.1 Downlink RLC data block */
Harald Welte43e060a2017-07-30 22:38:03 +0200142 type record DlMacHdrDataExt {
Harald Welte484160b2017-07-28 13:30:24 +0200143 /* Octet 1 */
Harald Welte484160b2017-07-28 13:30:24 +0200144 PowerReduction pr,
145 BIT1 spare,
146 uint4_t tfi, /* 3 or 4? */
147 boolean fbi,
Harald Welte43e060a2017-07-30 22:38:03 +0200148 /* Octet 2 */
Harald Welte484160b2017-07-28 13:30:24 +0200149 uint7_t bsn,
Harald Welte43e060a2017-07-30 22:38:03 +0200150 boolean e
151 } with {
152 variant (e) "FIELDLENGTH(1)"
153 };
154 type record DlMacDataHeader {
155 DlMacHeader mac_hdr,
156 DlMacHdrDataExt hdr_ext
Harald Welte484160b2017-07-28 13:30:24 +0200157 } with { variant "" };
Harald Welte43e060a2017-07-30 22:38:03 +0200158 type record RlcmacDlDataBlock {
159 DlMacDataHeader mac_hdr,
160 /* Octet 3..M / N: manual C++ Decoder */
161 LlcBlocks blocks
162 } with {
163 variant ""
164 };
Harald Welte484160b2017-07-28 13:30:24 +0200165
Harald Welte43e060a2017-07-30 22:38:03 +0200166 external function enc_RlcmacDlDataBlock(in RlcmacDlDataBlock si) return octetstring;
167 external function dec_RlcmacDlDataBlock(in octetstring stream) return RlcmacDlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200168
169
170 /* TS 44.060 10.2.2 */
171 type record UlMacDataHeader {
Harald Welte43e060a2017-07-30 22:38:03 +0200172 /* Octet 0 */
Harald Welteefbc2fc2017-07-31 00:05:23 +0200173 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200174 uint4_t countdown,
175 boolean stall_ind,
Harald Welte43e060a2017-07-30 22:38:03 +0200176 boolean retry,
177 /* Octet 1 */
178 BIT1 spare,
179 boolean pfi_ind,
180 uint5_t tfi,
181 boolean tlli_ind,
182 /* Octet 2 */
183 uint7_t bsn,
184 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200185 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200186 variant (stall_ind) "FIELDLENGTH(1)"
187 variant (retry) "FIELDLENGTH(1)"
188 variant (pfi_ind) "FIELDLENGTH(1)"
189 variant (tlli_ind) "FIELDLENGTH(1)"
190 variant (e) "FIELDLENGTH(1)"
Harald Welte484160b2017-07-28 13:30:24 +0200191 };
192
Harald Welte484160b2017-07-28 13:30:24 +0200193 type record RlcMacUlPfi {
194 uint7_t pfi,
195 boolean m
196 } with {
197 variant (m) "FIELDLENGTH(1)"
198 };
199
200 /* TS 44.060 10.2.2 */
201 type record RlcmacUlDataBlock {
202 /* MAC header */
203 UlMacDataHeader mac_hdr,
Harald Welte43e060a2017-07-30 22:38:03 +0200204 /* Octet 3 ... M (optional): manual C++ Decoder */
205 GprsTlli tlli optional,
206 RlcMacUlPfi pfi optional,
207 LlcBlocks blocks
Harald Welte484160b2017-07-28 13:30:24 +0200208 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200209 variant (tlli) "PRESENCE(mac_hdr.tlli_ind = true)"
210 variant (pfi) "PRESENCE(mac_hdr.pfi_ind = true)"
Harald Welte484160b2017-07-28 13:30:24 +0200211 };
212
Harald Welte43e060a2017-07-30 22:38:03 +0200213 external function enc_RlcmacUlDataBlock(in RlcmacUlDataBlock si) return octetstring;
214 external function dec_RlcmacUlDataBlock(in octetstring stream) return RlcmacUlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200215
Harald Welteefbc2fc2017-07-31 00:05:23 +0200216 type union RlcmacUlBlock {
217 RlcmacUlDataBlock data,
218 RlcmacUlCtrlBlock ctrl
219 } with {
220 variant "TAG(data, mac_hdr.payload_type = MAC_PT_RLC_DATA;
221 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
222 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
223 };
224
Harald Welte78a1af62017-07-31 17:33:56 +0200225 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
226 * use auto-generated functions here, as they would decode those sub-types
227 * based on the RAW coder, not baed on the manual C++ functions */
228 external function enc_RlcmacUlBlock(in RlcmacUlBlock si) return octetstring;
229 external function dec_RlcmacUlBlock(in octetstring stream) return RlcmacUlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200230
231 type union RlcmacDlBlock {
232 RlcmacDlDataBlock data,
233 RlcmacDlCtrlBlock ctrl
234 } with {
235 variant "TAG(data, mac_hdr.mac_hdr.payload_type = MAC_PT_RLC_DATA;
236 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
237 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
238 };
239
Harald Welte78a1af62017-07-31 17:33:56 +0200240 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
241 * use auto-generated functions here, as they would decode those sub-types
242 * based on the RAW coder, not baed on the manual C++ functions */
243 external function enc_RlcmacDlBlock(in RlcmacDlBlock si) return octetstring;
244 external function dec_RlcmacDlBlock(in octetstring stream) return RlcmacDlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200245
Harald Welte7024baa2018-03-02 23:37:51 +0100246 template (value) RlcmacUlBlock ts_RLC_UL_CTRL_ACK(RlcmacUlCtrlMsg ctrl,
247 MacPayloadType pt := MAC_PT_RLCMAC_NO_OPT,
248 boolean retry := false) := {
249 ctrl := {
250 mac_hdr := {
251 payload_type := pt,
252 spare := '00000'B,
253 retry := retry
254 },
255 payload := ctrl
256 }
257 }
258
Harald Welte060e27a2018-03-03 20:38:19 +0100259 /* Template fro uplink Data block */
260 template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
261 template LlcBlocks blocks := {}, template boolean stall := false) := {
262 data := {
263 mac_hdr := {
264 payload_type := MAC_PT_RLC_DATA,
265 countdown := cv,
266 stall_ind := false,
267 retry := false,
268 spare := '0'B,
269 pfi_ind := false,
270 tfi := tfi,
271 tlli_ind := false,
272 bsn := bsn,
273 e := false
274 },
275 tlli := omit,
276 pfi := omit,
277 blocks := blocks
278 }
279 }
280 template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
281 template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) := {
282 data := {
283 mac_hdr := {
284 payload_type := MAC_PT_RLC_DATA,
285 countdown := cv,
286 stall_ind := false,
287 retry := false,
288 spare := '0'B,
289 pfi_ind := false,
290 tfi := tfi,
291 tlli_ind := true,
292 bsn := bsn,
293 e := false
294 },
295 tlli := tlli,
296 pfi := omit,
297 blocks := blocks
298 }
299 }
300
301 template DlMacHeader t_RLCMAC_DlMacH(template MacPayloadType pt, template MacRrbp rrbp, template
302uint3_t usf) := {
303 payload_type := pt,
304 rrbp := rrbp,
305 rrbp_valid := ispresent(rrbp),
306 usf := usf
307 }
308
309 /* Receive Template for Downlink ACK/NACK */
310 template RlcmacDlBlock tr_RLCMAC_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := {
311 ctrl := {
312 mac_hdr := {
313 payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
314 rrbp:= ?,
315 rrbp_valid := true,
316 usf := ?
317 },
318 opt := *,
319 payload := {
320 msg_type := PACKET_UL_ACK_NACK,
321 u := {
322 ul_ack_nack := {
323 page_mode := ?,
324 msg_excape := ?,
325 uplink_tfi := ul_tfi,
326 is_egprs := '0'B,
327 gprs := {
328 ch_coding_cmd := ?,
329 ack_nack_desc := ?,
330 cont_res_tlli_present := ?,
331 cont_res_tlli := tlli,
332 pkt_ta_present := ?,
333 pkt_ta := *,
334 pwr_ctrl_present := ?,
335 pwr_ctrl := *
336 }
337 }
338 }
339 }
340 }
341 }
342
Harald Welteb669ee02018-03-09 12:50:02 +0100343 template RlcmacDlBlock tr_RLCMAC_DATA_RRBP := {
344 data := {
345 mac_hdr := {
346 mac_hdr := {
347 payload_type := MAC_PT_RLC_DATA,
348 rrbp := ?,
349 rrbp_valid := true,
350 usf := ?
351 },
352 hdr_ext := ?
353 },
354 blocks := ?
355 }
356 }
357
Harald Welte060e27a2018-03-03 20:38:19 +0100358 /* Template for Uplink MAC Control Header */
359 template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := {
360 payload_type := pt,
361 spare := '00000'B,
362 retry := retry
363 }
364
365 /* Template for Uplink Conntrol ACK */
366 template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := {
367 ctrl := {
368 mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT),
369 payload := {
370 msg_type := PACKET_CONTROL_ACK,
371 u := {
372 ctrl_ack := {
373 tlli := tlli,
374 ctrl_ack := ack
375 }
376 }
377 }
378 }
379 }
380
381 /* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */
382 template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, boolean more := false, boolean e := true) := {
383 /* let encoder figure out the header */
384 hdr := omit,
385 payload := data
386 }
387
388
Harald Welte484160b2017-07-28 13:30:24 +0200389} with { encode "RAW"; variant "FIELDORDER(msb)" }