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; |
Vadim Yanitskiy | 150d6d1 | 2022-10-20 19:10:04 +0700 | [diff] [blame] | 19 | import from GSM_RestOctets all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 20 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 21 | import from RLCMAC_CSN1_Types all; |
| 22 | import from RLCMAC_CSN1_Templates all; |
| 23 | import from RLCMAC_Types all; |
| 24 | import from RLCMAC_Templates all; |
| 25 | |
| 26 | import from MobileL3_CommonIE_Types all; |
| 27 | import from L3_Templates all; |
| 28 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 29 | import from PCUIF_Types all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 30 | import from PCUIF_Components all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 31 | import from Native_Functions all; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 32 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 33 | modulepar { |
| 34 | /* ARFCN of 1st TRX. Subsequent TRX are allocated incrementing ARFCNs. Nth TRX => base_arfcn + N-1 */ |
| 35 | GsmArfcn mp_base_arfcn := 871; |
| 36 | }; |
| 37 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 38 | type record TsTrxBtsNum { |
| 39 | uint3_t ts_nr, |
| 40 | uint3_t trx_nr, |
| 41 | uint8_t bts_nr, |
| 42 | uint8_t blk_nr |
| 43 | }; |
| 44 | |
Pau Espin Pedrol | 8155bf4 | 2020-10-29 17:34:26 +0100 | [diff] [blame] | 45 | /* Useful to store poll FN + BTS+TRX+TS requested by network */ |
| 46 | type record PollFnCtx { |
| 47 | TsTrxBtsNum tstrxbts, |
| 48 | uint32_t fn |
| 49 | }; |
| 50 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 51 | template (value) TsTrxBtsNum ts_TsTrxBtsNum(uint3_t ts_nr := 7, |
| 52 | uint3_t trx_nr := 0, |
| 53 | uint8_t bts_nr := 0, |
| 54 | uint8_t blk_nr := 0) := { |
| 55 | ts_nr := ts_nr, |
| 56 | trx_nr := trx_nr, |
| 57 | bts_nr := bts_nr, |
| 58 | blk_nr := blk_nr |
| 59 | }; |
| 60 | template TsTrxBtsNum tr_TsTrxBtsNum(template uint3_t ts_nr := ?, |
| 61 | template uint3_t trx_nr := ?, |
| 62 | template uint8_t bts_nr := ?, |
| 63 | template uint8_t blk_nr := ?) := { |
| 64 | ts_nr := ts_nr, |
| 65 | trx_nr := trx_nr, |
| 66 | bts_nr := bts_nr, |
| 67 | blk_nr := blk_nr |
| 68 | }; |
| 69 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 70 | type union PacketDlAssignChan { |
| 71 | PacketDlAssign ccch, |
| 72 | PacketDlAssignment pacch |
| 73 | }; |
| 74 | |
| 75 | type record DlTbf { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 76 | GsmRrMessage rr_imm_ass optional, |
| 77 | PacketDlAssignChan ass optional, |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 78 | uint5_t tfi, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 79 | GsmArfcn arfcn optional, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 80 | BIT8 ts_mask, |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 81 | AckNackDescription acknack_desc, |
| 82 | EgprsAckNackDescription egprs_acknack_desc |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | type union PacketUlAssignChan { |
| 86 | PacketUlAssign ccch, |
| 87 | EgprsUlAss ccch_egprs, |
| 88 | PacketUlAssignment pacch |
| 89 | }; |
| 90 | |
| 91 | type record UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 92 | GsmRrMessage rr_imm_ass optional, |
| 93 | PacketUlAssignChan ass optional, |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 94 | uint5_t tfi, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 95 | GsmArfcn arfcn optional, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 96 | BIT8 ts_mask, |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 97 | uint3_t usf[8], |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 98 | boolean is_egprs, |
| 99 | uint14_t bsn, |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 100 | CodingScheme tx_cs_mcs, |
| 101 | GsmFrameNumber start_time_fn |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | type record GprsMS { |
| 105 | hexstring imsi, |
| 106 | GprsTlli tlli, |
| 107 | uint16_t ra, |
| 108 | uint8_t ra_is_11bit, |
| 109 | PCUIF_BurstType burst_type, |
| 110 | TimingAdvance ta, |
| 111 | int16_t lqual_cb, |
| 112 | UlTbf ul_tbf optional, /* TODO: Only 1 UL tbf supported for now */ |
| 113 | DlTbf dl_tbf optional /* TODO: Only 1 DL tbf supported for now */ |
| 114 | }; |
Vadim Yanitskiy | cff3e1b | 2020-10-31 21:12:12 +0700 | [diff] [blame] | 115 | type record of GprsMS GprsMSList; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 116 | |
| 117 | template AckNackDescription t_AckNackDescription_init := { |
| 118 | final_ack := '0'B, |
| 119 | starting_seq_nr := 0, |
| 120 | receive_block_bitmap := '0000000000000000000000000000000000000000000000000000000000000000'B |
| 121 | } |
| 122 | |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 123 | template EgprsAckNackDescription t_EgprsAckNackDescription_init := { |
| 124 | final_ack := '0'B, |
| 125 | begin_window := '1'B, |
| 126 | end_window := '1'B, |
| 127 | starting_seq_nr := 1, |
| 128 | compressed := '0'B, |
| 129 | urbb := '0000000000000000000000000000000000000000000000000000000000000000'B |
| 130 | } |
| 131 | |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 132 | const uint3_t USF_UNUSED := 7; /* used to indicate PRACH */ |
| 133 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 134 | template (value) GprsMS t_GprsMS_def := { |
| 135 | imsi := f_gen_imsi(42), |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 136 | tlli := f_gen_tlli(), |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 137 | ra := bit2int(chan_req_def), |
| 138 | ra_is_11bit := 0, |
| 139 | burst_type := BURST_TYPE_0, |
| 140 | ta := 0, |
| 141 | lqual_cb := 0, |
| 142 | ul_tbf := omit, |
| 143 | dl_tbf := omit |
| 144 | }; |
| 145 | |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 146 | template (value) DlTbf t_DlTbf_def := { |
| 147 | rr_imm_ass := omit, |
| 148 | ass := omit, |
| 149 | tfi := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 150 | arfcn := omit, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 151 | ts_mask := '00000000'B, |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 152 | acknack_desc := t_AckNackDescription_init, |
| 153 | egprs_acknack_desc := t_EgprsAckNackDescription_init |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 154 | }; |
| 155 | |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 156 | template (value) UlTbf t_UlTbf_def := { |
| 157 | rr_imm_ass := omit, |
| 158 | ass := omit, |
| 159 | tfi := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 160 | arfcn := omit, |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 161 | ts_mask := '00000000'B, |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 162 | usf := { USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED, USF_UNUSED }, |
| 163 | is_egprs := false, |
| 164 | bsn := 0, |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 165 | tx_cs_mcs := CS_1, |
| 166 | start_time_fn := 0 |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 169 | type component MS_BTS_IFACE_CT { |
| 170 | /* Virtual BTS component */ |
| 171 | var RAW_PCU_BTS_CT vc_BTS; |
| 172 | /* Connection to the BTS component (one for now) */ |
| 173 | port RAW_PCU_MSG_PT BTS; |
| 174 | |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 175 | /* Mobile station(s) involved in a testing scenario */ |
Vadim Yanitskiy | cff3e1b | 2020-10-31 21:12:12 +0700 | [diff] [blame] | 176 | var GprsMSList g_ms := { }; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 177 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 178 | /* Value at which Countdown Procedure starts. Announced by network (GPRS Cell Options as per TS 04.60 Chapter 12.24) */ |
| 179 | var uint4_t g_bs_cv_max := 4; |
| 180 | } |
| 181 | |
Vadim Yanitskiy | 7942580 | 2020-10-31 21:23:08 +0700 | [diff] [blame] | 182 | /* 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] | 183 | function f_init_gprs_ms(integer num_ms := 1, template (value) GprsMS t_ms := t_GprsMS_def) |
| 184 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 185 | for (var integer i := 0; i < num_ms; i := i + 1 ) { |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 186 | var GprsMS ms := valueof(t_ms); |
| 187 | |
Vadim Yanitskiy | e12b2ac | 2020-10-31 21:21:47 +0700 | [diff] [blame] | 188 | /* We assume that num_ms is not a large number */ |
| 189 | ms.imsi := f_gen_imsi(i + 1); |
| 190 | ms.tlli := int2oct(i + 1, 4); |
| 191 | |
Vadim Yanitskiy | 7942580 | 2020-10-31 21:23:08 +0700 | [diff] [blame] | 192 | /* Ensure different RA for siblings */ |
| 193 | if (ms.ra == bit2int(chan_req_def)) { |
| 194 | /* 01111 { 0xx | x0x | xx0 } */ |
| 195 | f_ms_use_ra(ms, ms.ra + (i mod 7)); |
| 196 | } else if (ms.ra == bit2int(chan_req_sb)) { |
| 197 | /* 01110xxx */ |
| 198 | f_ms_use_ra(ms, ms.ra + (i mod 8)); |
| 199 | } |
| 200 | |
Vadim Yanitskiy | fa6b882 | 2020-10-31 21:10:29 +0700 | [diff] [blame] | 201 | /* Append to the global list */ |
| 202 | g_ms := g_ms & { ms }; |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 203 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 207 | function f_shutdown(charstring file, integer line, |
| 208 | boolean final := false) |
| 209 | runs on MS_BTS_IFACE_CT { |
| 210 | /* Determine if the test case was aborted in the middle */ |
| 211 | if (not final) { |
| 212 | log("Test case ", testcasename(), " aborted at ", file, ":", line); |
| 213 | } else { |
| 214 | /* Guard verdict to avoid 'none' */ |
| 215 | setverdict(pass); |
| 216 | } |
| 217 | |
| 218 | /* Properly shutdown virtual BTS and its clock generator */ |
| 219 | BTS.send(ts_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)); |
| 220 | vc_BTS.done; /* wait untill it's done */ |
| 221 | |
| 222 | /* Shutdown the others and MTC */ |
| 223 | all component.stop; |
| 224 | mtc.stop; |
| 225 | } |
| 226 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 227 | function f_arfcn2trxnr(GsmArfcn arfcn) runs on MS_BTS_IFACE_CT return uint3_t { |
| 228 | if (arfcn < mp_base_arfcn) { |
| 229 | setverdict(fail, "Unable to find TRX NR for arfcn ", arfcn); |
| 230 | f_shutdown(__BFILE__, __LINE__); |
| 231 | } |
| 232 | return arfcn - mp_base_arfcn; |
| 233 | } |
| 234 | |
| 235 | function f_trxnr2arfcn(uint3_t trx_nr) return GsmArfcn { |
| 236 | return mp_base_arfcn + trx_nr; |
| 237 | } |
| 238 | |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 239 | /* 3GPP TS 44.018 10.5.2.38 Starting Time */ |
| 240 | function f_tbf_starting_time_2_fn_mod_42432(TbfStartingTime st) |
| 241 | runs on MS_BTS_IFACE_CT return GsmFrameNumber { |
| 242 | return 51 * ((st.t3 - st.t2) mod 26) + st.t3 + 51 * 26 * st.t1; |
| 243 | } |
| 244 | |
Pau Espin Pedrol | 1451f9f | 2021-05-11 11:52:37 +0200 | [diff] [blame] | 245 | function fn2bn(GsmFrameNumber fn) return uint32_t { |
| 246 | return (fn mod 52) / 4; |
| 247 | } |
| 248 | function f_next_pdch_block(GsmFrameNumber fn) return GsmFrameNumber |
| 249 | { |
| 250 | var uint32_t bn := fn2bn(fn) + 1; |
| 251 | fn := fn - (fn mod 52); |
| 252 | fn := fn + bn * 4 + bn / 3; |
| 253 | return fn mod GsmMaxFrameNumber; |
| 254 | } |
| 255 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 256 | function f_ultbf_new_from_rr_imm_ass(in GsmRrMessage rr_imm_ass) |
| 257 | runs on MS_BTS_IFACE_CT return UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 258 | var UlTbf ul_tbf := valueof(t_UlTbf_def); |
| 259 | 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] | 260 | |
| 261 | ul_tbf.rr_imm_ass := rr_imm_ass; |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 262 | if (rr_imm_ass.payload.imm_ass.pkt_chan_desc.presence == '0'B and |
| 263 | rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.hopping == '0'B) { |
| 264 | ul_tbf.arfcn := rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.arfcn; |
| 265 | } |
| 266 | ul_tbf.ts_mask[tn_allocated] := '1'B; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 267 | |
| 268 | /* Make sure we received an UL TBF Assignment */ |
| 269 | if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_ULAss(?)))) { |
| 270 | ul_tbf.ass.ccch := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.ul; |
| 271 | log("Rx Uplink TBF GPRS assignment: ", ul_tbf.ass.ccch); |
| 272 | ul_tbf.is_egprs := false; |
| 273 | if (match(ul_tbf.ass.ccch, tr_PacketUlDynAssign)) { |
| 274 | ul_tbf.tfi := ul_tbf.ass.ccch.dynamic.tfi_assignment; |
Pau Espin Pedrol | 9040111 | 2020-05-20 17:36:27 +0200 | [diff] [blame] | 275 | 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] | 276 | ul_tbf.usf[tn_allocated] := ul_tbf.ass.ccch.dynamic.usf; |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 277 | if (ul_tbf.ass.ccch.dynamic.tbf_starting_time_present == '1'B) { |
| 278 | ul_tbf.start_time_fn := f_tbf_starting_time_2_fn_mod_42432(ul_tbf.ass.ccch.dynamic.tbf_starting_time); |
| 279 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 280 | } else if (match(ul_tbf.ass.ccch, tr_PacketUlSglAssign)) { |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 281 | ul_tbf.start_time_fn := f_tbf_starting_time_2_fn_mod_42432(ul_tbf.ass.ccch.single.tbf_starting_time); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 282 | } |
| 283 | } else if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_EGPRSULAss(?)))) { |
| 284 | ul_tbf.ass.ccch_egprs := rr_imm_ass.payload.imm_ass.rest_octets.lh.egprs_ul; |
| 285 | log("Rx Uplink TBF EGPRS assignment: ", ul_tbf.ass.ccch_egprs); |
| 286 | ul_tbf.is_egprs := true; |
| 287 | if (match(ul_tbf.ass.ccch_egprs, tr_EgprsUlAssDynamic)) { |
| 288 | ul_tbf.tfi := ul_tbf.ass.ccch_egprs.dynamic.tfi_assignment; |
Pau Espin Pedrol | 9040111 | 2020-05-20 17:36:27 +0200 | [diff] [blame] | 289 | 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] | 290 | ul_tbf.usf[tn_allocated] := ul_tbf.ass.ccch_egprs.dynamic.usf; |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 291 | if (ul_tbf.ass.ccch_egprs.dynamic.tbf_starting_time_present == '1'B) { |
| 292 | ul_tbf.start_time_fn := f_tbf_starting_time_2_fn_mod_42432(ul_tbf.ass.ccch_egprs.dynamic.tbf_starting_time); |
| 293 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 294 | } else if (match(ul_tbf.ass.ccch_egprs, tr_EgprsUlAssMultiblock)) { |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 295 | ul_tbf.start_time_fn := f_tbf_starting_time_2_fn_mod_42432(ul_tbf.ass.ccch_egprs.multiblock.tbf_starting_time); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 296 | /* Nothing to do here yet */ |
| 297 | } |
| 298 | } else { |
| 299 | setverdict(fail, "Failed to match UL TBF Assignment: ", rr_imm_ass); |
| 300 | f_shutdown(__BFILE__, __LINE__); |
| 301 | } |
| 302 | |
| 303 | setverdict(pass); |
| 304 | return ul_tbf; |
| 305 | } |
| 306 | |
| 307 | function f_ultbf_new_from_ass_pacch(RlcmacDlBlock dl_block) |
| 308 | runs on MS_BTS_IFACE_CT return UlTbf { |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 309 | var UlTbf ul_tbf := valueof(t_UlTbf_def); |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 310 | var boolean freq_par_present := false; |
| 311 | var FrequencyParameters freq_par; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 312 | |
| 313 | ul_tbf.ass.pacch := dl_block.ctrl.payload.u.ul_assignment; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 314 | ul_tbf.tx_cs_mcs := f_rlcmac_dl_block_get_assigned_ul_cs_mcs(dl_block); |
| 315 | ul_tbf.tfi := f_rlcmac_dl_block_get_tfi(dl_block); |
| 316 | /* TODO: handle GlobalTfiOrTlli tfi_or_tlli from pkt_ul_ass */ |
| 317 | |
| 318 | /* TODO: support single block allocation */ |
| 319 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 320 | 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] | 321 | freq_par_present := dl_block.ctrl.payload.u.ul_assignment.gprs.freq_par_present == '1'B; |
| 322 | if (freq_par_present) { |
| 323 | freq_par := dl_block.ctrl.payload.u.ul_assignment.gprs.freq_par; |
| 324 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 325 | ul_tbf.is_egprs := false; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 326 | for (var integer i := 0; i < 8; i := i + 1) { |
| 327 | 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] | 328 | ul_tbf.ts_mask[i] := '1'B; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 329 | ul_tbf.usf[i] := dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ts_allocation.ts[i].usf_tn; |
| 330 | } |
| 331 | } |
| 332 | } 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] | 333 | 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] | 334 | freq_par_present := dl_block.ctrl.payload.u.ul_assignment.egprs.freq_par_present == '1'B; |
| 335 | if (freq_par_present) { |
| 336 | freq_par := dl_block.ctrl.payload.u.ul_assignment.egprs.freq_par; |
| 337 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 338 | ul_tbf.is_egprs := true; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 339 | for (var integer i := 0; i < 8; i := i + 1) { |
| 340 | 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] | 341 | ul_tbf.ts_mask[i] := '1'B; |
Pau Espin Pedrol | eb98025 | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 342 | ul_tbf.usf[i] := dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ts_allocation.ts[i].usf_tn; |
| 343 | } |
| 344 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 345 | } |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 346 | |
| 347 | /* FIXME: freq_par and arfcn are optional. in that case we need to |
| 348 | * infer/reuse from current dl_tbf or ul_tbf */ |
| 349 | if (freq_par_present and freq_par.presence == '00'B) { |
| 350 | ul_tbf.arfcn := freq_par.arfcn; |
| 351 | } |
| 352 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 353 | return ul_tbf; |
| 354 | } |
| 355 | |
| 356 | function f_dltbf_new_from_rr_imm_ass(in GsmRrMessage rr_imm_ass, template PacketDlAssign dl_ass := tr_PacketDlAssign(?)) |
| 357 | runs on MS_BTS_IFACE_CT return DlTbf { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 358 | var DlTbf dl_tbf := valueof(t_DlTbf_def); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 359 | |
| 360 | dl_tbf.rr_imm_ass := rr_imm_ass; |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 361 | if (rr_imm_ass.payload.imm_ass.pkt_chan_desc.presence == '0'B and |
| 362 | rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.hopping == '0'B) { |
| 363 | dl_tbf.arfcn := rr_imm_ass.payload.imm_ass.pkt_chan_desc.zero.arfcn; |
| 364 | } |
| 365 | 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] | 366 | |
| 367 | /* Make sure we received a DL TBF Assignment */ |
| 368 | if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := true, rest := tr_IaRestOctets_DLAss(dl_ass)))) { |
| 369 | dl_tbf.ass.ccch := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.dl; |
| 370 | log("Rx Downlink TBF assignment: ", dl_tbf.ass); |
| 371 | } else { |
| 372 | setverdict(fail, "Failed to match DL TBF Assignment: ", rr_imm_ass); |
| 373 | f_shutdown(__BFILE__, __LINE__); |
| 374 | } |
| 375 | |
| 376 | /* TODO: match TLLI */ |
| 377 | if (dl_tbf.ass.ccch.group1_present == '1'B) { |
| 378 | dl_tbf.tfi := dl_tbf.ass.ccch.group1.tfi_assignment; |
| 379 | } else { |
| 380 | setverdict(fail, "Immediate Assignment contains no DL TFI"); |
| 381 | f_shutdown(__BFILE__, __LINE__); |
| 382 | } |
| 383 | |
| 384 | setverdict(pass); |
| 385 | return dl_tbf; |
| 386 | } |
| 387 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 388 | function f_dltbf_new_from_ass_pacch(RlcmacDlBlock dl_block) |
| 389 | runs on MS_BTS_IFACE_CT return DlTbf { |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 390 | var DlTbf dl_tbf := valueof(t_DlTbf_def); |
| 391 | var boolean freq_par_present := false; |
| 392 | var FrequencyParameters freq_par; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 393 | |
| 394 | dl_tbf.ass.pacch := dl_block.ctrl.payload.u.dl_assignment; |
| 395 | dl_tbf.tfi := f_rlcmac_dl_block_get_tfi(dl_block); |
| 396 | /* TODO: handle GlobalTfiOrTlli tfi_or_tlli from pkt_dl_ass */ |
Pau Espin Pedrol | b20b7e5 | 2020-10-28 21:28:45 +0100 | [diff] [blame] | 397 | |
| 398 | if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS(?))) { |
| 399 | dl_tbf.tfi := dl_block.ctrl.payload.u.dl_assignment.dl_tfi_assignment; |
| 400 | freq_par_present := dl_block.ctrl.payload.u.dl_assignment.freq_par_present == '1'B; |
| 401 | if (freq_par_present) { |
| 402 | freq_par := dl_block.ctrl.payload.u.dl_assignment.freq_par; |
| 403 | } |
| 404 | dl_tbf.ts_mask := dl_block.ctrl.payload.u.dl_assignment.timeslot_alloc; /* TODO: is this the correct order ? */ |
| 405 | /* TODO: check egprs in dl_assignment.rel_additions (PktDlAssR99Additions) */ |
| 406 | } |
| 407 | |
| 408 | /* FIXME: freq_par and arfcn are optional. in that case we need to |
| 409 | * infer/reuse from current dl_tbf or ul_tbf */ |
| 410 | if (freq_par_present and freq_par.presence == '00'B) { |
| 411 | dl_tbf.arfcn := freq_par.arfcn; |
| 412 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 413 | return dl_tbf; |
| 414 | } |
| 415 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 416 | function f_ms_tx_TsTrxBtsNum(inout GprsMS ms) |
| 417 | runs on MS_BTS_IFACE_CT return TsTrxBtsNum { |
| 418 | var uint3_t ts_nr := f_ultbf_next_ts(ms.ul_tbf); |
| 419 | |
| 420 | var uint3_t trx_nr; |
| 421 | if (ispresent(ms.ul_tbf.arfcn)) { |
| 422 | trx_nr := f_arfcn2trxnr(ms.ul_tbf.arfcn); |
| 423 | } else { |
| 424 | /* FIXME: implement search by hsn+maio+ma when freq hopping is enabled */ |
| 425 | setverdict(fail, "Asked for trx_nr but arfcn not available in ms.ul_tbf!"); |
| 426 | f_shutdown(__BFILE__, __LINE__); |
| 427 | } |
| 428 | return valueof(ts_TsTrxBtsNum(ts_nr, trx_nr)); |
| 429 | } |
| 430 | |
| 431 | function f_dltbf_num_slots(DlTbf dl_tbf) |
| 432 | runs on MS_BTS_IFACE_CT return integer { |
| 433 | var integer n := 0; |
| 434 | for (var integer i := 0; i < lengthof(dl_tbf.ts_mask); i := i + 1) { |
| 435 | if (dl_tbf.ts_mask[i] == '1'B) { |
| 436 | n := n + 1; |
| 437 | } |
| 438 | } |
| 439 | return n; |
| 440 | } |
| 441 | |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 442 | function f_dltbf_ack_block(inout DlTbf dl_tbf, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 443 | runs on MS_BTS_IFACE_CT { |
| 444 | var boolean is_egprs := ischosen(dl_block.data_egprs); |
| 445 | if (is_egprs) { |
| 446 | f_egprs_acknackdesc_ack_block(dl_tbf.egprs_acknack_desc, dl_block, final_ack); |
| 447 | } else { |
| 448 | f_acknackdesc_ack_block(dl_tbf.acknack_desc, dl_block, final_ack); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | function f_dltbf_ts_RLCMAC_DL_ACK_NACK(DlTbf dl_tbf, boolean use_egprs := false, |
Pau Espin Pedrol | db31765 | 2021-02-05 12:30:01 +0100 | [diff] [blame] | 453 | template (omit) ChannelReqDescription chreq_desc := omit) |
Pau Espin Pedrol | fa64e28 | 2021-02-05 17:56:52 +0100 | [diff] [blame] | 454 | runs on MS_BTS_IFACE_CT return template (value) RlcmacUlBlock { |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 455 | if (use_egprs) { |
| 456 | return ts_RLCMAC_DL_ACK_NACK_EGPRS(dl_tbf.tfi, dl_tbf.egprs_acknack_desc, false, chreq_desc); |
| 457 | } else { |
| 458 | return ts_RLCMAC_DL_ACK_NACK(dl_tbf.tfi, dl_tbf.acknack_desc, false, chreq_desc); |
| 459 | } |
| 460 | } |
| 461 | |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 462 | function f_ultbf_inc_bsn(inout UlTbf ul_tbf) |
| 463 | runs on MS_BTS_IFACE_CT { |
| 464 | ul_tbf.bsn := ul_tbf.bsn + 1; |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 465 | if (ul_tbf.is_egprs) { |
| 466 | ul_tbf.bsn := ul_tbf.bsn mod 2048; |
| 467 | } else { |
| 468 | ul_tbf.bsn := ul_tbf.bsn mod 128; |
| 469 | } |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 470 | } |
| 471 | |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 472 | function f_ultbf_next_ts(UlTbf ul_tbf) |
| 473 | runs on MS_BTS_IFACE_CT return uint3_t { |
| 474 | /* FIXME: in the future we probably want to store last used internally |
| 475 | /* and continue from there */ |
| 476 | for (var integer i := 0; i < lengthof(ul_tbf.ts_mask); i := i + 1) { |
| 477 | if (ul_tbf.ts_mask[i] == '1'B) { |
| 478 | return i; |
| 479 | } |
| 480 | } |
| 481 | setverdict(fail, "No TS available for tx!"); |
| 482 | f_shutdown(__BFILE__, __LINE__); |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | function f_ultbf_num_slots(UlTbf ul_tbf) |
| 487 | runs on MS_BTS_IFACE_CT return integer { |
| 488 | var integer n := 0; |
| 489 | for (var integer i := 0; i < lengthof(ul_tbf.ts_mask); i := i + 1) { |
| 490 | if (ul_tbf.ts_mask[i] == '1'B) { |
| 491 | n := n + 1; |
| 492 | } |
| 493 | } |
| 494 | return n; |
| 495 | } |
| 496 | |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 497 | function f_ultbf_payload_fill_length(UlTbf ul_tbf, boolean tlli := false, integer li_bytes := 0) |
| 498 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 499 | var uint32_t blk_len := f_rlcmac_cs_mcs2block_len_no_spare_bits(ul_tbf.tx_cs_mcs); |
| 500 | var uint32_t payload_fill_len; |
| 501 | |
| 502 | if (f_rlcmac_cs_mcs_is_mcs(ul_tbf.tx_cs_mcs)) { |
| 503 | payload_fill_len := blk_len - 5 - li_bytes; |
| 504 | } else { |
| 505 | /* GPRS: blk_len = 3 Header bytes + payload length. No LI byte in this case. */ |
| 506 | payload_fill_len := blk_len - 3 - li_bytes; |
| 507 | } |
| 508 | |
| 509 | if (tlli) { |
| 510 | payload_fill_len := payload_fill_len - 4; |
| 511 | } |
| 512 | return payload_fill_len; |
| 513 | } |
| 514 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 515 | function f_ms_use_ra(inout GprsMS ms, uint16_t ra, uint8_t ra_is_11bit := 0) |
| 516 | runs on MS_BTS_IFACE_CT { |
| 517 | ms.ra_is_11bit := ra_is_11bit; |
| 518 | ms.ra := ra; |
| 519 | if (ra_is_11bit == 0) { |
| 520 | ms.burst_type := BURST_TYPE_0; |
| 521 | } else { |
| 522 | ms.burst_type := BURST_TYPE_1; |
| 523 | } |
| 524 | } |
| 525 | |
Vadim Yanitskiy | 7431e9e | 2020-07-21 01:59:17 +0700 | [diff] [blame] | 526 | 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] | 527 | template RlcmacDlBlock t_pkt_ass := ?, |
Pau Espin Pedrol | 46e3604 | 2020-10-29 21:27:43 +0100 | [diff] [blame] | 528 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 529 | boolean ignore_dummy := true) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 530 | runs on MS_BTS_IFACE_CT return RlcmacDlBlock { |
| 531 | var RlcmacDlBlock dl_block; |
Pau Espin Pedrol | 46e3604 | 2020-10-29 21:27:43 +0100 | [diff] [blame] | 532 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 533 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 534 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 535 | block_nr := nr.blk_nr)); |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 536 | alt { |
Vadim Yanitskiy | 1160284 | 2022-10-05 02:02:27 +0700 | [diff] [blame] | 537 | [] as_ms_rx_pkt_ass_pacch(ms, poll_fn, t_pkt_ass, nr, dl_block); |
| 538 | [ignore_dummy] as_ms_rx_ignore_dummy(ms, nr); |
| 539 | /* TODO: fail */ |
| 540 | [] BTS.receive { |
| 541 | setverdict(fail, "Unexpected BTS message"); |
| 542 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 543 | } |
| 544 | } |
Pau Espin Pedrol | 46e3604 | 2020-10-29 21:27:43 +0100 | [diff] [blame] | 545 | return dl_block; |
| 546 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 547 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 548 | altstep as_ms_rx_ignore_dummy(inout GprsMS ms, template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 549 | runs on MS_BTS_IFACE_CT { |
| 550 | var BTS_PDTCH_Block data_msg; |
| 551 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 552 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
Vadim Yanitskiy | 7179d3e | 2022-10-04 03:27:29 +0700 | [diff] [blame] | 553 | tr_RLCMAC_DL_DUMMY_CTRL())) -> value data_msg { |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 554 | |
| 555 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 556 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 557 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 558 | block_nr := nr.blk_nr)); |
| 559 | repeat; |
| 560 | } |
| 561 | } |
| 562 | |
Pau Espin Pedrol | 518e82f | 2021-11-12 17:24:33 +0100 | [diff] [blame] | 563 | altstep as_pcuif_rx_ignore_empty(template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 564 | runs on MS_BTS_IFACE_CT { |
| 565 | var BTS_PDTCH_Block data_msg; |
| 566 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 567 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 568 | omit)) -> value data_msg { |
| 569 | |
| 570 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 571 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 572 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 573 | block_nr := nr.blk_nr)); |
| 574 | repeat; |
| 575 | } |
| 576 | } |
| 577 | |
Pau Espin Pedrol | 1f7dec4 | 2021-08-26 12:54:37 +0200 | [diff] [blame] | 578 | altstep as_rx_fail_dummy(template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 579 | runs on MS_BTS_IFACE_CT { |
| 580 | var BTS_PDTCH_Block data_msg; |
| 581 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 582 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
Vadim Yanitskiy | 7179d3e | 2022-10-04 03:27:29 +0700 | [diff] [blame] | 583 | tr_RLCMAC_DL_DUMMY_CTRL())) -> value data_msg { |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 584 | setverdict(fail, "Unexpected Dummy Ctrl block ", data_msg); |
| 585 | f_shutdown(__BFILE__, __LINE__); |
| 586 | } |
| 587 | } |
| 588 | |
Pau Espin Pedrol | 46e3604 | 2020-10-29 21:27:43 +0100 | [diff] [blame] | 589 | altstep as_ms_rx_pkt_ass_pacch(inout GprsMS ms, out uint32_t poll_fn, |
| 590 | template RlcmacDlBlock t_pkt_ass := ?, |
| 591 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
Pau Espin Pedrol | 46e3604 | 2020-10-29 21:27:43 +0100 | [diff] [blame] | 592 | out RlcmacDlBlock dl_block) |
| 593 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 594 | var BTS_PDTCH_Block data_msg; |
| 595 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 596 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, |
| 597 | sapi := PCU_IF_SAPI_PDTCH), |
| 598 | t_pkt_ass)) -> value data_msg { |
| 599 | var uint32_t dl_fn := data_msg.raw.fn; |
| 600 | dl_block := data_msg.dl_block; |
Pau Espin Pedrol | 46e3604 | 2020-10-29 21:27:43 +0100 | [diff] [blame] | 601 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 602 | |
| 603 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS)) { |
| 604 | ms.ul_tbf := f_ultbf_new_from_ass_pacch(dl_block); |
| 605 | if (ms.ul_tbf.ass.pacch.identity.tlli.tlli != ms.tlli) { |
| 606 | setverdict(fail, "Wrong TLLI ", ms.ul_tbf.ass.pacch.identity.tlli, " received vs exp ", ms.tlli); |
| 607 | f_shutdown(__BFILE__, __LINE__); |
| 608 | } |
| 609 | } else if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS)) { |
| 610 | ms.dl_tbf := f_dltbf_new_from_ass_pacch(dl_block); |
| 611 | if (ischosen(ms.dl_tbf.ass.pacch.tfi_or_tlli.tlli) and |
| 612 | ms.dl_tbf.ass.pacch.tfi_or_tlli.tlli.tlli != ms.tlli) { |
| 613 | setverdict(fail, "Wrong TLLI ", ms.dl_tbf.ass.pacch.tfi_or_tlli.tlli.tlli, " received vs exp ", ms.tlli); |
| 614 | f_shutdown(__BFILE__, __LINE__); |
| 615 | } |
| 616 | } else { |
| 617 | setverdict(fail, "Should not happen:", dl_block); |
| 618 | f_shutdown(__BFILE__, __LINE__); |
| 619 | } |
| 620 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 623 | 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] | 624 | runs on MS_BTS_IFACE_CT { |
| 625 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 626 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 627 | 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] | 628 | ms.ul_tbf := f_ultbf_new_from_rr_imm_ass(rr_imm_ass); |
| 629 | } |
| 630 | |
Philipp Maier | 8e1a5ee | 2023-07-18 15:47:16 +0200 | [diff] [blame^] | 631 | function f_ms_exp_dl_tbf_ass_ccch(inout GprsMS ms, template PCUIF_Sapi sapi := PCU_IF_SAPI_PCH, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 632 | template GsmRrMessage t_imm_ass := tr_IMM_TBF_ASS(true, ?, ?), |
| 633 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 634 | runs on MS_BTS_IFACE_CT { |
| 635 | var GsmRrMessage rr_imm_ass; |
| 636 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 637 | 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] | 638 | ms.dl_tbf := f_dltbf_new_from_rr_imm_ass(rr_imm_ass, tr_PacketDlAssign(ms.tlli)); |
| 639 | } |
| 640 | |
| 641 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 642 | function f_ms_tx_data_ind(inout GprsMS ms, octetstring data, uint32_t fn := 0, |
| 643 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 644 | runs on MS_BTS_IFACE_CT { |
Vadim Yanitskiy | 474ec92 | 2021-05-26 13:34:49 +0200 | [diff] [blame] | 645 | f_pcuif_tx_data_ind(data, fn, ms.ta, ms.lqual_cb, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 646 | } |
| 647 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 648 | function f_ms_tx_ul_block(inout GprsMS ms, template (value) RlcmacUlBlock ul_data, |
| 649 | uint32_t fn := 0, template (omit) CodingScheme force_cs_mcs := omit, |
| 650 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 651 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 652 | var octetstring data; |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 653 | var CodingScheme cs_mcs; |
| 654 | var uint32_t cs_mcs_len; |
| 655 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 656 | /* Encode the payload of DATA.ind */ |
| 657 | data := enc_RlcmacUlBlock(valueof(ul_data)); |
Pau Espin Pedrol | 245bfcb | 2020-06-30 20:17:07 +0200 | [diff] [blame] | 658 | |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 659 | if (ischosen(ul_data.ctrl)) { |
| 660 | /* Ctrl blocks are right now encoded by RAW encoder, which was |
| 661 | * found to have some issue with final padding, so we add it |
| 662 | * here manually. This is actually still incorrect because the |
| 663 | * remaining bits of last octet with data are not filled with |
| 664 | * the padding sequence, but it's good enough since anyway PCU |
| 665 | * don't check these. */ |
| 666 | 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] | 667 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 668 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 669 | f_ms_tx_data_ind(ms, data, fn, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 670 | } |
| 671 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 672 | function f_ms_tx_ul_data_block(inout GprsMS ms, octetstring payload, |
| 673 | uint4_t cv := 15, boolean with_tlli := false, uint32_t fn := 0, |
| 674 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 675 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 676 | var template (value) RlcmacUlBlock ul_data; |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 677 | |
| 678 | if (f_rlcmac_cs_mcs_is_mcs(ms.ul_tbf.tx_cs_mcs)) { |
| 679 | ul_data := t_RLCMAC_UL_EGPRS_DATA(mcs := ms.ul_tbf.tx_cs_mcs, |
| 680 | tfi := ms.ul_tbf.tfi, |
| 681 | cv := cv, |
| 682 | bsn1 := ms.ul_tbf.bsn, |
| 683 | bsn2_offset := 0, |
| 684 | blocks := {t_RLCMAC_LLCBLOCK_EGPRS(payload)}) |
| 685 | if (with_tlli) { |
| 686 | ul_data.data_egprs.tlli_ind := true; |
| 687 | ul_data.data_egprs.tlli := ms.tlli; |
| 688 | } |
| 689 | } else { |
| 690 | ul_data := t_RLCMAC_UL_DATA(cs := ms.ul_tbf.tx_cs_mcs, |
| 691 | tfi := ms.ul_tbf.tfi, |
| 692 | cv := cv, |
| 693 | bsn := ms.ul_tbf.bsn, |
| 694 | blocks := {t_RLCMAC_LLCBLOCK(payload)}); |
| 695 | if (with_tlli) { |
| 696 | ul_data.data.mac_hdr.tlli_ind := true; |
| 697 | ul_data.data.tlli := ms.tlli; |
| 698 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 699 | } |
Pau Espin Pedrol | 05b6c17 | 2020-06-26 17:28:23 +0200 | [diff] [blame] | 700 | f_ultbf_inc_bsn(ms.ul_tbf); |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 701 | f_ms_tx_ul_block(ms, ul_data, fn, nr := nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* 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] | 705 | function f_ms_tx_ul_data_block_multi(inout GprsMS ms, integer num_blocks := 1, boolean with_tlli := false, |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 706 | uint32_t fn := 0, template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 707 | runs on MS_BTS_IFACE_CT return octetstring { |
| 708 | var octetstring total_payload := ''O; |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 709 | 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] | 710 | |
| 711 | for (var integer i := 0; i < num_blocks; i := i + 1) { |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 712 | var octetstring payload := f_rnd_octstring(payload_fill_len); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 713 | /* Prepare a new UL block (CV, random payload) */ |
| 714 | var integer cv := num_blocks - i - 1; |
| 715 | if (cv > g_bs_cv_max) { |
| 716 | cv := 15; |
| 717 | } |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 718 | if (i == 1) { |
| 719 | /* We use FN on i=0 to jump to wanted FN time, then simply submit on next |
| 720 | * available frame (fn=0) */ |
| 721 | fn := 0; |
| 722 | } |
| 723 | f_ms_tx_ul_data_block(ms, payload, cv := cv, with_tlli := with_tlli, fn := fn, nr := nr); |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 724 | total_payload := total_payload & payload; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 725 | } |
| 726 | return total_payload; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | function f_rlcmac_dl_block_get_tfi(RlcmacDlBlock dl_block) |
| 730 | runs on MS_BTS_IFACE_CT return uint5_t { |
| 731 | if (ischosen(dl_block.data)) { |
| 732 | return dl_block.data.mac_hdr.hdr_ext.tfi; |
| 733 | } else if (ischosen(dl_block.data_egprs)) { |
| 734 | return dl_block.data_egprs.mac_hdr.tfi; |
| 735 | } else { /* Ctrl block */ |
| 736 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 737 | return dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ul_tfi_assignment; |
| 738 | } |
| 739 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(tr_DynamicAllocation(?))))) { |
| 740 | return dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ul_tfi_assignment; |
| 741 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 742 | if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS(?))) { |
| 743 | return dl_block.ctrl.payload.u.dl_assignment.dl_tfi_assignment; |
| 744 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 745 | } |
| 746 | setverdict(fail, "DlBlock doesn't contain a TFI:", dl_block); |
| 747 | f_shutdown(__BFILE__, __LINE__); |
| 748 | return 0; /* make compiler happy */ |
| 749 | } |
| 750 | |
Pau Espin Pedrol | f30fa1d | 2021-03-03 19:55:11 +0100 | [diff] [blame] | 751 | function f_rlcmac_dl_block_get_usf(RlcmacDlBlock dl_block) |
| 752 | runs on MS_BTS_IFACE_CT return uint3_t { |
| 753 | if (ischosen(dl_block.data)) { |
| 754 | return dl_block.data.mac_hdr.mac_hdr.usf; |
| 755 | } else if (ischosen(dl_block.data_egprs)) { |
| 756 | return dl_block.data_egprs.mac_hdr.usf; |
| 757 | } else { /* Ctrl block */ |
| 758 | return dl_block.ctrl.mac_hdr.usf; |
| 759 | } |
| 760 | setverdict(fail, "DlBlock doesn't contain a USF:", dl_block); |
| 761 | f_shutdown(__BFILE__, __LINE__); |
| 762 | return 0; /* make compiler happy */ |
| 763 | } |
| 764 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 765 | /* Get the Chan coding command from a dl block containing PACCH UL Assignment */ |
| 766 | function f_rlcmac_dl_block_get_assigned_ul_cs_mcs(RlcmacDlBlock dl_block) |
| 767 | runs on MS_BTS_IFACE_CT return CodingScheme { |
| 768 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(?)))) { |
| 769 | return f_rlcmac_block_ChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.gprs.ch_coding_cmd); |
| 770 | } |
| 771 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(?)))) { |
| 772 | return f_rlcmac_block_EgprsChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.egprs.chan_coding_cmd); |
| 773 | } |
| 774 | setverdict(fail, "DlBlock doesn't contain CS_MCS information:", dl_block); |
| 775 | f_shutdown(__BFILE__, __LINE__); |
| 776 | return CS_1; /* make compiler happy */ |
| 777 | } |
| 778 | |
| 779 | /* TS 44.060 sec 12.3 Ack/Nack Description */ |
| 780 | function f_acknackdesc_ack_block(inout AckNackDescription desc, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 781 | { |
| 782 | var uint7_t bsn; |
| 783 | var integer i; |
| 784 | var integer inc; |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 785 | bsn := dl_block.data.mac_hdr.hdr_ext.bsn; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 786 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 787 | /* Filling hole? */ |
| 788 | if (bsn < desc.starting_seq_nr) { |
| 789 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr - bsn)] := int2bit(1, 1); |
| 790 | return; |
| 791 | } |
Pau Espin Pedrol | 9a2d61b | 2020-11-05 17:59:16 +0100 | [diff] [blame] | 792 | /* Filling hole, wraparound: */ |
| 793 | if (bsn - desc.starting_seq_nr > lengthof(desc.receive_block_bitmap)) { |
| 794 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr + (218 - bsn))] := int2bit(1, 1); |
| 795 | return; |
| 796 | } |
| 797 | |
| 798 | inc := bsn - desc.starting_seq_nr + 1; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 799 | |
| 800 | /* SSN is increased, and so RBB values need to be moved */ |
| 801 | for (i := 0; i < lengthof(desc.receive_block_bitmap) - inc; i := i+1) { |
| 802 | desc.receive_block_bitmap[i] := desc.receive_block_bitmap[i + inc]; |
| 803 | } |
| 804 | for (i := lengthof(desc.receive_block_bitmap) - inc; i < lengthof(desc.receive_block_bitmap) - 1; i := i+1) { |
| 805 | desc.receive_block_bitmap[i] := int2bit(0, 1); |
| 806 | } |
| 807 | /* Now we can set current bit and update SSN */ |
Pau Espin Pedrol | 9a2d61b | 2020-11-05 17:59:16 +0100 | [diff] [blame] | 808 | desc.starting_seq_nr := (bsn + 1) mod 128; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 809 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - 1] := int2bit(1, 1); |
| 810 | |
| 811 | /* Finally update the final_ack bit as requested: */ |
| 812 | desc.final_ack := final_ack; |
| 813 | } |
| 814 | |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 815 | /* TS 44.060 sec 12.3 Ack/Nack Description */ |
| 816 | function f_egprs_acknackdesc_ack_block(inout EgprsAckNackDescription desc, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 817 | { |
| 818 | var uint11_t bsn; |
| 819 | var integer i; |
| 820 | var integer inc; |
| 821 | var integer n := 0; |
| 822 | var integer v_q := (desc.starting_seq_nr + 2047) mod 2048; /* SSN = V(Q) + 1 */ |
| 823 | |
| 824 | bsn := dl_block.data_egprs.mac_hdr.bsn1; |
| 825 | |
| 826 | /* Repetition? */ |
| 827 | if (bsn < v_q) { |
| 828 | /* Filling hole, wraparound: */ |
| 829 | if (bsn - v_q > lengthof(desc.urbb)) { |
| 830 | desc.urbb[lengthof(desc.urbb) - (v_q + (2048 - bsn))] := int2bit(1, 1); |
| 831 | return; |
| 832 | } |
| 833 | return; |
| 834 | } |
| 835 | |
| 836 | inc := bsn - v_q + 1; |
| 837 | desc.urbb[lengthof(desc.urbb) - inc] := int2bit(1, 1); |
| 838 | |
| 839 | for (i := lengthof(desc.urbb) - 1; i >= lengthof(desc.urbb) - inc; i := i - 1) { |
| 840 | if (desc.urbb[i] == '0'B) { |
| 841 | break; |
| 842 | } |
| 843 | n := n + 1; |
| 844 | } |
| 845 | |
| 846 | if (n > 0) { |
| 847 | /* SSN is increased, and so RBB values need to be moved */ |
| 848 | for (i := lengthof(desc.urbb) - 1; i >= n; i := i - 1) { |
| 849 | desc.urbb[i] := desc.urbb[i - n]; |
| 850 | } |
| 851 | for (i := n - 1; i >= 0; i := i - 1) { |
| 852 | desc.urbb[i] := int2bit(0, 1); |
| 853 | } |
| 854 | |
| 855 | desc.starting_seq_nr := (desc.starting_seq_nr + n) mod 2048; |
| 856 | } |
| 857 | |
| 858 | /* Finally update the final_ack bit as requested: */ |
| 859 | desc.final_ack := final_ack; |
| 860 | } |
| 861 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 862 | /* This function can be used to send DATA.cnf in response to the IUT originated DATA.req. */ |
| 863 | function f_pcuif_tx_data_cnf(in BTS_CCCH_Block data_msg) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 864 | runs on MS_BTS_IFACE_CT { |
| 865 | var PCUIF_Message pcu_msg_cnf := { |
| 866 | msg_type := PCU_IF_MSG_DATA_CNF, |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 867 | bts_nr := data_msg.bts_nr, |
| 868 | spare := '0000'O, |
| 869 | u := { data_cnf := data_msg.raw } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 870 | }; |
| 871 | |
| 872 | /* PCU wants DATA.cnf containing basically everything that was in DATA.req, |
| 873 | * but PCU_IF_SAPI_PCH is a special case - paging group shall be excluded. */ |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 874 | if (data_msg.raw.sapi == PCU_IF_SAPI_PCH) { |
| 875 | pcu_msg_cnf.u.data_cnf.data := substr(data_msg.raw.data, 3, |
| 876 | data_msg.raw.len - 3); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | BTS.send(pcu_msg_cnf); |
| 880 | } |
| 881 | |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 882 | |
Pau Espin Pedrol | 1303577 | 2021-02-18 16:07:06 +0100 | [diff] [blame] | 883 | private function f_ms_gtfi_tmpl(inout GprsMS ms) |
| 884 | runs on MS_BTS_IFACE_CT return template (present) GlobalTfi { |
| 885 | var template (present) GlobalTfi gtfi; |
| 886 | if (ispresent(ms.ul_tbf) and ispresent(ms.dl_tbf)) { |
| 887 | gtfi := ({ is_dl_tfi := false, tfi := ms.ul_tbf.tfi }, |
| 888 | { is_dl_tfi := true, tfi := ms.dl_tbf.tfi }); |
| 889 | } else if (ispresent(ms.ul_tbf)) { |
| 890 | gtfi := { is_dl_tfi := false, tfi := ms.ul_tbf.tfi }; |
| 891 | } else if (ispresent(ms.dl_tbf)) { |
| 892 | gtfi := { is_dl_tfi := true, tfi := ms.dl_tbf.tfi }; |
| 893 | } else { |
| 894 | gtfi := ?; |
| 895 | } |
| 896 | return gtfi; |
| 897 | } |
| 898 | |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 899 | altstep as_ms_rx_pkt_neighbor_cell_data(inout GprsMS ms, octetstring exp_si, |
| 900 | inout uint5_t exp_container_idx /* := 0 */, |
| 901 | inout integer si_offset /* := 0 */, |
Pau Espin Pedrol | 0d6ebb7 | 2021-02-11 14:53:24 +0100 | [diff] [blame] | 902 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 903 | boolean single_step := false) |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 904 | runs on MS_BTS_IFACE_CT { |
| 905 | var integer len; |
| 906 | var octetstring exp_si_chunk; |
Pau Espin Pedrol | 1303577 | 2021-02-18 16:07:06 +0100 | [diff] [blame] | 907 | var template (present) GlobalTfi gtfi := f_ms_gtfi_tmpl(ms); |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 908 | var BTS_PDTCH_Block data_msg; |
| 909 | var boolean do_repeat := true; |
| 910 | |
| 911 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 912 | tr_RLCMAC_DL_CTRL(?, tr_RlcMacDlCtrl_PKT_NEIGH_CELL_DATA(gtfi, exp_container_idx)) |
| 913 | )) -> value data_msg { |
| 914 | |
| 915 | var PacketNeighbourCellData neigh_data := data_msg.dl_block.ctrl.payload.u.neighbour_cell_data; |
| 916 | var PacketNeighbourCellDataContainer cont := neigh_data.container_list[0]; |
| 917 | |
| 918 | if (cont.cd_length == 31) { /* continues on next message */ |
| 919 | len := lengthof(cont.container_data); |
| 920 | exp_si_chunk := substr(exp_si, si_offset, len); |
| 921 | if (cont.container_data != exp_si_chunk) { |
| 922 | setverdict(fail, "Rx unexpected SI chunk at offset ", si_offset, ": ", |
| 923 | cont.container_data, " vs exp ", exp_si_chunk); |
| 924 | f_shutdown(__BFILE__, __LINE__); |
| 925 | } |
| 926 | si_offset := si_offset + len; |
| 927 | } else if (cont.cd_length == 0) { |
| 928 | /* we are done */ |
| 929 | if (si_offset != lengthof(exp_si)) { |
| 930 | setverdict(fail, "Rx unexpectd SI length ", si_offset, |
| 931 | " vs exp ", lengthof(exp_si)); |
| 932 | f_shutdown(__BFILE__, __LINE__); |
| 933 | } |
| 934 | do_repeat := false; |
| 935 | } else { /* data length, last message */ |
| 936 | len := cont.cd_length; |
| 937 | exp_si_chunk := substr(exp_si, si_offset, len); |
| 938 | if (cont.container_data != exp_si_chunk) { |
| 939 | setverdict(fail, "Rx unexpected SI chunk at offset ", si_offset, ": ", |
| 940 | cont.container_data, " vs exp ", exp_si_chunk); |
| 941 | f_shutdown(__BFILE__, __LINE__); |
| 942 | } |
| 943 | si_offset := si_offset + len; |
| 944 | /* we are done */ |
| 945 | if (si_offset != lengthof(exp_si)) { |
| 946 | setverdict(fail, "Rx unexpectd SI length ", si_offset, |
| 947 | " vs exp ", lengthof(exp_si)); |
| 948 | f_shutdown(__BFILE__, __LINE__); |
| 949 | } |
| 950 | do_repeat := false; |
| 951 | } |
| 952 | |
| 953 | exp_container_idx := exp_container_idx + 1; |
| 954 | |
Pau Espin Pedrol | 0d6ebb7 | 2021-02-11 14:53:24 +0100 | [diff] [blame] | 955 | if (not single_step and do_repeat) { |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 956 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 957 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 958 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 959 | block_nr := nr.blk_nr)); |
| 960 | repeat; |
| 961 | } |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | /* Handle groups of PKT NEIGHBOUR CELL DATA packets */ |
Pau Espin Pedrol | 0d6ebb7 | 2021-02-11 14:53:24 +0100 | [diff] [blame] | 966 | function f_ms_handle_pkt_neighbor_cell_data(inout GprsMS ms, octetstring exp_si, |
| 967 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 968 | uint5_t exp_container_idx := 0, |
| 969 | integer si_offset := 0, |
| 970 | boolean single_step := false) |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 971 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 972 | var BTS_PDTCH_Block data_msg; |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 973 | |
| 974 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 975 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 976 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 977 | block_nr := nr.blk_nr)); |
| 978 | alt { |
| 979 | [exp_container_idx == 0] as_ms_rx_ignore_dummy(ms, nr); |
Vadim Yanitskiy | 7031893 | 2022-10-05 02:04:25 +0700 | [diff] [blame] | 980 | [exp_container_idx > 0] as_rx_fail_dummy(nr); |
| 981 | [] as_ms_rx_pkt_neighbor_cell_data(ms, exp_si, exp_container_idx, si_offset, nr, single_step); |
| 982 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 983 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 984 | tr_RLCMAC_DL_CTRL(?, ?))) -> value data_msg { |
| 985 | var GlobalTfi gtfi := { is_dl_tfi := false, tfi := ms.ul_tbf.tfi }; |
| 986 | setverdict(fail, "Rx unexpected DL block: ", data_msg.dl_block, " vs exp ", |
| 987 | tr_RLCMAC_DL_CTRL(?, tr_RlcMacDlCtrl_PKT_NEIGH_CELL_DATA(gtfi, exp_container_idx))); |
| 988 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 989 | } |
| 990 | }; |
| 991 | |
| 992 | return; |
| 993 | } |
| 994 | |
Pau Espin Pedrol | 7e50fa2 | 2023-06-26 16:50:22 +0200 | [diff] [blame] | 995 | /* Keep receiving & discarding DL blocks until the PCU requests USF for this MS */ |
| 996 | function f_ms_wait_usf(inout GprsMS ms, template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 997 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 998 | var BTS_PDTCH_Block data_msg; |
| 999 | |
| 1000 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 1001 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 1002 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 1003 | block_nr := nr.blk_nr)); |
| 1004 | alt { |
| 1005 | [] as_pcuif_rx_ignore_empty(nr); |
| 1006 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 1007 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 1008 | ?)) -> value data_msg { |
| 1009 | var uint3_t rx_usf := f_rlcmac_dl_block_get_usf(data_msg.dl_block); |
| 1010 | var uint3_t exp_usf := ms.ul_tbf.usf[valueof(nr.ts_nr)]; |
| 1011 | log("Rx DL block USF ", rx_usf, " vs exp USF ", exp_usf); |
| 1012 | if (rx_usf != exp_usf) { |
| 1013 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 1014 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 1015 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 1016 | block_nr := nr.blk_nr)); |
| 1017 | repeat; |
| 1018 | } |
| 1019 | } |
| 1020 | }; |
| 1021 | |
| 1022 | return data_msg.raw.fn; |
| 1023 | } |
| 1024 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 1025 | //////////////////////// |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1026 | // Low level APIs |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 1027 | //////////////////////// |
| 1028 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1029 | altstep as_rx_ptcch(out BTS_PTCCH_Block ret_msg, template (present) PTCCHDownlinkMsg msg := ?, |
| 1030 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, boolean do_repeat := false) |
| 1031 | runs on MS_BTS_IFACE_CT { |
| 1032 | [] BTS.receive(tr_PCUIF_DATA_PTCCH(nr.bts_nr, |
| 1033 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PTCCH), |
| 1034 | msg)) -> value ret_msg { |
| 1035 | if (do_repeat) { |
| 1036 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 1037 | sapi := PCU_IF_SAPI_PTCCH, fn := 0, |
| 1038 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 1039 | block_nr := nr.blk_nr)) |
| 1040 | repeat; |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | altstep as_ms_rx_imm_ass(template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH, |
| 1046 | template GsmRrMessage t_imm_ass := ?, |
| 1047 | template (present) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 1048 | out GsmRrMessage rr_imm_ass) |
| 1049 | runs on MS_BTS_IFACE_CT { |
| 1050 | var BTS_CCCH_Block data_msg; |
| 1051 | [] BTS.receive(tr_PCUIF_DATA_RR(nr.bts_nr, |
| 1052 | tr_PCUIF_DATA(nr.trx_nr, 0, sapi := sapi), |
| 1053 | t_imm_ass)) -> value data_msg { |
| 1054 | rr_imm_ass := data_msg.rr_msg; |
| 1055 | log("Rx Immediate Assignment: ", rr_imm_ass); |
| 1056 | /* Send DATA.cnf back to the IUT (only needed for PCH) */ |
| 1057 | if (data_msg.raw.sapi == PCU_IF_SAPI_PCH) { |
| 1058 | f_pcuif_tx_data_cnf(data_msg); |
| 1059 | } |
| 1060 | setverdict(pass); |
| 1061 | } |
| 1062 | } |
| 1063 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1064 | 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] | 1065 | template GsmRrMessage t_imm_ass := ?, |
| 1066 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1067 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 1068 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1069 | timer T; |
| 1070 | |
| 1071 | T.start(2.0); |
| 1072 | alt { |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1073 | [] as_ms_rx_imm_ass(sapi, t_imm_ass, nr, rr_imm_ass); |
| 1074 | [] BTS.receive { repeat; } /* TODO: use as_ms_rx_ignore_dummy instead? */ |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1075 | [] T.timeout { |
| 1076 | setverdict(fail, "Timeout waiting for Immediate Assignment"); |
Pau Espin Pedrol | fddc20b | 2020-05-28 19:50:29 +0700 | [diff] [blame] | 1077 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1081 | return rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /* 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] | 1085 | const BIT8 chan_req_def := '01111000'B; /* 01111 { 0xx | x0x | xx0 } */ |
| 1086 | /* Single block (two phase or RR signalling) packet access */ |
| 1087 | const BIT8 chan_req_sb := '01110000'B; /* 01110xxx */ |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1088 | |
| 1089 | /* Establish an Uplink TBF by sending RACH.ind towards the PCU */ |
Vadim Yanitskiy | 28d18e1 | 2020-05-29 15:25:59 +0700 | [diff] [blame] | 1090 | function f_pcuif_tx_rach_rx_imm_ass(uint16_t ra := bit2int(chan_req_def), |
| 1091 | uint8_t is_11bit := 0, |
| 1092 | PCUIF_BurstType burst_type := BURST_TYPE_0, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1093 | TimingAdvance ta := 0, |
| 1094 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1095 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1096 | var uint32_t fn; |
| 1097 | |
| 1098 | /* FIXME: ask the BTS component to give us the current TDMA fn */ |
| 1099 | fn := 1337 + ta; |
| 1100 | |
| 1101 | /* Send RACH.ind */ |
| 1102 | log("Sending RACH.ind on fn=", fn, " with RA=", ra, ", TA=", ta); |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1103 | 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] | 1104 | ra := ra, is_11bit := is_11bit, |
| 1105 | burst_type := burst_type, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 1106 | fn := fn, arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1107 | qta := ta * 4)); |
| 1108 | |
| 1109 | /* 3GPP TS 44.018, table 9.1.8.1, note 2b: Request Reference shall be set to 127 |
| 1110 | * when Immediate Assignment is triggered by EGPRS Packet Channel Request. Here |
| 1111 | * we assume that 11 bit RA always contains EGPRS Packet Channel Request. */ |
| 1112 | if (is_11bit != 0) { ra := 127; } |
| 1113 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1114 | /* Expect Immediate (TBF) Assignment on the same TS/TRX/BTS */ |
| 1115 | 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] | 1116 | } |
| 1117 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1118 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 474ec92 | 2021-05-26 13:34:49 +0200 | [diff] [blame] | 1119 | function f_pcuif_tx_data_ind(octetstring data, uint32_t fn := 0, |
| 1120 | TimingAdvance ta := 0, int16_t lqual_cb := 0, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1121 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1122 | runs on MS_BTS_IFACE_CT { |
| 1123 | var template RAW_PCU_EventParam ev_param := {tdma_fn := ? }; |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1124 | 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] | 1125 | sapi := PCU_IF_SAPI_PDTCH, data := data, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 1126 | fn := fn, arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
Vadim Yanitskiy | 474ec92 | 2021-05-26 13:34:49 +0200 | [diff] [blame] | 1127 | ta_offs_qbits := ta * 4, lqual_cb := lqual_cb)); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1128 | if (fn != 0) { |
| 1129 | ev_param := {tdma_fn := fn }; |
| 1130 | } |
| 1131 | BTS.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_SENT, ev_param)); |
| 1132 | } |
| 1133 | |
| 1134 | /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */ |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1135 | function f_pcuif_rx_data_req_pdtch(out BTS_PDTCH_Block data_msg, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1136 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1137 | runs on MS_BTS_IFACE_CT { |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1138 | 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] | 1139 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 1140 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), block_nr := nr.blk_nr)); |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1141 | |
| 1142 | BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 1143 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), *) |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1144 | ) -> value data_msg; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1147 | /* Expect a Paging Request Type 1 from PCU on PCUIF on specified sapi. */ |
| 1148 | function f_pcuif_rx_pch_pag_req1(template MobileIdentityV mi1 := ?, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1149 | template integer pag_group := ?, |
| 1150 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1151 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 1152 | var GsmRrMessage rr_pag_req1; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1153 | var octetstring imsi_suff_octstr; |
| 1154 | var integer pag_group_rx; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1155 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1156 | var BTS_CCCH_Block data_msg; |
| 1157 | BTS.receive(tr_PCUIF_DATA_RR(nr.bts_nr, |
| 1158 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PCH), |
| 1159 | tr_PAG_REQ1(tr_MI_LV(mi1)))) -> value data_msg; |
| 1160 | rr_pag_req1 := data_msg.rr_msg; |
| 1161 | log("Rx Paging Request Type1: ", rr_pag_req1); |
| 1162 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1163 | |
| 1164 | /* First 3 bytes contain IMSI suffix to calculate paging group: */ |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1165 | imsi_suff_octstr := substr(data_msg.raw.data, 0, 3); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1166 | pag_group_rx := str2int(oct2char(imsi_suff_octstr[0])) * 100 + |
| 1167 | str2int(oct2char(imsi_suff_octstr[1])) * 10 + |
| 1168 | str2int(oct2char(imsi_suff_octstr[2])); |
| 1169 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1170 | /* Make sure that received paging froup matches the expected one */ |
| 1171 | if (not match(pag_group_rx, pag_group)) { |
| 1172 | setverdict(fail, "Paging group", pag_group_rx, " does not match expected ", pag_group); |
| 1173 | f_shutdown(__BFILE__, __LINE__); |
| 1174 | } |
| 1175 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1176 | /* Send DATA.cnf back to the IUT (only needed for PCH) */ |
| 1177 | f_pcuif_tx_data_cnf(data_msg); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1178 | return rr_pag_req1; |
| 1179 | } |
| 1180 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1181 | function f_rx_rlcmac_dl_block(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 1182 | template (present) CodingScheme exp_cs_mcs := ?, |
| 1183 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1184 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1185 | var BTS_PDTCH_Block data_msg; |
| 1186 | f_pcuif_rx_data_req_pdtch(data_msg, nr := nr); |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 1187 | |
| 1188 | if (data_msg.dl_block == omit) { |
| 1189 | setverdict(fail, "Expected RLCMAC block but received idle block (", data_msg.raw.len, ")"); |
| 1190 | f_shutdown(__BFILE__, __LINE__); |
| 1191 | } |
| 1192 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1193 | dl_block := data_msg.dl_block; |
| 1194 | dl_fn := data_msg.raw.fn; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1195 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1196 | var integer len := lengthof(data_msg.raw.data); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1197 | var CodingScheme cs_mcs := f_rlcmac_block_len2cs_mcs(len) |
| 1198 | if (not match(f_rlcmac_block_len2cs_mcs(len), exp_cs_mcs)) { |
| 1199 | setverdict(fail, "Failed to match Coding Scheme exp ", exp_cs_mcs, " vs ", cs_mcs, " (", len, ")"); |
| 1200 | f_shutdown(__BFILE__, __LINE__); |
| 1201 | } |
| 1202 | } |
| 1203 | |
Pau Espin Pedrol | cdbe903 | 2020-07-07 20:20:42 +0200 | [diff] [blame] | 1204 | function f_rx_rlcmac_dl_block_exp_ack_nack(out RlcmacDlBlock dl_block, out uint32_t poll_fn, |
| 1205 | template RlcmacDlBlock acknack_tmpl := (tr_RLCMAC_UL_ACK_NACK_GPRS(ul_tfi := ?), |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1206 | tr_RLCMAC_UL_ACK_NACK_EGPRS(ul_tfi := ?)), |
| 1207 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1208 | runs on MS_BTS_IFACE_CT { |
| 1209 | var uint32_t dl_fn; |
| 1210 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1211 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | cdbe903 | 2020-07-07 20:20:42 +0200 | [diff] [blame] | 1212 | if (match(dl_block, acknack_tmpl)) { |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 1213 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 1214 | return; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1215 | } |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 1216 | setverdict(fail, "Failed to match Packet Uplink ACK / NACK:", dl_block); |
| 1217 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1220 | function f_rx_rlcmac_dl_block_exp_dummy(out RlcmacDlBlock dl_block, |
| 1221 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 0b6b0d0 | 2022-10-25 21:21:02 +0200 | [diff] [blame] | 1222 | runs on MS_BTS_IFACE_CT return uint32_t { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1223 | var uint32_t dl_fn; |
| 1224 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1225 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Vadim Yanitskiy | 7179d3e | 2022-10-04 03:27:29 +0700 | [diff] [blame] | 1226 | if (not match(dl_block, tr_RLCMAC_DL_DUMMY_CTRL())) { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1227 | setverdict(fail, "Failed to match Packet DUMMY DL"); |
| 1228 | f_shutdown(__BFILE__, __LINE__); |
| 1229 | } |
Pau Espin Pedrol | 0b6b0d0 | 2022-10-25 21:21:02 +0200 | [diff] [blame] | 1230 | return dl_fn; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
Pau Espin Pedrol | e3e2bf6 | 2022-11-29 14:32:48 +0100 | [diff] [blame] | 1233 | /* Keep getting dl_block until first non RLCMAC Dummy is received, then return it */ |
| 1234 | function f_rx_rlcmac_dl_block_skip_dummy(out RlcmacDlBlock dl_block, |
| 1235 | integer max_dummy := -1, |
| 1236 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 1237 | runs on MS_BTS_IFACE_CT return uint32_t { |
Pau Espin Pedrol | c8b7327 | 2023-05-15 16:20:12 +0200 | [diff] [blame] | 1238 | var integer i := 0; |
Pau Espin Pedrol | e3e2bf6 | 2022-11-29 14:32:48 +0100 | [diff] [blame] | 1239 | var uint32_t dl_fn; |
| 1240 | |
| 1241 | while (true) { |
| 1242 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
| 1243 | if (not match(dl_block, tr_RLCMAC_DL_DUMMY_CTRL)) { |
| 1244 | /* Received first data, starting processing: */ |
| 1245 | break; |
| 1246 | } |
| 1247 | i := i + 1; |
| 1248 | if (max_dummy >= 0 and i > max_dummy) { |
| 1249 | setverdict(fail, "Didn't receive DL data after receiving ", i, " dummy blocks"); |
| 1250 | f_shutdown(__BFILE__, __LINE__); |
| 1251 | break; |
| 1252 | } |
| 1253 | } |
| 1254 | return dl_fn; |
| 1255 | } |
| 1256 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1257 | function f_rx_rlcmac_dl_block_exp_pkt_pag_req(out RlcmacDlBlock dl_block, |
| 1258 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1259 | runs on MS_BTS_IFACE_CT { |
| 1260 | var uint32_t dl_fn; |
| 1261 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1262 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1263 | if (not match(dl_block, tr_RLCMAC_PACKET_PAG_REQ())) { |
| 1264 | setverdict(fail, "Failed to match Packet Paging Request: ", dl_block, " vs ", tr_RLCMAC_PACKET_PAG_REQ()); |
| 1265 | f_shutdown(__BFILE__, __LINE__); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /* This function does what could probably be done with templates */ |
| 1270 | function f_rlcmac_dl_block_verify_data_gprs(in RlcmacDlDataBlock data_block, |
| 1271 | template (present) octetstring data := ?, |
| 1272 | template (present) uint7_t exp_bsn := ?, |
| 1273 | template (present) CodingScheme exp_cs := ?) |
| 1274 | runs on MS_BTS_IFACE_CT { |
| 1275 | if (not match(data_block.mac_hdr.hdr_ext.bsn, exp_bsn)) { |
| 1276 | setverdict(fail, "DL block BSN doesn't match: ", |
| 1277 | data_block.mac_hdr.hdr_ext.bsn, " vs exp ", exp_bsn); |
Pau Espin Pedrol | e582f20 | 2020-11-13 11:50:09 +0100 | [diff] [blame] | 1278 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | if (lengthof(data_block.blocks) < 1) { |
| 1282 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 1283 | f_shutdown(__BFILE__, __LINE__); |
| 1284 | } |
| 1285 | |
| 1286 | if (not match(data_block.blocks[0].payload, data)) { |
| 1287 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 1288 | data_block.blocks[0].payload, " vs ", data); |
| 1289 | f_shutdown(__BFILE__, __LINE__); |
| 1290 | } |
| 1291 | |
Pau Espin Pedrol | e5e64c1 | 2020-11-03 17:36:30 +0100 | [diff] [blame] | 1292 | if (not match(data_block.cs, exp_cs)) { |
| 1293 | setverdict(fail, "Failed to match ", data_block.cs, " vs exp ", exp_cs); |
| 1294 | f_shutdown(__BFILE__, __LINE__); |
| 1295 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | /* This function does what could probably be done with templates */ |
| 1299 | function f_rlcmac_dl_block_verify_data_egprs(in RlcmacDlEgprsDataBlock data_block, |
| 1300 | template (present) octetstring data := ?, |
| 1301 | template (present) uint14_t exp_bsn := ?, |
| 1302 | template (present) CodingScheme exp_cs := ?) |
| 1303 | runs on MS_BTS_IFACE_CT { |
| 1304 | if (not match(data_block.mac_hdr.bsn1, exp_bsn)) { |
| 1305 | setverdict(fail, "DL block BSN doesn't match: ", |
| 1306 | data_block.mac_hdr.bsn1, " vs exp ", exp_bsn); |
| 1307 | } |
| 1308 | |
| 1309 | if (lengthof(data_block.blocks) < 1) { |
| 1310 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 1311 | f_shutdown(__BFILE__, __LINE__); |
| 1312 | } |
| 1313 | |
| 1314 | if (not match(data_block.blocks[0].payload, data)) { |
| 1315 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 1316 | data_block.blocks[0].payload, " vs ", data); |
| 1317 | f_shutdown(__BFILE__, __LINE__); |
| 1318 | } |
| 1319 | |
Pau Espin Pedrol | e5e64c1 | 2020-11-03 17:36:30 +0100 | [diff] [blame] | 1320 | if (not match(data_block.mcs, exp_cs)) { |
| 1321 | setverdict(fail, "Failed to match ", data_block.mcs, " vs exp ", exp_cs); |
| 1322 | f_shutdown(__BFILE__, __LINE__); |
| 1323 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1324 | } |
| 1325 | |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 1326 | /* High level (task specific) helper for matching GPRS/EGPRS data blocks */ |
| 1327 | function f_rlcmac_dl_block_exp_data(in RlcmacDlBlock dl_block, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1328 | template (present) octetstring data := ?, |
| 1329 | template (present) uint7_t exp_bsn := ?, |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 1330 | template (present) CodingScheme exp_cs := ?) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1331 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1332 | /* Make sure it's either GPRS or EGPRS data block */ |
| 1333 | if (not match(dl_block, tr_RLCMAC_DATA)) { |
| 1334 | setverdict(fail, "Failed to match DL DATA: ", dl_block, " vs ", tr_RLCMAC_DATA); |
| 1335 | f_shutdown(__BFILE__, __LINE__); |
| 1336 | } |
| 1337 | |
| 1338 | if (ischosen(dl_block.data_egprs)) { |
| 1339 | f_rlcmac_dl_block_verify_data_egprs(dl_block.data_egprs, data, exp_bsn, exp_cs); |
| 1340 | } else if (ischosen(dl_block.data)) { |
| 1341 | f_rlcmac_dl_block_verify_data_gprs(dl_block.data, data, exp_bsn, exp_cs); |
| 1342 | } else { |
| 1343 | /* Should not happen, but the caller may theoretically give us a template for CTRL */ |
| 1344 | setverdict(fail, "DL block is neither GPRS nor EGPRS data block: ", dl_block); |
| 1345 | f_shutdown(__BFILE__, __LINE__); |
| 1346 | } |
| 1347 | } |
| 1348 | |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 1349 | /* High level (task specific) helper for receiving and matching GPRS/EGPRS data blocks */ |
| 1350 | function f_rx_rlcmac_dl_block_exp_data(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 1351 | template (present) octetstring data := ?, |
| 1352 | template (present) uint7_t exp_bsn := ?, |
| 1353 | template (present) CodingScheme exp_cs := ?, |
| 1354 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 1355 | runs on MS_BTS_IFACE_CT { |
| 1356 | /* FIXME: ideally we should use an alt statement with timeout here, rather than |
| 1357 | * having +100500 layers of abstraction. This would facilitate developing the |
| 1358 | * multi-TBF/-TRX/-BTS tests, where you cannot expect that the first received |
| 1359 | * block is exactly what you need. */ |
| 1360 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
| 1361 | |
| 1362 | f_rlcmac_dl_block_exp_data(dl_block, data, exp_bsn, exp_cs); |
| 1363 | } |
| 1364 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1365 | function f_dl_block_ack_fn(in RlcmacDlBlock dl_block, uint32_t dl_fn) |
| 1366 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 1367 | var boolean rrbp_valid; |
| 1368 | var MacRrbp rrbp; |
| 1369 | |
| 1370 | /* The argument must be either a GPRS or EGPRS data block */ |
| 1371 | if (ischosen(dl_block.data_egprs)) { |
Pau Espin Pedrol | aa0d7cc | 2020-11-12 21:05:11 +0100 | [diff] [blame] | 1372 | rrbp_valid := dl_block.data_egprs.mac_hdr.esp != '00'B; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1373 | rrbp := dl_block.data_egprs.mac_hdr.rrbp; |
| 1374 | } else if (ischosen(dl_block.data)) { |
| 1375 | rrbp_valid := dl_block.data.mac_hdr.mac_hdr.rrbp_valid; |
| 1376 | rrbp := dl_block.data.mac_hdr.mac_hdr.rrbp; |
| 1377 | } else { |
| 1378 | rrbp_valid := dl_block.ctrl.mac_hdr.rrbp_valid; |
| 1379 | rrbp := dl_block.ctrl.mac_hdr.rrbp; |
| 1380 | } |
| 1381 | |
| 1382 | /* Make sure that the given block really needs to be ACKnowledged */ |
| 1383 | if (not rrbp_valid) { |
| 1384 | setverdict(fail, "DL block shall not be ACKnowledged, field RRBP is not valid"); |
| 1385 | f_shutdown(__BFILE__, __LINE__); |
| 1386 | } |
| 1387 | |
| 1388 | return f_rrbp_ack_fn(dl_fn, rrbp); |
| 1389 | } |
| 1390 | |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 1391 | function f_dl_block_rrbp_valid(in RlcmacDlBlock dl_block) |
| 1392 | runs on MS_BTS_IFACE_CT return boolean { |
| 1393 | if (ischosen(dl_block.data_egprs)) { |
| 1394 | return dl_block.data_egprs.mac_hdr.esp != '00'B; |
| 1395 | } else if (ischosen(dl_block.data)) { |
| 1396 | return dl_block.data.mac_hdr.mac_hdr.rrbp_valid; |
| 1397 | } else { |
| 1398 | return dl_block.ctrl.mac_hdr.rrbp_valid; |
| 1399 | } |
| 1400 | } |
| 1401 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1402 | /* Return true if a given Packet Paging Request contains the given IMSI, false otherwise */ |
Pau Espin Pedrol | 1b31ba4 | 2021-02-05 12:41:58 +0100 | [diff] [blame] | 1403 | function f_pkt_paging_match_imsi(in PacketPagingReq req, template (present) hexstring imsi, |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1404 | boolean cs_domain := true, boolean ps_domain := true) |
| 1405 | runs on MS_BTS_IFACE_CT return boolean { |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1406 | if (not ispresent(req.repeated_pageinfo)) { |
| 1407 | setverdict(fail, "Packet Paging Request without MIs?!?"); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1408 | f_shutdown(__BFILE__, __LINE__); |
| 1409 | } |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1410 | |
| 1411 | for (var integer i := 0; i < lengthof(req.repeated_pageinfo); i := i + 1) { |
| 1412 | var PageInfo info := req.repeated_pageinfo[i].item; |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1413 | var MobileIdentityLV_Paging mi_lv; |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1414 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1415 | if (ischosen(info.cs)) { /* CS domain */ |
| 1416 | if (not ispresent(info.cs.mobile_identity)) |
| 1417 | { continue; } |
| 1418 | if (not cs_domain) |
| 1419 | { continue; } |
| 1420 | mi_lv := info.cs.mobile_identity; |
| 1421 | } else { /* PS domain */ |
| 1422 | if (not ispresent(info.ps.mobile_identity)) |
| 1423 | { continue; } |
| 1424 | if (not ps_domain) |
| 1425 | { continue; } |
| 1426 | mi_lv := info.ps.mobile_identity; |
| 1427 | } |
| 1428 | |
| 1429 | /* Make sure MI contains IMSI before referencing it */ |
| 1430 | if (match(mi_lv.mobile_id, decmatch tr_MI_IMSI(imsi))) { |
| 1431 | return true; |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1435 | return false; |
| 1436 | } |
| 1437 | |
| 1438 | /* Return true if a given Packet Paging Request contains the given P-TMSI, false otherwise */ |
| 1439 | function f_pkt_paging_match_tmsi(in PacketPagingReq req, template GsmTmsi tmsi, |
| 1440 | boolean cs_domain := true, boolean ps_domain := true) |
| 1441 | runs on MS_BTS_IFACE_CT return boolean { |
| 1442 | if (not ispresent(req.repeated_pageinfo)) { |
| 1443 | setverdict(fail, "Packet Paging Request without MIs?!?"); |
| 1444 | f_shutdown(__BFILE__, __LINE__); |
| 1445 | } |
| 1446 | |
| 1447 | for (var integer i := 0; i < lengthof(req.repeated_pageinfo); i := i + 1) { |
| 1448 | var PageInfo info := req.repeated_pageinfo[i].item; |
| 1449 | |
| 1450 | if (cs_domain and ischosen(info.cs)) { |
| 1451 | if (not ispresent(info.cs.tmsi)) |
| 1452 | { continue; } |
| 1453 | if (match(info.cs.tmsi, tmsi)) |
| 1454 | { return true; } |
| 1455 | } else if (ps_domain) { |
| 1456 | if (not ispresent(info.ps.ptmsi)) |
| 1457 | { continue; } |
| 1458 | if (match(info.ps.ptmsi, tmsi)) |
| 1459 | { return true; } |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | return false; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | } |