GTP_Templates: Add templates for some GTPv1C IEs

Change-Id: I84aac34ca40a2707dc9da28e112fd7684e706c8e
diff --git a/library/GTP_Templates.ttcn b/library/GTP_Templates.ttcn
index 031d9b2..30e42e6 100644
--- a/library/GTP_Templates.ttcn
+++ b/library/GTP_Templates.ttcn
@@ -162,6 +162,77 @@
 		ptmsi_Signature := ptmsi_sig
 	}
 
+	/* MS Validated - 7.7.10 */
+	template (value) MS_Validated ts_MS_Validated(template (value) BIT1 msValidated) := {
+		type_gtpc := '0D'O,
+		msValidated := msValidated,
+		spare := '1111111'B
+	}
+	template (present) MS_Validated tr_MS_Validated(template (present) BIT1 msValidated := ?) := {
+		type_gtpc := '0D'O,
+		msValidated := msValidated,
+		spare := '1111111'B
+	}
+	function f_tr_MS_Validated(template BIT1 msValidated := *) return template MS_Validated {
+		if (istemplatekind(msValidated, "omit")) {
+			return omit;
+		} else if (istemplatekind(msValidated, "*")) {
+			return *;
+		} else {
+			return tr_MS_Validated(msValidated);
+		}
+	}
+	private function f_ts_MS_Validated(template (omit) BIT1 msValidated)
+	return template (omit) MS_Validated {
+		if (istemplatekind(msValidated, "omit")) {
+			return omit;
+		}
+		return ts_MS_Validated(msValidated);
+	}
+
+	/* 7.7.13 TEI Data I */
+	template (value) TeidDataI ts_TeidDataI(template (value) OCT4 teid) := {
+		type_gtpc := '10'O,
+		teidDataI := teid
+	}
+	template (present) TeidDataI tr_TeidDataI(template (present) OCT4 teid := ?) := {
+		type_gtpc := '10'O,
+		teidDataI := teid
+	}
+
+	/* 7.7.14 TEI Control Plane */
+	template (value) TeidControlPlane ts_TEIC(template (value) OCT4 teic) := {
+		type_gtpc := '11'O,
+		teidControlPlane := teic
+	}
+	template (present) TeidControlPlane tr_TEIC(template (present) OCT4 teic := ?) := {
+		type_gtpc := '11'O,
+		teidControlPlane := teic
+	}
+	private function f_ts_TEIC(template (omit) OCT4 teic)
+	return template (omit) TeidControlPlane {
+		if (istemplatekind(teic, "omit")) {
+			return omit;
+		}
+		return ts_TEIC(teic);
+	}
+
+	/* 7.7.15 Tunnel Endpoint Identifier Data II */
+	template (value) TeidDataII ts_TeidDataII(template (value) BIT4 nsapi,
+						  template (value) OCT4 teid) := {
+		type_gtpc := '12'O,
+		nsapi := nsapi,
+		unused := '0000'B,
+		teidDataII := teid
+	}
+	template (present) TeidDataII tr_TeidDataII(template (present) BIT4 nsapi := ?,
+						    template (present) OCT4 teid := ?) := {
+		type_gtpc := '12'O,
+		nsapi := nsapi,
+		unused := '0000'B,
+		teidDataII := teid
+	}
+
 	/* IMEI(SV) IE TS 29.060 7.7.53 */
 	template (value) IMEISV_gtpc ts_IMEISV(template (value) OCT8 imeisv) := {
 		type_gtpc := '9A'O,
@@ -236,6 +307,82 @@
 		chargingChar := chargingChar
 	}
 
+	/* 7.7.28 MM Context */
+	template (value) MM_Context ts_MM_ContextUMTS(template (value) OCT16 ck,
+						      template (value) OCT16 ik) := {
+		type_gtpc := '81'O,
+		context := {
+			mmcontUMTS := {
+				lengthf := 0, /* overwritten */
+				ksi := '001'B,
+				usedGPRSIntegrityAlgorithm := '000'B,
+				ugipai := '1'B, /* Integrity Protection not required */
+				gupii := '1'B, /* Ignore "Used GPRS integrity protection algorithm" field" */
+				spare1 := '000'B,
+				noofVectors := 0, /* TODO: fill quintpuplets*/
+				security := '01'B, /* UMTS key and quintuplets */
+				ck := ck,
+				ik := ik,
+				quintupletlength := 0, /* overwritten */
+				quintuplet := ''O,
+				drx_par := '0000'O,
+				msNetW_cap_length := 0, /* overwritten */
+				msNetw_cap := omit,
+				containerLength := 0, /* overwritten */
+				container := omit,
+				access_restriction_data_length := 0, /* overwritten */
+				access_restriction_data := omit
+			}
+		}
+	}
+
+	/* 7.7.29 PDP Context */
+	template (value) PDP_Context_GTPC ts_PDP_Context_GTPC(template (value) octetstring pdp_addr,
+							      template (value) octetstring ggsn_gsn_addr,
+							      template (value) octetstring apn,
+							      template (value) OCT4 ggsn_teic := '12345678'O,
+							      template (value) OCT4 ggsn_teid := '87654321'O) := {
+		type_gtpc := '82'O,
+		lengthf := 0, /* overwritten */
+		nsapi := '0101'B,
+		order := '0'B,
+		asi := '0'B,
+		vaa := '0'B,
+		ea := '0'B,
+		sapi := '0011'B,
+		spare1 := '0000'B,
+		qos_subLength := 0, /* overwritten */
+		qos_sub := ts_QosProfileValueDefault,
+		qos_reqLength := 0, /* overwritten */
+		qos_req := ts_QosProfileValueDefault,
+		qos_negLength := 0, /* overwritten */
+		qos_neg := ts_QosProfileValueDefault,
+		snd := '0000'O,
+		snu := '0000'O,
+		sendNPDUnum := '00'O,
+		receiveNPDUnum := '00'O,
+		uteidControlPlane := ggsn_teic,
+		uteidData1 := ggsn_teid,
+		pdpcontext := '00'O,
+		pdp_typeorg := '0001'B, /* IETF */
+		spare2 := '1111'B,
+		pdp_typenum := '21'O, /* IETF IPV4 */
+		pdp_addressLength := 0, /* overwritten */
+		pdp_address := pdp_addr,
+		ggsn_addressControlPlaneLength := 0, /* overwritten */
+		ggsn_addressControlPlane := ggsn_gsn_addr,
+		ggsn_addressUserPlaneLength := 0, /* overwritten */
+		ggsn_addressUserPlane := ggsn_gsn_addr,
+		apnLength := 0, /* overwritten */
+		apn := apn,
+		transactionId := '0001'B,
+		spare3 := '0000'B,
+		transactionID_cont := '00'O,
+		pdp_typenum2 := omit,
+		pdp_addresslength2 := omit,
+		pdp_Address2 := omit
+	}
+
 
 	/* template matching reception of GTP-C unit-data */
 	template (present) Gtp1cUnitdata tr_GTPC_MsgType(template (present) GtpPeer peer,
@@ -398,6 +545,11 @@
 		lengthf := lengthof(ip_addr),
 		addressf := ip_addr
 	}
+	template (present) GSN_Address_GTPC tr_GsnAddr(template (present) octetstring ip_addr := ?) := {
+		type_gtpc := '85'O,
+		lengthf := ?,
+		addressf := ip_addr
+	}
 
 	template (value) MSISDN ts_Msisdn(octetstring msisdn) := {
 		type_gtpc := '86'O,
@@ -405,39 +557,46 @@
 		msisdn := msisdn
 	}
 
+	template (value) QoSV_GTPC ts_QosValueDefault := {
+		reliabilityClass := '011'B,
+		delayClass := '001'B,
+		spare1 := '00'B,
+		precedenceClass := '010'B,
+		spare2 := '0'B,
+		peakThroughput := '1001'B,
+		meanThroughput := '11111'B,
+		spare3 := '000'B,
+		deliverErroneusSDU := '010'B, /* Erroneus SDU are delivered */
+		deliveryOrder := '10'B, /* Without delivery order */
+		trafficClass := '100'B, /* Background */
+		maxSDUSize := '96'O, /* 1500 octets */
+		maxBitrateUplink := 'FE'O, /* 8640, continues in extended octet */
+		maxBitrateDownlink := 'FE'O, /* 8640, continues in extended octet */
+		sduErrorRatio := '0100'B, /* 1x10^-4 */
+		residualBER := '0101'B, /* 1x10^-3 */
+		trafficHandlingPriority := '01'B, /* prio 1 */
+		transferDelay := '000001'B, /* 10 ms */
+		guaranteedBitRateUplink := 'FE'O, /* 8640, continues in extended octet */
+		guaranteedBitRateDownlink := 'FE'O, /* 8640, continues in extended octet */
+		sourceStatisticsDescriptor := '0000'B, /* unknown */
+		signallingIndication := '0'B, /* Not optimized */
+		spare4 := '000'B,
+		maxBitrateDownlinkExt := '5B'O, /* 33 mbps */
+		guaranteedBitRateDownlinkExt := '5B'O, /* 33 mbps */
+		maxBitrateUplinkExt := '6e'O, /* 52 mbps */
+		guaranteedBitRateUplinkExt := '6e'O /* 52 mbps */
+	}
+
+	template (value) QualityOfServiceProfile_Value ts_QosProfileValueDefault := {
+		allocRetensionPrio := '00'O,
+		qos_ProfileValue := ts_QosValueDefault
+	}
+
 	template (value) QualityOfServiceProfile ts_QosDefault := {
 		type_gtpc := '87'O,
 		lengthf := 17,
 		allocRetensionPrio := '00'O,
-		qos_ProfileValue := {
-			reliabilityClass := '011'B,
-			delayClass := '001'B,
-			spare1 := '00'B,
-			precedenceClass := '010'B,
-			spare2 := '0'B,
-			peakThroughput := '1001'B,
-			meanThroughput := '11111'B,
-			spare3 := '000'B,
-			deliverErroneusSDU := '010'B, /* Erroneus SDU are delivered */
-			deliveryOrder := '10'B, /* Without delivery order */
-			trafficClass := '100'B, /* Background */
-			maxSDUSize := '96'O, /* 1500 octets */
-			maxBitrateUplink := 'FE'O, /* 8640, continues in extended octet */
-			maxBitrateDownlink := 'FE'O, /* 8640, continues in extended octet */
-			sduErrorRatio := '0100'B, /* 1x10^-4 */
-			residualBER := '0101'B, /* 1x10^-3 */
-			trafficHandlingPriority := '01'B, /* prio 1 */
-			transferDelay := '000001'B, /* 10 ms */
-			guaranteedBitRateUplink := 'FE'O, /* 8640, continues in extended octet */
-			guaranteedBitRateDownlink := 'FE'O, /* 8640, continues in extended octet */
-			sourceStatisticsDescriptor := '0000'B, /* unknown */
-			signallingIndication := '0'B, /* Not optimized */
-			spare4 := '000'B,
-			maxBitrateDownlinkExt := '5B'O, /* 33 mbps */
-			guaranteedBitRateDownlinkExt := '5B'O, /* 33 mbps */
-			maxBitrateUplinkExt := '6e'O, /* 52 mbps */
-			guaranteedBitRateUplinkExt := '6e'O /* 52 mbps */
-		}
+		qos_ProfileValue := ts_QosValueDefault
 	}
 
 	template (value) IMSI_gtpc ts_Imsi(hexstring digits) := {
@@ -469,18 +628,41 @@
 		}
 	}
 
-	function f_ts_RATType(template (omit) OCT1 ratType := omit) return template (omit) RATType {
-		var template (omit) RATType rt;
-		if (istemplatekind(ratType, "omit")) {
-			rt := omit;
+	/* 7.7.50 RAT Type */
+	type enumerated GTP_RATType {
+		GTP_RAT_TYPE_RESERVED		(0),
+		GTP_RAT_TYPE_UTRAN		(1),
+		GTP_RAT_TYPE_GERAN		(2),
+		GTP_RAT_TYPE_WLAN		(3),
+		GTP_RAT_TYPE_GAN		(4),
+		GTP_RAT_TYPE_HSPA_E		(5),
+		GTP_RAT_TYPE_EUTRAN		(6)
+	};
+	template (value) RATType ts_RATType(template (value) OCT1 rat_type) := {
+			type_gtpc := '97'O,
+			lengthf := 1,
+			ratTypeValue := rat_type
+	}
+	function f_ts_RATType(template (omit) OCT1 rat_type := omit) return template (omit) RATType {
+		if (istemplatekind(rat_type, "omit")) {
+			return omit;
 		} else {
-			rt := {
-				type_gtpc := '97'O,
-				lengthf := 1,
-				ratTypeValue := ratType
-			};
+			return ts_RATType(rat_type);
 		}
-		return rt;
+	}
+	template (present) RATType tr_RATType(template (present) OCT1 rat_type) := {
+			type_gtpc := '97'O,
+			lengthf := 1,
+			ratTypeValue := rat_type
+	}
+	function f_tr_RATType(template OCT1 rat_type := *) return template RATType {
+		if (istemplatekind(rat_type, "omit")) {
+			return omit;
+		} else if (istemplatekind(rat_type, "*")) {
+			return *;
+		} else {
+			return tr_RATType(rat_type);
+		}
 	}
 
 	template (value) RoutingAreaIdentity ts_RoutingAreaIdentity(template (value) hexstring mcc_digits,
@@ -947,11 +1129,44 @@
 	}
 
 	/* SGSN Context Request - 7.5.3 */
+	template (present) GTPC_PDUs tr_SGSNContextReqPDU(template (present) RoutingAreaIdentity rai := ?,
+							template (present) OCT4 teic := ?,
+							template (present) octetstring sgsn_addr_control := ?,
+							template hexstring imsi := *,
+							template BIT1 msValidated := *,
+							template TLLI tlli := *,
+							template PacketTMSI ptmsi := *,
+							template PTMSI_Signature ptmsi_sig := *,
+							template OCT1 rat_type := *) := {
+		sgsn_ContextRequest := {
+			imsi := f_tr_Imsi(imsi),
+			routingAreaIdentity := rai,
+			tlli := tlli,
+			packetTMSI := ptmsi,
+			ptmsi_Signature := ptmsi_sig,
+			ms_Validated := f_tr_MS_Validated(msValidated),
+			teidControlPlane := {
+				type_gtpc := '11'O,
+				teidControlPlane := teic
+			},
+			sgsn_addr_controlPlane := tr_GsnAddr(sgsn_addr_control),
+			alternative_sgsn_addr_controlPlane := *,
+			sGSN_Number := *,
+			ratType := f_tr_RATType(rat_type),
+			hopCounter := *,
+			private_extension_gtpc := *
+		}
+	}
+	template (present) Gtp1cUnitdata tr_GTPC_SGSNContextReq(template (present) GtpPeer peer,
+								template (present) GTPC_PDUs SGSNContextReqPDU) := {
+		peer := peer,
+		gtpc := tr_GTP1C_PDU(sgsnContextRequest, '00000000'O, SGSNContextReqPDU)
+	}
 	template (value) GTPC_PDUs ts_SGSNContextReqPDU(template (value) RoutingAreaIdentity rai,
 							template (value) OCT4 teic,
 							template (value) octetstring sgsn_addr_control,
 							template (omit) hexstring imsi := omit,
-							template (value) BIT1 msValidated := '0'B,
+							template (omit) BIT1 msValidated := '0'B,
 							template (omit) TLLI tlli := omit,
 							template (omit) PacketTMSI ptmsi := omit,
 							template (omit) PTMSI_Signature ptmsi_sig := omit,
@@ -962,11 +1177,7 @@
 			tlli := tlli,
 			packetTMSI := ptmsi,
 			ptmsi_Signature := ptmsi_sig,
-			ms_Validated := {
-				type_gtpc := '0D'O,
-				msValidated := msValidated,
-				spare := '1111111'B
-			},
+			ms_Validated := f_ts_MS_Validated(msValidated),
 			teidControlPlane := {
 				type_gtpc := '11'O,
 				teidControlPlane := teic
@@ -1025,7 +1236,66 @@
 								 template (present) GTPC_PDUs SGSNContextRespPDU := ?)
 		:= tr_GTPC_MsgType(peer, sgsnContextResponse, teid, SGSNContextRespPDU);
 
+	template (value) GTPC_PDUs ts_SGSNContextRespPDU(template (value) GTP_Cause cause,
+							template (omit) hexstring imsi := omit,
+							template (omit) OCT4 teic := omit,
+							template (omit) octetstring sgsn_addr_control := omit,
+							template (omit) MM_Context mm_context := omit,
+							template (omit) PDP_Context_GTPC_List pdp_ctx_list := omit) := {
+		sgsn_ContextResponse := {
+			cause := ts_Cause_gtpc(cause),
+			imsi := f_ts_Imsi(imsi),
+			teidControlPlane := f_ts_TEIC(teic),
+			rabContext := omit,
+			radioPrioritySMS := omit,
+			radioPriority := omit,
+			packetFlowID := omit,
+			charging_char := omit,
+			mm_Context := mm_context,
+			pdp_Context := pdp_ctx_list,
+			sgsn_addr_controlPlane := ts_GsnAddr(sgsn_addr_control),
+			pdpContextPriorization := omit,
+			radioPriority_LCS := omit,
+			mBMS_UE_Context := omit,
+			subscribedRFSP_Index := omit,
+			rFSP_IndexInUse := omit,
+			colocatedGGSN_PGW_FQDN := omit,
+			evolvedAllocationRetentionPriorityII := omit,
+			extendedCommonFlags := omit,
+			ue_network_capability := omit,
+			ue_ambr := omit,
+			apn_ambr_nsapi := omit,
+			signallingPriorityIndication_nsapi := omit,
+			higher_bitrates_than_16mbps_flag := omit,
+			selectionMode_nsapi := omit,
+			localHomeNetworkID_nsapi := omit,
+			uE_UsageType := omit,
+			extendedCommonFlagsII := omit,
+			private_extension_gtpc := omit
+		}
+	}
+	template (value) Gtp1cUnitdata ts_GTPC_SGSNContextResp(GtpPeer peer, OCT4 teid, uint16_t seq,
+							      template (value) GTPC_PDUs SGSNContextRespPDU) := {
+		peer := peer,
+		gtpc := ts_GTP1C_PDU(sgsnContextResponse, teid, valueof(SGSNContextRespPDU), seq)
+	}
+
+
 	/* SGSN Context Acknowledge - 7.5.5 */
+	template (present) GTPC_PDUs tr_SGSNContextAckPDU(template (present) GTP_Cause cause := ?) := {
+		sgsn_ContextAcknowledge := {
+			cause := tr_Cause_gtpc(cause),
+			teidDataII := *,
+			sgsn_AddressForUserTraffic := *,
+			sgsn_Number := *,
+			nodeIdentifier  := *,
+			private_extension_gtpc := *
+		}
+	}
+	template (present) Gtp1cUnitdata tr_GTPC_SGSNContextAck(template (present) GtpPeer peer := ?,
+								 template (present) OCT4 teid := ?,
+								 template (present) GTPC_PDUs SGSNContextAckPDU := ?)
+		:= tr_GTPC_MsgType(peer, sgsnContextAcknowledge, teid, SGSNContextAckPDU);
 	template (value) GTPC_PDUs ts_SGSNContextAckPDU(template (value) GTP_Cause cause := GTP_CAUSE_REQUEST_ACCEPTED) := {
 		sgsn_ContextAcknowledge := {
 			cause := ts_Cause_gtpc(cause),