blob: 78861ffda30704f2725e1e0df08ad941f77551c9 [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 Welte484160b2017-07-28 13:30:24 +0200116 };
Harald Welte43e060a2017-07-30 22:38:03 +0200117 type record LlcBlock {
118 /* Header is only present if LI field was present */
Harald Welte060e27a2018-03-03 20:38:19 +0100119 LlcBlockHdr hdr optional,
Harald Welte43e060a2017-07-30 22:38:03 +0200120 octetstring payload
121 } with { variant "" };
122 type record of LlcBlock LlcBlocks;
Harald Welte484160b2017-07-28 13:30:24 +0200123
124 /* TS 44.060 10.2.1 Downlink RLC data block */
Harald Welte43e060a2017-07-30 22:38:03 +0200125 type record DlMacHdrDataExt {
Harald Welte484160b2017-07-28 13:30:24 +0200126 /* Octet 1 */
Harald Welte484160b2017-07-28 13:30:24 +0200127 PowerReduction pr,
128 BIT1 spare,
129 uint4_t tfi, /* 3 or 4? */
130 boolean fbi,
Harald Welte43e060a2017-07-30 22:38:03 +0200131 /* Octet 2 */
Harald Welte484160b2017-07-28 13:30:24 +0200132 uint7_t bsn,
Harald Welte43e060a2017-07-30 22:38:03 +0200133 boolean e
134 } with {
135 variant (e) "FIELDLENGTH(1)"
136 };
137 type record DlMacDataHeader {
138 DlMacHeader mac_hdr,
139 DlMacHdrDataExt hdr_ext
Harald Welte484160b2017-07-28 13:30:24 +0200140 } with { variant "" };
Harald Welte43e060a2017-07-30 22:38:03 +0200141 type record RlcmacDlDataBlock {
142 DlMacDataHeader mac_hdr,
143 /* Octet 3..M / N: manual C++ Decoder */
144 LlcBlocks blocks
145 } with {
146 variant ""
147 };
Harald Welte484160b2017-07-28 13:30:24 +0200148
Harald Welte43e060a2017-07-30 22:38:03 +0200149 external function enc_RlcmacDlDataBlock(in RlcmacDlDataBlock si) return octetstring;
150 external function dec_RlcmacDlDataBlock(in octetstring stream) return RlcmacDlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200151
152
153 /* TS 44.060 10.2.2 */
154 type record UlMacDataHeader {
Harald Welte43e060a2017-07-30 22:38:03 +0200155 /* Octet 0 */
Harald Welteefbc2fc2017-07-31 00:05:23 +0200156 MacPayloadType payload_type,
Harald Welte484160b2017-07-28 13:30:24 +0200157 uint4_t countdown,
158 boolean stall_ind,
Harald Welte43e060a2017-07-30 22:38:03 +0200159 boolean retry,
160 /* Octet 1 */
161 BIT1 spare,
162 boolean pfi_ind,
163 uint5_t tfi,
164 boolean tlli_ind,
165 /* Octet 2 */
166 uint7_t bsn,
167 boolean e
Harald Welte484160b2017-07-28 13:30:24 +0200168 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200169 variant (stall_ind) "FIELDLENGTH(1)"
170 variant (retry) "FIELDLENGTH(1)"
171 variant (pfi_ind) "FIELDLENGTH(1)"
172 variant (tlli_ind) "FIELDLENGTH(1)"
173 variant (e) "FIELDLENGTH(1)"
Harald Welte484160b2017-07-28 13:30:24 +0200174 };
175
Harald Welte484160b2017-07-28 13:30:24 +0200176 type record RlcMacUlPfi {
177 uint7_t pfi,
178 boolean m
179 } with {
180 variant (m) "FIELDLENGTH(1)"
181 };
182
183 /* TS 44.060 10.2.2 */
184 type record RlcmacUlDataBlock {
185 /* MAC header */
186 UlMacDataHeader mac_hdr,
Harald Welte43e060a2017-07-30 22:38:03 +0200187 /* Octet 3 ... M (optional): manual C++ Decoder */
188 GprsTlli tlli optional,
189 RlcMacUlPfi pfi optional,
190 LlcBlocks blocks
Harald Welte484160b2017-07-28 13:30:24 +0200191 } with {
Harald Welte43e060a2017-07-30 22:38:03 +0200192 variant (tlli) "PRESENCE(mac_hdr.tlli_ind = true)"
193 variant (pfi) "PRESENCE(mac_hdr.pfi_ind = true)"
Harald Welte484160b2017-07-28 13:30:24 +0200194 };
195
Harald Welte43e060a2017-07-30 22:38:03 +0200196 external function enc_RlcmacUlDataBlock(in RlcmacUlDataBlock si) return octetstring;
197 external function dec_RlcmacUlDataBlock(in octetstring stream) return RlcmacUlDataBlock;
Harald Welte484160b2017-07-28 13:30:24 +0200198
Harald Welteefbc2fc2017-07-31 00:05:23 +0200199 type union RlcmacUlBlock {
200 RlcmacUlDataBlock data,
201 RlcmacUlCtrlBlock ctrl
202 } with {
203 variant "TAG(data, mac_hdr.payload_type = MAC_PT_RLC_DATA;
204 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
205 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
206 };
207
Harald Welte78a1af62017-07-31 17:33:56 +0200208 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
209 * use auto-generated functions here, as they would decode those sub-types
210 * based on the RAW coder, not baed on the manual C++ functions */
211 external function enc_RlcmacUlBlock(in RlcmacUlBlock si) return octetstring;
212 external function dec_RlcmacUlBlock(in octetstring stream) return RlcmacUlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200213
214 type union RlcmacDlBlock {
215 RlcmacDlDataBlock data,
216 RlcmacDlCtrlBlock ctrl
217 } with {
218 variant "TAG(data, mac_hdr.mac_hdr.payload_type = MAC_PT_RLC_DATA;
219 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_NO_OPT;
220 ctrl, mac_hdr.payload_type = MAC_PT_RLCMAC_OPT)"
221 };
222
Harald Welte78a1af62017-07-31 17:33:56 +0200223 /* as the sub-types (RlcmacDl*Block) are not using the RAW coder, we cannot
224 * use auto-generated functions here, as they would decode those sub-types
225 * based on the RAW coder, not baed on the manual C++ functions */
226 external function enc_RlcmacDlBlock(in RlcmacDlBlock si) return octetstring;
227 external function dec_RlcmacDlBlock(in octetstring stream) return RlcmacDlBlock;
Harald Welteefbc2fc2017-07-31 00:05:23 +0200228
Harald Welte7024baa2018-03-02 23:37:51 +0100229 template (value) RlcmacUlBlock ts_RLC_UL_CTRL_ACK(RlcmacUlCtrlMsg ctrl,
230 MacPayloadType pt := MAC_PT_RLCMAC_NO_OPT,
231 boolean retry := false) := {
232 ctrl := {
233 mac_hdr := {
234 payload_type := pt,
235 spare := '00000'B,
236 retry := retry
237 },
238 payload := ctrl
239 }
240 }
241
Harald Welte060e27a2018-03-03 20:38:19 +0100242 /* Template fro uplink Data block */
243 template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
244 template LlcBlocks blocks := {}, template boolean stall := false) := {
245 data := {
246 mac_hdr := {
247 payload_type := MAC_PT_RLC_DATA,
248 countdown := cv,
249 stall_ind := false,
250 retry := false,
251 spare := '0'B,
252 pfi_ind := false,
253 tfi := tfi,
254 tlli_ind := false,
255 bsn := bsn,
256 e := false
257 },
258 tlli := omit,
259 pfi := omit,
260 blocks := blocks
261 }
262 }
263 template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn,
264 template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) := {
265 data := {
266 mac_hdr := {
267 payload_type := MAC_PT_RLC_DATA,
268 countdown := cv,
269 stall_ind := false,
270 retry := false,
271 spare := '0'B,
272 pfi_ind := false,
273 tfi := tfi,
274 tlli_ind := true,
275 bsn := bsn,
276 e := false
277 },
278 tlli := tlli,
279 pfi := omit,
280 blocks := blocks
281 }
282 }
283
284 template DlMacHeader t_RLCMAC_DlMacH(template MacPayloadType pt, template MacRrbp rrbp, template
285uint3_t usf) := {
286 payload_type := pt,
287 rrbp := rrbp,
288 rrbp_valid := ispresent(rrbp),
289 usf := usf
290 }
291
292 /* Receive Template for Downlink ACK/NACK */
293 template RlcmacDlBlock tr_RLCMAC_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := {
294 ctrl := {
295 mac_hdr := {
296 payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT),
297 rrbp:= ?,
298 rrbp_valid := true,
299 usf := ?
300 },
301 opt := *,
302 payload := {
303 msg_type := PACKET_UL_ACK_NACK,
304 u := {
305 ul_ack_nack := {
306 page_mode := ?,
307 msg_excape := ?,
308 uplink_tfi := ul_tfi,
309 is_egprs := '0'B,
310 gprs := {
311 ch_coding_cmd := ?,
312 ack_nack_desc := ?,
313 cont_res_tlli_present := ?,
314 cont_res_tlli := tlli,
315 pkt_ta_present := ?,
316 pkt_ta := *,
317 pwr_ctrl_present := ?,
318 pwr_ctrl := *
319 }
320 }
321 }
322 }
323 }
324 }
325
326 /* Template for Uplink MAC Control Header */
327 template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := {
328 payload_type := pt,
329 spare := '00000'B,
330 retry := retry
331 }
332
333 /* Template for Uplink Conntrol ACK */
334 template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := {
335 ctrl := {
336 mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT),
337 payload := {
338 msg_type := PACKET_CONTROL_ACK,
339 u := {
340 ctrl_ack := {
341 tlli := tlli,
342 ctrl_ack := ack
343 }
344 }
345 }
346 }
347 }
348
349 /* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */
350 template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, boolean more := false, boolean e := true) := {
351 /* let encoder figure out the header */
352 hdr := omit,
353 payload := data
354 }
355
356
Harald Welte484160b2017-07-28 13:30:24 +0200357} with { encode "RAW"; variant "FIELDORDER(msb)" }