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 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 20 | import from RLCMAC_CSN1_Types all; |
| 21 | import from RLCMAC_CSN1_Templates all; |
| 22 | import from RLCMAC_Types all; |
| 23 | import from RLCMAC_Templates all; |
| 24 | |
| 25 | import from MobileL3_CommonIE_Types all; |
| 26 | import from L3_Templates all; |
| 27 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 28 | import from PCUIF_Types all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 29 | import from PCUIF_Components all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 30 | import from Native_Functions all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 31 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 32 | modulepar { |
| 33 | /* ARFCN of 1st TRX. Subsequent TRX are allocated incrementing ARFCNs. Nth TRX => base_arfcn + N-1 */ |
| 34 | GsmArfcn mp_base_arfcn := 871; |
| 35 | }; |
| 36 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 37 | type record TsTrxBtsNum { |
| 38 | uint3_t ts_nr, |
| 39 | uint3_t trx_nr, |
| 40 | uint8_t bts_nr, |
| 41 | uint8_t blk_nr |
| 42 | }; |
| 43 | |
Pau Espin Pedrol | 8155bf4 | 2020-10-29 17:34:26 +0100 | [diff] [blame] | 44 | /* Useful to store poll FN + BTS+TRX+TS requested by network */ |
| 45 | type record PollFnCtx { |
| 46 | TsTrxBtsNum tstrxbts, |
| 47 | uint32_t fn |
| 48 | }; |
| 49 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 50 | template (value) TsTrxBtsNum ts_TsTrxBtsNum(uint3_t ts_nr := 7, |
| 51 | uint3_t trx_nr := 0, |
| 52 | uint8_t bts_nr := 0, |
| 53 | uint8_t blk_nr := 0) := { |
| 54 | ts_nr := ts_nr, |
| 55 | trx_nr := trx_nr, |
| 56 | bts_nr := bts_nr, |
| 57 | blk_nr := blk_nr |
| 58 | }; |
| 59 | template TsTrxBtsNum tr_TsTrxBtsNum(template uint3_t ts_nr := ?, |
| 60 | template uint3_t trx_nr := ?, |
| 61 | template uint8_t bts_nr := ?, |
| 62 | template uint8_t blk_nr := ?) := { |
| 63 | ts_nr := ts_nr, |
| 64 | trx_nr := trx_nr, |
| 65 | bts_nr := bts_nr, |
| 66 | blk_nr := blk_nr |
| 67 | }; |
| 68 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 69 | type union PacketDlAssignChan { |
| 70 | PacketDlAssign ccch, |
| 71 | PacketDlAssignment pacch |
| 72 | }; |
| 73 | |
| 74 | type record DlTbf { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 75 | GsmRrMessage rr_imm_ass optional, |
| 76 | PacketDlAssignChan ass optional, |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 77 | uint5_t tfi, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 78 | GsmArfcn arfcn optional, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 79 | BIT8 ts_mask, |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 80 | AckNackDescription acknack_desc |
| 81 | }; |
| 82 | |
| 83 | type union PacketUlAssignChan { |
| 84 | PacketUlAssign ccch, |
| 85 | EgprsUlAss ccch_egprs, |
| 86 | PacketUlAssignment pacch |
| 87 | }; |
| 88 | |
| 89 | type record UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 90 | GsmRrMessage rr_imm_ass optional, |
| 91 | PacketUlAssignChan ass optional, |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 92 | uint5_t tfi, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 93 | GsmArfcn arfcn optional, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 94 | BIT8 ts_mask, |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 95 | uint3_t usf[8], |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 96 | boolean is_egprs, |
| 97 | uint14_t bsn, |
| 98 | CodingScheme tx_cs_mcs |
| 99 | }; |
| 100 | |
| 101 | type record GprsMS { |
| 102 | hexstring imsi, |
| 103 | GprsTlli tlli, |
| 104 | uint16_t ra, |
| 105 | uint8_t ra_is_11bit, |
| 106 | PCUIF_BurstType burst_type, |
| 107 | TimingAdvance ta, |
| 108 | int16_t lqual_cb, |
| 109 | UlTbf ul_tbf optional, /* TODO: Only 1 UL tbf supported for now */ |
| 110 | DlTbf dl_tbf optional /* TODO: Only 1 DL tbf supported for now */ |
| 111 | }; |
Vadim Yanitskiy | cff3e1b | 2020-10-31 21:12:12 +0700 | [diff] [blame] | 112 | type record of GprsMS GprsMSList; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 113 | |
| 114 | template AckNackDescription t_AckNackDescription_init := { |
| 115 | final_ack := '0'B, |
| 116 | starting_seq_nr := 0, |
| 117 | receive_block_bitmap := '0000000000000000000000000000000000000000000000000000000000000000'B |
| 118 | } |
| 119 | |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 120 | const uint3_t USF_UNUSED := 7; /* used to indicate PRACH */ |
| 121 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 122 | template (value) GprsMS t_GprsMS_def := { |
| 123 | imsi := f_gen_imsi(42), |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 124 | tlli := f_gen_tlli(), |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 125 | ra := bit2int(chan_req_def), |
| 126 | ra_is_11bit := 0, |
| 127 | burst_type := BURST_TYPE_0, |
| 128 | ta := 0, |
| 129 | lqual_cb := 0, |
| 130 | ul_tbf := omit, |
| 131 | dl_tbf := omit |
| 132 | }; |
| 133 | |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 134 | template (value) DlTbf t_DlTbf_def := { |
| 135 | rr_imm_ass := omit, |
| 136 | ass := omit, |
| 137 | tfi := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 138 | arfcn := omit, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 139 | ts_mask := '00000000'B, |
| 140 | acknack_desc := t_AckNackDescription_init |
| 141 | }; |
| 142 | |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 143 | template (value) UlTbf t_UlTbf_def := { |
| 144 | rr_imm_ass := omit, |
| 145 | ass := omit, |
| 146 | tfi := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 147 | arfcn := omit, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 148 | ts_mask := '00000000'B, |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 149 | usf := { USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED }, |
| 150 | is_egprs := false, |
| 151 | bsn := 0, |
| 152 | tx_cs_mcs := CS_1 |
| 153 | }; |
| 154 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 155 | type component MS_BTS_IFACE_CT { |
| 156 | /* Virtual BTS component */ |
| 157 | var RAW_PCU_BTS_CT vc_BTS; |
| 158 | /* Connection to the BTS component (one for now) */ |
| 159 | port RAW_PCU_MSG_PT BTS; |
| 160 | |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 161 | /* Mobile station(s) involved in a testing scenario */ |
Vadim Yanitskiy | cff3e1b | 2020-10-31 21:12:12 +0700 | [diff] [blame] | 162 | var GprsMSList g_ms := { }; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 163 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 164 | /* Value at which Countdown Procedure starts. Announced by network (GPRS Cell Options as per TS 04.60 Chapter 12.24) */ |
| 165 | var uint4_t g_bs_cv_max := 4; |
| 166 | } |
| 167 | |
Vadim Yanitskiy | 7942580 | 2020-10-31 21:23:08 +0700 | [diff] [blame] | 168 | /* Generate a list of GprsMS (unique IMSI/TLLI, cyclic RA) of the given size */ |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 169 | function f_init_gprs_ms(integer num_ms := 1, template (value) GprsMS t_ms := t_GprsMS_def) |
| 170 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 171 | for (var integer i := 0; i < num_ms; i := i + 1 ) { |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 172 | var GprsMS ms := valueof(t_ms); |
| 173 | |
Vadim Yanitskiy | e12b2ac | 2020-10-31 21:21:47 +0700 | [diff] [blame] | 174 | /* We assume that num_ms is not a large number */ |
| 175 | ms.imsi := f_gen_imsi(i + 1); |
| 176 | ms.tlli := int2oct(i + 1, 4); |
| 177 | |
Vadim Yanitskiy | 7942580 | 2020-10-31 21:23:08 +0700 | [diff] [blame] | 178 | /* Ensure different RA for siblings */ |
| 179 | if (ms.ra == bit2int(chan_req_def)) { |
| 180 | /* 01111 { 0xx | x0x | xx0 } */ |
| 181 | f_ms_use_ra(ms, ms.ra + (i mod 7)); |
| 182 | } else if (ms.ra == bit2int(chan_req_sb)) { |
| 183 | /* 01110xxx */ |
| 184 | f_ms_use_ra(ms, ms.ra + (i mod 8)); |
| 185 | } |
| 186 | |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 187 | /* Append to the global list */ |
| 188 | g_ms := g_ms & { ms }; |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 189 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 193 | function f_shutdown(charstring file, integer line, |
| 194 | boolean final := false) |
| 195 | runs on MS_BTS_IFACE_CT { |
| 196 | /* Determine if the test case was aborted in the middle */ |
| 197 | if (not final) { |
| 198 | log("Test case ", testcasename(), " aborted at ", file, ":", line); |
| 199 | } else { |
| 200 | /* Guard verdict to avoid 'none' */ |
| 201 | setverdict(pass); |
| 202 | } |
| 203 | |
| 204 | /* Properly shutdown virtual BTS and its clock generator */ |
| 205 | BTS.send(ts_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)); |
| 206 | vc_BTS.done; /* wait untill it's done */ |
| 207 | |
| 208 | /* Shutdown the others and MTC */ |
| 209 | all component.stop; |
| 210 | mtc.stop; |
| 211 | } |
| 212 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 213 | function f_arfcn2trxnr(GsmArfcn arfcn) runs on MS_BTS_IFACE_CT return uint3_t { |
| 214 | if (arfcn < mp_base_arfcn) { |
| 215 | setverdict(fail, "Unable to find TRX NR for arfcn ", arfcn); |
| 216 | f_shutdown(__BFILE__, __LINE__); |
| 217 | } |
| 218 | return arfcn - mp_base_arfcn; |
| 219 | } |
| 220 | |
| 221 | function f_trxnr2arfcn(uint3_t trx_nr) return GsmArfcn { |
| 222 | return mp_base_arfcn + trx_nr; |
| 223 | } |
| 224 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 225 | function f_ultbf_new_from_rr_imm_ass(in GsmRrMessage rr_imm_ass) |
| 226 | runs on MS_BTS_IFACE_CT return UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 227 | var UlTbf ul_tbf := valueof(t_UlTbf_def); |
| 228 | 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] | 229 | |
| 230 | ul_tbf.rr_imm_ass := rr_imm_ass; |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 231 | if (rr_imm_ass.payload.imm_ass.pkt_chan_desc.presence == '0'B and |
| 232 | rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.hopping == '0'B) { |
| 233 | ul_tbf.arfcn := rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.arfcn; |
| 234 | } |
| 235 | ul_tbf.ts_mask[tn_allocated] := '1'B; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 236 | |
| 237 | /* Make sure we received an UL TBF Assignment */ |
| 238 | if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_ULAss(?)))) { |
| 239 | ul_tbf.ass.ccch := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.ul; |
| 240 | log("Rx Uplink TBF GPRS assignment: ", ul_tbf.ass.ccch); |
| 241 | ul_tbf.is_egprs := false; |
| 242 | if (match(ul_tbf.ass.ccch, tr_PacketUlDynAssign)) { |
| 243 | ul_tbf.tfi := ul_tbf.ass.ccch.dynamic.tfi_assignment; |
Pau Espin Pedrol | 9040111 | 2020-05-20 17:36:27 +0200 | [diff] [blame] | 244 | 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] | 245 | ul_tbf.usf[tn_allocated] := ul_tbf.ass.ccch.dynamic.usf; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 246 | } else if (match(ul_tbf.ass.ccch, tr_PacketUlSglAssign)) { |
| 247 | /* Nothing to do here yet */ |
| 248 | } |
| 249 | } else if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_EGPRSULAss(?)))) { |
| 250 | ul_tbf.ass.ccch_egprs := rr_imm_ass.payload.imm_ass.rest_octets.lh.egprs_ul; |
| 251 | log("Rx Uplink TBF EGPRS assignment: ", ul_tbf.ass.ccch_egprs); |
| 252 | ul_tbf.is_egprs := true; |
| 253 | if (match(ul_tbf.ass.ccch_egprs, tr_EgprsUlAssDynamic)) { |
| 254 | ul_tbf.tfi := ul_tbf.ass.ccch_egprs.dynamic.tfi_assignment; |
Pau Espin Pedrol | 9040111 | 2020-05-20 17:36:27 +0200 | [diff] [blame] | 255 | 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] | 256 | 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] | 257 | } else if (match(ul_tbf.ass.ccch_egprs, tr_EgprsUlAssMultiblock)) { |
| 258 | /* Nothing to do here yet */ |
| 259 | } |
| 260 | } else { |
| 261 | setverdict(fail, "Failed to match UL TBF Assignment: ", rr_imm_ass); |
| 262 | f_shutdown(__BFILE__, __LINE__); |
| 263 | } |
| 264 | |
| 265 | setverdict(pass); |
| 266 | return ul_tbf; |
| 267 | } |
| 268 | |
| 269 | function f_ultbf_new_from_ass_pacch(RlcmacDlBlock dl_block) |
| 270 | runs on MS_BTS_IFACE_CT return UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 271 | var UlTbf ul_tbf := valueof(t_UlTbf_def); |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 272 | var boolean freq_par_present := false; |
| 273 | var FrequencyParameters freq_par; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 274 | |
| 275 | ul_tbf.ass.pacch := dl_block.ctrl.payload.u.ul_assignment; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 276 | ul_tbf.tx_cs_mcs := f_rlcmac_dl_block_get_assigned_ul_cs_mcs(dl_block); |
| 277 | ul_tbf.tfi := f_rlcmac_dl_block_get_tfi(dl_block); |
| 278 | /* TODO: handle GlobalTfiOrTlli tfi_or_tlli from pkt_ul_ass */ |
| 279 | |
| 280 | /* TODO: support single block allocation */ |
| 281 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 282 | ul_tbf.tfi := dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ul_tfi_assignment; |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 283 | freq_par_present := dl_block.ctrl.payload.u.ul_assignment.gprs.freq_par_present == '1'B; |
| 284 | if (freq_par_present) { |
| 285 | freq_par := dl_block.ctrl.payload.u.ul_assignment.gprs.freq_par; |
| 286 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 287 | ul_tbf.is_egprs := false; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 288 | for (var integer i := 0; i < 8; i := i + 1) { |
| 289 | if (dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ts_allocation.ts[i].presence == '1'B) { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 290 | ul_tbf.ts_mask[i] := '1'B; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 291 | ul_tbf.usf[i] := dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ts_allocation.ts[i].usf_tn; |
| 292 | } |
| 293 | } |
| 294 | } 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] | 295 | ul_tbf.tfi := dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ul_tfi_assignment; |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 296 | freq_par_present := dl_block.ctrl.payload.u.ul_assignment.egprs.freq_par_present == '1'B; |
| 297 | if (freq_par_present) { |
| 298 | freq_par := dl_block.ctrl.payload.u.ul_assignment.egprs.freq_par; |
| 299 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 300 | ul_tbf.is_egprs := true; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 301 | for (var integer i := 0; i < 8; i := i + 1) { |
| 302 | if (dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ts_allocation.ts[i].presence == '1'B) { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 303 | ul_tbf.ts_mask[i] := '1'B; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 304 | ul_tbf.usf[i] := dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ts_allocation.ts[i].usf_tn; |
| 305 | } |
| 306 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 307 | } |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 308 | |
| 309 | /* FIXME: freq_par and arfcn are optional. in that case we need to |
| 310 | * infer/reuse from current dl_tbf or ul_tbf */ |
| 311 | if (freq_par_present and freq_par.presence == '00'B) { |
| 312 | ul_tbf.arfcn := freq_par.arfcn; |
| 313 | } |
| 314 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 315 | return ul_tbf; |
| 316 | } |
| 317 | |
| 318 | function f_dltbf_new_from_rr_imm_ass(in GsmRrMessage rr_imm_ass, template PacketDlAssign dl_ass := tr_PacketDlAssign(?)) |
| 319 | runs on MS_BTS_IFACE_CT return DlTbf { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 320 | var DlTbf dl_tbf := valueof(t_DlTbf_def); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 321 | |
| 322 | dl_tbf.rr_imm_ass := rr_imm_ass; |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 323 | if (rr_imm_ass.payload.imm_ass.pkt_chan_desc.presence == '0'B and |
| 324 | rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.hopping == '0'B) { |
| 325 | dl_tbf.arfcn := rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.arfcn; |
| 326 | } |
| 327 | dl_tbf.ts_mask[rr_imm_ass.payload.imm_ass.pkt_chan_desc.tn] := '1'B; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 328 | |
| 329 | /* Make sure we received a DL TBF Assignment */ |
| 330 | if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := true, rest := tr_IaRestOctets_DLAss(dl_ass)))) { |
| 331 | dl_tbf.ass.ccch := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.dl; |
| 332 | log("Rx Downlink TBF assignment: ", dl_tbf.ass); |
| 333 | } else { |
| 334 | setverdict(fail, "Failed to match DL TBF Assignment: ", rr_imm_ass); |
| 335 | f_shutdown(__BFILE__, __LINE__); |
| 336 | } |
| 337 | |
| 338 | /* TODO: match TLLI */ |
| 339 | if (dl_tbf.ass.ccch.group1_present == '1'B) { |
| 340 | dl_tbf.tfi := dl_tbf.ass.ccch.group1.tfi_assignment; |
| 341 | } else { |
| 342 | setverdict(fail, "Immediate Assignment contains no DL TFI"); |
| 343 | f_shutdown(__BFILE__, __LINE__); |
| 344 | } |
| 345 | |
| 346 | setverdict(pass); |
| 347 | return dl_tbf; |
| 348 | } |
| 349 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 350 | function f_dltbf_new_from_ass_pacch(RlcmacDlBlock dl_block) |
| 351 | runs on MS_BTS_IFACE_CT return DlTbf { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 352 | var DlTbf dl_tbf := valueof(t_DlTbf_def); |
| 353 | var boolean freq_par_present := false; |
| 354 | var FrequencyParameters freq_par; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 355 | |
| 356 | dl_tbf.ass.pacch := dl_block.ctrl.payload.u.dl_assignment; |
| 357 | dl_tbf.tfi := f_rlcmac_dl_block_get_tfi(dl_block); |
| 358 | /* TODO: handle GlobalTfiOrTlli tfi_or_tlli from pkt_dl_ass */ |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 359 | |
| 360 | if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS(?))) { |
| 361 | dl_tbf.tfi := dl_block.ctrl.payload.u.dl_assignment.dl_tfi_assignment; |
| 362 | freq_par_present := dl_block.ctrl.payload.u.dl_assignment.freq_par_present == '1'B; |
| 363 | if (freq_par_present) { |
| 364 | freq_par := dl_block.ctrl.payload.u.dl_assignment.freq_par; |
| 365 | } |
| 366 | dl_tbf.ts_mask := dl_block.ctrl.payload.u.dl_assignment.timeslot_alloc; /* TODO: is this the correct order ? */ |
| 367 | /* TODO: check egprs in dl_assignment.rel_additions (PktDlAssR99Additions) */ |
| 368 | } |
| 369 | |
| 370 | /* FIXME: freq_par and arfcn are optional. in that case we need to |
| 371 | * infer/reuse from current dl_tbf or ul_tbf */ |
| 372 | if (freq_par_present and freq_par.presence == '00'B) { |
| 373 | dl_tbf.arfcn := freq_par.arfcn; |
| 374 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 375 | return dl_tbf; |
| 376 | } |
| 377 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 378 | function f_ms_tx_TsTrxBtsNum(inout GprsMS ms) |
| 379 | runs on MS_BTS_IFACE_CT return TsTrxBtsNum { |
| 380 | var uint3_t ts_nr := f_ultbf_next_ts(ms.ul_tbf); |
| 381 | |
| 382 | var uint3_t trx_nr; |
| 383 | if (ispresent(ms.ul_tbf.arfcn)) { |
| 384 | trx_nr := f_arfcn2trxnr(ms.ul_tbf.arfcn); |
| 385 | } else { |
| 386 | /* FIXME: implement search by hsn+maio+ma when freq hopping is enabled */ |
| 387 | setverdict(fail, "Asked for trx_nr but arfcn not available in ms.ul_tbf!"); |
| 388 | f_shutdown(__BFILE__, __LINE__); |
| 389 | } |
| 390 | return valueof(ts_TsTrxBtsNum(ts_nr, trx_nr)); |
| 391 | } |
| 392 | |
| 393 | function f_dltbf_num_slots(DlTbf dl_tbf) |
| 394 | runs on MS_BTS_IFACE_CT return integer { |
| 395 | var integer n := 0; |
| 396 | for (var integer i := 0; i < lengthof(dl_tbf.ts_mask); i := i + 1) { |
| 397 | if (dl_tbf.ts_mask[i] == '1'B) { |
| 398 | n := n + 1; |
| 399 | } |
| 400 | } |
| 401 | return n; |
| 402 | } |
| 403 | |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 404 | function f_ultbf_inc_bsn(inout UlTbf ul_tbf) |
| 405 | runs on MS_BTS_IFACE_CT { |
| 406 | ul_tbf.bsn := ul_tbf.bsn + 1; |
| 407 | ul_tbf.bsn := ul_tbf.bsn mod 128; /* FIXME: EGPRS SNS: 2048 */ |
| 408 | } |
| 409 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 410 | function f_ultbf_next_ts(UlTbf ul_tbf) |
| 411 | runs on MS_BTS_IFACE_CT return uint3_t { |
| 412 | /* FIXME: in the future we probably want to store last used internally |
| 413 | /* and continue from there */ |
| 414 | for (var integer i := 0; i < lengthof(ul_tbf.ts_mask); i := i + 1) { |
| 415 | if (ul_tbf.ts_mask[i] == '1'B) { |
| 416 | return i; |
| 417 | } |
| 418 | } |
| 419 | setverdict(fail, "No TS available for tx!"); |
| 420 | f_shutdown(__BFILE__, __LINE__); |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | function f_ultbf_num_slots(UlTbf ul_tbf) |
| 425 | runs on MS_BTS_IFACE_CT return integer { |
| 426 | var integer n := 0; |
| 427 | for (var integer i := 0; i < lengthof(ul_tbf.ts_mask); i := i + 1) { |
| 428 | if (ul_tbf.ts_mask[i] == '1'B) { |
| 429 | n := n + 1; |
| 430 | } |
| 431 | } |
| 432 | return n; |
| 433 | } |
| 434 | |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 435 | function f_ultbf_payload_fill_length(UlTbf ul_tbf, boolean tlli := false, integer li_bytes := 0) |
| 436 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 437 | var uint32_t blk_len := f_rlcmac_cs_mcs2block_len_no_spare_bits(ul_tbf.tx_cs_mcs); |
| 438 | var uint32_t payload_fill_len; |
| 439 | |
| 440 | if (f_rlcmac_cs_mcs_is_mcs(ul_tbf.tx_cs_mcs)) { |
| 441 | payload_fill_len := blk_len - 5 - li_bytes; |
| 442 | } else { |
| 443 | /* GPRS: blk_len = 3 Header bytes + payload length. No LI byte in this case. */ |
| 444 | payload_fill_len := blk_len - 3 - li_bytes; |
| 445 | } |
| 446 | |
| 447 | if (tlli) { |
| 448 | payload_fill_len := payload_fill_len - 4; |
| 449 | } |
| 450 | return payload_fill_len; |
| 451 | } |
| 452 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 453 | function f_ms_use_ra(inout GprsMS ms, uint16_t ra, uint8_t ra_is_11bit := 0) |
| 454 | runs on MS_BTS_IFACE_CT { |
| 455 | ms.ra_is_11bit := ra_is_11bit; |
| 456 | ms.ra := ra; |
| 457 | if (ra_is_11bit == 0) { |
| 458 | ms.burst_type := BURST_TYPE_0; |
| 459 | } else { |
| 460 | ms.burst_type := BURST_TYPE_1; |
| 461 | } |
| 462 | } |
| 463 | |
Vadim Yanitskiy | 7431e9e | 2020-07-21 01:59:17 +0700 | [diff] [blame] | 464 | function f_ms_rx_pkt_ass_pacch(inout GprsMS ms, out uint32_t poll_fn, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 465 | template RlcmacDlBlock t_pkt_ass := ?, |
| 466 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 467 | runs on MS_BTS_IFACE_CT return RlcmacDlBlock { |
| 468 | var RlcmacDlBlock dl_block; |
| 469 | var uint32_t dl_fn; |
| 470 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 471 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Vadim Yanitskiy | 7431e9e | 2020-07-21 01:59:17 +0700 | [diff] [blame] | 472 | if (not match(dl_block, t_pkt_ass)) { |
| 473 | setverdict(fail, "Failed to match Packet Assignment:", t_pkt_ass); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 474 | f_shutdown(__BFILE__, __LINE__); |
| 475 | } |
| 476 | |
| 477 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 478 | |
| 479 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS)) { |
| 480 | ms.ul_tbf := f_ultbf_new_from_ass_pacch(dl_block); |
| 481 | if (ms.ul_tbf.ass.pacch.identity.tlli.tlli != ms.tlli) { |
| 482 | setverdict(fail, "Wrong TLLI ", ms.ul_tbf.ass.pacch.identity.tlli, " received vs exp ", ms.tlli); |
| 483 | f_shutdown(__BFILE__, __LINE__); |
| 484 | } |
| 485 | } else if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS)) { |
| 486 | ms.dl_tbf := f_dltbf_new_from_ass_pacch(dl_block); |
Pau Espin Pedrol | 25e0f29 | 2020-10-29 12:36:40 +0100 | [diff] [blame] | 487 | if (ischosen(ms.dl_tbf.ass.pacch.tfi_or_tlli.tlli) and |
| 488 | ms.dl_tbf.ass.pacch.tfi_or_tlli.tlli.tlli != ms.tlli) { |
| 489 | setverdict(fail, "Wrong TLLI ", ms.dl_tbf.ass.pacch.tfi_or_tlli.tlli.tlli, " received vs exp ", ms.tlli); |
| 490 | f_shutdown(__BFILE__, __LINE__); |
| 491 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 492 | } else { |
| 493 | setverdict(fail, "Should not happen:", dl_block); |
| 494 | f_shutdown(__BFILE__, __LINE__); |
| 495 | } |
| 496 | |
| 497 | return dl_block; |
| 498 | } |
| 499 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 500 | function f_ms_establish_ul_tbf(inout GprsMS ms, template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 501 | runs on MS_BTS_IFACE_CT { |
| 502 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 503 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 504 | rr_imm_ass := f_pcuif_tx_rach_rx_imm_ass(ms.ra, ms.ra_is_11bit, ms.burst_type, ms.ta, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 505 | ms.ul_tbf := f_ultbf_new_from_rr_imm_ass(rr_imm_ass); |
| 506 | } |
| 507 | |
Vadim Yanitskiy | 84d1dd5 | 2020-05-28 21:09:22 +0700 | [diff] [blame] | 508 | function f_ms_exp_dl_tbf_ass_ccch(inout GprsMS ms, template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 509 | template GsmRrMessage t_imm_ass := tr_IMM_TBF_ASS(true, ?, ?), |
| 510 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 511 | runs on MS_BTS_IFACE_CT { |
| 512 | var GsmRrMessage rr_imm_ass; |
| 513 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 514 | rr_imm_ass := f_pcuif_rx_imm_ass(sapi, t_imm_ass, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 515 | ms.dl_tbf := f_dltbf_new_from_rr_imm_ass(rr_imm_ass, tr_PacketDlAssign(ms.tlli)); |
| 516 | } |
| 517 | |
| 518 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 519 | function f_ms_tx_data_ind(inout GprsMS ms, octetstring data, uint32_t fn := 0, |
| 520 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 521 | runs on MS_BTS_IFACE_CT { |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 522 | f_pcuif_tx_data_ind(data, ms.lqual_cb, fn, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 525 | function f_ms_tx_ul_block(inout GprsMS ms, template (value) RlcmacUlBlock ul_data, |
| 526 | uint32_t fn := 0, template (omit) CodingScheme force_cs_mcs := omit, |
| 527 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 528 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 529 | var octetstring data; |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 530 | var CodingScheme cs_mcs; |
| 531 | var uint32_t cs_mcs_len; |
| 532 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 533 | /* Encode the payload of DATA.ind */ |
| 534 | data := enc_RlcmacUlBlock(valueof(ul_data)); |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 535 | |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 536 | if (ischosen(ul_data.ctrl)) { |
| 537 | /* Ctrl blocks are right now encoded by RAW encoder, which was |
| 538 | * found to have some issue with final padding, so we add it |
| 539 | * here manually. This is actually still incorrect because the |
| 540 | * remaining bits of last octet with data are not filled with |
| 541 | * the padding sequence, but it's good enough since anyway PCU |
| 542 | * don't check these. */ |
| 543 | data := f_pad_oct(data, f_rlcmac_cs_mcs2block_len(CS_1), '2b'O); |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 544 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 545 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 546 | f_ms_tx_data_ind(ms, data, fn, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 549 | function f_ms_tx_ul_data_block(inout GprsMS ms, octetstring payload, |
| 550 | uint4_t cv := 15, boolean with_tlli := false, uint32_t fn := 0, |
| 551 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 552 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 553 | var template (value) RlcmacUlBlock ul_data; |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 554 | |
| 555 | if (f_rlcmac_cs_mcs_is_mcs(ms.ul_tbf.tx_cs_mcs)) { |
| 556 | ul_data := t_RLCMAC_UL_EGPRS_DATA(mcs := ms.ul_tbf.tx_cs_mcs, |
| 557 | tfi := ms.ul_tbf.tfi, |
| 558 | cv := cv, |
| 559 | bsn1 := ms.ul_tbf.bsn, |
| 560 | bsn2_offset := 0, |
| 561 | blocks := {t_RLCMAC_LLCBLOCK_EGPRS(payload)}) |
| 562 | if (with_tlli) { |
| 563 | ul_data.data_egprs.tlli_ind := true; |
| 564 | ul_data.data_egprs.tlli := ms.tlli; |
| 565 | } |
| 566 | } else { |
| 567 | ul_data := t_RLCMAC_UL_DATA(cs := ms.ul_tbf.tx_cs_mcs, |
| 568 | tfi := ms.ul_tbf.tfi, |
| 569 | cv := cv, |
| 570 | bsn := ms.ul_tbf.bsn, |
| 571 | blocks := {t_RLCMAC_LLCBLOCK(payload)}); |
| 572 | if (with_tlli) { |
| 573 | ul_data.data.mac_hdr.tlli_ind := true; |
| 574 | ul_data.data.tlli := ms.tlli; |
| 575 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 576 | } |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 577 | f_ultbf_inc_bsn(ms.ul_tbf); |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 578 | f_ms_tx_ul_block(ms, ul_data, fn, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /* Send random payload for last "num_blocks" blocks in Ul TBF (ending with CV=0). */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 582 | function f_ms_tx_ul_data_block_multi(inout GprsMS ms, integer num_blocks := 1, boolean with_tlli := false, |
| 583 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 584 | runs on MS_BTS_IFACE_CT return octetstring { |
| 585 | var octetstring total_payload := ''O; |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 586 | var uint32_t payload_fill_len := f_ultbf_payload_fill_length(ms.ul_tbf, with_tlli, 0); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 587 | |
| 588 | for (var integer i := 0; i < num_blocks; i := i + 1) { |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 589 | var octetstring payload := f_rnd_octstring(payload_fill_len); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 590 | /* Prepare a new UL block (CV, random payload) */ |
| 591 | var integer cv := num_blocks - i - 1; |
| 592 | if (cv > g_bs_cv_max) { |
| 593 | cv := 15; |
| 594 | } |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 595 | f_ms_tx_ul_data_block(ms, payload, cv := cv, with_tlli := with_tlli, nr := nr); |
| 596 | total_payload := total_payload & payload; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 597 | } |
| 598 | return total_payload; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | function f_rlcmac_dl_block_get_tfi(RlcmacDlBlock dl_block) |
| 602 | runs on MS_BTS_IFACE_CT return uint5_t { |
| 603 | if (ischosen(dl_block.data)) { |
| 604 | return dl_block.data.mac_hdr.hdr_ext.tfi; |
| 605 | } else if (ischosen(dl_block.data_egprs)) { |
| 606 | return dl_block.data_egprs.mac_hdr.tfi; |
| 607 | } else { /* Ctrl block */ |
| 608 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 609 | return dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ul_tfi_assignment; |
| 610 | } |
| 611 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(tr_DynamicAllocation(?))))) { |
| 612 | return dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ul_tfi_assignment; |
| 613 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 614 | if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS(?))) { |
| 615 | return dl_block.ctrl.payload.u.dl_assignment.dl_tfi_assignment; |
| 616 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 617 | } |
| 618 | setverdict(fail, "DlBlock doesn't contain a TFI:", dl_block); |
| 619 | f_shutdown(__BFILE__, __LINE__); |
| 620 | return 0; /* make compiler happy */ |
| 621 | } |
| 622 | |
| 623 | /* Get the Chan coding command from a dl block containing PACCH UL Assignment */ |
| 624 | function f_rlcmac_dl_block_get_assigned_ul_cs_mcs(RlcmacDlBlock dl_block) |
| 625 | runs on MS_BTS_IFACE_CT return CodingScheme { |
| 626 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(?)))) { |
| 627 | return f_rlcmac_block_ChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.gprs.ch_coding_cmd); |
| 628 | } |
| 629 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(?)))) { |
| 630 | return f_rlcmac_block_EgprsChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.egprs.chan_coding_cmd); |
| 631 | } |
| 632 | setverdict(fail, "DlBlock doesn't contain CS_MCS information:", dl_block); |
| 633 | f_shutdown(__BFILE__, __LINE__); |
| 634 | return CS_1; /* make compiler happy */ |
| 635 | } |
| 636 | |
| 637 | /* TS 44.060 sec 12.3 Ack/Nack Description */ |
| 638 | function f_acknackdesc_ack_block(inout AckNackDescription desc, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 639 | { |
| 640 | var uint7_t bsn; |
| 641 | var integer i; |
| 642 | var integer inc; |
| 643 | |
| 644 | if (ischosen(dl_block.data)) { |
| 645 | bsn := dl_block.data.mac_hdr.hdr_ext.bsn; |
| 646 | } else { |
| 647 | bsn := dl_block.data_egprs.mac_hdr.bsn1; |
| 648 | } |
| 649 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 650 | /* Filling hole? */ |
| 651 | if (bsn < desc.starting_seq_nr) { |
| 652 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr - bsn)] := int2bit(1, 1); |
| 653 | return; |
| 654 | } |
Pau Espin Pedrol | 9a2d61b | 2020-11-05 17:59:16 +0100 | [diff] [blame] | 655 | /* Filling hole, wraparound: */ |
| 656 | if (bsn - desc.starting_seq_nr > lengthof(desc.receive_block_bitmap)) { |
| 657 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr + (218 - bsn))] := int2bit(1, 1); |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | inc := bsn - desc.starting_seq_nr + 1; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 662 | |
| 663 | /* SSN is increased, and so RBB values need to be moved */ |
| 664 | for (i := 0; i < lengthof(desc.receive_block_bitmap) - inc; i := i+1) { |
| 665 | desc.receive_block_bitmap[i] := desc.receive_block_bitmap[i + inc]; |
| 666 | } |
| 667 | for (i := lengthof(desc.receive_block_bitmap) - inc; i < lengthof(desc.receive_block_bitmap) - 1; i := i+1) { |
| 668 | desc.receive_block_bitmap[i] := int2bit(0, 1); |
| 669 | } |
| 670 | /* Now we can set current bit and update SSN */ |
Pau Espin Pedrol | 9a2d61b | 2020-11-05 17:59:16 +0100 | [diff] [blame] | 671 | desc.starting_seq_nr := (bsn + 1) mod 128; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 672 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - 1] := int2bit(1, 1); |
| 673 | |
| 674 | /* Finally update the final_ack bit as requested: */ |
| 675 | desc.final_ack := final_ack; |
| 676 | } |
| 677 | |
| 678 | /* This function can be used to send DATA.cnf in response to the IUT originated DATA.req. |
| 679 | * NOTE: it's the responsibility of caller to make sure that pcu_msg contains u.data_req. */ |
| 680 | function f_pcuif_tx_data_cnf(in PCUIF_Message pcu_msg) |
| 681 | runs on MS_BTS_IFACE_CT { |
| 682 | var PCUIF_Message pcu_msg_cnf := { |
| 683 | msg_type := PCU_IF_MSG_DATA_CNF, |
| 684 | bts_nr := pcu_msg.bts_nr, |
| 685 | spare := pcu_msg.spare, |
| 686 | u := { data_cnf := pcu_msg.u.data_req } |
| 687 | }; |
| 688 | |
| 689 | /* PCU wants DATA.cnf containing basically everything that was in DATA.req, |
| 690 | * but PCU_IF_SAPI_PCH is a special case - paging group shall be excluded. */ |
| 691 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 692 | pcu_msg_cnf.u.data_cnf.data := substr(pcu_msg.u.data_req.data, 3, |
| 693 | pcu_msg.u.data_req.len - 3); |
| 694 | } |
| 695 | |
| 696 | BTS.send(pcu_msg_cnf); |
| 697 | } |
| 698 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 699 | //////////////////////// |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 700 | // Low level APIs |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 701 | //////////////////////// |
| 702 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 703 | function f_pcuif_rx_imm_ass(template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 704 | template GsmRrMessage t_imm_ass := ?, |
| 705 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 706 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 707 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 708 | var PCUIF_Message pcu_msg; |
| 709 | var octetstring data; |
| 710 | timer T; |
| 711 | |
| 712 | T.start(2.0); |
| 713 | alt { |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 714 | [] BTS.receive(tr_PCUIF_DATA_REQ(nr.bts_nr, nr.trx_nr, ts_nr := 0, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 715 | sapi := sapi, data := ?)) -> value pcu_msg { |
| 716 | /* On PCH the payload is prefixed with paging group (3 octets): skip it. |
| 717 | * TODO: add an additional template parameter, so we can match it. */ |
| 718 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 719 | data := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 720 | } else { |
| 721 | data := pcu_msg.u.data_req.data; |
| 722 | } |
| 723 | |
| 724 | rr_imm_ass := dec_GsmRrMessage(data); |
| 725 | if (not match(rr_imm_ass, t_imm_ass)) { |
| 726 | /* Not for us? Wait for more. */ |
| 727 | repeat; |
| 728 | } |
| 729 | |
| 730 | log("Rx Immediate Assignment: ", rr_imm_ass); |
Pau Espin Pedrol | 34c940b | 2020-05-28 19:56:11 +0700 | [diff] [blame] | 731 | |
| 732 | /* Send DATA.cnf back to the IUT (only needed for PCH) */ |
| 733 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 734 | f_pcuif_tx_data_cnf(pcu_msg); |
| 735 | } |
| 736 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 737 | setverdict(pass); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 738 | } |
| 739 | [] BTS.receive { repeat; } |
| 740 | [] T.timeout { |
| 741 | setverdict(fail, "Timeout waiting for Immediate Assignment"); |
Pau Espin Pedrol | fddc20b | 2020-05-28 19:50:29 +0700 | [diff] [blame] | 742 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 746 | return rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /* One phase packet access (see 3GPP TS 44.018, table 9.1.8.1) */ |
Vadim Yanitskiy | 1cea9fd | 2020-10-31 21:34:05 +0700 | [diff] [blame] | 750 | const BIT8 chan_req_def := '01111000'B; /* 01111 { 0xx | x0x | xx0 } */ |
| 751 | /* Single block (two phase or RR signalling) packet access */ |
| 752 | const BIT8 chan_req_sb := '01110000'B; /* 01110xxx */ |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 753 | |
| 754 | /* Establish an Uplink TBF by sending RACH.ind towards the PCU */ |
Vadim Yanitskiy | 28d18e1 | 2020-05-29 15:25:59 +0700 | [diff] [blame] | 755 | function f_pcuif_tx_rach_rx_imm_ass(uint16_t ra := bit2int(chan_req_def), |
| 756 | uint8_t is_11bit := 0, |
| 757 | PCUIF_BurstType burst_type := BURST_TYPE_0, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 758 | TimingAdvance ta := 0, |
| 759 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 760 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 761 | var uint32_t fn; |
| 762 | |
| 763 | /* FIXME: ask the BTS component to give us the current TDMA fn */ |
| 764 | fn := 1337 + ta; |
| 765 | |
| 766 | /* Send RACH.ind */ |
| 767 | log("Sending RACH.ind on fn=", fn, " with RA=", ra, ", TA=", ta); |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 768 | BTS.send(ts_PCUIF_RACH_IND(nr.bts_nr, nr.trx_nr, ts_nr := 0, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 769 | ra := ra, is_11bit := is_11bit, |
| 770 | burst_type := burst_type, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 771 | fn := fn, arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 772 | qta := ta * 4)); |
| 773 | |
| 774 | /* 3GPP TS 44.018, table 9.1.8.1, note 2b: Request Reference shall be set to 127 |
| 775 | * when Immediate Assignment is triggered by EGPRS Packet Channel Request. Here |
| 776 | * we assume that 11 bit RA always contains EGPRS Packet Channel Request. */ |
| 777 | if (is_11bit != 0) { ra := 127; } |
| 778 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 779 | /* Expect Immediate (TBF) Assignment on the same TS/TRX/BTS */ |
| 780 | return f_pcuif_rx_imm_ass(PCU_IF_SAPI_AGCH, tr_IMM_TBF_ASS(false, ra, fn), nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 781 | } |
| 782 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 783 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 784 | function f_pcuif_tx_data_ind(octetstring data, int16_t lqual_cb := 0, uint32_t fn := 0, |
| 785 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 786 | runs on MS_BTS_IFACE_CT { |
| 787 | var template RAW_PCU_EventParam ev_param := {tdma_fn := ? }; |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 788 | BTS.send(ts_PCUIF_DATA_IND(nr.bts_nr, nr.trx_nr, nr.ts_nr, nr.blk_nr, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 789 | sapi := PCU_IF_SAPI_PDTCH, data := data, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 790 | fn := fn, arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 791 | lqual_cb := lqual_cb)); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 792 | if (fn != 0) { |
| 793 | ev_param := {tdma_fn := fn }; |
| 794 | } |
| 795 | BTS.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_SENT, ev_param)); |
| 796 | } |
| 797 | |
| 798 | /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 799 | function f_pcuif_rx_data_req(out PCUIF_Message pcu_msg, |
| 800 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 801 | runs on MS_BTS_IFACE_CT { |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 802 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 803 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 804 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), block_nr := nr.blk_nr)); |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 805 | BTS.receive(tr_PCUIF_DATA_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 806 | sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg; |
| 807 | } |
| 808 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 809 | /* Expect a Paging Request Type 1 from PCU on PCUIF on specified sapi. */ |
| 810 | function f_pcuif_rx_pch_pag_req1(template MobileIdentityV mi1 := ?, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 811 | template integer pag_group := ?, |
| 812 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 813 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 814 | var GsmRrMessage rr_pag_req1; |
| 815 | var PCUIF_Message pcu_msg; |
| 816 | var octetstring imsi_suff_octstr; |
| 817 | var integer pag_group_rx; |
| 818 | var octetstring macblock; |
| 819 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 820 | BTS.receive(tr_PCUIF_DATA_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 821 | sapi := PCU_IF_SAPI_PCH)) -> value pcu_msg; |
| 822 | |
| 823 | /* First 3 bytes contain IMSI suffix to calculate paging group: */ |
| 824 | imsi_suff_octstr := substr(pcu_msg.u.data_req.data, 0, 3); |
| 825 | pag_group_rx := str2int(oct2char(imsi_suff_octstr[0])) * 100 + |
| 826 | str2int(oct2char(imsi_suff_octstr[1])) * 10 + |
| 827 | str2int(oct2char(imsi_suff_octstr[2])); |
| 828 | |
| 829 | /* Make sure we've got RR Paging Request Type 1 for a given MI */ |
| 830 | macblock := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 831 | rr_pag_req1 := dec_GsmRrMessage(macblock); |
| 832 | if (not match(rr_pag_req1, tr_PAG_REQ1(tr_MI_LV(mi1)))) { |
| 833 | setverdict(fail, "Failed to match Paging Request Type 1: ", rr_pag_req1); |
| 834 | f_shutdown(__BFILE__, __LINE__); |
| 835 | } |
| 836 | |
| 837 | /* Make sure that received paging froup matches the expected one */ |
| 838 | if (not match(pag_group_rx, pag_group)) { |
| 839 | setverdict(fail, "Paging group", pag_group_rx, " does not match expected ", pag_group); |
| 840 | f_shutdown(__BFILE__, __LINE__); |
| 841 | } |
| 842 | |
| 843 | f_pcuif_tx_data_cnf(pcu_msg); |
| 844 | return rr_pag_req1; |
| 845 | } |
| 846 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 847 | function f_rx_rlcmac_dl_block(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 848 | template (present) CodingScheme exp_cs_mcs := ?, |
| 849 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 850 | runs on MS_BTS_IFACE_CT { |
| 851 | var PCUIF_Message pcu_msg; |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 852 | f_pcuif_rx_data_req(pcu_msg, nr := nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 853 | dl_block := dec_RlcmacDlBlock(pcu_msg.u.data_req.data); |
| 854 | dl_fn := pcu_msg.u.data_req.fn; |
| 855 | |
| 856 | var integer len := lengthof(pcu_msg.u.data_req.data); |
| 857 | var CodingScheme cs_mcs := f_rlcmac_block_len2cs_mcs(len) |
| 858 | if (not match(f_rlcmac_block_len2cs_mcs(len), exp_cs_mcs)) { |
| 859 | setverdict(fail, "Failed to match Coding Scheme exp ", exp_cs_mcs, " vs ", cs_mcs, " (", len, ")"); |
| 860 | f_shutdown(__BFILE__, __LINE__); |
| 861 | } |
| 862 | } |
| 863 | |
Pau Espin Pedrol | cdbe903 | 2020-07-07 20:20:42 +0200 | [diff] [blame] | 864 | function f_rx_rlcmac_dl_block_exp_ack_nack(out RlcmacDlBlock dl_block, out uint32_t poll_fn, |
| 865 | template RlcmacDlBlock acknack_tmpl := (tr_RLCMAC_UL_ACK_NACK_GPRS(ul_tfi := ?), |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 866 | tr_RLCMAC_UL_ACK_NACK_EGPRS(ul_tfi := ?)), |
| 867 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 868 | runs on MS_BTS_IFACE_CT { |
| 869 | var uint32_t dl_fn; |
| 870 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 871 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | cdbe903 | 2020-07-07 20:20:42 +0200 | [diff] [blame] | 872 | if (match(dl_block, acknack_tmpl)) { |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 873 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 874 | return; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 875 | } |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 876 | setverdict(fail, "Failed to match Packet Uplink ACK / NACK:", dl_block); |
| 877 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 878 | } |
| 879 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 880 | function f_rx_rlcmac_dl_block_exp_dummy(out RlcmacDlBlock dl_block, |
| 881 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 882 | runs on MS_BTS_IFACE_CT { |
| 883 | var uint32_t dl_fn; |
| 884 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 885 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 886 | if (not match(dl_block, tr_RLCMAC_DUMMY_CTRL())) { |
| 887 | setverdict(fail, "Failed to match Packet DUMMY DL"); |
| 888 | f_shutdown(__BFILE__, __LINE__); |
| 889 | } |
| 890 | } |
| 891 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 892 | function f_rx_rlcmac_dl_block_exp_pkt_pag_req(out RlcmacDlBlock dl_block, |
| 893 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 894 | runs on MS_BTS_IFACE_CT { |
| 895 | var uint32_t dl_fn; |
| 896 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 897 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 898 | if (not match(dl_block, tr_RLCMAC_PACKET_PAG_REQ())) { |
| 899 | setverdict(fail, "Failed to match Packet Paging Request: ", dl_block, " vs ", tr_RLCMAC_PACKET_PAG_REQ()); |
| 900 | f_shutdown(__BFILE__, __LINE__); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /* This function does what could probably be done with templates */ |
| 905 | function f_rlcmac_dl_block_verify_data_gprs(in RlcmacDlDataBlock data_block, |
| 906 | template (present) octetstring data := ?, |
| 907 | template (present) uint7_t exp_bsn := ?, |
| 908 | template (present) CodingScheme exp_cs := ?) |
| 909 | runs on MS_BTS_IFACE_CT { |
| 910 | if (not match(data_block.mac_hdr.hdr_ext.bsn, exp_bsn)) { |
| 911 | setverdict(fail, "DL block BSN doesn't match: ", |
| 912 | data_block.mac_hdr.hdr_ext.bsn, " vs exp ", exp_bsn); |
Pau Espin Pedrol | e582f20 | 2020-11-13 11:50:09 +0100 | [diff] [blame] | 913 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | if (lengthof(data_block.blocks) < 1) { |
| 917 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 918 | f_shutdown(__BFILE__, __LINE__); |
| 919 | } |
| 920 | |
| 921 | if (not match(data_block.blocks[0].payload, data)) { |
| 922 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 923 | data_block.blocks[0].payload, " vs ", data); |
| 924 | f_shutdown(__BFILE__, __LINE__); |
| 925 | } |
| 926 | |
| 927 | /* Check next data blocks contain dummy frames */ |
| 928 | if (lengthof(data_block.blocks) > 1 and substr(data_block.blocks[1].payload, 0, 3) != '43C001'O) { |
| 929 | setverdict(fail, "Second data payload is not a dummy frame: ", |
| 930 | data_block.blocks[1].payload); |
| 931 | f_shutdown(__BFILE__, __LINE__); |
| 932 | } |
| 933 | |
Pau Espin Pedrol | e5e64c1 | 2020-11-03 17:36:30 +0100 | [diff] [blame] | 934 | if (not match(data_block.cs, exp_cs)) { |
| 935 | setverdict(fail, "Failed to match ", data_block.cs, " vs exp ", exp_cs); |
| 936 | f_shutdown(__BFILE__, __LINE__); |
| 937 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* This function does what could probably be done with templates */ |
| 941 | function f_rlcmac_dl_block_verify_data_egprs(in RlcmacDlEgprsDataBlock data_block, |
| 942 | template (present) octetstring data := ?, |
| 943 | template (present) uint14_t exp_bsn := ?, |
| 944 | template (present) CodingScheme exp_cs := ?) |
| 945 | runs on MS_BTS_IFACE_CT { |
| 946 | if (not match(data_block.mac_hdr.bsn1, exp_bsn)) { |
| 947 | setverdict(fail, "DL block BSN doesn't match: ", |
| 948 | data_block.mac_hdr.bsn1, " vs exp ", exp_bsn); |
| 949 | } |
| 950 | |
| 951 | if (lengthof(data_block.blocks) < 1) { |
| 952 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 953 | f_shutdown(__BFILE__, __LINE__); |
| 954 | } |
| 955 | |
| 956 | if (not match(data_block.blocks[0].payload, data)) { |
| 957 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 958 | data_block.blocks[0].payload, " vs ", data); |
| 959 | f_shutdown(__BFILE__, __LINE__); |
| 960 | } |
| 961 | |
| 962 | /* Check next data blocks contain dummy frames */ |
| 963 | if (lengthof(data_block.blocks) > 1 and substr(data_block.blocks[1].payload, 0, 3) != '43C001'O) { |
| 964 | setverdict(fail, "Second data payload is not a dummy frame: ", |
| 965 | data_block.blocks[1].payload); |
| 966 | f_shutdown(__BFILE__, __LINE__); |
| 967 | } |
| 968 | |
Pau Espin Pedrol | e5e64c1 | 2020-11-03 17:36:30 +0100 | [diff] [blame] | 969 | if (not match(data_block.mcs, exp_cs)) { |
| 970 | setverdict(fail, "Failed to match ", data_block.mcs, " vs exp ", exp_cs); |
| 971 | f_shutdown(__BFILE__, __LINE__); |
| 972 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 973 | } |
| 974 | |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 975 | /* High level (task specific) helper for matching GPRS/EGPRS data blocks */ |
| 976 | function f_rlcmac_dl_block_exp_data(in RlcmacDlBlock dl_block, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 977 | template (present) octetstring data := ?, |
| 978 | template (present) uint7_t exp_bsn := ?, |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 979 | template (present) CodingScheme exp_cs := ?) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 980 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 981 | /* Make sure it's either GPRS or EGPRS data block */ |
| 982 | if (not match(dl_block, tr_RLCMAC_DATA)) { |
| 983 | setverdict(fail, "Failed to match DL DATA: ", dl_block, " vs ", tr_RLCMAC_DATA); |
| 984 | f_shutdown(__BFILE__, __LINE__); |
| 985 | } |
| 986 | |
| 987 | if (ischosen(dl_block.data_egprs)) { |
| 988 | f_rlcmac_dl_block_verify_data_egprs(dl_block.data_egprs, data, exp_bsn, exp_cs); |
| 989 | } else if (ischosen(dl_block.data)) { |
| 990 | f_rlcmac_dl_block_verify_data_gprs(dl_block.data, data, exp_bsn, exp_cs); |
| 991 | } else { |
| 992 | /* Should not happen, but the caller may theoretically give us a template for CTRL */ |
| 993 | setverdict(fail, "DL block is neither GPRS nor EGPRS data block: ", dl_block); |
| 994 | f_shutdown(__BFILE__, __LINE__); |
| 995 | } |
| 996 | } |
| 997 | |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 998 | /* High level (task specific) helper for receiving and matching GPRS/EGPRS data blocks */ |
| 999 | function f_rx_rlcmac_dl_block_exp_data(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 1000 | template (present) octetstring data := ?, |
| 1001 | template (present) uint7_t exp_bsn := ?, |
| 1002 | template (present) CodingScheme exp_cs := ?, |
| 1003 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 1004 | runs on MS_BTS_IFACE_CT { |
| 1005 | /* FIXME: ideally we should use an alt statement with timeout here, rather than |
| 1006 | * having +100500 layers of abstraction. This would facilitate developing the |
| 1007 | * multi-TBF/-TRX/-BTS tests, where you cannot expect that the first received |
| 1008 | * block is exactly what you need. */ |
| 1009 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
| 1010 | |
| 1011 | f_rlcmac_dl_block_exp_data(dl_block, data, exp_bsn, exp_cs); |
| 1012 | } |
| 1013 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1014 | function f_dl_block_ack_fn(in RlcmacDlBlock dl_block, uint32_t dl_fn) |
| 1015 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 1016 | var boolean rrbp_valid; |
| 1017 | var MacRrbp rrbp; |
| 1018 | |
| 1019 | /* The argument must be either a GPRS or EGPRS data block */ |
| 1020 | if (ischosen(dl_block.data_egprs)) { |
Pau Espin Pedrol | aa0d7cc | 2020-11-12 21:05:11 +0100 | [diff] [blame] | 1021 | rrbp_valid := dl_block.data_egprs.mac_hdr.esp != '00'B; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1022 | rrbp := dl_block.data_egprs.mac_hdr.rrbp; |
| 1023 | } else if (ischosen(dl_block.data)) { |
| 1024 | rrbp_valid := dl_block.data.mac_hdr.mac_hdr.rrbp_valid; |
| 1025 | rrbp := dl_block.data.mac_hdr.mac_hdr.rrbp; |
| 1026 | } else { |
| 1027 | rrbp_valid := dl_block.ctrl.mac_hdr.rrbp_valid; |
| 1028 | rrbp := dl_block.ctrl.mac_hdr.rrbp; |
| 1029 | } |
| 1030 | |
| 1031 | /* Make sure that the given block really needs to be ACKnowledged */ |
| 1032 | if (not rrbp_valid) { |
| 1033 | setverdict(fail, "DL block shall not be ACKnowledged, field RRBP is not valid"); |
| 1034 | f_shutdown(__BFILE__, __LINE__); |
| 1035 | } |
| 1036 | |
| 1037 | return f_rrbp_ack_fn(dl_fn, rrbp); |
| 1038 | } |
| 1039 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1040 | /* Return true if a given Packet Paging Request contains the given IMSI, false otherwise */ |
| 1041 | function f_pkt_paging_match_imsi(in PacketPagingReq req, template hexstring imsi, |
| 1042 | boolean cs_domain := true, boolean ps_domain := true) |
| 1043 | runs on MS_BTS_IFACE_CT return boolean { |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1044 | if (not ispresent(req.repeated_pageinfo)) { |
| 1045 | setverdict(fail, "Packet Paging Request without MIs?!?"); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1046 | f_shutdown(__BFILE__, __LINE__); |
| 1047 | } |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1048 | |
| 1049 | for (var integer i := 0; i < lengthof(req.repeated_pageinfo); i := i + 1) { |
| 1050 | var PageInfo info := req.repeated_pageinfo[i].item; |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1051 | var MobileIdentityLV_Paging mi_lv; |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1052 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1053 | if (ischosen(info.cs)) { /* CS domain */ |
| 1054 | if (not ispresent(info.cs.mobile_identity)) |
| 1055 | { continue; } |
| 1056 | if (not cs_domain) |
| 1057 | { continue; } |
| 1058 | mi_lv := info.cs.mobile_identity; |
| 1059 | } else { /* PS domain */ |
| 1060 | if (not ispresent(info.ps.mobile_identity)) |
| 1061 | { continue; } |
| 1062 | if (not ps_domain) |
| 1063 | { continue; } |
| 1064 | mi_lv := info.ps.mobile_identity; |
| 1065 | } |
| 1066 | |
| 1067 | /* Make sure MI contains IMSI before referencing it */ |
| 1068 | if (match(mi_lv.mobile_id, decmatch tr_MI_IMSI(imsi))) { |
| 1069 | return true; |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1073 | return false; |
| 1074 | } |
| 1075 | |
| 1076 | /* Return true if a given Packet Paging Request contains the given P-TMSI, false otherwise */ |
| 1077 | function f_pkt_paging_match_tmsi(in PacketPagingReq req, template GsmTmsi tmsi, |
| 1078 | boolean cs_domain := true, boolean ps_domain := true) |
| 1079 | runs on MS_BTS_IFACE_CT return boolean { |
| 1080 | if (not ispresent(req.repeated_pageinfo)) { |
| 1081 | setverdict(fail, "Packet Paging Request without MIs?!?"); |
| 1082 | f_shutdown(__BFILE__, __LINE__); |
| 1083 | } |
| 1084 | |
| 1085 | for (var integer i := 0; i < lengthof(req.repeated_pageinfo); i := i + 1) { |
| 1086 | var PageInfo info := req.repeated_pageinfo[i].item; |
| 1087 | |
| 1088 | if (cs_domain and ischosen(info.cs)) { |
| 1089 | if (not ispresent(info.cs.tmsi)) |
| 1090 | { continue; } |
| 1091 | if (match(info.cs.tmsi, tmsi)) |
| 1092 | { return true; } |
| 1093 | } else if (ps_domain) { |
| 1094 | if (not ispresent(info.ps.ptmsi)) |
| 1095 | { continue; } |
| 1096 | if (match(info.ps.ptmsi, tmsi)) |
| 1097 | { return true; } |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | return false; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | } |