BSC_Tests: Implement ecnryption related procedures

Let's verify the operation of the CIPHERING MODE COMMAND as issued
by MSC, performed by BSC and implemented by simulated BTS/MS.

Change-Id: Ibc06bd2177c63837a794a0ca1f54ebef17499e78
diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn
index d615497..a76d1d6 100644
--- a/bsc/MSC_ConnectionHandler.ttcn
+++ b/bsc/MSC_ConnectionHandler.ttcn
@@ -99,6 +99,35 @@
 	RSL.send(ts_RSL_DATA_IND(chan_nr, link_id, enc_PDU_ML3_MS_NW(valueof(l3))));
 }
 
+function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit) runs on MSC_ConnHdlr {
+	var PDU_BSSAP bssap;
+	var RSL_Message rsl;
+
+	if (isvalue(kc128)) {
+		BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128)));
+	} else {
+		BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key));
+	}
+	alt {
+	/* RSL/UE Side */
+	[] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg, key)) -> value rsl {
+		var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload);
+		log("Rx L3 from net: ", l3);
+		if (ischosen(l3.msgs.rrm.cipheringModeCommand)) {
+			f_rsl_reply(ts_RRM_CiphModeCompl, rsl);
+		}
+		repeat;
+		}
+	[] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap {
+		// bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier
+		setverdict(pass);
+		}
+	[] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap {
+		setverdict(fail, "Ciphering Mode Reject");
+		}
+	}
+}
+
 /* establish a channel fully, expecting an assignment matching 'exp' */
 function f_establish_fully(TestHdlrParams pars, PDU_BSSAP ass_cmd, template PDU_BSSAP exp_ass_cpl)
 runs on MSC_ConnHdlr return PDU_BSSAP {