blob: 36b1f9d0fb55c125f006e96352e164b8244cbf92 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
3import from General_Types all;
4import from GSM_Types all;
5import from GSM_RR_Types all;
6import from Osmocom_Types all;
7import from GSM_Types all;
8import from GSM_RR_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +01009import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010010import from L1CTL_PortType all;
11import from L1CTL_Types all;
12import from LAPDm_Types all;
13import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020014import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010015
16import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010017import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010018import from IPA_Emulation all;
19import from RSL_Emulation all;
20
21import from IPL4asp_Types all;
22import from TRXC_Types all;
23import from TRXC_CodecPort all;
24import from TRXC_CodecPort_CtrlFunct all;
25
Harald Welte883340c2018-02-28 18:59:29 +010026import from PCUIF_Types all;
27import from PCUIF_CodecPort all;
28
Harald Welte7484fc42018-02-24 14:09:45 +010029import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010030import from MobileL3_RRM_Types all;
31import from MobileL3_Types all;
32import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010033
Harald Welte8da48242018-02-27 20:41:32 +010034import from Osmocom_VTY_Functions all;
35import from TELNETasp_PortType all;
36
Harald Welte70767382018-02-21 12:16:40 +010037/* The tests assume a BTS with the following timeslot configuration:
38 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020039 * TS1 : TCH/F
40 * TS2 : TCH/F
41 * TS3 : TCH/F_PDCH (IPA Style)
42 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010043 * TS5 : TCH/H
44 * TS6 : SDCCH/8
45 * TS7 : PDCH
46 */
47
48modulepar {
49 charstring mp_rsl_ip := "127.0.0.2";
50 integer mp_rsl_port := 3003;
51 integer mp_trx0_arfcn := 871;
Harald Weltea4d8f352018-03-01 15:47:20 +010052 charstring mp_bb_trxc_ip := "127.0.0.1";
Harald Welteef3e1c92018-02-28 23:40:14 +010053 integer mp_bb_trxc_port := 6701;
Harald Welte883340c2018-02-28 18:59:29 +010054 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Harald Welted5684392018-03-10 18:22:04 +010055 integer mp_tolerance_rxqual := 1;
56 integer mp_tolerance_rxlev := 3;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020057 charstring mp_ctrl_ip := "127.0.0.1";
58 integer mp_ctrl_port := 4238;
Harald Welte70767382018-02-21 12:16:40 +010059}
60
Harald Welte629cc6b2018-03-11 17:19:05 +010061type record of RslChannelNr ChannelNrs;
62
Harald Welte70767382018-02-21 12:16:40 +010063type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010064 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010065 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010066 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010067 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010068 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010069 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010070
71 /* L1CTL port (for classic tests) */
72 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010073
Harald Welte54a2a2d2018-02-26 09:14:05 +010074 /* TRXC port (for classic tests) */
75 port TRXC_CODEC_PT BB_TRXC;
76 var integer g_bb_trxc_conn_id;
77
Harald Welte8da48242018-02-27 20:41:32 +010078 port TELNETasp_PT BTSVTY;
79
Harald Welte883340c2018-02-28 18:59:29 +010080 /* PCU Interface of BTS */
81 port PCUIF_CODEC_PT PCU;
82 var integer g_pcu_conn_id;
83 /* Last PCU INFO IND we received */
84 var PCUIF_Message g_pcu_last_info;
85
Harald Welte48494ca2018-02-25 16:59:50 +010086 /* SI configuration */
87 var SystemInformationConfig si_cfg := {
88 bcch_extended := false,
89 si1_present := false,
90 si2bis_present := false,
91 si2ter_present := false,
92 si2quater_present := false,
93 si7_present := false,
94 si8_present := false,
95 si9_present := false,
96 si13_present := false,
97 si13alt_present := false,
98 si15_present := false,
99 si16_present := false,
100 si17_present := false,
101 si2n_present := false,
102 si21_present := false,
103 si22_present := false
104 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100105
106 /* all logical channels available on the BTS */
107 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100108 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100109}
110
111/* an individual call / channel */
112type component ConnHdlr extends RSL_DchanHdlr {
113 port L1CTL_PT L1CTL;
114
115 port TRXC_CODEC_PT BB_TRXC;
116 var integer g_bb_trxc_conn_id;
117
118 timer g_Tguard;
119 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
120
121 var ConnHdlrPars g_pars;
122 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100123 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200124
125 /* PCU Interface of BTS */
126 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100127}
128
129function f_init_rsl(charstring id) runs on test_CT {
130 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
131 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
132
133 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
134 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
135 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
136
137 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
138 vc_RSL.start(RSL_Emulation.main(false));
139}
140
141type record ConnHdlrPars {
142 RslChannelNr chan_nr,
143 RSL_IE_ChannelMode chan_mode,
144 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100145 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200146 TestSpecUnion spec optional,
147 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100148}
149
150/* Test-specific parameters */
151type union TestSpecUnion {
152 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100153}
154
Harald Welte82ccef72018-02-25 16:17:33 +0100155template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100156 max_retrans := RACH_MAX_RETRANS_7,
157 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100158 cell_barr_access := false,
159 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100160 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100161};
162
Harald Weltef10153f2018-02-25 16:34:05 +0100163template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100164 cell_resel_hyst_2dB := 2,
165 ms_txpwr_max_cch := 7,
Harald Weltef10153f2018-02-25 16:34:05 +0100166 acs := '0'B,
167 neci := true,
168 rxlev_access_min := 0
169}
170
171template (value) LocationAreaIdentification ts_LAI_default := {
172 mcc_mnc := '262F42'H,
173 lac := 42
174}
175
Harald Welte7484fc42018-02-24 14:09:45 +0100176/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100177template (value) SystemInformation ts_SI3_default := {
178 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100179 payload := {
180 si3 := {
181 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100182 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100183 ctrl_chan_desc := {
184 msc_r99 := true,
185 att := true,
186 bs_ag_blks_res := 1,
187 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100188 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100189 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
190 spare := '00'B,
191 bs_pa_mfrms := 0, /* 2 multiframes */
192 t3212 := 1 /* 6 minutes */
193 },
Harald Welte82ccef72018-02-25 16:17:33 +0100194 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100195 dn_ind := false,
196 pwrc := false,
197 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100198 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100199 },
Harald Weltef10153f2018-02-25 16:34:05 +0100200 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100201 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100202 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100203 }
204 }
205}
Harald Welte70767382018-02-21 12:16:40 +0100206
Harald Weltef8df4cb2018-03-10 15:15:08 +0100207template (value) SystemInformation ts_SI2_default := {
208 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100209 payload := {
210 si2 := {
211 bcch_freq_list := '00000000000000000000000000000000'O,
212 ncc_permitted := '11111111'B,
213 rach_control := ts_RachCtrl_default
214 }
215 }
216}
217
Harald Weltef8df4cb2018-03-10 15:15:08 +0100218template (value) SystemInformation ts_SI4_default := {
219 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100220 payload := {
221 si4 := {
222 lai := ts_LAI_default,
223 cell_sel_par := ts_CellSelPar_default,
224 rach_control := ts_RachCtrl_default,
225 cbch_chan_desc := omit,
226 cbch_mobile_alloc := omit,
227 rest_octets := ''O
228 }
229 }
230}
231
232function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
233runs on test_CT {
234 log("Setting ", rsl_si_type, ": ", si_enc);
235 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
236}
237
238function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
239runs on test_CT {
240 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
241 log("Setting ", rsl_si_type, ": ", si_dec);
242 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
243}
244
Harald Welte8da48242018-02-27 20:41:32 +0100245private function f_init_vty(charstring id) runs on test_CT {
246 map(self:BTSVTY, system:BTSVTY);
247 f_vty_set_prompts(BTSVTY);
248 f_vty_transceive(BTSVTY, "enable");
249}
250
Harald Welte883340c2018-02-28 18:59:29 +0100251/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200252private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
253 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100254 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200255 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
256 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100257 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200258 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Harald Welted378a252018-03-13 17:02:14 +0100259 setverdict(fail, "Invalid PCU Version/BTS Number received");
260 self.stop;
Harald Welte883340c2018-02-28 18:59:29 +0100261 }
262}
263
Harald Weltef26de0b2018-04-04 20:28:05 +0200264private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
265 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100266 timer T := 2.0;
267 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100268 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200269 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100270 return;
271 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200272 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100273
274 T.start;
275 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200276 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100277 [] T.timeout {
278 setverdict(fail, "Timeout waiting for PCU INFO_IND");
279 self.stop;
280 }
281 }
282}
283
Harald Welte70767382018-02-21 12:16:40 +0100284/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100285function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte83f6dbf2018-06-03 18:26:50 +0200286 timer T := 10.0;
Harald Welte629cc6b2018-03-11 17:19:05 +0100287 g_AllChannels := {
288 /* TS 1..4: TCH/F */
289 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
290 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
291 /* TS 5: TCH/H */
292 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
293 /* TS 0: SDCCH/4 */
294 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
295 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
296 /* TS 6: SDCCH/8 */
297 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
298 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
299 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
300 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
301 };
Harald Welte0472ab42018-03-12 15:02:26 +0100302 g_AllChanTypes := {
303 /* TS 1..4: TCH/F */
304 //valueof(ts_RslChanNr_Bm(1)),
305 /* TS 5: TCH/H */
306 //valueof(ts_RslChanNr_Lm(5,1)),
307 /* TS 0: SDCCH/4 */
308 valueof(ts_RslChanNr_SDCCH4(0,2)),
309 /* TS 6: SDCCH/8 */
310 valueof(ts_RslChanNr_SDCCH8(6,4))
311 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100312
Harald Welte70767382018-02-21 12:16:40 +0100313 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200314 T.start;
315 alt {
316 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
317 [] T.timeout {
318 setverdict(fail, "Timeout waiting for ASP_IPA_EVENT_UP");
319 self.stop;
320 }
321 }
Harald Welte2d142592018-02-25 13:19:44 +0100322 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100323 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200324 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100325
326 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100327 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
328 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
329 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
330 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100331
Harald Weltef26de0b2018-04-04 20:28:05 +0200332 map(self:PCU, system:PCU);
333 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100334
Harald Welte84271622018-03-10 17:21:03 +0100335 if (mp_bb_trxc_port != -1) {
336 var TrxcMessage ret;
337 /* start with a default moderate timing offset equalling TA=2 */
338 f_main_trxc_connect();
339 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
340 }
Harald Welte70767382018-02-21 12:16:40 +0100341}
342
Harald Welte294b0a22018-03-10 23:26:48 +0100343function f_shutdown() runs on test_CT {
344 /* shut down all "externally interfaced" components first to avoid unclean shutdown */
345 vc_IPA.stop;
346 vc_RSL.stop;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200347 f_ipa_ctrl_stop();
Harald Welte294b0a22018-03-10 23:26:48 +0100348}
349
Harald Welte68e495b2018-02-25 00:05:57 +0100350/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
351function f_init_l1ctl() runs on test_CT {
352 map(self:L1CTL, system:L1CTL);
353 f_connect_reset(L1CTL);
354}
355
Harald Welte70767382018-02-21 12:16:40 +0100356type function void_fn(charstring id) runs on ConnHdlr;
357
358/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200359function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100360runs on test_CT return ConnHdlr {
361 var charstring id := testcasename();
362 var ConnHdlr vc_conn;
363
364 vc_conn := ConnHdlr.create(id);
365 /* connect to RSL Emulation main component */
366 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
367 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200368 if (pcu_comp) {
369 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
370 * it from the test_CT and connect it to the component. This obviously only
371 * works for one component, i.e. no concurrency */
372 unmap(self:PCU, system:PCU);
373 map(vc_conn:PCU, system:PCU);
374 }
Harald Welte70767382018-02-21 12:16:40 +0100375
376 vc_conn.start(f_handler_init(fn, id, pars));
377 return vc_conn;
378}
379
Harald Welte7484fc42018-02-24 14:09:45 +0100380template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
381 streamId := sid,
382 rsl := rsl
383}
384
385template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
386 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
387 streamId := sid,
388 rsl := rsl
389}
390
Harald Welte70767382018-02-21 12:16:40 +0100391private altstep as_Tguard() runs on ConnHdlr {
392 [] g_Tguard.timeout {
393 setverdict(fail, "Tguard timeout");
394 self.stop;
395 }
396}
397
Harald Welte68e495b2018-02-25 00:05:57 +0100398private function f_l1_tune(L1CTL_PT L1CTL) {
Harald Welte70767382018-02-21 12:16:40 +0100399 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED);
400}
401
402private function f_trxc_connect() runs on ConnHdlr {
403 map(self:BB_TRXC, system:BB_TRXC);
404 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100405 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
406 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200407 if (not ispresent(res.connId)) {
408 setverdict(fail, "Could not connect to trx-control interface of trxcon, check your configuration");
409 self.stop;
410 }
Harald Welte70767382018-02-21 12:16:40 +0100411 g_bb_trxc_conn_id := res.connId;
412}
413
414private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100415 var TrxcMessage ret;
416 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100417}
418
419private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100420 var TrxcMessage ret;
421 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100422}
423
424/* first function started in ConnHdlr component */
425private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
426runs on ConnHdlr {
427 g_pars := pars;
428 g_chan_nr := pars.chan_nr;
429
430 map(self:L1CTL, system:L1CTL);
431 f_connect_reset(L1CTL);
432
Harald Welte84271622018-03-10 17:21:03 +0100433 if (mp_bb_trxc_port != -1) {
434 f_trxc_connect();
435 }
Harald Welte70767382018-02-21 12:16:40 +0100436
437 g_Tguard.start(pars.t_guard);
438 activate(as_Tguard());
439
440 f_rslem_register(0, pars.chan_nr);
441
442 /* call the user-supplied test case function */
443 fn.apply(id);
444}
445
Harald Welteb1726c92018-03-30 11:56:38 +0200446function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
447 boolean ignore_other := false)
448runs on ConnHdlr return RSL_Message {
449 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100450 timer T := 3.0;
451 RSL.send(tx);
452 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100453 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200454 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100455 T.stop;
456 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100457 }
Harald Welte1eba3742018-02-25 12:48:14 +0100458 [] T.timeout {
459 setverdict(fail, "Timeout expecting " & id);
460 self.stop;
461 }
Harald Welte21240e62018-03-11 21:43:35 +0100462 [not ignore_other] as_l1_sacch();
463 [not ignore_other] as_meas_res();
464 [not ignore_other] as_l1_dcch();
465 [not ignore_other] RSL.receive {
Harald Welte1eba3742018-02-25 12:48:14 +0100466 setverdict(fail, "Unexpected RSL message received");
Harald Welteb1726c92018-03-30 11:56:38 +0200467 self.stop;
Harald Welte70767382018-02-21 12:16:40 +0100468 }
Harald Welte21240e62018-03-11 21:43:35 +0100469 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100470 }
Harald Welteb1726c92018-03-30 11:56:38 +0200471 return rx;
472}
473
474function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
475 boolean ignore_other := false)
476runs on ConnHdlr {
477 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100478}
479
Harald Weltee613f962018-04-18 22:38:16 +0200480function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false)
481runs on ConnHdlr {
482 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode));
483 if (encr_enable) {
484 /* append encryption related IEs, if requested */
485 var RSL_IE_EncryptionInfo encr_info;
486 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
487 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
488encr_info})) };
489 }
490 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100491}
492
Harald Welte70767382018-02-21 12:16:40 +0100493function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100494 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100495 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100496}
497
Harald Welte70767382018-02-21 12:16:40 +0100498private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
499 template RSL_IE_ChannelMode chan_mode,
500 float t_guard := 20.0) := {
501 chan_nr := valueof(chan_nr),
502 chan_mode := valueof(chan_mode),
503 t_guard := t_guard,
504 l1_pars := {
505 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100506 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100507 meas_ul := {
508 full := {
509 rxlev := dbm2rxlev(-53),
510 rxqual := 0
511 },
512 sub := {
513 rxlev := dbm2rxlev(-53),
514 rxqual := 0
515 }
516 },
517 timing_offset_256syms := 0,
518 bs_power_level := 0,
519 ms_power_level := 0,
520 ms_actual_ta := 0
Harald Welte0472ab42018-03-12 15:02:26 +0100521 },
Harald Weltee613f962018-04-18 22:38:16 +0200522 spec := omit,
523 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100524}
525
Harald Welte93640c62018-02-25 16:59:33 +0100526/***********************************************************************
527 * Channel Activation / Deactivation
528 ***********************************************************************/
529
Harald Welte70767382018-02-21 12:16:40 +0100530/* Stress test: Do 500 channel activations/deactivations in rapid succession */
531function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
532 for (var integer i := 0; i < 500; i := i+1) {
533 f_rsl_chan_act(g_pars.chan_mode);
534 f_rsl_chan_deact();
535 }
536 setverdict(pass);
537}
538testcase TC_chan_act_stress() runs on test_CT {
539 var ConnHdlr vc_conn;
540 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
541 f_init(testcasename());
542 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
543 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100544 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100545}
546
547/* Test if re-activation of an already active channel fails as expected */
548function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
549 f_rsl_chan_act(g_pars.chan_mode);
550 /* attempt to activate the same lchan again -> expect reject */
551 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
552 alt {
553 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
554 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
555 }
556 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
557 setverdict(pass);
558 }
559 }
560 f_rsl_chan_deact();
561}
562testcase TC_chan_act_react() runs on test_CT {
563 var ConnHdlr vc_conn;
564 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100565 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100566 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
567 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100568 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100569}
570
571/* Attempt to de-activate a channel that's not active */
572function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
573 timer T := 3.0;
574 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
575 T.start;
576 alt {
577 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
578 setverdict(pass);
579 }
580 [] T.timeout {
581 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
582 }
583 }
584}
585testcase TC_chan_deact_not_active() runs on test_CT {
586 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100587 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100588 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
589 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100590 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100591}
592
593/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
594function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
595 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
596 alt {
597 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
598 setverdict(fail, "Unexpected CHAN ACT ACK");
599 }
600 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
601 setverdict(pass);
602 }
603 }
604}
605private type record WrongChanNrCase {
606 RslChannelNr chan_nr,
607 charstring description
608}
609private type record of WrongChanNrCase WrongChanNrCases;
610private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
611 chan_nr := chan_nr,
612 description := desc
613}
614
615testcase TC_chan_act_wrong_nr() runs on test_CT {
616 var ConnHdlr vc_conn;
617 var ConnHdlrPars pars;
618
Harald Welte294b0a22018-03-10 23:26:48 +0100619 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100620
621 var WrongChanNrCases wrong := {
622 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
623 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
624 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
625 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
626 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
627 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
628 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
629 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
630 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
631 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
632 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
633 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
634 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
635 };
636
637 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
638 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
639 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
640 vc_conn.done;
641 }
Harald Welte294b0a22018-03-10 23:26:48 +0100642 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
Harald Weltee613f962018-04-18 22:38:16 +0200645/* execute the same callback function on a variety of logical channels */
646private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
647 var ConnHdlr vc_conn;
648 f_init(testcasename());
649
650 /* test on each of the channels we have */
651 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
652 pars.chan_nr := valueof(g_AllChanTypes[i]);
653
654 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
655 vc_conn := f_start_handler(fn, pars);
656 vc_conn.done;
657 }
658
659 f_shutdown();
660}
661
Harald Welte93640c62018-02-25 16:59:33 +0100662/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100663 * SACCH handling
664 ***********************************************************************/
665
666private function f_exp_sacch(boolean exp) runs on ConnHdlr {
667 timer T_sacch := 3.0;
668 T_sacch.start;
669 alt {
670 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
671 setverdict(fail, "Received SACCH when not expecting it");
672 }
673 [not exp] T_sacch.timeout {
674 setverdict(pass);
675 }
676 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
677 setverdict(pass);
678 }
679 [exp] T_sacch.timeout {
680 setverdict(fail, "Timeout waiting for SACCH on ", g_chan_nr);
681 }
682 [] L1CTL.receive { repeat; }
683 [] RSL.receive { repeat; }
684 }
685}
686
687/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
688private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
689 f_l1_tune(L1CTL);
690 RSL.clear;
691
692 /* activate the logical channel */
693 f_est_dchan();
694 L1CTL.clear;
695
696 /* check that SACCH actually are received as expected */
697 f_exp_sacch(true);
698
699 /* deactivate SACCH on the logical channel */
700 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
701 f_sleep(1.0);
702 L1CTL.clear;
703
704 /* check that no SACCH are received anymore */
705 f_exp_sacch(false);
706
707 /* release the channel */
708 f_rsl_chan_deact();
709 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
710}
711testcase TC_deact_sacch() runs on test_CT {
712 var ConnHdlr vc_conn;
713 var ConnHdlrPars pars;
714 f_init();
715 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
716 //for (var integer i := 0; i < 1; i := i+1) {
717 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
718 log(testcasename(), ": Starting for ", g_AllChannels[i]);
719 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
720 vc_conn.done;
721 }
722 /* TODO: do the above in parallel, rather than sequentially? */
723 f_shutdown();
724}
725
Harald Welte55700662018-03-12 13:15:43 +0100726/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100727private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
728 var L1ctlDlMessage dl;
729 /* check that the specified SI5 value is actually sent */
730 timer T_sacch := 3.0;
731 L1CTL.clear;
732 T_sacch.start;
733 alt {
734 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
735 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
736 if (match(l3, l3_exp)) {
737 setverdict(pass);
738 } else {
739 repeat;
740 }
741 }
742 [] L1CTL.receive { repeat; }
743 [] T_sacch.timeout {
744 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
745 self.stop;
746 }
747 }
748}
749
Harald Welte55700662018-03-12 13:15:43 +0100750/* verify that given SACCH payload is not present */
751private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
752 var L1ctlDlMessage dl;
753 /* check that the specified SI5 value is actually sent */
754 timer T_sacch := 3.0;
755 L1CTL.clear;
756 T_sacch.start;
757 alt {
758 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
759 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
760 if (match(l3, l3_exp)) {
761 setverdict(fail, "Received unexpected SACCH ", dl);
762 self.stop;
763 } else {
764 repeat;
765 }
766 }
767 [] L1CTL.receive { repeat; }
768 [] T_sacch.timeout {
769 setverdict(pass);
770 }
771 }
772}
773
Harald Welte629cc6b2018-03-11 17:19:05 +0100774/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100775private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
776 /* Set a known default SACCH filling for SI5 */
777 var octetstring si5 := f_rnd_octstring(19);
778 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
779
780 f_l1_tune(L1CTL);
781 RSL.clear;
782
783 /* activate the logical channel */
784 f_est_dchan();
785
786 /* check that the specified SI5 value is actually sent */
787 f_sacch_present(si5);
788
789 /* release the channel */
790 RSL.clear;
791 f_rsl_chan_deact();
792 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
793}
794testcase TC_sacch_filling() runs on test_CT {
795 var ConnHdlr vc_conn;
796 var ConnHdlrPars pars;
797 f_init();
798 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
799 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
800 log(testcasename(), ": Starting for ", g_AllChannels[i]);
801 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
802 vc_conn.done;
803 }
804 /* TODO: do the above in parallel, rather than sequentially? */
805 f_shutdown();
806}
807
Harald Welte629cc6b2018-03-11 17:19:05 +0100808/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100809private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
810 /* Set a known default SACCH filling for SI5 */
811 var octetstring si5 := f_rnd_octstring(19);
812 var octetstring si5_diff := f_rnd_octstring(19);
813 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
814
815 f_l1_tune(L1CTL);
816 RSL.clear;
817
818 log("Activating channel, expecting standard SI5");
819 /* activate the logical channel */
820 f_est_dchan();
821 /* check that the specified SI5 value is actually sent */
822 f_sacch_present(si5);
823
824 /* set channel-specific different SI5 */
825 log("Setting channel specific SACCH INFO, expecting it");
826 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
827 /* check that the specified lchan-specific value is now used */
828 f_sacch_present(si5_diff);
829
830 /* deactivate the channel and re-activate it, this should result in default SI5 */
831 log("De-activating and re-activating channel, expecting standard SI5");
832 f_rsl_chan_deact();
833 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
834 /* Verify that the TRX-wide default SACCH filling is present again */
835 f_sacch_present(si5);
836
837 /* release the channel */
838 RSL.clear;
839 f_rsl_chan_deact();
840 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
841}
842testcase TC_sacch_info_mod() runs on test_CT {
843 var ConnHdlr vc_conn;
844 var ConnHdlrPars pars;
845 f_init();
846 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
847 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
848 log(testcasename(), ": Starting for ", g_AllChannels[i]);
849 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
850 vc_conn.done;
851 }
852 /* TODO: do the above in parallel, rather than sequentially? */
853 f_shutdown();
854}
855
Harald Welte075d84c2018-03-12 13:07:24 +0100856/* Test SACCH scheduling of multiple different SI message types */
857private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
858 var octetstring si5 := f_rnd_octstring(19);
859 var octetstring si5bis := f_rnd_octstring(19);
860 var octetstring si5ter := f_rnd_octstring(19);
861 var octetstring si6 := f_rnd_octstring(19);
862
863 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
864 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
865 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
866 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
867
868 f_l1_tune(L1CTL);
869 RSL.clear;
870
871 /* activate the logical channel */
872 f_est_dchan();
873 L1CTL.clear;
874
875 /* check that SACCH actually are received as expected */
876 f_sacch_present(si5);
877 f_sacch_present(si5bis);
878 f_sacch_present(si5ter);
879 f_sacch_present(si6);
880
881 /* release the channel */
882 f_rsl_chan_deact();
883 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
884}
885testcase TC_sacch_multi() runs on test_CT {
886 var ConnHdlr vc_conn;
887 var ConnHdlrPars pars;
888 f_init();
889 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
890 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
891 log(testcasename(), ": Starting for ", g_AllChannels[i]);
892 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
893 vc_conn.done;
894 }
895 /* TODO: do the above in parallel, rather than sequentially? */
896 f_shutdown();
897}
898
Harald Welte55700662018-03-12 13:15:43 +0100899/* Test if SACH information is modified as expected */
900private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
901 var octetstring si5 := f_rnd_octstring(19);
902 var octetstring si6 := f_rnd_octstring(19);
903
904 /* First, configure both SI5 and SI6 to be transmitted */
905 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
906 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
907
908 f_l1_tune(L1CTL);
909 RSL.clear;
910
911 /* activate the logical channel */
912 f_est_dchan();
913 L1CTL.clear;
914
915 /* check that SACCH actually are received as expected */
916 f_sacch_present(si5);
917 f_sacch_present(si6);
918
919 /* disable SI6 */
920 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
921
922 /* check that SI5 is still transmitted */
923 f_sacch_present(si5);
924 /* check if SI6 is now gone */
925 f_sacch_missing(si6);
926
927 /* release the channel */
928 f_rsl_chan_deact();
929 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
930}
931testcase TC_sacch_multi_chg() runs on test_CT {
932 var ConnHdlr vc_conn;
933 var ConnHdlrPars pars;
934 f_init();
935 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
936 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
937 log(testcasename(), ": Starting for ", g_AllChannels[i]);
938 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
939 vc_conn.done;
940 }
941 /* TODO: do the above in parallel, rather than sequentially? */
942 f_shutdown();
943}
944
Harald Welte075d84c2018-03-12 13:07:24 +0100945/* TODO: Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
946/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +0100947
948
949/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100950 * RACH Handling
951 ***********************************************************************/
952
Harald Welte8c24c2b2018-02-26 08:31:31 +0100953/* like L1SAP_IS_PACKET_RACH */
954private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100955 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100956 return true;
957 }
958 return false;
959}
960
961/* generate a random RACH for circuit-switched */
962private function f_rnd_ra_cs() return OCT1 {
963 var OCT1 ra;
964 do {
965 ra := f_rnd_octstring(1);
966 } while (ra_is_ps(ra));
967 return ra;
968}
969
Harald Welte883340c2018-02-28 18:59:29 +0100970/* generate a random RACH for packet-switched */
971private function f_rnd_ra_ps() return OCT1 {
972 var OCT1 ra;
973 do {
974 ra := f_rnd_octstring(1);
975 } while (not ra_is_ps(ra));
976 return ra;
977}
978
Harald Welte8c24c2b2018-02-26 08:31:31 +0100979/* Send 1000 RACH requests and check their RA+FN on the RSL side */
980testcase TC_rach_content() runs on test_CT {
981 f_init(testcasename());
982 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100983 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100984
Harald Welte8c24c2b2018-02-26 08:31:31 +0100985 var GsmFrameNumber fn_last := 0;
986 for (var integer i := 0; i < 1000; i := i+1) {
987 var OCT1 ra := f_rnd_ra_cs();
988 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
989 if (fn == fn_last) {
990 setverdict(fail, "Two RACH in same FN?!?");
991 self.stop;
992 }
993 fn_last := fn;
994
995 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100996 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100997 alt {
998 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
999 T.stop;
1000 }
1001 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
1002 setverdict(fail, "Unexpected CHAN RQD");
1003 self.stop;
1004 }
1005 [] RSL_CCHAN.receive { repeat; }
1006 [] T.timeout {
1007 setverdict(fail, "Timeout waiting for CHAN RQD");
1008 self.stop;
1009 }
1010 }
1011 }
1012 setverdict(pass);
Harald Welte294b0a22018-03-10 23:26:48 +01001013 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001014}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001015
1016/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1017testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001018 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001019 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001020 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001021 f_l1_tune(L1CTL);
1022
1023 var GsmFrameNumber fn_last := 0;
1024 for (var integer i := 0; i < 1000; i := i+1) {
1025 var OCT1 ra := f_rnd_ra_cs();
1026 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1027 if (fn == fn_last) {
1028 setverdict(fail, "Two RACH in same FN?!?");
1029 self.stop;
1030 }
1031 fn_last := fn;
1032 }
1033 var integer rsl_chrqd := 0;
1034 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001035 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001036 alt {
1037 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1038 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001039 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001040 repeat;
1041 }
1042 [] RSL_CCHAN.receive { repeat; }
1043 [] T.timeout { }
1044 }
1045 if (rsl_chrqd == 1000) {
1046 setverdict(pass);
1047 } else {
1048 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
1049 }
Harald Welte294b0a22018-03-10 23:26:48 +01001050 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001051}
1052
Harald Welte54a2a2d2018-02-26 09:14:05 +01001053private function f_main_trxc_connect() runs on test_CT {
1054 map(self:BB_TRXC, system:BB_TRXC);
1055 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +01001056 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
1057 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001058 if (not ispresent(res.connId)) {
1059 setverdict(fail, "Could not connect to trx-control interface of trxcon, check your configuration");
1060 self.stop;
1061 }
Harald Welte54a2a2d2018-02-26 09:14:05 +01001062 g_bb_trxc_conn_id := res.connId;
1063}
1064
1065private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001066 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001067 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +01001068 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001069 f_sleep(0.5);
1070
1071 /* Transmit RACH request + wait for confirmation */
1072 var OCT1 ra := f_rnd_ra_cs();
1073 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1074
1075 /* Check for expected result */
1076 timer T := 1.5;
1077 T.start;
1078 alt {
1079 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1080 setverdict(pass);
1081 }
1082 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +01001083 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001084 }
1085 [] RSL_CCHAN.receive { repeat; }
1086 [not expect_pass] T.timeout {
1087 setverdict(pass);
1088 }
1089 [expect_pass] T.timeout {
1090 setverdict(fail, "Timeout waiting for CHAN RQD");
1091 }
1092 }
1093}
1094
1095/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1096testcase TC_rach_max_ta() runs on test_CT {
1097 f_init(testcasename());
1098 f_init_l1ctl();
1099 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001100 f_sleep(1.0);
1101
1102 /* default max-ta is 63 (full range of GSM timing advance */
1103
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001104 /* We allow early arrival up to 2 symbols */
1105 f_rach_toffs(-1*256, true);
1106 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001107 f_rach_toffs(-10*256, false);
1108
1109 /* 0 / 32 / 63 bits is legal / permitted */
1110 f_rach_toffs(0, true);
1111 f_rach_toffs(32*256, true);
1112 f_rach_toffs(63*256, true);
1113
1114 /* more than 63 bits is not legal / permitted */
1115 f_rach_toffs(64*256, false);
1116 f_rach_toffs(127*256, false);
Harald Welte294b0a22018-03-10 23:26:48 +01001117 f_shutdown();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001118}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001119
Harald Welte93640c62018-02-25 16:59:33 +01001120/***********************************************************************
1121 * Measurement Processing / Reporting
1122 ***********************************************************************/
1123
Harald Welte70767382018-02-21 12:16:40 +01001124template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1125 spare := '0'B,
1126 lpd := 0,
1127 sapi := sapi,
1128 c_r := c_r,
1129 ea := true
1130}
1131
Harald Welted879bd92018-03-12 15:01:23 +01001132template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001133 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001134 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001135 len := 0, /* overwritten */
1136 m := false,
1137 el := 1,
1138 payload := pl
1139}
1140
1141/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1142altstep as_l1_sacch() runs on ConnHdlr {
1143 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001144 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001145 log("SACCH received: ", l1_dl.payload.data_ind.payload);
1146 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001147 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001148 log("LAPDm: ", lb);
Harald Welted879bd92018-03-12 15:01:23 +01001149 var octetstring pl := '0000'O & enc_LapdmFrameAB(lb);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001150 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001151 repeat;
1152 }
1153}
1154
1155altstep as_l1_dcch() runs on ConnHdlr {
1156 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001157 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001158 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1159 var octetstring pl := '010301'O;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001160 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001161 repeat;
1162 }
1163}
1164
1165type record MeasElem {
1166 uint6_t rxlev,
1167 uint3_t rxqual
1168}
1169
1170type record MeasElemFS {
1171 MeasElem full,
1172 MeasElem sub
1173}
1174
1175type record ConnL1Pars {
1176 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001177 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001178 MeasElemFS meas_ul,
1179 int16_t timing_offset_256syms,
1180 uint5_t bs_power_level,
1181 uint5_t ms_power_level,
1182 uint8_t ms_actual_ta
1183}
1184
1185/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1186private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1187 return 63 + (toffs256s/256);
1188}
1189
Harald Welted5684392018-03-10 18:22:04 +01001190private function f_max(integer a, integer b) return integer {
1191 if (a > b) {
1192 return a;
1193 } else {
1194 return b;
1195 }
1196}
1197
1198private function f_min(integer a, integer b) return integer {
1199 if (a < b) {
1200 return a;
1201 } else {
1202 return b;
1203 }
1204}
1205
1206/* compute negative tolerance val-tolerance, ensure >= min */
1207private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1208 val := val - tolerance;
1209 return f_max(val, min);
1210}
1211
1212/* compute positive tolerance val+tolerance, ensure <= max */
1213private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1214 val := val + tolerance;
1215 return f_min(val, max);
1216}
1217
1218/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1219private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1220return template integer {
1221 var template integer ret;
1222 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1223 return ret;
1224}
1225
1226
Harald Welte70767382018-02-21 12:16:40 +01001227/* build a template for matching measurement results against */
1228private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1229 var ConnL1Pars l1p := g_pars.l1_pars;
1230 var template RSL_IE_UplinkMeas ul_meas := {
1231 len := 3,
1232 rfu := '0'B,
1233 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001234 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001235 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001236 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001237 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001238 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1239 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001240 supp_meas_info := omit
1241 };
Harald Welte685d5982018-02-27 20:42:05 +01001242 if (l1p.toa256_enabled) {
1243 ul_meas.len := 5;
1244 ul_meas.supp_meas_info := int2oct(l1p.timing_offset_256syms, 2);
1245 }
Harald Welte70767382018-02-21 12:16:40 +01001246 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
1247 ul_meas.rxlev_f_u := ?;
1248 ul_meas.rxlev_s_u := ?;
1249 ul_meas.rxq_f_u := ?;
1250 ul_meas.rxq_s_u := ?;
1251 var template RSL_IE_BS_Power bs_power := {
1252 reserved := 0,
1253 epc := false,
1254 fpc := false,
1255 power_level := l1p.bs_power_level
1256 };
1257 var template RSL_IE_L1Info l1_info := {
1258 ms_power_lvl := l1p.ms_power_level,
1259 fpc := false,
1260 reserved := 0,
1261 actual_ta := l1p.ms_actual_ta
1262 };
1263 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
1264 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
1265 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1266 ?, t_toffs);
1267}
1268
1269/* verify we regularly receive measurement reports with incrementing numbers */
1270altstep as_meas_res() runs on ConnHdlr {
1271 var RSL_Message rsl;
1272 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1273 /* increment counter of next to-be-expected meas rep */
1274 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1275 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001276 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001277 repeat;
1278 }
1279 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001280 /* increment counter of next to-be-expected meas rep */
1281 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1282 if (g_first_meas_res) {
1283 g_first_meas_res := false;
1284 repeat;
1285 } else {
1286 setverdict(fail, "Received unspecific MEAS RES ", rsl);
1287 self.stop;
1288 }
Harald Welte70767382018-02-21 12:16:40 +01001289 }
1290 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
1291 setverdict(fail, "Received unexpected MEAS RES ", rsl);
1292 self.stop;
1293 }
1294 [] g_Tmeas_exp.timeout {
1295 setverdict(fail, "Didn't receive expected measurement result")
1296 self.stop;
1297 }
1298}
1299
Harald Weltee613f962018-04-18 22:38:16 +02001300private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1301 select (rsl_alg_id) {
1302 case (RSL_ALG_ID_A5_0) { return 0; }
1303 case (RSL_ALG_ID_A5_1) { return 1; }
1304 case (RSL_ALG_ID_A5_2) { return 2; }
1305 case (RSL_ALG_ID_A5_3) { return 3; }
1306 case (RSL_ALG_ID_A5_4) { return 4; }
1307 case (RSL_ALG_ID_A5_5) { return 5; }
1308 case (RSL_ALG_ID_A5_6) { return 6; }
1309 case (RSL_ALG_ID_A5_7) { return 7; }
1310 case else {
1311 setverdict(fail, "Unknwon Algorithm ID");
1312 self.stop;
1313 }
1314 }
1315}
1316
1317private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1318 select (rsl_alg_id) {
1319 case (RSL_ALG_ID_A5_1) { return '000'B; }
1320 case (RSL_ALG_ID_A5_2) { return '001'B; }
1321 case (RSL_ALG_ID_A5_3) { return '010'B; }
1322 case (RSL_ALG_ID_A5_4) { return '011'B; }
1323 case (RSL_ALG_ID_A5_5) { return '100'B; }
1324 case (RSL_ALG_ID_A5_6) { return '101'B; }
1325 case (RSL_ALG_ID_A5_7) { return '110'B; }
1326 case else {
1327 setverdict(fail, "Unknwon Algorithm ID");
1328 self.stop;
1329 }
1330 }
1331}
1332
1333
Harald Welte70767382018-02-21 12:16:40 +01001334/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltee613f962018-04-18 22:38:16 +02001335private function f_est_dchan(boolean encr_enable := false) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001336 var GsmFrameNumber fn;
1337 var ImmediateAssignment imm_ass;
1338 var integer ra := 23;
1339
1340 fn := f_L1CTL_RACH(L1CTL, ra);
1341 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
1342 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
1343
1344 /* Activate channel on BTS side */
Harald Weltee613f962018-04-18 22:38:16 +02001345 f_rsl_chan_act(g_pars.chan_mode, encr_enable);
Harald Welte70767382018-02-21 12:16:40 +01001346
1347 /* Send IMM.ASS via CCHAN */
1348 var ChannelDescription ch_desc := {
1349 chan_nr := g_pars.chan_nr,
1350 tsc := 7,
1351 h := false,
1352 arfcn := mp_trx0_arfcn,
1353 maio_hsn := omit
1354 };
1355 var MobileAllocation ma := {
1356 len := 0,
1357 ma := ''B
1358 };
1359 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1360 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1361
1362 /* receive IMM.ASS on MS side */
1363 var ImmediateAssignment ia_um;
1364 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1365 /* enable dedicated mode */
1366 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001367 /* enable encryption, if requested */
1368 if (encr_enable) {
1369 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1370 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1371 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001372
1373 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001374}
1375
1376/* establish DChan, verify existance + contents of measurement reports */
1377function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001378 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001379 RSL.clear;
1380
Harald Welte5398d5e2018-03-10 19:00:24 +01001381 if (mp_bb_trxc_port != -1) {
1382 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
1383 f_trxc_fake_rssi(100);
Harald Welte70767382018-02-21 12:16:40 +01001384
Harald Welte5398d5e2018-03-10 19:00:24 +01001385 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
1386 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1387 } else {
1388 g_pars.l1_pars.timing_offset_256syms := 0; /* FIXME */
1389 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-55); /* FIXME */
1390 }
1391 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
Harald Welte70767382018-02-21 12:16:40 +01001392
1393 f_est_dchan();
1394
1395 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1396 * RSL measurement reports on Abis side */
1397 timer T := 8.0;
1398 T.start;
1399 alt {
1400 [] as_l1_sacch();
1401 [] as_meas_res();
1402 [] as_l1_dcch();
1403 [] L1CTL.receive { repeat; }
1404 [g_Tmeas_exp.running] T.timeout {
1405 /* as_meas_res() would have done setverdict(fail) / self.stop in case
1406 * of any earlier errors, so if we reach this timeout, we're good */
1407 setverdict(pass);
1408 }
1409 [] T.timeout {
1410 setverdict(fail, "No MEAS RES received at all");
1411 }
1412 }
1413 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001414 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001415}
Harald Welte0472ab42018-03-12 15:02:26 +01001416
Harald Welte70767382018-02-21 12:16:40 +01001417testcase TC_meas_res_sign_tchf() runs on test_CT {
1418 var ConnHdlr vc_conn;
1419 var ConnHdlrPars pars;
1420 f_init(testcasename());
1421 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1422 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1423 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1424 vc_conn.done;
1425 }
Harald Welte294b0a22018-03-10 23:26:48 +01001426 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001427}
1428testcase TC_meas_res_sign_tchh() runs on test_CT {
1429 var ConnHdlr vc_conn;
1430 var ConnHdlrPars pars;
1431 f_init(testcasename());
1432 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1433 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1434 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1435 vc_conn.done;
1436 }
Harald Welte294b0a22018-03-10 23:26:48 +01001437 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001438}
1439testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1440 var ConnHdlr vc_conn;
1441 var ConnHdlrPars pars;
1442 f_init(testcasename());
1443 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1444 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1445 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1446 vc_conn.done;
1447 }
Harald Welte294b0a22018-03-10 23:26:48 +01001448 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001449}
1450testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1451 var ConnHdlr vc_conn;
1452 var ConnHdlrPars pars;
1453 f_init(testcasename());
1454 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1455 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1456 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1457 vc_conn.done;
1458 }
Harald Welte294b0a22018-03-10 23:26:48 +01001459 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001460}
Harald Welte685d5982018-02-27 20:42:05 +01001461testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1462 var ConnHdlr vc_conn;
1463 var ConnHdlrPars pars;
1464 f_init(testcasename());
1465 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1466 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1467 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1468 pars.l1_pars.toa256_enabled := true;
1469 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1470 vc_conn.done;
1471 }
Harald Welte294b0a22018-03-10 23:26:48 +01001472 f_shutdown();
Harald Welte685d5982018-02-27 20:42:05 +01001473}
1474
Harald Welte70767382018-02-21 12:16:40 +01001475
Harald Welte0472ab42018-03-12 15:02:26 +01001476/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND (TS 48.058 4.10) */
Harald Welte70767382018-02-21 12:16:40 +01001477private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001478 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001479 RSL.clear;
1480
1481 f_est_dchan();
1482 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001483 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001484
1485 timer T := 40.0;
1486 T.start;
1487 alt {
1488 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1489 setverdict(pass)
1490 }
1491 [] RSL.receive { repeat };
1492 [] T.timeout {
1493 setverdict(fail, "No CONN FAIL IND received");
1494 }
1495 }
1496 f_rsl_chan_deact();
1497}
1498testcase TC_conn_fail_crit() runs on test_CT {
1499 var ConnHdlr vc_conn;
1500 var ConnHdlrPars pars;
1501 f_init(testcasename());
1502 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1503 pars.t_guard := 60.0;
1504 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1505 vc_conn.done;
1506}
1507
Harald Welte93640c62018-02-25 16:59:33 +01001508/***********************************************************************
1509 * Paging
1510 ***********************************************************************/
1511
Harald Welte68e495b2018-02-25 00:05:57 +01001512function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1513 if (tmsi == 'FFFFFFFF'O) {
1514 return true;
1515 } else {
1516 return false;
1517 }
1518}
Harald Welte70767382018-02-21 12:16:40 +01001519
Harald Welte68e495b2018-02-25 00:05:57 +01001520altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1521runs on test_CT {
1522 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001523 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001524 repeat;
1525 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001526 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001527 var octetstring without_plen :=
1528 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1529 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1530 if (match(rr, tr_PAGING_REQ1)) {
1531 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1532 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1533 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1534 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1535 }
1536 } else if (match(rr, tr_PAGING_REQ2)) {
1537 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1538 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1539 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1540 }
1541 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1542 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1543 }
1544 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1545 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1546 }
1547 } else if (match(rr, tr_PAGING_REQ3)) {
1548 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1549 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1550 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1551 }
1552 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1553 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1554 }
1555 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1556 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1557 }
1558 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1559 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1560 }
1561 }
1562 repeat;
1563 }
1564}
1565
1566type record PagingTestCfg {
1567 boolean combined_ccch,
1568 integer bs_ag_blks_res,
1569 float load_factor,
1570 boolean exp_load_ind,
1571 boolean exp_overload,
1572 boolean use_tmsi
1573}
1574
1575type record PagingTestState {
1576 integer num_paging_sent,
1577 integer num_paging_rcv_msgs,
1578 integer num_paging_rcv_ids,
1579 integer num_overload
1580}
1581
1582/* receive + ignore RSL RF RES IND */
1583altstep as_rsl_res_ind() runs on test_CT {
1584 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1585 repeat;
1586 }
1587}
1588
1589/* Helper function for paging related testing */
1590private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1591 f_init(testcasename());
1592 f_init_l1ctl();
1593 f_l1_tune(L1CTL);
1594
1595 var PagingTestState st := {
1596 num_paging_sent := 0,
1597 num_paging_rcv_msgs := 0,
1598 num_paging_rcv_ids := 0,
1599 num_overload := 0
1600 };
1601
1602 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1603 var float max_pch_imsi_per_sec;
1604 if (cfg.use_tmsi) {
1605 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1606 } else {
1607 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1608 }
1609 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1610 var float interval := 1.0 / pch_blocks_per_sec;
1611 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1612
1613 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1614 /* build mobile Identity */
1615 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1616 if (cfg.use_tmsi) {
1617 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1618 } else {
1619 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1620 }
1621 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1622 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1623
1624 /* Send RSL PAGING COMMAND */
1625 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1626 st.num_paging_sent := st.num_paging_sent + 1;
1627
1628 /* Wait for interval to next PAGING COMMAND */
1629 timer T_itv := interval;
1630 T_itv.start;
1631 alt {
1632 /* check for presence of CCCH LOAD IND (paging load) */
1633 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1634 st.num_overload := st.num_overload + 1;
1635 repeat;
1636 }
1637 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1638 setverdict(fail, "Unexpected PCH Overload");
1639 }
1640 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1641 log("Rx LOAD_IND");
1642 /* FIXME: analyze/verify interval + contents */
1643 repeat;
1644 }
1645 /* check if paging requests arrive on Um side */
1646 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1647 [] L1CTL.receive { repeat; }
1648 [] T_itv.timeout { }
1649 [] as_rsl_res_ind();
1650 }
1651 }
1652
1653 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1654 timer T_wait := 18.0;
1655 T_wait.start;
1656 alt {
1657 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1658 [] L1CTL.receive { repeat; }
1659 /* 65535 == empty paging queue, we can terminate*/
1660 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1661 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1662 [] T_wait.timeout {
1663 setverdict(fail, "Waiting for empty paging queue");
1664 }
1665 [] as_rsl_res_ind();
1666 }
1667
Harald Welte294b0a22018-03-10 23:26:48 +01001668 f_shutdown();
1669
Harald Welte68e495b2018-02-25 00:05:57 +01001670 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1671 " rcvd_ids=", st.num_paging_rcv_ids);
1672 return st;
1673}
1674
1675/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1676 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1677 * - that CCCH LOAD IND (PCH) are being generated
1678 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1679testcase TC_paging_imsi_80percent() runs on test_CT {
1680 var PagingTestCfg cfg := {
1681 combined_ccch := true,
1682 bs_ag_blks_res := 1,
1683 load_factor := 0.8,
1684 exp_load_ind := true,
1685 exp_overload := false,
1686 use_tmsi := false
1687 };
1688 var PagingTestState st := f_TC_paging(cfg);
1689 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1690 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1691 st.num_paging_rcv_ids);
1692 } else {
1693 setverdict(pass);
1694 }
1695}
1696
1697/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1698 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1699 * - that CCCH LOAD IND (PCH) are being generated
1700 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1701testcase TC_paging_tmsi_80percent() runs on test_CT {
1702 var PagingTestCfg cfg := {
1703 combined_ccch := true,
1704 bs_ag_blks_res := 1,
1705 load_factor := 0.8,
1706 exp_load_ind := true,
1707 exp_overload := false,
1708 use_tmsi := true
1709 };
1710 var PagingTestState st := f_TC_paging(cfg);
1711 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1712 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1713 st.num_paging_rcv_ids);
1714 } else {
1715 setverdict(pass);
1716 }
1717}
1718
1719/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1720 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1721 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1722 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1723testcase TC_paging_imsi_200percent() runs on test_CT {
1724 var PagingTestCfg cfg := {
1725 combined_ccch := true,
1726 bs_ag_blks_res := 1,
1727 load_factor := 2.0,
1728 exp_load_ind := true,
1729 exp_overload := true,
1730 use_tmsi := false
1731 };
1732 var PagingTestState st := f_TC_paging(cfg);
1733 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1734 * slots and will fully drain that buffer before returning */
1735 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1736 if (not match(st.num_paging_rcv_ids, tpl)) {
1737 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1738 } else {
1739 setverdict(pass);
1740 }
1741}
1742
1743/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1744 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1745 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1746 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1747testcase TC_paging_tmsi_200percent() runs on test_CT {
1748 var PagingTestCfg cfg := {
1749 combined_ccch := true,
1750 bs_ag_blks_res := 1,
1751 load_factor := 2.0,
1752 exp_load_ind := true,
1753 exp_overload := true,
1754 use_tmsi := true
1755 };
1756 var PagingTestState st := f_TC_paging(cfg);
1757 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1758 * slots and will fully drain that buffer before returning */
Harald Welte0803cde2018-04-15 21:36:54 +02001759 var template integer tpl := (st.num_paging_sent*66/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001760 if (not match(st.num_paging_rcv_ids, tpl)) {
1761 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1762 } else {
1763 setverdict(pass);
1764 }
1765}
1766
1767
Harald Welte93640c62018-02-25 16:59:33 +01001768/***********************************************************************
1769 * Immediate Assignment / AGCH
1770 ***********************************************************************/
1771
Harald Welte68e495b2018-02-25 00:05:57 +01001772testcase TC_imm_ass() runs on test_CT {
1773 f_init(testcasename());
1774 for (var integer i := 0; i < 1000; i := i+1) {
1775 var octetstring ia_enc := f_rnd_octstring(8);
1776 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
1777 f_sleep(0.02);
1778 }
1779 /* FIXME: check if imm.ass arrive on Um side */
1780 /* FIXME: check for DELETE INDICATION */
1781 f_sleep(100.0);
Harald Welte294b0a22018-03-10 23:26:48 +01001782 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001783}
1784
Harald Welte48494ca2018-02-25 16:59:50 +01001785/***********************************************************************
1786 * BCCH
1787 ***********************************************************************/
1788
1789/* tuple of Frame Number + decoded SI */
1790type record SystemInformationFn {
1791 GsmFrameNumber frame_number,
1792 SystemInformation si
1793}
1794
1795/* an arbitrary-length vector of decoded SI + gsmtap header */
1796type record of SystemInformationFn SystemInformationVector;
1797
1798/* an array of SI-vectors indexed by TC value */
1799type SystemInformationVector SystemInformationVectorPerTc[8];
1800
1801/* determine if a given SI vector contains given SI type at least once */
1802function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1803 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1804 var integer fn_mod51 := arr[i].frame_number mod 51;
1805 if (not bcch_ext and fn_mod51 == 2 or
1806 bcch_ext and fn_mod51 == 6) {
1807 if (arr[i].si.header.message_type == key) {
1808 return true;
1809 }
1810 }
1811 }
1812 return false;
1813}
1814
1815/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1816function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1817 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1818 setverdict(fail, "No ", key, " in TC=", tc, "!");
1819 }
1820}
1821
1822/* check if a given SI vector contains given SI type at least once on any TC */
1823function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1824 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1825 if (f_si_vecslot_contains(arr[tc], key) or
1826 f_si_vecslot_contains(arr[tc], key, true)) {
1827 return true;
1828 }
1829 }
1830 return false;
1831}
1832
1833/* determine if a given SI vector contains given SI type at least N of M times */
1834function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1835 var integer count := 0;
1836 if (sizeof(arr) < m) {
1837 setverdict(fail, "Error: Insufficient SI in array");
1838 self.stop;
1839 }
1840 for (var integer i:= 0; i < m; i := i + 1) {
1841 var integer fn_mod51 := arr[i].frame_number mod 51;
1842 if (not bcch_ext and fn_mod51 == 2 or
1843 bcch_ext and fn_mod51 == 6) {
1844 if (arr[i].si.header.message_type == key) {
1845 count := count + 1;
1846 }
1847 }
1848 }
1849 if (count >= n) {
1850 return true;
1851 } else {
1852 return false;
1853 }
1854}
1855
1856/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1857function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1858 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1859 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1860 }
1861}
1862
1863/* determine if a given SI vector contains given SI type at least once */
1864function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1865 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1866 var integer fn_mod51 := arr[i].frame_number mod 51;
1867 if (not bcch_ext and fn_mod51 == 2 or
1868 bcch_ext and fn_mod51 == 6) {
1869 if (arr[i].si.header.message_type != key) {
1870 return false;
1871 }
1872 }
1873 }
1874 return true;
1875}
1876
1877/* ensure a given TC slot of the SI vector contains only given SI type */
1878function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1879 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1880 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1881 }
1882}
1883
1884/* SI configuration of cell, against which we validate actual SI messages */
1885type set SystemInformationConfig {
1886 boolean bcch_extended,
1887 boolean si1_present,
1888 boolean si2bis_present,
1889 boolean si2ter_present,
1890 boolean si2quater_present,
1891 boolean si7_present,
1892 boolean si8_present,
1893 boolean si9_present,
1894 boolean si13_present,
1895 boolean si13alt_present,
1896 boolean si15_present,
1897 boolean si16_present,
1898 boolean si17_present,
1899 boolean si2n_present,
1900 boolean si21_present,
1901 boolean si22_present
1902}
1903
1904/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1905function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1906 var integer i;
1907 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1908 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001909 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001910 }
1911 }
1912 if (cfg.si1_present) {
1913 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1914 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
1915 * when TC = 0, it can assume that System Information Type 1 is not in use. */
1916 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1917 /* make sure *ALL* contain SI1 */
1918 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1919 }
1920 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
1921 /* iii) A SI 2 message will be sent at least every time TC = 1 */
1922 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
1923 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
1924 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
1925 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
1926
1927 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
1928 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
1929 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
1930 * consecutive occurrences of TC = 4. */
1931 if (cfg.si2bis_present and not cfg.si2ter_present) {
1932 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1933 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
1934 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
1935 } else if (cfg.si2ter_present and cfg.si2bis_present) {
1936 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1937 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
1938 }
1939
1940 if (cfg.si7_present or cfg.si8_present) {
1941 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
1942 * if System Information type 4 does not contain all information needed for cell
1943 * selection and reselection. */
1944 if (not cfg.bcch_extended) {
1945 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
1946 }
1947 if (cfg.si7_present) {
1948 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
1949 }
1950 if (cfg.si8_present) {
1951 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
1952 }
1953 }
1954
1955 if (cfg.si2quater_present) {
1956 /* iii) System information type 2 quater is sent if needed, as determined by the system
1957 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
1958 * and 2ter are used, otherwise it shall be sent at least once within any of 4
1959 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
1960 * within any of 4 consecutive occurrences of TC = 5. */
1961 if (not (cfg.bcch_extended)) {
1962 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
1963 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
1964 } else {
1965 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
1966 }
1967 } else {
1968 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
1969 }
1970 }
1971 if (cfg.si9_present) {
1972 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
1973 * in system information type 3 as defined in 3GPP TS 44.018. */
1974 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
1975 }
1976 if (cfg.si13_present) {
1977 /* vii) System Information type 13 is only related to the GPRS service. System Information
1978 * Type 13 need only be sent if GPRS support is indicated in one or more of System
1979 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
1980 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
1981 * In the case that the message is sent on the BCCH Norm, it is sent at least once
1982 * within any of 4 consecutive occurrences of TC=4. */
1983 if (not cfg.bcch_extended) {
1984 log("not-bccch-extended");
1985 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
1986 } else {
1987 log("bccch-extended");
1988 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
1989 }
1990 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
1991 setverdict(fail, "Cannot have SI13alt and SI13");
1992 }
1993 }
1994 if (cfg.si16_present or cfg.si17_present) {
1995 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
1996 * should not be sent in a cell where network sharing is used (see rule xv). */
1997 if (cfg.si22_present) {
1998 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1999 }
2000 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
2001 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2002 }
2003 if (not cfg.bcch_extended) {
2004 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2005 }
2006 if (cfg.si16_present) {
2007 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2008 }
2009 if (cfg.si17_present) {
2010 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2011 }
2012 }
2013
2014 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2015 * broadcast information. The frequency with which they are sent is determined by the
2016 * system operator. System Information type 9 identifies the scheduling of System
2017 * Information type 18 and 20 messages. */
2018
2019 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2020 * Information Type 19 is present, then its scheduling shall be indicated in System
2021 * Information Type 9. */
2022
2023 if (cfg.si15_present) {
2024 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2025 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2026 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2027 * 4 consecutive occurrences of TC = 1. */
2028 if (not cfg.bcch_extended) {
2029 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2030 } else {
2031 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2032 }
2033 }
2034 if (cfg.si13alt_present) {
2035 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2036 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2037 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2038 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2039 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2040 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2041 * of TC = 4. */
2042 if (cfg.si13_present) {
2043 testcase.stop("Error: Cannot have SI13alt and SI13");
2044 }
2045 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
2046 setverdict(fail, "Cannot have SI13alt and SI13");
2047 }
2048 if (not cfg.bcch_extended) {
2049 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2050 } else {
2051 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2052 }
2053 }
2054 if (cfg.si2n_present) {
2055 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2056 * as determined by the system operator. In the case that the message is sent on the
2057 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2058 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2059 * consecutive occurrences of TC = 4. */
2060 if (not cfg.bcch_extended) {
2061 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2062 } else {
2063 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2064 }
2065 }
2066 if (cfg.si21_present) {
2067 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2068 * determined by the system operator. If Extended Access Barring is in use in the cell
2069 * then this message is sent at least once within any of 4 consecutive occurrences of
2070 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2071 * cell then this message shall only be sent on BCCH Ext. */
2072 if (not cfg.bcch_extended) {
2073 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2074 } else {
2075 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2076 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
2077 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
2078 }
2079 }
2080 }
2081 if (cfg.si22_present) {
2082 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2083 * should not be sent in a cell where SoLSA is used (see rule viii). System
2084 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2085 * =2 and TC=6. */
2086 if (cfg.si16_present or cfg.si17_present) {
2087 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2088 }
2089 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2090 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
2091 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2092 }
2093 if (not cfg.bcch_extended) {
2094 testcase.stop("Error: SI22 requires BCCH Extd!");
2095 } else {
2096 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2097 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2098 }
2099 }
2100}
2101
2102/* sample Systme Information for specified duration via L1CTL */
2103function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2104 timer T := duration;
2105 var SystemInformationVectorPerTc si_per_tc;
2106 var L1ctlDlMessage l1_dl;
2107
2108 /* initialize all per-TC vectors empty */
2109 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2110 si_per_tc[i] := {};
2111 }
2112
2113 /* flush all previous L1 queued msgs */
2114 pt.clear;
2115
2116 T.start;
2117 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002118 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002119 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2120 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2121 log("Ignoring non-RR SI ", l1_dl);
2122 repeat;
2123 }
2124 var SystemInformationFn sig := {
2125 frame_number := l1_dl.dl_info.frame_nr,
2126 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2127 }
2128 var integer tc := f_gsm_compute_tc(sig.frame_number);
2129 log("SI received at TC=", tc, ": ", sig.si);
2130 /* append to the per-TC bucket */
2131 si_per_tc[tc] := si_per_tc[tc] & { sig };
2132 repeat;
2133 }
2134 [] pt.receive { repeat; }
2135 [] T.timeout { }
2136 }
2137
2138 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2139 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2140 }
2141 log("si_per_tc=", si_per_tc);
2142 return si_per_tc;
2143}
2144
2145/* helper function: Set given SI via RSL + validate scheduling.
2146 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2147function f_TC_si_sched() runs on test_CT {
2148 var SystemInformationVectorPerTc si_per_tc;
2149 f_init_l1ctl();
2150 f_l1_tune(L1CTL);
2151
2152 /* Sample + Validate Scheduling */
2153 si_per_tc := f_l1_sample_si(L1CTL);
2154 f_validate_si_scheduling(si_cfg, si_per_tc);
2155
2156 setverdict(pass);
2157}
2158
2159testcase TC_si_sched_default() runs on test_CT {
2160 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002161 /* 2+3+4 are mandatory and set in f_init() */
2162 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002163 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01002164}
2165
2166testcase TC_si_sched_1() runs on test_CT {
2167 f_init();
2168 si_cfg.si1_present := true;
2169 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002170 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002171 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002172}
2173
2174testcase TC_si_sched_2bis() runs on test_CT {
2175 f_init();
2176 si_cfg.si2bis_present := true;
2177 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2178 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002179 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002180}
2181
2182testcase TC_si_sched_2ter() runs on test_CT {
2183 f_init();
2184 si_cfg.si2ter_present := true;
2185 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2186 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002187 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002188}
2189
2190testcase TC_si_sched_2ter_2bis() runs on test_CT {
2191 f_init();
2192 si_cfg.si2bis_present := true;
2193 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2194 si_cfg.si2ter_present := true;
2195 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2196 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002197 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002198}
2199
2200testcase TC_si_sched_2quater() runs on test_CT {
2201 f_init();
2202 si_cfg.si2quater_present := true;
2203 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2204 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002205 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002206}
2207
2208testcase TC_si_sched_13() runs on test_CT {
2209 f_init();
2210 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002211 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002212 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002213 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002214}
2215
2216testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2217 f_init();
2218 si_cfg.si2bis_present := true;
2219 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2220 si_cfg.si2ter_present := true;
2221 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2222 si_cfg.si2quater_present := true;
2223 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2224 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002225 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002226 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002227 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002228}
2229
2230
Harald Welte68e495b2018-02-25 00:05:57 +01002231testcase TC_bcch_info() runs on test_CT {
2232 f_init(testcasename());
2233 /* FIXME: enable / disable individual BCCH info */
2234 //ts_RSL_BCCH_INFO(si_type, info);
2235 /* expect no ERROR REPORT after either of them *
2236 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01002237 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01002238}
2239
Harald Welte93640c62018-02-25 16:59:33 +01002240/***********************************************************************
2241 * Low-Level Protocol Errors / ERROR REPORT
2242 ***********************************************************************/
2243
Harald Welte01d982c2018-02-25 01:31:40 +01002244private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2245 timer T := 5.0;
2246 T.start;
2247 alt {
2248 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2249 setverdict(pass);
2250 }
2251 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
2252 setverdict(fail, "Wrong cause in RSL ERR REP");
2253 }
2254 [] RSL_CCHAN.receive {
2255 repeat;
2256 }
2257 [] T.timeout {
2258 setverdict(fail, "Timeout waiting for RSL ERR REP");
2259 }
2260 }
2261}
2262
2263/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2264testcase TC_rsl_protocol_error() runs on test_CT {
2265 f_init(testcasename());
2266 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2267 rsl.ies := omit;
2268 RSL_CCHAN.send(ts_RSL_UD(rsl));
2269
2270 f_exp_err_rep(RSL_ERR_PROTO);
2271}
2272
2273/* Provoke a mandatory IE error and match on ERROR REPORT */
2274testcase TC_rsl_mand_ie_error() runs on test_CT {
2275 f_init(testcasename());
2276
2277 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2278 rsl.ies := { rsl.ies[0] };
2279 RSL_CCHAN.send(ts_RSL_UD(rsl));
2280
2281 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2282}
2283
2284/* Provoke an IE content error and match on ERROR REPORT */
2285testcase TC_rsl_ie_content_error() runs on test_CT {
2286 f_init(testcasename());
2287 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2288 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2289 RSL_CCHAN.send(ts_RSL_UD(rsl));
2290
2291 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2292}
2293
Harald Welte93640c62018-02-25 16:59:33 +01002294/***********************************************************************
2295 * IPA CRCX/MDCX/DLCS media stream handling
2296 ***********************************************************************/
2297
Harald Weltea871a382018-02-25 02:03:14 +01002298/* Send IPA DLCX to inactive lchan */
2299function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002300 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2301 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002302}
2303testcase TC_ipa_dlcx_not_active() runs on test_CT {
2304 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2305 f_init(testcasename());
2306 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2307 vc_conn.done;
2308}
Harald Welte68e495b2018-02-25 00:05:57 +01002309
Harald Weltea3f1df92018-02-25 12:49:55 +01002310/* Send IPA CRCX twice to inactive lchan */
2311function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2312 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2313 "IPA CRCX ACK");
2314 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2315 "IPA CRCX NACK");
2316}
2317testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2318 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2319 f_init(testcasename());
2320 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2321 vc_conn.done;
2322}
2323
2324/* Regular sequence of CRCX/MDCX/DLCX */
2325function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2326 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2327 "IPA CRCX ACK");
2328 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2329 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2330 var uint7_t rtp_pt2 := f_rnd_int(127);
2331 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2332 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2333 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2334 "IPA MDCX ACK");
2335 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2336 "IPA DLCX ACK");
2337}
2338testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2339 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2340 f_init(testcasename());
2341 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2342 vc_conn.done;
2343}
2344
Harald Welte3ae11da2018-02-25 13:36:06 +01002345/* Sequence of CRCX, 2x MDCX, DLCX */
2346function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2347 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2348 "IPA CRCX ACK");
2349 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2350 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2351 var uint7_t rtp_pt2 := f_rnd_int(127);
2352 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2353 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2354 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2355 "IPA MDCX ACK");
2356 /* Second MDCX */
2357 remote_ip := f_rnd_int(c_UINT32_MAX);
2358 remote_port := f_rnd_int(c_UINT16_MAX);
2359 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2360 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2361 "IPA MDCX ACK");
2362 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2363 "IPA DLCX ACK");
2364}
2365testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2366 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2367 f_init(testcasename());
2368 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2369 vc_conn.done;
2370}
2371
Harald Welte9912eb52018-02-25 13:30:15 +01002372/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2373function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2374 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2375 "IPA CRCX NACK");
2376}
2377testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2378 var ConnHdlrPars pars;
2379 var ConnHdlr vc_conn;
2380 f_init(testcasename());
2381
2382 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2383 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2384 vc_conn.done;
2385
2386 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2387 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2388 vc_conn.done;
2389}
2390
Harald Weltea3f1df92018-02-25 12:49:55 +01002391
Harald Welte883340c2018-02-28 18:59:29 +01002392/***********************************************************************
2393 * PCU Socket related tests
2394 ***********************************************************************/
2395
2396private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2397runs on test_CT {
2398 timer T := 3.0;
2399
2400 /* we don't expect any RTS.req before PDCH are active */
2401 T.start;
2402 alt {
2403 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2404 setverdict(fail, "PCU RTS.req before PDCH active?");
2405 self.stop;
2406 }
2407 [] PCU.receive { repeat; }
2408 [] T.timeout { }
2409 }
2410
2411 /* Send PDCH activate request for known PDCH timeslot */
2412 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2413
2414 /* we now expect RTS.req for this timeslot (only) */
2415 T.start;
2416 alt {
2417 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2418 setverdict(pass);
2419 }
2420 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2421 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2422 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2423 self.stop;
2424 }
2425 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2426 setverdict(fail, "RTS.req for wrong TRX/TS");
2427 self.stop;
2428 }
2429 [] PCU.receive { repeat; }
2430 [exp_success] T.timeout {
2431 setverdict(fail, "Timeout waiting for PCU RTS.req");
2432 }
2433 [not exp_success] T.timeout {
2434 setverdict(pass);
2435 }
2436 }
2437}
2438
2439private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2440runs on test_CT {
2441 timer T := 3.0;
2442
2443 /* Send PDCH activate request for known PDCH timeslot */
2444 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2445
2446 PCU.clear;
2447 /* we now expect no RTS.req for this timeslot */
2448 T.start;
2449 alt {
2450 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2451 setverdict(fail, "Received unexpected PCU RTS.req");
2452 self.stop;
2453 }
2454 [] PCU.receive { repeat; }
2455 [] T.timeout {
2456 setverdict(pass);
2457 }
2458 }
2459}
2460
2461/* PDCH activation via PCU socket; check for presence of RTS.req */
2462testcase TC_pcu_act_req() runs on test_CT {
2463 f_init();
2464 f_TC_pcu_act_req(0, 0, 7, true);
2465}
2466
2467/* PDCH activation via PCU socket on non-PDCU timeslot */
2468testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2469 f_init();
2470 f_TC_pcu_act_req(0, 0, 1, false);
2471}
2472
2473/* PDCH activation via PCU socket on wrong BTS */
2474testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2475 f_init();
2476 f_TC_pcu_act_req(23, 0, 7, false);
2477}
2478
2479/* PDCH activation via PCU socket on wrong TRX */
2480testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2481 f_init();
2482 f_TC_pcu_act_req(0, 23, 7, false);
2483}
2484
2485/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2486testcase TC_pcu_deact_req() runs on test_CT {
2487 f_init();
2488 /* Activate PDCH */
2489 f_TC_pcu_act_req(0, 0, 7, true);
2490 f_sleep(1.0);
2491 /* and De-Activate again */
2492 f_TC_pcu_deact_req(0, 0, 7);
2493}
2494
2495/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2496testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2497 f_init();
2498 f_TC_pcu_deact_req(0, 0, 1);
2499}
2500
2501/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2502testcase TC_pcu_ver_si13() runs on test_CT {
2503 const octetstring si13 := '00010203040506070909'O;
2504 var PCUIF_send_data sd;
2505 timer T:= 3.0;
2506 f_init();
2507
2508 /* Set SI13 via RSL */
2509 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2510 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2511 T.start;
2512 alt {
2513 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2514 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2515 setverdict(pass);
2516 } else {
2517 repeat;
2518 }
2519 }
2520 [] PCU.receive { repeat; }
2521 [] T.timeout {
2522 setverdict(fail, "Timeout waiting for SI13");
2523 self.stop;
2524 }
2525 }
2526}
2527
2528private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2529
2530/* helper function to send a PCU DATA.req */
2531private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2532 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2533runs on test_CT
2534{
2535 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2536 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2537}
2538
2539/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2540private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2541 PCUIF_Sapi sapi, octetstring data)
2542runs on test_CT
2543{
2544 var PCUIF_send_data sd;
2545
2546 timer T := 3.0;
2547 T.start;
2548 alt {
2549 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2550 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2551 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2552 sd.data.u.rts_req.fn, sapi, data);
2553 }
2554 [] PCU.receive { repeat; }
2555 [] T.timeout {
2556 setverdict(fail, "Timeout waiting for RTS.ind");
2557 }
2558 }
2559}
2560
2561/* Send DATA.req on invalid BTS */
2562testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2563 f_init();
2564 f_TC_pcu_act_req(0, 0, 7, true);
2565 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2566 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2567 f_sleep(10.0);
2568}
2569
2570/* Send DATA.req on invalid TRX */
2571testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2572 f_init();
2573 f_TC_pcu_act_req(0, 0, 7, true);
2574 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2575 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2576 f_sleep(10.0);
2577}
2578
2579/* Send DATA.req on invalid timeslot */
2580testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2581 f_init();
2582 f_TC_pcu_act_req(0, 0, 7, true);
2583 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2584 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2585 f_sleep(10.0);
2586}
2587
2588/* Send DATA.req on timeslot that hasn't been activated */
2589testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2590 f_init();
2591 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2592 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2593 f_sleep(2.0);
2594}
2595
2596testcase TC_pcu_data_req_pdtch() runs on test_CT {
2597 f_init();
2598 f_TC_pcu_act_req(0, 0, 7, true);
2599 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2600 /* FIXME: how to check this was actually sent */
2601 f_sleep(2.0);
2602}
2603
2604testcase TC_pcu_data_req_ptcch() runs on test_CT {
2605 f_init();
2606 f_TC_pcu_act_req(0, 0, 7, true);
2607 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2608 /* FIXME: how to check this was actually sent */
2609 f_sleep(2.0);
2610}
2611
2612/* Send AGCH from PCU; check it appears on Um side */
2613testcase TC_pcu_data_req_agch() runs on test_CT {
2614 timer T := 3.0;
2615 f_init();
2616 f_init_l1ctl();
2617 f_l1_tune(L1CTL);
2618
2619 f_TC_pcu_act_req(0, 0, 7, true);
2620 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2621
2622 T.start;
2623 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002624 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002625 setverdict(pass);
2626 }
2627 [] L1CTL.receive { repeat; }
2628 [] T.timeout {
2629 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2630 }
2631 }
2632}
2633
2634/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2635testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2636 var octetstring imm_ass := f_rnd_octstring(23);
2637 f_init();
2638 f_init_l1ctl();
2639 f_l1_tune(L1CTL);
2640
2641 /* append 3 last imsi digits so BTS can compute pagng group */
2642 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2643
2644 timer T := 0.5;
2645 T.start;
2646 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002647 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002648 /* TODO: verify paging group */
2649 setverdict(pass);
2650 }
2651 [] L1CTL.receive { repeat; }
2652 [] T.timeout {
2653 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2654 }
2655 }
2656}
2657
2658/* Send RACH from Um side, expect it to show up on PCU socket */
2659testcase TC_pcu_rach_content() runs on test_CT {
2660 f_init();
2661 f_init_l1ctl();
2662 f_l1_tune(L1CTL);
2663
2664 var GsmFrameNumber fn_last := 0;
2665 for (var integer i := 0; i < 1000; i := i+1) {
2666 var OCT1 ra := f_rnd_ra_ps();
2667 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2668 if (fn == fn_last) {
2669 setverdict(fail, "Two RACH in same FN?!?");
2670 self.stop;
2671 }
2672 fn_last := fn;
2673
2674 timer T := 2.0;
2675 T.start;
2676 alt {
2677 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2678 T.stop;
2679 }
2680 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2681 setverdict(fail, "Unexpected RACH IND");
2682 self.stop;
2683 }
2684 [] PCU.receive { repeat; }
2685 [] T.timeout {
2686 setverdict(fail, "Timeout waiting for RACH IND");
2687 self.stop;
2688 }
2689 }
2690 }
2691 setverdict(pass);
2692}
2693
2694private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2695 var integer strlen := lengthof(str);
2696 for (var integer i := 0; i < len-strlen; i := i+1) {
2697 str := str & pad;
2698 }
2699 return str;
2700}
2701
2702/* Send PAGING via RSL, expect it to shw up on PCU socket */
2703testcase TC_pcu_paging_from_rsl() runs on test_CT {
2704 f_init();
2705
2706 for (var integer i := 0; i < 100; i := i+1) {
2707 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2708 timer T := 3.0;
2709 if (i < 50) {
2710 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2711 } else {
2712 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2713 }
2714 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2715 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2716 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2717
2718 /* Send RSL PAGING COMMAND */
2719 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2720 T.start;
2721 alt {
2722 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2723 }
2724 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2725 setverdict(fail, "Unexpected PAGING REQ");
2726 self.stop;
2727 }
2728 [] PCU.receive { repeat; }
2729 [] T.timeout {
2730 setverdict(fail, "Timeout waiting for PAGING REQ");
2731 self.stop;
2732 }
2733 }
2734 }
2735 setverdict(pass);
2736}
2737
Harald Welte3d04ae62018-04-04 20:29:05 +02002738/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002739 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002740 ***********************************************************************/
2741
2742private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2743runs on ConnHdlr {
2744 var PCUIF_send_data sd;
2745 /* Expect BTS to immediately acknowledge activation as PDCH */
2746 PCU.clear;
2747 f_rsl_chan_act(g_pars.chan_mode);
2748 /* expect INFO_IND on PCU interface listing TS as PDCH */
2749 alt {
2750 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2751 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2752 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2753 self.stop;
2754 }
2755 }
2756 [] PCU.receive { repeat; }
2757 }
2758 /* try to activate this PDCH from the PCU point of view */
2759 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2760 /* FIXME: is there a response? */
2761}
2762
2763private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2764runs on ConnHdlr {
2765 var PCUIF_send_data sd;
2766 /* Send RSL CHAN REL (deactivate) */
2767 PCU.clear;
2768 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2769 /* expect BTS to ask PCU to deactivate the channel */
2770 alt {
2771 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2772 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2773 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2774 self.stop;
2775 }
2776 }
2777 [] PCU.receive { repeat; }
2778 }
2779 /* Emulate PCU asking BTS to deactivate PDCH */
2780 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2781 alt {
2782 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2783 setverdict(pass);
2784 }
2785 [] RSL.receive { repeat; }
2786 }
2787}
2788
2789/* Activate Osmocom-style dynamic PDCH from BSC side */
2790function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2791 var PCUIF_Message first_info;
2792 var integer ts_nr := g_chan_nr.tn;
2793 var integer trx_nr := 0;
2794 var integer bts_nr := 0;
2795 var integer pcu_conn_id := -1;
2796
2797 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2798
2799 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2800 f_sleep(3.0);
2801 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2802 setverdict(pass);
2803}
2804testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2805 var ConnHdlrPars pars;
2806 var ConnHdlr vc_conn;
2807 f_init(testcasename());
2808
2809 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2810 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2811 vc_conn.done;
2812}
2813
2814/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2815function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2816 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002817 var integer pcu_conn_id := -1;
2818
2819 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2820
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02002821 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2822 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
2823 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02002824 setverdict(pass);
2825}
2826testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
2827 var ConnHdlrPars pars;
2828 var ConnHdlr vc_conn;
2829 f_init(testcasename());
2830
2831 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2832 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
2833 vc_conn.done;
2834}
2835
2836/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
2837function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
2838 var PCUIF_Message first_info;
2839 var integer ts_nr := g_chan_nr.tn;
2840 var integer trx_nr := 0;
2841 var integer bts_nr := 0;
2842 var integer pcu_conn_id := -1;
2843
2844 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2845
2846 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02002847 /* Send a second Chan Activ and expect it to be NACKed */
2848 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2849 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02002850 setverdict(pass);
2851}
2852testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
2853 var ConnHdlrPars pars;
2854 var ConnHdlr vc_conn;
2855 f_init(testcasename());
2856
2857 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2858 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
2859 vc_conn.done;
2860}
2861
2862/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
2863function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
2864 var PCUIF_Message first_info;
2865 var integer ts_nr := g_chan_nr.tn;
2866 var integer trx_nr := 0;
2867 var integer bts_nr := 0;
2868 var integer pcu_conn_id := -1;
2869 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
2870
2871 /* register for the TCH/F channel number */
2872 f_rslem_register(0, chan_nr);
2873
2874 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2875
2876 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
2877 "RSL CHAN ACT");
2878 setverdict(pass);
2879}
2880testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
2881 var ConnHdlrPars pars;
2882 var ConnHdlr vc_conn;
2883 f_init(testcasename());
2884
2885 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2886 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
2887 vc_conn.done;
2888}
2889
2890/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
2891function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
2892 var PCUIF_Message first_info;
2893 var integer ts_nr := g_chan_nr.tn;
2894 var integer trx_nr := 0;
2895 var integer bts_nr := 0;
2896 var integer pcu_conn_id := -1;
2897 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
2898 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
2899
2900 /* register for the TCH/H channel numbers */
2901 f_rslem_register(0, chan_nr[0]);
2902 f_rslem_register(0, chan_nr[1]);
2903
2904 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2905
2906 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
2907 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
2908 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
2909 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
2910 setverdict(pass);
2911}
2912testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
2913 var ConnHdlrPars pars;
2914 var ConnHdlr vc_conn;
2915 f_init(testcasename());
2916
2917 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2918 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
2919 vc_conn.done;
2920}
2921
Harald Welte9bbbfb52018-04-05 09:33:19 +02002922/***********************************************************************
2923 * IPA Style Dynamic Timeslot Support
2924 ***********************************************************************/
2925
2926private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2927runs on ConnHdlr {
2928 var PCUIF_send_data sd;
2929 /* Expect BTS to immediately acknowledge activation as PDCH */
2930 PCU.clear;
2931 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
2932 /* expect INFO_IND on PCU interface listing TS as PDCH */
2933 alt {
2934 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2935 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2936 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2937 self.stop;
2938 }
2939 }
2940 [] PCU.receive { repeat; }
2941 }
2942 /* try to activate this PDCH from the PCU point of view */
2943 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2944 /* FIXME: is there a response? */
2945
2946 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
2947}
2948
2949private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2950runs on ConnHdlr {
2951 var PCUIF_send_data sd;
2952 /* Send RSL CHAN REL (deactivate) */
2953 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
2954 PCU.clear;
2955 /* expect BTS to ask PCU to deactivate the channel */
2956 alt {
2957 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2958 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2959 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2960 self.stop;
2961 }
2962 }
2963 [] PCU.receive { repeat; }
2964 }
2965 /* Emulate PCU asking BTS to deactivate PDCH */
2966 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2967 alt {
2968 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
2969 setverdict(pass);
2970 }
2971 [] RSL.receive { repeat; }
2972 }
2973}
2974
2975/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
2976function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
2977 var PCUIF_Message first_info;
2978 var integer ts_nr := g_chan_nr.tn;
2979 var integer trx_nr := 0;
2980 var integer bts_nr := 0;
2981 var integer pcu_conn_id := -1;
2982
2983 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2984
2985 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2986 f_sleep(3.0);
2987 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2988
2989 setverdict(pass);
2990
2991}
2992testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
2993 var ConnHdlrPars pars;
2994 var ConnHdlr vc_conn;
2995 f_init();
2996
2997 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
2998 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
2999 vc_conn.done;
3000}
3001
3002/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
3003function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
3004 var PCUIF_Message first_info;
3005 var integer ts_nr := g_chan_nr.tn;
3006 var integer trx_nr := 0;
3007 var integer bts_nr := 0;
3008 var integer pcu_conn_id := -1;
3009
3010 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3011
3012 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3013 "RSL CHAN ACT");
3014 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3015 "RF CHAN REL", true);
3016 setverdict(pass);
3017}
3018testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
3019 var ConnHdlrPars pars;
3020 var ConnHdlr vc_conn;
3021 f_init(testcasename());
3022
3023 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3024 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
3025 vc_conn.done;
3026}
3027
3028/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
3029function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
3030 var PCUIF_Message first_info;
3031 var integer ts_nr := g_chan_nr.tn;
3032 var integer trx_nr := 0;
3033 var integer bts_nr := 0;
3034 var integer pcu_conn_id := -1;
3035
3036 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3037
3038 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
3039 "RSL CHAN ACT");
3040
3041 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3042 alt {
3043 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
3044 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
3045 setverdict(fail, "Unexpected PDCH ACT ACK");
3046 self.stop;
3047 }
3048 [] RSL.receive { repeat; }
3049 }
3050
3051 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
3052 "RF CHAN REL", true);
3053 setverdict(pass);
3054}
3055testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
3056 var ConnHdlrPars pars;
3057 var ConnHdlr vc_conn;
3058 f_init(testcasename());
3059
3060 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3061 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
3062 vc_conn.done;
3063}
3064
3065/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
3066function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
3067 var PCUIF_Message first_info;
3068 var integer ts_nr := g_chan_nr.tn;
3069 var integer trx_nr := 0;
3070 var integer bts_nr := 0;
3071 var integer pcu_conn_id := -1;
3072
3073 /* register for the TCH/F channel number */
3074 f_rslem_register(0, g_chan_nr);
3075
3076 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3077
3078 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3079
3080 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3081 "RSL CHAN ACT");
3082
3083 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3084
3085 setverdict(pass);
3086}
3087testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3088 var ConnHdlrPars pars;
3089 var ConnHdlr vc_conn;
3090 f_init(testcasename());
3091
3092 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3093 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3094 vc_conn.done;
3095}
3096
3097
Harald Welte0472ab42018-03-12 15:02:26 +01003098/***********************************************************************
3099 * LAPDm / RLL related
3100 ***********************************************************************/
3101
3102private function f_tx_lapdm(template (value) LapdmFrame l,
3103 template (value) RslLinkId link_id) runs on ConnHdlr {
3104 var octetstring l2 := enc_LapdmFrame(valueof(l));
3105 if (valueof(link_id.c) == SACCH) {
3106 /* prepend dummy L1 header */
3107 l2 := '0000'O & l2;
3108 }
3109 log("encoding ", l, " to ", l2);
3110 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
3111}
3112
3113type record RllTestCase {
3114 uint3_t sapi,
3115 RslLinkId link_id,
3116 octetstring l3,
3117 boolean exp
3118}
3119type record of RllTestCase RllTestCases;
3120template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3121 sapi := sapi,
3122 link_id := id,
3123 l3 := l3,
3124 exp := exp
3125}
3126
3127/* execute the same callback function with a set of different parameters (tcs) on a
3128 * variety of logical channels */
3129private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3130 var ConnHdlrPars pars;
3131 var ConnHdlr vc_conn;
3132 f_init(testcasename());
3133
3134 /* test on each of the channels we have */
3135 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3136 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3137
3138 /* test each of the test cases on the current channel */
3139 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3140 pars.spec.rll := tcs[j];
3141 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3142 vc_conn := f_start_handler(fn, pars);
3143 vc_conn.done;
3144 }
3145 }
3146
3147 f_shutdown();
3148}
3149
3150/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3151private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3152 var RllTestCase tc := g_pars.spec.rll;
3153 timer T := 3.0;
3154
3155 f_l1_tune(L1CTL);
3156 RSL.clear;
3157
3158 /* activate the logical channel */
3159 f_est_dchan();
3160 L1CTL.clear;
3161
3162 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3163 T.start;
3164 alt {
3165 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3166 if (tc.exp) {
3167 setverdict(pass);
3168 } else {
3169 setverdict(fail, "Unexpected EST IND with L3 in ", tc);
3170 }
3171 }
3172 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3173 if (tc.exp) {
3174 setverdict(pass);
3175 } else {
3176 setverdict(fail, "Unexpected EST IND without L3 in ", tc);
3177 }
3178 }
3179 [tc.exp] T.timeout {
3180 setverdict(fail, "Timeout waiting for EST IND");
3181 }
3182 [not tc.exp] T.timeout {
3183 setverdict(pass);
3184 }
3185 }
3186
3187 f_rsl_chan_deact();
3188 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3189 f_rslem_unregister(0, g_chan_nr);
3190}
3191testcase TC_rll_est_ind() runs on test_CT {
3192 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02003193 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01003194 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02003195 /* normal SAPI0 establishment */
3196 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01003197 /* SAPI 3 doesn't support contention resolution */
3198 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3199 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3200 /* normal SAPI3 establishment on main DCCH */
3201 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3202 /* normal SAPI3 establishment on SACCH */
3203 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3204 };
3205 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3206}
3207
3208/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3209private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3210 var RllTestCase tc := g_pars.spec.rll;
3211 var L1ctlDlMessage dl;
3212 timer T := 3.0;
3213
3214 f_l1_tune(L1CTL);
3215 RSL.clear;
3216
3217 /* activate the logical channel */
3218 f_est_dchan();
3219 L1CTL.clear;
3220
3221 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3222 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3223 T.start;
3224 alt {
3225 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3226 var LapdmFrame lapdm;
3227 var octetstring l2 := dl.payload.data_ind.payload;
3228 if (dl.dl_info.link_id.c == SACCH) {
3229 /* remove L1 header */
3230 l2 := substr(l2, 2, lengthof(l2)-2);
3231 }
3232 lapdm.ab := dec_LapdmFrameAB(l2);
3233 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3234 setverdict(pass);
3235 } else {
3236 repeat;
3237 }
3238 }
3239 [] L1CTL.receive { repeat; }
3240 [] T.timeout {
3241 setverdict(fail, "Timeout waiting for SABM");
3242 self.stop;
3243 }
3244 }
3245
3246 f_rsl_chan_deact();
3247 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3248 f_rslem_unregister(0, g_chan_nr);
3249}
3250testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3251 var RllTestCases tcs := {
3252 /* normal SAPI3 establishment on main DCCH */
3253 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3254 };
3255 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3256}
3257testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3258 var RllTestCases tcs := {
3259 /* normal SAPI3 establishment on SACCH */
3260 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3261 }
3262 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3263}
3264
3265/* altstep to receive a LAPDm frame matching the given template */
3266private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3267 var L1ctlDlMessage dl;
3268 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3269 var LapdmFrame lapdm;
3270 var octetstring l2 := dl.payload.data_ind.payload;
3271 if (dl.dl_info.link_id.c == SACCH) {
3272 /* remove L1 header */
3273 l2 := substr(l2, 2, lengthof(l2)-2);
3274 }
3275 if (ischosen(exp.ab)) {
3276 lapdm.ab := dec_LapdmFrameAB(l2);
3277 } else if (ischosen(exp.b4)) {
3278 lapdm.b4 := dec_LapdmFrameB4(l2);
3279 } else if (ischosen(exp.bbis)) {
3280 lapdm.bbis := dec_LapdmFrameBbis(l2);
3281 }
3282 log("Rx LAPDm ", lapdm);
3283 if (match(lapdm, exp)) {
3284 setverdict(pass);
3285 } else {
3286 repeat;
3287 }
3288 }
3289 [] L1CTL.receive { repeat; }
3290}
3291private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3292 timer T := t;
3293 T.start;
3294 alt {
3295 [] T.timeout {
3296 setverdict(fail, "Timeout waiting for LAPDm ", exp);
3297 self.stop;
3298 }
3299 [] as_l1_exp_lapdm(exp);
3300 }
3301}
3302
3303/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3304private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3305 /* send SABM from MS -> BTS */
3306 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3307 /* expect RLL EST IND on Abis */
3308 alt {
3309 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3310 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3311 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
3312 setverdict(fail, "Failing due to RSL_ERROR_IND");
3313 self.stop;
3314 }
3315 [] RSL.receive { repeat; }
3316 }
3317 /* expect UA from BTS -> MS */
3318 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3319}
3320
3321/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3322private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3323 var RllTestCase tc := g_pars.spec.rll;
3324
3325 f_l1_tune(L1CTL);
3326 RSL.clear;
3327
3328 /* activate the logical channel */
3329 f_est_dchan();
3330 L1CTL.clear;
3331
3332 /* first establish the link-layer */
3333 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3334
3335 /* then send the DISC */
3336 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3337 /* ... and expect the REL IND on the RSL side */
3338 alt {
3339 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3340 setverdict(pass);
3341 }
3342 }
3343
3344 /* release the channel */
3345 f_rsl_chan_deact();
3346 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3347 f_rslem_unregister(0, g_chan_nr);
3348}
3349testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3350 var RllTestCases tcs := {
3351 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3352 };
3353 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3354}
3355
3356testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3357 var RllTestCases tcs := {
3358 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3359 };
3360 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3361}
3362testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3363 var RllTestCases tcs := {
3364 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3365 };
3366 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3367}
3368testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3369 var RllTestCases tcs := {
3370 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3371 };
3372 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3373}
3374
3375/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3376private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3377 var RllTestCase tc := g_pars.spec.rll;
3378 f_l1_tune(L1CTL);
3379 RSL.clear;
3380
3381 /* activate the logical channel */
3382 f_est_dchan();
3383 L1CTL.clear;
3384
3385 /* first establish the link-layer */
3386 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3387
3388 /* then send the REL REQ via RSL */
3389 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3390 /* ... and expect the DISC on the Um side */
3391 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02003392 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01003393 /* FIXME: send a UA in resposne to the DISC */
3394 }
3395 }
3396
3397 /* release the channel */
3398 f_rsl_chan_deact();
3399 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3400 f_rslem_unregister(0, g_chan_nr);
3401}
3402testcase TC_rll_rel_req() runs on test_CT {
3403 var RllTestCases tcs := {
3404 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3405 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3406 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3407 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3408 };
3409 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3410}
3411
3412/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3413testcase TC_rll_data_req() runs on test_CT {
3414}
3415
3416/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3417testcase TC_rll_data_ind() runs on test_CT {
3418}
3419
3420/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3421private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3422 var RllTestCase tc := g_pars.spec.rll;
3423
3424 f_l1_tune(L1CTL);
3425 RSL.clear;
3426
3427 f_est_dchan();
3428 L1CTL.clear;
3429
3430 /* Send UNITDATA REQ on RSL side */
3431 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3432 /* Expect it to arrive on the other side */
3433 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02003434 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003435 } else {
Harald Weltee613f962018-04-18 22:38:16 +02003436 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01003437 }
3438
3439 /* release the channel */
3440 f_rsl_chan_deact();
3441 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3442 f_rslem_unregister(0, g_chan_nr);
3443}
3444testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3445 var octetstring l3 := f_rnd_octstring(15);
3446 var RllTestCases tcs := {
3447 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3448 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3449 };
3450 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3451}
3452testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3453 var octetstring l3 := f_rnd_octstring(19);
3454 var RllTestCases tcs := {
3455 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3456 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3457 };
3458 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3459}
3460
3461/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3462private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3463 var RllTestCase tc := g_pars.spec.rll;
3464
3465 f_l1_tune(L1CTL);
3466 RSL.clear;
3467
3468 f_est_dchan();
3469 L1CTL.clear;
3470
3471 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02003472 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01003473 /* Expdct RLL UNITDATA IND on RSL side */
3474 alt {
3475 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3476 setverdict(pass);
3477 }
3478 [] RSL.receive { repeat; }
3479 }
3480
3481 /* release the channel */
3482 f_rsl_chan_deact();
3483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3484 f_rslem_unregister(0, g_chan_nr);
3485}
3486testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
3487 var octetstring l3 := f_rnd_octstring(15);
3488 var RllTestCases tcs := {
3489 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3490 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3491 };
3492 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3493}
3494testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3495 var octetstring l3 := f_rnd_octstring(18);
3496 var RllTestCases tcs := {
3497 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3498 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3499 };
3500 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3501}
3502
Harald Weltee613f962018-04-18 22:38:16 +02003503/***********************************************************************
3504 * Encryption Related
3505 ***********************************************************************/
3506
3507/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3508function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3509 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
3510 if (link_id.c == SACCH) {
3511 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
3512 } else {
3513 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
3514 }
3515}
3516
3517/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3518function f_unitdata_mo(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3519 timer T := 3.0;
3520 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
3521 T.start;
3522 /* Expect RLL UNITDATA IND on RSL side */
3523 alt {
3524 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
3525 setverdict(pass);
3526 }
3527 [] T.timeout {
3528 setverdict(fail, "Timeout waiting for UNIT_DATA_IND");
3529 }
3530 [] RSL.receive { repeat; }
3531 }
3532}
3533
3534/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
3535function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
3536 f_l1_tune(L1CTL);
3537 f_est_dchan(true);
3538
3539 /* now we actually need to transmit some data both ways to check if the encryption works */
3540 var L1ctlDlMessage dl;
3541
3542 var octetstring l3 := f_rnd_octstring(16);
3543 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3544
3545 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
3546 f_unitdata_mt(link_id, l3);
3547
3548 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
3549 f_unitdata_mo(link_id, l3);
3550
3551 /* release the channel */
3552 f_rsl_chan_deact();
3553 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3554 f_rslem_unregister(0, g_chan_nr);
3555}
3556testcase TC_chan_act_a51() runs on test_CT {
3557 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3558 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3559 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3560}
3561testcase TC_chan_act_a52() runs on test_CT {
3562 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3563 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3564 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3565}
3566testcase TC_chan_act_a53() runs on test_CT {
3567 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3568 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3569 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
3570}
3571
3572
3573/* Test unencrypted channel activation followed by explicit ENCR CMD later */
3574function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
3575 /* L3 payload doesn't matter, as it is passed transparently */
3576 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
3577 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
3578 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3579
3580 f_l1_tune(L1CTL);
3581
3582 /* first establish a dedicated channel in the clear */
3583 f_est_dchan(false);
3584
3585 /* Establish ABM */
3586 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3587
3588 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
3589 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
3590 /* expect the L3 to arrive still unencrypted on the MS side */
3591 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
3592
3593 /* configure L1 to apply ciphering */
3594 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
3595 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
3596
3597 /* send first ciphered I-frame in response */
3598 l3 := '0a0b0c0d'O;
3599 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3600 RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3));
3601
3602 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
3603 * and hence enable encryption also on the downlink */
3604
3605 /* expect bi-directional communication work in encrypted mode */
3606 f_unitdata_mo(link_id, f_rnd_octstring(15));
3607 f_unitdata_mt(link_id, f_rnd_octstring(15));
3608
3609 /* release the channel */
3610 f_rsl_chan_deact();
3611 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3612 f_rslem_unregister(0, g_chan_nr);
3613}
3614testcase TC_encr_cmd_a51() runs on test_CT {
3615 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3616 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
3617 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3618}
3619testcase TC_encr_cmd_a52() runs on test_CT {
3620 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3621 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
3622 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3623}
3624testcase TC_encr_cmd_a53() runs on test_CT {
3625 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3626 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
3627 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
3628}
3629
3630private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
3631 var LapdmFrame lf;
3632 var octetstring reenc;
3633
3634 /* decode the LAPDm frame */
3635 if (ischosen(exp_match.ab)) {
3636 lf.ab := dec_LapdmFrameAB(enc);
3637 } else {
3638 setverdict(fail, "unsupported frame type");
3639 self.stop;
3640 }
3641
3642 /* check if decoder result matches expectation */
3643 if (not match(lf, exp_match)) {
3644 setverdict(fail, name, ": decoded LAPDm doesn't match");
3645 } else {
3646 log(name, ": matched");
3647 setverdict(pass);
3648 }
3649
3650 /* test if re-encoded frame equals original input */
3651 reenc := enc_LapdmFrame(lf);
3652 if (enc != reenc) {
3653 setverdict(fail, name, ": re-encoded LAPDm frame doesn't match");
3654 } else {
3655 setverdict(pass);
3656 }
3657}
3658
3659testcase TC_lapdm_selftest() runs on test_CT {
3660 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
3661 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
3662 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
3663 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
3664 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
3665 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
3666 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
3667}
3668
Harald Welte0472ab42018-03-12 15:02:26 +01003669
3670/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
3671/* protocol error as per 44.006 */
3672/* link layer failure (repetition of I-frame N200 times without ACK */
3673/* repetition of SABM or DISC N200 times without ACK */
3674/* receptiom of SABM in multi-frame established state */
3675
3676
3677
3678
Harald Welte883340c2018-02-28 18:59:29 +01003679
Harald Welte68e495b2018-02-25 00:05:57 +01003680/* TODO Areas:
3681
3682* channel activation
3683** with BS_Power / MS_Power, bypassing power control loop
3684** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01003685** with timing advance from initial activation on
3686* mode modify
3687** encryption
3688** multirate
3689* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01003690** unsupported algorithm
3691* handover detection
3692* MS Power Control
3693* BS Power Control
3694* Physical Context
3695* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01003696* CCCH Load Indication for PCH and RACH
3697* Delete Indication on AGCH overflow
3698* SMS Broadcast Req / Cmd / CBCH LOad Ind
3699* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01003700* error handling
3701* discriminator error
3702** type error
3703** sequence error
3704** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01003705* PCU interface
3706** TIME_IND from BTS->PCU
3707** DATA_IND from BTS->PCU
3708** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01003709
3710*/
Harald Welte70767382018-02-21 12:16:40 +01003711
3712control {
3713 execute( TC_chan_act_stress() );
3714 execute( TC_chan_act_react() );
3715 execute( TC_chan_deact_not_active() );
3716 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01003717 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01003718 execute( TC_sacch_filling() );
3719 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01003720 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01003721 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01003722 execute( TC_rach_content() );
3723 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01003724 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01003725 execute( TC_meas_res_sign_tchf() );
3726 execute( TC_meas_res_sign_tchh() );
3727 execute( TC_meas_res_sign_sdcch4() );
3728 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01003729 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01003730 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01003731 execute( TC_paging_imsi_80percent() );
3732 execute( TC_paging_tmsi_80percent() );
3733 execute( TC_paging_imsi_200percent() );
3734 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01003735 execute( TC_rsl_protocol_error() );
3736 execute( TC_rsl_mand_ie_error() );
3737 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01003738 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01003739 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01003740 execute( TC_si_sched_2bis() );
3741 execute( TC_si_sched_2ter() );
3742 execute( TC_si_sched_2ter_2bis() );
3743 execute( TC_si_sched_2quater() );
3744 execute( TC_si_sched_13() );
3745 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01003746 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01003747 execute( TC_ipa_crcx_twice_not_active() );
3748 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01003749 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01003750 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01003751
3752 execute( TC_pcu_act_req() );
3753 execute( TC_pcu_act_req_wrong_ts() );
3754 execute( TC_pcu_act_req_wrong_bts() );
3755 execute( TC_pcu_act_req_wrong_trx() );
3756 execute( TC_pcu_deact_req() );
3757 execute( TC_pcu_deact_req_wrong_ts() );
3758 execute( TC_pcu_ver_si13() );
3759 execute( TC_pcu_data_req_wrong_bts() );
3760 execute( TC_pcu_data_req_wrong_trx() );
3761 execute( TC_pcu_data_req_wrong_ts() );
3762 execute( TC_pcu_data_req_ts_inactive() );
3763 execute( TC_pcu_data_req_pdtch() );
3764 execute( TC_pcu_data_req_ptcch() );
3765 execute( TC_pcu_data_req_agch() );
3766 execute( TC_pcu_data_req_imm_ass_pch() );
3767 execute( TC_pcu_rach_content() );
3768 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02003769
3770 execute( TC_dyn_osmo_pdch_act_deact() );
3771 execute( TC_dyn_osmo_pdch_unsol_deact() );
3772 execute( TC_dyn_osmo_pdch_double_act() );
3773 execute( TC_dyn_osmo_pdch_tchf_act() );
3774 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02003775 execute( TC_dyn_ipa_pdch_act_deact() );
3776 execute( TC_dyn_ipa_pdch_tchf_act() );
3777 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
3778 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01003779
3780 execute( TC_rll_est_ind() );
3781 execute( TC_rll_est_req_DCCH_3() );
3782 execute( TC_rll_est_req_ACCH_3() );
3783 execute( TC_rll_rel_ind_DCCH_0() );
3784 execute( TC_rll_rel_ind_DCCH_3() );
3785 execute( TC_rll_rel_ind_ACCH_0() );
3786 execute( TC_rll_rel_ind_ACCH_3() );
3787 execute( TC_rll_rel_req() );
3788 execute( TC_rll_unit_data_req_DCCH() );
3789 execute( TC_rll_unit_data_req_ACCH() );
3790 execute( TC_rll_unit_data_ind_DCCH() );
3791 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02003792
3793 execute( TC_chan_act_a51() );
3794 execute( TC_chan_act_a52() );
3795 execute( TC_chan_act_a53() );
3796 execute( TC_encr_cmd_a51() );
3797 execute( TC_encr_cmd_a52() );
3798 execute( TC_encr_cmd_a53() );
3799
3800 execute( TC_lapdm_selftest() );
Harald Welte70767382018-02-21 12:16:40 +01003801}
3802
3803
3804}