module MME_Tests_emergency {

/* Osmocom MME test suite in TTCN-3, emergency call related procedures (3GPP TS 24.301)
 * (C) 2025 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * All rights reserved.
 * Author: Andreas Eversberg <aeversberg@sysmocom.de>
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

import from General_Types all;
import from Osmocom_Types all;
import from Misc_Helpers all;
import from L3_Templates all;
import from DNS_Helpers all;
import from MME_Tests all;

import from NAS_EPS_Templates all;

import from ConnHdlr all;

private function f_TC_emergency_supported() runs on ConnHdlr {
	f_attach();
}
testcase TC_emergency_supported() runs on MTC_CT {
	f_init(2001, init_diameter := true, init_gtpv2c_s11 := true);
	f_s1ap_setup(0);

	var ConnHdlrPars pars := f_init_pars(ue_idx := 0);
	var ConnHdlr vc_conn;
	pars.emerg_pars.expect_s1_emergency := true;
	pars.emerg_pars.s1_emergency := '1'B;
	vc_conn := f_start_handler_with_pars(refers(f_TC_emergency_supported), pars);
	vc_conn.done;
}

private function f_TC_emergency_number_included() runs on ConnHdlr {
	f_attach();
}
testcase TC_emergency_number_included() runs on MTC_CT {
	f_init(2002, init_diameter := true, init_gtpv2c_s11 := true);
	f_s1ap_setup(0);

	var ConnHdlrPars pars := f_init_pars(ue_idx := 0);
	var ConnHdlr vc_conn;
	pars.emerg_pars.expect_s1_emergency := true;
	pars.emerg_pars.s1_emergency := '1'B;
	pars.emerg_pars.expect_number := true;
	pars.emerg_pars.numbers := 2;
	pars.emerg_pars.categories[0] := '00001'B; /* police */
	pars.emerg_pars.digits[0] := '11F0'O; /* 110 */
	pars.emerg_pars.categories[1] := '00110'B; /* fire + ambulance */
	pars.emerg_pars.digits[1] := '11F2'O; /* 112 */
	vc_conn := f_start_handler_with_pars(refers(f_TC_emergency_number_included), pars);
	vc_conn.done;
}

private function f_TC_emergency_bearer() runs on ConnHdlr {
	f_attach();
	f_emergency_bearer();
}
testcase TC_emergency_bearer() runs on MTC_CT {
	f_init(2003, init_diameter := true, init_gtpv2c_s11 := true);
	f_s1ap_setup(0);

	var ConnHdlrPars pars := f_init_pars(ue_idx := 0);
	var ConnHdlr vc_conn;
	vc_conn := f_start_handler_with_pars(refers(f_TC_emergency_bearer), pars);
	vc_conn.done;
}

control {
	execute( TC_emergency_supported() );
	execute( TC_emergency_number_included() );
	execute( TC_emergency_bearer() );
}

}
