blob: 3a1ecb103663afe101c2d9cd5aa43c0beccae54b [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 Pedrol65bab9e2019-12-04 21:05:10 +010034 function f_rrbp_fn_delay(MacRrbp rrbp) return uint32_t {
35 select (rrbp) {
36 case (RRBP_Nplus13_mod_2715648) { return 13; }
37 case (RRBP_Nplus17_or_18_mod_2715648) { return 17; }
38 case (RRBP_Nplus21_or_22_mod_2715648) { return 21; }
39 case (RRBP_Nplus26_mod_2715648) { return 26; }
40 }
41 return 0;
42 }
43
Harald Welte484160b2017-07-28 13:30:24 +020044 /* Partof DL RLC data block and DL RLC/MAC ctrl block */
45 type record DlMacHeader {
46 MacPayloadType payload_type,
47 MacRrbp rrbp,
48 boolean rrbp_valid,
49 uint3_t usf
50 } with {
51 variant (rrbp_valid) "FIELDLENGTH(1)"
52 };
53
54 /* TS 44.060 10.4.10a */
55 type enumerated PowerReduction {
56 PWR_RED_0_to_3dB ('00'B),
57 PWR_RED_3_to_7dB ('01'B),
58 PWR_RED_7_to_10dB ('10'B),
59 PWR_RED_RESERVED ('11'B)
60 } with { variant "FIELDLENGTH(2)" };
61
62 /* TS 44.060 10.4.9d */
63 type enumerated DirectionBit {
64 DIR_UPLINK_TBF ('0'B),
65 DIR_DOWNLINK_TBF ('1'B)
66 } with { variant "FIELDLENGTH(1)" };
67
68 type record TfiOctet {
69 /* PR, TFI, D */
70 PowerReduction pr,
71 uint5_t tfi,
72 DirectionBit d
73 } with { variant "" };
74
75 type record RbsnExtOctet {
76 uint3_t rbsn_e,
77 BIT1 fs_e,
78 BIT4 spare
79 } with { variant "" };
80
81 type record DlCtrlOptOctets {
82 /* RBSN, RTI, FS, AC (optional, depending on mac_hdr.payload_type) */
83 BIT1 rbsn,
84 uint5_t rti,
85 boolean fs,
86 boolean tfi_octet_present,
87 TfiOctet tfi optional,
88 RbsnExtOctet rbsn_ext optional
89 } with {
90 variant (fs) "FIELDLENGTH(1)"
91 variant (tfi_octet_present) "FIELDLENGTH(1)"
92 variant (tfi) "PRESENCE(tfi_octet_present = true)"
93 variant (rbsn_ext) "PRESENCE(rbsn='1'B, fs=false)"
94 };
95
96 /* TS 44.060 10.3.1 Downlink RLC/MAC control block */
97 type record RlcmacDlCtrlBlock {
98 DlMacHeader mac_hdr,
99 DlCtrlOptOctets opt optional,
Harald Welte9d348522017-08-01 00:27:39 +0200100 RlcmacDlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +0200101 } with {
102 variant (opt) "PRESENCE(mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
103 };
104
105 external function enc_RlcmacDlCtrlBlock(in RlcmacDlCtrlBlock si) return octetstring
106 with { extension "prototype(convert) encode(RAW)" };
107 external function dec_RlcmacDlCtrlBlock(in octetstring stream) return RlcmacDlCtrlBlock
108 with { extension "prototype(convert) decode(RAW)" };
109
110 type record UlMacCtrlHeader {
Harald Welteefbc2fc2017-07-31 00:05:23 +0200111 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200112 BIT5 spare,
113 boolean retry
114 } with { variant (retry) "FIELDLENGTH(1)" };
115
116 /* TS 44.060 10.3.2 UplinkRLC/MAC control block */
117 type record RlcmacUlCtrlBlock {
118 UlMacCtrlHeader mac_hdr,
Harald Welte9d348522017-08-01 00:27:39 +0200119 RlcmacUlCtrlMsg payload
Harald Welte484160b2017-07-28 13:30:24 +0200120 } with { variant "" };
121
122 external function enc_RlcmacUlCtrlBlock(in RlcmacUlCtrlBlock si) return octetstring
123 with { extension "prototype(convert) encode(RAW)" };
124 external function dec_RlcmacUlCtrlBlock(in octetstring stream) return RlcmacUlCtrlBlock
125 with { extension "prototype(convert) decode(RAW)" };
126
127 /* a single RLC block / LLC-segment */
Harald Welte43e060a2017-07-30 22:38:03 +0200128 type record LlcBlockHdr {
Harald Welte484160b2017-07-28 13:30:24 +0200129 uint6_t length_ind,
130 /* 1 = new LLC PDU starts */
Harald Welte060e27a2018-03-03 20:38:19 +0100131 boolean more,
Harald Welte484160b2017-07-28 13:30:24 +0200132 /* 0 = another extension octet after LLC PDU, 1 = no more extension octets */
Harald Welte43e060a2017-07-30 22:38:03 +0200133 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200134 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200135 variant (e) "FIELDLENGTH(1)"
Harald Weltecc5c1152018-03-09 12:54:01 +0100136 encode "RAW"
Harald Welte484160b2017-07-28 13:30:24 +0200137 };
Harald Weltecc5c1152018-03-09 12:54:01 +0100138
139 external function enc_LlcBlockHdr(in LlcBlockHdr si) return octetstring
140 with { extension "prototype(convert) encode(RAW)" };
141 external function dec_LlcBlockHdr(in octetstring stream) return LlcBlockHdr
142 with { extension "prototype(convert) decode(RAW)" };
143
Harald Welte43e060a2017-07-30 22:38:03 +0200144 type record LlcBlock {
145 /* Header is only present if LI field was present */
Harald Welte060e27a2018-03-03 20:38:19 +0100146 LlcBlockHdr hdr optional,
Harald Welte43e060a2017-07-30 22:38:03 +0200147 octetstring payload
148 } with { variant "" };
149 type record of LlcBlock LlcBlocks;
Harald Welte484160b2017-07-28 13:30:24 +0200150
151 /* TS 44.060 10.2.1 Downlink RLC data block */
Harald Welte43e060a2017-07-30 22:38:03 +0200152 type record DlMacHdrDataExt {
Harald Welte484160b2017-07-28 13:30:24 +0200153 /* Octet 1 */
Harald Welte484160b2017-07-28 13:30:24 +0200154 PowerReduction pr,
155 BIT1 spare,
156 uint4_t tfi, /* 3 or 4? */
157 boolean fbi,
Harald Welte43e060a2017-07-30 22:38:03 +0200158 /* Octet 2 */
Harald Welte484160b2017-07-28 13:30:24 +0200159 uint7_t bsn,
Harald Welte43e060a2017-07-30 22:38:03 +0200160 boolean e
161 } with {
162 variant (e) "FIELDLENGTH(1)"
163 };
164 type record DlMacDataHeader {
165 DlMacHeader mac_hdr,
166 DlMacHdrDataExt hdr_ext
Harald Welte484160b2017-07-28 13:30:24 +0200167 } with { variant "" };
Harald Welte43e060a2017-07-30 22:38:03 +0200168 type record RlcmacDlDataBlock {
169 DlMacDataHeader mac_hdr,
170 /* Octet 3..M / N: manual C++ Decoder */
171 LlcBlocks blocks
172 } with {
173 variant ""
174 };
Harald Welte484160b2017-07-28 13:30:24 +0200175
Harald Welte43e060a2017-07-30 22:38:03 +0200176 external function enc_RlcmacDlDataBlock(in RlcmacDlDataBlock si) return octetstring;
177 external function dec_RlcmacDlDataBlock(in octetstring stream) return RlcmacDlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200178
179
180 /* TS 44.060 10.2.2 */
181 type record UlMacDataHeader {
Harald Welte43e060a2017-07-30 22:38:03 +0200182 /* Octet 0 */
Harald Welteefbc2fc2017-07-31 00:05:23 +0200183 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200184 uint4_t countdown,
185 boolean stall_ind,
Harald Welte43e060a2017-07-30 22:38:03 +0200186 boolean retry,
187 /* Octet 1 */
188 BIT1 spare,
189 boolean pfi_ind,
190 uint5_t tfi,
191 boolean tlli_ind,
192 /* Octet 2 */
193 uint7_t bsn,
194 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200195 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200196 variant (stall_ind) "FIELDLENGTH(1)"
197 variant (retry) "FIELDLENGTH(1)"
198 variant (pfi_ind) "FIELDLENGTH(1)"
199 variant (tlli_ind) "FIELDLENGTH(1)"
200 variant (e) "FIELDLENGTH(1)"
Harald Welte484160b2017-07-28 13:30:24 +0200201 };
202
Harald Welte484160b2017-07-28 13:30:24 +0200203 type record RlcMacUlPfi {
204 uint7_t pfi,
205 boolean m
206 } with {
207 variant (m) "FIELDLENGTH(1)"
208 };
209
210 /* TS 44.060 10.2.2 */
211 type record RlcmacUlDataBlock {
212 /* MAC header */
213 UlMacDataHeader mac_hdr,
Harald Welte43e060a2017-07-30 22:38:03 +0200214 /* Octet 3 ... M (optional): manual C++ Decoder */
215 GprsTlli tlli optional,
216 RlcMacUlPfi pfi optional,
217 LlcBlocks blocks
Harald Welte484160b2017-07-28 13:30:24 +0200218 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200219 variant (tlli) "PRESENCE(mac_hdr.tlli_ind = true)"
220 variant (pfi) "PRESENCE(mac_hdr.pfi_ind = true)"
Harald Welte484160b2017-07-28 13:30:24 +0200221 };
222
Harald Welte43e060a2017-07-30 22:38:03 +0200223 external function enc_RlcmacUlDataBlock(in RlcmacUlDataBlock si) return octetstring;
224 external function dec_RlcmacUlDataBlock(in octetstring stream) return RlcmacUlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200225
Harald Welteefbc2fc2017-07-31 00:05:23 +0200226 type union RlcmacUlBlock {
227 RlcmacUlDataBlock data,
228 RlcmacUlCtrlBlock ctrl
229 } with {
230 variant "TAG(data, mac_hdr.payload_type = MAC_PT_RLC_DATA;
231 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
232 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
233 };
234
Harald Welte78a1af62017-07-31 17:33:56 +0200235 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
236 * use auto-generated functions here, as they would decode those sub-types
237 * based on the RAW coder, not baed on the manual C++ functions */
238 external function enc_RlcmacUlBlock(in RlcmacUlBlock si) return octetstring;
239 external function dec_RlcmacUlBlock(in octetstring stream) return RlcmacUlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200240
241 type union RlcmacDlBlock {
242 RlcmacDlDataBlock data,
243 RlcmacDlCtrlBlock ctrl
244 } with {
245 variant "TAG(data, mac_hdr.mac_hdr.payload_type = MAC_PT_RLC_DATA;
246 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
247 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
248 };
249
Harald Welte78a1af62017-07-31 17:33:56 +0200250 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
251 * use auto-generated functions here, as they would decode those sub-types
252 * based on the RAW coder, not baed on the manual C++ functions */
253 external function enc_RlcmacDlBlock(in RlcmacDlBlock si) return octetstring;
254 external function dec_RlcmacDlBlock(in octetstring stream) return RlcmacDlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200255
Harald Welte7024baa2018-03-02 23:37:51 +0100256 template (value) RlcmacUlBlock ts_RLC_UL_CTRL_ACK(RlcmacUlCtrlMsg ctrl,
257 MacPayloadType pt := MAC_PT_RLCMAC_NO_OPT,
258 boolean retry := false) := {
259 ctrl := {
260 mac_hdr := {
261 payload_type := pt,
262 spare := '00000'B,
263 retry := retry
264 },
265 payload := ctrl
266 }
267 }
268
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +0100269 /* Send Template for Downlink ACK/NACK */
270 template RlcmacUlBlock ts_RLCMAC_DL_ACK_NACK(template uint5_t tfi, AckNackDescription andesc, boolean retry := false) := {
271 ctrl := {
272 mac_hdr := {
273 payload_type := MAC_PT_RLCMAC_NO_OPT,
274 spare := '00000'B,
275 retry := retry
276 },
277 payload := {
278 msg_type := PACKET_DL_ACK_NACK,
279 u := {
280 dl_ack_nack := {
281 dl_tfi := tfi,
282 ack_nack_desc := andesc,
283 chreq_desc_presence := '0'B,
284 chreq_desc := omit,
285 ch_qual_rep := c_ChQualRep_default
286 }
287 }
288 }
289 }
290 }
291
292 /* Template for uplink Data block */
Harald Welte060e27a2018-03-03 20:38:19 +0100293 template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
294 template LlcBlocks blocks := {}, template boolean stall := false) := {
295 data := {
296 mac_hdr := {
297 payload_type := MAC_PT_RLC_DATA,
298 countdown := cv,
299 stall_ind := false,
300 retry := false,
301 spare := '0'B,
302 pfi_ind := false,
303 tfi := tfi,
304 tlli_ind := false,
305 bsn := bsn,
306 e := false
307 },
308 tlli := omit,
309 pfi := omit,
310 blocks := blocks
311 }
312 }
313 template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
314 template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) := {
315 data := {
316 mac_hdr := {
317 payload_type := MAC_PT_RLC_DATA,
318 countdown := cv,
319 stall_ind := false,
320 retry := false,
321 spare := '0'B,
322 pfi_ind := false,
323 tfi := tfi,
324 tlli_ind := true,
325 bsn := bsn,
326 e := false
327 },
328 tlli := tlli,
329 pfi := omit,
330 blocks := blocks
331 }
332 }
333
334 template DlMacHeader t_RLCMAC_DlMacH(template MacPayloadType pt, template MacRrbp rrbp, template
335uint3_t usf) := {
336 payload_type := pt,
337 rrbp := rrbp,
338 rrbp_valid := ispresent(rrbp),
339 usf := usf
340 }
341
Pau Espin Pedrol596faa42019-10-04 19:31:29 +0200342 template RlcmacDlBlock tr_RLCMAC_DUMMY_CTRL(template uint3_t usf := ?) := {
343 ctrl := {
344 mac_hdr := {
345 payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
346 rrbp:= ?,
347 rrbp_valid := ?,
348 usf := usf
349 },
350 opt := *,
351 payload := {
352 msg_type := PACKET_DL_DUMMY_CTRL,
353 u := {
354 dl_dummy := {
355 page_mode := ?,
356 persistence_levels_present := ?,
357 persistence_levels := *
358 }
359 }
360 }
361 }
362 }
363
Pau Espin Pedrol21659632019-12-02 19:12:08 +0100364 /* Receive Template for Uplink ACK/NACK */
365 template RlcmacDlBlock tr_RLCMAC_UL_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := {
Harald Welte060e27a2018-03-03 20:38:19 +0100366 ctrl := {
367 mac_hdr := {
368 payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
369 rrbp:= ?,
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +0200370 rrbp_valid := ?,
Harald Welte060e27a2018-03-03 20:38:19 +0100371 usf := ?
372 },
373 opt := *,
374 payload := {
375 msg_type := PACKET_UL_ACK_NACK,
376 u := {
377 ul_ack_nack := {
378 page_mode := ?,
379 msg_excape := ?,
380 uplink_tfi := ul_tfi,
381 is_egprs := '0'B,
382 gprs := {
383 ch_coding_cmd := ?,
384 ack_nack_desc := ?,
385 cont_res_tlli_present := ?,
386 cont_res_tlli := tlli,
387 pkt_ta_present := ?,
388 pkt_ta := *,
389 pwr_ctrl_present := ?,
390 pwr_ctrl := *
391 }
392 }
393 }
394 }
395 }
396 }
397
Harald Welteb669ee02018-03-09 12:50:02 +0100398 template RlcmacDlBlock tr_RLCMAC_DATA_RRBP := {
399 data := {
400 mac_hdr := {
401 mac_hdr := {
402 payload_type := MAC_PT_RLC_DATA,
403 rrbp := ?,
404 rrbp_valid := true,
405 usf := ?
406 },
407 hdr_ext := ?
408 },
409 blocks := ?
410 }
411 }
412
Harald Welte060e27a2018-03-03 20:38:19 +0100413 /* Template for Uplink MAC Control Header */
414 template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := {
415 payload_type := pt,
416 spare := '00000'B,
417 retry := retry
418 }
419
Pau Espin Pedrol21659632019-12-02 19:12:08 +0100420 /* Template for Uplink Control ACK */
Harald Welte060e27a2018-03-03 20:38:19 +0100421 template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := {
422 ctrl := {
423 mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT),
424 payload := {
425 msg_type := PACKET_CONTROL_ACK,
426 u := {
427 ctrl_ack := {
428 tlli := tlli,
429 ctrl_ack := ack
430 }
431 }
432 }
433 }
434 }
435
436 /* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */
437 template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, boolean more := false, boolean e := true) := {
438 /* let encoder figure out the header */
439 hdr := omit,
440 payload := data
441 }
442
Vadim Yanitskiy1bd8ec52019-10-01 05:44:52 +0700443 /* PTCCH/D (Packet Timing Advance Control Channel) message.
444 * TODO: add a spec. reference to the message format definition. */
445 type record PTCCHTimingAdvanceIE {
446 BIT1 spare ('0'B),
447 uint7_t ta_val
448 } with { variant "" };
449 type record of PTCCHTimingAdvanceIE PTCCHTimingAdvanceIEs;
450 type record PTCCHDownlinkMsg {
451 PTCCHTimingAdvanceIEs ta_idx length(16),
452 octetstring padding length(7)
453 } with { variant "" };
454
455 external function enc_PTCCHDownlinkMsg(in PTCCHDownlinkMsg si) return octetstring
456 with { extension "prototype(convert) encode(RAW)" };
457 external function dec_PTCCHDownlinkMsg(in octetstring stream) return PTCCHDownlinkMsg
458 with { extension "prototype(convert) decode(RAW)" };
459
460 template PTCCHDownlinkMsg tr_PTCCHDownlinkMsg(
461 template (present) uint7_t tai0_ta := ?,
462 template (present) uint7_t tai1_ta := ?,
463 template (present) uint7_t tai2_ta := ?,
464 template (present) uint7_t tai3_ta := ?,
465 template (present) uint7_t tai4_ta := ?,
466 template (present) uint7_t tai5_ta := ?,
467 template (present) uint7_t tai6_ta := ?,
468 template (present) uint7_t tai7_ta := ?,
469 template (present) uint7_t tai8_ta := ?,
470 template (present) uint7_t tai9_ta := ?,
471 template (present) uint7_t tai10_ta := ?,
472 template (present) uint7_t tai11_ta := ?,
473 template (present) uint7_t tai12_ta := ?,
474 template (present) uint7_t tai13_ta := ?,
475 template (present) uint7_t tai14_ta := ?,
476 template (present) uint7_t tai15_ta := ?
477 ) := {
478 ta_idx := {
479 { spare := '0'B, ta_val := tai0_ta },
480 { spare := '0'B, ta_val := tai1_ta },
481 { spare := '0'B, ta_val := tai2_ta },
482 { spare := '0'B, ta_val := tai3_ta },
483 { spare := '0'B, ta_val := tai4_ta },
484 { spare := '0'B, ta_val := tai5_ta },
485 { spare := '0'B, ta_val := tai6_ta },
486 { spare := '0'B, ta_val := tai7_ta },
487 { spare := '0'B, ta_val := tai8_ta },
488 { spare := '0'B, ta_val := tai9_ta },
489 { spare := '0'B, ta_val := tai10_ta },
490 { spare := '0'B, ta_val := tai11_ta },
491 { spare := '0'B, ta_val := tai12_ta },
492 { spare := '0'B, ta_val := tai13_ta },
493 { spare := '0'B, ta_val := tai14_ta },
494 { spare := '0'B, ta_val := tai15_ta }
495 },
496 padding := '2B2B2B2B2B2B2B'O
497 }
498
Harald Welte060e27a2018-03-03 20:38:19 +0100499
Harald Welte484160b2017-07-28 13:30:24 +0200500} with { encode "RAW"; variant "FIELDORDER(msb)" }