Pau Espin Pedrol | e8d7d16 | 2020-04-29 19:07:36 +0200 | [diff] [blame] | 1 | /* TITAN REW encode/decode definitions for 3GPP TS 44.060 RLC/MAC Blocks */ |
| 2 | |
| 3 | /* (C) 2017-2018 Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | */ |
| 12 | |
| 13 | module RLCMAC_Templates { |
| 14 | import from General_Types all; |
| 15 | import from Osmocom_Types all; |
| 16 | import from GSM_Types all; |
| 17 | import from RLCMAC_CSN1_Types all; |
| 18 | import from RLCMAC_CSN1_Templates all; |
| 19 | import from RLCMAC_Types all; |
| 20 | |
| 21 | /* TS 44.060 10.4.5 */ |
| 22 | function f_rrbp_fn_delay(MacRrbp rrbp) return uint32_t { |
| 23 | select (rrbp) { |
| 24 | case (RRBP_Nplus13_mod_2715648) { return 13; } |
| 25 | case (RRBP_Nplus17_or_18_mod_2715648) { return 17; } |
| 26 | case (RRBP_Nplus21_or_22_mod_2715648) { return 21; } |
| 27 | case (RRBP_Nplus26_mod_2715648) { return 26; } |
| 28 | } |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | function f_rlcmac_cs_mcs2block_len(CodingScheme cs_mcs) return uint32_t { |
| 33 | select (cs_mcs) { |
| 34 | case (CS_1) { return 23; } |
| 35 | case (CS_2) { return 34; } |
| 36 | case (CS_3) { return 40; } |
| 37 | case (CS_4) { return 54; } |
| 38 | case (MCS_1) { return 27; } |
| 39 | case (MCS_2) { return 33; } |
| 40 | case (MCS_3) { return 42; } |
| 41 | case (MCS_4) { return 49; } |
| 42 | case (MCS_5) { return 61; } |
| 43 | case (MCS_6) { return 79; } |
| 44 | case (MCS_7) { return 119; } |
| 45 | case (MCS_8) { return 143; } |
| 46 | case (MCS_9) { return 155; } |
| 47 | } |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | function f_rlcmac_block_len2cs_mcs(uint32_t len) return CodingScheme { |
| 52 | select (len) { |
| 53 | case (23) { return CS_1; } |
| 54 | case (34) { return CS_2; } |
| 55 | case (40) { return CS_3; } |
| 56 | case (54) { return CS_4; } |
| 57 | case (27) { return MCS_1; } |
| 58 | case (33) { return MCS_2; } |
| 59 | case (42) { return MCS_3; } |
| 60 | case (49) { return MCS_4; } |
| 61 | case (60) { return MCS_5; } |
| 62 | case (61) { return MCS_5; } |
| 63 | case (78) { return MCS_6; } |
| 64 | case (79) { return MCS_6; } |
| 65 | case (118) { return MCS_7; } |
| 66 | case (119) { return MCS_7; } |
| 67 | case (142) { return MCS_8; } |
| 68 | case (143) { return MCS_8; } |
| 69 | case (154) { return MCS_9; } |
| 70 | case (155) { return MCS_9; } |
| 71 | } |
| 72 | return CS_1; |
| 73 | } |
| 74 | |
| 75 | template (value) RlcmacUlBlock ts_RLC_UL_CTRL_ACK(RlcmacUlCtrlMsg ctrl, |
| 76 | MacPayloadType pt := MAC_PT_RLCMAC_NO_OPT, |
| 77 | boolean retry := false) := { |
| 78 | ctrl := { |
| 79 | mac_hdr := { |
| 80 | payload_type := pt, |
| 81 | spare := '00000'B, |
| 82 | retry := retry |
| 83 | }, |
| 84 | payload := ctrl |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /* Send Template for Downlink ACK/NACK */ |
| 89 | template RlcmacUlBlock ts_RLCMAC_DL_ACK_NACK(template uint5_t tfi, AckNackDescription andesc, boolean retry := false) := { |
| 90 | ctrl := { |
| 91 | mac_hdr := { |
| 92 | payload_type := MAC_PT_RLCMAC_NO_OPT, |
| 93 | spare := '00000'B, |
| 94 | retry := retry |
| 95 | }, |
| 96 | payload := { |
| 97 | msg_type := PACKET_DL_ACK_NACK, |
| 98 | u := { |
| 99 | dl_ack_nack := { |
| 100 | dl_tfi := tfi, |
| 101 | ack_nack_desc := andesc, |
| 102 | chreq_desc_presence := '0'B, |
| 103 | chreq_desc := omit, |
| 104 | ch_qual_rep := c_ChQualRep_default |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /* Template for uplink Data block */ |
| 112 | template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn, |
| 113 | template LlcBlocks blocks := {}, template boolean stall := false) := { |
| 114 | data := { |
| 115 | mac_hdr := { |
| 116 | payload_type := MAC_PT_RLC_DATA, |
| 117 | countdown := cv, |
| 118 | stall_ind := false, |
| 119 | retry := false, |
| 120 | spare := '0'B, |
| 121 | pfi_ind := false, |
| 122 | tfi := tfi, |
| 123 | tlli_ind := false, |
| 124 | bsn := bsn, |
| 125 | e := false |
| 126 | }, |
| 127 | tlli := omit, |
| 128 | pfi := omit, |
| 129 | blocks := blocks |
| 130 | } |
| 131 | } |
| 132 | template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn, |
| 133 | template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) := { |
| 134 | data := { |
| 135 | mac_hdr := { |
| 136 | payload_type := MAC_PT_RLC_DATA, |
| 137 | countdown := cv, |
| 138 | stall_ind := false, |
| 139 | retry := false, |
| 140 | spare := '0'B, |
| 141 | pfi_ind := false, |
| 142 | tfi := tfi, |
| 143 | tlli_ind := true, |
| 144 | bsn := bsn, |
| 145 | e := false |
| 146 | }, |
| 147 | tlli := tlli, |
| 148 | pfi := omit, |
| 149 | blocks := blocks |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | template DlMacHeader t_RLCMAC_DlMacH(template MacPayloadType pt, template MacRrbp rrbp, template |
| 154 | uint3_t usf) := { |
| 155 | payload_type := pt, |
| 156 | rrbp := rrbp, |
| 157 | rrbp_valid := ispresent(rrbp), |
| 158 | usf := usf |
| 159 | } |
| 160 | |
| 161 | template RlcmacDlBlock tr_RLCMAC_DUMMY_CTRL(template uint3_t usf := ?, template PageMode page_mode := ?) := { |
| 162 | ctrl := { |
| 163 | mac_hdr := { |
| 164 | payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT), |
| 165 | rrbp:= ?, |
| 166 | rrbp_valid := ?, |
| 167 | usf := usf |
| 168 | }, |
| 169 | opt := *, |
| 170 | payload := { |
| 171 | msg_type := PACKET_DL_DUMMY_CTRL, |
| 172 | u := { |
| 173 | dl_dummy := { |
| 174 | page_mode := page_mode, |
| 175 | persistence_levels_present := ?, |
| 176 | persistence_levels := * |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | template RlcmacDlBlock tr_RLCMAC_DL_PACKET_ASS(template uint3_t usf := ?) := { |
| 184 | ctrl := { |
| 185 | mac_hdr := { |
| 186 | payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT), |
| 187 | rrbp:= ?, |
| 188 | rrbp_valid := ?, |
| 189 | usf := usf |
| 190 | }, |
| 191 | opt := *, |
| 192 | payload := { |
| 193 | msg_type := PACKET_DL_ASSIGNMENT, |
| 194 | u := { |
| 195 | dl_assignment := { |
| 196 | page_mode := ?, |
| 197 | pres1 := ?, |
| 198 | persistence_levels := *, |
| 199 | tfi_or_tlli := ? |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | template RlcmacDlBlock tr_RLCMAC_UL_PACKET_ASS(template uint3_t usf := ?) := { |
| 207 | ctrl := { |
| 208 | mac_hdr := { |
| 209 | payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT), |
| 210 | rrbp:= ?, |
| 211 | rrbp_valid := ?, |
| 212 | usf := usf |
| 213 | }, |
| 214 | opt := *, |
| 215 | payload := { |
| 216 | msg_type := PACKET_UL_ASSIGNMENT, |
| 217 | u := { |
| 218 | ul_assignment := { |
| 219 | page_mode := ?, |
| 220 | persistence_levels_present := ?, |
| 221 | persistence_levels := *, |
| 222 | identity := ?, |
| 223 | is_egprs := ?, /* msg escape */ |
| 224 | gprs := * |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /* Receive Template for Uplink ACK/NACK */ |
| 233 | template RlcmacDlBlock tr_RLCMAC_UL_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := { |
| 234 | ctrl := { |
| 235 | mac_hdr := { |
| 236 | payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT), |
| 237 | rrbp:= ?, |
| 238 | rrbp_valid := ?, |
| 239 | usf := ? |
| 240 | }, |
| 241 | opt := *, |
| 242 | payload := { |
| 243 | msg_type := PACKET_UL_ACK_NACK, |
| 244 | u := { |
| 245 | ul_ack_nack := { |
| 246 | page_mode := ?, |
| 247 | msg_excape := ?, |
| 248 | uplink_tfi := ul_tfi, |
| 249 | is_egprs := '0'B, |
| 250 | gprs := { |
| 251 | ch_coding_cmd := ?, |
| 252 | ack_nack_desc := ?, |
| 253 | cont_res_tlli_present := ?, |
| 254 | cont_res_tlli := tlli, |
| 255 | pkt_ta_present := ?, |
| 256 | pkt_ta := *, |
| 257 | pwr_ctrl_present := ?, |
| 258 | pwr_ctrl := * |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | template RlcmacDlBlock tr_RLCMAC_PACKET_PAG_REQ(template uint3_t usf := ?) := { |
| 267 | ctrl := { |
| 268 | mac_hdr := { |
| 269 | payload_type := MAC_PT_RLCMAC_NO_OPT, |
| 270 | rrbp:= ?, |
| 271 | rrbp_valid := ?, |
| 272 | usf := usf |
| 273 | }, |
| 274 | opt := *, |
| 275 | payload := { |
| 276 | msg_type := PACKET_PAGING_REQUEST, |
| 277 | u := { |
| 278 | paging := { |
| 279 | page_mode := ?, |
| 280 | persistence_levels_present := ?, |
| 281 | persistence_levels := *, |
| 282 | nln_present := ?, |
| 283 | nln := *, |
| 284 | repeated_pageinfo_present := ?, |
| 285 | repeated_pageinfo := * |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | template RlcmacDlBlock tr_RLCMAC_DATA_RRBP := { |
| 293 | data := { |
| 294 | mac_hdr := { |
| 295 | mac_hdr := { |
| 296 | payload_type := MAC_PT_RLC_DATA, |
| 297 | rrbp := ?, |
| 298 | rrbp_valid := true, |
| 299 | usf := ? |
| 300 | }, |
| 301 | hdr_ext := ? |
| 302 | }, |
| 303 | blocks := ? |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | template RlcmacDlBlock tr_RLCMAC_DATA_EGPRS := { |
| 308 | data_egprs := { |
| 309 | mac_hdr := ?, |
| 310 | fbi := ?, |
| 311 | e := ?, |
| 312 | blocks := ? |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /* Template for Uplink MAC Control Header */ |
| 317 | template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := { |
| 318 | payload_type := pt, |
| 319 | spare := '00000'B, |
| 320 | retry := retry |
| 321 | } |
| 322 | |
| 323 | /* Template for Uplink Control ACK */ |
| 324 | template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := { |
| 325 | ctrl := { |
| 326 | mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT), |
| 327 | payload := { |
| 328 | msg_type := PACKET_CONTROL_ACK, |
| 329 | u := { |
| 330 | ctrl_ack := { |
| 331 | tlli := tlli, |
| 332 | ctrl_ack := ack |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */ |
| 340 | template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, boolean more := false, boolean e := true) := { |
| 341 | /* let encoder figure out the header */ |
| 342 | hdr := omit, |
| 343 | payload := data |
| 344 | } |
| 345 | |
| 346 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |