sgsn: add TC_iu_attach_encr with UEA > 0

Test new osmo-sgsn Iu attach with UEA (encryption) enabled

Related: SYS#5516
Depends: I27e8e0078c45426bf227bb44aac82a4875d18d0f (osmo-sgsn)
Change-Id: I1a7c3b156830058c43f15f55883ea301d2d01d5f
diff --git a/sgsn/SGSN_Tests.ttcn b/sgsn/SGSN_Tests.ttcn
index c29095f..981e924 100644
--- a/sgsn/SGSN_Tests.ttcn
+++ b/sgsn/SGSN_Tests.ttcn
@@ -465,13 +465,13 @@
 
 /* helper function to create, connect and start a BSSGP_ConnHdlr component */
 function f_start_handler(void_fn fn, charstring id, GbInstances gb, integer imsi_suffix,
-			 float t_guard := 30.0)
+			 float t_guard := 30.0, boolean expect_ciph := false)
 runs on test_CT return BSSGP_ConnHdlr {
 	var BSSGP_ConnHdlr vc_conn;
 	var SGSN_ConnHdlrNetworkPars net_pars := {
 		expect_ptmsi := true,
 		expect_auth := true,
-		expect_ciph := false
+		expect_ciph := expect_ciph
 	};
 	var BSSGP_ConnHdlrPars pars := {
 		imei := f_gen_imei(imsi_suffix),
@@ -687,6 +687,34 @@
 	return l3_mt;
 }
 
+/* (copied from msc/BSC_ConnectionHandler.ttcn) */
+private altstep as_ciph_utran() runs on BSSGP_ConnHdlr
+{
+	[g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
+									   uia_key := oct2bit(g_pars.vec.ik),
+									   key_sts := ?,
+									   uea_algs := ?,
+									   uea_key := oct2bit(g_pars.vec.ck))) {
+		var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
+		var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
+		BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
+		}
+	[g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
+		setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
+		mtc.stop;
+		}
+	[not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
+									    uia_key := oct2bit(g_pars.vec.ik),
+									    key_sts := ?)) {
+		var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
+		BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
+		}
+	[not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
+		setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
+		mtc.stop;
+		}
+}
+
 /* perform GMM authentication (if expected).
  * Note, for umts_aka_challenge to work, the revisionLevelIndicatior needs to
  * be 1 to mark R99 capability, in the GMM Attach Request, see f_gmm_attach(). */
@@ -754,12 +782,8 @@
 
 		/* Security Mode Command + Complete on Iu case */
 		if (is_iu(ran_index)) {
-			BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?, uia_key := oct2bit(g_pars.vec.ik),
-								key_sts := ?)) {
-				var IntegrityProtectionAlgorithm uia_chosen := 0; /* 0 = standard_UMTS_integrity_algorithm_UIA1 */
-				BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
-				BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)))
-			}
+			as_ciph_utran();
+			BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
 		}
 	} else {
 		/* wait for identity procedure */