Commit 8b22dd87 authored by mullers's avatar mullers
Browse files

calc len implementation for SA proposal started

parent 9742c8d8
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -242,4 +242,26 @@
	external function fx_calcAuth()
	return octetstring;

	/* @desc 	This external function runs the IkePayload through Codec and returns 
	 *			the octetstring representing the IkePayload
	 *			
	 * @param 	p_ikePayload Ike Payload to be encoded to octetstring
	 * @return 	octetstring
	*/
	external function fx_ikePLToOct(IkePayload p_ikePayload)
	return octetstring;

	/* @desc 	This external function runs the SaProposal through Codec and returns 
	 *			the octetstring representing the SaProposal
	 *			
	 * @param 	p_saProposal SaProposal to be encoded to octetstring
	 * @return 	octetstring
	*/
	external function fx_saProposalToOct(SaProposal p_saProposal)
	return octetstring;



	

}// end module LibIpv6_ExternalFunctions
+1 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
	import from LibIpv6_CommonRfcs_TypesAndValues all;
	import from LibIpv6_Rfc4306Ikev2_TypesAndValues all;
	
	
group rfc2460Root_Functions {
	
	group ipv6Packets {	
@@ -197,19 +198,6 @@ group rfc2460Root_Functions {
		}
		v_ret := f_setAuthHeader (v_activeIpv6Packet);

		//smu added
		if (ispresent(v_activeIpv6Packet.ipv6Payload)) {
			if (ischosen(v_activeIpv6Packet.ipv6Payload.ikeMsg)) {
			
				//length  in octets of this user datagram  including the header and the data.
				v_activeIpv6Packet.ipv6Payload.ikeMsg.msgLength := 0;
				v_activeIpv6Packet.ipv6Payload.ikeMsg.checksum := 0;
			}
			
			
		}
		

		p_ipv6Packet := v_activeIpv6Packet;

		return v_ret;
+111 −10
Original line number Diff line number Diff line
@@ -576,15 +576,30 @@ group sendRequests {
	function f_sendIkeSaInitReq(in template IkeSaInitRequest p_ikeSaInitRequest)
	runs on Ipv6Node
	return FncRetCode {
		var IkeSaInitRequest v_ipPkt;
		v_ipPkt := valueof(p_ikeSaInitRequest);
		var IkeSaInitRequest v_ipPkt := valueof(p_ikeSaInitRequest);
		var FncRetCode v_ret := e_error;

		//smu added
		if (ispresent(v_ipPkt.ipv6Payload)) {
			if (ischosen(v_ipPkt.ipv6Payload.ikeMsg)) {

				//Length in octets of IKEv2 header + payloads in octets
				v_ipPkt.ipv6Payload.ikeMsg.ikev2Header.messageLength := 0;

				//For each IkePayload: Length in octets of the current payload, including the generic payload header
				v_ret := f_calcPList(v_ipPkt.ipv6Payload.ikeMsg.payloadList);


				//Length in octets of this proposal, including all transforms and attributes that follow.

				
			
				//Length in octets of this UDP packet including the header and the data.
				v_ipPkt.ipv6Payload.ikeMsg.msgLength := 0;
				v_ipPkt.ipv6Payload.ikeMsg.checksum := 0;
			}
			
			
		if(f_setExtensionHeaders(
			v_ipPkt,
			v_ipPkt.ipv6Hdr.sourceAddress,
			v_ipPkt.ipv6Hdr.destinationAddress) != e_success) {
				log(" **** f_sendIkeSaInitReq: Error when calculating length of templates ****");
				return e_error;
		}
		
		//send
@@ -804,4 +819,90 @@ group establishSAFns {

}//end establishSAFns


group calcIkeFns {
	
	function f_calcPList(inout IkePayloadList p_payloadList)
	return FncRetCode {
		var FncRetCode v_ret := e_success;
		var UInt8 i := 0;

		for(i:=0;i<sizeof(p_payloadList) and v_ret == e_success; i := i+1) {
			v_ret := f_calcIkePLLen(p_payloadList[i]);
		}

		return v_ret;

	}//end f_calcPList

	function f_calcIkePLLen(inout IkePayload p_payload)
	return FncRetCode {
		var FncRetCode v_ret := e_success;
		var UInt8 i := 0;
		var UInt8 j := 0;

		if (ischosen(p_payload.securityAssociation)) {
			p_payload.securityAssociation.payloadLength := lengthof(fx_ikePLToOct(p_payload));
			for(i:=0;i<sizeof(p_payload.securityAssociation.saProposalList[i]); i := i+1) {
				//smu add transforms here
				p_payload.securityAssociation.saProposalList[i].proposalLength := lengthof(fx_saProposalToOct(p_payload.securityAssociation.saProposalList[i]));
			}
		}
		else if (ischosen(p_payload.keyExchange)) {
			p_payload.securityAssociation.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.idInitiator)) {
			p_payload.keyExchange.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.idResponder)) {
			p_payload.idResponder.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.certificate)) {
			p_payload.certificate.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.certificateRequest)) {
			p_payload.certificateRequest.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.authentication)) {
			p_payload.authentication.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.nonce)) {
			p_payload.nonce.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.notify)) {
			p_payload.notify.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		//else if (ischosen(p_payload.delete)) {
		//	p_payload.delete.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		//}
		else if (ischosen(p_payload.vendorId)) {
			p_payload.vendorId.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.tsInitiator)) {
			p_payload.tsInitiator.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.tsResponder)) {
			p_payload.tsResponder.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.encrypted)) {
			p_payload.encrypted.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.configuration)) {
			p_payload.configuration.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else if (ischosen(p_payload.extensibleAuth)) {
			p_payload.extensibleAuth.payloadLength := lengthof(fx_ikePLToOct(p_payload));
		}
		else {
			v_ret := e_error;
			log("**** f_calcPL: Error: IkePayload contains unknown element. IkePayload length cannot be calculated ****")
			log(p_payload);
		}

		return v_ret;

	}//end f_calcIkePLLen
	
}//end group calcIkeFns

} // end module LibIpv6_Rfc4306Ikev2_Functions