Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1 | module GPRS_Components { |
| 2 | /* |
| 3 | * Osmocom PCU test suite in TTCN-3, components for GPRS handlng |
| 4 | * (C) 2018-2019 Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2019 Vadim Yanitskiy <axilirator@gmail.com> |
| 6 | * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Released under the terms of GNU General Public License, Version 2 or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 13 | */ |
| 14 | |
| 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
| 17 | import from GSM_Types all; |
| 18 | import from GSM_RR_Types all; |
| 19 | |
| 20 | import from Osmocom_VTY_Functions all; |
| 21 | import from TELNETasp_PortType all; |
| 22 | |
| 23 | import from MobileL3_GMM_SM_Types all; |
| 24 | import from RLCMAC_CSN1_Types all; |
| 25 | import from RLCMAC_CSN1_Templates all; |
| 26 | import from RLCMAC_Types all; |
| 27 | import from RLCMAC_Templates all; |
| 28 | |
| 29 | import from MobileL3_CommonIE_Types all; |
| 30 | import from L3_Templates all; |
| 31 | |
| 32 | import from NS_Types all; |
| 33 | import from BSSGP_Types all; |
| 34 | import from Osmocom_Gb_Types all; |
| 35 | |
| 36 | import from BSSGP_Emulation all; /* BssgpConfig */ |
| 37 | import from NS_Emulation all; /* NSConfiguration */ |
| 38 | |
| 39 | import from UD_Types all; |
| 40 | import from PCUIF_Types all; |
| 41 | import from PCUIF_CodecPort all; |
| 42 | import from PCUIF_Components all; |
| 43 | import from IPL4asp_Types all; |
| 44 | import from Native_Functions all; |
| 45 | import from SGSN_Components all; |
| 46 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 47 | type union PacketDlAssignChan { |
| 48 | PacketDlAssign ccch, |
| 49 | PacketDlAssignment pacch |
| 50 | }; |
| 51 | |
| 52 | type record DlTbf { |
| 53 | GsmRrMessage rr_imm_ass, |
| 54 | PacketDlAssignChan ass, |
| 55 | uint5_t tfi, |
| 56 | AckNackDescription acknack_desc |
| 57 | }; |
| 58 | |
| 59 | type union PacketUlAssignChan { |
| 60 | PacketUlAssign ccch, |
| 61 | EgprsUlAss ccch_egprs, |
| 62 | PacketUlAssignment pacch |
| 63 | }; |
| 64 | |
| 65 | type record UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 66 | GsmRrMessage rr_imm_ass optional, |
| 67 | PacketUlAssignChan ass optional, |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 68 | uint5_t tfi, |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 69 | uint3_t usf[8], |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 70 | boolean is_egprs, |
| 71 | uint14_t bsn, |
| 72 | CodingScheme tx_cs_mcs |
| 73 | }; |
| 74 | |
| 75 | type record GprsMS { |
| 76 | hexstring imsi, |
| 77 | GprsTlli tlli, |
| 78 | uint16_t ra, |
| 79 | uint8_t ra_is_11bit, |
| 80 | PCUIF_BurstType burst_type, |
| 81 | TimingAdvance ta, |
| 82 | int16_t lqual_cb, |
| 83 | UlTbf ul_tbf optional, /* TODO: Only 1 UL tbf supported for now */ |
| 84 | DlTbf dl_tbf optional /* TODO: Only 1 DL tbf supported for now */ |
| 85 | }; |
| 86 | type record of GprsMS GprsMSArray; |
| 87 | |
| 88 | template AckNackDescription t_AckNackDescription_init := { |
| 89 | final_ack := '0'B, |
| 90 | starting_seq_nr := 0, |
| 91 | receive_block_bitmap := '0000000000000000000000000000000000000000000000000000000000000000'B |
| 92 | } |
| 93 | |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 94 | const uint3_t USF_UNUSED := 7; /* used to indicate PRACH */ |
| 95 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 96 | template (value) GprsMS t_GprsMS_def := { |
| 97 | imsi := f_gen_imsi(42), |
| 98 | tlli := '00000001'O, |
| 99 | ra := bit2int(chan_req_def), |
| 100 | ra_is_11bit := 0, |
| 101 | burst_type := BURST_TYPE_0, |
| 102 | ta := 0, |
| 103 | lqual_cb := 0, |
| 104 | ul_tbf := omit, |
| 105 | dl_tbf := omit |
| 106 | }; |
| 107 | |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 108 | template (value) UlTbf t_UlTbf_def := { |
| 109 | rr_imm_ass := omit, |
| 110 | ass := omit, |
| 111 | tfi := 0, |
| 112 | usf := { USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED }, |
| 113 | is_egprs := false, |
| 114 | bsn := 0, |
| 115 | tx_cs_mcs := CS_1 |
| 116 | }; |
| 117 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 118 | type component MS_BTS_IFACE_CT { |
| 119 | /* Virtual BTS component */ |
| 120 | var RAW_PCU_BTS_CT vc_BTS; |
| 121 | /* Connection to the BTS component (one for now) */ |
| 122 | port RAW_PCU_MSG_PT BTS; |
| 123 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 124 | /* Support only 1 ms for now */ |
| 125 | var GprsMS g_ms[1]; |
| 126 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 127 | /* Value at which Countdown Procedure starts. Announced by network (GPRS Cell Options as per TS 04.60 Chapter 12.24) */ |
| 128 | var uint4_t g_bs_cv_max := 4; |
| 129 | } |
| 130 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 131 | function f_init_gprs_ms(template (value) GprsMS ms_params := t_GprsMS_def) runs on MS_BTS_IFACE_CT |
| 132 | { |
| 133 | g_ms[0] := valueof(ms_params); |
| 134 | } |
| 135 | |
| 136 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 137 | function f_shutdown(charstring file, integer line, |
| 138 | boolean final := false) |
| 139 | runs on MS_BTS_IFACE_CT { |
| 140 | /* Determine if the test case was aborted in the middle */ |
| 141 | if (not final) { |
| 142 | log("Test case ", testcasename(), " aborted at ", file, ":", line); |
| 143 | } else { |
| 144 | /* Guard verdict to avoid 'none' */ |
| 145 | setverdict(pass); |
| 146 | } |
| 147 | |
| 148 | /* Properly shutdown virtual BTS and its clock generator */ |
| 149 | BTS.send(ts_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)); |
| 150 | vc_BTS.done; /* wait untill it's done */ |
| 151 | |
| 152 | /* Shutdown the others and MTC */ |
| 153 | all component.stop; |
| 154 | mtc.stop; |
| 155 | } |
| 156 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 157 | function f_ultbf_new_from_rr_imm_ass(in GsmRrMessage rr_imm_ass) |
| 158 | runs on MS_BTS_IFACE_CT return UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 159 | var UlTbf ul_tbf := valueof(t_UlTbf_def); |
| 160 | var uint3_t tn_allocated := rr_imm_ass.payload.imm_ass.pkt_chan_desc.tn; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 161 | |
| 162 | ul_tbf.rr_imm_ass := rr_imm_ass; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 163 | |
| 164 | /* Make sure we received an UL TBF Assignment */ |
| 165 | if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_ULAss(?)))) { |
| 166 | ul_tbf.ass.ccch := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.ul; |
| 167 | log("Rx Uplink TBF GPRS assignment: ", ul_tbf.ass.ccch); |
| 168 | ul_tbf.is_egprs := false; |
| 169 | if (match(ul_tbf.ass.ccch, tr_PacketUlDynAssign)) { |
| 170 | ul_tbf.tfi := ul_tbf.ass.ccch.dynamic.tfi_assignment; |
Pau Espin Pedrol | 9040111 | 2020-05-20 17:36:27 +0200 | [diff] [blame] | 171 | ul_tbf.tx_cs_mcs := f_rlcmac_block_ChCodingCommand2cs_mcs(ul_tbf.ass.ccch.dynamic.ch_coding_cmd); |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 172 | ul_tbf.usf[tn_allocated] := ul_tbf.ass.ccch.dynamic.usf; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 173 | } else if (match(ul_tbf.ass.ccch, tr_PacketUlSglAssign)) { |
| 174 | /* Nothing to do here yet */ |
| 175 | } |
| 176 | } else if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_EGPRSULAss(?)))) { |
| 177 | ul_tbf.ass.ccch_egprs := rr_imm_ass.payload.imm_ass.rest_octets.lh.egprs_ul; |
| 178 | log("Rx Uplink TBF EGPRS assignment: ", ul_tbf.ass.ccch_egprs); |
| 179 | ul_tbf.is_egprs := true; |
| 180 | if (match(ul_tbf.ass.ccch_egprs, tr_EgprsUlAssDynamic)) { |
| 181 | ul_tbf.tfi := ul_tbf.ass.ccch_egprs.dynamic.tfi_assignment; |
Pau Espin Pedrol | 9040111 | 2020-05-20 17:36:27 +0200 | [diff] [blame] | 182 | ul_tbf.tx_cs_mcs := f_rlcmac_block_EgprsChCodingCommand2cs_mcs(ul_tbf.ass.ccch_egprs.dynamic.egprs_ch_coding_cmd); |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 183 | ul_tbf.usf[tn_allocated] := ul_tbf.ass.ccch_egprs.dynamic.usf; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 184 | } else if (match(ul_tbf.ass.ccch_egprs, tr_EgprsUlAssMultiblock)) { |
| 185 | /* Nothing to do here yet */ |
| 186 | } |
| 187 | } else { |
| 188 | setverdict(fail, "Failed to match UL TBF Assignment: ", rr_imm_ass); |
| 189 | f_shutdown(__BFILE__, __LINE__); |
| 190 | } |
| 191 | |
| 192 | setverdict(pass); |
| 193 | return ul_tbf; |
| 194 | } |
| 195 | |
| 196 | function f_ultbf_new_from_ass_pacch(RlcmacDlBlock dl_block) |
| 197 | runs on MS_BTS_IFACE_CT return UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 198 | var UlTbf ul_tbf := valueof(t_UlTbf_def); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 199 | |
| 200 | ul_tbf.ass.pacch := dl_block.ctrl.payload.u.ul_assignment; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 201 | ul_tbf.tx_cs_mcs := f_rlcmac_dl_block_get_assigned_ul_cs_mcs(dl_block); |
| 202 | ul_tbf.tfi := f_rlcmac_dl_block_get_tfi(dl_block); |
| 203 | /* TODO: handle GlobalTfiOrTlli tfi_or_tlli from pkt_ul_ass */ |
| 204 | |
| 205 | /* TODO: support single block allocation */ |
| 206 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 207 | ul_tbf.tfi := dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ul_tfi_assignment; |
| 208 | ul_tbf.is_egprs := false; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 209 | for (var integer i := 0; i < 8; i := i + 1) { |
| 210 | if (dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ts_allocation.ts[i].presence == '1'B) { |
| 211 | ul_tbf.usf[i] := dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ts_allocation.ts[i].usf_tn; |
| 212 | } |
| 213 | } |
| 214 | } else if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(tr_DynamicAllocation(?))))) { |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 215 | ul_tbf.tfi := dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ul_tfi_assignment; |
| 216 | ul_tbf.is_egprs := true; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 217 | for (var integer i := 0; i < 8; i := i + 1) { |
| 218 | if (dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ts_allocation.ts[i].presence == '1'B) { |
| 219 | ul_tbf.usf[i] := dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ts_allocation.ts[i].usf_tn; |
| 220 | } |
| 221 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 222 | } |
| 223 | return ul_tbf; |
| 224 | } |
| 225 | |
| 226 | function f_dltbf_new_from_rr_imm_ass(in GsmRrMessage rr_imm_ass, template PacketDlAssign dl_ass := tr_PacketDlAssign(?)) |
| 227 | runs on MS_BTS_IFACE_CT return DlTbf { |
| 228 | var DlTbf dl_tbf; |
| 229 | |
| 230 | dl_tbf.rr_imm_ass := rr_imm_ass; |
| 231 | dl_tbf.acknack_desc := valueof(t_AckNackDescription_init); |
| 232 | |
| 233 | /* Make sure we received a DL TBF Assignment */ |
| 234 | if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := true, rest := tr_IaRestOctets_DLAss(dl_ass)))) { |
| 235 | dl_tbf.ass.ccch := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.dl; |
| 236 | log("Rx Downlink TBF assignment: ", dl_tbf.ass); |
| 237 | } else { |
| 238 | setverdict(fail, "Failed to match DL TBF Assignment: ", rr_imm_ass); |
| 239 | f_shutdown(__BFILE__, __LINE__); |
| 240 | } |
| 241 | |
| 242 | /* TODO: match TLLI */ |
| 243 | if (dl_tbf.ass.ccch.group1_present == '1'B) { |
| 244 | dl_tbf.tfi := dl_tbf.ass.ccch.group1.tfi_assignment; |
| 245 | } else { |
| 246 | setverdict(fail, "Immediate Assignment contains no DL TFI"); |
| 247 | f_shutdown(__BFILE__, __LINE__); |
| 248 | } |
| 249 | |
| 250 | setverdict(pass); |
| 251 | return dl_tbf; |
| 252 | } |
| 253 | |
| 254 | /* TODO: get stuff from f_rx_rlcmac_dl_block_exp_pkt_ass */ |
| 255 | function f_dltbf_new_from_ass_pacch(RlcmacDlBlock dl_block) |
| 256 | runs on MS_BTS_IFACE_CT return DlTbf { |
| 257 | var DlTbf dl_tbf; |
| 258 | |
| 259 | dl_tbf.ass.pacch := dl_block.ctrl.payload.u.dl_assignment; |
| 260 | dl_tbf.tfi := f_rlcmac_dl_block_get_tfi(dl_block); |
| 261 | /* TODO: handle GlobalTfiOrTlli tfi_or_tlli from pkt_dl_ass */ |
| 262 | dl_tbf.acknack_desc := valueof(t_AckNackDescription_init); |
| 263 | return dl_tbf; |
| 264 | } |
| 265 | |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 266 | function f_ultbf_inc_bsn(inout UlTbf ul_tbf) |
| 267 | runs on MS_BTS_IFACE_CT { |
| 268 | ul_tbf.bsn := ul_tbf.bsn + 1; |
| 269 | ul_tbf.bsn := ul_tbf.bsn mod 128; /* FIXME: EGPRS SNS: 2048 */ |
| 270 | } |
| 271 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 272 | function f_ms_use_ra(inout GprsMS ms, uint16_t ra, uint8_t ra_is_11bit := 0) |
| 273 | runs on MS_BTS_IFACE_CT { |
| 274 | ms.ra_is_11bit := ra_is_11bit; |
| 275 | ms.ra := ra; |
| 276 | if (ra_is_11bit == 0) { |
| 277 | ms.burst_type := BURST_TYPE_0; |
| 278 | } else { |
| 279 | ms.burst_type := BURST_TYPE_1; |
| 280 | } |
| 281 | } |
| 282 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 283 | function f_ms_rx_imm_ass_pacch(inout GprsMS ms, out uint32_t poll_fn, template RlcmacDlBlock t_imm_ass := ?) |
| 284 | runs on MS_BTS_IFACE_CT return RlcmacDlBlock { |
| 285 | var RlcmacDlBlock dl_block; |
| 286 | var uint32_t dl_fn; |
| 287 | |
| 288 | f_rx_rlcmac_dl_block(dl_block, dl_fn); |
| 289 | if (not match(dl_block, t_imm_ass)) { |
| 290 | setverdict(fail, "Failed to match Packet Assignment:", t_imm_ass); |
| 291 | f_shutdown(__BFILE__, __LINE__); |
| 292 | } |
| 293 | |
| 294 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 295 | |
| 296 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS)) { |
| 297 | ms.ul_tbf := f_ultbf_new_from_ass_pacch(dl_block); |
| 298 | if (ms.ul_tbf.ass.pacch.identity.tlli.tlli != ms.tlli) { |
| 299 | setverdict(fail, "Wrong TLLI ", ms.ul_tbf.ass.pacch.identity.tlli, " received vs exp ", ms.tlli); |
| 300 | f_shutdown(__BFILE__, __LINE__); |
| 301 | } |
| 302 | } else if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS)) { |
| 303 | ms.dl_tbf := f_dltbf_new_from_ass_pacch(dl_block); |
| 304 | /* TODO: match tlli from ms.dl_tbf.ass.pacch with ms.tlli), or error */ |
| 305 | } else { |
| 306 | setverdict(fail, "Should not happen:", dl_block); |
| 307 | f_shutdown(__BFILE__, __LINE__); |
| 308 | } |
| 309 | |
| 310 | return dl_block; |
| 311 | } |
| 312 | |
Vadim Yanitskiy | 84d1dd5 | 2020-05-28 21:09:22 +0700 | [diff] [blame] | 313 | function f_ms_establish_ul_tbf(inout GprsMS ms) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 314 | runs on MS_BTS_IFACE_CT { |
| 315 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 316 | |
Vadim Yanitskiy | 28d18e1 | 2020-05-29 15:25:59 +0700 | [diff] [blame] | 317 | rr_imm_ass := f_pcuif_tx_rach_rx_imm_ass(ms.ra, ms.ra_is_11bit, ms.burst_type, ms.ta); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 318 | ms.ul_tbf := f_ultbf_new_from_rr_imm_ass(rr_imm_ass); |
| 319 | } |
| 320 | |
Vadim Yanitskiy | 84d1dd5 | 2020-05-28 21:09:22 +0700 | [diff] [blame] | 321 | function f_ms_exp_dl_tbf_ass_ccch(inout GprsMS ms, template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH, |
| 322 | template GsmRrMessage t_imm_ass := tr_IMM_TBF_ASS(true, ?, ?)) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 323 | runs on MS_BTS_IFACE_CT { |
| 324 | var GsmRrMessage rr_imm_ass; |
| 325 | |
Vadim Yanitskiy | 84d1dd5 | 2020-05-28 21:09:22 +0700 | [diff] [blame] | 326 | rr_imm_ass := f_pcuif_rx_imm_ass(sapi, t_imm_ass); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 327 | ms.dl_tbf := f_dltbf_new_from_rr_imm_ass(rr_imm_ass, tr_PacketDlAssign(ms.tlli)); |
| 328 | } |
| 329 | |
| 330 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
| 331 | function f_ms_tx_data_ind(inout GprsMS ms, octetstring data, uint32_t fn := 0) |
| 332 | runs on MS_BTS_IFACE_CT { |
| 333 | f_pcuif_tx_data_ind(data, ms.lqual_cb, fn); |
| 334 | } |
| 335 | |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 336 | function f_ms_tx_ul_block(inout GprsMS ms, template (value) RlcmacUlBlock ul_data, uint32_t fn := 0, template (omit) CodingScheme force_cs_mcs := omit) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 337 | runs on MS_BTS_IFACE_CT return integer { |
| 338 | var octetstring data; |
| 339 | var integer padding_len; |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 340 | var CodingScheme cs_mcs; |
| 341 | var uint32_t cs_mcs_len; |
| 342 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 343 | /* Encode the payload of DATA.ind */ |
| 344 | data := enc_RlcmacUlBlock(valueof(ul_data)); |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 345 | |
| 346 | if (ispresent(force_cs_mcs)) { |
| 347 | cs_mcs := valueof(force_cs_mcs); |
| 348 | } else if (ischosen(ul_data.ctrl)) { |
| 349 | cs_mcs := CS_1; /* CTRL is always CS1 */ |
| 350 | } else { |
| 351 | /* Add padding to encode payload to minimum required CS/MCS: */ |
| 352 | cs_mcs := f_rlcmac_block_len_required_cs_mcs(lengthof(data), ischosen(ul_data.data_egprs)); |
| 353 | } |
| 354 | |
| 355 | cs_mcs_len := f_rlcmac_cs_mcs2block_len(cs_mcs); |
| 356 | padding_len := cs_mcs_len - lengthof(data); |
| 357 | if (padding_len < 0) { |
| 358 | setverdict(fail, "Unable to encode UL block of size ", lengthof(data), " with ", cs_mcs); |
| 359 | f_shutdown(__BFILE__, __LINE__); |
| 360 | } |
| 361 | data := f_pad_oct(data, cs_mcs_len, '00'O); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 362 | |
| 363 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
| 364 | f_ms_tx_data_ind(ms, data, fn); |
| 365 | return padding_len; |
| 366 | } |
| 367 | |
| 368 | /* FIXME: Only supports sending CS-1 so far */ |
| 369 | function f_ms_tx_ul_data_block(inout GprsMS ms, octetstring payload, uint4_t cv := 15, boolean with_tlli := false, uint32_t fn := 0) |
| 370 | runs on MS_BTS_IFACE_CT return integer { |
| 371 | var template (value) RlcmacUlBlock ul_data; |
| 372 | ul_data := t_RLCMAC_UL_DATA(tfi := ms.ul_tbf.tfi, |
| 373 | cv := cv, |
| 374 | bsn := ms.ul_tbf.bsn, |
| 375 | blocks := {t_RLCMAC_LLCBLOCK(payload)}); |
| 376 | if (with_tlli) { |
| 377 | ul_data.data.mac_hdr.tlli_ind := true; |
| 378 | ul_data.data.tlli := ms.tlli; |
| 379 | } |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 380 | f_ultbf_inc_bsn(ms.ul_tbf); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 381 | return f_ms_tx_ul_block(ms, ul_data, fn); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /* Send random payload for last "num_blocks" blocks in Ul TBF (ending with CV=0). */ |
| 385 | function f_ms_tx_ul_data_block_multi(inout GprsMS ms, integer num_blocks := 1, boolean with_tlli := false) |
| 386 | runs on MS_BTS_IFACE_CT return octetstring { |
| 387 | var octetstring total_payload := ''O; |
| 388 | |
| 389 | for (var integer i := 0; i < num_blocks; i := i + 1) { |
| 390 | var integer padding_len; |
| 391 | var octetstring payload := f_rnd_octstring(10); |
| 392 | /* Prepare a new UL block (CV, random payload) */ |
| 393 | var integer cv := num_blocks - i - 1; |
| 394 | if (cv > g_bs_cv_max) { |
| 395 | cv := 15; |
| 396 | } |
| 397 | padding_len := f_ms_tx_ul_data_block(ms, payload, cv := cv, with_tlli := with_tlli) |
| 398 | total_payload := total_payload & payload & f_pad_oct(''O, padding_len, '00'O); |
| 399 | } |
| 400 | return total_payload; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | function f_rlcmac_dl_block_get_tfi(RlcmacDlBlock dl_block) |
| 404 | runs on MS_BTS_IFACE_CT return uint5_t { |
| 405 | if (ischosen(dl_block.data)) { |
| 406 | return dl_block.data.mac_hdr.hdr_ext.tfi; |
| 407 | } else if (ischosen(dl_block.data_egprs)) { |
| 408 | return dl_block.data_egprs.mac_hdr.tfi; |
| 409 | } else { /* Ctrl block */ |
| 410 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 411 | return dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ul_tfi_assignment; |
| 412 | } |
| 413 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(tr_DynamicAllocation(?))))) { |
| 414 | return dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ul_tfi_assignment; |
| 415 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 416 | if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS(?))) { |
| 417 | return dl_block.ctrl.payload.u.dl_assignment.dl_tfi_assignment; |
| 418 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 419 | } |
| 420 | setverdict(fail, "DlBlock doesn't contain a TFI:", dl_block); |
| 421 | f_shutdown(__BFILE__, __LINE__); |
| 422 | return 0; /* make compiler happy */ |
| 423 | } |
| 424 | |
| 425 | /* Get the Chan coding command from a dl block containing PACCH UL Assignment */ |
| 426 | function f_rlcmac_dl_block_get_assigned_ul_cs_mcs(RlcmacDlBlock dl_block) |
| 427 | runs on MS_BTS_IFACE_CT return CodingScheme { |
| 428 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(?)))) { |
| 429 | return f_rlcmac_block_ChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.gprs.ch_coding_cmd); |
| 430 | } |
| 431 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(?)))) { |
| 432 | return f_rlcmac_block_EgprsChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.egprs.chan_coding_cmd); |
| 433 | } |
| 434 | setverdict(fail, "DlBlock doesn't contain CS_MCS information:", dl_block); |
| 435 | f_shutdown(__BFILE__, __LINE__); |
| 436 | return CS_1; /* make compiler happy */ |
| 437 | } |
| 438 | |
| 439 | /* TS 44.060 sec 12.3 Ack/Nack Description */ |
| 440 | function f_acknackdesc_ack_block(inout AckNackDescription desc, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 441 | { |
| 442 | var uint7_t bsn; |
| 443 | var integer i; |
| 444 | var integer inc; |
| 445 | |
| 446 | if (ischosen(dl_block.data)) { |
| 447 | bsn := dl_block.data.mac_hdr.hdr_ext.bsn; |
| 448 | } else { |
| 449 | bsn := dl_block.data_egprs.mac_hdr.bsn1; |
| 450 | } |
| 451 | |
| 452 | inc := bsn - desc.starting_seq_nr + 1; |
| 453 | /* Filling hole? */ |
| 454 | if (bsn < desc.starting_seq_nr) { |
| 455 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr - bsn)] := int2bit(1, 1); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | /* SSN is increased, and so RBB values need to be moved */ |
| 460 | for (i := 0; i < lengthof(desc.receive_block_bitmap) - inc; i := i+1) { |
| 461 | desc.receive_block_bitmap[i] := desc.receive_block_bitmap[i + inc]; |
| 462 | } |
| 463 | for (i := lengthof(desc.receive_block_bitmap) - inc; i < lengthof(desc.receive_block_bitmap) - 1; i := i+1) { |
| 464 | desc.receive_block_bitmap[i] := int2bit(0, 1); |
| 465 | } |
| 466 | /* Now we can set current bit and update SSN */ |
| 467 | desc.starting_seq_nr := bsn + 1; |
| 468 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - 1] := int2bit(1, 1); |
| 469 | |
| 470 | /* Finally update the final_ack bit as requested: */ |
| 471 | desc.final_ack := final_ack; |
| 472 | } |
| 473 | |
| 474 | /* This function can be used to send DATA.cnf in response to the IUT originated DATA.req. |
| 475 | * NOTE: it's the responsibility of caller to make sure that pcu_msg contains u.data_req. */ |
| 476 | function f_pcuif_tx_data_cnf(in PCUIF_Message pcu_msg) |
| 477 | runs on MS_BTS_IFACE_CT { |
| 478 | var PCUIF_Message pcu_msg_cnf := { |
| 479 | msg_type := PCU_IF_MSG_DATA_CNF, |
| 480 | bts_nr := pcu_msg.bts_nr, |
| 481 | spare := pcu_msg.spare, |
| 482 | u := { data_cnf := pcu_msg.u.data_req } |
| 483 | }; |
| 484 | |
| 485 | /* PCU wants DATA.cnf containing basically everything that was in DATA.req, |
| 486 | * but PCU_IF_SAPI_PCH is a special case - paging group shall be excluded. */ |
| 487 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 488 | pcu_msg_cnf.u.data_cnf.data := substr(pcu_msg.u.data_req.data, 3, |
| 489 | pcu_msg.u.data_req.len - 3); |
| 490 | } |
| 491 | |
| 492 | BTS.send(pcu_msg_cnf); |
| 493 | } |
| 494 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 495 | //////////////////////// |
| 496 | // OLD APIs |
| 497 | //////////////////////// |
| 498 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 499 | function f_pcuif_rx_imm_ass(template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH, |
Pau Espin Pedrol | 71c08f6 | 2020-05-28 19:44:56 +0700 | [diff] [blame] | 500 | template GsmRrMessage t_imm_ass := ?) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 501 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 502 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 503 | var PCUIF_Message pcu_msg; |
| 504 | var octetstring data; |
| 505 | timer T; |
| 506 | |
| 507 | T.start(2.0); |
| 508 | alt { |
Pau Espin Pedrol | 71c08f6 | 2020-05-28 19:44:56 +0700 | [diff] [blame] | 509 | [] BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 0, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 510 | sapi := sapi, data := ?)) -> value pcu_msg { |
| 511 | /* On PCH the payload is prefixed with paging group (3 octets): skip it. |
| 512 | * TODO: add an additional template parameter, so we can match it. */ |
| 513 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 514 | data := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 515 | } else { |
| 516 | data := pcu_msg.u.data_req.data; |
| 517 | } |
| 518 | |
| 519 | rr_imm_ass := dec_GsmRrMessage(data); |
| 520 | if (not match(rr_imm_ass, t_imm_ass)) { |
| 521 | /* Not for us? Wait for more. */ |
| 522 | repeat; |
| 523 | } |
| 524 | |
| 525 | log("Rx Immediate Assignment: ", rr_imm_ass); |
Pau Espin Pedrol | 34c940b | 2020-05-28 19:56:11 +0700 | [diff] [blame] | 526 | |
| 527 | /* Send DATA.cnf back to the IUT (only needed for PCH) */ |
| 528 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 529 | f_pcuif_tx_data_cnf(pcu_msg); |
| 530 | } |
| 531 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 532 | setverdict(pass); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 533 | } |
| 534 | [] BTS.receive { repeat; } |
| 535 | [] T.timeout { |
| 536 | setverdict(fail, "Timeout waiting for Immediate Assignment"); |
Pau Espin Pedrol | fddc20b | 2020-05-28 19:50:29 +0700 | [diff] [blame] | 537 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 541 | return rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /* One phase packet access (see 3GPP TS 44.018, table 9.1.8.1) */ |
| 545 | const BIT8 chan_req_def := '01111000'B; |
| 546 | |
| 547 | /* Establish an Uplink TBF by sending RACH.ind towards the PCU */ |
Vadim Yanitskiy | 28d18e1 | 2020-05-29 15:25:59 +0700 | [diff] [blame] | 548 | function f_pcuif_tx_rach_rx_imm_ass(uint16_t ra := bit2int(chan_req_def), |
| 549 | uint8_t is_11bit := 0, |
| 550 | PCUIF_BurstType burst_type := BURST_TYPE_0, |
| 551 | TimingAdvance ta := 0) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 552 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 553 | var uint32_t fn; |
| 554 | |
| 555 | /* FIXME: ask the BTS component to give us the current TDMA fn */ |
| 556 | fn := 1337 + ta; |
| 557 | |
| 558 | /* Send RACH.ind */ |
| 559 | log("Sending RACH.ind on fn=", fn, " with RA=", ra, ", TA=", ta); |
Pau Espin Pedrol | 71c08f6 | 2020-05-28 19:44:56 +0700 | [diff] [blame] | 560 | BTS.send(ts_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 0, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 561 | ra := ra, is_11bit := is_11bit, |
| 562 | burst_type := burst_type, |
| 563 | fn := fn, arfcn := 871, |
| 564 | qta := ta * 4)); |
| 565 | |
| 566 | /* 3GPP TS 44.018, table 9.1.8.1, note 2b: Request Reference shall be set to 127 |
| 567 | * when Immediate Assignment is triggered by EGPRS Packet Channel Request. Here |
| 568 | * we assume that 11 bit RA always contains EGPRS Packet Channel Request. */ |
| 569 | if (is_11bit != 0) { ra := 127; } |
| 570 | |
| 571 | /* Expect Immediate (TBF) Assignment on TS0/AGCH */ |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 572 | return f_pcuif_rx_imm_ass(PCU_IF_SAPI_AGCH, tr_IMM_TBF_ASS(false, ra, fn)); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 575 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
| 576 | function f_pcuif_tx_data_ind(octetstring data, int16_t lqual_cb := 0, uint32_t fn := 0) |
| 577 | runs on MS_BTS_IFACE_CT { |
| 578 | var template RAW_PCU_EventParam ev_param := {tdma_fn := ? }; |
| 579 | BTS.send(ts_PCUIF_DATA_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7, block_nr := 0, |
| 580 | sapi := PCU_IF_SAPI_PDTCH, data := data, |
| 581 | fn := fn, arfcn := 871, lqual_cb := lqual_cb)); |
| 582 | if (fn != 0) { |
| 583 | ev_param := {tdma_fn := fn }; |
| 584 | } |
| 585 | BTS.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_SENT, ev_param)); |
| 586 | } |
| 587 | |
| 588 | /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */ |
| 589 | function f_pcuif_rx_data_req(out PCUIF_Message pcu_msg) |
| 590 | runs on MS_BTS_IFACE_CT { |
| 591 | BTS.send(ts_PCUIF_RTS_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7, |
| 592 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 593 | arfcn := 871, block_nr := 0)); |
| 594 | BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7, |
| 595 | sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg; |
| 596 | } |
| 597 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 598 | /* Expect a Paging Request Type 1 from PCU on PCUIF on specified sapi. */ |
| 599 | function f_pcuif_rx_pch_pag_req1(template MobileIdentityV mi1 := ?, |
| 600 | template integer pag_group := ?) |
| 601 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 602 | var GsmRrMessage rr_pag_req1; |
| 603 | var PCUIF_Message pcu_msg; |
| 604 | var octetstring imsi_suff_octstr; |
| 605 | var integer pag_group_rx; |
| 606 | var octetstring macblock; |
| 607 | |
| 608 | BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 0, |
| 609 | sapi := PCU_IF_SAPI_PCH)) -> value pcu_msg; |
| 610 | |
| 611 | /* First 3 bytes contain IMSI suffix to calculate paging group: */ |
| 612 | imsi_suff_octstr := substr(pcu_msg.u.data_req.data, 0, 3); |
| 613 | pag_group_rx := str2int(oct2char(imsi_suff_octstr[0])) * 100 + |
| 614 | str2int(oct2char(imsi_suff_octstr[1])) * 10 + |
| 615 | str2int(oct2char(imsi_suff_octstr[2])); |
| 616 | |
| 617 | /* Make sure we've got RR Paging Request Type 1 for a given MI */ |
| 618 | macblock := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 619 | rr_pag_req1 := dec_GsmRrMessage(macblock); |
| 620 | if (not match(rr_pag_req1, tr_PAG_REQ1(tr_MI_LV(mi1)))) { |
| 621 | setverdict(fail, "Failed to match Paging Request Type 1: ", rr_pag_req1); |
| 622 | f_shutdown(__BFILE__, __LINE__); |
| 623 | } |
| 624 | |
| 625 | /* Make sure that received paging froup matches the expected one */ |
| 626 | if (not match(pag_group_rx, pag_group)) { |
| 627 | setverdict(fail, "Paging group", pag_group_rx, " does not match expected ", pag_group); |
| 628 | f_shutdown(__BFILE__, __LINE__); |
| 629 | } |
| 630 | |
| 631 | f_pcuif_tx_data_cnf(pcu_msg); |
| 632 | return rr_pag_req1; |
| 633 | } |
| 634 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 635 | function f_rx_rlcmac_dl_block(out RlcmacDlBlock dl_block, out uint32_t dl_fn, template (present) CodingScheme exp_cs_mcs := ?) |
| 636 | runs on MS_BTS_IFACE_CT { |
| 637 | var PCUIF_Message pcu_msg; |
| 638 | f_pcuif_rx_data_req(pcu_msg); |
| 639 | dl_block := dec_RlcmacDlBlock(pcu_msg.u.data_req.data); |
| 640 | dl_fn := pcu_msg.u.data_req.fn; |
| 641 | |
| 642 | var integer len := lengthof(pcu_msg.u.data_req.data); |
| 643 | var CodingScheme cs_mcs := f_rlcmac_block_len2cs_mcs(len) |
| 644 | if (not match(f_rlcmac_block_len2cs_mcs(len), exp_cs_mcs)) { |
| 645 | setverdict(fail, "Failed to match Coding Scheme exp ", exp_cs_mcs, " vs ", cs_mcs, " (", len, ")"); |
| 646 | f_shutdown(__BFILE__, __LINE__); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | function f_rx_rlcmac_dl_block_exp_ack_nack(out RlcmacDlBlock dl_block, out uint32_t poll_fn) |
| 651 | runs on MS_BTS_IFACE_CT { |
| 652 | var uint32_t dl_fn; |
| 653 | |
| 654 | f_rx_rlcmac_dl_block(dl_block, dl_fn); |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 655 | if (match(dl_block, tr_RLCMAC_UL_ACK_NACK_GPRS(ul_tfi := ?)) or |
| 656 | match(dl_block, tr_RLCMAC_UL_ACK_NACK_EGPRS(ul_tfi := ?))) { |
| 657 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 658 | return; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 659 | } |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 660 | setverdict(fail, "Failed to match Packet Uplink ACK / NACK:", dl_block); |
| 661 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | function f_rx_rlcmac_dl_block_exp_dummy(out RlcmacDlBlock dl_block) |
| 665 | runs on MS_BTS_IFACE_CT { |
| 666 | var uint32_t dl_fn; |
| 667 | |
| 668 | f_rx_rlcmac_dl_block(dl_block, dl_fn); |
| 669 | if (not match(dl_block, tr_RLCMAC_DUMMY_CTRL())) { |
| 670 | setverdict(fail, "Failed to match Packet DUMMY DL"); |
| 671 | f_shutdown(__BFILE__, __LINE__); |
| 672 | } |
| 673 | } |
| 674 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 675 | function f_rx_rlcmac_dl_block_exp_pkt_pag_req(out RlcmacDlBlock dl_block) |
| 676 | runs on MS_BTS_IFACE_CT { |
| 677 | var uint32_t dl_fn; |
| 678 | |
| 679 | f_rx_rlcmac_dl_block(dl_block, dl_fn); |
| 680 | if (not match(dl_block, tr_RLCMAC_PACKET_PAG_REQ())) { |
| 681 | setverdict(fail, "Failed to match Packet Paging Request: ", dl_block, " vs ", tr_RLCMAC_PACKET_PAG_REQ()); |
| 682 | f_shutdown(__BFILE__, __LINE__); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /* This function does what could probably be done with templates */ |
| 687 | function f_rlcmac_dl_block_verify_data_gprs(in RlcmacDlDataBlock data_block, |
| 688 | template (present) octetstring data := ?, |
| 689 | template (present) uint7_t exp_bsn := ?, |
| 690 | template (present) CodingScheme exp_cs := ?) |
| 691 | runs on MS_BTS_IFACE_CT { |
| 692 | if (not match(data_block.mac_hdr.hdr_ext.bsn, exp_bsn)) { |
| 693 | setverdict(fail, "DL block BSN doesn't match: ", |
| 694 | data_block.mac_hdr.hdr_ext.bsn, " vs exp ", exp_bsn); |
| 695 | } |
| 696 | |
| 697 | if (lengthof(data_block.blocks) < 1) { |
| 698 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 699 | f_shutdown(__BFILE__, __LINE__); |
| 700 | } |
| 701 | |
| 702 | if (not match(data_block.blocks[0].payload, data)) { |
| 703 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 704 | data_block.blocks[0].payload, " vs ", data); |
| 705 | f_shutdown(__BFILE__, __LINE__); |
| 706 | } |
| 707 | |
| 708 | /* Check next data blocks contain dummy frames */ |
| 709 | if (lengthof(data_block.blocks) > 1 and substr(data_block.blocks[1].payload, 0, 3) != '43C001'O) { |
| 710 | setverdict(fail, "Second data payload is not a dummy frame: ", |
| 711 | data_block.blocks[1].payload); |
| 712 | f_shutdown(__BFILE__, __LINE__); |
| 713 | } |
| 714 | |
| 715 | /* TODO: check exp_cs */ |
| 716 | } |
| 717 | |
| 718 | /* This function does what could probably be done with templates */ |
| 719 | function f_rlcmac_dl_block_verify_data_egprs(in RlcmacDlEgprsDataBlock data_block, |
| 720 | template (present) octetstring data := ?, |
| 721 | template (present) uint14_t exp_bsn := ?, |
| 722 | template (present) CodingScheme exp_cs := ?) |
| 723 | runs on MS_BTS_IFACE_CT { |
| 724 | if (not match(data_block.mac_hdr.bsn1, exp_bsn)) { |
| 725 | setverdict(fail, "DL block BSN doesn't match: ", |
| 726 | data_block.mac_hdr.bsn1, " vs exp ", exp_bsn); |
| 727 | } |
| 728 | |
| 729 | if (lengthof(data_block.blocks) < 1) { |
| 730 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 731 | f_shutdown(__BFILE__, __LINE__); |
| 732 | } |
| 733 | |
| 734 | if (not match(data_block.blocks[0].payload, data)) { |
| 735 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 736 | data_block.blocks[0].payload, " vs ", data); |
| 737 | f_shutdown(__BFILE__, __LINE__); |
| 738 | } |
| 739 | |
| 740 | /* Check next data blocks contain dummy frames */ |
| 741 | if (lengthof(data_block.blocks) > 1 and substr(data_block.blocks[1].payload, 0, 3) != '43C001'O) { |
| 742 | setverdict(fail, "Second data payload is not a dummy frame: ", |
| 743 | data_block.blocks[1].payload); |
| 744 | f_shutdown(__BFILE__, __LINE__); |
| 745 | } |
| 746 | |
| 747 | /* TODO: Check exp_cs. In the case of EGPRS, first check mac_hdr.header_type and then decode CPS = exp_cs based on mac_hdr.header_type. |
| 748 | See wireshark's egprs_Header_type1_coding_puncturing_scheme_to_mcs. */ |
| 749 | } |
| 750 | |
| 751 | /* High level (task specific) helper for receiving and matching GPRS/EGPRS data blocks */ |
| 752 | function f_rx_rlcmac_dl_block_exp_data(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 753 | template (present) octetstring data := ?, |
| 754 | template (present) uint7_t exp_bsn := ?, |
| 755 | template (present) CodingScheme exp_cs := ?) |
| 756 | runs on MS_BTS_IFACE_CT { |
| 757 | /* FIXME: ideally we should use an alt statement with timeout here, rather than |
| 758 | * having +100500 layers of abstraction. This would facilitate developing the |
| 759 | * multi-TBF/-TRX/-BTS tests, where you cannot expect that the first received |
| 760 | * block is exactly what you need. */ |
| 761 | f_rx_rlcmac_dl_block(dl_block, dl_fn); |
| 762 | |
| 763 | /* Make sure it's either GPRS or EGPRS data block */ |
| 764 | if (not match(dl_block, tr_RLCMAC_DATA)) { |
| 765 | setverdict(fail, "Failed to match DL DATA: ", dl_block, " vs ", tr_RLCMAC_DATA); |
| 766 | f_shutdown(__BFILE__, __LINE__); |
| 767 | } |
| 768 | |
| 769 | if (ischosen(dl_block.data_egprs)) { |
| 770 | f_rlcmac_dl_block_verify_data_egprs(dl_block.data_egprs, data, exp_bsn, exp_cs); |
| 771 | } else if (ischosen(dl_block.data)) { |
| 772 | f_rlcmac_dl_block_verify_data_gprs(dl_block.data, data, exp_bsn, exp_cs); |
| 773 | } else { |
| 774 | /* Should not happen, but the caller may theoretically give us a template for CTRL */ |
| 775 | setverdict(fail, "DL block is neither GPRS nor EGPRS data block: ", dl_block); |
| 776 | f_shutdown(__BFILE__, __LINE__); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | function f_dl_block_ack_fn(in RlcmacDlBlock dl_block, uint32_t dl_fn) |
| 781 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 782 | var boolean rrbp_valid; |
| 783 | var MacRrbp rrbp; |
| 784 | |
| 785 | /* The argument must be either a GPRS or EGPRS data block */ |
| 786 | if (ischosen(dl_block.data_egprs)) { |
| 787 | rrbp_valid := true; /* always valid */ |
| 788 | rrbp := dl_block.data_egprs.mac_hdr.rrbp; |
| 789 | } else if (ischosen(dl_block.data)) { |
| 790 | rrbp_valid := dl_block.data.mac_hdr.mac_hdr.rrbp_valid; |
| 791 | rrbp := dl_block.data.mac_hdr.mac_hdr.rrbp; |
| 792 | } else { |
| 793 | rrbp_valid := dl_block.ctrl.mac_hdr.rrbp_valid; |
| 794 | rrbp := dl_block.ctrl.mac_hdr.rrbp; |
| 795 | } |
| 796 | |
| 797 | /* Make sure that the given block really needs to be ACKnowledged */ |
| 798 | if (not rrbp_valid) { |
| 799 | setverdict(fail, "DL block shall not be ACKnowledged, field RRBP is not valid"); |
| 800 | f_shutdown(__BFILE__, __LINE__); |
| 801 | } |
| 802 | |
| 803 | return f_rrbp_ack_fn(dl_fn, rrbp); |
| 804 | } |
| 805 | |
| 806 | function f_pkt_paging_match_tmsi(in PacketPagingReq req, template GsmTmsi tmsi) |
| 807 | runs on MS_BTS_IFACE_CT { |
| 808 | if (not match(req.repeated_pageinfo.cs.tmsi, tmsi)) { |
| 809 | setverdict(fail, "Mobile Identity (TMSI/P-TMSI) mismatch: ", |
| 810 | "expected: ", tmsi, "got: ", req.repeated_pageinfo.cs.tmsi); |
| 811 | f_shutdown(__BFILE__, __LINE__); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | } |