blob: c946594ec79068c08bbfe223bf73ec63605c336d [file] [log] [blame]
Harald Welte484160b2017-07-28 13:30:24 +02001/* TITAN REW encode/decode definitions for 3GPP TS 44.060 RLC/MAC Blocks */
2module RLCMAC_Types {
3 import from General_Types all;
4 import from Osmocom_Types all;
5 import from GSM_Types all;
Harald Welte9d348522017-08-01 00:27:39 +02006 import from RLCMAC_CSN1_Types all;
Harald Welte484160b2017-07-28 13:30:24 +02007
8 /* TS 44.060 10.4.7 */
9 type enumerated MacPayloadType {
10 MAC_PT_RLC_DATA ('00'B),
11 MAC_PT_RLCMAC_NO_OPT ('01'B),
12 MAC_PT_RLCMAC_OPT ('10'B),
13 MAC_PT_RESERVED ('11'B)
14 } with { variant "FIELDLENGTH(2)" };
15
16 /* TS 44.060 10.4.5 */
17 type enumerated MacRrbp {
18 RRBP_Nplus13_mod_2715648 ('00'B),
19 RRBP_Nplus17_or_18_mod_2715648 ('01'B),
Harald Welte1cd673d2018-03-02 21:41:31 +010020 RRBP_Nplus21_or_22_mod_2715648 ('10'B),
Harald Welte484160b2017-07-28 13:30:24 +020021 RRBP_Nplus26_mod_2715648 ('11'B)
22 } with { variant "FIELDLENGTH(2)" };
23
24 /* Partof DL RLC data block and DL RLC/MAC ctrl block */
25 type record DlMacHeader {
26 MacPayloadType payload_type,
27 MacRrbp rrbp,
28 boolean rrbp_valid,
29 uint3_t usf
30 } with {
31 variant (rrbp_valid) "FIELDLENGTH(1)"
32 };
33
34 /* TS 44.060 10.4.10a */
35 type enumerated PowerReduction {
36 PWR_RED_0_to_3dB ('00'B),
37 PWR_RED_3_to_7dB ('01'B),
38 PWR_RED_7_to_10dB ('10'B),
39 PWR_RED_RESERVED ('11'B)
40 } with { variant "FIELDLENGTH(2)" };
41
42 /* TS 44.060 10.4.9d */
43 type enumerated DirectionBit {
44 DIR_UPLINK_TBF ('0'B),
45 DIR_DOWNLINK_TBF ('1'B)
46 } with { variant "FIELDLENGTH(1)" };
47
48 type record TfiOctet {
49 /* PR, TFI, D */
50 PowerReduction pr,
51 uint5_t tfi,
52 DirectionBit d
53 } with { variant "" };
54
55 type record RbsnExtOctet {
56 uint3_t rbsn_e,
57 BIT1 fs_e,
58 BIT4 spare
59 } with { variant "" };
60
61 type record DlCtrlOptOctets {
62 /* RBSN, RTI, FS, AC (optional, depending on mac_hdr.payload_type) */
63 BIT1 rbsn,
64 uint5_t rti,
65 boolean fs,
66 boolean tfi_octet_present,
67 TfiOctet tfi optional,
68 RbsnExtOctet rbsn_ext optional
69 } with {
70 variant (fs) "FIELDLENGTH(1)"
71 variant (tfi_octet_present) "FIELDLENGTH(1)"
72 variant (tfi) "PRESENCE(tfi_octet_present = true)"
73 variant (rbsn_ext) "PRESENCE(rbsn='1'B, fs=false)"
74 };
75
76 /* TS 44.060 10.3.1 Downlink RLC/MAC control block */
77 type record RlcmacDlCtrlBlock {
78 DlMacHeader mac_hdr,
79 DlCtrlOptOctets opt optional,
Harald Welte9d348522017-08-01 00:27:39 +020080 RlcmacDlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +020081 } with {
82 variant (opt) "PRESENCE(mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
83 };
84
85 external function enc_RlcmacDlCtrlBlock(in RlcmacDlCtrlBlock si) return octetstring
86 with { extension "prototype(convert) encode(RAW)" };
87 external function dec_RlcmacDlCtrlBlock(in octetstring stream) return RlcmacDlCtrlBlock
88 with { extension "prototype(convert) decode(RAW)" };
89
90 type record UlMacCtrlHeader {
Harald Welteefbc2fc2017-07-31 00:05:23 +020091 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +020092 BIT5 spare,
93 boolean retry
94 } with { variant (retry) "FIELDLENGTH(1)" };
95
96 /* TS 44.060 10.3.2 UplinkRLC/MAC control block */
97 type record RlcmacUlCtrlBlock {
98 UlMacCtrlHeader mac_hdr,
Harald Welte9d348522017-08-01 00:27:39 +020099 RlcmacUlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +0200100 } with { variant "" };
101
102 external function enc_RlcmacUlCtrlBlock(in RlcmacUlCtrlBlock si) return octetstring
103 with { extension "prototype(convert) encode(RAW)" };
104 external function dec_RlcmacUlCtrlBlock(in octetstring stream) return RlcmacUlCtrlBlock
105 with { extension "prototype(convert) decode(RAW)" };
106
107 /* a single RLC block / LLC-segment */
Harald Welte43e060a2017-07-30 22:38:03 +0200108 type record LlcBlockHdr {
Harald Welte484160b2017-07-28 13:30:24 +0200109 uint6_t length_ind,
110 /* 1 = new LLC PDU starts */
Harald Welte060e27a2018-03-03 20:38:19 +0100111 boolean more,
Harald Welte484160b2017-07-28 13:30:24 +0200112 /* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
Harald Welte43e060a2017-07-30 22:38:03 +0200113 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200114 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200115 variant (e) "FIELDLENGTH(1)"
Harald Weltecc5c1152018-03-09 12:54:01 +0100116 encode "RAW"
Harald Welte484160b2017-07-28 13:30:24 +0200117 };
Harald Weltecc5c1152018-03-09 12:54:01 +0100118
119 external function enc_LlcBlockHdr(in LlcBlockHdr si) return octetstring
120 with { extension "prototype(convert) encode(RAW)" };
121 external function dec_LlcBlockHdr(in octetstring stream) return LlcBlockHdr
122 with { extension "prototype(convert) decode(RAW)" };
123
Harald Welte43e060a2017-07-30 22:38:03 +0200124 type record LlcBlock {
125 /* Header is only present if LI field was present */
Harald Welte060e27a2018-03-03 20:38:19 +0100126 LlcBlockHdr hdr optional,
Harald Welte43e060a2017-07-30 22:38:03 +0200127 octetstring payload
128 } with { variant "" };
129 type record of LlcBlock LlcBlocks;
Harald Welte484160b2017-07-28 13:30:24 +0200130
131 /* TS 44.060 10.2.1 Downlink RLC data block */
Harald Welte43e060a2017-07-30 22:38:03 +0200132 type record DlMacHdrDataExt {
Harald Welte484160b2017-07-28 13:30:24 +0200133 /* Octet 1 */
Harald Welte484160b2017-07-28 13:30:24 +0200134 PowerReduction pr,
135 BIT1 spare,
136 uint4_t tfi, /* 3 or 4? */
137 boolean fbi,
Harald Welte43e060a2017-07-30 22:38:03 +0200138 /* Octet 2 */
Harald Welte484160b2017-07-28 13:30:24 +0200139 uint7_t bsn,
Harald Welte43e060a2017-07-30 22:38:03 +0200140 boolean e
141 } with {
142 variant (e) "FIELDLENGTH(1)"
143 };
144 type record DlMacDataHeader {
145 DlMacHeader mac_hdr,
146 DlMacHdrDataExt hdr_ext
Harald Welte484160b2017-07-28 13:30:24 +0200147 } with { variant "" };
Harald Welte43e060a2017-07-30 22:38:03 +0200148 type record RlcmacDlDataBlock {
149 DlMacDataHeader mac_hdr,
150 /* Octet 3..M / N: manual C++ Decoder */
151 LlcBlocks blocks
152 } with {
153 variant ""
154 };
Harald Welte484160b2017-07-28 13:30:24 +0200155
Harald Welte43e060a2017-07-30 22:38:03 +0200156 external function enc_RlcmacDlDataBlock(in RlcmacDlDataBlock si) return octetstring;
157 external function dec_RlcmacDlDataBlock(in octetstring stream) return RlcmacDlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200158
159
160 /* TS 44.060 10.2.2 */
161 type record UlMacDataHeader {
Harald Welte43e060a2017-07-30 22:38:03 +0200162 /* Octet 0 */
Harald Welteefbc2fc2017-07-31 00:05:23 +0200163 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200164 uint4_t countdown,
165 boolean stall_ind,
Harald Welte43e060a2017-07-30 22:38:03 +0200166 boolean retry,
167 /* Octet 1 */
168 BIT1 spare,
169 boolean pfi_ind,
170 uint5_t tfi,
171 boolean tlli_ind,
172 /* Octet 2 */
173 uint7_t bsn,
174 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200175 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200176 variant (stall_ind) "FIELDLENGTH(1)"
177 variant (retry) "FIELDLENGTH(1)"
178 variant (pfi_ind) "FIELDLENGTH(1)"
179 variant (tlli_ind) "FIELDLENGTH(1)"
180 variant (e) "FIELDLENGTH(1)"
Harald Welte484160b2017-07-28 13:30:24 +0200181 };
182
Harald Welte484160b2017-07-28 13:30:24 +0200183 type record RlcMacUlPfi {
184 uint7_t pfi,
185 boolean m
186 } with {
187 variant (m) "FIELDLENGTH(1)"
188 };
189
190 /* TS 44.060 10.2.2 */
191 type record RlcmacUlDataBlock {
192 /* MAC header */
193 UlMacDataHeader mac_hdr,
Harald Welte43e060a2017-07-30 22:38:03 +0200194 /* Octet 3 ... M (optional): manual C++ Decoder */
195 GprsTlli tlli optional,
196 RlcMacUlPfi pfi optional,
197 LlcBlocks blocks
Harald Welte484160b2017-07-28 13:30:24 +0200198 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200199 variant (tlli) "PRESENCE(mac_hdr.tlli_ind = true)"
200 variant (pfi) "PRESENCE(mac_hdr.pfi_ind = true)"
Harald Welte484160b2017-07-28 13:30:24 +0200201 };
202
Harald Welte43e060a2017-07-30 22:38:03 +0200203 external function enc_RlcmacUlDataBlock(in RlcmacUlDataBlock si) return octetstring;
204 external function dec_RlcmacUlDataBlock(in octetstring stream) return RlcmacUlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200205
Harald Welteefbc2fc2017-07-31 00:05:23 +0200206 type union RlcmacUlBlock {
207 RlcmacUlDataBlock data,
208 RlcmacUlCtrlBlock ctrl
209 } with {
210 variant "TAG(data, mac_hdr.payload_type = MAC_PT_RLC_DATA;
211 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
212 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
213 };
214
Harald Welte78a1af62017-07-31 17:33:56 +0200215 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
216 * use auto-generated functions here, as they would decode those sub-types
217 * based on the RAW coder, not baed on the manual C++ functions */
218 external function enc_RlcmacUlBlock(in RlcmacUlBlock si) return octetstring;
219 external function dec_RlcmacUlBlock(in octetstring stream) return RlcmacUlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200220
221 type union RlcmacDlBlock {
222 RlcmacDlDataBlock data,
223 RlcmacDlCtrlBlock ctrl
224 } with {
225 variant "TAG(data, mac_hdr.mac_hdr.payload_type = MAC_PT_RLC_DATA;
226 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
227 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
228 };
229
Harald Welte78a1af62017-07-31 17:33:56 +0200230 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
231 * use auto-generated functions here, as they would decode those sub-types
232 * based on the RAW coder, not baed on the manual C++ functions */
233 external function enc_RlcmacDlBlock(in RlcmacDlBlock si) return octetstring;
234 external function dec_RlcmacDlBlock(in octetstring stream) return RlcmacDlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200235
Harald Welte7024baa2018-03-02 23:37:51 +0100236 template (value) RlcmacUlBlock ts_RLC_UL_CTRL_ACK(RlcmacUlCtrlMsg ctrl,
237 MacPayloadType pt := MAC_PT_RLCMAC_NO_OPT,
238 boolean retry := false) := {
239 ctrl := {
240 mac_hdr := {
241 payload_type := pt,
242 spare := '00000'B,
243 retry := retry
244 },
245 payload := ctrl
246 }
247 }
248
Harald Welte060e27a2018-03-03 20:38:19 +0100249 /* Template fro uplink Data block */
250 template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
251 template LlcBlocks blocks := {}, template boolean stall := false) := {
252 data := {
253 mac_hdr := {
254 payload_type := MAC_PT_RLC_DATA,
255 countdown := cv,
256 stall_ind := false,
257 retry := false,
258 spare := '0'B,
259 pfi_ind := false,
260 tfi := tfi,
261 tlli_ind := false,
262 bsn := bsn,
263 e := false
264 },
265 tlli := omit,
266 pfi := omit,
267 blocks := blocks
268 }
269 }
270 template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
271 template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) := {
272 data := {
273 mac_hdr := {
274 payload_type := MAC_PT_RLC_DATA,
275 countdown := cv,
276 stall_ind := false,
277 retry := false,
278 spare := '0'B,
279 pfi_ind := false,
280 tfi := tfi,
281 tlli_ind := true,
282 bsn := bsn,
283 e := false
284 },
285 tlli := tlli,
286 pfi := omit,
287 blocks := blocks
288 }
289 }
290
291 template DlMacHeader t_RLCMAC_DlMacH(template MacPayloadType pt, template MacRrbp rrbp, template
292uint3_t usf) := {
293 payload_type := pt,
294 rrbp := rrbp,
295 rrbp_valid := ispresent(rrbp),
296 usf := usf
297 }
298
299 /* Receive Template for Downlink ACK/NACK */
300 template RlcmacDlBlock tr_RLCMAC_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := {
301 ctrl := {
302 mac_hdr := {
303 payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
304 rrbp:= ?,
305 rrbp_valid := true,
306 usf := ?
307 },
308 opt := *,
309 payload := {
310 msg_type := PACKET_UL_ACK_NACK,
311 u := {
312 ul_ack_nack := {
313 page_mode := ?,
314 msg_excape := ?,
315 uplink_tfi := ul_tfi,
316 is_egprs := '0'B,
317 gprs := {
318 ch_coding_cmd := ?,
319 ack_nack_desc := ?,
320 cont_res_tlli_present := ?,
321 cont_res_tlli := tlli,
322 pkt_ta_present := ?,
323 pkt_ta := *,
324 pwr_ctrl_present := ?,
325 pwr_ctrl := *
326 }
327 }
328 }
329 }
330 }
331 }
332
Harald Welteb669ee02018-03-09 12:50:02 +0100333 template RlcmacDlBlock tr_RLCMAC_DATA_RRBP := {
334 data := {
335 mac_hdr := {
336 mac_hdr := {
337 payload_type := MAC_PT_RLC_DATA,
338 rrbp := ?,
339 rrbp_valid := true,
340 usf := ?
341 },
342 hdr_ext := ?
343 },
344 blocks := ?
345 }
346 }
347
Harald Welte060e27a2018-03-03 20:38:19 +0100348 /* Template for Uplink MAC Control Header */
349 template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := {
350 payload_type := pt,
351 spare := '00000'B,
352 retry := retry
353 }
354
355 /* Template for Uplink Conntrol ACK */
356 template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := {
357 ctrl := {
358 mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT),
359 payload := {
360 msg_type := PACKET_CONTROL_ACK,
361 u := {
362 ctrl_ack := {
363 tlli := tlli,
364 ctrl_ack := ack
365 }
366 }
367 }
368 }
369 }
370
371 /* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */
372 template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, boolean more := false, boolean e := true) := {
373 /* let encoder figure out the header */
374 hdr := omit,
375 payload := data
376 }
377
378
Harald Welte484160b2017-07-28 13:30:24 +0200379} with { encode "RAW"; variant "FIELDORDER(msb)" }