libvlr: fix is_ciph_required(): always send SecModeCmd for UTRAN

Ciphering is optional in both GERAN and UTRAN, however for the later
it's *required* to enable integrity protection for the signalling.
Thus we must always send Security Mode Command in UTRAN, even in
case if ciphering is disabled (UEA0) in the configuration.

The actual decision whether to send CMC/SMC or not is taken in:

  * vlr_access_req_fsm.c / _proc_arq_vlr_node2(), and
  * vlr_lu_fsm.c / vlr_loc_upd_post_auth().

depending on the value returned by is_ciph_required().  Let's
rename this function to is_cmc_smc_required() and ensure that
it always returns true in UTRAN.

This change fixes the Iu test cases in ttcn3-msc-test.

Change-Id: I6205f13453eff7afbf25e013d72ae98a78fcd31b
Fixes: OS#5333
diff --git a/tests/msc_vlr/msc_vlr_test_umts_authen.c b/tests/msc_vlr/msc_vlr_test_umts_authen.c
index f132cdf..0a2a446 100644
--- a/tests/msc_vlr/msc_vlr_test_umts_authen.c
+++ b/tests/msc_vlr/msc_vlr_test_umts_authen.c
@@ -124,31 +124,38 @@
 	VERBOSE_ASSERT(auth_request_sent, == true, "%d");
 	VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
 
-	if (encryption) {
-		if (via_ran == OSMO_RAT_GERAN_A) {
+	switch (via_ran) {
+	case OSMO_RAT_GERAN_A:
+		if (encryption) {
 			btw("Test code not implemented");
 			OSMO_ASSERT(false);
-		} else {
-			/* On UTRAN */
-			btw("Encryption enabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl");
-			expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
-			ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
-			VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
-			VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
-
-			btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
-			gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
-			ms_sends_security_mode_complete(1);
-			VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
-			VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
 		}
-	} else {
-		/* Encryption disabled */
+
 		btw("Encryption disabled. MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
 		gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
 		ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
 		VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
 		VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
+		break;
+	case OSMO_RAT_UTRAN_IU:
+		/* Even if encryption is disabled (UEA0), we still expect a SecurityModeControl
+		 * message indicating UIA, because integrity protection is mandatory in UTRAN. */
+		btw("Encryption %sabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl",
+		    encryption ? "en" : "dis");
+		expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
+		ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
+		VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
+		VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
+
+		btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
+		gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
+		ms_sends_security_mode_complete(encryption ? 0x01 : 0x00);
+		VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
+		VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
+		break;
+	default:
+		btw("Unhandled RAT %s", osmo_rat_type_name(via_ran));
+		OSMO_ASSERT(false);
 	}
 
 	btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
@@ -198,28 +205,35 @@
 	EXPECT_ACCEPTED(false);
 	thwart_rx_non_initial_requests();
 
-	if (encryption) {
-		if (via_ran == OSMO_RAT_GERAN_A) {
+	switch (via_ran) {
+	case OSMO_RAT_GERAN_A:
+		if (encryption) {
 			btw("Test code not implemented");
 			OSMO_ASSERT(false);
-		} else {
-			/* On UTRAN */
-			btw("Encryption enabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl");
-			expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
-			ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
-			VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
-			VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
-
-			btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
-			ms_sends_security_mode_complete(1);
-			VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
 		}
-	} else {
-		/* Encryption disabled */
+
 		btw("Encryption disabled. MS sends Authen Response, VLR accepts with a CM Service Accept");
 		gsup_expect_tx(NULL);
 		ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
 		VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
+		break;
+	case OSMO_RAT_UTRAN_IU:
+		/* Even if encryption is disabled (UEA0), we still expect a SecurityModeControl
+		 * message indicating UIA, because integrity protection is mandatory in UTRAN. */
+		btw("Encryption %sabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl",
+		    encryption ? "en" : "dis");
+		expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
+		ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
+		VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
+		VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
+
+		btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
+		ms_sends_security_mode_complete(encryption ? 0x01 : 0x00);
+		VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
+		break;
+	default:
+		btw("Unhandled RAT %s", osmo_rat_type_name(via_ran));
+		OSMO_ASSERT(false);
 	}
 
 	/* Release connection */
@@ -265,27 +279,34 @@
 	EXPECT_ACCEPTED(false);
 	thwart_rx_non_initial_requests();
 
-	if (encryption) {
-		if (via_ran == OSMO_RAT_GERAN_A) {
+	switch (via_ran) {
+	case OSMO_RAT_GERAN_A:
+		if (encryption) {
 			btw("Test code not implemented");
 			OSMO_ASSERT(false);
-		} else {
-			/* On UTRAN */
-			btw("Encryption enabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl");
-			expect_security_mode_ctrl(NULL, "eb50e770ddcc3060101d2f43b6c2b884");
-			ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */
-			VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
-
-			btw("MS sends SecurityModeControl acceptance, VLR accepts and sends SMS");
-			dtap_expect_tx(sms);
-			ms_sends_security_mode_complete(1);
 		}
-	} else {
-		/* Encryption disabled */
+
 		btw("Encryption disabled. MS sends Authen Response, VLR accepts and sends pending SMS");
 		dtap_expect_tx(sms);
 		ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */
 		VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
+		break;
+	case OSMO_RAT_UTRAN_IU:
+		/* Even if encryption is disabled (UEA0), we still expect a SecurityModeControl
+		 * message indicating UIA, because integrity protection is mandatory in UTRAN. */
+		btw("Encryption %sabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl",
+		    encryption ? "en" : "dis");
+		expect_security_mode_ctrl(NULL, "eb50e770ddcc3060101d2f43b6c2b884");
+		ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */
+		VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
+
+		btw("MS sends SecurityModeControl acceptance, VLR accepts and sends SMS");
+		dtap_expect_tx(sms);
+		ms_sends_security_mode_complete(encryption ? 0x01 : 0x00);
+		break;
+	default:
+		btw("Unhandled RAT %s", osmo_rat_type_name(via_ran));
+		OSMO_ASSERT(false);
 	}
 
 	btw("SMS was delivered, no requests pending for subscr");
@@ -516,31 +537,38 @@
 	VERBOSE_ASSERT(auth_request_sent, == true, "%d");
 	VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
 
-	if (encryption) {
-		if (via_ran == OSMO_RAT_GERAN_A) {
+	switch (via_ran) {
+	case OSMO_RAT_GERAN_A:
+		if (encryption) {
 			btw("Test code not implemented");
 			OSMO_ASSERT(false);
-		} else {
-			/* On UTRAN */
-			btw("Encryption enabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl");
-			expect_security_mode_ctrl(NULL, "8a90c769b7272f3bb7a1c1fbb1ea9349");
-			ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e");
-			VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
-			VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
-
-			btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
-			gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
-			ms_sends_security_mode_complete(1);
-			VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
-			VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
 		}
-	} else {
-		/* Encryption disabled */
+
 		btw("Encryption disabled. MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
 		gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
 		ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e");
 		VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
 		VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
+		break;
+	case OSMO_RAT_UTRAN_IU:
+		/* Even if encryption is disabled (UEA0), we still expect a SecurityModeControl
+		 * message indicating UIA, because integrity protection is mandatory in UTRAN. */
+		btw("Encryption %sabled. MS sends Authen Response, VLR accepts and sends SecurityModeControl",
+		    encryption ? "en" : "dis");
+		expect_security_mode_ctrl(NULL, "8a90c769b7272f3bb7a1c1fbb1ea9349");
+		ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e");
+		VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
+		VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
+
+		btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
+		gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
+		ms_sends_security_mode_complete(encryption ? 0x01 : 0x00);
+		VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
+		VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
+		break;
+	default:
+		btw("Unhandled RAT %s", osmo_rat_type_name(via_ran));
+		OSMO_ASSERT(false);
 	}
 
 	btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");