blob: e7ee9e7ac30b4db8ee935ba884488b741c88d996 [file] [log] [blame]
Harald Weltef6dd64d2017-11-19 12:09:51 +01001module MSC_Tests {
2
3import from General_Types all;
4import from Osmocom_Types all;
5
6import from M3UA_Types all;
7import from M3UA_Emulation all;
8
9import from MTP3asp_Types all;
10import from MTP3asp_PortType all;
11
12import from SCCPasp_Types all;
13import from SCCP_Types all;
14import from SCCP_Emulation all;
15
16import from SCTPasp_Types all;
17import from SCTPasp_PortType all;
18
Harald Weltea49e36e2018-01-21 19:29:33 +010019import from Osmocom_CTRL_Functions all;
20import from Osmocom_CTRL_Types all;
21import from Osmocom_CTRL_Adapter all;
22
Harald Welte3ca1c902018-01-24 18:51:27 +010023import from TELNETasp_PortType all;
24import from Osmocom_VTY_Functions all;
25
Harald Weltea49e36e2018-01-21 19:29:33 +010026import from MNCC_Emulation all;
Harald Welte2bb825f2018-01-22 11:31:18 +010027import from MNCC_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010028
Harald Welte4aa970c2018-01-26 10:38:09 +010029import from MGCP_Emulation all;
30import from MGCP_Types all;
31import from MGCP_Templates all;
32import from SDP_Types all;
33
Harald Weltea49e36e2018-01-21 19:29:33 +010034import from GSUP_Emulation all;
35import from GSUP_Types all;
36import from IPA_Emulation all;
37
Harald Weltef6dd64d2017-11-19 12:09:51 +010038import from BSSAP_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010039import from BSSAP_Adapter all;
40import from BSSAP_CodecPort all;
41import from BSSMAP_Templates all;
42import from BSSMAP_Emulation all;
43import from BSC_ConnectionHandler all;
Harald Weltef6dd64d2017-11-19 12:09:51 +010044
Harald Weltea49e36e2018-01-21 19:29:33 +010045import from MobileL3_Types all;
46import from MobileL3_CommonIE_Types all;
47import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010048import from L3_Common all;
Harald Weltef6dd64d2017-11-19 12:09:51 +010049
Harald Weltef6dd64d2017-11-19 12:09:51 +010050
Harald Weltea4ca4462018-02-09 00:17:14 +010051type component MTC_CT extends CTRL_Adapter_CT {
Harald Weltef6dd64d2017-11-19 12:09:51 +010052 var boolean g_initialized := false;
Harald Weltea49e36e2018-01-21 19:29:33 +010053
Harald Weltea4ca4462018-02-09 00:17:14 +010054 var BSSAP_Adapter g_bssap;
55
Harald Weltea49e36e2018-01-21 19:29:33 +010056 /* no 'adapter_CT' for MNCC or GSUP */
57 var MNCC_Emulation_CT vc_MNCC;
Harald Welte4aa970c2018-01-26 10:38:09 +010058 var MGCP_Emulation_CT vc_MGCP;
Harald Weltea49e36e2018-01-21 19:29:33 +010059 var GSUP_Emulation_CT vc_GSUP;
60 var IPA_Emulation_CT vc_GSUP_IPA;
61
62 /* only to get events from IPA underneath GSUP */
63 port IPA_CTRL_PT GSUP_IPA_EVENT;
Harald Welte3ca1c902018-01-24 18:51:27 +010064 /* VTY to MSC */
65 port TELNETasp_PT MSCVTY;
Philipp Maier328d1662018-03-07 10:40:27 +010066
67 /* A port to directly send BSSAP messages. This port is used for
68 * tests that require low level access to sen arbitrary BSSAP
69 * messages. Run f_init_bssap_direct() to connect and initialize */
70 port BSSAP_CODEC_PT BSSAP_DIRECT;
71
72 /* When BSSAP messages are directly sent, then the connection
73 * handler is not active, which means that also no guard timer is
74 * set up. The following timer will serve as a replacement */
75 timer Tguard_direct := 60.0;
Harald Weltef6dd64d2017-11-19 12:09:51 +010076}
77
78modulepar {
Harald Weltea49e36e2018-01-21 19:29:33 +010079 /* remote parameters of IUT */
80 charstring mp_msc_ip := "127.0.0.1";
81 integer mp_msc_ctrl_port := 4255;
82 integer mp_msc_vty_port := 4254;
Harald Weltef6dd64d2017-11-19 12:09:51 +010083
Harald Weltea49e36e2018-01-21 19:29:33 +010084 /* local parameters of emulated HLR */
85 charstring mp_hlr_ip := "127.0.0.1";
86 integer mp_hlr_port := 4222;
Harald Welte6126fb02018-01-27 20:08:24 +010087 charstring mp_mgw_ip := "127.0.0.1";
88 integer mp_mgw_port := 2427;
Harald Weltef6dd64d2017-11-19 12:09:51 +010089
Harald Weltea49e36e2018-01-21 19:29:33 +010090 charstring mp_msc_mncc := "/tmp/mncc";
Harald Weltea4ca4462018-02-09 00:17:14 +010091
92 BSSAP_Configuration mp_bssap_cfg := {
93 sccp_service_type := "mtp3_itu",
94 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
95 own_pc := 185,
96 own_ssn := 254,
97 peer_pc := 187,
98 peer_ssn := 254
99 };
Harald Weltef6dd64d2017-11-19 12:09:51 +0100100}
101
Philipp Maier328d1662018-03-07 10:40:27 +0100102/* altstep for the global guard timer (only used when BSSAP_DIRECT
103 * is used for communication */
104private altstep as_Tguard_direct() runs on MTC_CT {
105 [] Tguard_direct.timeout {
106 setverdict(fail, "Tguard timeout");
107 self.stop;
108 }
109}
Harald Weltef6dd64d2017-11-19 12:09:51 +0100110
Harald Weltea49e36e2018-01-21 19:29:33 +0100111function f_init_mncc(charstring id) runs on MTC_CT {
112 id := id & "-MNCC";
113 var MnccOps ops := {
114 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
115 unitdata_cb := refers(MNCC_Emulation.DummyUnitdataCallback)
116 }
117
118 vc_MNCC := MNCC_Emulation_CT.create(id);
119 map(vc_MNCC:MNCC, system:MNCC_CODEC_PT);
120 vc_MNCC.start(MNCC_Emulation.main(ops, id, mp_msc_mncc));
Harald Weltef6dd64d2017-11-19 12:09:51 +0100121}
122
Harald Welte4aa970c2018-01-26 10:38:09 +0100123function f_init_mgcp(charstring id) runs on MTC_CT {
124 id := id & "-MGCP";
125 var MGCPOps ops := {
126 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
127 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
128 }
129 var MGCP_conn_parameters pars := {
Harald Welte6126fb02018-01-27 20:08:24 +0100130 callagent_ip := mp_msc_ip,
Harald Welte4aa970c2018-01-26 10:38:09 +0100131 callagent_udp_port := -1,
Harald Welte6126fb02018-01-27 20:08:24 +0100132 mgw_ip := mp_mgw_ip,
133 mgw_udp_port := mp_mgw_port
Harald Welte4aa970c2018-01-26 10:38:09 +0100134 }
135
136 vc_MGCP := MGCP_Emulation_CT.create(id);
137 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
138 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
139}
140
Harald Weltea49e36e2018-01-21 19:29:33 +0100141function f_init_gsup(charstring id) runs on MTC_CT {
142 id := id & "-GSUP";
143 var GsupOps ops := {
144 create_cb := refers(GSUP_Emulation.ExpectedCreateCallback)
145 }
146
147 vc_GSUP_IPA := IPA_Emulation_CT.create(id & "-IPA");
148 vc_GSUP := GSUP_Emulation_CT.create(id);
149
150 map(vc_GSUP_IPA:IPA_PORT, system:IPA_CODEC_PT);
151 connect(vc_GSUP:GSUP, vc_GSUP_IPA:IPA_GSUP_PORT);
152 /* we use this hack to get events like ASP_IPA_EVENT_UP */
153 connect(vc_GSUP_IPA:IPA_CTRL_PORT, self:GSUP_IPA_EVENT);
154
155 vc_GSUP.start(GSUP_Emulation.main(ops, id));
156 vc_GSUP_IPA.start(IPA_Emulation.main_server(mp_hlr_ip, mp_hlr_port));
157
158 /* wait for incoming connection to GSUP port before proceeding */
159 timer T := 10.0;
160 T.start;
161 alt {
162 [] GSUP_IPA_EVENT.receive(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_UP)) { }
163 [] T.timeout {
164 setverdict(inconc, "No connection to GSUP Port");
165 self.stop
166 }
167 }
Harald Weltef6dd64d2017-11-19 12:09:51 +0100168}
169
Harald Weltea49e36e2018-01-21 19:29:33 +0100170function f_init() runs on MTC_CT {
Harald Weltef6dd64d2017-11-19 12:09:51 +0100171
172 if (g_initialized == true) {
173 return;
174 }
175 g_initialized := true;
176
Harald Weltea4ca4462018-02-09 00:17:14 +0100177 f_bssap_init(g_bssap, mp_bssap_cfg, "MSC_Test", BSC_BssmapOps);
Harald Weltea49e36e2018-01-21 19:29:33 +0100178 f_ipa_ctrl_start(mp_msc_ip, mp_msc_ctrl_port);
179 f_init_mncc("MSC_Test");
Harald Welte4aa970c2018-01-26 10:38:09 +0100180 f_init_mgcp("MSC_Test");
Harald Weltea49e36e2018-01-21 19:29:33 +0100181 f_init_gsup("MSC_Test");
Harald Welte3ca1c902018-01-24 18:51:27 +0100182
183 map(self:MSCVTY, system:MSCVTY);
184 f_vty_set_prompts(MSCVTY);
185 f_vty_transceive(MSCVTY, "enable");
Harald Welteb14c77a2018-01-25 17:25:44 +0100186
187 /* set some defaults */
188 f_vty_config(MSCVTY, "network", "authentication optional");
189 f_vty_config(MSCVTY, "msc", "assign-tmsi");
190 f_vty_config(MSCVTY, "network", "encryption a5 0");
Harald Weltef6dd64d2017-11-19 12:09:51 +0100191}
192
Philipp Maier328d1662018-03-07 10:40:27 +0100193/* Initialize for a direct connection to BSSAP. This function is an alternative
194 * to f_init() when the high level functions of the BSC_ConnectionHandler are
195 * not needed. */
196function f_init_bssap_direct() runs on MTC_CT {
197 f_bssap_init(g_bssap, mp_bssap_cfg, "MSC_Test", omit);
198 connect(g_bssap.vc_SCCP:SCCP_SP_PORT, self:BSSAP_DIRECT);
199
200 /* Start guard timer and activate it as default */
201 Tguard_direct.start
202 activate(as_Tguard_direct());
203}
204
Harald Weltef6dd64d2017-11-19 12:09:51 +0100205template PDU_BSSAP ts_BSSAP_BSSMAP := {
206 discriminator := '0'B,
207 spare := '0000000'B,
208 dlci := omit,
209 lengthIndicator := 0, /* overwritten by codec */
210 pdu := ?
211}
212
213template PDU_BSSAP tr_BSSAP_BSSMAP := {
214 discriminator := '0'B,
215 spare := '0000000'B,
216 dlci := omit,
217 lengthIndicator := ?,
218 pdu := {
219 bssmap := ?
220 }
221}
222
223
224type integer BssmapCause;
225
226template (value) BSSMAP_IE_Cause ts_BSSMAP_IE_Cause(BssmapCause val) := {
227 elementIdentifier := '04'O,
228 lengthIndicator := 0,
229 causeValue := int2bit(val, 7),
230 extensionCauseValue := '0'B,
231 spare1 := omit
232}
233
234template (value) PDU_BSSAP ts_BSSMAP_Reset(BssmapCause cause) modifies ts_BSSAP_BSSMAP := {
235 pdu := {
236 bssmap := {
237 reset := {
238 messageType := '30'O,
239 cause := ts_BSSMAP_IE_Cause(cause),
240 a_InterfaceSelectorForReset := omit
241 }
242 }
243 }
244}
245
246template (value) PDU_BSSAP ts_BSSMAP_ResetAck modifies ts_BSSAP_BSSMAP := {
247 pdu := {
248 bssmap := {
249 resetAck := {
250 messageType := '31'O,
251 a_InterfaceSelectorForReset := omit
252 }
253 }
254 }
255}
256
257template PDU_BSSAP tr_BSSMAP_ResetAck modifies tr_BSSAP_BSSMAP := {
258 pdu := {
259 bssmap := {
260 resetAck := {
261 messageType := '31'O,
262 a_InterfaceSelectorForReset := *
263 }
264 }
265 }
266}
267
268template BSSMAP_IE_CellIdentifier ts_BSSMAP_IE_CellID := {
269 elementIdentifier := '05'O,
270 lengthIndicator := 0,
271 cellIdentifierDiscriminator := '0000'B,
272 spare1_4 := '0000'B,
273 cellIdentification := ?
274}
275
276type uint16_t BssmapLAC;
277type uint16_t BssmapCI;
278
279/*
280template BSSMAP_IE_CellIdentifier ts_CellId_CGI(mcc, mnc, lac, ci)
281modifies ts_BSSMAP_IE_CellID := {
282 cellIdentification := {
283 cI_LAC_CGI := {
284 mnc_mcc := FIXME,
285 lac := int2oct(lac, 2),
286 ci := int2oct(ci, 2)
287 }
288 }
289}
290*/
291
292template BSSMAP_IE_CellIdentifier ts_CellID_LAC_CI(BssmapLAC lac, BssmapCI ci)
293modifies ts_BSSMAP_IE_CellID := {
294 cellIdentification := {
295 cI_LAC_CI := {
296 lac := int2oct(lac, 2),
297 ci := int2oct(ci, 2)
298 }
299 }
300}
301
302template BSSMAP_IE_CellIdentifier ts_CellId_CI(BssmapCI ci)
303modifies ts_BSSMAP_IE_CellID := {
304 cellIdentification := {
305 cI_CI := int2oct(ci, 2)
306 }
307}
308
309template BSSMAP_IE_CellIdentifier ts_CellId_none
310modifies ts_BSSMAP_IE_CellID := {
311 cellIdentification := {
312 cI_noCell := ''O
313 }
314}
315
316
317template BSSMAP_IE_Layer3Information ts_BSSMAP_IE_L3Info(octetstring l3info) := {
318 elementIdentifier := '17'O,
319 lengthIndicator := 0,
320 layer3info := l3info
321}
322
323template PDU_BSSAP ts_BSSMAP_ComplL3(BSSMAP_IE_CellIdentifier cell_id, octetstring l3_info)
324modifies ts_BSSAP_BSSMAP := {
325 pdu := {
326 bssmap := {
327 completeLayer3Information := {
328 messageType := '57'O,
329 cellIdentifier := cell_id,
330 layer3Information := ts_BSSMAP_IE_L3Info(l3_info),
331 chosenChannel := omit,
332 lSAIdentifier := omit,
333 aPDU := omit,
334 codecList := omit,
335 redirectAttemptFlag := omit,
336 sendSequenceNumber := omit,
337 iMSI := omit
338 }
339 }
340 }
341}
342
343template PDU_BSSAP ts_BSSMAP_HandoReq(BssmapCause cause, BSSMAP_IE_CellIdentifierList cid_list)
344modifies ts_BSSAP_BSSMAP := {
345 pdu := {
346 bssmap := {
347 handoverRequired := {
348 messageType := '11'O,
349 cause := ts_BSSMAP_IE_Cause(cause),
350 responseRequest := omit,
351 cellIdentifierList := cid_list,
352 circuitPoolList := omit,
353 currentChannelType1 := omit,
354 speechVersion := omit,
355 queueingIndicator := omit,
356 oldToNewBSSInfo := omit,
357 sourceToTargetRNCTransparentInfo := omit,
358 sourceToTargetRNCTransparentInfoCDMA := omit,
359 gERANClassmark := omit,
360 talkerPriority := omit,
361 speechCodec := omit,
362 cSG_Identifier := omit
363 }
364 }
365 }
366}
367
Harald Weltea49e36e2018-01-21 19:29:33 +0100368type function void_fn(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr;
Harald Weltef6dd64d2017-11-19 12:09:51 +0100369
Harald Weltea49e36e2018-01-21 19:29:33 +0100370/* FIXME: move into BSC_ConnectionHandler? */
Neels Hofmeyr9adaa702018-03-01 20:23:19 +0100371function f_init_pars(integer imsi_suffix) runs on MTC_CT return BSC_ConnHdlrPars {
Harald Weltede371492018-01-27 23:44:41 +0100372 var BSC_ConnHdlrNetworkPars net_pars := {
373 kc_support := '0A'O, /* A5/1 and A5/3 enabled */
374 expect_tmsi := true,
375 expect_auth := false,
376 expect_ciph := false
377 };
Harald Weltea49e36e2018-01-21 19:29:33 +0100378 var BSC_ConnHdlrPars pars := {
Harald Weltea4ca4462018-02-09 00:17:14 +0100379 sccp_addr_own := g_bssap.sccp_addr_own,
380 sccp_addr_peer := g_bssap.sccp_addr_peer,
Harald Weltea49e36e2018-01-21 19:29:33 +0100381 cell_id := valueof(ts_CellId_CGI('262'H, '042'H, 23, 42)),
Harald Welte81b7f9d2018-01-24 19:06:24 +0100382 imei := f_gen_imei(imsi_suffix),
383 imsi := f_gen_imsi(imsi_suffix),
384 msisdn := f_gen_msisdn(imsi_suffix),
Harald Welte256571e2018-01-24 18:47:19 +0100385 tmsi := omit,
Harald Welte9de84792018-01-28 01:06:35 +0100386 cm1 := valueof(ts_CM1),
Harald Welte82600572018-01-21 20:54:08 +0100387 cm2 := valueof(ts_CM2_default),
Harald Welte16114282018-01-24 22:41:21 +0100388 cm3 := omit,
Harald Weltede371492018-01-27 23:44:41 +0100389 vec := omit,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100390 net := net_pars,
391 send_early_cm := true
Harald Weltea49e36e2018-01-21 19:29:33 +0100392 };
Neels Hofmeyr9adaa702018-03-01 20:23:19 +0100393 return pars;
394}
395
396function f_start_handler_with_pars(void_fn fn, BSC_ConnHdlrPars pars) runs on MTC_CT return BSC_ConnHdlr {
397 var BSC_ConnHdlr vc_conn;
398 var charstring id := testcasename();
Harald Weltea49e36e2018-01-21 19:29:33 +0100399
400 vc_conn := BSC_ConnHdlr.create(id);
401 /* BSSMAP part / A interface */
Harald Weltea4ca4462018-02-09 00:17:14 +0100402 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
403 connect(vc_conn:BSSAP_PROC, g_bssap.vc_BSSMAP:PROC);
Harald Weltea49e36e2018-01-21 19:29:33 +0100404 /* MNCC part */
405 connect(vc_conn:MNCC, vc_MNCC:MNCC_CLIENT);
406 connect(vc_conn:MNCC_PROC, vc_MNCC:MNCC_PROC);
Harald Welte4aa970c2018-01-26 10:38:09 +0100407 /* MGCP part */
408 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
409 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltea49e36e2018-01-21 19:29:33 +0100410 /* GSUP part */
411 connect(vc_conn:GSUP, vc_GSUP:GSUP_CLIENT);
412 connect(vc_conn:GSUP_PROC, vc_GSUP:GSUP_PROC);
413
Harald Weltea10db902018-01-27 12:44:49 +0100414 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
415 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
Harald Weltea49e36e2018-01-21 19:29:33 +0100416 vc_conn.start(derefers(fn)(id, pars));
417 return vc_conn;
418}
419
Neels Hofmeyr9adaa702018-03-01 20:23:19 +0100420function f_start_handler(void_fn fn, integer imsi_suffix) runs on MTC_CT return BSC_ConnHdlr {
421 return f_start_handler_with_pars(fn, f_init_pars(imsi_suffix));
422}
423
Harald Weltea49e36e2018-01-21 19:29:33 +0100424private function f_tc_lu_imsi_noauth_tmsi(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100425 f_init_handler(pars);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100426 f_perform_lu();
Harald Weltea49e36e2018-01-21 19:29:33 +0100427}
Harald Weltea49e36e2018-01-21 19:29:33 +0100428testcase TC_lu_imsi_noauth_tmsi() runs on MTC_CT {
429 var BSC_ConnHdlr vc_conn;
430 f_init();
431
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100432 vc_conn := f_start_handler(refers(f_tc_lu_imsi_noauth_tmsi), 1);
Harald Weltea49e36e2018-01-21 19:29:33 +0100433 vc_conn.done;
434}
435
436private function f_tc_lu_imsi_noauth_notmsi(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltede371492018-01-27 23:44:41 +0100437 pars.net.expect_tmsi := false;
Harald Weltea10db902018-01-27 12:44:49 +0100438 f_init_handler(pars);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100439 f_perform_lu();
Harald Weltea49e36e2018-01-21 19:29:33 +0100440}
Harald Weltea49e36e2018-01-21 19:29:33 +0100441testcase TC_lu_imsi_noauth_notmsi() runs on MTC_CT {
442 var BSC_ConnHdlr vc_conn;
443 f_init();
Harald Welte3ca1c902018-01-24 18:51:27 +0100444 f_vty_config(MSCVTY, "msc", "no assign-tmsi");
Harald Weltea49e36e2018-01-21 19:29:33 +0100445
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100446 vc_conn := f_start_handler(refers(f_tc_lu_imsi_noauth_notmsi), 2);
Harald Weltea49e36e2018-01-21 19:29:33 +0100447 vc_conn.done;
448}
449
450/* Do LU by IMSI, refuse it on GSUP and expect LU REJ back to MS */
451private function f_tc_lu_imsi_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100452 f_init_handler(pars);
Harald Weltea49e36e2018-01-21 19:29:33 +0100453 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi);
454
455 f_create_gsup_expect(hex2str(g_pars.imsi));
456 f_bssap_compl_l3(l3_lu);
457 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
458 GSUP.send(ts_GSUP_UL_ERR(g_pars.imsi, 23));
459 alt {
460 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(int2oct(23,1)))) { }
461 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) {
462 setverdict(fail, "Expecting LU REJ, but got ACCEPT");
463 self.stop;
464 }
465 }
Harald Welte1ddc7162018-01-27 14:25:46 +0100466 f_expect_clear();
Harald Weltea49e36e2018-01-21 19:29:33 +0100467}
468testcase TC_lu_imsi_reject() runs on MTC_CT {
469 var BSC_ConnHdlr vc_conn;
470 f_init();
471
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100472 vc_conn := f_start_handler(refers(f_tc_lu_imsi_reject), 3);
Harald Weltea49e36e2018-01-21 19:29:33 +0100473 vc_conn.done;
474}
475
476/* Do LU by IMSI, timeout on GSUP */
477private function f_tc_lu_imsi_timeout_gsup(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100478 f_init_handler(pars);
Harald Weltea49e36e2018-01-21 19:29:33 +0100479 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi);
480
481 f_create_gsup_expect(hex2str(g_pars.imsi));
482 f_bssap_compl_l3(l3_lu);
483 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
484 /* Normally the HLR would need to respond here, but we decide to force a timeout here */
485 alt {
486 /* FIXME: Expect specific reject cause */
487 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { }
488 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) {
489 setverdict(fail, "Expecting LU REJ, but got ACCEPT");
490 self.stop;
491 }
492 }
Harald Welte1ddc7162018-01-27 14:25:46 +0100493 f_expect_clear();
Harald Weltea49e36e2018-01-21 19:29:33 +0100494}
495testcase TC_lu_imsi_timeout_gsup() runs on MTC_CT {
496 var BSC_ConnHdlr vc_conn;
497 f_init();
498
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100499 vc_conn := f_start_handler(refers(f_tc_lu_imsi_timeout_gsup), 4);
Harald Weltea49e36e2018-01-21 19:29:33 +0100500 vc_conn.done;
501}
502
Harald Welte7b1b2812018-01-22 21:23:06 +0100503private function f_tc_lu_imsi_auth_tmsi(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltede371492018-01-27 23:44:41 +0100504 pars.net.expect_auth := true;
Harald Weltea10db902018-01-27 12:44:49 +0100505 f_init_handler(pars);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100506 f_perform_lu();
Harald Welte7b1b2812018-01-22 21:23:06 +0100507}
508testcase TC_lu_imsi_auth_tmsi() runs on MTC_CT {
509 var BSC_ConnHdlr vc_conn;
510 f_init();
Harald Welte3ca1c902018-01-24 18:51:27 +0100511 f_vty_config(MSCVTY, "network", "authentication required");
Harald Welte7b1b2812018-01-22 21:23:06 +0100512
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100513 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi), 5);
Harald Welte7b1b2812018-01-22 21:23:06 +0100514 vc_conn.done;
515}
516
Harald Weltea49e36e2018-01-21 19:29:33 +0100517
518/* Send CM SERVICE REQ for IMSI that has never performed LU before */
519private function f_tc_cmserv_imsi_unknown(charstring id, BSC_ConnHdlrPars pars)
520runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100521 f_init_handler(pars);
Harald Weltea49e36e2018-01-21 19:29:33 +0100522
523 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
524 var BSSMAP_IE_CellIdentifier cell_id := valueof(ts_CellId_CGI('262'H, '042'H, 23, 42));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100525 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
Harald Weltea49e36e2018-01-21 19:29:33 +0100526
527 f_create_gsup_expect(hex2str(g_pars.imsi));
528
529 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
530 f_bssap_compl_l3(l3_info);
531
532 timer T := 10.0;
Harald Weltef6dd64d2017-11-19 12:09:51 +0100533 T.start;
534 alt {
Harald Weltea49e36e2018-01-21 19:29:33 +0100535 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ)) { }
536 //[] BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC)) { }
537 [] BSSAP.receive { setverdict(fail, "Received unexpected BSSAP"); }
538 [] GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)) {
539 setverdict(fail, "Unexpected GSUP UL REQ");
540 }
Daniel Willmann90829d62018-02-15 17:45:14 +0100541 [] T.timeout { setverdict(fail, "Timeout waiting for CM SERV REQ"); }
Harald Weltef6dd64d2017-11-19 12:09:51 +0100542 }
543
Harald Welte1ddc7162018-01-27 14:25:46 +0100544 f_expect_clear();
Harald Weltef6dd64d2017-11-19 12:09:51 +0100545}
Harald Weltea49e36e2018-01-21 19:29:33 +0100546testcase TC_cmserv_imsi_unknown() runs on MTC_CT {
547 var BSC_ConnHdlr vc_conn;
548 f_init();
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100549 vc_conn := f_start_handler(refers(f_tc_cmserv_imsi_unknown), 6);
Harald Weltea49e36e2018-01-21 19:29:33 +0100550 vc_conn.done;
551}
552
Harald Welte2bb825f2018-01-22 11:31:18 +0100553private function f_tc_lu_and_mo_call(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100554 f_init_handler(pars);
Harald Welteb71901a2018-01-26 19:16:05 +0100555 var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
556 cpars.bss_rtp_port := 1110;
557 cpars.mgcp_connection_id_bss := '22222'H;
558 cpars.mgcp_connection_id_mss := '33333'H;
Harald Welte2bb825f2018-01-22 11:31:18 +0100559
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100560 f_perform_lu();
Harald Welteb71901a2018-01-26 19:16:05 +0100561 f_mo_call(cpars);
Harald Welte2bb825f2018-01-22 11:31:18 +0100562}
563testcase TC_lu_and_mo_call() runs on MTC_CT {
564 var BSC_ConnHdlr vc_conn;
565 f_init();
566
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100567 vc_conn := f_start_handler(refers(f_tc_lu_and_mo_call), 7);
Harald Welte071ed732018-01-23 19:53:52 +0100568 vc_conn.done;
569}
570
571/* Test LU (with authentication enabled), where HLR times out sending SAI response */
572private function f_tc_lu_auth_sai_timeout(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100573 f_init_handler(pars);
Harald Welte071ed732018-01-23 19:53:52 +0100574
575 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
576 var PDU_DTAP_MT dtap_mt;
577
578 /* tell GSUP dispatcher to send this IMSI to us */
579 f_create_gsup_expect(hex2str(g_pars.imsi));
580
581 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
582 f_bssap_compl_l3(l3_lu);
583
584 /* Send Early Classmark, just for the fun of it */
585 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
586
587 GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi));
588 /* The HLR would normally return an auth vector here, but we fail to do so. */
589
590 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej));
Harald Welte1ddc7162018-01-27 14:25:46 +0100591 f_expect_clear();
Harald Welte071ed732018-01-23 19:53:52 +0100592}
593testcase TC_lu_auth_sai_timeout() runs on MTC_CT {
594 var BSC_ConnHdlr vc_conn;
595 f_init();
Harald Welte3ca1c902018-01-24 18:51:27 +0100596 f_vty_config(MSCVTY, "network", "authentication required");
Harald Welte071ed732018-01-23 19:53:52 +0100597
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100598 vc_conn := f_start_handler(refers(f_tc_lu_auth_sai_timeout), 8);
Harald Welte071ed732018-01-23 19:53:52 +0100599 vc_conn.done;
600}
601
602/* Test LU (with authentication enabled), where HLR rejects sending SAI error */
603private function f_tc_lu_auth_sai_err(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100604 f_init_handler(pars);
Harald Welte071ed732018-01-23 19:53:52 +0100605
606 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
607 var PDU_DTAP_MT dtap_mt;
608
609 /* tell GSUP dispatcher to send this IMSI to us */
610 f_create_gsup_expect(hex2str(g_pars.imsi));
611
612 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
613 f_bssap_compl_l3(l3_lu);
614
615 /* Send Early Classmark, just for the fun of it */
616 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
617
618 GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi));
619 GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 13));
620
621 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej));
Harald Welte1ddc7162018-01-27 14:25:46 +0100622 f_expect_clear();
Harald Welte071ed732018-01-23 19:53:52 +0100623}
624testcase TC_lu_auth_sai_err() runs on MTC_CT {
625 var BSC_ConnHdlr vc_conn;
626 f_init();
Harald Welte3ca1c902018-01-24 18:51:27 +0100627 f_vty_config(MSCVTY, "network", "authentication required");
Harald Welte071ed732018-01-23 19:53:52 +0100628
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100629 vc_conn := f_start_handler(refers(f_tc_lu_auth_sai_err), 9);
Harald Welte2bb825f2018-01-22 11:31:18 +0100630 vc_conn.done;
631}
Harald Weltea49e36e2018-01-21 19:29:33 +0100632
Harald Weltebc881782018-01-23 20:09:15 +0100633/* Test LU but BSC will send a clear request in the middle */
634private function f_tc_lu_clear_request(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100635 f_init_handler(pars);
Harald Weltebc881782018-01-23 20:09:15 +0100636
637 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
638 var PDU_DTAP_MT dtap_mt;
639
640 /* tell GSUP dispatcher to send this IMSI to us */
641 f_create_gsup_expect(hex2str(g_pars.imsi));
642
643 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
644 f_bssap_compl_l3(l3_lu);
645
646 /* Send Early Classmark, just for the fun of it */
647 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
648
649 f_sleep(1.0);
650 /* send clear request in the middle of the LU */
651 BSSAP.send(ts_BSSMAP_ClearRequest(0));
652 BSSAP.receive(tr_BSSMAP_ClearCommand);
653 BSSAP.send(ts_BSSMAP_ClearComplete);
Harald Welte89a32492018-01-27 19:07:28 +0100654 alt {
655 /* See https://osmocom.org/issues/2862 */
656 [] BSSAP.receive(tr_BSSMAP_ClearCommand) { repeat; }
657 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {}
658 }
Harald Weltebc881782018-01-23 20:09:15 +0100659 setverdict(pass);
660}
661testcase TC_lu_clear_request() runs on MTC_CT {
662 var BSC_ConnHdlr vc_conn;
663 f_init();
664
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100665 vc_conn := f_start_handler(refers(f_tc_lu_clear_request), 10);
Harald Weltebc881782018-01-23 20:09:15 +0100666 vc_conn.done;
667}
668
Harald Welte66af9e62018-01-24 17:28:21 +0100669/* Test LU but BSC will send a clear request in the middle */
670private function f_tc_lu_disconnect(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100671 f_init_handler(pars);
Harald Welte66af9e62018-01-24 17:28:21 +0100672
673 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
674 var PDU_DTAP_MT dtap_mt;
675
676 /* tell GSUP dispatcher to send this IMSI to us */
677 f_create_gsup_expect(hex2str(g_pars.imsi));
678
679 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
680 f_bssap_compl_l3(l3_lu);
681
682 /* Send Early Classmark, just for the fun of it */
683 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
684
685 f_sleep(1.0);
686 /* send clear request in the middle of the LU */
687 BSSAP.send(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
688 setverdict(pass);
689}
690testcase TC_lu_disconnect() runs on MTC_CT {
691 var BSC_ConnHdlr vc_conn;
692 f_init();
693
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100694 vc_conn := f_start_handler(refers(f_tc_lu_disconnect), 11);
Harald Welte66af9e62018-01-24 17:28:21 +0100695 vc_conn.done;
696}
697
698
Harald Welteba7b6d92018-01-23 21:32:34 +0100699/* Test LU but with illegal mobile identity type = IMEI */
700private function f_tc_lu_by_imei(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100701 f_init_handler(pars);
Harald Welteba7b6d92018-01-23 21:32:34 +0100702
Harald Welte256571e2018-01-24 18:47:19 +0100703 var PDU_ML3_MS_NW l3_lu := f_build_lu_imei(g_pars.imei)
Harald Welteba7b6d92018-01-23 21:32:34 +0100704 var PDU_DTAP_MT dtap_mt;
705
706 /* tell GSUP dispatcher to send this IMSI to us */
707 f_create_gsup_expect(hex2str(g_pars.imsi));
708
709 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
710 f_bssap_compl_l3(l3_lu);
711
712 /* Send Early Classmark, just for the fun of it */
713 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
714 /* wait for LU reject, ignore any ID REQ */
715 alt {
716 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { }
717 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req)) { repeat; }
718 }
719 /* wait for normal teardown */
Harald Welte1ddc7162018-01-27 14:25:46 +0100720 f_expect_clear();
Harald Welteba7b6d92018-01-23 21:32:34 +0100721}
722testcase TC_lu_by_imei() runs on MTC_CT {
723 var BSC_ConnHdlr vc_conn;
724 f_init();
725
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100726 vc_conn := f_start_handler(refers(f_tc_lu_by_imei), 12);
Harald Welteba7b6d92018-01-23 21:32:34 +0100727 vc_conn.done;
728}
729
730/* Test LU by TMSI with unknown TMSI, expect (and answer) ID REQ. */
731private function f_tc_lu_tmsi_noauth_unknown(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100732 f_init_handler(pars);
Harald Welteba7b6d92018-01-23 21:32:34 +0100733
734 var PDU_ML3_MS_NW l3_lu := f_build_lu_tmsi('01020304'O); /* FIXME: Random */
735 var PDU_DTAP_MT dtap_mt;
736
737 /* tell GSUP dispatcher to send this IMSI to us */
738 f_create_gsup_expect(hex2str(g_pars.imsi));
739
740 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
741 f_bssap_compl_l3(l3_lu);
742
743 /* Send Early Classmark, just for the fun of it */
744 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
745
746 /* Wait for + respond to ID REQ (IMSI) */
747 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req('001'B)));
748 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp_IMSI(g_pars.imsi)));
749
750 /* Expect MSC to do UpdateLocation to HLR; respond to it */
751 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
752 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
753 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
754 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
755
756 alt {
Harald Welte7ec4fa82018-01-27 10:57:40 +0100757 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) {
758 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
759 }
Harald Welteba7b6d92018-01-23 21:32:34 +0100760 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
761 setverdict(fail, "Expected LU ACK, but received REJ");
762 }
763 }
764
765 /* wait for normal teardown */
Harald Welte1ddc7162018-01-27 14:25:46 +0100766 f_expect_clear();
Harald Welteba7b6d92018-01-23 21:32:34 +0100767}
768testcase TC_lu_by_tmsi_noauth_unknown() runs on MTC_CT {
769 var BSC_ConnHdlr vc_conn;
770 f_init();
771
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100772 vc_conn := f_start_handler(refers(f_tc_lu_tmsi_noauth_unknown), 13);
Harald Welteba7b6d92018-01-23 21:32:34 +0100773 vc_conn.done;
774}
775
776
Harald Welte45164da2018-01-24 12:51:27 +0100777/* Test IMSI DETACH (MI=IMSI) */
778private function f_tc_imsi_detach_by_imsi(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100779 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100780
781 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
782
783 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
784 f_bssap_compl_l3(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(mi)));
785
786 /* Send Early Classmark, just for the fun of it? */
787 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
788
789 /* wait for normal teardown */
Harald Welte1ddc7162018-01-27 14:25:46 +0100790 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100791}
792testcase TC_imsi_detach_by_imsi() runs on MTC_CT {
793 var BSC_ConnHdlr vc_conn;
794 f_init();
795
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100796 vc_conn := f_start_handler(refers(f_tc_imsi_detach_by_imsi), 14);
Harald Welte45164da2018-01-24 12:51:27 +0100797 vc_conn.done;
798}
799
800/* Test IMSI DETACH (MI=TMSI) */
801private function f_tc_imsi_detach_by_tmsi(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100802 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100803
804 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV('01020304'O));
805
806 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
807 f_bssap_compl_l3(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(mi)));
808
809 /* Send Early Classmark, just for the fun of it? */
810 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
811
812 /* wait for normal teardown */
Harald Welte1ddc7162018-01-27 14:25:46 +0100813 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100814}
815testcase TC_imsi_detach_by_tmsi() runs on MTC_CT {
816 var BSC_ConnHdlr vc_conn;
817 f_init();
818
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100819 vc_conn := f_start_handler(refers(f_tc_imsi_detach_by_tmsi), 15);
Harald Welte45164da2018-01-24 12:51:27 +0100820 vc_conn.done;
821}
822
823/* Test IMSI DETACH (MI=IMEI), which is illegal */
824private function f_tc_imsi_detach_by_imei(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100825 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100826
Harald Welte256571e2018-01-24 18:47:19 +0100827 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
Harald Welte45164da2018-01-24 12:51:27 +0100828
829 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
830 f_bssap_compl_l3(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(mi)));
831
832 /* Send Early Classmark, just for the fun of it? */
833 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
834
835 /* wait for normal teardown */
Harald Welte1ddc7162018-01-27 14:25:46 +0100836 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100837}
838testcase TC_imsi_detach_by_imei() runs on MTC_CT {
839 var BSC_ConnHdlr vc_conn;
840 f_init();
841
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100842 vc_conn := f_start_handler(refers(f_tc_imsi_detach_by_imei), 16);
Harald Welte45164da2018-01-24 12:51:27 +0100843 vc_conn.done;
844}
845
846
847/* helper function for an emergency call. caller passes in mobile identity to use */
848private function f_emerg_call(MobileIdentityLV mi) runs on BSC_ConnHdlr {
Harald Welte0bef21e2018-02-10 09:48:23 +0100849 var CallParameters cpars := valueof(t_CallParams('112'H, 0));
850 cpars.emergency := true;
Harald Welte45164da2018-01-24 12:51:27 +0100851
Harald Welte0bef21e2018-02-10 09:48:23 +0100852 f_mo_call(cpars);
Harald Welte45164da2018-01-24 12:51:27 +0100853}
854
855/* establish an emergency call by IMEI, no SIM inserted (and hence no IMSI) */
856private function f_tc_emerg_call_imei_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100857 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100858
Harald Welte256571e2018-01-24 18:47:19 +0100859 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100860 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
Harald Welte45164da2018-01-24 12:51:27 +0100861 f_bssap_compl_l3(l3_info);
862 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ('05'O)));
Harald Welte1ddc7162018-01-27 14:25:46 +0100863 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100864}
865testcase TC_emerg_call_imei_reject() runs on MTC_CT {
866 var BSC_ConnHdlr vc_conn;
867 f_init();
868
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100869 vc_conn := f_start_handler(refers(f_tc_emerg_call_imei_reject), 17);
Harald Welte45164da2018-01-24 12:51:27 +0100870 vc_conn.done;
871}
872
Harald Welted5b91402018-01-24 18:48:16 +0100873/* establish an emergency call by IMSI, SIM inserted (and hence IMSI) */
Harald Welte45164da2018-01-24 12:51:27 +0100874private function f_tc_emerg_call_imsi(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100875 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100876 /* First perform location update to ensure subscriber is known */
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100877 f_perform_lu();
Harald Welte45164da2018-01-24 12:51:27 +0100878 /* Then issue emergency call identified by IMSI */
879 f_emerg_call(valueof(ts_MI_IMSI_LV(g_pars.imsi)));
880}
881testcase TC_emerg_call_imsi() runs on MTC_CT {
882 var BSC_ConnHdlr vc_conn;
883 f_init();
884
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100885 vc_conn := f_start_handler(refers(f_tc_emerg_call_imsi), 18);
Harald Welte45164da2018-01-24 12:51:27 +0100886 vc_conn.done;
887}
888
889/* CM Service Request for VGCS -> reject */
890private function f_tc_cm_serv_req_vgcs_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100891 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100892
893 /* First perform location update to ensure subscriber is known */
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100894 f_perform_lu();
Harald Welte45164da2018-01-24 12:51:27 +0100895
896 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100897 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VGCS, mi));
Harald Welte45164da2018-01-24 12:51:27 +0100898 f_bssap_compl_l3(l3_info);
899 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ(int2oct(32,1))));
Harald Welte1ddc7162018-01-27 14:25:46 +0100900 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100901}
902testcase TC_cm_serv_req_vgcs_reject() runs on MTC_CT {
903 var BSC_ConnHdlr vc_conn;
904 f_init();
905
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100906 vc_conn := f_start_handler(refers(f_tc_cm_serv_req_vgcs_reject), 19);
Harald Welte45164da2018-01-24 12:51:27 +0100907 vc_conn.done;
908}
909
910/* CM Service Request for VBS -> reject */
911private function f_tc_cm_serv_req_vbs_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100912 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100913
914 /* First perform location update to ensure subscriber is known */
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100915 f_perform_lu();
Harald Welte45164da2018-01-24 12:51:27 +0100916
917 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100918 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VBS, mi));
Harald Welte45164da2018-01-24 12:51:27 +0100919 f_bssap_compl_l3(l3_info);
920 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ(int2oct(32,1))));
Harald Welte1ddc7162018-01-27 14:25:46 +0100921 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100922}
923testcase TC_cm_serv_req_vbs_reject() runs on MTC_CT {
924 var BSC_ConnHdlr vc_conn;
925 f_init();
926
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100927 vc_conn := f_start_handler(refers(f_tc_cm_serv_req_vbs_reject), 20);
Harald Welte45164da2018-01-24 12:51:27 +0100928 vc_conn.done;
929}
930
931/* CM Service Request for LCS -> reject */
932private function f_tc_cm_serv_req_lcs_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100933 f_init_handler(pars);
Harald Welte45164da2018-01-24 12:51:27 +0100934
935 /* First perform location update to ensure subscriber is known */
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100936 f_perform_lu();
Harald Welte45164da2018-01-24 12:51:27 +0100937
938 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100939 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_LCS, mi));
Harald Welte45164da2018-01-24 12:51:27 +0100940 f_bssap_compl_l3(l3_info);
941 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ(int2oct(32,1))));
Harald Welte1ddc7162018-01-27 14:25:46 +0100942 f_expect_clear();
Harald Welte45164da2018-01-24 12:51:27 +0100943}
944testcase TC_cm_serv_req_lcs_reject() runs on MTC_CT {
945 var BSC_ConnHdlr vc_conn;
946 f_init();
947
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100948 vc_conn := f_start_handler(refers(f_tc_cm_serv_req_lcs_reject), 21);
Harald Welte45164da2018-01-24 12:51:27 +0100949 vc_conn.done;
950}
951
Harald Welte0195ab12018-01-24 21:50:20 +0100952/* CM Re-Establishment Request */
953private function f_tc_cm_reest_req_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100954 f_init_handler(pars);
Harald Welte0195ab12018-01-24 21:50:20 +0100955
956 /* First perform location update to ensure subscriber is known */
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100957 f_perform_lu();
Harald Welte0195ab12018-01-24 21:50:20 +0100958
959 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
960 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REEST_REQ(0, mi));
961 f_bssap_compl_l3(l3_info);
962 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ(int2oct(32,1))));
Harald Welte1ddc7162018-01-27 14:25:46 +0100963 f_expect_clear();
Harald Welte0195ab12018-01-24 21:50:20 +0100964}
965testcase TC_cm_reest_req_reject() runs on MTC_CT {
966 var BSC_ConnHdlr vc_conn;
967 f_init();
Harald Welte0195ab12018-01-24 21:50:20 +0100968
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +0100969 vc_conn := f_start_handler(refers(f_tc_cm_reest_req_reject), 22);
Harald Welte0195ab12018-01-24 21:50:20 +0100970 vc_conn.done;
971}
972
Harald Weltec638f4d2018-01-24 22:00:36 +0100973/* Test LU (with authentication enabled), with wrong response from MS */
974private function f_tc_lu_auth_2G_fail(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100975 f_init_handler(pars);
Harald Weltec638f4d2018-01-24 22:00:36 +0100976
977 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
978
979 /* tell GSUP dispatcher to send this IMSI to us */
980 f_create_gsup_expect(hex2str(g_pars.imsi));
981
982 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
983 f_bssap_compl_l3(l3_lu);
984
985 /* Send Early Classmark, just for the fun of it */
986 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
987
988 var AuthVector vec := f_gen_auth_vec_2g();
989 var GSUP_IE auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(vec.rand, vec.sres, vec.kc));
990 GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi));
991 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
992
993 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(vec.rand)));
994 /* Send back wrong auth response */
995 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G('00000000'O)));
996
997 /* Expect GSUP AUTH FAIL REP to HLR */
998 GSUP.receive(tr_GSUP_AUTH_FAIL_IND(g_pars.imsi));
999
1000 /* Expect LU REJECT with Cause == Illegal MS */
1001 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej('03'O)));
Harald Welte1ddc7162018-01-27 14:25:46 +01001002 f_expect_clear();
Harald Weltec638f4d2018-01-24 22:00:36 +01001003}
1004testcase TC_lu_auth_2G_fail() runs on MTC_CT {
1005 var BSC_ConnHdlr vc_conn;
1006 f_init();
1007 f_vty_config(MSCVTY, "network", "authentication required");
Harald Weltec638f4d2018-01-24 22:00:36 +01001008
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001009 vc_conn := f_start_handler(refers(f_tc_lu_auth_2G_fail), 23);
Harald Weltec638f4d2018-01-24 22:00:36 +01001010 vc_conn.done;
1011}
1012
Harald Weltede371492018-01-27 23:44:41 +01001013/* A5/1 + A5/3 permitted on network side, and MS capable to do it */
Harald Welte16114282018-01-24 22:41:21 +01001014private function f_tc_lu_imsi_auth_tmsi_encr_13_13(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltede371492018-01-27 23:44:41 +01001015 pars.net.expect_auth := true;
1016 pars.net.expect_ciph := true;
Harald Weltea10db902018-01-27 12:44:49 +01001017 f_init_handler(pars);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001018 f_perform_lu();
Harald Welte16114282018-01-24 22:41:21 +01001019}
1020testcase TC_lu_imsi_auth_tmsi_encr_13_13() runs on MTC_CT {
1021 var BSC_ConnHdlr vc_conn;
1022 f_init();
1023 f_vty_config(MSCVTY, "network", "authentication required");
Harald Welte16114282018-01-24 22:41:21 +01001024 f_vty_config(MSCVTY, "network", "encryption a5 1 3");
1025
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001026 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_13_13), 24);
Harald Welte16114282018-01-24 22:41:21 +01001027 vc_conn.done;
1028}
1029
Harald Welte1af6ea82018-01-25 18:33:15 +01001030/* Test Complete L3 without payload */
1031private function f_tc_cl3_no_payload(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001032 f_init_handler(pars);
Harald Welte1af6ea82018-01-25 18:33:15 +01001033
1034 /* Send Complete L3 Info with empty L3 frame */
1035 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
1036 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, ''O))));
1037
Harald Weltef466eb42018-01-27 14:26:54 +01001038 timer T := 5.0;
1039 T.start;
Harald Welte1af6ea82018-01-25 18:33:15 +01001040 alt {
1041 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {}
1042 /* Expect LU REJECT with Cause == Illegal MS */
1043 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1044 BSSAP.send(ts_BSSMAP_ClearComplete);
1045 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1046 }
Harald Weltef466eb42018-01-27 14:26:54 +01001047 [] T.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +01001048 setverdict(fail, "Timeout waiting for ClearCommand or SCCP Release");
Harald Weltef466eb42018-01-27 14:26:54 +01001049 self.stop;
1050 }
Harald Welte1af6ea82018-01-25 18:33:15 +01001051 }
1052 setverdict(pass);
1053}
1054testcase TC_cl3_no_payload() runs on MTC_CT {
1055 var BSC_ConnHdlr vc_conn;
1056 f_init();
1057
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001058 vc_conn := f_start_handler(refers(f_tc_cl3_no_payload), 25);
Harald Welte1af6ea82018-01-25 18:33:15 +01001059 vc_conn.done;
1060}
1061
1062/* Test Complete L3 with random payload */
1063private function f_tc_cl3_rnd_payload(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001064 f_init_handler(pars);
Harald Welte1af6ea82018-01-25 18:33:15 +01001065
1066 var integer len := float2int(rnd() * 256.0);
1067 var octetstring payl := f_rnd_octstring(len);
1068
1069 /* Send Complete L3 Info with empty L3 frame */
1070 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
1071 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, payl))));
1072
Harald Weltef466eb42018-01-27 14:26:54 +01001073 timer T := 5.0;
1074 T.start;
Harald Welte1af6ea82018-01-25 18:33:15 +01001075 alt {
1076 /* Immediate disconnect */
1077 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {}
1078 /* Expect LU REJECT with Cause == Illegal MS */
1079 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1080 BSSAP.send(ts_BSSMAP_ClearComplete);
1081 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1082 }
1083 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) { repeat; }
Harald Weltef466eb42018-01-27 14:26:54 +01001084 [] T.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +01001085 setverdict(fail, "Timeout waiting for ClearCommand or SCCP Release");
Harald Weltef466eb42018-01-27 14:26:54 +01001086 self.stop;
1087 }
Harald Welte1af6ea82018-01-25 18:33:15 +01001088 }
1089 setverdict(pass);
1090}
1091testcase TC_cl3_rnd_payload() runs on MTC_CT {
1092 var BSC_ConnHdlr vc_conn;
1093 f_init();
1094
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001095 vc_conn := f_start_handler(refers(f_tc_cl3_rnd_payload), 26);
Harald Welte1af6ea82018-01-25 18:33:15 +01001096 vc_conn.done;
1097}
1098
Harald Welte116e4332018-01-26 22:17:48 +01001099/* Test Complete L3 with random payload */
1100private function f_tc_establish_and_nothing(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001101 f_init_handler(pars);
Harald Welte116e4332018-01-26 22:17:48 +01001102
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001103 f_perform_lu();
Harald Welte116e4332018-01-26 22:17:48 +01001104
Harald Weltede371492018-01-27 23:44:41 +01001105 f_establish_fully(valueof(ts_MI_IMSI_LV(g_pars.imsi)));
Harald Welte1ddc7162018-01-27 14:25:46 +01001106 f_expect_clear();
Harald Welte116e4332018-01-26 22:17:48 +01001107}
1108testcase TC_establish_and_nothing() runs on MTC_CT {
1109 var BSC_ConnHdlr vc_conn;
1110 f_init();
1111
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001112 vc_conn := f_start_handler(refers(f_tc_establish_and_nothing), 27);
Harald Welte116e4332018-01-26 22:17:48 +01001113 vc_conn.done;
1114}
1115
Harald Welte12510c52018-01-26 22:26:24 +01001116/* Test MO Call SETUP with no response from MNCC */
1117private function f_tc_mo_setup_and_nothing(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001118 f_init_handler(pars);
1119
Harald Welte12510c52018-01-26 22:26:24 +01001120 var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
1121
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001122 f_perform_lu();
Harald Welte12510c52018-01-26 22:26:24 +01001123
Harald Weltede371492018-01-27 23:44:41 +01001124 f_establish_fully(valueof(ts_MI_IMSI_LV(g_pars.imsi)));
Harald Welte12510c52018-01-26 22:26:24 +01001125 f_create_mncc_expect(hex2str(cpars.called_party));
1126 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1127
1128 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1129
Harald Welte1ddc7162018-01-27 14:25:46 +01001130 f_expect_clear(30.0);
Harald Welte12510c52018-01-26 22:26:24 +01001131}
1132testcase TC_mo_setup_and_nothing() runs on MTC_CT {
1133 var BSC_ConnHdlr vc_conn;
1134 f_init();
1135
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001136 vc_conn := f_start_handler(refers(f_tc_mo_setup_and_nothing), 28);
Harald Welte12510c52018-01-26 22:26:24 +01001137 vc_conn.done;
1138}
1139
Harald Welte3ab88002018-01-26 22:37:25 +01001140/* Test MO Call with no response to RAN-side CRCX */
1141private function f_tc_mo_crcx_ran_timeout(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001142 f_init_handler(pars);
Harald Welte3ab88002018-01-26 22:37:25 +01001143 var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
1144 var MNCC_PDU mncc;
1145 var MgcpCommand mgcp_cmd;
1146
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001147 f_perform_lu();
Harald Welte3ab88002018-01-26 22:37:25 +01001148
Harald Weltede371492018-01-27 23:44:41 +01001149 f_establish_fully(valueof(ts_MI_IMSI_LV(g_pars.imsi)));
Harald Welte3ab88002018-01-26 22:37:25 +01001150 f_create_mncc_expect(hex2str(cpars.called_party));
1151 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1152
1153 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1154 MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc;
1155 cpars.mncc_callref := mncc.u.signal.callref;
1156 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1157 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
1158
1159 MGCP.receive(tr_CRCX) -> value mgcp_cmd;
Harald Welte1852a842018-01-26 22:53:36 +01001160 cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1161 cpars.mgcp_ep := mgcp_cmd.line.ep;
Harald Welte3ab88002018-01-26 22:37:25 +01001162 /* never respond to this */
1163
Philipp Maier8e58f592018-03-14 11:10:56 +01001164 /* When the connection with the MGW fails, the MSC will first request
1165 * a release via call control. We will answer this request normally. */
1166 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1167 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1168
Harald Welte1ddc7162018-01-27 14:25:46 +01001169 f_expect_clear(30.0);
Harald Welte3ab88002018-01-26 22:37:25 +01001170}
1171testcase TC_mo_crcx_ran_timeout() runs on MTC_CT {
1172 var BSC_ConnHdlr vc_conn;
1173 f_init();
1174
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001175 vc_conn := f_start_handler(refers(f_tc_mo_crcx_ran_timeout), 29);
Harald Welte3ab88002018-01-26 22:37:25 +01001176 vc_conn.done;
1177}
1178
Harald Welte0cc82d92018-01-26 22:52:34 +01001179/* Test MO Call with reject to RAN-side CRCX */
1180private function f_tc_mo_crcx_ran_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001181 f_init_handler(pars);
Harald Welte0cc82d92018-01-26 22:52:34 +01001182 var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
1183 var MNCC_PDU mncc;
1184 var MgcpCommand mgcp_cmd;
1185
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001186 f_perform_lu();
Harald Welte0cc82d92018-01-26 22:52:34 +01001187
Harald Weltede371492018-01-27 23:44:41 +01001188 f_establish_fully(valueof(ts_MI_IMSI_LV(g_pars.imsi)));
Harald Welte0cc82d92018-01-26 22:52:34 +01001189 f_create_mncc_expect(hex2str(cpars.called_party));
1190 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1191
1192 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1193 MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc;
1194 cpars.mncc_callref := mncc.u.signal.callref;
1195 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1196 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
1197
1198 MGCP.receive(tr_CRCX) -> value mgcp_cmd;
1199 cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1200 cpars.mgcp_ep := mgcp_cmd.line.ep;
1201 /* Respond to CRCX with error */
1202 var MgcpResponse mgcp_rsp := {
1203 line := {
1204 code := "542",
1205 trans_id := mgcp_cmd.line.trans_id,
1206 string := "FORCED_FAIL"
1207 },
1208 params := omit,
1209 sdp := omit
1210 }
1211 MGCP.send(mgcp_rsp);
1212
1213 timer T := 30.0;
1214 T.start;
1215 alt {
1216 [] T.timeout { setverdict(fail, "Timeout waiting for channel release"); self.stop; }
1217 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1218 BSSAP.send(ts_BSSMAP_ClearComplete);
1219 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1220 setverdict(pass);
1221 }
Daniel Willmann5868e622018-02-15 17:42:59 +01001222 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1223 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1224 repeat;
1225 }
1226 [] BSSAP.receive {
1227 repeat;
1228 }
Harald Welte0cc82d92018-01-26 22:52:34 +01001229 [] MNCC.receive { repeat; }
1230 [] GSUP.receive { repeat; }
1231 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1232 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1233 f_create_mgcp_delete_ep(cpars.mgcp_ep);
Harald Welteec6e5b42018-01-27 12:45:15 +01001234 repeat;
Harald Welte0cc82d92018-01-26 22:52:34 +01001235 }
1236 [] MGCP.receive { repeat; }
1237 }
1238}
1239testcase TC_mo_crcx_ran_reject() runs on MTC_CT {
1240 var BSC_ConnHdlr vc_conn;
1241 f_init();
1242
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001243 vc_conn := f_start_handler(refers(f_tc_mo_crcx_ran_reject), 30);
Harald Welte0cc82d92018-01-26 22:52:34 +01001244 vc_conn.done;
1245}
1246
Harald Welte3ab88002018-01-26 22:37:25 +01001247
Harald Welte812f7a42018-01-27 00:49:18 +01001248/* helper function to start a MT call: MNCC SETUP; Paging; DChan est.; DTAP SETUP */
1249private function f_mt_call_start(inout CallParameters cpars) runs on BSC_ConnHdlr {
1250 var MNCC_PDU mncc;
1251 var MgcpCommand mgcp_cmd;
1252 var OCT4 tmsi;
1253
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001254 f_perform_lu();
Harald Welte812f7a42018-01-27 00:49:18 +01001255 if (isvalue(g_pars.tmsi)) {
1256 tmsi := g_pars.tmsi;
1257 } else {
1258 tmsi := 'FFFFFFFF'O;
1259 }
1260 f_bssmap_register_imsi(g_pars.imsi, tmsi);
1261
1262 /* Allocate call reference and send SETUP via MNCC to MSC */
1263 cpars.mncc_callref := f_rnd_int(2147483648);
1264 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
1265 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
1266
1267 /* MSC->BSC: expect PAGING from MSC */
1268 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1269 /* MS -> MSC: PAGING RESPONSE */
Harald Welte081b19a2018-02-10 09:11:13 +01001270 f_establish_fully(valueof(ts_MI_IMSI_LV(g_pars.imsi)), EST_TYPE_PAG_RESP);
Harald Welte812f7a42018-01-27 00:49:18 +01001271
1272 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1273
1274 /* MSC->MS: SETUP */
1275 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1276}
1277
1278/* Test MT Call */
1279private function f_tc_mt_crcx_ran_reject(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +01001280 f_init_handler(pars);
Harald Welte812f7a42018-01-27 00:49:18 +01001281 var CallParameters cpars := valueof(t_CallParams('123456'H, 0));
1282 var MNCC_PDU mncc;
1283 var MgcpCommand mgcp_cmd;
1284
1285 f_mt_call_start(cpars);
1286
1287 /* MS->MSC: CALL CONFIRMED */
1288 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CALL_CONF(cpars.transaction_id)));
1289
1290 MNCC.receive(tr_MNCC_CALL_CONF_ind(cpars.mncc_callref));
1291
1292 MGCP.receive(tr_CRCX) -> value mgcp_cmd;
1293 cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1294 cpars.mgcp_ep := mgcp_cmd.line.ep;
1295 /* Respond to CRCX with error */
1296 var MgcpResponse mgcp_rsp := {
1297 line := {
1298 code := "542",
1299 trans_id := mgcp_cmd.line.trans_id,
1300 string := "FORCED_FAIL"
1301 },
1302 params := omit,
1303 sdp := omit
1304 }
1305 MGCP.send(mgcp_rsp);
1306
1307 timer T := 30.0;
1308 T.start;
1309 alt {
1310 [] T.timeout { setverdict(fail, "Timeout waiting for channel release"); self.stop; }
1311 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1312 BSSAP.send(ts_BSSMAP_ClearComplete);
1313 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1314 setverdict(pass);
1315 }
1316 [] BSSAP.receive { repeat; }
1317 [] MNCC.receive { repeat; }
1318 [] GSUP.receive { repeat; }
1319 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1320 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1321 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1322 repeat;
1323 }
1324 [] MGCP.receive { repeat; }
1325 }
1326}
1327testcase TC_mt_crcx_ran_reject() runs on MTC_CT {
1328 var BSC_ConnHdlr vc_conn;
1329 f_init();
1330
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001331 vc_conn := f_start_handler(refers(f_tc_mt_crcx_ran_reject), 31);
Harald Welte812f7a42018-01-27 00:49:18 +01001332 vc_conn.done;
1333}
1334
1335
1336/* Test MT Call T310 timer */
1337private function f_tc_mt_t310(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
Harald Weltead2952e2018-01-27 14:12:46 +01001338 f_init_handler(pars, 200.0);
Harald Welte812f7a42018-01-27 00:49:18 +01001339 var CallParameters cpars := valueof(t_CallParams('123456'H, 0));
1340 var MNCC_PDU mncc;
1341 var MgcpCommand mgcp_cmd;
1342
1343 f_mt_call_start(cpars);
1344
1345 /* MS->MSC: CALL CONFIRMED */
1346 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CALL_CONF(cpars.transaction_id)));
1347 MNCC.receive(tr_MNCC_CALL_CONF_ind(cpars.mncc_callref));
1348
1349 MGCP.receive(tr_CRCX) -> value mgcp_cmd;
1350 cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1351 cpars.mgcp_ep := mgcp_cmd.line.ep;
1352 /* FIXME: Respond to CRCX */
1353
1354 /* old libosmocore T310 default timeout is 180s. so let's wait 190 */
1355 timer T := 190.0;
1356 T.start;
1357 alt {
1358 [] T.timeout { setverdict(fail, "Timeout waiting for T310"); self.stop; }
1359 [] MNCC.receive(tr_MNCC_DISC_ind(cpars.mncc_callref)) {
1360 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1361 }
1362 }
1363 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1364 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1365 /* FIXME: We're sending this with TIflag 0: allocated by sender, which is wrong */
1366 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1367
1368 alt {
1369 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1370 BSSAP.send(ts_BSSMAP_ClearComplete);
1371 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1372 setverdict(pass);
1373 }
1374 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1375 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1376 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1377 repeat;
1378 }
1379 }
1380}
1381testcase TC_mt_t310() runs on MTC_CT {
1382 var BSC_ConnHdlr vc_conn;
1383 f_init();
1384
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001385 vc_conn := f_start_handler(refers(f_tc_mt_t310), 32);
Harald Welte812f7a42018-01-27 00:49:18 +01001386 vc_conn.done;
1387}
1388
Harald Welte167458a2018-01-27 15:58:16 +01001389/* Perform successful LU + MO call, then GSUP LocationCancel. Subscriber must be denied CM SERV */
1390private function f_tc_gsup_cancel(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1391 f_init_handler(pars);
1392 var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
1393 cpars.bss_rtp_port := 1110;
1394 cpars.mgcp_connection_id_bss := '22222'H;
1395 cpars.mgcp_connection_id_mss := '33333'H;
1396
1397 /* Location Update to make subscriber known */
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001398 f_perform_lu();
Harald Welte167458a2018-01-27 15:58:16 +01001399
1400 /* First MO call should succeed */
1401 f_mo_call(cpars);
1402
1403 /* Cancel the subscriber in the VLR */
1404 GSUP.send(ts_GSUP_CL_REQ(g_pars.imsi, OSMO_GSUP_CANCEL_TYPE_WITHDRAW));
1405 alt {
1406 [] GSUP.receive(tr_GSUP_CL_RES(g_pars.imsi)) { }
1407 [] GSUP.receive(tr_GSUP_CL_ERR(g_pars.imsi)) {
1408 setverdict(fail, "Received GSUP Location Cancel Error");
1409 self.stop;
1410 }
1411 }
1412
1413 /* Follow-up transactions should fail */
1414 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
1415 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
1416 f_bssap_compl_l3(l3_info);
1417 alt {
1418 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ)) { }
1419 [] BSSAP.receive {
1420 setverdict(fail, "Received unexpected BSSAP instead of CM SERV REJ");
1421 self.stop;
1422 }
1423 }
1424 setverdict(pass);
1425}
1426testcase TC_gsup_cancel() runs on MTC_CT {
1427 var BSC_ConnHdlr vc_conn;
1428 f_init();
1429
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001430 vc_conn := f_start_handler(refers(f_tc_gsup_cancel), 33);
Harald Welte167458a2018-01-27 15:58:16 +01001431 vc_conn.done;
1432}
1433
Harald Welte9de84792018-01-28 01:06:35 +01001434/* A5/1 only permitted on network side, and MS capable to do it */
1435private function f_tc_lu_imsi_auth_tmsi_encr_1_13(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1436 pars.net.expect_auth := true;
1437 pars.net.expect_ciph := true;
1438 pars.net.kc_support := '02'O; /* A5/1 only */
1439 f_init_handler(pars);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001440 f_perform_lu();
Harald Welte9de84792018-01-28 01:06:35 +01001441}
1442testcase TC_lu_imsi_auth_tmsi_encr_1_13() runs on MTC_CT {
1443 var BSC_ConnHdlr vc_conn;
1444 f_init();
1445 f_vty_config(MSCVTY, "network", "authentication required");
1446 f_vty_config(MSCVTY, "network", "encryption a5 1");
1447
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001448 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_1_13), 34);
Harald Welte9de84792018-01-28 01:06:35 +01001449 vc_conn.done;
1450}
1451
1452/* A5/3 only permitted on network side, and MS capable to do it */
1453private function f_tc_lu_imsi_auth_tmsi_encr_3_13(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1454 pars.net.expect_auth := true;
1455 pars.net.expect_ciph := true;
1456 pars.net.kc_support := '08'O; /* A5/3 only */
1457 f_init_handler(pars);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001458 f_perform_lu();
Harald Welte9de84792018-01-28 01:06:35 +01001459}
1460testcase TC_lu_imsi_auth_tmsi_encr_3_13() runs on MTC_CT {
1461 var BSC_ConnHdlr vc_conn;
1462 f_init();
1463 f_vty_config(MSCVTY, "network", "authentication required");
1464 f_vty_config(MSCVTY, "network", "encryption a5 3");
1465
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001466 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_3_13), 35);
Harald Welte9de84792018-01-28 01:06:35 +01001467 vc_conn.done;
1468}
1469
1470/* A5/3 only permitted on network side, and MS with only A5/1 support */
1471private function f_tc_lu_imsi_auth_tmsi_encr_3_1(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1472 pars.net.expect_auth := true;
1473 pars.net.expect_ciph := true;
1474 pars.net.kc_support := '08'O; /* A5/3 only */
1475 pars.cm2.classmarkInformationType2_oct5.a5_3 := '0'B;
1476 f_init_handler(pars, 15.0);
1477
1478 /* cannot use f_perform_lu() as we expect a reject */
1479 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi);
1480 f_create_gsup_expect(hex2str(g_pars.imsi));
1481 f_bssap_compl_l3(l3_lu);
Neels Hofmeyr29b8da02018-03-01 18:09:45 +01001482 if (pars.send_early_cm) {
1483 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
1484 } else {
1485 pars.cm1.esind := '0'B;
1486 }
Harald Welte9de84792018-01-28 01:06:35 +01001487 f_mm_auth();
1488 alt {
1489 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { }
1490 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?,?)) {
1491 setverdict(fail, "CipherModeCommand despite no A5 intersection");
1492 self.stop;
1493 }
1494 [] BSSAP.receive {
1495 setverdict(inconc, "Unknown/unexpected BSSAP received");
1496 self.stop;
1497 }
1498 }
1499 setverdict(pass);
1500}
1501testcase TC_lu_imsi_auth_tmsi_encr_3_1() runs on MTC_CT {
1502 var BSC_ConnHdlr vc_conn;
1503 f_init();
1504 f_vty_config(MSCVTY, "network", "authentication required");
1505 f_vty_config(MSCVTY, "network", "encryption a5 3");
1506
Neels Hofmeyr29b8da02018-03-01 18:09:45 +01001507 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_3_1), 360);
1508 vc_conn.done;
1509}
1510testcase TC_lu_imsi_auth_tmsi_encr_3_1_no_cm() runs on MTC_CT {
1511 var BSC_ConnHdlrPars pars;
1512 var BSC_ConnHdlr vc_conn;
1513 f_init();
1514 f_vty_config(MSCVTY, "network", "authentication required");
1515 f_vty_config(MSCVTY, "network", "encryption a5 3");
1516
1517 pars := f_init_pars(361);
1518 pars.send_early_cm := false;
1519 vc_conn := f_start_handler_with_pars(refers(f_tc_lu_imsi_auth_tmsi_encr_3_1), pars);
Harald Welte9de84792018-01-28 01:06:35 +01001520 vc_conn.done;
1521}
Neels Hofmeyr1b3c6e32018-03-01 17:52:21 +01001522testcase TC_lu_imsi_auth_tmsi_encr_3_1_log_msc_debug() runs on MTC_CT {
1523 var BSC_ConnHdlr vc_conn;
1524 f_init();
1525 f_vty_config(MSCVTY, "network", "authentication required");
1526 f_vty_config(MSCVTY, "network", "encryption a5 3");
1527
1528 /* Make sure the MSC category is on DEBUG level to trigger the log
1529 * message that is reported in OS#2947 to trigger the segfault */
1530 f_vty_config(MSCVTY, "log stderr", "logging level msc debug");
1531
1532 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_3_1), 362);
1533 vc_conn.done;
1534}
Harald Welte9de84792018-01-28 01:06:35 +01001535
1536/* A5/1 + A5/3 only permitted on network side, and MS with only A5/2 support */
1537private function f_tc_lu_imsi_auth_tmsi_encr_13_2(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1538 pars.net.expect_auth := true;
1539 pars.net.expect_ciph := true;
1540 pars.net.kc_support := '0A'O; /* A5/1 + A5/3 */
1541 pars.cm1.a5_1 := '1'B;
1542 pars.cm2.a5_1 := '1'B;
1543 pars.cm2.classmarkInformationType2_oct5.a5_3 := '0'B;
1544 pars.cm2.classmarkInformationType2_oct5.a5_2 := '1'B;
1545 f_init_handler(pars, 15.0);
1546
1547 /* cannot use f_perform_lu() as we expect a reject */
1548 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi);
1549 f_create_gsup_expect(hex2str(g_pars.imsi));
1550 f_bssap_compl_l3(l3_lu);
1551 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
1552 f_mm_auth();
1553 alt {
1554 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { }
1555 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?,?)) {
1556 setverdict(fail, "CipherModeCommand despite no A5 intersection");
1557 self.stop;
1558 }
1559 [] BSSAP.receive {
1560 setverdict(inconc, "Unknown/unexpected BSSAP received");
1561 self.stop;
1562 }
1563 }
1564 setverdict(pass);
1565}
1566testcase TC_lu_imsi_auth_tmsi_encr_13_2() runs on MTC_CT {
1567 var BSC_ConnHdlr vc_conn;
1568 f_init();
1569 f_vty_config(MSCVTY, "network", "authentication required");
1570 f_vty_config(MSCVTY, "network", "encryption a5 1 3");
1571
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001572 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_13_2), 37);
Harald Welte9de84792018-01-28 01:06:35 +01001573 vc_conn.done;
1574}
1575
1576/* A5/0 + A5/1 + A5/3 only permitted on network side, and MS with only A5/2 support */
1577private function f_tc_lu_imsi_auth_tmsi_encr_013_2(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1578 pars.net.expect_auth := true;
1579 pars.net.expect_ciph := true;
1580 pars.net.kc_support := '0B'O; /* A5/1 + A5/3 */
1581 pars.cm1.a5_1 := '1'B;
1582 pars.cm2.a5_1 := '1'B;
1583 pars.cm2.classmarkInformationType2_oct5.a5_3 := '0'B;
1584 pars.cm2.classmarkInformationType2_oct5.a5_2 := '1'B;
1585 f_init_handler(pars, 15.0);
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001586 f_perform_lu();
Harald Welte9de84792018-01-28 01:06:35 +01001587}
1588testcase TC_lu_imsi_auth_tmsi_encr_013_2() runs on MTC_CT {
1589 var BSC_ConnHdlr vc_conn;
1590 f_init();
1591 f_vty_config(MSCVTY, "network", "authentication required");
1592 f_vty_config(MSCVTY, "network", "encryption a5 0 1 3");
1593
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001594 vc_conn := f_start_handler(refers(f_tc_lu_imsi_auth_tmsi_encr_013_2), 38);
Harald Welte9de84792018-01-28 01:06:35 +01001595 vc_conn.done;
1596}
1597
Harald Welte33ec09b2018-02-10 15:34:46 +01001598/* LU followed by MT call (including paging) */
1599private function f_tc_lu_and_mt_call(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1600 f_init_handler(pars);
1601 //FIXME: odd digits var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
1602 var CallParameters cpars := valueof(t_CallParams('123456'H, 0));
1603 cpars.bss_rtp_port := 1110;
1604 cpars.mgcp_connection_id_bss := '10004'H;
1605 cpars.mgcp_connection_id_mss := '10005'H;
1606
Philipp Maier4b2692d2018-03-14 16:37:48 +01001607 /* Note: This is an optional parameter. When the call-agent (MSC) does
1608 * supply a full endpoint name this setting will be overwritten. */
1609 cpars.mgcp_ep := "rtpbridge/1@mgw";
1610
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001611 f_perform_lu();
Harald Welte33ec09b2018-02-10 15:34:46 +01001612 f_mt_call(cpars);
1613}
1614testcase TC_lu_and_mt_call() runs on MTC_CT {
1615 var BSC_ConnHdlr vc_conn;
1616 f_init();
1617
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001618 vc_conn := f_start_handler(refers(f_tc_lu_and_mt_call), 39);
Harald Welte33ec09b2018-02-10 15:34:46 +01001619 vc_conn.done;
1620}
1621
Daniel Willmann8b084372018-02-04 13:35:26 +01001622/* Test MO Call SETUP with DTMF */
1623private function f_tc_mo_setup_dtmf_dup(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
1624 f_init_handler(pars);
1625 var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
1626 cpars.bss_rtp_port := 1110;
1627 cpars.mgcp_connection_id_bss := '22222'H;
1628 cpars.mgcp_connection_id_mss := '33333'H;
1629
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +01001630 f_perform_lu();
Daniel Willmann8b084372018-02-04 13:35:26 +01001631 f_mo_seq_dtmf_dup(cpars);
1632}
1633testcase TC_mo_setup_and_dtmf_dup() runs on MTC_CT {
1634 var BSC_ConnHdlr vc_conn;
1635 f_init();
1636
Neels Hofmeyre9b8eeb2018-03-01 20:29:58 +01001637 vc_conn := f_start_handler(refers(f_tc_mo_setup_dtmf_dup), 39);
Daniel Willmann8b084372018-02-04 13:35:26 +01001638 vc_conn.done;
1639}
Harald Welte9de84792018-01-28 01:06:35 +01001640
Philipp Maier328d1662018-03-07 10:40:27 +01001641testcase TC_cr_before_reset() runs on MTC_CT {
1642 timer T := 4.0;
1643 var boolean reset_ack_seen := false;
1644 f_init_bssap_direct();
1645
1646 /* Make a blind connection attemt, to trigger the deadlock condition */
1647 BSSAP_DIRECT.send(ts_BSSAP_CONNECT_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, 1, omit));
1648
1649 /* Send a BSSMAP reset */
1650 BSSAP_DIRECT.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
1651 T.start
1652 alt {
1653 [] BSSAP_DIRECT.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_ResetAck)) {
1654 reset_ack_seen := true;
1655 repeat;
1656 }
1657
1658 /* Acknowledge MSC sided reset requests */
1659 [] BSSAP_DIRECT.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
1660 BSSAP_DIRECT.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_ResetAck));
1661 repeat;
1662 }
1663
1664 /* Ignore all other messages (e.g CR from the connection request) */
1665 [] BSSAP_DIRECT.receive { repeat }
1666
1667 /* If we got no BSSMAP RESET ACK back, then the MSC entered the
1668 * deadlock situation. The MSC is then unable to respond to any
1669 * further BSSMAP RESET or any other sort of traffic. */
1670 [reset_ack_seen == true] T.timeout { setverdict(pass) }
1671 [reset_ack_seen == false] T.timeout {
1672 setverdict(fail, "no BSSMAP RESET ACK seen!");
1673 }
1674 }
1675}
Harald Welte9de84792018-01-28 01:06:35 +01001676
Harald Welte12510c52018-01-26 22:26:24 +01001677
Harald Welte45164da2018-01-24 12:51:27 +01001678
Harald Welteba7b6d92018-01-23 21:32:34 +01001679/* TODO:
1680 * continue to send repeated MO signalling messages to keep channel open: does MSC tmeout?
1681 * malformed messages (missing IE, invalid message type): properly rejected?
1682 * MT call while LU or is ongoing: Do we use existing lchan or page while lchan active?
1683 * 3G/2G auth permutations
1684 * encryption algorithms vs. classmark vs. vty config
Harald Welteba7b6d92018-01-23 21:32:34 +01001685 * send new transaction after/during clear (like SMS, ...)
Harald Welte45164da2018-01-24 12:51:27 +01001686 * too long L3 INFO in DTAP
1687 * too long / padded BSSAP
1688 * too long / short TLV values
Harald Welteba7b6d92018-01-23 21:32:34 +01001689 */
Harald Weltef6dd64d2017-11-19 12:09:51 +01001690
1691
1692control {
Philipp Maier328d1662018-03-07 10:40:27 +01001693 execute( TC_cr_before_reset() );
Harald Weltea49e36e2018-01-21 19:29:33 +01001694 execute( TC_lu_imsi_noauth_tmsi() );
Harald Welted2328a22018-01-27 14:27:16 +01001695 execute( TC_lu_imsi_noauth_notmsi() );
Harald Weltea49e36e2018-01-21 19:29:33 +01001696 execute( TC_lu_imsi_reject() );
1697 execute( TC_lu_imsi_timeout_gsup() );
Harald Welted2328a22018-01-27 14:27:16 +01001698 execute( TC_lu_imsi_auth_tmsi() );
1699 execute( TC_cmserv_imsi_unknown() );
Harald Welte2bb825f2018-01-22 11:31:18 +01001700 execute( TC_lu_and_mo_call() );
Harald Welte071ed732018-01-23 19:53:52 +01001701 execute( TC_lu_auth_sai_timeout() );
1702 execute( TC_lu_auth_sai_err() );
Harald Weltee1a2f3c2018-01-24 17:28:48 +01001703 execute( TC_lu_clear_request() );
1704 execute( TC_lu_disconnect() );
1705 execute( TC_lu_by_imei() );
1706 execute( TC_lu_by_tmsi_noauth_unknown() );
1707 execute( TC_imsi_detach_by_imsi() );
1708 execute( TC_imsi_detach_by_tmsi() );
1709 execute( TC_imsi_detach_by_imei() );
1710 execute( TC_emerg_call_imei_reject() );
1711 execute( TC_emerg_call_imsi() );
1712 execute( TC_cm_serv_req_vgcs_reject() );
1713 execute( TC_cm_serv_req_vbs_reject() );
1714 execute( TC_cm_serv_req_lcs_reject() );
Harald Welte0195ab12018-01-24 21:50:20 +01001715 execute( TC_cm_reest_req_reject() );
Harald Welte1af6ea82018-01-25 18:33:15 +01001716 execute( TC_lu_auth_2G_fail() );
1717 execute( TC_lu_imsi_auth_tmsi_encr_13_13() );
1718 execute( TC_cl3_no_payload() );
1719 execute( TC_cl3_rnd_payload() );
Harald Welte1852a842018-01-26 22:53:36 +01001720 execute( TC_establish_and_nothing() );
1721 execute( TC_mo_setup_and_nothing() );
1722 execute( TC_mo_crcx_ran_timeout() );
1723 execute( TC_mo_crcx_ran_reject() );
Harald Welted2328a22018-01-27 14:27:16 +01001724 execute( TC_mt_crcx_ran_reject() );
Daniel Willmann8b084372018-02-04 13:35:26 +01001725 execute( TC_mo_setup_and_dtmf_dup() );
Harald Welteaa54cf82018-01-30 08:15:32 +01001726 //execute( TC_mt_t310() );
Harald Welte167458a2018-01-27 15:58:16 +01001727 execute( TC_gsup_cancel() );
Harald Welte9de84792018-01-28 01:06:35 +01001728 execute( TC_lu_imsi_auth_tmsi_encr_1_13() );
1729 execute( TC_lu_imsi_auth_tmsi_encr_3_13() );
1730 execute( TC_lu_imsi_auth_tmsi_encr_3_1() );
Neels Hofmeyr29b8da02018-03-01 18:09:45 +01001731 execute( TC_lu_imsi_auth_tmsi_encr_3_1_no_cm() );
Harald Welte9de84792018-01-28 01:06:35 +01001732 execute( TC_lu_imsi_auth_tmsi_encr_13_2() );
1733 execute( TC_lu_imsi_auth_tmsi_encr_013_2() );
Harald Welte33ec09b2018-02-10 15:34:46 +01001734
1735 execute( TC_lu_and_mt_call() );
1736
Neels Hofmeyr1b3c6e32018-03-01 17:52:21 +01001737 /* Run this last: at the time of writing this test crashes the MSC */
1738 execute( TC_lu_imsi_auth_tmsi_encr_3_1_log_msc_debug() );
Harald Weltef6dd64d2017-11-19 12:09:51 +01001739}
1740
1741
1742}