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