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 | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 631 | function f_ms_exp_dl_tbf_ass_ccch(inout GprsMS ms, template PCUIF_Sapi sapi := PCU_IF_SAPI_PCH_2, |
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 | |
Pau Espin Pedrol | bd849cc | 2023-07-28 14:54:46 +0200 | [diff] [blame] | 672 | function f_ms_tx_ul_data_blocks_gprs(inout GprsMS ms, template (value) LlcBlocks blocks, |
| 673 | uint4_t cv := 15, boolean with_tlli := false, uint32_t fn := 0, |
| 674 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 675 | runs on MS_BTS_IFACE_CT { |
| 676 | var template (value) RlcmacUlBlock ul_data; |
| 677 | |
| 678 | ul_data := t_RLCMAC_UL_DATA(cs := ms.ul_tbf.tx_cs_mcs, |
| 679 | tfi := ms.ul_tbf.tfi, |
| 680 | cv := cv, |
| 681 | bsn := ms.ul_tbf.bsn, |
| 682 | blocks := blocks); |
| 683 | if (with_tlli) { |
| 684 | ul_data.data.mac_hdr.tlli_ind := true; |
| 685 | ul_data.data.tlli := ms.tlli; |
| 686 | } |
| 687 | f_ultbf_inc_bsn(ms.ul_tbf); |
| 688 | f_ms_tx_ul_block(ms, ul_data, fn, nr := nr); |
| 689 | } |
| 690 | |
| 691 | function f_ms_tx_ul_data_blocks_egprs(inout GprsMS ms, template (value) EgprsLlcBlocks blocks, |
| 692 | uint4_t cv := 15, boolean with_tlli := false, uint32_t fn := 0, |
| 693 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 694 | runs on MS_BTS_IFACE_CT { |
| 695 | var template (value) RlcmacUlBlock ul_data; |
| 696 | |
| 697 | ul_data := t_RLCMAC_UL_EGPRS_DATA(mcs := ms.ul_tbf.tx_cs_mcs, |
| 698 | tfi := ms.ul_tbf.tfi, |
| 699 | cv := cv, |
| 700 | bsn1 := ms.ul_tbf.bsn, |
| 701 | bsn2_offset := 0, |
| 702 | blocks := blocks); |
| 703 | if (with_tlli) { |
| 704 | ul_data.data_egprs.tlli_ind := true; |
| 705 | ul_data.data_egprs.tlli := ms.tlli; |
| 706 | } |
| 707 | f_ultbf_inc_bsn(ms.ul_tbf); |
| 708 | f_ms_tx_ul_block(ms, ul_data, fn, nr := nr); |
| 709 | } |
| 710 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 711 | function f_ms_tx_ul_data_block(inout GprsMS ms, octetstring payload, |
| 712 | uint4_t cv := 15, boolean with_tlli := false, uint32_t fn := 0, |
| 713 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 714 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 715 | var template (value) RlcmacUlBlock ul_data; |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 716 | |
| 717 | if (f_rlcmac_cs_mcs_is_mcs(ms.ul_tbf.tx_cs_mcs)) { |
Pau Espin Pedrol | bd849cc | 2023-07-28 14:54:46 +0200 | [diff] [blame] | 718 | f_ms_tx_ul_data_blocks_egprs(ms, {t_RLCMAC_LLCBLOCK_EGPRS(payload)}, cv, with_tlli, fn, nr) |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 719 | } else { |
Pau Espin Pedrol | bd849cc | 2023-07-28 14:54:46 +0200 | [diff] [blame] | 720 | f_ms_tx_ul_data_blocks_gprs(ms, {t_RLCMAC_LLCBLOCK(payload)}, cv, with_tlli, fn, nr); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 721 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /* 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] | 725 | 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] | 726 | uint32_t fn := 0, template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 727 | runs on MS_BTS_IFACE_CT return octetstring { |
| 728 | var octetstring total_payload := ''O; |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 729 | 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] | 730 | |
| 731 | for (var integer i := 0; i < num_blocks; i := i + 1) { |
Pau Espin Pedrol | cb00c52 | 2020-11-06 19:52:05 +0100 | [diff] [blame] | 732 | var octetstring payload := f_rnd_octstring(payload_fill_len); |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 733 | /* Prepare a new UL block (CV, random payload) */ |
| 734 | var integer cv := num_blocks - i - 1; |
| 735 | if (cv > g_bs_cv_max) { |
| 736 | cv := 15; |
| 737 | } |
Pau Espin Pedrol | dee5570 | 2021-04-23 21:08:22 +0200 | [diff] [blame] | 738 | if (i == 1) { |
| 739 | /* We use FN on i=0 to jump to wanted FN time, then simply submit on next |
| 740 | * available frame (fn=0) */ |
| 741 | fn := 0; |
| 742 | } |
| 743 | 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] | 744 | total_payload := total_payload & payload; |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 745 | } |
| 746 | return total_payload; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | function f_rlcmac_dl_block_get_tfi(RlcmacDlBlock dl_block) |
| 750 | runs on MS_BTS_IFACE_CT return uint5_t { |
| 751 | if (ischosen(dl_block.data)) { |
| 752 | return dl_block.data.mac_hdr.hdr_ext.tfi; |
| 753 | } else if (ischosen(dl_block.data_egprs)) { |
| 754 | return dl_block.data_egprs.mac_hdr.tfi; |
| 755 | } else { /* Ctrl block */ |
| 756 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(tr_DynamicAllocation(?))))) { |
| 757 | return dl_block.ctrl.payload.u.ul_assignment.gprs.dyn_block_alloc.ul_tfi_assignment; |
| 758 | } |
| 759 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(tr_DynamicAllocation(?))))) { |
| 760 | return dl_block.ctrl.payload.u.ul_assignment.egprs.dyn_block_alloc.ul_tfi_assignment; |
| 761 | } |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 762 | if (match(dl_block, tr_RLCMAC_DL_PACKET_ASS(?))) { |
| 763 | return dl_block.ctrl.payload.u.dl_assignment.dl_tfi_assignment; |
| 764 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 765 | } |
| 766 | setverdict(fail, "DlBlock doesn't contain a TFI:", dl_block); |
| 767 | f_shutdown(__BFILE__, __LINE__); |
| 768 | return 0; /* make compiler happy */ |
| 769 | } |
| 770 | |
Pau Espin Pedrol | f30fa1d | 2021-03-03 19:55:11 +0100 | [diff] [blame] | 771 | function f_rlcmac_dl_block_get_usf(RlcmacDlBlock dl_block) |
| 772 | runs on MS_BTS_IFACE_CT return uint3_t { |
| 773 | if (ischosen(dl_block.data)) { |
| 774 | return dl_block.data.mac_hdr.mac_hdr.usf; |
| 775 | } else if (ischosen(dl_block.data_egprs)) { |
| 776 | return dl_block.data_egprs.mac_hdr.usf; |
| 777 | } else { /* Ctrl block */ |
| 778 | return dl_block.ctrl.mac_hdr.usf; |
| 779 | } |
| 780 | setverdict(fail, "DlBlock doesn't contain a USF:", dl_block); |
| 781 | f_shutdown(__BFILE__, __LINE__); |
| 782 | return 0; /* make compiler happy */ |
| 783 | } |
| 784 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 785 | /* Get the Chan coding command from a dl block containing PACCH UL Assignment */ |
| 786 | function f_rlcmac_dl_block_get_assigned_ul_cs_mcs(RlcmacDlBlock dl_block) |
| 787 | runs on MS_BTS_IFACE_CT return CodingScheme { |
| 788 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_GPRS(?, tr_PktUlAssGprsDynamic(?)))) { |
| 789 | return f_rlcmac_block_ChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.gprs.ch_coding_cmd); |
| 790 | } |
| 791 | if (match(dl_block, tr_RLCMAC_UL_PACKET_ASS_EGPRS(?, tr_PktUlAssEgprsDynamic(?)))) { |
| 792 | return f_rlcmac_block_EgprsChCodingCommand2cs_mcs(dl_block.ctrl.payload.u.ul_assignment.egprs.chan_coding_cmd); |
| 793 | } |
| 794 | setverdict(fail, "DlBlock doesn't contain CS_MCS information:", dl_block); |
| 795 | f_shutdown(__BFILE__, __LINE__); |
| 796 | return CS_1; /* make compiler happy */ |
| 797 | } |
| 798 | |
| 799 | /* TS 44.060 sec 12.3 Ack/Nack Description */ |
| 800 | function f_acknackdesc_ack_block(inout AckNackDescription desc, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 801 | { |
| 802 | var uint7_t bsn; |
| 803 | var integer i; |
| 804 | var integer inc; |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 805 | bsn := dl_block.data.mac_hdr.hdr_ext.bsn; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 806 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 807 | /* Filling hole? */ |
| 808 | if (bsn < desc.starting_seq_nr) { |
| 809 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr - bsn)] := int2bit(1, 1); |
| 810 | return; |
| 811 | } |
Pau Espin Pedrol | 9a2d61b | 2020-11-05 17:59:16 +0100 | [diff] [blame] | 812 | /* Filling hole, wraparound: */ |
| 813 | if (bsn - desc.starting_seq_nr > lengthof(desc.receive_block_bitmap)) { |
| 814 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - (desc.starting_seq_nr + (218 - bsn))] := int2bit(1, 1); |
| 815 | return; |
| 816 | } |
| 817 | |
| 818 | inc := bsn - desc.starting_seq_nr + 1; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 819 | |
| 820 | /* SSN is increased, and so RBB values need to be moved */ |
| 821 | for (i := 0; i < lengthof(desc.receive_block_bitmap) - inc; i := i+1) { |
| 822 | desc.receive_block_bitmap[i] := desc.receive_block_bitmap[i + inc]; |
| 823 | } |
| 824 | for (i := lengthof(desc.receive_block_bitmap) - inc; i < lengthof(desc.receive_block_bitmap) - 1; i := i+1) { |
| 825 | desc.receive_block_bitmap[i] := int2bit(0, 1); |
| 826 | } |
| 827 | /* Now we can set current bit and update SSN */ |
Pau Espin Pedrol | 9a2d61b | 2020-11-05 17:59:16 +0100 | [diff] [blame] | 828 | desc.starting_seq_nr := (bsn + 1) mod 128; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 829 | desc.receive_block_bitmap[lengthof(desc.receive_block_bitmap) - 1] := int2bit(1, 1); |
| 830 | |
| 831 | /* Finally update the final_ack bit as requested: */ |
| 832 | desc.final_ack := final_ack; |
| 833 | } |
| 834 | |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 835 | /* TS 44.060 sec 12.3 Ack/Nack Description */ |
| 836 | function f_egprs_acknackdesc_ack_block(inout EgprsAckNackDescription desc, RlcmacDlBlock dl_block, BIT1 final_ack := '0'B) |
| 837 | { |
| 838 | var uint11_t bsn; |
| 839 | var integer i; |
| 840 | var integer inc; |
| 841 | var integer n := 0; |
| 842 | var integer v_q := (desc.starting_seq_nr + 2047) mod 2048; /* SSN = V(Q) + 1 */ |
| 843 | |
| 844 | bsn := dl_block.data_egprs.mac_hdr.bsn1; |
| 845 | |
| 846 | /* Repetition? */ |
| 847 | if (bsn < v_q) { |
| 848 | /* Filling hole, wraparound: */ |
| 849 | if (bsn - v_q > lengthof(desc.urbb)) { |
| 850 | desc.urbb[lengthof(desc.urbb) - (v_q + (2048 - bsn))] := int2bit(1, 1); |
| 851 | return; |
| 852 | } |
| 853 | return; |
| 854 | } |
| 855 | |
| 856 | inc := bsn - v_q + 1; |
| 857 | desc.urbb[lengthof(desc.urbb) - inc] := int2bit(1, 1); |
| 858 | |
| 859 | for (i := lengthof(desc.urbb) - 1; i >= lengthof(desc.urbb) - inc; i := i - 1) { |
| 860 | if (desc.urbb[i] == '0'B) { |
| 861 | break; |
| 862 | } |
| 863 | n := n + 1; |
| 864 | } |
| 865 | |
| 866 | if (n > 0) { |
| 867 | /* SSN is increased, and so RBB values need to be moved */ |
| 868 | for (i := lengthof(desc.urbb) - 1; i >= n; i := i - 1) { |
| 869 | desc.urbb[i] := desc.urbb[i - n]; |
| 870 | } |
| 871 | for (i := n - 1; i >= 0; i := i - 1) { |
| 872 | desc.urbb[i] := int2bit(0, 1); |
| 873 | } |
| 874 | |
| 875 | desc.starting_seq_nr := (desc.starting_seq_nr + n) mod 2048; |
| 876 | } |
| 877 | |
| 878 | /* Finally update the final_ack bit as requested: */ |
| 879 | desc.final_ack := final_ack; |
| 880 | } |
| 881 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 882 | /* This function can be used to send DATA.cnf in response to the IUT originated DATA.req. */ |
| 883 | 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] | 884 | runs on MS_BTS_IFACE_CT { |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 885 | var PCUIF_data_cnf cnf := { |
| 886 | sapi := data_msg.raw.sapi, |
| 887 | msg_id := data_msg.msg_id |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 888 | }; |
| 889 | |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 890 | var PCUIF_Message pcu_msg_cnf := { |
| 891 | msg_type := PCU_IF_MSG_DATA_CNF_2, |
| 892 | bts_nr := data_msg.bts_nr, |
| 893 | spare := '0000'O, |
| 894 | u := { data_cnf2 := cnf} |
| 895 | }; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 896 | |
| 897 | BTS.send(pcu_msg_cnf); |
| 898 | } |
| 899 | |
Pau Espin Pedrol | 1303577 | 2021-02-18 16:07:06 +0100 | [diff] [blame] | 900 | private function f_ms_gtfi_tmpl(inout GprsMS ms) |
| 901 | runs on MS_BTS_IFACE_CT return template (present) GlobalTfi { |
| 902 | var template (present) GlobalTfi gtfi; |
| 903 | if (ispresent(ms.ul_tbf) and ispresent(ms.dl_tbf)) { |
| 904 | gtfi := ({ is_dl_tfi := false, tfi := ms.ul_tbf.tfi }, |
| 905 | { is_dl_tfi := true, tfi := ms.dl_tbf.tfi }); |
| 906 | } else if (ispresent(ms.ul_tbf)) { |
| 907 | gtfi := { is_dl_tfi := false, tfi := ms.ul_tbf.tfi }; |
| 908 | } else if (ispresent(ms.dl_tbf)) { |
| 909 | gtfi := { is_dl_tfi := true, tfi := ms.dl_tbf.tfi }; |
| 910 | } else { |
| 911 | gtfi := ?; |
| 912 | } |
| 913 | return gtfi; |
| 914 | } |
| 915 | |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 916 | altstep as_ms_rx_pkt_neighbor_cell_data(inout GprsMS ms, octetstring exp_si, |
| 917 | inout uint5_t exp_container_idx /* := 0 */, |
| 918 | inout integer si_offset /* := 0 */, |
Pau Espin Pedrol | 0d6ebb7 | 2021-02-11 14:53:24 +0100 | [diff] [blame] | 919 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 920 | boolean single_step := false) |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 921 | runs on MS_BTS_IFACE_CT { |
| 922 | var integer len; |
| 923 | var octetstring exp_si_chunk; |
Pau Espin Pedrol | 1303577 | 2021-02-18 16:07:06 +0100 | [diff] [blame] | 924 | var template (present) GlobalTfi gtfi := f_ms_gtfi_tmpl(ms); |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 925 | var BTS_PDTCH_Block data_msg; |
| 926 | var boolean do_repeat := true; |
| 927 | |
| 928 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 929 | tr_RLCMAC_DL_CTRL(?, tr_RlcMacDlCtrl_PKT_NEIGH_CELL_DATA(gtfi, exp_container_idx)) |
| 930 | )) -> value data_msg { |
| 931 | |
| 932 | var PacketNeighbourCellData neigh_data := data_msg.dl_block.ctrl.payload.u.neighbour_cell_data; |
| 933 | var PacketNeighbourCellDataContainer cont := neigh_data.container_list[0]; |
| 934 | |
| 935 | if (cont.cd_length == 31) { /* continues on next message */ |
| 936 | len := lengthof(cont.container_data); |
| 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 | } else if (cont.cd_length == 0) { |
| 945 | /* we are done */ |
| 946 | if (si_offset != lengthof(exp_si)) { |
| 947 | setverdict(fail, "Rx unexpectd SI length ", si_offset, |
| 948 | " vs exp ", lengthof(exp_si)); |
| 949 | f_shutdown(__BFILE__, __LINE__); |
| 950 | } |
| 951 | do_repeat := false; |
| 952 | } else { /* data length, last message */ |
| 953 | len := cont.cd_length; |
| 954 | exp_si_chunk := substr(exp_si, si_offset, len); |
| 955 | if (cont.container_data != exp_si_chunk) { |
| 956 | setverdict(fail, "Rx unexpected SI chunk at offset ", si_offset, ": ", |
| 957 | cont.container_data, " vs exp ", exp_si_chunk); |
| 958 | f_shutdown(__BFILE__, __LINE__); |
| 959 | } |
| 960 | si_offset := si_offset + len; |
| 961 | /* we are done */ |
| 962 | if (si_offset != lengthof(exp_si)) { |
| 963 | setverdict(fail, "Rx unexpectd SI length ", si_offset, |
| 964 | " vs exp ", lengthof(exp_si)); |
| 965 | f_shutdown(__BFILE__, __LINE__); |
| 966 | } |
| 967 | do_repeat := false; |
| 968 | } |
| 969 | |
| 970 | exp_container_idx := exp_container_idx + 1; |
| 971 | |
Pau Espin Pedrol | 0d6ebb7 | 2021-02-11 14:53:24 +0100 | [diff] [blame] | 972 | if (not single_step and do_repeat) { |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 973 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 974 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 975 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 976 | block_nr := nr.blk_nr)); |
| 977 | repeat; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | /* Handle groups of PKT NEIGHBOUR CELL DATA packets */ |
Pau Espin Pedrol | 0d6ebb7 | 2021-02-11 14:53:24 +0100 | [diff] [blame] | 983 | function f_ms_handle_pkt_neighbor_cell_data(inout GprsMS ms, octetstring exp_si, |
| 984 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 985 | uint5_t exp_container_idx := 0, |
| 986 | integer si_offset := 0, |
| 987 | boolean single_step := false) |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 988 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 989 | var BTS_PDTCH_Block data_msg; |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 990 | |
| 991 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 992 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 993 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 994 | block_nr := nr.blk_nr)); |
| 995 | alt { |
| 996 | [exp_container_idx == 0] as_ms_rx_ignore_dummy(ms, nr); |
Vadim Yanitskiy | 7031893 | 2022-10-05 02:04:25 +0700 | [diff] [blame] | 997 | [exp_container_idx > 0] as_rx_fail_dummy(nr); |
| 998 | [] as_ms_rx_pkt_neighbor_cell_data(ms, exp_si, exp_container_idx, si_offset, nr, single_step); |
| 999 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 1000 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 1001 | tr_RLCMAC_DL_CTRL(?, ?))) -> value data_msg { |
| 1002 | var GlobalTfi gtfi := { is_dl_tfi := false, tfi := ms.ul_tbf.tfi }; |
| 1003 | setverdict(fail, "Rx unexpected DL block: ", data_msg.dl_block, " vs exp ", |
| 1004 | tr_RLCMAC_DL_CTRL(?, tr_RlcMacDlCtrl_PKT_NEIGH_CELL_DATA(gtfi, exp_container_idx))); |
| 1005 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | 6cb71cc | 2021-02-11 13:54:01 +0100 | [diff] [blame] | 1006 | } |
| 1007 | }; |
| 1008 | |
| 1009 | return; |
| 1010 | } |
| 1011 | |
Pau Espin Pedrol | 7e50fa2 | 2023-06-26 16:50:22 +0200 | [diff] [blame] | 1012 | /* Keep receiving & discarding DL blocks until the PCU requests USF for this MS */ |
| 1013 | function f_ms_wait_usf(inout GprsMS ms, template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 1014 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 1015 | var BTS_PDTCH_Block data_msg; |
| 1016 | |
| 1017 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 1018 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 1019 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 1020 | block_nr := nr.blk_nr)); |
| 1021 | alt { |
| 1022 | [] as_pcuif_rx_ignore_empty(nr); |
| 1023 | [] BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
| 1024 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PDTCH), |
| 1025 | ?)) -> value data_msg { |
| 1026 | var uint3_t rx_usf := f_rlcmac_dl_block_get_usf(data_msg.dl_block); |
| 1027 | var uint3_t exp_usf := ms.ul_tbf.usf[valueof(nr.ts_nr)]; |
| 1028 | log("Rx DL block USF ", rx_usf, " vs exp USF ", exp_usf); |
| 1029 | if (rx_usf != exp_usf) { |
| 1030 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 1031 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
| 1032 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 1033 | block_nr := nr.blk_nr)); |
| 1034 | repeat; |
| 1035 | } |
| 1036 | } |
| 1037 | }; |
| 1038 | |
| 1039 | return data_msg.raw.fn; |
| 1040 | } |
| 1041 | |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 1042 | //////////////////////// |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1043 | // Low level APIs |
Pau Espin Pedrol | 4f7b8fd | 2020-05-18 18:28:17 +0200 | [diff] [blame] | 1044 | //////////////////////// |
| 1045 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1046 | altstep as_rx_ptcch(out BTS_PTCCH_Block ret_msg, template (present) PTCCHDownlinkMsg msg := ?, |
| 1047 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum, boolean do_repeat := false) |
| 1048 | runs on MS_BTS_IFACE_CT { |
| 1049 | [] BTS.receive(tr_PCUIF_DATA_PTCCH(nr.bts_nr, |
| 1050 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PTCCH), |
| 1051 | msg)) -> value ret_msg { |
| 1052 | if (do_repeat) { |
| 1053 | BTS.send(ts_PCUIF_RTS_REQ(nr.bts_nr, nr.trx_nr, nr.ts_nr, |
| 1054 | sapi := PCU_IF_SAPI_PTCCH, fn := 0, |
| 1055 | arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
| 1056 | block_nr := nr.blk_nr)) |
| 1057 | repeat; |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 1062 | altstep as_ms_rx_imm_ass(template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH_2, |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1063 | template GsmRrMessage t_imm_ass := ?, |
| 1064 | template (present) TsTrxBtsNum nr := ts_TsTrxBtsNum, |
| 1065 | out GsmRrMessage rr_imm_ass) |
| 1066 | runs on MS_BTS_IFACE_CT { |
| 1067 | var BTS_CCCH_Block data_msg; |
| 1068 | [] BTS.receive(tr_PCUIF_DATA_RR(nr.bts_nr, |
| 1069 | tr_PCUIF_DATA(nr.trx_nr, 0, sapi := sapi), |
| 1070 | t_imm_ass)) -> value data_msg { |
| 1071 | rr_imm_ass := data_msg.rr_msg; |
| 1072 | log("Rx Immediate Assignment: ", rr_imm_ass); |
| 1073 | /* Send DATA.cnf back to the IUT (only needed for PCH) */ |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 1074 | f_pcuif_tx_data_cnf(data_msg); |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1075 | setverdict(pass); |
| 1076 | } |
| 1077 | } |
| 1078 | |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 1079 | function f_pcuif_rx_imm_ass(template PCUIF_Sapi sapi := PCU_IF_SAPI_AGCH_2, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1080 | template GsmRrMessage t_imm_ass := ?, |
| 1081 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1082 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 1083 | var GsmRrMessage rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1084 | timer T; |
| 1085 | |
| 1086 | T.start(2.0); |
| 1087 | alt { |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1088 | [] as_ms_rx_imm_ass(sapi, t_imm_ass, nr, rr_imm_ass); |
| 1089 | [] BTS.receive { repeat; } /* TODO: use as_ms_rx_ignore_dummy instead? */ |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1090 | [] T.timeout { |
| 1091 | setverdict(fail, "Timeout waiting for Immediate Assignment"); |
Pau Espin Pedrol | fddc20b | 2020-05-28 19:50:29 +0700 | [diff] [blame] | 1092 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1096 | return rr_imm_ass; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /* 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] | 1100 | const BIT8 chan_req_def := '01111000'B; /* 01111 { 0xx | x0x | xx0 } */ |
| 1101 | /* Single block (two phase or RR signalling) packet access */ |
| 1102 | const BIT8 chan_req_sb := '01110000'B; /* 01110xxx */ |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1103 | |
| 1104 | /* Establish an Uplink TBF by sending RACH.ind towards the PCU */ |
Vadim Yanitskiy | 28d18e1 | 2020-05-29 15:25:59 +0700 | [diff] [blame] | 1105 | function f_pcuif_tx_rach_rx_imm_ass(uint16_t ra := bit2int(chan_req_def), |
| 1106 | uint8_t is_11bit := 0, |
| 1107 | PCUIF_BurstType burst_type := BURST_TYPE_0, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1108 | TimingAdvance ta := 0, |
| 1109 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Vadim Yanitskiy | 7466c33 | 2020-05-28 20:41:19 +0700 | [diff] [blame] | 1110 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1111 | var uint32_t fn; |
| 1112 | |
| 1113 | /* FIXME: ask the BTS component to give us the current TDMA fn */ |
| 1114 | fn := 1337 + ta; |
| 1115 | |
| 1116 | /* Send RACH.ind */ |
| 1117 | log("Sending RACH.ind on fn=", fn, " with RA=", ra, ", TA=", ta); |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1118 | 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] | 1119 | ra := ra, is_11bit := is_11bit, |
| 1120 | burst_type := burst_type, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 1121 | fn := fn, arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1122 | qta := ta * 4)); |
| 1123 | |
| 1124 | /* 3GPP TS 44.018, table 9.1.8.1, note 2b: Request Reference shall be set to 127 |
| 1125 | * when Immediate Assignment is triggered by EGPRS Packet Channel Request. Here |
| 1126 | * we assume that 11 bit RA always contains EGPRS Packet Channel Request. */ |
| 1127 | if (is_11bit != 0) { ra := 127; } |
| 1128 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1129 | /* Expect Immediate (TBF) Assignment on the same TS/TRX/BTS */ |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 1130 | return f_pcuif_rx_imm_ass(PCU_IF_SAPI_AGCH_2, tr_IMM_TBF_ASS(false, ra, fn), nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1133 | /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */ |
Vadim Yanitskiy | 474ec92 | 2021-05-26 13:34:49 +0200 | [diff] [blame] | 1134 | function f_pcuif_tx_data_ind(octetstring data, uint32_t fn := 0, |
| 1135 | TimingAdvance ta := 0, int16_t lqual_cb := 0, |
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 { |
| 1138 | var template RAW_PCU_EventParam ev_param := {tdma_fn := ? }; |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1139 | 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] | 1140 | sapi := PCU_IF_SAPI_PDTCH, data := data, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 1141 | fn := fn, arfcn := f_trxnr2arfcn(valueof(nr.trx_nr)), |
Vadim Yanitskiy | 474ec92 | 2021-05-26 13:34:49 +0200 | [diff] [blame] | 1142 | ta_offs_qbits := ta * 4, lqual_cb := lqual_cb)); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1143 | if (fn != 0) { |
| 1144 | ev_param := {tdma_fn := fn }; |
| 1145 | } |
| 1146 | BTS.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_SENT, ev_param)); |
| 1147 | } |
| 1148 | |
| 1149 | /* 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] | 1150 | 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] | 1151 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1152 | runs on MS_BTS_IFACE_CT { |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1153 | 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] | 1154 | sapi := PCU_IF_SAPI_PDTCH, fn := 0, |
Pau Espin Pedrol | 2aead38 | 2020-10-29 20:46:47 +0100 | [diff] [blame] | 1155 | 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] | 1156 | |
| 1157 | BTS.receive(tr_PCUIF_DATA_PDTCH(nr.bts_nr, |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 1158 | 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] | 1159 | ) -> value data_msg; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1160 | } |
| 1161 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1162 | /* Expect a Paging Request Type 1 from PCU on PCUIF on specified sapi. */ |
| 1163 | function f_pcuif_rx_pch_pag_req1(template MobileIdentityV mi1 := ?, |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1164 | template integer pag_group := ?, |
| 1165 | template (present) TsTrxBtsNum nr := tr_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1166 | runs on MS_BTS_IFACE_CT return GsmRrMessage { |
| 1167 | var GsmRrMessage rr_pag_req1; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1168 | var octetstring imsi_suff_octstr; |
| 1169 | var integer pag_group_rx; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1170 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1171 | var BTS_CCCH_Block data_msg; |
| 1172 | BTS.receive(tr_PCUIF_DATA_RR(nr.bts_nr, |
Philipp Maier | 4222f47 | 2023-08-22 17:28:00 +0200 | [diff] [blame] | 1173 | tr_PCUIF_DATA(nr.trx_nr, nr.ts_nr, sapi := PCU_IF_SAPI_PCH_2), |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1174 | tr_PAG_REQ1(tr_MI_LV(mi1)))) -> value data_msg; |
| 1175 | rr_pag_req1 := data_msg.rr_msg; |
| 1176 | log("Rx Paging Request Type1: ", rr_pag_req1); |
| 1177 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1178 | |
| 1179 | /* First 3 bytes contain IMSI suffix to calculate paging group: */ |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1180 | imsi_suff_octstr := substr(data_msg.raw.data, 0, 3); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1181 | pag_group_rx := str2int(oct2char(imsi_suff_octstr[0])) * 100 + |
| 1182 | str2int(oct2char(imsi_suff_octstr[1])) * 10 + |
| 1183 | str2int(oct2char(imsi_suff_octstr[2])); |
| 1184 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1185 | /* Make sure that received paging froup matches the expected one */ |
| 1186 | if (not match(pag_group_rx, pag_group)) { |
| 1187 | setverdict(fail, "Paging group", pag_group_rx, " does not match expected ", pag_group); |
| 1188 | f_shutdown(__BFILE__, __LINE__); |
| 1189 | } |
| 1190 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1191 | /* Send DATA.cnf back to the IUT (only needed for PCH) */ |
| 1192 | f_pcuif_tx_data_cnf(data_msg); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1193 | return rr_pag_req1; |
| 1194 | } |
| 1195 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1196 | function f_rx_rlcmac_dl_block(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 1197 | template (present) CodingScheme exp_cs_mcs := ?, |
| 1198 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1199 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1200 | var BTS_PDTCH_Block data_msg; |
| 1201 | f_pcuif_rx_data_req_pdtch(data_msg, nr := nr); |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 1202 | |
| 1203 | if (data_msg.dl_block == omit) { |
| 1204 | setverdict(fail, "Expected RLCMAC block but received idle block (", data_msg.raw.len, ")"); |
| 1205 | f_shutdown(__BFILE__, __LINE__); |
| 1206 | } |
| 1207 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1208 | dl_block := data_msg.dl_block; |
| 1209 | dl_fn := data_msg.raw.fn; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1210 | |
Pau Espin Pedrol | b34bb06 | 2021-01-19 18:58:07 +0100 | [diff] [blame] | 1211 | var integer len := lengthof(data_msg.raw.data); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1212 | var CodingScheme cs_mcs := f_rlcmac_block_len2cs_mcs(len) |
| 1213 | if (not match(f_rlcmac_block_len2cs_mcs(len), exp_cs_mcs)) { |
| 1214 | setverdict(fail, "Failed to match Coding Scheme exp ", exp_cs_mcs, " vs ", cs_mcs, " (", len, ")"); |
| 1215 | f_shutdown(__BFILE__, __LINE__); |
| 1216 | } |
| 1217 | } |
| 1218 | |
Pau Espin Pedrol | cdbe903 | 2020-07-07 20:20:42 +0200 | [diff] [blame] | 1219 | function f_rx_rlcmac_dl_block_exp_ack_nack(out RlcmacDlBlock dl_block, out uint32_t poll_fn, |
| 1220 | template RlcmacDlBlock acknack_tmpl := (tr_RLCMAC_UL_ACK_NACK_GPRS(ul_tfi := ?), |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1221 | tr_RLCMAC_UL_ACK_NACK_EGPRS(ul_tfi := ?)), |
| 1222 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1223 | runs on MS_BTS_IFACE_CT { |
| 1224 | var uint32_t dl_fn; |
| 1225 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1226 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | cdbe903 | 2020-07-07 20:20:42 +0200 | [diff] [blame] | 1227 | if (match(dl_block, acknack_tmpl)) { |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 1228 | poll_fn := f_rrbp_ack_fn(dl_fn, dl_block.ctrl.mac_hdr.rrbp); |
| 1229 | return; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1230 | } |
Pau Espin Pedrol | 692222c | 2020-05-17 00:25:37 +0200 | [diff] [blame] | 1231 | setverdict(fail, "Failed to match Packet Uplink ACK / NACK:", dl_block); |
| 1232 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1235 | function f_rx_rlcmac_dl_block_exp_dummy(out RlcmacDlBlock dl_block, |
| 1236 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | 0b6b0d0 | 2022-10-25 21:21:02 +0200 | [diff] [blame] | 1237 | runs on MS_BTS_IFACE_CT return uint32_t { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1238 | var uint32_t dl_fn; |
| 1239 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1240 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Vadim Yanitskiy | 7179d3e | 2022-10-04 03:27:29 +0700 | [diff] [blame] | 1241 | if (not match(dl_block, tr_RLCMAC_DL_DUMMY_CTRL())) { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1242 | setverdict(fail, "Failed to match Packet DUMMY DL"); |
| 1243 | f_shutdown(__BFILE__, __LINE__); |
| 1244 | } |
Pau Espin Pedrol | 0b6b0d0 | 2022-10-25 21:21:02 +0200 | [diff] [blame] | 1245 | return dl_fn; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
Pau Espin Pedrol | e3e2bf6 | 2022-11-29 14:32:48 +0100 | [diff] [blame] | 1248 | /* Keep getting dl_block until first non RLCMAC Dummy is received, then return it */ |
| 1249 | function f_rx_rlcmac_dl_block_skip_dummy(out RlcmacDlBlock dl_block, |
| 1250 | integer max_dummy := -1, |
| 1251 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 1252 | runs on MS_BTS_IFACE_CT return uint32_t { |
Pau Espin Pedrol | c8b7327 | 2023-05-15 16:20:12 +0200 | [diff] [blame] | 1253 | var integer i := 0; |
Pau Espin Pedrol | e3e2bf6 | 2022-11-29 14:32:48 +0100 | [diff] [blame] | 1254 | var uint32_t dl_fn; |
| 1255 | |
| 1256 | while (true) { |
| 1257 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
| 1258 | if (not match(dl_block, tr_RLCMAC_DL_DUMMY_CTRL)) { |
| 1259 | /* Received first data, starting processing: */ |
| 1260 | break; |
| 1261 | } |
| 1262 | i := i + 1; |
| 1263 | if (max_dummy >= 0 and i > max_dummy) { |
| 1264 | setverdict(fail, "Didn't receive DL data after receiving ", i, " dummy blocks"); |
| 1265 | f_shutdown(__BFILE__, __LINE__); |
| 1266 | break; |
| 1267 | } |
| 1268 | } |
| 1269 | return dl_fn; |
| 1270 | } |
| 1271 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1272 | function f_rx_rlcmac_dl_block_exp_pkt_pag_req(out RlcmacDlBlock dl_block, |
| 1273 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1274 | runs on MS_BTS_IFACE_CT { |
| 1275 | var uint32_t dl_fn; |
| 1276 | |
Vadim Yanitskiy | 4b7473d | 2020-09-21 04:15:39 +0700 | [diff] [blame] | 1277 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1278 | if (not match(dl_block, tr_RLCMAC_PACKET_PAG_REQ())) { |
| 1279 | setverdict(fail, "Failed to match Packet Paging Request: ", dl_block, " vs ", tr_RLCMAC_PACKET_PAG_REQ()); |
| 1280 | f_shutdown(__BFILE__, __LINE__); |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /* This function does what could probably be done with templates */ |
| 1285 | function f_rlcmac_dl_block_verify_data_gprs(in RlcmacDlDataBlock data_block, |
| 1286 | template (present) octetstring data := ?, |
| 1287 | template (present) uint7_t exp_bsn := ?, |
| 1288 | template (present) CodingScheme exp_cs := ?) |
| 1289 | runs on MS_BTS_IFACE_CT { |
| 1290 | if (not match(data_block.mac_hdr.hdr_ext.bsn, exp_bsn)) { |
| 1291 | setverdict(fail, "DL block BSN doesn't match: ", |
| 1292 | data_block.mac_hdr.hdr_ext.bsn, " vs exp ", exp_bsn); |
Pau Espin Pedrol | e582f20 | 2020-11-13 11:50:09 +0100 | [diff] [blame] | 1293 | f_shutdown(__BFILE__, __LINE__); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | if (lengthof(data_block.blocks) < 1) { |
| 1297 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 1298 | f_shutdown(__BFILE__, __LINE__); |
| 1299 | } |
| 1300 | |
| 1301 | if (not match(data_block.blocks[0].payload, data)) { |
| 1302 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 1303 | data_block.blocks[0].payload, " vs ", data); |
| 1304 | f_shutdown(__BFILE__, __LINE__); |
| 1305 | } |
| 1306 | |
Pau Espin Pedrol | e5e64c1 | 2020-11-03 17:36:30 +0100 | [diff] [blame] | 1307 | if (not match(data_block.cs, exp_cs)) { |
| 1308 | setverdict(fail, "Failed to match ", data_block.cs, " vs exp ", exp_cs); |
| 1309 | f_shutdown(__BFILE__, __LINE__); |
| 1310 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | /* This function does what could probably be done with templates */ |
| 1314 | function f_rlcmac_dl_block_verify_data_egprs(in RlcmacDlEgprsDataBlock data_block, |
| 1315 | template (present) octetstring data := ?, |
| 1316 | template (present) uint14_t exp_bsn := ?, |
| 1317 | template (present) CodingScheme exp_cs := ?) |
| 1318 | runs on MS_BTS_IFACE_CT { |
| 1319 | if (not match(data_block.mac_hdr.bsn1, exp_bsn)) { |
| 1320 | setverdict(fail, "DL block BSN doesn't match: ", |
| 1321 | data_block.mac_hdr.bsn1, " vs exp ", exp_bsn); |
| 1322 | } |
| 1323 | |
| 1324 | if (lengthof(data_block.blocks) < 1) { |
| 1325 | setverdict(fail, "DL block has no LLC payload: ", data_block); |
| 1326 | f_shutdown(__BFILE__, __LINE__); |
| 1327 | } |
| 1328 | |
| 1329 | if (not match(data_block.blocks[0].payload, data)) { |
| 1330 | setverdict(fail, "Failed to match content of LLC payload in DL Block: ", |
| 1331 | data_block.blocks[0].payload, " vs ", data); |
| 1332 | f_shutdown(__BFILE__, __LINE__); |
| 1333 | } |
| 1334 | |
Pau Espin Pedrol | e5e64c1 | 2020-11-03 17:36:30 +0100 | [diff] [blame] | 1335 | if (not match(data_block.mcs, exp_cs)) { |
| 1336 | setverdict(fail, "Failed to match ", data_block.mcs, " vs exp ", exp_cs); |
| 1337 | f_shutdown(__BFILE__, __LINE__); |
| 1338 | } |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 1341 | /* High level (task specific) helper for matching GPRS/EGPRS data blocks */ |
| 1342 | function f_rlcmac_dl_block_exp_data(in RlcmacDlBlock dl_block, |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1343 | template (present) octetstring data := ?, |
| 1344 | template (present) uint7_t exp_bsn := ?, |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 1345 | template (present) CodingScheme exp_cs := ?) |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1346 | runs on MS_BTS_IFACE_CT { |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1347 | /* Make sure it's either GPRS or EGPRS data block */ |
| 1348 | if (not match(dl_block, tr_RLCMAC_DATA)) { |
| 1349 | setverdict(fail, "Failed to match DL DATA: ", dl_block, " vs ", tr_RLCMAC_DATA); |
| 1350 | f_shutdown(__BFILE__, __LINE__); |
| 1351 | } |
| 1352 | |
| 1353 | if (ischosen(dl_block.data_egprs)) { |
| 1354 | f_rlcmac_dl_block_verify_data_egprs(dl_block.data_egprs, data, exp_bsn, exp_cs); |
| 1355 | } else if (ischosen(dl_block.data)) { |
| 1356 | f_rlcmac_dl_block_verify_data_gprs(dl_block.data, data, exp_bsn, exp_cs); |
| 1357 | } else { |
| 1358 | /* Should not happen, but the caller may theoretically give us a template for CTRL */ |
| 1359 | setverdict(fail, "DL block is neither GPRS nor EGPRS data block: ", dl_block); |
| 1360 | f_shutdown(__BFILE__, __LINE__); |
| 1361 | } |
| 1362 | } |
| 1363 | |
Pau Espin Pedrol | 5d07ae6 | 2020-11-05 17:59:30 +0100 | [diff] [blame] | 1364 | /* High level (task specific) helper for receiving and matching GPRS/EGPRS data blocks */ |
| 1365 | function f_rx_rlcmac_dl_block_exp_data(out RlcmacDlBlock dl_block, out uint32_t dl_fn, |
| 1366 | template (present) octetstring data := ?, |
| 1367 | template (present) uint7_t exp_bsn := ?, |
| 1368 | template (present) CodingScheme exp_cs := ?, |
| 1369 | template (value) TsTrxBtsNum nr := ts_TsTrxBtsNum) |
| 1370 | runs on MS_BTS_IFACE_CT { |
| 1371 | /* FIXME: ideally we should use an alt statement with timeout here, rather than |
| 1372 | * having +100500 layers of abstraction. This would facilitate developing the |
| 1373 | * multi-TBF/-TRX/-BTS tests, where you cannot expect that the first received |
| 1374 | * block is exactly what you need. */ |
| 1375 | f_rx_rlcmac_dl_block(dl_block, dl_fn, nr := nr); |
| 1376 | |
| 1377 | f_rlcmac_dl_block_exp_data(dl_block, data, exp_bsn, exp_cs); |
| 1378 | } |
| 1379 | |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1380 | function f_dl_block_ack_fn(in RlcmacDlBlock dl_block, uint32_t dl_fn) |
| 1381 | runs on MS_BTS_IFACE_CT return uint32_t { |
| 1382 | var boolean rrbp_valid; |
| 1383 | var MacRrbp rrbp; |
| 1384 | |
| 1385 | /* The argument must be either a GPRS or EGPRS data block */ |
| 1386 | if (ischosen(dl_block.data_egprs)) { |
Pau Espin Pedrol | aa0d7cc | 2020-11-12 21:05:11 +0100 | [diff] [blame] | 1387 | rrbp_valid := dl_block.data_egprs.mac_hdr.esp != '00'B; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1388 | rrbp := dl_block.data_egprs.mac_hdr.rrbp; |
| 1389 | } else if (ischosen(dl_block.data)) { |
| 1390 | rrbp_valid := dl_block.data.mac_hdr.mac_hdr.rrbp_valid; |
| 1391 | rrbp := dl_block.data.mac_hdr.mac_hdr.rrbp; |
| 1392 | } else { |
| 1393 | rrbp_valid := dl_block.ctrl.mac_hdr.rrbp_valid; |
| 1394 | rrbp := dl_block.ctrl.mac_hdr.rrbp; |
| 1395 | } |
| 1396 | |
| 1397 | /* Make sure that the given block really needs to be ACKnowledged */ |
| 1398 | if (not rrbp_valid) { |
| 1399 | setverdict(fail, "DL block shall not be ACKnowledged, field RRBP is not valid"); |
| 1400 | f_shutdown(__BFILE__, __LINE__); |
| 1401 | } |
| 1402 | |
| 1403 | return f_rrbp_ack_fn(dl_fn, rrbp); |
| 1404 | } |
| 1405 | |
Pau Espin Pedrol | e8db673 | 2020-11-12 21:06:41 +0100 | [diff] [blame] | 1406 | function f_dl_block_rrbp_valid(in RlcmacDlBlock dl_block) |
| 1407 | runs on MS_BTS_IFACE_CT return boolean { |
| 1408 | if (ischosen(dl_block.data_egprs)) { |
| 1409 | return dl_block.data_egprs.mac_hdr.esp != '00'B; |
| 1410 | } else if (ischosen(dl_block.data)) { |
| 1411 | return dl_block.data.mac_hdr.mac_hdr.rrbp_valid; |
| 1412 | } else { |
| 1413 | return dl_block.ctrl.mac_hdr.rrbp_valid; |
| 1414 | } |
| 1415 | } |
| 1416 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1417 | /* 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] | 1418 | 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] | 1419 | boolean cs_domain := true, boolean ps_domain := true) |
| 1420 | runs on MS_BTS_IFACE_CT return boolean { |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1421 | if (not ispresent(req.repeated_pageinfo)) { |
| 1422 | setverdict(fail, "Packet Paging Request without MIs?!?"); |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1423 | f_shutdown(__BFILE__, __LINE__); |
| 1424 | } |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1425 | |
| 1426 | for (var integer i := 0; i < lengthof(req.repeated_pageinfo); i := i + 1) { |
| 1427 | var PageInfo info := req.repeated_pageinfo[i].item; |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1428 | var MobileIdentityLV_Paging mi_lv; |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1429 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1430 | if (ischosen(info.cs)) { /* CS domain */ |
| 1431 | if (not ispresent(info.cs.mobile_identity)) |
| 1432 | { continue; } |
| 1433 | if (not cs_domain) |
| 1434 | { continue; } |
| 1435 | mi_lv := info.cs.mobile_identity; |
| 1436 | } else { /* PS domain */ |
| 1437 | if (not ispresent(info.ps.mobile_identity)) |
| 1438 | { continue; } |
| 1439 | if (not ps_domain) |
| 1440 | { continue; } |
| 1441 | mi_lv := info.ps.mobile_identity; |
| 1442 | } |
| 1443 | |
| 1444 | /* Make sure MI contains IMSI before referencing it */ |
| 1445 | if (match(mi_lv.mobile_id, decmatch tr_MI_IMSI(imsi))) { |
| 1446 | return true; |
Vadim Yanitskiy | e94164d | 2020-10-31 05:46:03 +0700 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
Vadim Yanitskiy | 3e5f074 | 2020-11-01 03:30:18 +0700 | [diff] [blame] | 1450 | return false; |
| 1451 | } |
| 1452 | |
| 1453 | /* Return true if a given Packet Paging Request contains the given P-TMSI, false otherwise */ |
| 1454 | function f_pkt_paging_match_tmsi(in PacketPagingReq req, template GsmTmsi tmsi, |
| 1455 | boolean cs_domain := true, boolean ps_domain := true) |
| 1456 | runs on MS_BTS_IFACE_CT return boolean { |
| 1457 | if (not ispresent(req.repeated_pageinfo)) { |
| 1458 | setverdict(fail, "Packet Paging Request without MIs?!?"); |
| 1459 | f_shutdown(__BFILE__, __LINE__); |
| 1460 | } |
| 1461 | |
| 1462 | for (var integer i := 0; i < lengthof(req.repeated_pageinfo); i := i + 1) { |
| 1463 | var PageInfo info := req.repeated_pageinfo[i].item; |
| 1464 | |
| 1465 | if (cs_domain and ischosen(info.cs)) { |
| 1466 | if (not ispresent(info.cs.tmsi)) |
| 1467 | { continue; } |
| 1468 | if (match(info.cs.tmsi, tmsi)) |
| 1469 | { return true; } |
| 1470 | } else if (ps_domain) { |
| 1471 | if (not ispresent(info.ps.ptmsi)) |
| 1472 | { continue; } |
| 1473 | if (match(info.ps.ptmsi, tmsi)) |
| 1474 | { return true; } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | return false; |
Pau Espin Pedrol | aedc511 | 2020-05-16 17:30:42 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | } |