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/library/BSSMAP_Templates.ttcn b/library/BSSMAP_Templates.ttcn
index 24a888c..bb1b537 100644
--- a/library/BSSMAP_Templates.ttcn
+++ b/library/BSSMAP_Templates.ttcn
@@ -703,5 +703,62 @@
 	}
 }
 
+template PDU_BSSAP ts_BSSMAP_CipherModeCmd(OCT1 alg, OCT8 key)
+modifies ts_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeCommand := {
+				messageType := '53'O,
+				layer3HeaderInfo := omit,
+				encryptionInformation := ts_BSSMAP_IE_EncrInfo(key, alg),
+				cipherResponseMode := omit,
+				kC128 := omit
+			}
+		}
+	}
+}
+
+template PDU_BSSAP ts_BSSMAP_CipherModeCmdKc128(OCT1 alg, OCT8 key, OCT16 kc128)
+modifies ts_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeCommand := {
+				messageType := '53'O,
+				layer3HeaderInfo := omit,
+				encryptionInformation := ts_BSSMAP_IE_EncrInfo(key, alg),
+				cipherResponseMode := omit,
+				kC128 := { '83'O, kc128 }
+			}
+		}
+	}
+}
+
+template PDU_BSSAP tr_BSSMAP_CipherModeCompl(template OCT1 alg := ?) modifies tr_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeComplete := {
+				messageType := '55'O,
+				layer3MessageContents := *,
+				chosenEncryptionAlgorithm := {
+					elementIdentifier := '2C'O,
+					algorithmIdentifier := alg
+				}
+			}
+		}
+	}
+}
+
+template PDU_BSSAP tr_BSSMAP_CipherModeRej modifies tr_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeReject := {
+				messageType := '59'O,
+				cause  := ?
+			}
+		}
+	}
+}
+
+
 
 } with { encode "RAW" };
diff --git a/library/L3_Templates.ttcn b/library/L3_Templates.ttcn
index 4755989..f0f3d38 100644
--- a/library/L3_Templates.ttcn
+++ b/library/L3_Templates.ttcn
@@ -126,5 +126,20 @@
 	}
 }
 
+template (value) PDU_ML3_MS_NW ts_RRM_CiphModeCompl := {
+	discriminator := '0000'B, /* overwritten */
+	tiOrSkip := {
+		skipIndicator := '0000'B
+	},
+	msgs := {
+		rrm := {
+			cipheringModeComplete := {
+				messageType := '00110010'B,
+				mobileEquipmentIdentity := omit
+			}
+		}
+	}
+}
+
 
 }
diff --git a/library/RSL_Types.ttcn b/library/RSL_Types.ttcn
index 67e4dc9..0604440 100644
--- a/library/RSL_Types.ttcn
+++ b/library/RSL_Types.ttcn
@@ -330,6 +330,19 @@
 		uint5_t		power_level
 	}
 
+	/* 9.3.7 */
+	type record RSL_IE_EncryptionInfo {
+		uint8_t		len,
+		OCT1		alg_id,
+		octetstring	key
+	} with { variant (len) "LENGTHTO(alg_id,key)" };
+
+	template RSL_IE_EncryptionInfo tr_RSL_IE_EncrInfo(template OCT1 alg, template octetstring key) := {
+		len := ?,
+		alg_id := alg,
+		key := key
+	}
+
 	/* 9.3.8 */
 	type record RSL_IE_FrameNumber {
 		uint5_t		t1_p,
@@ -550,6 +563,7 @@
 		uint8_t			paging_group,
 		RSL_IE_ChanNeeded	chan_needed,
 		RSL_IE_StartingTime	starting_time,
+		RSL_IE_EncryptionInfo	encr_info,
 		RSL_IE_RequestRef	req_ref,
 		RSL_LV			full_imm_ass_info,
 		RSL_LV			ms_identity,
@@ -595,6 +609,7 @@
 					paging_group, iei = RSL_IE_PAGING_GROUP;
 					chan_needed, iei = RSL_IE_CHAN_NEEDED;
 					starting_time, iei = RSL_IE_STARTNG_TIME;
+					encr_info, iei = RSL_IE_ENCR_INFO;
 
 					req_ref, iei = RSL_IE_REQ_REFERENCE;
 					full_imm_ass_info, iei = RSL_IE_FULL_IMM_ASS_INFO;
@@ -852,6 +867,22 @@
 		}
 	}
 
+	/* 8.4.6 BSC ->BTS */
+	template RSL_Message tr_RSL_ENCR_CMD(template RslChannelNr chan_nr,
+					     template RslLinkId link_id := ?,
+					     template OCT1 alg := ?,
+					     template octetstring key := ?,
+					     template octetstring l3_info := ?) := {
+		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
+		msg_type := RSL_MT_ENCR_CMD,
+		ies := {
+			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
+			tr_RSL_IE(RSL_IE_Body:{encr_info := tr_RSL_IE_EncrInfo(alg, key)}),
+			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
+			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
+		}
+	}
+
 	/* 8.4.10 BTS -> BSC */
 	template RSL_Message ts_RSL_MODE_MODIFY_ACK(RslChannelNr chan_nr) := {
 		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),