bts: ciphering tests

Change-Id: If450e36cfd8cde713f304e57ec09bc1239bdf7ea
diff --git a/library/L1CTL_PortType.ttcn b/library/L1CTL_PortType.ttcn
index f8bc670..51a3936 100644
--- a/library/L1CTL_PortType.ttcn
+++ b/library/L1CTL_PortType.ttcn
@@ -4,6 +4,7 @@
 	import from UD_PortType all;
 	import from UD_Types all;
 	import from Osmocom_Types all;
+	import from Osmocom_Types all;
 	import from GSM_Types all;
 	import from GSM_RR_Types all;
 	import from L1CTL_PortType_CtrlFunct all;
@@ -176,7 +177,10 @@
 				self.stop;
 				}
 		}
+	}
 
+	function f_L1CTL_CRYPTO_REQ(L1CTL_PT pt, RslChannelNr chan_nr, uint8_t algo, octetstring key) {
+		pt.send(ts_L1CTL_CRYPTO_REQ(chan_nr, algo, key));
 	}
 
 	function f_connect_reset(L1CTL_PT pt, charstring l1ctl_sock_path := m_l1ctl_sock_path) {
diff --git a/library/L1CTL_Types.ttcn b/library/L1CTL_Types.ttcn
index 4c0e14d..656f292 100644
--- a/library/L1CTL_Types.ttcn
+++ b/library/L1CTL_Types.ttcn
@@ -286,6 +286,12 @@
 		OCT3		padding
 	} with { variant "" };
 
+	type record L1CtlCryptoReq {
+		uint8_t		algo,
+		uint8_t		key_len,
+		octetstring	key
+	} with { variant (key_len) "LENGTHTO(key)" };
+
 
 	type record L1ctlTrafficReq {
 		octetstring	data length(TRAFFIC_DATA_LEN)
@@ -311,6 +317,7 @@
 		L1ctlDmEstReq		dm_est_req,
 		L1ctlReset		reset_req,
 		//L1ctlNeighPmReq		neigh_pm_req,
+		L1CtlCryptoReq		crypto_req,
 		L1ctlTrafficReq		traffic_req,
 		L1ctlTbfCfgReq		tbf_cfg_req,
 		octetstring		other
@@ -341,6 +348,7 @@
 					     par_req, header.msg_type = L1CTL_PARAM_REQ;
 					     dm_est_req, header.msg_type = L1CTL_DM_EST_REQ;
 					     reset_req, header.msg_type = L1CTL_RESET_REQ;
+					     crypto_req, header.msg_type = L1CTL_CRYPTO_REQ;
 					     traffic_req, header.msg_type = L1CTL_TRAFFIC_REQ;
 					     tbf_cfg_req, header.msg_type = L1CTL_TBF_CFG_REQ;
 					     other, OTHERWISE;
@@ -631,6 +639,25 @@
 		}
 	};
 
+	template (value) L1ctlUlMessage ts_L1CTL_CRYPTO_REQ(RslChannelNr chan_nr, uint8_t algo,
+							    octetstring key) := {
+		header := ts_L1ctlHeader(L1CTL_CRYPTO_REQ),
+		ul_info := {
+			chan_nr := chan_nr,
+			link_id := ts_RslLinkID_DCCH(0),
+			padding := '0000'O
+		},
+		ul_info_tbf := omit,
+		ul_info_abs := omit,
+		payload := {
+			crypto_req := {
+				algo := algo,
+				key_len := 0, /* overwritten */
+				key := key
+			}
+		}
+	};
+
 	template ImmediateAssignment t_IMM_ASS(uint8_t ra, GsmFrameNumber fn) := {
 		ded_or_tbf := ?,
 		page_mode := ?,
diff --git a/library/L3_Templates.ttcn b/library/L3_Templates.ttcn
index 3304662..5acd2bf 100644
--- a/library/L3_Templates.ttcn
+++ b/library/L3_Templates.ttcn
@@ -388,6 +388,28 @@
 	}
 }
 
+template (value) PDU_ML3_NW_MS ts_RRM_CiphModeCmd(BIT3 alg_id) := {
+	discriminator := '0000'B, /* overwritten */
+	tiOrSkip := {
+		skipIndicator := '0000'B
+	},
+	msgs := {
+		rrm := {
+			cipheringModeCommand := {
+				messageType := '00110101'B,
+				cipherModeSetting := {
+					sC := '1'B,
+					algorithmIdentifier := alg_id
+				},
+				cipherModeResponse := {
+					cR := '0'B,
+					spare := '000'B
+				}
+			}
+		}
+	}
+}
+
 template (value) PDU_ML3_MS_NW ts_RRM_CiphModeCompl := {
 	discriminator := '0000'B, /* overwritten */
 	tiOrSkip := {
diff --git a/library/LAPDm_Types.ttcn b/library/LAPDm_Types.ttcn
index 2e008e5..32e1ba6 100644
--- a/library/LAPDm_Types.ttcn
+++ b/library/LAPDm_Types.ttcn
@@ -275,10 +275,10 @@
 		}
 	}
 
-	template LapdmFrame ts_LAPDm_UI(LapdmSapi sapi, boolean c_r, boolean p, octetstring l3) := {
+	template LapdmFrame ts_LAPDm_UI(LapdmSapi sapi, boolean c_r, octetstring l3) := {
 		ab := {
 			addr := ts_LapdmAddr(sapi, c_r),
-			ctrl := ts_LapdmCtrlUI(p),
+			ctrl := ts_LapdmCtrlUI,
 			len := 0,
 			m := false,
 			el := 1,
@@ -286,10 +286,10 @@
 		}
 	}
 	template LapdmFrame tr_LAPDm_UI(template LapdmSapi sapi, template boolean c_r,
-					  template boolean p, template octetstring l3) := {
+					template octetstring l3) := {
 		ab := {
 			addr := tr_LapdmAddr(sapi, c_r),
-			ctrl := tr_LapdmCtrlUI(p),
+			ctrl := tr_LapdmCtrlUI,
 			len := ?,
 			m := false,
 			el := 1,
@@ -297,22 +297,69 @@
 		}
 	}
 
-	template LapdmFrame ts_LAPDm_B4_UI(LapdmSapi sapi, boolean c_r, boolean p, octetstring l3) := {
+	template LapdmFrame ts_LAPDm_B4_UI(LapdmSapi sapi, boolean c_r, octetstring l3) := {
 		b4 := {
 			addr := ts_LapdmAddr(sapi, c_r),
-			ctrl := ts_LapdmCtrlUI(p),
+			ctrl := ts_LapdmCtrlUI,
 			payload := l3
 		}
 	}
 	template LapdmFrame tr_LAPDm_B4_UI(template LapdmSapi sapi, template boolean c_r,
-					  template boolean p, template octetstring l3) := {
+					   template octetstring l3) := {
 		b4 := {
 			addr := tr_LapdmAddr(sapi, c_r),
-			ctrl := tr_LapdmCtrlUI(p),
+			ctrl := tr_LapdmCtrlUI,
 			payload := l3
 		}
 	}
 
+	template LapdmFrame tr_LAPDm_I(template LapdmSapi sapi, template boolean c_r,
+					template boolean p, template uint3_t nr,
+					template uint3_t ns, template octetstring l3) := {
+		ab := {
+			addr := tr_LapdmAddr(sapi, c_r),
+			ctrl := tr_LapdmCtrlI(nr, ns, p),
+			len := ?,
+			m := false,
+			el := 1,
+			payload := l3
+		}
+	}
+	template (value) LapdmFrame ts_LAPDm_I(LapdmSapi sapi, boolean c_r, boolean p, uint3_t nr,
+						uint3_t ns, octetstring l3) := {
+		ab := {
+			addr := ts_LapdmAddr(sapi, c_r),
+			ctrl := ts_LapdmCtrlI(nr, ns, p),
+			len := 0,
+			m := false,
+			el := 1,
+			payload := l3
+		}
+	}
+
+	template LapdmFrame tr_LAPDm_RR(template LapdmSapi sapi, template boolean c_r,
+					template boolean p, template uint3_t nr) := {
+		ab := {
+			addr := tr_LapdmAddr(sapi, c_r),
+			ctrl := tr_LapdmCtrlRR(nr, p),
+			len := 0,
+			m := false,
+			el := 1,
+			payload := ''O
+		}
+	}
+	template (value) LapdmFrame ts_LAPDm_RR(LapdmSapi sapi, boolean c_r,
+						boolean p, uint3_t nr) := {
+		ab := {
+			addr := ts_LapdmAddr(sapi, c_r),
+			ctrl := ts_LapdmCtrlRR(nr, p),
+			len := 0,
+			m := false,
+			el := 1,
+			payload := ''O
+		}
+	}
+
 
 
 } with { encode "RAW"; /*variant "FIELDORDER(msb)" */}
diff --git a/library/RSL_Types.ttcn b/library/RSL_Types.ttcn
index 2d9c92e..b81bbbd 100644
--- a/library/RSL_Types.ttcn
+++ b/library/RSL_Types.ttcn
@@ -364,18 +364,30 @@
 	}
 
 	/* 9.3.7 */
+	type enumerated RSL_AlgId {
+		RSL_ALG_ID_A5_0 ('00000001'B),
+		RSL_ALG_ID_A5_1 ('00000010'B),
+		RSL_ALG_ID_A5_2 ('00000011'B),
+		RSL_ALG_ID_A5_3 ('00000100'B),
+		RSL_ALG_ID_A5_4 ('00000101'B),
+		RSL_ALG_ID_A5_5 ('00000110'B),
+		RSL_ALG_ID_A5_6 ('00000111'B),
+		RSL_ALG_ID_A5_7 ('00001000'B)
+	} with { variant "FIELDLENGTH(8)" };
 	type record RSL_IE_EncryptionInfo {
 		uint8_t		len,
-		OCT1		alg_id,
+		RSL_AlgId	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) := {
+	template RSL_IE_EncryptionInfo tr_RSL_IE_EncrInfo(template RSL_AlgId alg,
+							  template octetstring key) := {
 		len := ?,
 		alg_id := alg,
 		key := key
 	}
-	template (value) RSL_IE_EncryptionInfo ts_RSL_IE_EncrInfo(OCT1 alg, octetstring key) := {
+	template (value) RSL_IE_EncryptionInfo ts_RSL_IE_EncrInfo(template (value) RSL_AlgId alg,
+								  octetstring key) := {
 		len := 0, /* overwritten */
 		alg_id := alg,
 		key := key
@@ -1154,7 +1166,7 @@
 	/* 8.4.6 BSC ->BTS */
 	template RSL_Message tr_RSL_ENCR_CMD(template RslChannelNr chan_nr,
 					     template RslLinkId link_id := ?,
-					     template OCT1 alg := ?,
+					     template RSL_AlgId alg := ?,
 					     template octetstring key := ?,
 					     template octetstring l3_info := ?) := {
 		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
@@ -1168,7 +1180,7 @@
 	}
 	template (value) RSL_Message ts_RSL_ENCR_CMD(template (value) RslChannelNr chan_nr,
 						     template (value) RslLinkId link_id,
-						     OCT1 alg, octetstring key,
+						     template (value) RSL_AlgId alg, octetstring key,
 						     octetstring l3_info) := {
 		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
 		msg_type := RSL_MT_ENCR_CMD,