]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1.Update IPsec driver to set the Transform structure’s Next Payload field to be zero...
authorqianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 23 Nov 2011 10:31:04 +0000 (10:31 +0000)
committerqianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 23 Nov 2011 10:31:04 +0000 (10:31 +0000)
2.Delete all SAs in the IPsec->Stop().

Signed-off-by: qianouyang
Reviewed-by: sfu5
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12768 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/IpSecDxe/IkeService.c
NetworkPkg/IpSecDxe/IkeService.h
NetworkPkg/IpSecDxe/Ikev2/Exchange.c
NetworkPkg/IpSecDxe/Ikev2/Payload.c
NetworkPkg/IpSecDxe/IpSecDriver.c
NetworkPkg/IpSecDxe/IpSecImpl.c

index 8def212daec3e7d4243b09886b644bc0708fc6c9..2ea5962537c42cb7c30e961961ae5bb8e56147e5 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
   Provide IPsec Key Exchange (IKE) service general interfaces.\r
-  \r
+\r
   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
@@ -104,13 +104,13 @@ IkeLookupUdp (
 \r
 /**\r
   Configure a UDPIO's UDP4 instance.\r
-  \r
-  This fuction is called by the UdpIoCreateIo() to configures a \r
+\r
+  This fuction is called by the UdpIoCreateIo() to configures a\r
   UDP4 instance.\r
-    \r
+\r
   @param[in] UdpIo         The UDP_IO to be configured.\r
   @param[in] Context       User-defined data when calling UdpIoCreateIo().\r
-  \r
+\r
   @retval EFI_SUCCESS      The configuration succeeded.\r
   @retval Others           The UDP4 instance fails to configure.\r
 \r
@@ -146,13 +146,13 @@ IkeConfigUdp4 (
 \r
 /**\r
   Configure a UDPIO's UDP6 instance.\r
-  \r
-  This fuction is called by the UdpIoCreateIo()to configure a \r
+\r
+  This fuction is called by the UdpIoCreateIo()to configure a\r
   UDP6 instance.\r
-    \r
+\r
   @param[in] UdpIo         The UDP_IO to be configured.\r
   @param[in] Context       User-defined data when calling UdpIoCreateIo().\r
-  \r
+\r
   @retval EFI_SUCCESS      The configuration succeeded.\r
   @retval Others           The configuration fails.\r
 \r
@@ -194,14 +194,14 @@ IkeConfigUdp6 (
 \r
 /**\r
   Open and configure the related output UDPIO for IKE packet sending.\r
-  \r
-  If the UdpService is not configured, this fuction calls UdpIoCreatIo() to \r
+\r
+  If the UdpService is not configured, this fuction calls UdpIoCreatIo() to\r
   create UDPIO to bind this UdpService for IKE packet sending. If the UdpService\r
   has already been configured, then return.\r
-  \r
+\r
   @param[in] UdpService     The UDP_IO to be configured.\r
   @param[in] RemoteIp       User-defined data when calling UdpIoCreateIo().\r
-  \r
+\r
   @retval EFI_SUCCESS      The configuration is successful.\r
   @retval Others           The configuration fails.\r
 \r
@@ -340,16 +340,16 @@ ON_EXIT:
 \r
 /**\r
   Open and configure a UDPIO of Udp4 for IKE packet receiving.\r
-  \r
-  This function is called at the IPsecDriverBinding start. IPsec create a UDP4 and \r
+\r
+  This function is called at the IPsecDriverBinding start. IPsec create a UDP4 and\r
   UDP4 IO for each NIC handle.\r
-  \r
+\r
   @param[in] Private        Point to IPSEC_PRIVATE_DATA\r
   @param[in] Controller     Handler for NIC card.\r
-  \r
+\r
   @retval EFI_SUCCESS             The Operation is successful.\r
   @retval EFI_OUT_OF_RESOURCE     The required system resource can't be allocated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IkeOpenInputUdp4 (\r
@@ -411,16 +411,16 @@ IkeOpenInputUdp4 (
 \r
 /**\r
   Open and configure a UDPIO of Udp6 for IKE packet receiving.\r
-  \r
+\r
   This function is called at the IPsecDriverBinding start. IPsec create a UDP6 and UDP6\r
   IO for each NIC handle.\r
-  \r
+\r
   @param[in] Private        Point to IPSEC_PRIVATE_DATA\r
   @param[in] Controller     Handler for NIC card.\r
-  \r
+\r
   @retval EFI_SUCCESS             The Operation is successful.\r
   @retval EFI_OUT_OF_RESOURCE     The required system resource can't be allocated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IkeOpenInputUdp6 (\r
@@ -479,18 +479,18 @@ IkeOpenInputUdp6 (
 \r
 /**\r
   The general interface of starting IPsec Key Exchange.\r
-  \r
+\r
   This function is called when a IKE negotiation to start getting a Key.\r
-  \r
-  @param[in] UdpService   Point to IKE_UDP_SERVICE which will be used for \r
+\r
+  @param[in] UdpService   Point to IKE_UDP_SERVICE which will be used for\r
                           IKE packet sending.\r
   @param[in] SpdEntry     Point to the SPD entry related to the IKE negotiation.\r
   @param[in] RemoteIp     Point to EFI_IP_ADDRESS related to the IKE negotiation.\r
-  \r
+\r
   @retval EFI_SUCCESS            The Operation is successful.\r
   @retval EFI_ACCESS_DENIED      No related PAD entry was found.\r
   @retval EFI_INVALID_PARAMETER  The IKE version is not supported.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IkeNegotiate (\r
@@ -519,8 +519,8 @@ IkeNegotiate (
   }\r
   //\r
   // Try to find the IKE SA session in the IKEv1 and IKEv2 established SA session list.\r
-  //  \r
-  IkeSaSession = (UINT8 *) Ikev2SaSessionLookup (&Private->Ikev2EstablishedList, RemoteIp);    \r
+  //\r
+  IkeSaSession = (UINT8 *) Ikev2SaSessionLookup (&Private->Ikev2EstablishedList, RemoteIp);\r
 \r
 \r
   if (IkeSaSession == NULL) {\r
@@ -551,7 +551,7 @@ IkeNegotiate (
     if (IkeVersion != 2) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-   \r
+\r
     Exchange = mIkeExchange[IkeVersion - 1];\r
     //\r
     // Start the quick mode stage to negotiate child SA.\r
@@ -564,15 +564,15 @@ IkeNegotiate (
 \r
 /**\r
   The generic interface when receive a IKE packet.\r
-  \r
+\r
   This function is called when UDP IO receives a IKE packet.\r
-  \r
+\r
   @param[in] Packet       Point to received IKE packet.\r
-  @param[in] EndPoint     Point to UDP_END_POINT which contains the information of \r
+  @param[in] EndPoint     Point to UDP_END_POINT which contains the information of\r
                           Remote IP and Port.\r
   @param[in] IoStatus     The Status of Recieve Token.\r
   @param[in] Context      Point to data passed from the caller.\r
-    \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -687,17 +687,19 @@ ON_EXIT:
 \r
 /**\r
   Delete all established IKE SAs and related Child SAs.\r
-  \r
-  This function is the subfunction of the IpSecCleanupAllSa(). It first calls  \r
-  IkeDeleteChildSa() to delete all Child SAs then send out the related \r
+\r
+  This function is the subfunction of the IpSecCleanupAllSa(). It first calls\r
+  IkeDeleteChildSa() to delete all Child SAs then send out the related\r
   Information packet.\r
 \r
-  @param[in]  Private  Pointer of the IPSEC_PRIVATE_DATA\r
+  @param[in]  Private           Pointer of the IPSEC_PRIVATE_DATA\r
+  @param[in]  IsDisableIPsec    Indicate whether needs to disable IPsec.\r
 \r
 **/\r
 VOID\r
 IkeDeleteAllSas (\r
-  IN IPSEC_PRIVATE_DATA  *Private\r
+  IN IPSEC_PRIVATE_DATA  *Private,\r
+  IN BOOLEAN             IsDisableIpsec\r
   )\r
 {\r
   LIST_ENTRY             *Entry;\r
@@ -719,17 +721,17 @@ IkeDeleteAllSas (
   //\r
   if (!IsListEmpty (&Private->Ikev2SessionList)) {\r
     NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->Ikev2SessionList) {\r
-      Ikev2SaSession = IKEV2_SA_SESSION_BY_SESSION (Entry);  \r
+      Ikev2SaSession = IKEV2_SA_SESSION_BY_SESSION (Entry);\r
       RemoveEntryList (Entry);\r
       Ikev2SaSessionFree (Ikev2SaSession);\r
     }\r
   }\r
-  \r
+\r
   //\r
   // If there is no existing established IKE SA, set the Ipsec DisableFlag to TRUE\r
   // and turn off the IsIPsecDisabling flag.\r
   //\r
-  if (IsListEmpty (&Private->Ikev2EstablishedList)) {\r
+  if (IsListEmpty (&Private->Ikev2EstablishedList) && IsDisableIpsec) {\r
     Value = IPSEC_STATUS_DISABLED;\r
     Status = gRT->SetVariable (\r
                IPSECCONFIG_STATUS_NAME,\r
@@ -752,7 +754,7 @@ IkeDeleteAllSas (
     for (Entry = Private->Ikev2EstablishedList.ForwardLink; Entry != &Private->Ikev2EstablishedList;) {\r
       Ikev2SaSession = IKEV2_SA_SESSION_BY_SESSION (Entry);\r
       Entry = Entry->ForwardLink;\r
-    \r
+\r
       Ikev2SaSession->SessionCommon.State = IkeStateSaDeleting;\r
 \r
       //\r
@@ -762,10 +764,10 @@ IkeDeleteAllSas (
       if (IkeVersion == 2) {\r
         Exchange = mIkeExchange[IkeVersion - 1];\r
         Exchange->NegotiateInfo((UINT8*)Ikev2SaSession, NULL);\r
-      }      \r
+      }\r
     }\r
   }\r
-  \r
+\r
 }\r
 \r
 \r
index 215fb93fdd2abeadcf80bc6bf8a2d0e14b3ab632..d1ac103dd4a8094d34f5c1cf4952ec66d9764c92 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
   Prototypes definitions of IKE service.\r
-  \r
+\r
   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
@@ -44,7 +44,7 @@ EFI_STATUS
   );\r
 \r
 /**\r
-  This is prototype definition fo general interface to start a IKE negotiation at Quick Mode. \r
+  This is prototype definition fo general interface to start a IKE negotiation at Quick Mode.\r
 \r
   This function will be called when the related IKE SA is existed and start to\r
   create a Child SA.\r
@@ -81,7 +81,7 @@ EFI_STATUS
   );\r
 \r
 /**\r
-  This is prototype definition of the general interface when recived a IKE Pakcet \r
+  This is prototype definition of the general interface when recived a IKE Pakcet\r
   for the IKE SA establishing.\r
 \r
   @param[in]  UdpService      Point to UDP service used to send IKE Packet.\r
@@ -97,8 +97,8 @@ VOID
 \r
 /**\r
   This is prototyp definition of the general interface when recived a IKE Packet\r
-  xfor the Child SA establishing. \r
\r
+  xfor the Child SA establishing.\r
+\r
   @param[in]  UdpService      Point to UDP service used to send IKE packet.\r
   @param[in]  IkePacket       Point to received IKE packet.\r
 \r
@@ -111,7 +111,7 @@ VOID
   );\r
 \r
 /**\r
-  This is prototype definition of the general interface when received a IKE \r
+  This is prototype definition of the general interface when received a IKE\r
   information Packet.\r
 \r
   @param[in]  UdpService      Point to UDP service used to send IKE packet.\r
@@ -137,16 +137,16 @@ typedef struct _IKE_EXCHANGE_INTERFACE {
 \r
 /**\r
   Open and configure a UDPIO of Udp4 for IKE packet receiving.\r
-  \r
-  This function is called at the IPsecDriverBinding start. IPsec create a UDP4 and  \r
+\r
+  This function is called at the IPsecDriverBinding start. IPsec create a UDP4 and\r
   a UDP4 IO for each NIC handle.\r
-  \r
+\r
   @param[in] Private        Point to IPSEC_PRIVATE_DATA\r
   @param[in] Controller     Handler for NIC card.\r
-  \r
+\r
   @retval EFI_SUCCESS             The Operation is successful.\r
   @retval EFI_OUT_OF_RESOURCE     The required system resource can't be allocated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IkeOpenInputUdp4 (\r
@@ -156,16 +156,16 @@ IkeOpenInputUdp4 (
 \r
 /**\r
   Open and configure a UDPIO of Udp6 for IKE packet receiving.\r
-  \r
+\r
   This function is called at the IPsecDriverBinding start. IPsec create a UDP6 and UDP6\r
   IO for each NIC handle.\r
-  \r
+\r
   @param[in] Private        Point to IPSEC_PRIVATE_DATA\r
   @param[in] Controller     Handler for NIC card.\r
-  \r
+\r
   @retval EFI_SUCCESS             The Operation is successful.\r
   @retval EFI_OUT_OF_RESOURCE     The required system resource can't be allocated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IkeOpenInputUdp6 (\r
@@ -175,17 +175,17 @@ IkeOpenInputUdp6 (
 \r
 /**\r
   The general interface of starting IPsec Key Exchange.\r
-  \r
+\r
   This function is called when start a IKE negotiation to get a Key.\r
-  \r
-  @param[in] UdpService   Point to IKE_UDP_SERVICE which will be used for \r
+\r
+  @param[in] UdpService   Point to IKE_UDP_SERVICE which will be used for\r
                           IKE packet sending.\r
   @param[in] SpdEntry     Point to the SPD entry related to the IKE negotiation.\r
   @param[in] RemoteIp     Point to EFI_IP_ADDRESS related to the IKE negotiation.\r
-  \r
+\r
   @retval EFI_SUCCESS          The Operation is successful.\r
   @retval EFI_ACCESS_DENIED    No related PAD entry was found.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IkeNegotiate (\r
@@ -196,15 +196,15 @@ IkeNegotiate (
 \r
 /**\r
   The general interface when receive a IKE packet.\r
-  \r
+\r
   This function is called when UDP IO receives a IKE packet.\r
-  \r
+\r
   @param[in] Packet       Point to received IKE packet.\r
-  @param[in] EndPoint     Point to UDP_END_POINT which contains the information of \r
+  @param[in] EndPoint     Point to UDP_END_POINT which contains the information of\r
                           Remote IP and Port.\r
   @param[in] IoStatus     The Status of Recieve Token.\r
   @param[in] Context      Point to data passed from the caller.\r
-    \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -235,17 +235,19 @@ IkeLookupUdp (
 \r
 /**\r
   Delete all established IKE SAs and related Child SAs.\r
-  \r
-  This function is the subfunction of the IpSecCleanupAllSa(). It first calls  \r
-  IkeDeleteChildSa() to delete all Child SAs then send out the related \r
+\r
+  This function is the subfunction of the IpSecCleanupAllSa(). It first calls\r
+  IkeDeleteChildSa() to delete all Child SAs then send out the related\r
   Information packet.\r
 \r
-  @param[in]  Private  Pointer of the IPSEC_PRIVATE_DATA.\r
+  @param[in]  Private           Pointer of the IPSEC_PRIVATE_DATA.\r
+  @param[in]  IsDisableIPsec    Indicate whether needs to disable IPsec.\r
 \r
 **/\r
 VOID\r
 IkeDeleteAllSas (\r
-  IN IPSEC_PRIVATE_DATA             *Private\r
+  IN IPSEC_PRIVATE_DATA             *Private,\r
+  IN BOOLEAN                        IsDisableIpsec\r
   );\r
 \r
 \r
index 94bdd86d908615abe773050329e81e3e3e58dc08..ffa53824d0f98f3df5293b0aa8bce1c126ed51a5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The general interfaces of the IKEv2.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -46,7 +46,7 @@ Ikev2NegotiateSa (
   IKEV2_PACKET_HANDLER      Handler;\r
   IKE_PACKET                *IkePacket;\r
   EFI_STATUS                Status;\r
-  \r
+\r
   if (UdpService == NULL || RemoteIp == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -66,7 +66,7 @@ Ikev2NegotiateSa (
     //\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
   // Create a new IkeSaSession and initiate the common parameters.\r
   //\r
@@ -79,7 +79,7 @@ Ikev2NegotiateSa (
   // Set the specific parameters and state(IKE_STATE_INIT).\r
   //\r
   IkeSaSession->Spd            = SpdEntry;\r
-  IkeSaSession->Pad            = PadEntry;  \r
+  IkeSaSession->Pad            = PadEntry;\r
   SessionCommon                = &IkeSaSession->SessionCommon;\r
   SessionCommon->IsInitiator   = TRUE;\r
   SessionCommon->State         = IkeStateInit;\r
@@ -88,13 +88,13 @@ Ikev2NegotiateSa (
   // to support it.\r
   //\r
   SessionCommon->PreferDhGroup = IKEV2_TRANSFORM_ID_DH_1024MODP;\r
-  \r
+\r
   CopyMem (\r
     &SessionCommon->RemotePeerIp,\r
     RemoteIp,\r
     sizeof (EFI_IP_ADDRESS)\r
     );\r
-  \r
+\r
   CopyMem (\r
     &SessionCommon->LocalPeerIp,\r
     &UdpService->DefaultAddress,\r
@@ -147,15 +147,15 @@ ON_ERROR:
 /**\r
   It is general interface to negotiate the Child SA.\r
 \r
-  There are three situations which will invoke this function. First, create a CHILD \r
-  SA if the input Context is NULL. Second, rekeying the existing IKE SA if the Context \r
-  is a IKEv2_SA_SESSION. Third, rekeying the existing CHILD SA if the context is a \r
+  There are three situations which will invoke this function. First, create a CHILD\r
+  SA if the input Context is NULL. Second, rekeying the existing IKE SA if the Context\r
+  is a IKEv2_SA_SESSION. Third, rekeying the existing CHILD SA if the context is a\r
   IKEv2_CHILD_SA_SESSION.\r
 \r
   @param[in] IkeSaSession  Pointer to IKEv2_SA_SESSION related to this operation.\r
   @param[in] SpdEntry      Pointer to IPSEC_SPD_ENTRY related to this operation.\r
   @param[in] Context       The data pass from the caller.\r
-  \r
+\r
   @retval EFI_SUCCESS          The operation is successful.\r
   @retval EFI_OUT_OF_RESOURCES The required system resource can't be allocated.\r
   @retval EFI_UNSUPPORTED      The condition is not support yet.\r
@@ -239,7 +239,7 @@ Ikev2NegotiateChildSa (
     if (EFI_ERROR (Status)) {\r
       goto ON_ERROR;\r
     }\r
-    \r
+\r
     //\r
     // Insert the ChildSaSession into processing child SA list.\r
     //\r
@@ -278,8 +278,8 @@ ON_ERROR:
   It is general interface to start the Information Exchange.\r
 \r
   There are three situations which will invoke this function. First, deliver a Delete Information\r
-  to delete the IKE SA if the input Context is NULL and the state of related IkeSaSeesion's is on \r
-  deleting.Second, deliver a Notify Information without the contents if the input Context is NULL. \r
+  to delete the IKE SA if the input Context is NULL and the state of related IkeSaSeesion's is on\r
+  deleting.Second, deliver a Notify Information without the contents if the input Context is NULL.\r
   Third, deliver a Notify Information if the input Context is not NULL.\r
 \r
   @param[in] IkeSaSession  Pointer to IKEv2_SA_SESSION related to this operation.\r
@@ -297,7 +297,7 @@ Ikev2NegotiateInfo (
   IN UINT8           *Context\r
   )\r
 {\r
-  \r
+\r
   EFI_STATUS                Status;\r
   IKEV2_SA_SESSION          *Ikev2SaSession;\r
   IKEV2_CHILD_SA_SESSION    *ChildSaSession;\r
@@ -318,11 +318,6 @@ Ikev2NegotiateInfo (
   //\r
   if (Ikev2SaSession->SessionCommon.State == IkeStateSaDeleting && Context == NULL) {\r
 \r
-    //\r
-    // The IKE SA Session should be initiator if it triggers the deleting.\r
-    //\r
-    Ikev2SaSession->SessionCommon.IsInitiator = TRUE;\r
-\r
     //\r
     // Generate Information Packet which contains the Delete Payload.\r
     //\r
@@ -335,10 +330,12 @@ Ikev2NegotiateInfo (
     //\r
     // Send out the Packet\r
     //\r
-    Status = Ikev2SendIkePacket (UdpService, (UINT8 *) SaCommon, IkePacket, 0);\r
+    if (UdpService != NULL) {\r
+      Status = Ikev2SendIkePacket (UdpService, (UINT8 *) SaCommon, IkePacket, 0);\r
 \r
-    if (EFI_ERROR (Status)) {\r
-      goto ON_ERROR;\r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_ERROR;\r
+      }\r
     }\r
   } else if (!IsListEmpty (&Ikev2SaSession->DeleteSaList)) {\r
     //\r
@@ -360,10 +357,12 @@ Ikev2NegotiateInfo (
       //\r
       // Send out the Packet\r
       //\r
-      Status = Ikev2SendIkePacket (UdpService, (UINT8 *) &ChildSaSession->SessionCommon, IkePacket, 0);\r
+      if (UdpService != NULL) {\r
+        Status = Ikev2SendIkePacket (UdpService, (UINT8 *) &ChildSaSession->SessionCommon, IkePacket, 0);\r
 \r
-      if (EFI_ERROR (Status)) {\r
-        goto ON_ERROR;\r
+        if (EFI_ERROR (Status)) {\r
+          goto ON_ERROR;\r
+        }\r
       }\r
     }\r
   }  else if (Context == NULL) {\r
@@ -386,9 +385,9 @@ ON_ERROR:
 /**\r
   The general interface when received a IKEv2 packet for the IKE SA establishing.\r
 \r
-  This function first find the related IKE SA Session according to the IKE packet's \r
+  This function first find the related IKE SA Session according to the IKE packet's\r
   remote IP. Then call the corresponding function to handle this IKE packet according\r
-  to the related IKE SA Session's State. \r
+  to the related IKE SA Session's State.\r
 \r
   @param[in] UdpService    Pointer of related UDP Service.\r
   @param[in] IkePacket     Data passed by caller.\r
@@ -411,13 +410,13 @@ Ikev2HandleSa (
   IPSEC_PRIVATE_DATA      *Private;\r
   BOOLEAN                 IsNewSession;\r
 \r
-  Private = (UdpService->IpVersion == IP_VERSION_4) ? \r
+  Private = (UdpService->IpVersion == IP_VERSION_4) ?\r
              IPSEC_PRIVATE_DATA_FROM_UDP4LIST(UdpService->ListHead) :\r
              IPSEC_PRIVATE_DATA_FROM_UDP6LIST(UdpService->ListHead);\r
 \r
   ChildSaSession = NULL;\r
   ChildSaCommon  = NULL;\r
-  \r
+\r
   //\r
   // Lookup the remote ip address in the processing IKE SA session list.\r
   //\r
@@ -461,7 +460,7 @@ Ikev2HandleSa (
       &UdpService->DefaultAddress,\r
       sizeof (EFI_IP_ADDRESS)\r
       );\r
-    \r
+\r
     IsNewSession = TRUE;\r
   }\r
 \r
@@ -517,15 +516,15 @@ Ikev2HandleSa (
     //\r
     // Generate a piggyback child SA in IKE_STATE_AUTH state.\r
     //\r
-    ASSERT (IsListEmpty (&IkeSaSession->ChildSaSessionList) && \r
+    ASSERT (IsListEmpty (&IkeSaSession->ChildSaSessionList) &&\r
             IsListEmpty (&IkeSaSession->ChildSaEstablishSessionList));\r
-    \r
+\r
     ChildSaSession = Ikev2ChildSaSessionCreate (IkeSaSession, UdpService);\r
     ChildSaCommon  = &ChildSaSession->SessionCommon;\r
 \r
     //\r
     // Initialize the SA data for Child SA.\r
-    //    \r
+    //\r
     ChildSaSession->SaData = Ikev2InitializeSaData (ChildSaCommon);\r
   }\r
 \r
@@ -570,7 +569,7 @@ Ikev2HandleSa (
 \r
     //\r
     // Remove the Established Child SA Session from the IkeSaSession->ChildSaSessionList\r
-    // ,insert it into IkeSaSession->ChildSaEstablishSessionList and save this Child SA \r
+    // ,insert it into IkeSaSession->ChildSaEstablishSessionList and save this Child SA\r
     // into SAD.\r
     //\r
     ChildSaSession = IKEV2_CHILD_SA_SESSION_BY_IKE_SA (IkeSaSession->ChildSaSessionList.BackLink);\r
@@ -610,12 +609,12 @@ ON_ERROR:
 \r
 /**\r
 \r
-  The general interface when received a IKEv2 packet for the IKE Child SA establishing \r
+  The general interface when received a IKEv2 packet for the IKE Child SA establishing\r
   or IKE SA/CHILD SA rekeying.\r
 \r
-  This function first find the related IKE SA Session according to the IKE packet's \r
+  This function first find the related IKE SA Session according to the IKE packet's\r
   remote IP. Then call the corresponding function to handle this IKE packet according\r
-  to the related IKE Child Session's State. \r
+  to the related IKE Child Session's State.\r
 \r
   @param[in] UdpService    Pointer of related UDP Service.\r
   @param[in] IkePacket     Data passed by caller.\r
@@ -632,8 +631,8 @@ Ikev2HandleChildSa (
   IKEV2_CREATE_CHILD_REQUEST_TYPE  RequestType;\r
   IKE_PACKET                       *Reply;\r
   IPSEC_PRIVATE_DATA               *Private;\r
-  \r
-  Private = (UdpService->IpVersion == IP_VERSION_4) ? \r
+\r
+  Private = (UdpService->IpVersion == IP_VERSION_4) ?\r
              IPSEC_PRIVATE_DATA_FROM_UDP4LIST(UdpService->ListHead) :\r
              IPSEC_PRIVATE_DATA_FROM_UDP6LIST(UdpService->ListHead);\r
 \r
@@ -671,20 +670,20 @@ Ikev2HandleChildSa (
 \r
   //\r
   // Get the request type: CreateChildSa/RekeyChildSa/RekeyIkeSa.\r
-  //  \r
+  //\r
   RequestType = Ikev2ChildExchangeRequestType (IkePacket);\r
 \r
   switch (RequestType) {\r
   case IkeRequestTypeCreateChildSa:\r
-  case IkeRequestTypeRekeyChildSa: \r
-  case IkeRequestTypeRekeyIkeSa: \r
+  case IkeRequestTypeRekeyChildSa:\r
+  case IkeRequestTypeRekeyIkeSa:\r
     //\r
     // Parse the IKE request packet. Not support CREATE_CHILD_SA exchange yet, so\r
-    // only EFI_UNSUPPORTED will be returned and that will trigger a reply with a \r
+    // only EFI_UNSUPPORTED will be returned and that will trigger a reply with a\r
     // Notify payload of type NO_ADDITIONAL_SAS.\r
     //\r
     Status = mIkev2CreateChild.Parser ((UINT8 *) IkeSaSession, IkePacket);\r
-    if (EFI_ERROR (Status)) {     \r
+    if (EFI_ERROR (Status)) {\r
       goto ON_REPLY;\r
     }\r
 \r
@@ -694,7 +693,7 @@ Ikev2HandleChildSa (
     //\r
     return ;\r
   }\r
-  \r
+\r
 ON_REPLY:\r
   //\r
   // Generate the reply packet if needed and send it out.\r
@@ -712,15 +711,15 @@ ON_REPLY:
         }\r
       }\r
     }\r
-  }  \r
+  }\r
   return ;\r
 }\r
 \r
 /**\r
 \r
   It is general interface to handle IKEv2 information Exchange.\r
-  \r
-  @param[in] UdpService  Point to IKE UPD Service related to this information exchange.  \r
+\r
+  @param[in] UdpService  Point to IKE UPD Service related to this information exchange.\r
   @param[in] IkePacket   The IKE packet to be parsed.\r
 \r
 **/\r
@@ -735,15 +734,15 @@ Ikev2HandleInfo (
   IKEV2_SA_SESSION        *IkeSaSession;\r
   IPSEC_PRIVATE_DATA      *Private;\r
 \r
-  Private = (UdpService->IpVersion == IP_VERSION_4) ? \r
-             IPSEC_PRIVATE_DATA_FROM_UDP4LIST(UdpService->ListHead) : \r
+  Private = (UdpService->IpVersion == IP_VERSION_4) ?\r
+             IPSEC_PRIVATE_DATA_FROM_UDP4LIST(UdpService->ListHead) :\r
              IPSEC_PRIVATE_DATA_FROM_UDP6LIST(UdpService->ListHead);\r
 \r
   //\r
   // Lookup the remote ip address in the processing IKE SA session list.\r
   //\r
   IkeSaSession = Ikev2SaSessionLookup (&Private->Ikev2EstablishedList, &IkePacket->RemotePeerIp);\r
-  \r
+\r
   if (IkeSaSession == NULL) {\r
     //\r
     // Drop the packet if no IKE SA associated.\r
@@ -754,12 +753,12 @@ Ikev2HandleInfo (
   // Validate the IKE packet header.\r
   //\r
   if (!Ikev2ValidateHeader (IkeSaSession, IkePacket->Header)) {\r
-  \r
+\r
     //\r
     // Drop the packet if invalid IKE header.\r
     //\r
     return;\r
-  }  \r
+  }\r
 \r
   SessionCommon = &IkeSaSession->SessionCommon;\r
 \r
@@ -778,7 +777,7 @@ Ikev2HandleInfo (
     // Drop the packet if fail to parse.\r
     //\r
     return;\r
-  }    \r
+  }\r
 }\r
 \r
 IKE_EXCHANGE_INTERFACE  mIkev1Exchange = {
index 333074d2606d0c9fae4c72a000c2d6a5c615939b..c1e134804c34f4ca2e4dd2def3ef7d9e606aed1c 100644 (file)
 #include "IpSecCryptIo.h"\r
 \r
 //\r
-// The Constant String of "Key Pad for IKEv2" for Authentication Payload generation. \r
+// The Constant String of "Key Pad for IKEv2" for Authentication Payload generation.\r
 //\r
 #define CONSTANT_KEY_SIZE     17\r
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mConstantKey[CONSTANT_KEY_SIZE] = \r
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mConstantKey[CONSTANT_KEY_SIZE] =\r
 {\r
   'K', 'e', 'y', ' ', 'P', 'a', 'd', ' ', 'f', 'o', 'r', ' ', 'I', 'K', 'E', 'v', '2'\r
 };\r
@@ -31,13 +31,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mConstantKey[CONSTANT_KEY_SIZE] =
   Generate Ikev2 SA payload according to SessionSaData\r
 \r
   @param[in] SessionSaData   The data used in SA payload.\r
-  @param[in] NextPayload     The payload type presented in NextPayload field of \r
+  @param[in] NextPayload     The payload type presented in NextPayload field of\r
                              SA Payload header.\r
   @param[in] Type            The SA type. It MUST be neither (1) for IKE_SA or\r
                              (2) for CHILD_SA or (3) for INFO.\r
 \r
   @retval a Pointer to SA IKE payload.\r
-  \r
+\r
 **/\r
 IKE_PAYLOAD *\r
 Ikev2GenerateSaPayload (\r
@@ -56,16 +56,16 @@ Ikev2GenerateSaPayload (
   // TODO: Get the Proposal Number and Transform Number from IPsec Config,\r
   // after the Ipsecconfig Application is support it.\r
   //\r
-  \r
+\r
   if (Type == IkeSessionTypeIkeSa) {\r
-    SaDataSize = sizeof (IKEV2_SA_DATA) + \r
+    SaDataSize = sizeof (IKEV2_SA_DATA) +\r
                  SessionSaData->NumProposals * sizeof (IKEV2_PROPOSAL_DATA) +\r
                  sizeof (IKEV2_TRANSFORM_DATA) * SessionSaData->NumProposals * 4;\r
   } else {\r
-    SaDataSize = sizeof (IKEV2_SA_DATA) + \r
+    SaDataSize = sizeof (IKEV2_SA_DATA) +\r
                  SessionSaData->NumProposals * sizeof (IKEV2_PROPOSAL_DATA) +\r
                  sizeof (IKEV2_TRANSFORM_DATA) * SessionSaData->NumProposals * 3;\r
-             \r
+\r
   }\r
 \r
   SaData = AllocateZeroPool (SaDataSize);\r
@@ -82,10 +82,10 @@ Ikev2GenerateSaPayload (
 /**\r
   Generate a Nonce payload containing the input parameter NonceBuf.\r
 \r
-  @param[in]  NonceBuf      The nonce buffer contains the whole Nonce payload block \r
+  @param[in]  NonceBuf      The nonce buffer contains the whole Nonce payload block\r
                             except the payload header.\r
   @param[in]  NonceSize     The buffer size of the NonceBuf\r
-  @param[in]  NextPayload   The payload type presented in the NextPayload field \r
+  @param[in]  NextPayload   The payload type presented in the NextPayload field\r
                             of Nonce Payload header.\r
 \r
   @retval Pointer to Nonce IKE paload.\r
@@ -133,11 +133,11 @@ Ikev2GenerateNoncePayload (
 }\r
 \r
 /**\r
-  Generate a Key Exchange payload according to the DH group type and save the \r
+  Generate a Key Exchange payload according to the DH group type and save the\r
   public Key into IkeSaSession IkeKey field.\r
 \r
   @param[in, out] IkeSaSession    Pointer of the IKE_SA_SESSION.\r
-  @param[in]      NextPayload     The payload type presented in the NextPayload field of Key \r
+  @param[in]      NextPayload     The payload type presented in the NextPayload field of Key\r
                                   Exchange Payload header.\r
 \r
   @retval Pointer to Key IKE payload.\r
@@ -174,7 +174,7 @@ Ikev2GenerateKePayload (
   } else {\r
     KeSize = sizeof (IKEV2_KEY_EXCHANGE) + IkeKeys->DhBuffer->GxSize;\r
   }\r
-  \r
+\r
   //\r
   // Allocate buffer for Key Exchange\r
   //\r
@@ -186,13 +186,13 @@ Ikev2GenerateKePayload (
   Ke->DhGroup               = IkeSaSession->SessionCommon.PreferDhGroup;\r
 \r
   CopyMem (Ke + 1, IkeKeys->DhBuffer->GxBuffer, IkeKeys->DhBuffer->GxSize);\r
-  \r
+\r
+  //\r
+  // Create IKE_PAYLOAD to point to Key Exchange payload\r
   //\r
-  // Create IKE_PAYLOAD to point to Key Exchange payload  \r
-  //  \r
   KePayload = IkePayloadAlloc ();\r
   ASSERT (KePayload != NULL);\r
-  \r
+\r
   KePayload->PayloadType = IKEV2_PAYLOAD_TYPE_KE;\r
   KePayload->PayloadBuf  = (UINT8 *) Ke;\r
   KePayload->PayloadSize = KeSize;\r
@@ -203,7 +203,7 @@ Ikev2GenerateKePayload (
   Generate a ID payload.\r
 \r
   @param[in] CommonSession   Pointer to IKEV2_SESSION_COMMON related to ID payload.\r
-  @param[in] NextPayload     The payload type presented in the NextPayload field \r
+  @param[in] NextPayload     The payload type presented in the NextPayload field\r
                              of ID Payload header.\r
 \r
   @retval Pointer to ID IKE payload.\r
@@ -234,7 +234,7 @@ Ikev2GenerateIdPayload (
   //   !                                                               !\r
   //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
   //\r
-  \r
+\r
   IpVersion = CommonSession->UdpService->IpVersion;\r
   AddrSize  = (UINT8) ((IpVersion == IP_VERSION_4) ? sizeof(EFI_IPv4_ADDRESS) : sizeof(EFI_IPv6_ADDRESS));\r
   IdSize    = sizeof (IKEV2_ID) + AddrSize;\r
@@ -250,7 +250,7 @@ Ikev2GenerateIdPayload (
   IdPayload->PayloadSize  = IdSize;\r
 \r
   //\r
-  // Set generic header of identification payload \r
+  // Set generic header of identification payload\r
   //\r
   Id->Header.NextPayload    = NextPayload;\r
   Id->Header.PayloadLength  = (UINT16) IdSize;\r
@@ -264,7 +264,7 @@ Ikev2GenerateIdPayload (
   Generate a ID payload.\r
 \r
   @param[in] CommonSession   Pointer to IKEV2_SESSION_COMMON related to ID payload.\r
-  @param[in] NextPayload     The payload type presented in the NextPayload field \r
+  @param[in] NextPayload     The payload type presented in the NextPayload field\r
                              of ID Payload header.\r
   @param[in] InCert          Pointer to the Certificate which distinguished name\r
                              will be added into the Id payload.\r
@@ -287,7 +287,7 @@ Ikev2GenerateCertIdPayload (
   UINT8          IpVersion;\r
   UINTN          SubjectSize;\r
   UINT8          *CertSubject;\r
-  \r
+\r
   //\r
   // ID payload\r
   //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\r
@@ -328,7 +328,7 @@ Ikev2GenerateCertIdPayload (
   IdPayload->PayloadSize  = IdSize;\r
 \r
   //\r
-  // Set generic header of identification payload \r
+  // Set generic header of identification payload\r
   //\r
   Id->Header.NextPayload    = NextPayload;\r
   Id->Header.PayloadLength  = (UINT16) IdSize;\r
@@ -344,15 +344,15 @@ Ikev2GenerateCertIdPayload (
 /**\r
   Generate a Authentication Payload.\r
 \r
-  This function is used for both Authentication generation and verification. When the \r
-  IsVerify is TRUE, it create a Auth Data for verification. This function choose the \r
+  This function is used for both Authentication generation and verification. When the\r
+  IsVerify is TRUE, it create a Auth Data for verification. This function choose the\r
   related IKE_SA_INIT Message for Auth data creation according to the IKE Session's type\r
   and the value of IsVerify parameter.\r
 \r
   @param[in]  IkeSaSession  Pointer to IKEV2_SA_SESSION related to.\r
-  @param[in]  IdPayload     Pointer to the ID payload to be used for Authentication \r
+  @param[in]  IdPayload     Pointer to the ID payload to be used for Authentication\r
                             payload generation.\r
-  @param[in]  NextPayload   The type filled into the Authentication Payload next \r
+  @param[in]  NextPayload   The type filled into the Authentication Payload next\r
                             payload field.\r
   @param[in]  IsVerify      If it is TURE, the Authentication payload is used for\r
                             verification.\r
@@ -392,11 +392,11 @@ Ikev2PskGenerateAuthPayload (
   //    !                                                               !\r
   //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
   //\r
\r
+\r
   KeyBuf      = NULL;\r
   AuthPayload = NULL;\r
   Digest      = NULL;\r
-  \r
+\r
   DigestSize = IpSecGetHmacDigestLength ((UINT8)IkeSaSession->SessionCommon.SaParams->Prf);\r
   Digest     = AllocateZeroPool (DigestSize);\r
 \r
@@ -415,7 +415,7 @@ Ikev2PskGenerateAuthPayload (
   Status = IpSecCryptoIoHmac (\r
              (UINT8)IkeSaSession->SessionCommon.SaParams->Prf,\r
              IkeSaSession->Pad->Data->AuthData,\r
-             IkeSaSession->Pad->Data->AuthDataSize,             \r
+             IkeSaSession->Pad->Data->AuthDataSize,\r
              (HASH_DATA_FRAGMENT *)Fragments,\r
              1,\r
              Digest,\r
@@ -485,7 +485,7 @@ Ikev2PskGenerateAuthPayload (
 \r
   //\r
   // Copy the result of Prf(SK_Pr, IDi/r) to Fragments[2].\r
-  // \r
+  //\r
   Fragments[2].Data     = AllocateZeroPool (DigestSize);\r
   Fragments[2].DataSize = DigestSize;\r
   CopyMem (Fragments[2].Data, Digest, DigestSize);\r
@@ -542,7 +542,7 @@ Ikev2PskGenerateAuthPayload (
     Digest,\r
     DigestSize\r
     );\r
-  \r
+\r
   //\r
   // Fill in IKE_PACKET\r
   //\r
@@ -559,7 +559,7 @@ EXIT:
   if (Fragments[2].Data != NULL) {\r
     //\r
     // Free the buffer which contains the result of Prf(SK_Pr, IDi/r)\r
-    //     \r
+    //\r
     FreePool (Fragments[2].Data);\r
   }\r
 \r
@@ -574,26 +574,26 @@ EXIT:
 }\r
 \r
 /**\r
-  Generate a Authentication Payload for Certificate Auth method.  \r
+  Generate a Authentication Payload for Certificate Auth method.\r
 \r
-  This function has two functions. One is creating a local Authentication \r
-  Payload for sending and other is creating the remote Authentication data \r
+  This function has two functions. One is creating a local Authentication\r
+  Payload for sending and other is creating the remote Authentication data\r
   for verification when the IsVerify is TURE.\r
 \r
   @param[in]  IkeSaSession      Pointer to IKEV2_SA_SESSION related to.\r
-  @param[in]  IdPayload         Pointer to the ID payload to be used for Authentication \r
+  @param[in]  IdPayload         Pointer to the ID payload to be used for Authentication\r
                                 payload generation.\r
-  @param[in]  NextPayload       The type filled into the Authentication Payload \r
+  @param[in]  NextPayload       The type filled into the Authentication Payload\r
                                 next payload field.\r
-  @param[in]  IsVerify          If it is TURE, the Authentication payload is used \r
+  @param[in]  IsVerify          If it is TURE, the Authentication payload is used\r
                                 for verification.\r
-  @param[in]  UefiPrivateKey    Pointer to the UEFI private key. Ignore it when \r
+  @param[in]  UefiPrivateKey    Pointer to the UEFI private key. Ignore it when\r
                                 verify the authenticate payload.\r
-  @param[in]  UefiPrivateKeyLen The size of UefiPrivateKey in bytes. Ignore it \r
+  @param[in]  UefiPrivateKeyLen The size of UefiPrivateKey in bytes. Ignore it\r
                                 when verify the authenticate payload.\r
-  @param[in]  UefiKeyPwd        Pointer to the password of UEFI private key. \r
+  @param[in]  UefiKeyPwd        Pointer to the password of UEFI private key.\r
                                 Ignore it when verify the authenticate payload.\r
-  @param[in]  UefiKeyPwdLen     The size of UefiKeyPwd in bytes.Ignore it when \r
+  @param[in]  UefiKeyPwdLen     The size of UefiKeyPwd in bytes.Ignore it when\r
                                 verify the authenticate payload.\r
 \r
   @return pointer to IKE Authentication payload for Cerifitcation method.\r
@@ -722,10 +722,10 @@ Ikev2CertGenerateAuthPayload (
     IpSecDumpBuf ("RealMessage1", Fragments[0].Data, Fragments[0].DataSize);\r
     IpSecDumpBuf ("NonceRDdata", Fragments[1].Data, Fragments[1].DataSize);\r
   }\r
-  \r
+\r
   //\r
   // Copy the result of Prf(SK_Pr, IDi/r) to Fragments[2].\r
-  // \r
+  //\r
   Fragments[2].Data     = AllocateZeroPool (DigestSize);\r
   Fragments[2].DataSize = DigestSize;\r
   CopyMem (Fragments[2].Data, Digest, DigestSize);\r
@@ -746,7 +746,7 @@ Ikev2CertGenerateAuthPayload (
 \r
   IpSecDumpBuf ("HashSignedOctects", Digest, DigestSize);\r
   //\r
-  // Sign the data by the private Key  \r
+  // Sign the data by the private Key\r
   //\r
   if (!IsVerify) {\r
     IpSecCryptoIoAuthDataWithCertificate (\r
@@ -820,7 +820,7 @@ EXIT:
   if (Fragments[2].Data != NULL) {\r
     //\r
     // Free the buffer which contains the result of Prf(SK_Pr, IDi/r)\r
-    //     \r
+    //\r
     FreePool (Fragments[2].Data);\r
   }\r
 \r
@@ -840,9 +840,9 @@ EXIT:
   This function generates TSi or TSr payload according to type of next payload.\r
   If the next payload is Responder TS, gereate TSi Payload. Otherwise, generate\r
   TSr payload.\r
-  \r
+\r
   @param[in] ChildSa        Pointer to IKEV2_CHILD_SA_SESSION related to this TS payload.\r
-  @param[in] NextPayload    The payload type presented in the NextPayload field \r
+  @param[in] NextPayload    The payload type presented in the NextPayload field\r
                             of ID Payload header.\r
   @param[in] IsTunnel       It indicates that if the Ts Payload is after the CP payload.\r
                             If yes, it means the Tsi and Tsr payload should be with\r
@@ -886,7 +886,7 @@ Ikev2GenerateTsPayload (
 \r
   IpVersion    = ChildSa->SessionCommon.UdpService->IpVersion;\r
   //\r
-  // The Starting Address and Ending Address is variable length depends on \r
+  // The Starting Address and Ending Address is variable length depends on\r
   // is IPv4 or IPv6\r
   //\r
   AddrSize      = (UINT8)((IpVersion == IP_VERSION_4) ? sizeof (EFI_IPv4_ADDRESS) : sizeof (EFI_IPv6_ADDRESS));\r
@@ -901,7 +901,7 @@ Ikev2GenerateTsPayload (
   TsSelector->TSType = (UINT8)((IpVersion == IP_VERSION_4) ? IKEV2_TS_TYPE_IPV4_ADDR_RANGE : IKEV2_TS_TYPS_IPV6_ADDR_RANGE);\r
 \r
   //\r
-  // For tunnel mode \r
+  // For tunnel mode\r
   //\r
   if (IsTunnel) {\r
     TsSelector->IpProtocolId = IKEV2_TS_ANY_PROTOCOL;\r
@@ -917,8 +917,8 @@ Ikev2GenerateTsPayload (
     //\r
     if (NextPayload == IKEV2_PAYLOAD_TYPE_TS_RSP){\r
       //\r
-      // Create initiator Traffic Selector \r
-      //      \r
+      // Create initiator Traffic Selector\r
+      //\r
       TsSelector->SelecorLen   = (UINT16)SelectorSize;\r
 \r
       //\r
@@ -929,7 +929,7 @@ Ikev2GenerateTsPayload (
       if (ChildSa->SessionCommon.IsInitiator) {\r
         if (ChildSa->Spd->Selector->LocalPort != 0 &&\r
             ChildSa->Spd->Selector->LocalPortRange == 0) {\r
-          //  \r
+          //\r
           // For not port range.\r
           //\r
           TsSelector->StartPort = ChildSa->Spd->Selector->LocalPort;\r
@@ -947,7 +947,7 @@ Ikev2GenerateTsPayload (
           goto ON_ERROR;\r
         }\r
       } else {\r
-        if (ChildSa->Spd->Selector->RemotePort != 0 && \r
+        if (ChildSa->Spd->Selector->RemotePort != 0 &&\r
             ChildSa->Spd->Selector->RemotePortRange == 0) {\r
           //\r
           // For not port range.\r
@@ -970,7 +970,7 @@ Ikev2GenerateTsPayload (
       //\r
       // Copy Address.Currently the address range is not supported.\r
       // The Starting address is same as Ending address\r
-      // TODO: Support Address Range. \r
+      // TODO: Support Address Range.\r
       //\r
       CopyMem (\r
         (UINT8*)TsSelector + sizeof(TRAFFIC_SELECTOR),\r
@@ -993,9 +993,9 @@ Ikev2GenerateTsPayload (
     }else{\r
         //\r
         // Create responder Traffic Selector\r
-        //      \r
+        //\r
         TsSelector->SelecorLen   = (UINT16)SelectorSize;\r
-        \r
+\r
         //\r
         // Currently only support the port range from 0~0xffff. Don't support other\r
         // port range.\r
@@ -1045,7 +1045,7 @@ Ikev2GenerateTsPayload (
         //\r
         // Copy Address.Currently the address range is not supported.\r
         // The Starting address is same as Ending address\r
-        // TODO: Support Address Range. \r
+        // TODO: Support Address Range.\r
         //\r
         CopyMem (\r
           (UINT8*)TsSelector + sizeof(TRAFFIC_SELECTOR),\r
@@ -1072,8 +1072,8 @@ Ikev2GenerateTsPayload (
       TsSelector->IpProtocolId = (UINT8)ChildSa->Spd->Selector->NextLayerProtocol;\r
     } else {\r
       TsSelector->IpProtocolId = IKEV2_TS_ANY_PROTOCOL;\r
-    } \r
-    \r
+    }\r
+\r
   TsPayloadBuf->Header.NextPayload    = NextPayload;\r
   TsPayloadBuf->Header.PayloadLength  = (UINT16)TsPayloadSize;\r
   TsPayloadBuf->TSNumbers             = 1;\r
@@ -1082,10 +1082,10 @@ Ikev2GenerateTsPayload (
 \r
 ON_ERROR:\r
   if (TsPayload != NULL) {\r
-    IkePayloadFree (TsPayload);  \r
+    IkePayloadFree (TsPayload);\r
     TsPayload = NULL;\r
   }\r
-ON_EXIT: \r
+ON_EXIT:\r
   return TsPayload;\r
 }\r
 \r
@@ -1093,23 +1093,23 @@ ON_EXIT:
   Generate the Notify payload.\r
 \r
   Since the structure of Notify payload which defined in RFC 4306 is simple, so\r
-  there is no internal data structure for Notify payload. This function generate \r
-  Notify payload defined in RFC 4306, but all the fields in this payload are still \r
-  in host order and need call Ikev2EncodePayload() to convert those fields from \r
+  there is no internal data structure for Notify payload. This function generate\r
+  Notify payload defined in RFC 4306, but all the fields in this payload are still\r
+  in host order and need call Ikev2EncodePayload() to convert those fields from\r
   the host order to network order beforing sending it.\r
 \r
   @param[in]  ProtocolId        The protocol type ID. For IKE_SA it MUST be one (1).\r
                                 For IPsec SAs it MUST be neither (2) for AH or (3)\r
                                 for ESP.\r
-  @param[in]  NextPayload       The next paylaod type in NextPayload field of \r
+  @param[in]  NextPayload       The next paylaod type in NextPayload field of\r
                                 the Notify payload.\r
-  @param[in]  SpiSize           Size of the SPI in SPI size field of the Notify Payload.  \r
-  @param[in]  MessageType       The message type in NotifyMessageType field of the \r
+  @param[in]  SpiSize           Size of the SPI in SPI size field of the Notify Payload.\r
+  @param[in]  MessageType       The message type in NotifyMessageType field of the\r
                                 Notify Payload.\r
   @param[in]  SpiBuf            Pointer to buffer contains the SPI value.\r
   @param[in]  NotifyData        Pointer to buffer contains the notification data.\r
   @param[in]  NotifyDataSize    The size of NotifyData in bytes.\r
-  \r
+\r
 \r
   @retval Pointer to IKE Notify Payload.\r
 \r
@@ -1190,14 +1190,14 @@ Ikev2GenerateNotifyPayload (
 /**\r
   Generate the Delete payload.\r
 \r
-  Since the structure of Delete payload which defined in RFC 4306 is simple, \r
-  there is no internal data structure for Delete payload. This function generate \r
-  Delete payload defined in RFC 4306, but all the fields in this payload are still \r
-  in host order and need call Ikev2EncodePayload() to convert those fields from \r
+  Since the structure of Delete payload which defined in RFC 4306 is simple,\r
+  there is no internal data structure for Delete payload. This function generate\r
+  Delete payload defined in RFC 4306, but all the fields in this payload are still\r
+  in host order and need call Ikev2EncodePayload() to convert those fields from\r
   the host order to network order beforing sending it.\r
 \r
   @param[in]  IkeSaSession      Pointer to IKE SA Session to be used of Delete payload generation.\r
-  @param[in]  NextPayload       The next paylaod type in NextPayload field of \r
+  @param[in]  NextPayload       The next paylaod type in NextPayload field of\r
                                 the Delete payload.\r
   @param[in]  SpiSize           Size of the SPI in SPI size field of the Delete Payload.\r
   @param[in]  SpiNum            Number of SPI in NumofSPIs field of the Delete Payload.\r
@@ -1213,7 +1213,7 @@ Ikev2GenerateDeletePayload (
   IN UINT8             SpiSize,\r
   IN UINT16            SpiNum,\r
   IN UINT8             *SpiBuf\r
-  \r
+\r
   )\r
 {\r
   IKE_PAYLOAD  *DelPayload;\r
@@ -1237,12 +1237,12 @@ Ikev2GenerateDeletePayload (
   if (SpiBufSize != 0 && SpiBuf == NULL) {\r
     return NULL;\r
   }\r
-  \r
+\r
   DelPayloadLen = (UINT16) (sizeof (IKEV2_DELETE) + SpiBufSize);\r
 \r
   Del           = AllocateZeroPool (DelPayloadLen);\r
   ASSERT (Del != NULL);\r
-  \r
+\r
   //\r
   // Set Delete Payload's Generic Header\r
   //\r
@@ -1275,13 +1275,13 @@ Ikev2GenerateDeletePayload (
 /**\r
   Generate the Configuration payload.\r
 \r
-  This function generate configuration payload defined in RFC 4306, but all the \r
-  fields in this payload are still in host order and need call Ikev2EncodePayload() \r
+  This function generate configuration payload defined in RFC 4306, but all the\r
+  fields in this payload are still in host order and need call Ikev2EncodePayload()\r
   to convert those fields from the host order to network order beforing sending it.\r
 \r
-  @param[in]  IkeSaSession      Pointer to IKE SA Session to be used for Delete payload \r
+  @param[in]  IkeSaSession      Pointer to IKE SA Session to be used for Delete payload\r
                                 generation.\r
-  @param[in]  NextPayload       The next paylaod type in NextPayload field of \r
+  @param[in]  NextPayload       The next paylaod type in NextPayload field of\r
                                 the Delete payload.\r
   @param[in]  CfgType           The attribute type in the Configuration attribute.\r
 \r
@@ -1323,8 +1323,8 @@ Ikev2GenerateCpPayload (
   CfgAttributes = (IKEV2_CFG_ATTRIBUTES *)((UINT8 *)Cfg + sizeof (IKEV2_CFG));\r
 \r
   //\r
-  // Only generate the configuration payload with an empty INTERNAL_IP4_ADDRESS \r
-  // or INTERNAL_IP6_ADDRESS. \r
+  // Only generate the configuration payload with an empty INTERNAL_IP4_ADDRESS\r
+  // or INTERNAL_IP6_ADDRESS.\r
   //\r
 \r
   Cfg->Header.NextPayload   = NextPayload;\r
@@ -1355,7 +1355,7 @@ Ikev2GenerateCpPayload (
   IPSEC_PROTO_ISAKMP or if the SpiSize is not zero or if the MessageType is not\r
   the COOKIE, return EFI_INVALID_PARAMETER.\r
 \r
-  @param[in]      IkeNCookie    Pointer to the IKE_PAYLOAD which contians the \r
+  @param[in]      IkeNCookie    Pointer to the IKE_PAYLOAD which contians the\r
                                 Notify Cookie payload.\r
                                 the Notify payload.\r
   @param[in, out] IkeSaSession  Pointer to the relevant IKE SA Session.\r
@@ -1369,14 +1369,14 @@ EFI_STATUS
 Ikev2ParserNotifyCookiePayload (\r
   IN     IKE_PAYLOAD      *IkeNCookie,\r
   IN OUT IKEV2_SA_SESSION *IkeSaSession\r
-  ) \r
+  )\r
 {\r
   IKEV2_NOTIFY      *NotifyPayload;\r
   UINTN             NotifyDataSize;\r
 \r
   NotifyPayload = (IKEV2_NOTIFY *)IkeNCookie->PayloadBuf;\r
 \r
-  if ((NotifyPayload->ProtocolId != IPSEC_PROTO_ISAKMP) || \r
+  if ((NotifyPayload->ProtocolId != IPSEC_PROTO_ISAKMP) ||\r
       (NotifyPayload->SpiSize != 0) ||\r
       (NotifyPayload->MessageType != IKEV2_NOTIFICATION_COOKIE)\r
       ) {\r
@@ -1392,8 +1392,8 @@ Ikev2ParserNotifyCookiePayload (
   IkeSaSession->NCookieSize = NotifyDataSize;\r
 \r
   CopyMem (\r
-    IkeSaSession->NCookie, \r
-    NotifyPayload + sizeof (IKEV2_NOTIFY), \r
+    IkeSaSession->NCookie,\r
+    NotifyPayload + sizeof (IKEV2_NOTIFY),\r
     NotifyDataSize\r
     );\r
 \r
@@ -1404,16 +1404,16 @@ Ikev2ParserNotifyCookiePayload (
 /**\r
   Generate the Certificate payload or Certificate Request Payload.\r
 \r
-  Since the Certificate Payload structure is same with Certificate Request Payload, \r
+  Since the Certificate Payload structure is same with Certificate Request Payload,\r
   the only difference is that one contains the Certificate Data, other contains\r
-  the acceptable certificateion CA. This function generate Certificate payload \r
-  or Certificate Request Payload defined in RFC 4306, but all the fields \r
-  in the payload are still in host order and need call Ikev2EncodePayload() \r
+  the acceptable certificateion CA. This function generate Certificate payload\r
+  or Certificate Request Payload defined in RFC 4306, but all the fields\r
+  in the payload are still in host order and need call Ikev2EncodePayload()\r
   to convert those fields from the host order to network order beforing sending it.\r
 \r
-  @param[in]  IkeSaSession      Pointer to IKE SA Session to be used of Delete payload \r
+  @param[in]  IkeSaSession      Pointer to IKE SA Session to be used of Delete payload\r
                                 generation.\r
-  @param[in]  NextPayload       The next paylaod type in NextPayload field of \r
+  @param[in]  NextPayload       The next paylaod type in NextPayload field of\r
                                 the Delete payload.\r
   @param[in]  Certificate       Pointer of buffer contains the certification data.\r
   @param[in]  CertificateLen    The length of Certificate in byte.\r
@@ -1462,7 +1462,7 @@ Ikev2GenerateCertificatePayload (
 \r
   Status       = EFI_SUCCESS;\r
   PublicKey    = NULL;\r
-  PublicKeyLen = 0; \r
+  PublicKeyLen = 0;\r
 \r
   if (!IsRequest) {\r
     PayloadLen = (UINT16) (sizeof (IKEV2_CERT) + CertificateLen);\r
@@ -1477,7 +1477,7 @@ Ikev2GenerateCertificatePayload (
   if (Cert == NULL) {\r
     return NULL;\r
   }\r
-   \r
+\r
   //\r
   // Generate Certificate Payload or Certificate Request Payload.\r
   //\r
@@ -1498,7 +1498,7 @@ Ikev2GenerateCertificatePayload (
                &PublicKeyLen\r
                );\r
     if (EFI_ERROR (Status)) {\r
-      goto ON_EXIT; \r
+      goto ON_EXIT;\r
     }\r
 \r
     Fragment[0].Data     = PublicKey;\r
@@ -1508,7 +1508,7 @@ Ikev2GenerateCertificatePayload (
     if (HashData == NULL) {\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     Status = IpSecCryptoIoHash (\r
                IKE_AALG_SHA1HMAC,\r
                Fragment,\r
@@ -1519,7 +1519,7 @@ Ikev2GenerateCertificatePayload (
     if (EFI_ERROR (Status)) {\r
       goto ON_EXIT;\r
     }\r
-    \r
+\r
     CopyMem (\r
       ((UINT8 *)Cert) + sizeof (IKEV2_CERT),\r
       HashData,\r
@@ -1531,7 +1531,7 @@ Ikev2GenerateCertificatePayload (
   if (CertPayload == NULL) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   if (!IsRequest) {\r
     CertPayload->PayloadType = IKEV2_PAYLOAD_TYPE_CERT;\r
   } else {\r
@@ -1583,7 +1583,7 @@ ClearAllPayloads (
   @param[in] SaData        Pointer to IKEV2_SA_DATA to be transfered.\r
 \r
   @retval  return the pointer of IKEV2_SA.\r
-  \r
+\r
 **/\r
 IKEV2_SA*\r
 Ikev2EncodeSa (\r
@@ -1605,10 +1605,8 @@ Ikev2EncodeSa (
   UINTN                 TransformIndex;\r
   IKE_SA_ATTRIBUTE      *SaAttribute;\r
   IKEV2_PROPOSAL        *Proposal;\r
-  IKEV2_PROPOSAL        *LastProposal;\r
   IKEV2_TRANSFORM       *Transform;\r
-  IKEV2_TRANSFORM       *LastTransform;\r
-  \r
+\r
   //\r
   // Transform IKE_SA_DATA structure to IKE_SA Payload.\r
   // Header length is host order.\r
@@ -1635,7 +1633,6 @@ Ikev2EncodeSa (
   CopyMem (Sa, SaData, sizeof (IKEV2_SA));\r
   Sa->Header.PayloadLength  = (UINT16) sizeof (IKEV2_SA);\r
   ProposalsSize             = 0;\r
-  LastProposal              = NULL;\r
   Proposal                  = (IKEV2_PROPOSAL *) (Sa + 1);\r
 \r
   //\r
@@ -1655,7 +1652,6 @@ Ikev2EncodeSa (
     }\r
 \r
     TransformsSize  = 0;\r
-    LastTransform   = NULL;\r
     Transform       = (IKEV2_TRANSFORM *) ((UINT8 *) (Proposal + 1) + Proposal->SpiSize);\r
 \r
     //\r
@@ -1690,17 +1686,17 @@ Ikev2EncodeSa (
 \r
       TransformSize                 = sizeof (IKEV2_TRANSFORM) + SaAttrsSize;\r
       TransformsSize               += TransformSize;\r
-      \r
+\r
       Transform->Header.NextPayload   = IKE_TRANSFORM_NEXT_PAYLOAD_MORE;\r
       Transform->Header.PayloadLength = HTONS ((UINT16)TransformSize);\r
-      \r
-      if (TransformIndex == ProposalData->NumTransforms) {\r
-        LastTransform->Header.NextPayload = IKE_TRANSFORM_NEXT_PAYLOAD_NONE;\r
+\r
+      if (TransformIndex == (UINTN)(ProposalData->NumTransforms - 1)) {\r
+        Transform->Header.NextPayload = IKE_TRANSFORM_NEXT_PAYLOAD_NONE;\r
       }\r
 \r
       Transform     = (IKEV2_TRANSFORM *)((UINT8 *) Transform + TransformSize);\r
     }\r
-    \r
+\r
     //\r
     // Set Proposal's Generic Header.\r
     //\r
@@ -1708,9 +1704,9 @@ Ikev2EncodeSa (
     ProposalsSize                 += ProposalSize;\r
     Proposal->Header.NextPayload   = IKE_PROPOSAL_NEXT_PAYLOAD_MORE;\r
     Proposal->Header.PayloadLength = HTONS ((UINT16)ProposalSize);\r
-    \r
-    if (ProposalIndex == SaData->NumProposals) {\r
-      LastProposal->Header.NextPayload = IKE_PROPOSAL_NEXT_PAYLOAD_NONE;\r
+\r
+    if (ProposalIndex == (UINTN)(SaData->NumProposals - 1)) {\r
+      Proposal->Header.NextPayload = IKE_PROPOSAL_NEXT_PAYLOAD_NONE;\r
     }\r
 \r
     //\r
@@ -1731,7 +1727,7 @@ Ikev2EncodeSa (
 \r
   This function converts the received SA payload to internal data structure.\r
 \r
-  @param[in]  SessionCommon       Pointer to IKE Common Session used to decode the SA \r
+  @param[in]  SessionCommon       Pointer to IKE Common Session used to decode the SA\r
                                   Payload.\r
   @param[in]  Sa                  Pointer to SA Payload\r
 \r
@@ -1804,11 +1800,14 @@ Ikev2DecodeSa (
   }\r
 \r
   //\r
-  // Check the proposal number. The Proposal Payload type is 2. Nonce Paylod is 0.\r
-  // SUM(ProposalNextPayload) = Proposal Num * 2 + Noce Payload Type (0).\r
+  // Check the proposal number.\r
+  // The proposal Substructure, the NextPayLoad field indicates : 0 (last) or 2 (more)\r
+  // which Specifies whether this is the last Proposal Substructure in the SA.\r
+  // Here suming all Proposal NextPayLoad field to check the proposal number is correct\r
+  // or not.\r
   //\r
   if (TotalProposals == 0 ||\r
-      (TotalProposals - 1) * IKE_PROPOSAL_NEXT_PAYLOAD_MORE + IKE_PROPOSAL_NEXT_PAYLOAD_NONE != ProposalNextPayloadSum\r
+      (TotalProposals - 1) * IKE_PROPOSAL_NEXT_PAYLOAD_MORE != ProposalNextPayloadSum\r
       ) {\r
     Status = EFI_INVALID_PARAMETER;\r
     goto Exit;\r
@@ -1843,7 +1842,7 @@ Ikev2DecodeSa (
        ProposalIndex < TotalProposals;\r
        ProposalIndex++\r
        ) {\r
-       \r
+\r
     //\r
     // TODO: check ProposalId\r
     //\r
@@ -1902,7 +1901,7 @@ Ikev2DecodeSa (
       SaAttrRemaining = TransformSize - sizeof (IKEV2_TRANSFORM);\r
 \r
       //\r
-      // According to RFC 4603, currently only the Key length attribute type is \r
+      // According to RFC 4603, currently only the Key length attribute type is\r
       // supported. For each Transform, there is only one attributeion.\r
       //\r
       if (SaAttrRemaining > 0) {\r
@@ -1920,12 +1919,12 @@ Ikev2DecodeSa (
         if (TransformData->Attribute.AttrType != IKEV2_ATTRIBUTE_TYPE_KEYLEN) {\r
           Status = EFI_INVALID_PARAMETER;\r
           goto Exit;\r
-        }        \r
+        }\r
       }\r
 \r
       //\r
       // Move to next Transform\r
-      //      \r
+      //\r
       Transform = IKEV2_NEXT_TRANSFORM_WITH_SIZE (Transform, TransformSize);\r
     }\r
     Proposal     = IKEV2_NEXT_PROPOSAL_WITH_SIZE (Proposal, ProposalSize);\r
@@ -1945,7 +1944,7 @@ Exit:
 /**\r
   General interface of payload encoding.\r
 \r
-  This function encodes the internal data structure into payload which \r
+  This function encodes the internal data structure into payload which\r
   is defined in RFC 4306. The IkePayload->PayloadBuf is used to store both the input\r
   payload and converted payload. Only the SA payload use the interal structure\r
   to store the attribute. Other payload use structure which is same with the RFC\r
@@ -2006,17 +2005,17 @@ Ikev2EncodePayload (
     NotifyPayload               = (IKEV2_NOTIFY *) IkePayload->PayloadBuf;\r
     NotifyPayload->MessageType  = HTONS (NotifyPayload->MessageType);\r
     break;\r
-    \r
+\r
   case IKEV2_PAYLOAD_TYPE_DELETE:\r
     DeletePayload           = (IKEV2_DELETE *) IkePayload->PayloadBuf;\r
     DeletePayload->NumSpis  = HTONS (DeletePayload->NumSpis);\r
     break;\r
-    \r
+\r
   case IKEV2_PAYLOAD_TYPE_KE:\r
     KeyPayload              = (IKEV2_KEY_EXCHANGE *) IkePayload->PayloadBuf;\r
     KeyPayload->DhGroup     = HTONS (KeyPayload->DhGroup);\r
     break;\r
-    \r
+\r
   case IKEV2_PAYLOAD_TYPE_TS_INIT:\r
   case IKEV2_PAYLOAD_TYPE_TS_RSP:\r
     TsPayload = (IKEV2_TS *) IkePayload->PayloadBuf;\r
@@ -2031,7 +2030,7 @@ Ikev2EncodePayload (
       TrafficSelector->SelecorLen = HTONS (TrafficSelector->SelecorLen);\r
       TrafficSelector->StartPort  = HTONS (TrafficSelector->StartPort);\r
       TrafficSelector->EndPort    = HTONS (TrafficSelector->EndPort);\r
-      \r
+\r
     }\r
 \r
     break;\r
@@ -2040,14 +2039,14 @@ Ikev2EncodePayload (
     CfgAttribute = (IKEV2_CFG_ATTRIBUTES *)(((IKEV2_CFG *) IkePayload->PayloadBuf) + 1);\r
     CfgAttribute->AttritType  = HTONS (CfgAttribute->AttritType);\r
     CfgAttribute->ValueLength = HTONS (CfgAttribute->ValueLength);\r
-    \r
+\r
   case IKEV2_PAYLOAD_TYPE_ID_INIT:\r
   case IKEV2_PAYLOAD_TYPE_ID_RSP:\r
   case IKEV2_PAYLOAD_TYPE_AUTH:\r
   default:\r
     break;\r
   }\r
-  \r
+\r
   PayloadHdr  = (IKEV2_COMMON_PAYLOAD_HEADER *) IkePayload->PayloadBuf;\r
   IkePayload->PayloadSize = PayloadHdr->PayloadLength;\r
   PayloadHdr->PayloadLength = HTONS (PayloadHdr->PayloadLength);\r
@@ -2062,7 +2061,7 @@ Ikev2EncodePayload (
 \r
   @param[in]      SessionCommon     Pointer to IKE Session Common used for decoding.\r
   @param[in, out] IkePayload        Pointer to IKE payload to be decoded as input, and\r
-                                    store the decoded result as output. \r
+                                    store the decoded result as output.\r
 \r
   @retval EFI_INVALID_PARAMETER  Meet error when decoding the SA payload.\r
   @retval EFI_SUCCESS            Decoded successfully.\r
@@ -2092,8 +2091,8 @@ Ikev2DecodePayload (
   // Transform the IKE payload to Internal IKE structure.\r
   // Only the SA payload and Hash Payload use the interal\r
   // structure to store the attribute. Other payloads use\r
-  // structure which is same with the definitions in RFC, \r
-  // so there is no need to tranform them to internal IKE \r
+  // structure which is same with the definitions in RFC,\r
+  // so there is no need to tranform them to internal IKE\r
   // structure.\r
   //\r
   Status      = EFI_SUCCESS;\r
@@ -2123,9 +2122,9 @@ Ikev2DecodePayload (
     if (!IkePayload->IsPayloadBufExt) {\r
       FreePool (IkePayload->PayloadBuf);\r
     }\r
-    \r
+\r
     IkePayload->PayloadBuf      = (UINT8 *) SaData;\r
-    IkePayload->IsPayloadBufExt = FALSE;    \r
+    IkePayload->IsPayloadBufExt = FALSE;\r
     break;\r
 \r
   case IKEV2_PAYLOAD_TYPE_ID_INIT:\r
@@ -2145,7 +2144,7 @@ Ikev2DecodePayload (
     NotifyPayload               = (IKEV2_NOTIFY *) PayloadHdr;\r
     NotifyPayload->MessageType  = NTOHS (NotifyPayload->MessageType);\r
     break;\r
-    \r
+\r
   case IKEV2_PAYLOAD_TYPE_DELETE:\r
     if (PayloadSize < sizeof (IKEV2_DELETE)) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -2155,7 +2154,7 @@ Ikev2DecodePayload (
     DeletePayload           = (IKEV2_DELETE *) PayloadHdr;\r
     DeletePayload->NumSpis  = NTOHS (DeletePayload->NumSpis);\r
     break;\r
-    \r
+\r
   case IKEV2_PAYLOAD_TYPE_AUTH:\r
     if (PayloadSize < sizeof (IKEV2_AUTH)) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -2166,7 +2165,7 @@ Ikev2DecodePayload (
   case IKEV2_PAYLOAD_TYPE_KE:\r
     KeyPayload              = (IKEV2_KEY_EXCHANGE *) IkePayload->PayloadBuf;\r
     KeyPayload->DhGroup     = HTONS (KeyPayload->DhGroup);\r
-    break;  \r
+    break;\r
 \r
   case IKEV2_PAYLOAD_TYPE_TS_INIT:\r
   case IKEV2_PAYLOAD_TYPE_TS_RSP :\r
@@ -2212,12 +2211,12 @@ Ikev2DecodePayload (
 /**\r
   Decode the IKE packet.\r
 \r
-  This function first decrypts the IKE packet if needed , then separates the whole \r
+  This function first decrypts the IKE packet if needed , then separates the whole\r
   IKE packet from the IkePacket->PayloadBuf into IkePacket payload list.\r
-  \r
-  @param[in]      SessionCommon          Pointer to IKEV1_SESSION_COMMON containing \r
+\r
+  @param[in]      SessionCommon          Pointer to IKEV1_SESSION_COMMON containing\r
                                          some parameter used by IKE packet decoding.\r
-  @param[in, out] IkePacket              The IKE Packet to be decoded on input, and \r
+  @param[in, out] IkePacket              The IKE Packet to be decoded on input, and\r
                                          the decoded result on return.\r
   @param[in]      IkeType                The type of IKE. IKE_SA_TYPE, IKE_INFO_TYPE and\r
                                          IKE_CHILD_TYPE are supported.\r
@@ -2243,7 +2242,7 @@ Ikev2DecodePacket (
   IKEV2_SA_SESSION            *IkeSaSession;\r
 \r
   IkeHeader = NULL;\r
-  \r
+\r
   //\r
   // Check if the IkePacket need decrypt.\r
   //\r
@@ -2260,7 +2259,7 @@ Ikev2DecodePacket (
   // If the IkePacket doesn't contain any payload return invalid parameter.\r
   //\r
   if (IkePacket->Header->NextPayload == IKEV2_PAYLOAD_TYPE_NONE) {\r
-    if ((SessionCommon->State >= IkeStateAuth) && \r
+    if ((SessionCommon->State >= IkeStateAuth) &&\r
         (IkePacket->Header->ExchangeType == IKEV2_EXCHANGE_TYPE_INFO)\r
         ) {\r
       //\r
@@ -2301,7 +2300,7 @@ Ikev2DecodePacket (
       IkeSaSession->RespPacket     = AllocateZeroPool (IkePacket->Header->Length);\r
       if (IkeSaSession->RespPacket == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
-        goto Exit; \r
+        goto Exit;\r
       }\r
       IkeSaSession->RespPacketSize = IkePacket->Header->Length;\r
       CopyMem (IkeSaSession->RespPacket, IkeHeader, sizeof (IKE_HEADER));\r
@@ -2309,12 +2308,12 @@ Ikev2DecodePacket (
         IkeSaSession->RespPacket + sizeof (IKE_HEADER),\r
         IkePacket->PayloadsBuf,\r
         IkePacket->Header->Length - sizeof (IKE_HEADER)\r
-        );         \r
+        );\r
     } else {\r
       IkeSaSession->InitPacket     = AllocateZeroPool (IkePacket->Header->Length);\r
       if (IkeSaSession->InitPacket == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
-        goto Exit; \r
+        goto Exit;\r
       }\r
       IkeSaSession->InitPacketSize = IkePacket->Header->Length;\r
       CopyMem (IkeSaSession->InitPacket, IkeHeader, sizeof (IKE_HEADER));\r
@@ -2327,7 +2326,7 @@ Ikev2DecodePacket (
   }\r
 \r
   //\r
-  // Point to the first Payload \r
+  // Point to the first Payload\r
   //\r
   PayloadHdr  = (IKEV2_COMMON_PAYLOAD_HEADER *) IkePacket->PayloadsBuf;\r
   PayloadType = IkePacket->Header->NextPayload;\r
@@ -2412,9 +2411,9 @@ Exit:
 \r
   This function puts all Payloads into one payload then encrypt it if needed.\r
 \r
-  @param[in]      SessionCommon      Pointer to IKEV2_SESSION_COMMON containing \r
+  @param[in]      SessionCommon      Pointer to IKEV2_SESSION_COMMON containing\r
                                      some parameter used during IKE packet encoding.\r
-  @param[in, out] IkePacket          Pointer to IKE_PACKET to be encoded as input, \r
+  @param[in, out] IkePacket          Pointer to IKE_PACKET to be encoded as input,\r
                                      and the encoded result as output.\r
   @param[in]      IkeType            The type of IKE. IKE_SA_TYPE, IKE_INFO_TYPE and\r
                                      IKE_CHILD_TYPE are supportted.\r
@@ -2479,12 +2478,12 @@ Ikev2EncodePacket (
   }\r
 \r
   //\r
-  // If the packet is first message, store whole message in IkeSa->InitiPacket \r
+  // If the packet is first message, store whole message in IkeSa->InitiPacket\r
   // for following Auth Payload calculation.\r
   //\r
   if (IkePacket->Header->ExchangeType == IKEV2_EXCHANGE_TYPE_INIT) {\r
     IkeSaSession =  IKEV2_SA_SESSION_FROM_COMMON (SessionCommon);\r
-    if (SessionCommon->IsInitiator) {      \r
+    if (SessionCommon->IsInitiator) {\r
       IkeSaSession->InitPacketSize = IkePacket->PayloadTotalSize + sizeof (IKE_HEADER);\r
       IkeSaSession->InitPacket     = AllocateZeroPool (IkeSaSession->InitPacketSize);\r
       ASSERT (IkeSaSession->InitPacket != NULL);\r
@@ -2500,7 +2499,7 @@ Ikev2EncodePacket (
           );\r
         PayloadTotalSize = PayloadTotalSize + IkePayload->PayloadSize;\r
       }\r
-    } else {      \r
+    } else {\r
       IkeSaSession->RespPacketSize = IkePacket->PayloadTotalSize + sizeof(IKE_HEADER);\r
       IkeSaSession->RespPacket     = AllocateZeroPool (IkeSaSession->RespPacketSize);\r
       ASSERT (IkeSaSession->RespPacket != NULL);\r
@@ -2528,9 +2527,9 @@ Ikev2EncodePacket (
 \r
   This function decrypts the Encrypted IKE packet and put the result into IkePacket->PayloadBuf.\r
 \r
-  @param[in]      SessionCommon       Pointer to IKEV2_SESSION_COMMON containing \r
+  @param[in]      SessionCommon       Pointer to IKEV2_SESSION_COMMON containing\r
                                       some parameter used during decrypting.\r
-  @param[in, out] IkePacket           Pointer to IKE_PACKET to be decrypted as input, \r
+  @param[in, out] IkePacket           Pointer to IKE_PACKET to be decrypted as input,\r
                                       and the decrypted result as output.\r
   @param[in, out] IkeType             The type of IKE. IKE_SA_TYPE, IKE_INFO_TYPE and\r
                                       IKE_CHILD_TYPE are supportted.\r
@@ -2538,7 +2537,7 @@ Ikev2EncodePacket (
   @retval EFI_INVALID_PARAMETER      If the IKE packet length is zero or the\r
                                      IKE packet length is not aligned with Algorithm Block Size\r
   @retval EFI_SUCCESS                Decrypt IKE packet successfully.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 Ikev2DecryptPacket (\r
@@ -2548,12 +2547,12 @@ Ikev2DecryptPacket (
   )\r
 {\r
   UINT8                  CryptBlockSize;      // Encrypt Block Size\r
-  UINTN                  DecryptedSize;       // Encrypted IKE Payload Size  \r
+  UINTN                  DecryptedSize;       // Encrypted IKE Payload Size\r
   UINT8                  *DecryptedBuf;       // Encrypted IKE Payload buffer\r
   UINTN                  IntegritySize;\r
   UINT8                  *IntegrityBuffer;\r
-  UINTN                  IvSize;              // Iv Size \r
-  UINT8                  CheckSumSize;        // Integrity Check Sum Size depends on intergrity Auth \r
+  UINTN                  IvSize;              // Iv Size\r
+  UINT8                  CheckSumSize;        // Integrity Check Sum Size depends on intergrity Auth\r
   UINT8                  *CheckSumData;       // Check Sum data\r
   IKEV2_SA_SESSION       *IkeSaSession;\r
   IKEV2_CHILD_SA_SESSION *ChildSaSession;\r
@@ -2582,7 +2581,7 @@ Ikev2DecryptPacket (
   // Get the Block Size\r
   //\r
   if (SessionCommon->IkeSessionType == IkeSessionTypeIkeSa) {\r
-    \r
+\r
     CryptBlockSize = (UINT8) IpSecGetEncryptBlockSize ((UINT8) SessionCommon->SaParams->EncAlgId);\r
     CryptKeyLength = IpSecGetEncryptKeyLength ((UINT8) SessionCommon->SaParams->EncAlgId);\r
     CheckSumSize   = (UINT8) IpSecGetIcvLength ((UINT8) SessionCommon->SaParams->IntegAlgId);\r
@@ -2615,7 +2614,7 @@ Ikev2DecryptPacket (
   CopyMem (IntegrityBuffer + sizeof (IKE_HEADER), IkePacket->PayloadsBuf, IkePacket->PayloadTotalSize);\r
 \r
   //\r
-  // Change Host order to Network order, since the header order was changed \r
+  // Change Host order to Network order, since the header order was changed\r
   // in the IkePacketFromNetbuf.\r
   //\r
   IkeHdrHostToNet ((IKE_HEADER *)IntegrityBuffer);\r
@@ -2663,9 +2662,9 @@ Ikev2DecryptPacket (
     Status = EFI_ACCESS_DENIED;\r
     goto ON_EXIT;\r
   }\r
\r
+\r
   IvSize = CryptBlockSize;\r
-   \r
+\r
   //\r
   // Decrypt the payload with the key.\r
   //\r
@@ -2716,7 +2715,7 @@ Ikev2DecryptPacket (
   // Save the next payload of encrypted payload into IkePacket->Hdr->NextPayload\r
   //\r
   IkePacket->Header->NextPayload = ((IKEV2_ENCRYPTED *) IkePacket->PayloadsBuf)->Header.NextPayload;\r
-  \r
+\r
   //\r
   // Free old IkePacket->PayloadBuf and point it to decrypted paylaod buffer.\r
   //\r
@@ -2725,7 +2724,7 @@ Ikev2DecryptPacket (
   IkePacket->PayloadTotalSize = DecryptedSize - PadLen;\r
 \r
   IPSEC_DUMP_BUF ("Decrypted Buffer", DecryptedBuf, DecryptedSize);\r
-  \r
+\r
 \r
 ON_EXIT:\r
   if (CheckSumData != NULL) {\r
@@ -2739,7 +2738,7 @@ ON_EXIT:
   if (IntegrityBuffer != NULL) {\r
     FreePool (IntegrityBuffer);\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -2748,7 +2747,7 @@ ON_EXIT:
 \r
   This function encrypt IKE packet before sending it. The Encrypted IKE packet\r
   is put in to IKEV2 Encrypted Payload.\r
-  \r
+\r
   @param[in]        SessionCommon     Pointer to IKEV2_SESSION_COMMON related to the IKE packet.\r
   @param[in, out]   IkePacket         Pointer to IKE packet to be encrypted.\r
 \r
@@ -2764,15 +2763,15 @@ Ikev2EncryptPacket (
 {\r
   UINT8                  CryptBlockSize;      // Encrypt Block Size\r
   UINT8                  CryptBlockSizeMask;  // Block Mask\r
-  UINTN                  EncryptedSize;       // Encrypted IKE Payload Size  \r
+  UINTN                  EncryptedSize;       // Encrypted IKE Payload Size\r
   UINT8                  *EncryptedBuf;       // Encrypted IKE Payload buffer\r
   UINT8                  *EncryptPayloadBuf;  // Contain whole Encrypted Payload\r
   UINTN                  EncryptPayloadSize;  // Total size of the Encrypted payload\r
-  UINT8                  *IntegrityBuf;       // Buffer to be intergity \r
+  UINT8                  *IntegrityBuf;       // Buffer to be intergity\r
   UINT32                 IntegrityBufSize;    // Buffer size of IntegrityBuf\r
   UINT8                  *IvBuffer;           // Initialization Vector\r
-  UINT8                  IvSize;              // Iv Size \r
-  UINT8                  CheckSumSize;        // Integrity Check Sum Size depends on intergrity Auth \r
+  UINT8                  IvSize;              // Iv Size\r
+  UINT8                  CheckSumSize;        // Integrity Check Sum Size depends on intergrity Auth\r
   UINT8                  *CheckSumData;       // Check Sum data\r
   UINTN                  Index;\r
   IKE_PAYLOAD            *EncryptPayload;\r
@@ -2816,7 +2815,7 @@ Ikev2EncryptPacket (
     CryptKeyLength = IpSecGetEncryptKeyLength ((UINT8) IkeSaSession->SessionCommon.SaParams->EncAlgId);\r
     CheckSumSize   = (UINT8) IpSecGetIcvLength ((UINT8) IkeSaSession->SessionCommon.SaParams->IntegAlgId);\r
   }\r
-  \r
+\r
   //\r
   // Calcualte the EncryptPayloadSize and the PAD length\r
   //\r
@@ -2910,11 +2909,11 @@ Ikev2EncryptPacket (
 \r
   //\r
   // Fill in the IKE Packet header\r
-  //  \r
+  //\r
   IkePacket->PayloadTotalSize    = EncryptPayloadSize;\r
   IkePacket->Header->Length      = (UINT32) (sizeof (IKE_HEADER) + IkePacket->PayloadTotalSize);\r
   IkePacket->Header->NextPayload = IKEV2_PAYLOAD_TYPE_ENCRYPT;\r
-  \r
+\r
   IntegrityBuf                   = AllocateZeroPool (IkePacket->Header->Length);\r
   if (IntegrityBuf == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -2954,7 +2953,7 @@ Ikev2EncryptPacket (
       (UINT8)IkeSaSession->SessionCommon.SaParams->IntegAlgId,\r
       IkeSaSession->IkeKeys->SkArKey,\r
       IkeSaSession->IkeKeys->SkArKeySize,\r
-      (HASH_DATA_FRAGMENT *) Fragments, \r
+      (HASH_DATA_FRAGMENT *) Fragments,\r
       1,\r
       CheckSumData,\r
       CheckSumSize\r
@@ -2986,7 +2985,7 @@ Ikev2EncryptPacket (
   EncryptPayload->PayloadBuf  = EncryptPayloadBuf;\r
   EncryptPayload->PayloadSize = EncryptPayloadSize;\r
   EncryptPayload->PayloadType = IKEV2_PAYLOAD_TYPE_ENCRYPT;\r
-  \r
+\r
   IKE_PACKET_APPEND_PAYLOAD (IkePacket, EncryptPayload);\r
 \r
 ON_EXIT:\r
@@ -3037,8 +3036,8 @@ Ikev2OnPacketAccepted (
   The notification function. It will be called when the related UDP_TX_TOKEN's event\r
   is signaled.\r
 \r
-  This function frees the Net Buffer pointed to the input Packet. \r
-  \r
+  This function frees the Net Buffer pointed to the input Packet.\r
+\r
   @param[in]  Packet           Pointer to Net buffer containing the sending IKE packet.\r
   @param[in]  EndPoint         Pointer to UDP_END_POINT containing the remote and local\r
                                address information.\r
@@ -3064,11 +3063,11 @@ Ikev2OnPacketSent (
 \r
  IkePacket  = (IKE_PACKET *) Context;\r
  Private    = NULL;\r
\r
+\r
  if (EFI_ERROR (IoStatus)) {\r
     DEBUG ((DEBUG_ERROR, "Error send the last packet in IkeSessionTypeIkeSa with %r\n", IoStatus));\r
   }\r
-  \r
+\r
   NetbufFree (Packet);\r
 \r
   if (IkePacket->IsDeleteInfo) {\r
@@ -3088,7 +3087,7 @@ Ikev2OnPacketSent (
     if (IkePacket->Spi != 0 ) {\r
       //\r
       // At that time, the established Child SA still in eht ChildSaEstablishSessionList.\r
-      // And meanwhile, if the Child SA is in the the ChildSa in Delete list, \r
+      // And meanwhile, if the Child SA is in the the ChildSa in Delete list,\r
       // remove it from delete list and delete it direclty.\r
       //\r
       ChildSaSession = Ikev2ChildSaSessionLookupBySpi (\r
@@ -3129,7 +3128,7 @@ Ikev2OnPacketSent (
   IkePacketFree (IkePacket);\r
 \r
   //\r
-  // when all IKE SAs were disabled by calling "IPsecConfig -disable", the IPsec status \r
+  // when all IKE SAs were disabled by calling "IPsecConfig -disable", the IPsec status\r
   // should be changed.\r
   //\r
   if (Private != NULL && Private->IsIPsecDisabling) {\r
@@ -3163,8 +3162,8 @@ Ikev2OnPacketSent (
   @param[in]  IkeUdpService     Pointer to IKE_UDP_SERVICE used to send the IKE packet.\r
   @param[in]  SessionCommon     Pointer to IKEV1_SESSION_COMMON related to the IKE packet.\r
   @param[in]  IkePacket         Pointer to IKE_PACKET to be sent out.\r
-  @param[in]  IkeType           The type of IKE to point what's kind of the IKE \r
-                                packet is to be sent out. IKE_SA_TYPE, IKE_INFO_TYPE \r
+  @param[in]  IkeType           The type of IKE to point what's kind of the IKE\r
+                                packet is to be sent out. IKE_SA_TYPE, IKE_INFO_TYPE\r
                                 and IKE_CHILD_TYPE are supportted.\r
 \r
   @retval     EFI_SUCCESS       The operation complete successfully.\r
@@ -3185,7 +3184,7 @@ Ikev2SendIkePacket (
   IKEV2_SESSION_COMMON  *Common;\r
 \r
   Common = (IKEV2_SESSION_COMMON *) SessionCommon;\r
-  \r
+\r
   //\r
   // Set the resend interval\r
   //\r
@@ -3212,7 +3211,7 @@ Ikev2SendIkePacket (
 \r
   IKE_PACKET_REF (IkePacket);\r
   //\r
-  // If the last sent packet is same with this round packet, the packet is resent packet. \r
+  // If the last sent packet is same with this round packet, the packet is resent packet.\r
   //\r
   if (IkePacket != Common->LastSentPacket && Common->LastSentPacket != NULL) {\r
     IkePacketFree (Common->LastSentPacket);\r
index bd12aa2e07a29b695af34002a76b2eca1776f77a..753c70db545a1384aa90c6c717630a0d584553fc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Driver Binding Protocol for IPsec Driver.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -81,7 +81,7 @@ IpSecDriverBindingSupported (
 \r
   @retval EFI_SUCCES           This driver is added to ControllerHandle\r
   @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
-  @retval EFI_DEVICE_ERROR     The device could not be started due to a device error.  \r
+  @retval EFI_DEVICE_ERROR     The device could not be started due to a device error.\r
                                Currently not implemented.\r
   @retval other                This driver does not support this device\r
 \r
@@ -189,6 +189,10 @@ IpSecDriverBindingStop (
 \r
   Private = IPSEC_PRIVATE_DATA_FROM_IPSEC (IpSec);\r
 \r
+  //\r
+  // Delete all SAs before stop Ipsec.\r
+  //\r
+  IkeDeleteAllSas (Private, FALSE);\r
   //\r
   // If has udp4 io opened on the controller, close and free it.\r
   //\r
@@ -256,9 +260,9 @@ EFI_DRIVER_BINDING_PROTOCOL gIpSecDriverBinding = {
 \r
 /**\r
   This is a callback function when the mIpSecInstance.DisabledEvent is signaled.\r
-    \r
+\r
   @param[in]  Event        Event whose notification function is being invoked.\r
-  @param[in]  Context      Pointer to the notification function's context. \r
+  @param[in]  Context      Pointer to the notification function's context.\r
 \r
 **/\r
 VOID\r
@@ -271,15 +275,15 @@ IpSecCleanupAllSa (
   IPSEC_PRIVATE_DATA  *Private;\r
   Private                   = (IPSEC_PRIVATE_DATA *) Context;\r
   Private->IsIPsecDisabling = TRUE;\r
-  IkeDeleteAllSas (Private);\r
+  IkeDeleteAllSas (Private, TRUE);\r
 }\r
 \r
 /**\r
   This is the declaration of an EFI image entry point. This entry point is\r
   the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers, including\r
   both device drivers and bus drivers.\r
-  \r
-  The entry point for IPsec driver which installs the driver binding, \r
+\r
+  The entry point for IPsec driver which installs the driver binding,\r
   component name protocol, IPsec Config protcolon, and IPsec protocol in\r
   its ImageHandle.\r
 \r
@@ -289,7 +293,7 @@ IpSecCleanupAllSa (
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_ALREADY_STARTED   The IPsec driver has been already loaded.\r
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
-  @retval Others                The operation is failed. \r
+  @retval Others                The operation is failed.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -346,7 +350,7 @@ IpSecDriverEntryPoint (
   Private->Signature    = IPSEC_PRIVATE_DATA_SIGNATURE;\r
   Private->ImageHandle  = ImageHandle;\r
   CopyMem (&Private->IpSec, &mIpSecInstance, sizeof (EFI_IPSEC2_PROTOCOL));\r
-  \r
+\r
   //\r
   // Initilize Private's members. Thess members is used for IKE.\r
   //\r
@@ -356,7 +360,7 @@ IpSecDriverEntryPoint (
   InitializeListHead (&Private->Ikev1EstablishedList);\r
   InitializeListHead (&Private->Ikev2SessionList);\r
   InitializeListHead (&Private->Ikev2EstablishedList);\r
-  \r
+\r
   RandomSeed (NULL, 0);\r
   //\r
   // Initialize the ipsec config data and restore it from variable.\r
@@ -390,7 +394,7 @@ IpSecDriverEntryPoint (
   if (EFI_ERROR (Status)) {\r
     goto ON_UNINSTALL_IPSEC;\r
   }\r
-  \r
+\r
   return Status;\r
 \r
 ON_UNINSTALL_IPSEC:\r
index 50cd4d8540490fe6e603085769c10291d8d5000e..347bdd994ef45201d70f93b6401643b9c2c82f36 100644 (file)
@@ -23,7 +23,7 @@
   Check if the specified Address is the Valid Address Range.\r
 \r
   This function checks if the bytes after prefixed length are all Zero in this\r
-  Address. This Address is supposed to point to a range address. That means it \r
+  Address. This Address is supposed to point to a range address. That means it\r
   should gives the correct prefixed address and the bytes outside the prefixed are\r
   zero.\r
 \r
@@ -329,7 +329,7 @@ IpSecLookupSadBySpd (
 {\r
   LIST_ENTRY      *Entry;\r
   IPSEC_SAD_ENTRY *SadEntry;\r
-  \r
+\r
   NET_LIST_FOR_EACH (Entry, SadList) {\r
 \r
     SadEntry = IPSEC_SAD_ENTRY_FROM_SPD (Entry);\r
@@ -341,7 +341,7 @@ IpSecLookupSadBySpd (
           DestAddress,\r
           SadEntry->Data->SpdSelector->RemoteAddress,\r
           SadEntry->Data->SpdSelector->RemoteAddressCount\r
-          )){    \r
+          )){\r
       return SadEntry;\r
     }\r
   }\r
@@ -382,7 +382,7 @@ IpSecLookupSadBySpi (
     if (SadEntry->Id->Spi == Spi) {\r
       if (SadEntry->Data->Mode == EfiIPsecTunnel) {\r
         if (CompareMem (\r
-              &DestAddress, \r
+              &DestAddress,\r
               &SadEntry->Data->TunnelDestAddress,\r
               sizeof (EFI_IP_ADDRESS)\r
               )) {\r
@@ -391,14 +391,14 @@ IpSecLookupSadBySpi (
       } else {\r
         if (SadEntry->Data->SpdSelector != NULL &&\r
             IpSecMatchIpAddress (\r
-              IpVersion, \r
-              DestAddress, \r
+              IpVersion,\r
+              DestAddress,\r
               SadEntry->Data->SpdSelector->RemoteAddress,\r
               SadEntry->Data->SpdSelector->RemoteAddressCount\r
               )\r
             ) {\r
           return SadEntry;\r
-        }       \r
+        }\r
       }\r
     }\r
   }\r
@@ -471,14 +471,13 @@ IpSecLookupSadEntry (
       sizeof (EFI_IP_ADDRESS)\r
       );\r
   }\r
-  \r
+\r
   //\r
   // Find the SAD entry in the spd.sas list according to the dest address.\r
   //\r
   Entry = IpSecLookupSadBySpd (&SpdEntry->Data->Sas, &DestIp, IpVersion);\r
 \r
   if (Entry == NULL) {\r
-\r
     if (OldLastHead != IP6_ICMP ||\r
         (OldLastHead == IP6_ICMP && *IpPayload == ICMP_V6_ECHO_REQUEST)\r
         ) {\r
@@ -498,7 +497,7 @@ IpSecLookupSadEntry (
           &DestIp\r
         );\r
       }\r
-      \r
+\r
     }\r
 \r
     return EFI_NOT_READY;\r
@@ -595,7 +594,7 @@ IpSecLookupSpdEntry (
   IN     VOID                    *IpHead,\r
   IN     UINT8                   *IpPayload,\r
   IN     UINT8                   Protocol,\r
-  IN     BOOLEAN                 IsOutbound, \r
+  IN     BOOLEAN                 IsOutbound,\r
      OUT EFI_IPSEC_ACTION        *Action\r
   )\r
 {\r
@@ -733,7 +732,7 @@ IpSecRecycleCallback (
 }\r
 \r
 /**\r
-  Calculate the extension hader of IP. The return length only doesn't contain \r
+  Calculate the extension hader of IP. The return length only doesn't contain\r
   the fixed IP header length.\r
 \r
   @param[in]  IpHead             Points to an IP head to be calculated.\r
@@ -801,7 +800,7 @@ IpSecEspAuthVerifyPayload (
   //\r
   HashFragment[0].Data     = EspBuffer;\r
   HashFragment[0].DataSize = AuthSize;\r
-  \r
+\r
   Status = IpSecCryptoIoHmac (\r
              SadEntry->Data->AlgoInfo.EspAlgoInfo.AuthAlgoId,\r
              SadEntry->Data->AlgoInfo.EspAlgoInfo.AuthKey,\r
@@ -814,7 +813,7 @@ IpSecEspAuthVerifyPayload (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Compare the calculated icv and the appended original icv.\r
   //\r
@@ -832,10 +831,10 @@ IpSecEspAuthVerifyPayload (
   @param[in]  IpHead       The pointer to IP header.\r
   @param[in]  IpVersion    The version of IP (IP4 or IP6).\r
   @param[in]  Spi          The SPI used to search the related SAD entry.\r
-  \r
+\r
 \r
   @retval     NULL             Not find the related SAD entry.\r
-  @retval     IPSEC_SAD_ENTRY  Return the related SAD entry. \r
+  @retval     IPSEC_SAD_ENTRY  Return the related SAD entry.\r
 \r
 **/\r
 IPSEC_SAD_ENTRY *\r
@@ -843,10 +842,10 @@ IpSecFoundSadFromInboundPacket (
    UINT8   *IpHead,\r
    UINT8   IpVersion,\r
    UINT32  Spi\r
-   ) \r
+   )\r
 {\r
   EFI_IP_ADDRESS   DestIp;\r
-   \r
+\r
   //\r
   // Parse destination address from ip header.\r
   //\r
@@ -864,10 +863,10 @@ IpSecFoundSadFromInboundPacket (
       sizeof (EFI_IPv6_ADDRESS)\r
       );\r
   }\r
-  \r
+\r
   //\r
   // Lookup SAD entry according to the spi and dest address.\r
-  //  \r
+  //\r
   return IpSecLookupSadBySpi (Spi, &DestIp, IpVersion);\r
 }\r
 \r
@@ -994,7 +993,7 @@ IpSecIsIp6ExtsValid (
        }\r
 \r
        return TRUE;\r
-    }   \r
+    }\r
   }\r
 \r
   *LastHeader = NextHeader;\r
@@ -1007,14 +1006,14 @@ IpSecIsIp6ExtsValid (
 }\r
 \r
 /**\r
-  The actual entry to process the tunnel header and inner header for tunnel mode \r
+  The actual entry to process the tunnel header and inner header for tunnel mode\r
   outbound traffic.\r
 \r
-  This function is the subfunction of IpSecEspInboundPacket(). It change the destination \r
+  This function is the subfunction of IpSecEspInboundPacket(). It change the destination\r
   Ip address to the station address and recalculate the uplayyer's checksum.\r
-  \r
 \r
-  @param[in, out] IpHead             Points to the IP header containing the ESP header \r
+\r
+  @param[in, out] IpHead             Points to the IP header containing the ESP header\r
                                      to be trimed on input, and without ESP header\r
                                      on return.\r
   @param[in]      IpPayload          The decrypted Ip payload. It start from the inner\r
@@ -1042,10 +1041,10 @@ IpSecTunnelInboundPacket (
   IP6_ICMP_HEAD    *Icmp6Head;\r
 \r
   Checksum = NULL;\r
-  \r
+\r
   if (IpVersion == IP_VERSION_4) {\r
     //\r
-    // Zero OutIP header use this to indicate the input packet is under \r
+    // Zero OutIP header use this to indicate the input packet is under\r
     // IPsec Tunnel protected.\r
     //\r
     ZeroMem (\r
@@ -1057,20 +1056,20 @@ IpSecTunnelInboundPacket (
       &SadData->TunnelDestAddress.v4,\r
       sizeof (EFI_IPv4_ADDRESS)\r
       );\r
-      \r
+\r
     //\r
     // Recalculate IpHeader Checksum\r
     //\r
     if (((IP4_HEAD *)(IpPayload))->Checksum != 0 ) {\r
       ((IP4_HEAD *)(IpPayload))->Checksum = 0;\r
       ((IP4_HEAD *)(IpPayload))->Checksum = (UINT16) (~NetblockChecksum (\r
-                                                        (UINT8 *)IpPayload, \r
+                                                        (UINT8 *)IpPayload,\r
                                                         ((IP4_HEAD *)IpPayload)->HeadLen << 2\r
                                                         ));\r
 \r
 \r
     }\r
-    \r
+\r
     //\r
     // Recalcualte PseudoChecksum\r
     //\r
@@ -1091,7 +1090,7 @@ IpSecTunnelInboundPacket (
       break;\r
       }\r
     PacketChecksum = NetblockChecksum (\r
-                       (UINT8 *)IpPayload + (((IP4_HEAD *)IpPayload)->HeadLen << 2), \r
+                       (UINT8 *)IpPayload + (((IP4_HEAD *)IpPayload)->HeadLen << 2),\r
                        NTOHS (((IP4_HEAD *)IpPayload)->TotalLen) - (((IP4_HEAD *)IpPayload)->HeadLen << 2)\r
                        );\r
     PseudoChecksum = NetPseudoHeadChecksum (\r
@@ -1100,14 +1099,14 @@ IpSecTunnelInboundPacket (
                        ((IP4_HEAD *)IpPayload)->Protocol,\r
                        0\r
                        );\r
-      \r
+\r
       if (Checksum != NULL) {\r
         *Checksum = NetAddChecksum (PacketChecksum, PseudoChecksum);\r
         *Checksum = (UINT16) ~(NetAddChecksum (*Checksum, HTONS((UINT16)(NTOHS (((IP4_HEAD *)IpPayload)->TotalLen) - (((IP4_HEAD *)IpPayload)->HeadLen << 2)))));\r
       }\r
     }else {\r
       //\r
-      //  Zero OutIP header use this to indicate the input packet is under \r
+      //  Zero OutIP header use this to indicate the input packet is under\r
       //  IPsec Tunnel protected.\r
       //\r
       ZeroMem (\r
@@ -1119,7 +1118,7 @@ IpSecTunnelInboundPacket (
         &SadData->TunnelDestAddress.v6,\r
         sizeof (EFI_IPv6_ADDRESS)\r
         );\r
-      \r
+\r
       //\r
       // Get the Extension Header and Header length.\r
       //\r
@@ -1130,7 +1129,7 @@ IpSecTunnelInboundPacket (
         &LastHead,\r
         &OptionLen\r
         );\r
-      \r
+\r
       //\r
       // Recalcualte PseudoChecksum\r
       //\r
@@ -1154,7 +1153,7 @@ IpSecTunnelInboundPacket (
         break;\r
       }\r
       PacketChecksum = NetblockChecksum (\r
-                         IpPayload + sizeof (EFI_IP6_HEADER) + OptionLen, \r
+                         IpPayload + sizeof (EFI_IP6_HEADER) + OptionLen,\r
                          NTOHS(((EFI_IP6_HEADER *)IpPayload)->PayloadLength) - OptionLen\r
                          );\r
       PseudoChecksum = NetIp6PseudoHeadChecksum (\r
@@ -1163,7 +1162,7 @@ IpSecTunnelInboundPacket (
                          *LastHead,\r
                          0\r
                          );\r
-    \r
+\r
     if (Checksum != NULL) {\r
       *Checksum = NetAddChecksum (PacketChecksum, PseudoChecksum);\r
       *Checksum = (UINT16) ~(NetAddChecksum (\r
@@ -1171,22 +1170,22 @@ IpSecTunnelInboundPacket (
                                HTONS ((UINT16)((NTOHS (((EFI_IP6_HEADER *)(IpPayload))->PayloadLength)) - OptionLen))\r
                                ));\r
     }\r
-  }    \r
+  }\r
 }\r
 \r
 /**\r
   The actual entry to create inner header for tunnel mode inbound traffic.\r
 \r
-  This function is the subfunction of IpSecEspOutboundPacket(). It create \r
-  the sending packet by encrypting its payload and inserting ESP header in the orginal \r
+  This function is the subfunction of IpSecEspOutboundPacket(). It create\r
+  the sending packet by encrypting its payload and inserting ESP header in the orginal\r
   IP header, then return the IpHeader and IPsec protected Fragmentable.\r
-  \r
-  @param[in, out] IpHead             Points to IP header containing the orginal IP header \r
+\r
+  @param[in, out] IpHead             Points to IP header containing the orginal IP header\r
                                      to be processed on input, and inserted ESP header\r
                                      on return.\r
   @param[in]      IpVersion          The version of IP.\r
   @param[in]      SadData            The related SAD data.\r
-  @param[in, out] LastHead           The Last Header in IP header.  \r
+  @param[in, out] LastHead           The Last Header in IP header.\r
   @param[in]      OptionsBuffer      Pointer to the options buffer.\r
   @param[in]      OptionsLength      Length of the options buffer.\r
   @param[in, out] FragmentTable      Pointer to a list of fragments to be protected by\r
@@ -1221,7 +1220,7 @@ IpSecTunnelOutboundPacket (
   if (OptionsLength == NULL) {\r
     return NULL;\r
   }\r
-  \r
+\r
   if (IpVersion == IP_VERSION_4) {\r
     InnerHead = AllocateZeroPool (sizeof (IP4_HEAD) + *OptionsLength);\r
     ASSERT (InnerHead != NULL);\r
@@ -1256,7 +1255,7 @@ IpSecTunnelOutboundPacket (
       *OptionsLength = 0;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // 2. Reassamlbe Fragment into Packet\r
   //\r
@@ -1294,13 +1293,13 @@ IpSecTunnelOutboundPacket (
     Checksum = &IcmpHead->Checksum;\r
     *Checksum = 0;\r
     break;\r
-  \r
-  default: \r
+\r
+  default:\r
     break;\r
   }\r
 \r
   PacketChecksum = NetbufChecksum (Packet);\r
-    \r
+\r
   if (IpVersion == IP_VERSION_4) {\r
     //\r
     // Replace the source address of Inner Header.\r
@@ -1318,7 +1317,7 @@ IpSecTunnelOutboundPacket (
                        *LastHead,\r
                        0\r
                        );\r
-    \r
+\r
    } else {\r
      //\r
      // Replace the source address of Inner Header.\r
@@ -1335,7 +1334,7 @@ IpSecTunnelOutboundPacket (
                       *LastHead,\r
                       0\r
                       );\r
-   \r
+\r
    }\r
    if (Checksum != NULL) {\r
      *Checksum = NetAddChecksum (PacketChecksum, PseudoChecksum);\r
@@ -1351,12 +1350,12 @@ IpSecTunnelOutboundPacket (
 /**\r
   The actual entry to relative function processes the inbound traffic of ESP header.\r
 \r
-  This function is the subfunction of IpSecProtectInboundPacket(). It checks the \r
+  This function is the subfunction of IpSecProtectInboundPacket(). It checks the\r
   received packet security property and trim the ESP header and then returns without\r
   an IPsec protected IP Header and FramgmentTable.\r
-  \r
+\r
   @param[in]      IpVersion          The version of IP.\r
-  @param[in, out] IpHead             Points to the IP header containing the ESP header \r
+  @param[in, out] IpHead             Points to the IP header containing the ESP header\r
                                      to be trimed on input, and without ESP header\r
                                      on return.\r
   @param[out]     LastHead           The Last Header in IP header on return.\r
@@ -1417,7 +1416,7 @@ IpSecEspInboundPacket (
   *RecycleEvent     = NULL;\r
   PlainPayloadSize  = 0;\r
   NextHeader        = 0;\r
-  \r
+\r
   //\r
   // Build netbuf from fragment table first.\r
   //\r
@@ -1433,27 +1432,27 @@ IpSecEspInboundPacket (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // Get the esp size and esp header from netbuf.\r
   //\r
   EspSize   = Payload->TotalSize;\r
   EspHeader = (EFI_ESP_HEADER *) NetbufGetByte (Payload, 0, NULL);\r
-  \r
+\r
   if (EspHeader == NULL) {\r
     Status = EFI_ACCESS_DENIED;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // Parse destination address from ip header and found the related SAD Entry.\r
   //\r
   SadEntry = IpSecFoundSadFromInboundPacket (\r
-               IpHead, \r
+               IpHead,\r
                IpVersion,\r
                NTOHL (EspHeader->Spi)\r
                );\r
-  \r
+\r
   if (SadEntry == NULL) {\r
     Status = EFI_ACCESS_DENIED;\r
     goto ON_EXIT;\r
@@ -1475,7 +1474,7 @@ IpSecEspInboundPacket (
     // TODO: Check SA lifetime and sequence number\r
     //\r
   }\r
-    \r
+\r
   //\r
   // Allocate buffer for decryption and authentication.\r
   //\r
@@ -1493,7 +1492,7 @@ IpSecEspInboundPacket (
   IcvSize   = IpSecGetIcvLength (SadEntry->Data->AlgoInfo.EspAlgoInfo.AuthAlgoId);\r
   IvSize    = IpSecGetEncryptIvLength (SadEntry->Data->AlgoInfo.EspAlgoInfo.EncAlgoId);\r
   BlockSize = IpSecGetEncryptBlockSize (SadEntry->Data->AlgoInfo.EspAlgoInfo.EncAlgoId);\r
-  \r
+\r
   //\r
   // Make sure the ESP packet is not mal-formt.\r
   // 1. Check whether the Espsize is larger than ESP header + IvSize + EspTail + IcvSize.\r
@@ -1540,20 +1539,20 @@ IpSecEspInboundPacket (
       goto ON_EXIT;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Parse EspTail and compute the plain payload size.\r
   //\r
   EspTail           = (EFI_ESP_TAIL *) (ProcessBuffer + EspSize - IcvSize - sizeof (EFI_ESP_TAIL));\r
   PaddingSize       = EspTail->PaddingLength;\r
   NextHeader        = EspTail->NextHeader;\r
-  \r
+\r
   if (EspSize <= (MiscSize + sizeof (EFI_ESP_TAIL) + PaddingSize)) {\r
     Status = EFI_ACCESS_DENIED;\r
     goto ON_EXIT;\r
   }\r
   PlainPayloadSize  = EspSize - MiscSize - sizeof (EFI_ESP_TAIL) - PaddingSize;\r
-  \r
+\r
   //\r
   // TODO: handle anti-replay window\r
   //\r
@@ -1577,7 +1576,7 @@ IpSecEspInboundPacket (
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // The caller will take responsible to handle the original fragment table\r
   //\r
@@ -1589,7 +1588,7 @@ IpSecEspInboundPacket (
 \r
   RecycleContext->PayloadBuffer       = ProcessBuffer;\r
   RecycleContext->FragmentTable       = *FragmentTable;\r
-  \r
+\r
   //\r
   // If Tunnel, recalculate upper-layyer PesudoCheckSum and trim the out\r
   //\r
@@ -1602,20 +1601,20 @@ IpSecEspInboundPacket (
       SadData,\r
       LastHead\r
       );\r
-    \r
+\r
     if (IpVersion == IP_VERSION_4) {\r
       (*FragmentTable)[0].FragmentBuffer  = InnerHead ;\r
       (*FragmentTable)[0].FragmentLength  = (UINT32) PlainPayloadSize;\r
-      \r
-    }else {      \r
+\r
+    }else {\r
       (*FragmentTable)[0].FragmentBuffer  = InnerHead;\r
       (*FragmentTable)[0].FragmentLength  = (UINT32) PlainPayloadSize;\r
-    }    \r
+    }\r
   } else {\r
     (*FragmentTable)[0].FragmentBuffer  = ProcessBuffer + sizeof (EFI_ESP_HEADER) + IvSize;\r
     (*FragmentTable)[0].FragmentLength  = (UINT32) PlainPayloadSize;\r
   }\r
-  \r
+\r
   *FragmentCount                      = 1;\r
 \r
   //\r
@@ -1633,7 +1632,7 @@ IpSecEspInboundPacket (
     //\r
     *LastHead = NextHeader;\r
   }\r
-  \r
+\r
 \r
   //\r
   // Update the SPD association of the SAD entry.\r
@@ -1721,7 +1720,7 @@ IpSecEspOutboundPacket (
   EFI_ESP_TAIL          *EspTail;        // Address behind padding\r
   UINT8                 *InnerHead;\r
   HASH_DATA_FRAGMENT    HashFragment[1];\r
-  \r
+\r
   Status          = EFI_ACCESS_DENIED;\r
   SaId            = SadEntry->Id;\r
   SadData         = SadEntry->Data;\r
@@ -1754,7 +1753,7 @@ IpSecEspOutboundPacket (
                   FragmentTable,\r
                   FragmentCount\r
                   );\r
-    \r
+\r
     if (InnerHead == NULL) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
@@ -1794,7 +1793,7 @@ IpSecEspOutboundPacket (
     //\r
     // OPtions should be encryption into it\r
     //\r
-    PlainPayloadSize += *OptionsLength;    \r
+    PlainPayloadSize += *OptionsLength;\r
   }\r
 \r
 \r
@@ -1852,7 +1851,7 @@ IpSecEspOutboundPacket (
       // HeadLen, Total Length\r
       //\r
       ((IP4_HEAD *)InnerHead)->HeadLen  = (UINT8) ((sizeof (IP4_HEAD) + *OptionsLength) >> 2);\r
-      ((IP4_HEAD *)InnerHead)->TotalLen = HTONS ((UINT16) PlainPayloadSize);  \r
+      ((IP4_HEAD *)InnerHead)->TotalLen = HTONS ((UINT16) PlainPayloadSize);\r
       ((IP4_HEAD *)InnerHead)->Checksum = 0;\r
       ((IP4_HEAD *)InnerHead)->Checksum = (UINT16) (~NetblockChecksum (\r
                                                   (UINT8 *)InnerHead,\r
@@ -1904,7 +1903,7 @@ IpSecEspOutboundPacket (
       EspTail->NextHeader = 4;\r
     } else {\r
       EspTail->NextHeader = 41;\r
-    }    \r
+    }\r
   }\r
 \r
   //\r
@@ -1914,8 +1913,8 @@ IpSecEspOutboundPacket (
              (UINT8 *) (EspHeader + 1),\r
              IvSize\r
              );\r
-  \r
-  \r
+\r
+\r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
@@ -2011,10 +2010,10 @@ IpSecEspOutboundPacket (
   if (SadData->Mode == EfiIPsecTunnel) {\r
     if (IpVersion == IP_VERSION_4) {\r
       CopyMem (\r
-        &((IP4_HEAD *) IpHead)->Src, \r
+        &((IP4_HEAD *) IpHead)->Src,\r
         &SadData->TunnelSourceAddress.v4,\r
         sizeof (EFI_IPv4_ADDRESS)\r
-        );  \r
+        );\r
       CopyMem (\r
         &((IP4_HEAD *) IpHead)->Dst,\r
         &SadData->TunnelDestAddress.v4,\r
@@ -2065,11 +2064,11 @@ ON_EXIT:
 /**\r
   This function processes the inbound traffic with IPsec.\r
 \r
-  It checks the received packet security property, trims the ESP/AH header, and then \r
+  It checks the received packet security property, trims the ESP/AH header, and then\r
   returns without an IPsec protected IP Header and FragmentTable.\r
-  \r
+\r
   @param[in]      IpVersion          The version of IP.\r
-  @param[in, out] IpHead             Points to IP header containing the ESP/AH header \r
+  @param[in, out] IpHead             Points to IP header containing the ESP/AH header\r
                                      to be trimed on input, and without ESP/AH header\r
                                      on return.\r
   @param[in, out] LastHead           The Last Header in IP header on return.\r