]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetLib:
authortye <tye@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Oct 2009 10:15:40 +0000 (10:15 +0000)
committertye <tye@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Oct 2009 10:15:40 +0000 (10:15 +0000)
1. Add new interface Ip6IsValidUnicast
2. Add new enum IP6_EXTENSION_HEADER_TYPE
3. Add new structure IP6_ICMP_* definitions
4. Update structure from EFI_UDP4_HEADER to EFI_UDP_HEADER
5. Add new macro EFI_IP6_EQUAL

IpIoLib:
1. Update the IpIoLib to a combined library for both v4 and v6 network stack
2. Fix a bug in IpIoIcmpHandler() - for IPv6 packet, the header length is variable (basic header + extension) rathar than fixed length.
   The fix removes the IPv6 header fields and notify the user with the ICMPv6 packet only containing payload.

TcpDxe/UdpDxe:
1. Update to adapt the new combined IpIoLib
2. Add gEfiIp6ProtocolGuid/gEfiIp6ServiceBindingProtocolGuid to [Protocols] in INF file since the Ip6.h is included in IpIoLib and NetLib.
3. Pass the TCP4/UDP4 UEFI SCT test on NT32 platform.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9374 6f19259b-4bc3-4df7-8a09-765794883524

14 files changed:
MdeModulePkg/Include/Library/IpIoLib.h
MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.h
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c

index daf8c308a1076ff55cef95c1748e844888702313..a27487f7e57afa8e09c38e8f4a84a8b608dceb19 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
-  Ihis library is only intended to be used by UEFI network stack modules.\r
-  It provides the IpIo layer on the EFI IP4 Protocol.\r
+  This library is only intended to be used by UEFI network stack modules.\r
+  It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6 protocol.\r
 \r
-Copyright (c) 2005 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define _IP_IO_H_\r
 \r
 #include <Protocol/Ip4.h>\r
+#include <Protocol/Ip6.h>\r
 \r
 #include <Library/NetLib.h>\r
 \r
@@ -77,7 +78,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define NET_PROTO_HDR(Buf, Type)  ((Type *) ((Buf)->BlockOp[0].Head))\r
 \r
   \r
-extern EFI_IP4_CONFIG_DATA  mIpIoDefaultIpConfigData;\r
+extern EFI_IP4_CONFIG_DATA  mIp4IoDefaultIpConfigData;\r
+extern EFI_IP6_CONFIG_DATA  mIp6IoDefaultIpConfigData;\r
+\r
+typedef enum {\r
+  IP_VERSION_4 = 4,\r
+  IP_VERSION_6 = 6\r
+} IP_VERSION;\r
 \r
 ///\r
 /// This error will be delivered to the\r
@@ -97,21 +104,64 @@ typedef enum {
   ICMP_ERR_PARAMPROB\r
 } ICMP_ERROR;\r
 \r
+typedef enum {\r
+  ICMP6_ERR_UNREACH_NET      = 0,\r
+  ICMP6_ERR_UNREACH_HOST,\r
+  ICMP6_ERR_UNREACH_PROTOCOL,\r
+  ICMP6_ERR_UNREACH_PORT,\r
+  ICMP6_ERR_PACKAGE_TOOBIG,\r
+  ICMP6_ERR_TIMXCEED_HOPLIMIT,\r
+  ICMP6_ERR_TIMXCEED_REASS,\r
+  ICMP6_ERR_PARAMPROB_HEADER,\r
+  ICMP6_ERR_PARAMPROB_NEXHEADER,\r
+  ICMP6_ERR_PARAMPROB_IPV6OPTION\r
+} ICMP6_ERROR;\r
+\r
 ///\r
 /// The helper struct for IpIoGetIcmpErrStatus(). It is for internal use only.\r
 ///\r
 typedef struct {\r
-  BOOLEAN     IsHard;\r
-  BOOLEAN     Notify;\r
+  EFI_STATUS                Error;\r
+  BOOLEAN                   IsHard;\r
+  BOOLEAN                   Notify;\r
 } ICMP_ERROR_INFO;\r
 \r
+typedef union {\r
+  EFI_IP4_COMPLETION_TOKEN  Ip4Token;\r
+  EFI_IP6_COMPLETION_TOKEN  Ip6Token;\r
+} IP_IO_IP_COMPLETION_TOKEN;\r
+\r
+typedef union {\r
+  EFI_IP4_TRANSMIT_DATA     Ip4TxData;\r
+  EFI_IP6_TRANSMIT_DATA     Ip6TxData;\r
+} IP_IO_IP_TX_DATA;\r
+\r
+typedef union {\r
+  EFI_IP4_RECEIVE_DATA      Ip4RxData;\r
+  EFI_IP6_RECEIVE_DATA      Ip6RxData;\r
+} IP_IO_IP_RX_DATA;\r
+\r
+typedef union {\r
+  EFI_IP4_OVERRIDE_DATA     Ip4OverrideData;\r
+  EFI_IP6_OVERRIDE_DATA     Ip6OverrideData;\r
+} IP_IO_OVERRIDE;\r
+\r
+typedef union {\r
+  EFI_IP4_CONFIG_DATA       Ip4CfgData;\r
+  EFI_IP6_CONFIG_DATA       Ip6CfgData;\r
+} IP_IO_IP_CONFIG_DATA;\r
+\r
 ///\r
 /// The IP session for an IP receive packet.\r
 ///\r
 typedef struct _EFI_NET_SESSION_DATA {\r
-  IP4_ADDR        Source;     ///< Source IP of the received packet\r
-  IP4_ADDR        Dest;       ///< Destination IP of the received packet\r
-  EFI_IP4_HEADER  *IpHdr;     ///< IP4 header of the received packet\r
+  EFI_IP_ADDRESS        Source;     ///< Source IP of the received packet\r
+  EFI_IP_ADDRESS        Dest;       ///< Destination IP of the received packet\r
+  union {\r
+    EFI_IP4_HEADER      *Ip4Hdr;    ///< IP4 header of the received packet\r
+    EFI_IP6_HEADER      *Ip6Hdr;    ///< IP6 header of the received packet\r
+  } IpHdr;\r
+  IP_VERSION            IpVersion;  ///< The IP version of the received packet\r
 } EFI_NET_SESSION_DATA;\r
 \r
 /**\r
@@ -141,7 +191,7 @@ VOID
   @param[in] Status        Result of the sending\r
   @param[in] Context       The data provided by user for the received packet when\r
                            the callback is registered in IP_IO_OPEN_DATA::SndContext.\r
-  @param[in] Sender        A pointer to EFI_IP4_PROTOCOL for sender\r
+  @param[in] Sender        A pointer to EFI_IP4_PROTOCOL or EFI_IP6_PROTOCOL\r
   @param[in] NotifyData    Context data specified when calling IpIoSend()\r
   \r
 **/\r
@@ -155,8 +205,8 @@ VOID
   );\r
 \r
 ///\r
-/// This data structure wraps Ip4 instances. The IpIo Library uses it for all\r
-/// Ip4 operations.\r
+/// This data structure wraps Ip4/Ip6 instances. The IpIo Library uses it for all\r
+/// Ip4/Ip6 operations.\r
 ///\r
 typedef struct _IP_IO {\r
   ///\r
@@ -175,7 +225,7 @@ typedef struct _IP_IO {
   //\r
   // The IP instance consumed by this IP_IO\r
   //\r
-  EFI_IP4_PROTOCOL              *Ip;\r
+  VOID                          *Ip;\r
   BOOLEAN                       IsConfigured;\r
 \r
   ///\r
@@ -186,7 +236,7 @@ typedef struct _IP_IO {
   ///\r
   /// Token and event used to get data from IP\r
   ///\r
-  EFI_IP4_COMPLETION_TOKEN      RcvToken;\r
+  IP_IO_IP_COMPLETION_TOKEN     RcvToken; \r
 \r
   ///\r
   /// List entry used to link the token passed to IP_IO\r
@@ -200,6 +250,10 @@ typedef struct _IP_IO {
   VOID                          *SndContext;     ///< See IP_IO_OPEN_DATA::SndContext\r
   PKT_RCVD_NOTIFY               PktRcvdNotify;   ///< See IP_IO_OPEN_DATA::PktRcvdNotify\r
   PKT_SENT_NOTIFY               PktSentNotify;   ///< See IP_IO_OPEN_DATA::PktSentNotify\r
+  //\r
+  // Ip Version \r
+  //\r
+  IP_VERSION                    IpVersion;\r
 } IP_IO;\r
 \r
 ///\r
@@ -207,11 +261,11 @@ typedef struct _IP_IO {
 /// It is used by IpIoOpen().\r
 ///\r
 typedef struct _IP_IO_OPEN_DATA {\r
-  EFI_IP4_CONFIG_DATA IpConfigData;    ///< Configuration of the IP instance\r
-  VOID                *RcvdContext;    ///< Context data used by receive callback\r
-  VOID                *SndContext;     ///< Context data used by send callback\r
-  PKT_RCVD_NOTIFY     PktRcvdNotify;   ///< Receive callback\r
-  PKT_SENT_NOTIFY     PktSentNotify;   ///< Send callback\r
+  IP_IO_IP_CONFIG_DATA IpConfigData;    ///< Configuration of the IP instance\r
+  VOID                 *RcvdContext;    ///< Context data used by receive callback\r
+  VOID                 *SndContext;     ///< Context data used by send callback\r
+  PKT_RCVD_NOTIFY      PktRcvdNotify;   ///< Receive callback\r
+  PKT_SENT_NOTIFY      PktSentNotify;   ///< Send callback\r
 } IP_IO_OPEN_DATA;\r
 \r
 ///\r
@@ -225,37 +279,41 @@ typedef struct _IP_IO_SEND_ENTRY {
   IP_IO                     *IpIo;\r
   VOID                      *Context;\r
   VOID                      *NotifyData;\r
-  EFI_IP4_PROTOCOL          *Ip;\r
+  VOID                      *Ip;\r
   NET_BUF                   *Pkt;\r
-  EFI_IP4_COMPLETION_TOKEN  *SndToken;\r
+  IP_IO_IP_COMPLETION_TOKEN SndToken;\r
 } IP_IO_SEND_ENTRY;\r
 \r
-typedef EFI_IP4_OVERRIDE_DATA IP_IO_OVERRIDE;\r
-\r
 ///\r
 /// The IP_IO_IP_INFO is used in IpIoSend() to override the default IP instance\r
 /// in IP_IO.\r
 ///\r
 typedef struct _IP_IO_IP_INFO {\r
-  IP4_ADDR                  Addr;\r
-  IP4_ADDR                  SubnetMask;\r
+  EFI_IP_ADDRESS            Addr;\r
+  union {\r
+   IP4_ADDR                 SubnetMask;\r
+   UINT8                    PrefixLength;\r
+  } PreMask;\r
   LIST_ENTRY                Entry;\r
   EFI_HANDLE                ChildHandle;\r
-  EFI_IP4_PROTOCOL          *Ip;\r
-  EFI_IP4_COMPLETION_TOKEN  DummyRcvToken;\r
+  VOID                      *Ip;\r
+  IP_IO_IP_COMPLETION_TOKEN DummyRcvToken;\r
   INTN                      RefCnt;\r
+  IP_VERSION                IpVersion;\r
 } IP_IO_IP_INFO;\r
 \r
 /**\r
   Create a new IP_IO instance.\r
   \r
-  This function uses IP4 service binding protocol in Controller to create an IP4\r
-  child (aka IP4 instance).\r
+  This function uses IP4/IP6 service binding protocol in Controller to create\r
+  an IP4/IP6 child (aka IP4/IP6 instance).\r
 \r
   @param[in]  Image             The image handle of the driver or application that\r
                                 consumes IP_IO.\r
-  @param[in]  Controller        The controller handle that has IP4 service binding\r
-                                protocol installed.\r
+  @param[in]  Controller        The controller handle that has IP4 or IP6 service\r
+                                binding protocol installed.\r
+  @param[in]  IpVersion         The version of the IP protocol to use, either\r
+                                IPv4 or IPv6.                            \r
 \r
   @return Pointer to a newly created IP_IO instance, or NULL if failed.\r
 \r
@@ -264,7 +322,8 @@ IP_IO *
 EFIAPI\r
 IpIoCreate (\r
   IN EFI_HANDLE Image,\r
-  IN EFI_HANDLE Controller\r
+  IN EFI_HANDLE Controller,\r
+  IN IP_VERSION IpVersion\r
   );\r
 \r
 /**\r
@@ -361,7 +420,7 @@ IpIoSend (
   IN     IP_IO_IP_INFO  *Sender        OPTIONAL,\r
   IN     VOID           *Context       OPTIONAL,\r
   IN     VOID           *NotifyData    OPTIONAL,\r
-  IN     IP4_ADDR       Dest,\r
+  IN     EFI_IP_ADDRESS *Dest,\r
   IN     IP_IO_OVERRIDE *OverrideData  OPTIONAL\r
   );\r
 \r
@@ -399,15 +458,15 @@ IpIoAddIp (
   );\r
 \r
 /**\r
-  Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData\r
+  Configure the IP instance of this IpInfo and start the receiving if IpConfigData\r
   is not NULL.\r
 \r
   @param[in, out]  IpInfo          Pointer to the IP_IO_IP_INFO instance.\r
-  @param[in, out]  Ip4ConfigData   The IP4 configure data used to configure the IP\r
-                                   instance. If NULL, the IP instance is reset. If\r
-                                   UseDefaultAddress is set to TRUE, and the configure\r
+  @param[in, out]  IpConfigData    The IP4 or IP6 configure data used to configure \r
+                                   the IP instance. If NULL, the IP instance is reset.\r
+                                   If UseDefaultAddress is set to TRUE, and the configure\r
                                    operation succeeds, the default address information\r
-                                   is written back in this Ip4ConfigData.\r
+                                   is written back in this IpConfigData.\r
 \r
   @retval          EFI_SUCCESS     The IP instance of this IpInfo is configured successfully,\r
                                    or there is no need to reconfigure it.\r
@@ -418,7 +477,7 @@ EFI_STATUS
 EFIAPI\r
 IpIoConfigIp (\r
   IN OUT IP_IO_IP_INFO        *IpInfo,\r
-  IN OUT EFI_IP4_CONFIG_DATA  *Ip4ConfigData OPTIONAL\r
+  IN OUT VOID                 *IpConfigData OPTIONAL\r
   );\r
 \r
 /**\r
@@ -448,6 +507,8 @@ IpIoRemoveIp (
   specified Src. The IpIo was added previously by IpIoAddIp().\r
 \r
   @param[in, out]  IpIo              Pointer to the pointer of the IP_IO instance.\r
+  @param[in]       IpVersion         The version of the IP protocol to use, either\r
+                                     IPv4 or IPv6.\r
   @param[in]       Src               The local IP address.\r
 \r
   @return Pointer to the IP protocol can be used for sending purpose and its local\r
@@ -457,8 +518,9 @@ IpIoRemoveIp (
 IP_IO_IP_INFO *\r
 EFIAPI\r
 IpIoFindSender (\r
-  IN OUT IP_IO     **IpIo,\r
-  IN     IP4_ADDR  Src\r
+  IN OUT IP_IO           **IpIo,\r
+  IN     IP_VERSION      IpVersion,\r
+  IN     EFI_IP_ADDRESS  *Src\r
   );\r
 \r
 /**\r
@@ -468,6 +530,9 @@ IpIoFindSender (
   are not NULL, this routine will fill them.\r
 \r
   @param[in]   IcmpError             IcmpError Type.\r
+  @param[in]   IpVersion             The version of the IP protocol to use,\r
+                                     either IPv4 or IPv6.\r
+  \r
   @param[out]  IsHard                Whether it is a hard error.\r
   @param[out]  Notify                Whether it need to notify SockError.\r
 \r
@@ -478,8 +543,41 @@ EFI_STATUS
 EFIAPI\r
 IpIoGetIcmpErrStatus (\r
   IN  ICMP_ERROR  IcmpError,\r
+  IN  IP_VERSION  IpVersion,\r
   OUT BOOLEAN     *IsHard  OPTIONAL,\r
   OUT BOOLEAN     *Notify  OPTIONAL\r
   );\r
 \r
+/**\r
+  Refresh the remote peer's Neighbor Cache entries.\r
+\r
+  This function is called when the caller needs the IpIo to refresh the existing\r
+  IPv6 neighbor cache entries since the neighbor is considered reachable by the \r
+  node has recently received a confirmation that packets sent recently to the \r
+  neighbor were received by its IP layer. \r
+\r
+  @param[in]   IpIo                  Pointer to an IP_IO instance\r
+  @param[in]   Neighbor              The IP address of the neighbor\r
+  @param[in]   Timeout               Time in 100-ns units that this entry will\r
+                                     remain in the neighbor cache. A value of \r
+                                     zero means that the entry is permanent. \r
+                                     A value of non-zero means that the entry is \r
+                                     dynamic and will be deleted after Timeout.\r
+\r
+  @retval      EFI_SUCCESS           The operation is completed successfully.\r
+  @retval      EFI_NOT_STARTED       The IpIo is not configured.\r
+  @retval      EFI_INVALID_PARAMETER Neighbor Address is invalid.\r
+  @retval      EFI_NOT_FOUND         The neighbor cache entry is not in the \r
+                                     neighbor table.  \r
+  @retval      EFI_OUT_OF_RESOURCES  Failed due to resource limit.\r
+\r
+**/\r
+EFI_STATUS\r
+IpIoRefreshNeighbor (\r
+  IN IP_IO           *IpIo,\r
+  IN EFI_IP_ADDRESS  *Neighbor,\r
+  IN UINT32          Timeout  \r
+  );\r
+\r
 #endif\r
+\r
index 16c45cd749d7fda623c605bd75b5934e5d6a0b84..61102a788b750c048868e09c22bb83a13ea6a61d 100644 (file)
@@ -16,6 +16,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef _NET_LIB_H_\r
 #define _NET_LIB_H_\r
 \r
+#include <Protocol/Ip6.h>\r
+\r
 typedef UINT32          IP4_ADDR;\r
 typedef UINT32          TCP_SEQNO;\r
 typedef UINT16          TCP_PORTNO;\r
@@ -40,6 +42,15 @@ typedef enum {
   IP4_MASK_NUM          = 33\r
 } IP4_CLASS_TYPE;\r
 \r
+typedef enum {\r
+  IP6_HOP_BY_HOP        = 0,\r
+  IP6_DESTINATION       = 60,\r
+  IP6_FRAGMENT          = 44,\r
+  IP6_AH                = 51,\r
+  IP6_ESP               = 50,\r
+  IP6_NO_NEXT_HEADER    = 59\r
+} IP6_EXTENSION_HEADER_TYPE;\r
+\r
 #pragma pack(1)\r
 \r
 //\r
@@ -95,6 +106,22 @@ typedef struct {
   UINT16                Seq;\r
 } IP4_ICMP_QUERY_HEAD;\r
 \r
+typedef struct {\r
+  UINT8                 Type;\r
+  UINT8                 Code;\r
+  UINT16                Checksum;\r
+} IP6_ICMP_HEAD;\r
+\r
+typedef struct {\r
+  IP6_ICMP_HEAD         Head;\r
+  UINT32                Fourth;\r
+  EFI_IP6_HEADER        IpHead;\r
+} IP6_ICMP_ERROR_HEAD;\r
+\r
+typedef struct {\r
+  IP6_ICMP_HEAD         Head;\r
+  UINT32                Fourth;\r
+} IP6_ICMP_INFORMATION_HEAD;\r
 \r
 //\r
 // UDP header definition\r
@@ -104,8 +131,7 @@ typedef struct {
   UINT16                DstPort;\r
   UINT16                Length;\r
   UINT16                Checksum;\r
-} EFI_UDP4_HEADER;\r
-\r
+} EFI_UDP_HEADER;\r
 \r
 //\r
 // TCP header definition\r
@@ -160,6 +186,9 @@ typedef struct {
 #define EFI_NTOHL(EfiIp)         (NTOHL (EFI_IP4 ((EfiIp))))\r
 #define EFI_IP4_EQUAL(Ip1, Ip2)  (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)\r
 \r
+#define EFI_IP6_EQUAL(Ip1, Ip2)  (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv6_ADDRESS)) == 0)\r
+\r
+\r
 /**\r
   Return the length of the mask. \r
   \r
@@ -227,6 +256,25 @@ Ip4IsUnicast (
   IN IP4_ADDR               NetMask\r
   );\r
 \r
+/**\r
+  Check whether the incoming IPv6 address is a valid unicast address.\r
+\r
+  If the address is a multicast address has binary 0xFF at the start, it is not\r
+  a valid unicast address. If the address is unspecified ::, it is not a valid\r
+  unicast address to be assigned to any node. If the address is loopback address\r
+  ::1, it is also not a valid unicast address to be assigned to any physical\r
+  interface. \r
+\r
+  @param[in]  Ip6                   The IPv6 address to check against.\r
+\r
+  @return TRUE if Ip6 is a valid unicast address on the network, otherwise FALSE.\r
+\r
+**/ \r
+BOOLEAN\r
+Ip6IsValidUnicast (\r
+  IN EFI_IPv6_ADDRESS       *Ip6\r
+  );\r
+\r
 extern IP4_ADDR gIp4AllMasks[IP4_MASK_NUM];\r
 \r
 \r
index 0843173a64548b5caede71d3e3caecb8b73fa27f..e18537fd5f0ad42f21b40e1223149c72071c90e2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   IpIo Library.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation.<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -29,7 +29,7 @@ LIST_ENTRY  mActiveIpIoList = {
   &mActiveIpIoList\r
 };\r
 \r
-EFI_IP4_CONFIG_DATA  mIpIoDefaultIpConfigData = {\r
+EFI_IP4_CONFIG_DATA  mIp4IoDefaultIpConfigData = {\r
   EFI_IP_PROTO_UDP,\r
   FALSE,\r
   TRUE,\r
@@ -46,17 +46,44 @@ EFI_IP4_CONFIG_DATA  mIpIoDefaultIpConfigData = {
   0\r
 };\r
 \r
+EFI_IP6_CONFIG_DATA  mIp6IoDefaultIpConfigData = {\r
+  EFI_IP_PROTO_UDP,\r
+  FALSE,\r
+  TRUE,\r
+  FALSE,\r
+  {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},\r
+  {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},\r
+  0,\r
+  255,\r
+  0,\r
+  0,\r
+  0\r
+};\r
+\r
 ICMP_ERROR_INFO  mIcmpErrMap[10] = {\r
-  {FALSE, TRUE},\r
-  {FALSE, TRUE},\r
-  {TRUE, TRUE},\r
-  {TRUE, TRUE},\r
-  {TRUE, TRUE},\r
-  {FALSE, TRUE},\r
-  {FALSE, TRUE},\r
-  {FALSE, TRUE},\r
-  {FALSE, FALSE},\r
-  {FALSE, TRUE}\r
+  { EFI_NETWORK_UNREACHABLE,  FALSE, TRUE  }, // ICMP_ERR_UNREACH_NET\r
+  { EFI_HOST_UNREACHABLE,     FALSE, TRUE  }, // ICMP_ERR_UNREACH_HOST\r
+  { EFI_PROTOCOL_UNREACHABLE, TRUE,  TRUE  }, // ICMP_ERR_UNREACH_PROTOCOL\r
+  { EFI_PORT_UNREACHABLE,     TRUE,  TRUE  }, // ICMP_ERR_UNREACH_PORT\r
+  { EFI_ICMP_ERROR,           TRUE,  TRUE  }, // ICMP_ERR_MSGSIZE\r
+  { EFI_ICMP_ERROR,           FALSE, TRUE  }, // ICMP_ERR_UNREACH_SRCFAIL\r
+  { EFI_HOST_UNREACHABLE,     FALSE, TRUE  }, // ICMP_ERR_TIMXCEED_INTRANS\r
+  { EFI_HOST_UNREACHABLE,     FALSE, TRUE  }, // ICMP_ERR_TIMEXCEED_REASS\r
+  { EFI_ICMP_ERROR,           FALSE, FALSE }, // ICMP_ERR_QUENCH\r
+  { EFI_ICMP_ERROR,           FALSE, TRUE  }  // ICMP_ERR_PARAMPROB\r
+};\r
+\r
+ICMP_ERROR_INFO  mIcmp6ErrMap[10] = {\r
+  { EFI_NETWORK_UNREACHABLE,  FALSE, TRUE  }, // ICMP6_ERR_UNREACH_NET\r
+  { EFI_HOST_UNREACHABLE,     FALSE, TRUE  }, // ICMP6_ERR_UNREACH_HOST\r
+  { EFI_PROTOCOL_UNREACHABLE, TRUE,  TRUE  }, // ICMP6_ERR_UNREACH_PROTOCOL\r
+  { EFI_PORT_UNREACHABLE,     TRUE,  TRUE  }, // ICMP6_ERR_UNREACH_PORT    \r
+  { EFI_ICMP_ERROR,           TRUE,  TRUE  }, // ICMP6_ERR_PACKAGE_TOOBIG\r
+  { EFI_HOST_UNREACHABLE,     FALSE, TRUE  }, // ICMP6_ERR_TIMXCEED_HOPLIMIT\r
+  { EFI_HOST_UNREACHABLE,     FALSE, TRUE  }, // ICMP_ERR_TIMEXCEED_REASS\r
+  { EFI_ICMP_ERROR,           FALSE, TRUE  }, // ICMP_ERR_PARAMPROB_HEADER    \r
+  { EFI_ICMP_ERROR,           FALSE, TRUE  }, // ICMP_ERR_PARAMPROB_NEXHEADER\r
+  { EFI_ICMP_ERROR,           FALSE, TRUE  }  // ICMP_ERR_PARAMPROB_IPV6OPTION\r
 };\r
 \r
 \r
@@ -95,6 +122,8 @@ IpIoTransmitHandler (
   @param[in]    ControllerHandle   The controller handle.\r
   @param[in]    ImageHandle        The image handle.\r
   @param[in]    ChildHandle        Pointer to the buffer to save the IP child handle.\r
+  @param[in]    IpVersion          The version of the IP protocol to use, either\r
+                                   IPv4 or IPv6.\r
   @param[out]   Interface          Pointer used to get the IP protocol interface.\r
 \r
   @retval       EFI_SUCCESS        The IP child is created and the IP protocol\r
@@ -107,10 +136,23 @@ IpIoCreateIpChildOpenProtocol (
   IN  EFI_HANDLE  ControllerHandle,\r
   IN  EFI_HANDLE  ImageHandle,\r
   IN  EFI_HANDLE  *ChildHandle,\r
+  IN  IP_VERSION  IpVersion,  \r
   OUT VOID        **Interface\r
   )\r
 {\r
   EFI_STATUS  Status;\r
+  EFI_GUID    *ServiceBindingGuid;\r
+  EFI_GUID    *IpProtocolGuid;\r
+\r
+  if (IpVersion == IP_VERSION_4) {\r
+    ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;\r
+    IpProtocolGuid     = &gEfiIp4ProtocolGuid;\r
+  } else if (IpVersion == IP_VERSION_6){\r
+    ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;\r
+    IpProtocolGuid     = &gEfiIp6ProtocolGuid;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   //\r
   // Create an IP child.\r
@@ -118,7 +160,7 @@ IpIoCreateIpChildOpenProtocol (
   Status = NetLibCreateServiceChild (\r
              ControllerHandle,\r
              ImageHandle,\r
-             &gEfiIp4ServiceBindingProtocolGuid,\r
+             ServiceBindingGuid,\r
              ChildHandle\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -130,7 +172,7 @@ IpIoCreateIpChildOpenProtocol (
   //\r
   Status = gBS->OpenProtocol (\r
                   *ChildHandle,\r
-                  &gEfiIp4ProtocolGuid,\r
+                  IpProtocolGuid,\r
                   Interface,\r
                   ImageHandle,\r
                   ControllerHandle,\r
@@ -143,7 +185,7 @@ IpIoCreateIpChildOpenProtocol (
     NetLibDestroyServiceChild (\r
       ControllerHandle,\r
       ImageHandle,\r
-      &gEfiIp4ServiceBindingProtocolGuid,\r
+      ServiceBindingGuid,\r
       *ChildHandle\r
       );\r
   }\r
@@ -158,6 +200,8 @@ IpIoCreateIpChildOpenProtocol (
   @param[in]  ControllerHandle    The controller handle.\r
   @param[in]  ImageHandle         The image handle.\r
   @param[in]  ChildHandle         The child handle of the IP child.\r
+  @param[in]  IpVersion           The version of the IP protocol to use, either\r
+                                  IPv4 or IPv6.\r
 \r
   @retval     EFI_SUCCESS         The IP protocol is closed and the relevant IP child\r
                                   is destroyed.\r
@@ -168,17 +212,30 @@ EFI_STATUS
 IpIoCloseProtocolDestroyIpChild (\r
   IN EFI_HANDLE  ControllerHandle,\r
   IN EFI_HANDLE  ImageHandle,\r
-  IN EFI_HANDLE  ChildHandle\r
+  IN EFI_HANDLE  ChildHandle,\r
+  IN IP_VERSION  IpVersion\r
   )\r
 {\r
   EFI_STATUS  Status;\r
+  EFI_GUID    *ServiceBindingGuid;\r
+  EFI_GUID    *IpProtocolGuid;\r
+\r
+  if (IpVersion == IP_VERSION_4) {\r
+    ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;\r
+    IpProtocolGuid     = &gEfiIp4ProtocolGuid;\r
+  } else if (IpVersion == IP_VERSION_6) {\r
+    ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;\r
+    IpProtocolGuid     = &gEfiIp6ProtocolGuid;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   //\r
   // Close the previously openned IP protocol.\r
   //\r
   gBS->CloseProtocol (\r
          ChildHandle,\r
-         &gEfiIp4ProtocolGuid,\r
+         IpProtocolGuid,\r
          ImageHandle,\r
          ControllerHandle\r
          );\r
@@ -189,27 +246,27 @@ IpIoCloseProtocolDestroyIpChild (
   Status = NetLibDestroyServiceChild (\r
              ControllerHandle,\r
              ImageHandle,\r
-             &gEfiIp4ServiceBindingProtocolGuid,\r
+             ServiceBindingGuid,\r
              ChildHandle\r
              );\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
-  This function handles ICMP packets.\r
+  This function handles ICMPv4 packets. It is the worker function of \r
+  IpIoIcmpHandler.\r
 \r
-  @param[in]       IpIo          Pointer to the IP_IO instance.\r
-  @param[in, out]  Pkt           Pointer to the ICMP packet.\r
-  @param[in]       Session       Pointer to the net session of this ICMP packet.\r
+  @param[in]       IpIo            Pointer to the IP_IO instance.\r
+  @param[in, out]  Pkt             Pointer to the ICMPv4 packet.\r
+  @param[in]       Session         Pointer to the net session of this ICMPv4 packet.\r
 \r
-  @retval          EFI_SUCCESS   The ICMP packet is handled successfully.\r
-  @retval          EFI_ABORTED   This type of ICMP packet is not supported.\r
+  @retval          EFI_SUCCESS     The ICMPv4 packet is handled successfully.\r
+  @retval          EFI_ABORTED     This type of ICMPv4 packet is not supported.\r
 \r
 **/\r
 EFI_STATUS\r
-IpIoIcmpHandler (\r
+IpIoIcmpv4Handler (\r
   IN     IP_IO                *IpIo,\r
   IN OUT NET_BUF              *Pkt,\r
   IN     EFI_NET_SESSION_DATA *Session\r
@@ -223,6 +280,8 @@ IpIoIcmpHandler (
   UINT8                Code;\r
   UINT32               TrimBytes;\r
 \r
+  ASSERT (IpIo->IpVersion == IP_VERSION_4);\r
+\r
   IcmpHdr = NET_PROTO_HDR (Pkt, IP4_ICMP_ERROR_HEAD);\r
   IpHdr   = (EFI_IP4_HEADER *) (&IcmpHdr->IpHead);\r
 \r
@@ -320,9 +379,204 @@ IpIoIcmpHandler (
 \r
   IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
 \r
+  return EFI_SUCCESS;  \r
+}\r
+\r
+/**\r
+  This function handles ICMPv6 packets. It is the worker function of \r
+  IpIoIcmpHandler.\r
+\r
+  @param[in]       IpIo            Pointer to the IP_IO instance.\r
+  @param[in, out]  Pkt             Pointer to the ICMPv6 packet.\r
+  @param[in]       Session         Pointer to the net session of this ICMPv6 packet.\r
+\r
+  @retval          EFI_SUCCESS     The ICMPv6 packet is handled successfully.\r
+  @retval          EFI_ABORTED     This type of ICMPv6 packet is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+IpIoIcmpv6Handler (\r
+  IN     IP_IO                *IpIo,\r
+  IN OUT NET_BUF              *Pkt,\r
+  IN     EFI_NET_SESSION_DATA *Session\r
+  )\r
+{\r
+  IP6_ICMP_ERROR_HEAD  *IcmpHdr;\r
+  EFI_IP6_HEADER       *IpHdr;\r
+  ICMP6_ERROR          IcmpErr;\r
+  UINT8                *PayLoadHdr;\r
+  UINT8                Type;\r
+  UINT8                Code;\r
+  UINT8                NextHeader;\r
+  UINT32               TrimBytes;\r
+  BOOLEAN              Flag;\r
+\r
+  ASSERT (IpIo->IpVersion == IP_VERSION_6);\r
+\r
+  //\r
+  // Check the ICMPv6 packet length.\r
+  //\r
+  if (Pkt->TotalSize < sizeof (IP6_ICMP_ERROR_HEAD)) {\r
+\r
+    return EFI_ABORTED;\r
+  }\r
+\r
+  IcmpHdr = NET_PROTO_HDR (Pkt, IP6_ICMP_ERROR_HEAD);\r
+  Type    = IcmpHdr->Head.Type;\r
+  Code    = IcmpHdr->Head.Code;\r
+\r
+  //\r
+  // Analyze the ICMPv6 Error in this ICMPv6 packet\r
+  // \r
+  switch (Type) {\r
+  case ICMP_V6_DEST_UNREACHABLE:\r
+    switch (Code) {\r
+    case ICMP_V6_NO_ROUTE_TO_DEST:\r
+    case ICMP_V6_BEYOND_SCOPE:\r
+    case ICMP_V6_ROUTE_REJECTED:\r
+      IcmpErr = ICMP6_ERR_UNREACH_NET;\r
+\r
+      break;\r
+\r
+    case ICMP_V6_COMM_PROHIBITED:\r
+    case ICMP_V6_ADDR_UNREACHABLE:\r
+    case ICMP_V6_SOURCE_ADDR_FAILED:\r
+      IcmpErr = ICMP6_ERR_UNREACH_HOST;\r
+\r
+      break;\r
+\r
+    case ICMP_V6_PORT_UNREACHABLE:\r
+      IcmpErr = ICMP6_ERR_UNREACH_PORT;\r
+\r
+      break;\r
+\r
+     default:\r
+      return EFI_ABORTED;\r
+    }\r
+\r
+    break;\r
+\r
+  case ICMP_V6_PACKET_TOO_BIG:\r
+    if (Code >= 1) {\r
+      return EFI_ABORTED;\r
+    }\r
+\r
+    IcmpErr = ICMP6_ERR_PACKAGE_TOOBIG;\r
+\r
+    break;\r
+\r
+  case ICMP_V6_TIME_EXCEEDED:\r
+    if (Code > 1) {\r
+      return EFI_ABORTED;\r
+    }\r
+\r
+    IcmpErr = (ICMP6_ERROR) (ICMP6_ERR_TIMXCEED_HOPLIMIT + Code);\r
+\r
+    break;\r
+\r
+  case ICMP_V6_PARAMETER_PROBLEM:\r
+    if (Code > 3) {\r
+      return EFI_ABORTED;\r
+    }\r
+\r
+    IcmpErr = (ICMP6_ERROR) (ICMP6_ERR_PARAMPROB_HEADER + Code);\r
+\r
+    break;\r
+\r
+   default:\r
+\r
+     return EFI_ABORTED;\r
+   } \r
+\r
+  //\r
+  // Notify user the ICMPv6 packet only containing payload except\r
+  // IPv6 basic header, extension header and ICMP header\r
+  //\r
+\r
+  IpHdr      = (EFI_IP6_HEADER *) (&IcmpHdr->IpHead);\r
+  NextHeader = IpHdr->NextHeader;\r
+  PayLoadHdr = (UINT8 *) ((UINT8 *) IcmpHdr + sizeof (IP6_ICMP_ERROR_HEAD));\r
+  Flag       = TRUE;\r
+  \r
+  do {\r
+    switch (NextHeader) {\r
+    case EFI_IP_PROTO_UDP:\r
+    case EFI_IP_PROTO_TCP:\r
+    case EFI_IP_PROTO_ICMP:\r
+    case IP6_NO_NEXT_HEADER:\r
+      Flag = FALSE;\r
+\r
+      break;\r
+\r
+    case IP6_HOP_BY_HOP:\r
+    case IP6_DESTINATION:\r
+      //\r
+      // The Hdr Ext Len is 8-bit unsigned integer in 8-octet units, not including\r
+      // the first 8 octets.\r
+      //\r
+      NextHeader = *(PayLoadHdr);\r
+      PayLoadHdr = (UINT8 *) (PayLoadHdr + (*(PayLoadHdr + 1) + 1) * 8);\r
+\r
+      break;\r
+\r
+    case IP6_FRAGMENT:\r
+      //\r
+      // The Fragment Header Length is 8 octets.\r
+      //\r
+      NextHeader = *(PayLoadHdr);\r
+      PayLoadHdr = (UINT8 *) (PayLoadHdr + 8);\r
+\r
+      break;\r
+\r
+    default:\r
+\r
+      return EFI_ABORTED;\r
+    }\r
+  } while (Flag);\r
+\r
+  TrimBytes = (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr);\r
+  \r
+  NetbufTrim (Pkt, TrimBytes, TRUE);\r
+\r
+  IpIo->PktRcvdNotify (EFI_ICMP_ERROR, (ICMP_ERROR) IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  This function handles ICMP packets.\r
+\r
+  @param[in]       IpIo            Pointer to the IP_IO instance.\r
+  @param[in, out]  Pkt             Pointer to the ICMP packet.\r
+  @param[in]       Session         Pointer to the net session of this ICMP packet.\r
+\r
+  @retval          EFI_SUCCESS     The ICMP packet is handled successfully.\r
+  @retval          EFI_ABORTED     This type of ICMP packet is not supported.\r
+  @retval          EFI_UNSUPPORTED The IP protocol version in IP_IO is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+IpIoIcmpHandler (\r
+  IN     IP_IO                *IpIo,\r
+  IN OUT NET_BUF              *Pkt,\r
+  IN     EFI_NET_SESSION_DATA *Session\r
+  )\r
+{\r
+\r
+  if (IpIo->IpVersion == IP_VERSION_4) {\r
+\r
+    return IpIoIcmpv4Handler (IpIo, Pkt, Session);\r
+\r
+  } else if (IpIo->IpVersion == IP_VERSION_6) {\r
+\r
+    return IpIoIcmpv6Handler (IpIo, Pkt, Session);\r
+\r
+  } else {\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+}\r
+\r
 \r
 /**\r
   Free function for receive token of IP_IO. It is used to\r
@@ -361,19 +615,30 @@ IP_IO_SEND_ENTRY *
 IpIoCreateSndEntry (\r
   IN OUT IP_IO             *IpIo,\r
   IN OUT NET_BUF           *Pkt,\r
-  IN     EFI_IP4_PROTOCOL  *Sender,\r
+  IN     VOID              *Sender,\r
   IN     VOID              *Context    OPTIONAL,\r
   IN     VOID              *NotifyData OPTIONAL,\r
-  IN     IP4_ADDR          Dest,\r
+  IN     EFI_IP_ADDRESS    *Dest       OPTIONAL,\r
   IN     IP_IO_OVERRIDE    *Override\r
   )\r
 {\r
   IP_IO_SEND_ENTRY          *SndEntry;\r
-  EFI_IP4_COMPLETION_TOKEN  *SndToken;\r
-  EFI_IP4_TRANSMIT_DATA     *TxData;\r
+  EFI_EVENT                 Event;  \r
   EFI_STATUS                Status;\r
-  EFI_IP4_OVERRIDE_DATA     *OverrideData;\r
-  volatile UINT32           Index;\r
+  NET_FRAGMENT              *ExtFragment;\r
+  UINT32                    FragmentCount;\r
+  IP_IO_OVERRIDE            *OverrideData;\r
+  IP_IO_IP_TX_DATA          *TxData;\r
+  EFI_IP4_TRANSMIT_DATA     *Ip4TxData;\r
+  EFI_IP6_TRANSMIT_DATA     *Ip6TxData;\r
+\r
+  if ((IpIo->IpVersion != IP_VERSION_4) && (IpIo->IpVersion != IP_VERSION_6)) {\r
+    return NULL;\r
+  }\r
+\r
+  Event        = NULL;\r
+  TxData       = NULL;\r
+  OverrideData = NULL;\r
 \r
   //\r
   // Allocate resource for SndEntry\r
@@ -383,73 +648,95 @@ IpIoCreateSndEntry (
     return NULL;\r
   }\r
 \r
-  //\r
-  // Allocate resource for SndToken\r
-  //\r
-  SndToken = AllocatePool (sizeof (EFI_IP4_COMPLETION_TOKEN));\r
-  if (NULL == SndToken) {\r
-    goto ReleaseSndEntry;\r
-  }\r
-\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL,\r
                   TPL_NOTIFY,\r
                   IpIoTransmitHandler,\r
                   SndEntry,\r
-                  &(SndToken->Event)\r
+                  &Event\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ReleaseSndToken;\r
+    goto ON_ERROR;\r
   }\r
 \r
+  FragmentCount = Pkt->BlockOpNum;\r
+\r
   //\r
   // Allocate resource for TxData\r
   //\r
-  TxData = AllocatePool (\r
-    sizeof (EFI_IP4_TRANSMIT_DATA) +\r
-    sizeof (EFI_IP4_FRAGMENT_DATA) * (Pkt->BlockOpNum - 1)\r
+  TxData = (IP_IO_IP_TX_DATA *) AllocatePool (\r
+    sizeof (IP_IO_IP_TX_DATA) + sizeof (NET_FRAGMENT) * (FragmentCount - 1)\r
     );\r
 \r
   if (NULL == TxData) {\r
-    goto ReleaseEvent;\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  //\r
+  // Build a fragment table to contain the fragments in the packet. \r
+  //\r
+  if (IpIo->IpVersion == IP_VERSION_4) {\r
+    ExtFragment = (NET_FRAGMENT *) TxData->Ip4TxData.FragmentTable;\r
+  } else {\r
+    ExtFragment = (NET_FRAGMENT *) TxData->Ip6TxData.FragmentTable;\r
   }\r
 \r
+  NetbufBuildExt (Pkt, ExtFragment, &FragmentCount);\r
+\r
+\r
   //\r
   // Allocate resource for OverrideData if needed\r
   //\r
-  OverrideData = NULL;\r
   if (NULL != Override) {\r
 \r
-    OverrideData = AllocatePool (sizeof (EFI_IP4_OVERRIDE_DATA));\r
+    OverrideData = AllocateCopyPool (sizeof (IP_IO_OVERRIDE), Override);\r
     if (NULL == OverrideData) {\r
-      goto ReleaseResource;\r
+      goto ON_ERROR;\r
     }\r
-    //\r
-    // Set the fields of OverrideData\r
-    //\r
-    CopyMem (OverrideData, Override, sizeof (*OverrideData));\r
   }\r
 \r
   //\r
-  // Set the fields of TxData\r
+  // Set other fields of TxData except the fragment table\r
   //\r
-  CopyMem (&TxData->DestinationAddress, &Dest, sizeof (EFI_IPv4_ADDRESS));\r
-  TxData->OverrideData                  = OverrideData;\r
-  TxData->OptionsLength                 = 0;\r
-  TxData->OptionsBuffer                 = NULL;\r
-  TxData->TotalDataLength               = Pkt->TotalSize;\r
-  TxData->FragmentCount                 = Pkt->BlockOpNum;\r
+  if (IpIo->IpVersion == IP_VERSION_4) {\r
 \r
+    Ip4TxData = &TxData->Ip4TxData;\r
 \r
-  for (Index = 0; Index < Pkt->BlockOpNum; Index++) {\r
-    TxData->FragmentTable[Index].FragmentBuffer = Pkt->BlockOp[Index].Head;\r
-    TxData->FragmentTable[Index].FragmentLength = Pkt->BlockOp[Index].Size;\r
-  }\r
+    CopyMem (&Ip4TxData->DestinationAddress, Dest, sizeof (EFI_IPv4_ADDRESS));\r
 \r
-  //\r
-  // Set the fields of SndToken\r
-  //\r
-  SndToken->Packet.TxData = TxData;\r
+    Ip4TxData->OverrideData    = &OverrideData->Ip4OverrideData;\r
+    Ip4TxData->OptionsLength   = 0;\r
+    Ip4TxData->OptionsBuffer   = NULL;\r
+    Ip4TxData->TotalDataLength = Pkt->TotalSize;\r
+    Ip4TxData->FragmentCount   = FragmentCount;\r
+\r
+    //\r
+    // Set the fields of SndToken\r
+    //\r
+    SndEntry->SndToken.Ip4Token.Event         = Event;\r
+    SndEntry->SndToken.Ip4Token.Packet.TxData = Ip4TxData;\r
+  } else {\r
+\r
+    Ip6TxData = &TxData->Ip6TxData;\r
+\r
+    if (Dest != NULL) {\r
+      CopyMem (&Ip6TxData->DestinationAddress, Dest, sizeof (EFI_IPv6_ADDRESS));\r
+    } else {\r
+      ZeroMem (&Ip6TxData->DestinationAddress, sizeof (EFI_IPv6_ADDRESS));\r
+    }\r
+\r
+    Ip6TxData->OverrideData  = &OverrideData->Ip6OverrideData;\r
+    Ip6TxData->DataLength    = Pkt->TotalSize;\r
+    Ip6TxData->FragmentCount = FragmentCount;\r
+    Ip6TxData->ExtHdrsLength = 0;\r
+    Ip6TxData->ExtHdrs       = NULL;\r
+    \r
+    //\r
+    // Set the fields of SndToken\r
+    //\r
+    SndEntry->SndToken.Ip6Token.Event         = Event;\r
+    SndEntry->SndToken.Ip6Token.Packet.TxData = Ip6TxData;\r
+  }\r
 \r
   //\r
   // Set the fields of SndEntry\r
@@ -462,23 +749,27 @@ IpIoCreateSndEntry (
   SndEntry->Pkt         = Pkt;\r
   NET_GET_REF (Pkt);\r
 \r
-  SndEntry->SndToken = SndToken;\r
-\r
   InsertTailList (&IpIo->PendingSndList, &SndEntry->Entry);\r
 \r
   return SndEntry;\r
 \r
-ReleaseResource:\r
-  gBS->FreePool (TxData);\r
+ON_ERROR:\r
+\r
+  if (OverrideData != NULL) {\r
+    FreePool (OverrideData);\r
+  }\r
 \r
-ReleaseEvent:\r
-  gBS->CloseEvent (SndToken->Event);\r
+  if (TxData != NULL) {\r
+    FreePool (TxData);\r
+  }\r
 \r
-ReleaseSndToken:\r
-  gBS->FreePool (SndToken);\r
+  if (SndEntry != NULL) {\r
+    FreePool (SndEntry);\r
+  }\r
 \r
-ReleaseSndEntry:\r
-  gBS->FreePool (SndEntry);\r
+  if (Event != NULL) {\r
+    gBS->CloseEvent (Event);\r
+  }\r
 \r
   return NULL;\r
 }\r
@@ -497,22 +788,35 @@ IpIoDestroySndEntry (
   IN IP_IO_SEND_ENTRY  *SndEntry\r
   )\r
 {\r
-  EFI_IP4_TRANSMIT_DATA  *TxData;\r
+  EFI_EVENT         Event;\r
+  IP_IO_IP_TX_DATA  *TxData;\r
+  IP_IO_OVERRIDE    *Override;\r
+\r
+  if (SndEntry->IpIo->IpVersion == IP_VERSION_4) {\r
+    Event              = SndEntry->SndToken.Ip4Token.Event;\r
+    TxData             = (IP_IO_IP_TX_DATA *) SndEntry->SndToken.Ip4Token.Packet.TxData;\r
+    Override           = (IP_IO_OVERRIDE *) TxData->Ip4TxData.OverrideData;\r
+  } else if (SndEntry->IpIo->IpVersion == IP_VERSION_6) {\r
+    Event              = SndEntry->SndToken.Ip6Token.Event;\r
+    TxData             = (IP_IO_IP_TX_DATA *) SndEntry->SndToken.Ip6Token.Packet.TxData;\r
+    Override           = (IP_IO_OVERRIDE *) TxData->Ip6TxData.OverrideData;\r
+  } else {\r
+    return ;\r
+  }\r
 \r
-  TxData = SndEntry->SndToken->Packet.TxData;\r
+  gBS->CloseEvent (Event);\r
 \r
-  if (NULL != TxData->OverrideData) {\r
-    gBS->FreePool (TxData->OverrideData);\r
+  FreePool (TxData);\r
+\r
+  if (NULL != Override) {\r
+    FreePool (Override);\r
   }\r
 \r
-  gBS->FreePool (TxData);\r
   NetbufFree (SndEntry->Pkt);\r
-  gBS->CloseEvent (SndEntry->SndToken->Event);\r
 \r
-  gBS->FreePool (SndEntry->SndToken);\r
   RemoveEntryList (&SndEntry->Entry);\r
 \r
-  gBS->FreePool (SndEntry);\r
+  FreePool (SndEntry);\r
 }\r
 \r
 \r
@@ -530,14 +834,23 @@ IpIoTransmitHandlerDpc (
 {\r
   IP_IO             *IpIo;\r
   IP_IO_SEND_ENTRY  *SndEntry;\r
+  EFI_STATUS        Status;\r
 \r
   SndEntry  = (IP_IO_SEND_ENTRY *) Context;\r
 \r
   IpIo      = SndEntry->IpIo;\r
 \r
+  if (IpIo->IpVersion == IP_VERSION_4) {\r
+    Status = SndEntry->SndToken.Ip4Token.Status;\r
+  } else if (IpIo->IpVersion == IP_VERSION_6){\r
+    Status = SndEntry->SndToken.Ip6Token.Status;\r
+  } else {\r
+    return ;\r
+  }\r
+\r
   if ((IpIo->PktSentNotify != NULL) && (SndEntry->NotifyData != NULL)) {\r
     IpIo->PktSentNotify (\r
-            SndEntry->SndToken->Status,\r
+            Status,\r
             SndEntry->Context,\r
             SndEntry->Ip,\r
             SndEntry->NotifyData\r
@@ -582,23 +895,61 @@ IpIoDummyHandlerDpc (
   )\r
 {\r
   IP_IO_IP_INFO             *IpInfo;\r
-  EFI_IP4_COMPLETION_TOKEN  *DummyToken;\r
+  EFI_STATUS                 Status;\r
+  EFI_EVENT                  RecycleEvent;\r
 \r
   IpInfo      = (IP_IO_IP_INFO *) Context;\r
-  DummyToken  = &(IpInfo->DummyRcvToken);\r
 \r
-  if (EFI_ABORTED == DummyToken->Status) {\r
+  if ((IpInfo->IpVersion != IP_VERSION_4) && (IpInfo->IpVersion != IP_VERSION_6)) {\r
+    return ;\r
+  }\r
+\r
+  RecycleEvent = NULL;\r
+\r
+  if (IpInfo->IpVersion == IP_VERSION_4) {\r
+    Status = IpInfo->DummyRcvToken.Ip4Token.Status;\r
+\r
+    if (IpInfo->DummyRcvToken.Ip4Token.Packet.RxData != NULL) {\r
+      RecycleEvent = IpInfo->DummyRcvToken.Ip4Token.Packet.RxData->RecycleSignal;\r
+    }\r
+  } else {\r
+    Status = IpInfo->DummyRcvToken.Ip6Token.Status;\r
+\r
+    if (IpInfo->DummyRcvToken.Ip6Token.Packet.RxData != NULL) {\r
+      RecycleEvent = IpInfo->DummyRcvToken.Ip6Token.Packet.RxData->RecycleSignal;\r
+    }\r
+  }\r
+\r
+\r
+\r
+  if (EFI_ABORTED == Status) {\r
     //\r
     // The reception is actively aborted by the consumer, directly return.\r
     //\r
     return;\r
-  } else if (EFI_SUCCESS == DummyToken->Status) {\r
-    ASSERT ((DummyToken->Packet.RxData)!= NULL);\r
+  } else if (EFI_SUCCESS == Status) {\r
+    //\r
+    // Recycle the RxData.\r
+    //\r
+    ASSERT (RecycleEvent != NULL);\r
 \r
-    gBS->SignalEvent (DummyToken->Packet.RxData->RecycleSignal);\r
+    gBS->SignalEvent (RecycleEvent);\r
   }\r
 \r
-  IpInfo->Ip->Receive (IpInfo->Ip, DummyToken);\r
+  //\r
+  // Continue the receive.\r
+  //\r
+  if (IpInfo->IpVersion == IP_VERSION_4) {\r
+    ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Receive (\r
+                                           (EFI_IP4_PROTOCOL *) (IpInfo->Ip),\r
+                                           &IpInfo->DummyRcvToken.Ip4Token\r
+                                           );\r
+  } else {\r
+    ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Receive (\r
+                                           (EFI_IP6_PROTOCOL *) (IpInfo->Ip),\r
+                                           &IpInfo->DummyRcvToken.Ip6Token\r
+                                           );\r
+  }\r
 }\r
 \r
 \r
@@ -638,16 +989,23 @@ IpIoListenHandlerDpc (
 {\r
   IP_IO                 *IpIo;\r
   EFI_STATUS            Status;\r
-  EFI_IP4_RECEIVE_DATA  *RxData;\r
-  EFI_IP4_PROTOCOL      *Ip;\r
+  IP_IO_IP_RX_DATA      *RxData;\r
+  VOID                  *Ip;\r
   EFI_NET_SESSION_DATA  Session;\r
   NET_BUF               *Pkt;\r
 \r
-  IpIo    = (IP_IO *) Context;\r
+  IpIo = (IP_IO *) Context;\r
+  Ip   = IpIo->Ip;\r
 \r
-  Ip      = IpIo->Ip;\r
-  Status  = IpIo->RcvToken.Status;\r
-  RxData  = IpIo->RcvToken.Packet.RxData;\r
+  if (IpIo->IpVersion == IP_VERSION_4) {\r
+    Status = IpIo->RcvToken.Ip4Token.Status;\r
+    RxData = (IP_IO_IP_RX_DATA *) IpIo->RcvToken.Ip4Token.Packet.RxData;\r
+  } else if (IpIo->IpVersion == IP_VERSION_6) {\r
+    Status = IpIo->RcvToken.Ip6Token.Status;\r
+    RxData = (IP_IO_IP_RX_DATA *) IpIo->RcvToken.Ip6Token.Packet.RxData;\r
+  } else {\r
+    return;\r
+  }\r
 \r
   if (EFI_ABORTED == Status) {\r
     //\r
@@ -669,8 +1027,9 @@ IpIoListenHandlerDpc (
     goto CleanUp;\r
   }\r
 \r
-  if ((EFI_IP4 (RxData->Header->SourceAddress) != 0) &&\r
-    !Ip4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) {\r
+  if (IpIo->IpVersion == IP_VERSION_4) {\r
+    if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&\r
+      !Ip4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) {\r
     //\r
     // The source address is not zero and it's not a unicast IP address, discard it.\r
     //\r
@@ -678,15 +1037,15 @@ IpIoListenHandlerDpc (
   }\r
 \r
   //\r
-  // Create a netbuffer representing packet\r
+  // Create a netbuffer representing IPv4 packet\r
   //\r
   Pkt = NetbufFromExt (\r
-          (NET_FRAGMENT *) RxData->FragmentTable,\r
-          RxData->FragmentCount,\r
+          (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,\r
+          RxData->Ip4RxData.FragmentCount,\r
           0,\r
           0,\r
           IpIoExtFree,\r
-          RxData->RecycleSignal\r
+          RxData->Ip4RxData.RecycleSignal\r
           );\r
   if (NULL == Pkt) {\r
     goto CleanUp;\r
@@ -695,9 +1054,47 @@ IpIoListenHandlerDpc (
   //\r
   // Create a net session\r
   //\r
-  Session.Source = EFI_IP4 (RxData->Header->SourceAddress);\r
-  Session.Dest   = EFI_IP4 (RxData->Header->DestinationAddress);\r
-  Session.IpHdr  = RxData->Header;\r
+  Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress);\r
+  Session.Dest.Addr[0]   = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress);\r
+  Session.IpHdr.Ip4Hdr   = RxData->Ip4RxData.Header;\r
+  Session.IpVersion      = IP_VERSION_4;\r
+  } else {\r
+\r
+    if (!Ip6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) {\r
+      goto CleanUp;\r
+    }\r
+    \r
+    //\r
+    // Create a netbuffer representing IPv6 packet\r
+    //\r
+    Pkt = NetbufFromExt (\r
+            (NET_FRAGMENT *) RxData->Ip6RxData.FragmentTable,\r
+            RxData->Ip6RxData.FragmentCount,\r
+            0,\r
+            0,\r
+            IpIoExtFree,\r
+            RxData->Ip6RxData.RecycleSignal\r
+            );\r
+    if (NULL == Pkt) {\r
+      goto CleanUp;\r
+    }\r
+\r
+    //\r
+    // Create a net session\r
+    //\r
+    CopyMem (\r
+      &Session.Source, \r
+      &RxData->Ip6RxData.Header->SourceAddress,\r
+      sizeof(EFI_IPv6_ADDRESS)\r
+      );\r
+    CopyMem (\r
+      &Session.Dest, \r
+      &RxData->Ip6RxData.Header->DestinationAddress, \r
+      sizeof(EFI_IPv6_ADDRESS)\r
+      );\r
+    Session.IpHdr.Ip6Hdr = RxData->Ip6RxData.Header;\r
+    Session.IpVersion    = IP_VERSION_6;\r
+  } \r
 \r
   if (EFI_SUCCESS == Status) {\r
 \r
@@ -715,12 +1112,21 @@ IpIoListenHandlerDpc (
   goto Resume;\r
 \r
 CleanUp:\r
-  gBS->SignalEvent (RxData->RecycleSignal);\r
+\r
+  if (IpIo->IpVersion == IP_VERSION_4){\r
+    gBS->SignalEvent (RxData->Ip4RxData.RecycleSignal);\r
+  } else {\r
+    gBS->SignalEvent (RxData->Ip6RxData.RecycleSignal); \r
+  }\r
 \r
 Resume:\r
-  Ip->Receive (Ip, &(IpIo->RcvToken));\r
-}\r
 \r
+  if (IpIo->IpVersion == IP_VERSION_4){\r
+    ((EFI_IP4_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip4Token));\r
+  } else {\r
+    ((EFI_IP6_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip6Token));\r
+  }\r
+}\r
 \r
 /**\r
   This function add IpIoListenHandlerDpc to the end of the DPC queue.\r
@@ -746,13 +1152,15 @@ IpIoListenHandler (
 /**\r
   Create a new IP_IO instance.\r
   \r
-  This function uses IP4 service binding protocol in Controller to create an IP4\r
-  child (aka IP4 instance).\r
+  This function uses IP4/IP6 service binding protocol in Controller to create\r
+  an IP4/IP6 child (aka IP4/IP6 instance).\r
 \r
   @param[in]  Image             The image handle of the driver or application that\r
                                 consumes IP_IO.\r
-  @param[in]  Controller        The controller handle that has IP4 service binding\r
-                                protocol installed.\r
+  @param[in]  Controller        The controller handle that has IP4 or IP6 service\r
+                                binding protocol installed.\r
+  @param[in]  IpVersion         The version of the IP protocol to use, either\r
+                                IPv4 or IPv6.                            \r
 \r
   @return Pointer to a newly created IP_IO instance, or NULL if failed.\r
 \r
@@ -761,11 +1169,15 @@ IP_IO *
 EFIAPI\r
 IpIoCreate (\r
   IN EFI_HANDLE Image,\r
-  IN EFI_HANDLE Controller\r
+  IN EFI_HANDLE Controller,\r
+  IN IP_VERSION IpVersion  \r
   )\r
 {\r
   EFI_STATUS  Status;\r
   IP_IO       *IpIo;\r
+  EFI_EVENT   Event;\r
+\r
+  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));\r
 \r
   IpIo = AllocateZeroPool (sizeof (IP_IO));\r
   if (NULL == IpIo) {\r
@@ -776,18 +1188,26 @@ IpIoCreate (
   InitializeListHead (&(IpIo->IpList));\r
   IpIo->Controller  = Controller;\r
   IpIo->Image       = Image;\r
+  IpIo->IpVersion   = IpVersion;\r
+  Event             = NULL;\r
 \r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL,\r
                   TPL_NOTIFY,\r
                   IpIoListenHandler,\r
                   IpIo,\r
-                  &(IpIo->RcvToken.Event)\r
+                  &Event\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     goto ReleaseIpIo;\r
   }\r
 \r
+  if (IpVersion == IP_VERSION_4) {\r
+    IpIo->RcvToken.Ip4Token.Event = Event;\r
+  } else {\r
+    IpIo->RcvToken.Ip6Token.Event = Event;\r
+  }\r
+\r
   //\r
   // Create an IP child and open IP protocol\r
   //\r
@@ -795,6 +1215,7 @@ IpIoCreate (
              Controller,\r
              Image,\r
              &IpIo->ChildHandle,\r
+             IpVersion,             \r
              (VOID **)&(IpIo->Ip)\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -805,8 +1226,8 @@ IpIoCreate (
 \r
 ReleaseIpIo:\r
 \r
-  if (NULL != IpIo->RcvToken.Event) {\r
-    gBS->CloseEvent (IpIo->RcvToken.Event);\r
+  if (Event != NULL) {\r
+    gBS->CloseEvent (Event);\r
   }\r
 \r
   gBS->FreePool (IpIo);\r
@@ -842,18 +1263,35 @@ IpIoOpen (
   )\r
 {\r
   EFI_STATUS        Status;\r
-  EFI_IP4_PROTOCOL  *Ip;\r
+  VOID              *Ip;\r
+  IP_VERSION        IpVersion;\r
 \r
   if (IpIo->IsConfigured) {\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
+  IpVersion = IpIo->IpVersion;\r
+\r
+  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));\r
+\r
   Ip = IpIo->Ip;\r
 \r
   //\r
   // configure ip\r
   //\r
-  Status = Ip->Configure (Ip, &OpenData->IpConfigData);\r
+  if (IpVersion == IP_VERSION_4){\r
+    Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure (\r
+                                          (EFI_IP4_PROTOCOL *) Ip,\r
+                                          &OpenData->IpConfigData.Ip4CfgData\r
+                                          );\r
+  } else {\r
+\r
+    Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure (\r
+                                          (EFI_IP6_PROTOCOL *) Ip, \r
+                                          &OpenData->IpConfigData.Ip6CfgData\r
+                                          );\r
+  }\r
+\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -863,10 +1301,18 @@ IpIoOpen (
   // @bug (0.0.0.0, 0.0.0.0, 0.0.0.0). Delete this statement if Ip modified\r
   // @bug its code\r
   //\r
-  Status = Ip->Routes (Ip, TRUE, &mZeroIp4Addr, &mZeroIp4Addr, &mZeroIp4Addr);\r
-\r
-  if (EFI_ERROR (Status) && (EFI_NOT_FOUND != Status)) {\r
-    return Status;\r
+  if (IpVersion == IP_VERSION_4){\r
+    Status = ((EFI_IP4_PROTOCOL *) Ip)->Routes (\r
+                                          (EFI_IP4_PROTOCOL *) Ip,\r
+                                          TRUE,\r
+                                          &mZeroIp4Addr,\r
+                                          &mZeroIp4Addr,\r
+                                          &mZeroIp4Addr\r
+                                          );\r
+\r
+    if (EFI_ERROR (Status) && (EFI_NOT_FOUND != Status)) {\r
+      return Status;\r
+    }\r
   }\r
 \r
   IpIo->PktRcvdNotify = OpenData->PktRcvdNotify;\r
@@ -875,15 +1321,32 @@ IpIoOpen (
   IpIo->RcvdContext   = OpenData->RcvdContext;\r
   IpIo->SndContext    = OpenData->SndContext;\r
 \r
-  IpIo->Protocol      = OpenData->IpConfigData.DefaultProtocol;\r
+  if (IpVersion == IP_VERSION_4){\r
+    IpIo->Protocol = OpenData->IpConfigData.Ip4CfgData.DefaultProtocol;\r
 \r
-  //\r
-  // start to listen incoming packet\r
-  //\r
-  Status = Ip->Receive (Ip, &(IpIo->RcvToken));\r
-  if (EFI_ERROR (Status)) {\r
-    Ip->Configure (Ip, NULL);\r
-    goto ErrorExit;\r
+    //\r
+    // start to listen incoming packet\r
+    //\r
+    Status = ((EFI_IP4_PROTOCOL *) Ip)->Receive (\r
+                                          (EFI_IP4_PROTOCOL *) Ip,\r
+                                          &(IpIo->RcvToken.Ip4Token)\r
+                                          );\r
+    if (EFI_ERROR (Status)) {\r
+      ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL);\r
+      goto ErrorExit;\r
+    }\r
+\r
+  } else {\r
+\r
+    IpIo->Protocol = OpenData->IpConfigData.Ip6CfgData.DefaultProtocol;\r
+    Status = ((EFI_IP6_PROTOCOL *) Ip)->Receive (\r
+                                          (EFI_IP6_PROTOCOL *) Ip,\r
+                                          &(IpIo->RcvToken.Ip6Token)\r
+                                          );\r
+    if (EFI_ERROR (Status)) {\r
+      ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);\r
+      goto ErrorExit;\r
+    }\r
   }\r
 \r
   IpIo->IsConfigured = TRUE;\r
@@ -914,13 +1377,18 @@ IpIoStop (
   )\r
 {\r
   EFI_STATUS        Status;\r
-  EFI_IP4_PROTOCOL  *Ip;\r
+  VOID              *Ip;\r
   IP_IO_IP_INFO     *IpInfo;\r
+  IP_VERSION        IpVersion;\r
 \r
   if (!IpIo->IsConfigured) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  IpVersion = IpIo->IpVersion;\r
+\r
+  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));\r
+\r
   //\r
   // Remove the IpIo from the active IpIo list.\r
   //\r
@@ -931,7 +1399,11 @@ IpIoStop (
   //\r
   // Configure NULL Ip\r
   //\r
-  Status = Ip->Configure (Ip, NULL);\r
+  if (IpVersion == IP_VERSION_4) {\r
+    Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL);\r
+  } else {\r
+    Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);\r
+  }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -956,7 +1428,11 @@ IpIoStop (
   //\r
   // Close the receive event.\r
   //\r
-  gBS->CloseEvent (IpIo->RcvToken.Event);\r
+  if (IpVersion == IP_VERSION_4){\r
+    gBS->CloseEvent (IpIo->RcvToken.Ip4Token.Event);\r
+  } else {\r
+    gBS->CloseEvent (IpIo->RcvToken.Ip6Token.Event);\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -989,7 +1465,12 @@ IpIoDestroy (
   //\r
   // Close the IP protocol and destroy the child.\r
   //\r
-  IpIoCloseProtocolDestroyIpChild (IpIo->Controller, IpIo->Image, IpIo->ChildHandle);\r
+  IpIoCloseProtocolDestroyIpChild (\r
+    IpIo->Controller,\r
+    IpIo->Image,\r
+    IpIo->ChildHandle,\r
+    IpIo->IpVersion\r
+    );\r
 \r
   gBS->FreePool (IpIo);\r
 \r
@@ -1028,14 +1509,16 @@ IpIoSend (
   IN     IP_IO_IP_INFO  *Sender        OPTIONAL,\r
   IN     VOID           *Context       OPTIONAL,\r
   IN     VOID           *NotifyData    OPTIONAL,\r
-  IN     IP4_ADDR       Dest,\r
+  IN     EFI_IP_ADDRESS *Dest,\r
   IN     IP_IO_OVERRIDE *OverrideData  OPTIONAL\r
   )\r
 {\r
   EFI_STATUS        Status;\r
-  EFI_IP4_PROTOCOL  *Ip;\r
+  VOID              *Ip;\r
   IP_IO_SEND_ENTRY  *SndEntry;\r
 \r
+  ASSERT ((IpIo->IpVersion != IP_VERSION_4) || (Dest != NULL));\r
+\r
   if (!IpIo->IsConfigured) {\r
     return EFI_NOT_STARTED;\r
   }\r
@@ -1053,7 +1536,18 @@ IpIoSend (
   //\r
   // Send this Packet\r
   //\r
-  Status = Ip->Transmit (Ip, SndEntry->SndToken);\r
+  if (IpIo->IpVersion == IP_VERSION_4){\r
+    Status = ((EFI_IP4_PROTOCOL *) Ip)->Transmit (\r
+                                          (EFI_IP4_PROTOCOL *) Ip,\r
+                                          &SndEntry->SndToken.Ip4Token\r
+                                          );\r
+  } else {\r
+    Status = ((EFI_IP6_PROTOCOL *) Ip)->Transmit (\r
+                                          (EFI_IP6_PROTOCOL *) Ip,\r
+                                          &SndEntry->SndToken.Ip6Token\r
+                                          );\r
+  }\r
+\r
   if (EFI_ERROR (Status)) {\r
     IpIoDestroySndEntry (SndEntry);\r
   }\r
@@ -1078,9 +1572,9 @@ IpIoCancelTxToken (
 {\r
   LIST_ENTRY        *Node;\r
   IP_IO_SEND_ENTRY  *SndEntry;\r
-  EFI_IP4_PROTOCOL  *Ip;\r
+  VOID              *Ip;\r
 \r
-  ASSERT ((IpIo)!= NULL && (Packet)!= NULL);\r
+  ASSERT ((IpIo != NULL) && (Packet != NULL));\r
 \r
   NET_LIST_FOR_EACH (Node, &IpIo->PendingSndList) {\r
 \r
@@ -1089,7 +1583,18 @@ IpIoCancelTxToken (
     if (SndEntry->Pkt == Packet) {\r
 \r
       Ip = SndEntry->Ip;\r
-      Ip->Cancel (Ip, SndEntry->SndToken);\r
+\r
+      if (IpIo->IpVersion == IP_VERSION_4) {\r
+        ((EFI_IP4_PROTOCOL *) Ip)->Cancel (\r
+                                     (EFI_IP4_PROTOCOL *) Ip,\r
+                                     &SndEntry->SndToken.Ip4Token\r
+                                     );\r
+      } else {\r
+        ((EFI_IP6_PROTOCOL *) Ip)->Cancel (\r
+                                     (EFI_IP6_PROTOCOL *) Ip,\r
+                                     &SndEntry->SndToken.Ip6Token\r
+                                     );\r
+      }\r
 \r
       break;\r
     }\r
@@ -1119,12 +1624,13 @@ IpIoAddIp (
 {\r
   EFI_STATUS     Status;\r
   IP_IO_IP_INFO  *IpInfo;\r
+  EFI_EVENT      Event;\r
 \r
   ASSERT (IpIo != NULL);\r
 \r
   IpInfo = AllocatePool (sizeof (IP_IO_IP_INFO));\r
   if (IpInfo == NULL) {\r
-    return IpInfo;\r
+    return NULL;\r
   }\r
 \r
   //\r
@@ -1133,17 +1639,20 @@ IpIoAddIp (
   //\r
   InitializeListHead (&IpInfo->Entry);\r
   IpInfo->ChildHandle = NULL;\r
-  IpInfo->Addr        = 0;\r
-  IpInfo->SubnetMask  = 0;\r
-  IpInfo->RefCnt      = 1;\r
+  ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr));\r
+  ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask));\r
+\r
+  IpInfo->RefCnt    = 1;\r
+  IpInfo->IpVersion = IpIo->IpVersion;\r
 \r
   //\r
-  // Create the IP instance and open the Ip4 protocol.\r
+  // Create the IP instance and open the IP protocol.\r
   //\r
   Status = IpIoCreateIpChildOpenProtocol (\r
              IpIo->Controller,\r
              IpIo->Image,\r
              &IpInfo->ChildHandle,\r
+             IpInfo->IpVersion,\r
              (VOID **) &IpInfo->Ip\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -1158,12 +1667,18 @@ IpIoAddIp (
                   TPL_NOTIFY,\r
                   IpIoDummyHandler,\r
                   IpInfo,\r
-                  &IpInfo->DummyRcvToken.Event\r
+                  &Event\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     goto ReleaseIpChild;\r
   }\r
 \r
+  if (IpInfo->IpVersion == IP_VERSION_4) {\r
+    IpInfo->DummyRcvToken.Ip4Token.Event = Event;\r
+  } else {\r
+    IpInfo->DummyRcvToken.Ip6Token.Event = Event;\r
+  }\r
+\r
   //\r
   // Link this IpInfo into the IpIo.\r
   //\r
@@ -1176,7 +1691,8 @@ ReleaseIpChild:
   IpIoCloseProtocolDestroyIpChild (\r
     IpIo->Controller,\r
     IpIo->Image,\r
-    IpInfo->ChildHandle\r
+    IpInfo->ChildHandle,\r
+    IpInfo->IpVersion\r
     );\r
 \r
 ReleaseIpInfo:\r
@@ -1188,15 +1704,15 @@ ReleaseIpInfo:
 \r
 \r
 /**\r
-  Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData\r
+  Configure the IP instance of this IpInfo and start the receiving if IpConfigData\r
   is not NULL.\r
 \r
   @param[in, out]  IpInfo          Pointer to the IP_IO_IP_INFO instance.\r
-  @param[in, out]  Ip4ConfigData   The IP4 configure data used to configure the IP\r
+  @param[in, out]  IpConfigData    The IP configure data used to configure the IP\r
                                    instance, if NULL the IP instance is reset. If\r
                                    UseDefaultAddress is set to TRUE, and the configure\r
                                    operation succeeds, the default address information\r
-                                   is written back in this Ip4ConfigData.\r
+                                   is written back in this IpConfigData.\r
 \r
   @retval          EFI_SUCCESS     The IP instance of this IpInfo is configured successfully\r
                                    or no need to reconfigure it.\r
@@ -1207,12 +1723,14 @@ EFI_STATUS
 EFIAPI\r
 IpIoConfigIp (\r
   IN OUT IP_IO_IP_INFO        *IpInfo,\r
-  IN OUT EFI_IP4_CONFIG_DATA  *Ip4ConfigData OPTIONAL\r
+  IN OUT VOID                 *IpConfigData OPTIONAL\r
   )\r
 {\r
   EFI_STATUS         Status;\r
-  EFI_IP4_PROTOCOL   *Ip;\r
+  VOID               *Ip;\r
+  IP_VERSION         IpVersion;\r
   EFI_IP4_MODE_DATA  Ip4ModeData;\r
+  EFI_IP6_MODE_DATA  Ip6ModeData;\r
 \r
   ASSERT (IpInfo != NULL);\r
 \r
@@ -1220,42 +1738,125 @@ IpIoConfigIp (
     //\r
     // This IP instance is shared, don't reconfigure it until it has only one\r
     // consumer. Currently, only the tcp children cloned from their passive parent\r
-    // will share the same IP. So this cases only happens while Ip4ConfigData is NULL,\r
+    // will share the same IP. So this cases only happens while IpConfigData is NULL,\r
     // let the last consumer clean the IP instance.\r
     //\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  IpVersion = IpInfo->IpVersion;\r
+  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));\r
+\r
   Ip = IpInfo->Ip;\r
 \r
-  Status = Ip->Configure (Ip, Ip4ConfigData);\r
+  if (IpInfo->IpVersion == IP_VERSION_4) {\r
+    Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, IpConfigData);\r
+  } else {\r
+    Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, IpConfigData);\r
+  }\r
+\r
   if (EFI_ERROR (Status)) {\r
     goto OnExit;\r
   }\r
 \r
-  if (Ip4ConfigData != NULL) {\r
+  if (IpConfigData != NULL) {\r
+    if (IpInfo->IpVersion == IP_VERSION_4){\r
 \r
-    if (Ip4ConfigData->UseDefaultAddress) {\r
-      Ip->GetModeData (Ip, &Ip4ModeData, NULL, NULL);\r
+      if (((EFI_IP4_CONFIG_DATA *) IpConfigData)->UseDefaultAddress) {\r
+        ((EFI_IP4_PROTOCOL *) Ip)->GetModeData (\r
+                                     (EFI_IP4_PROTOCOL *) Ip, \r
+                                     &Ip4ModeData, \r
+                                     NULL, \r
+                                     NULL\r
+                                     );\r
 \r
-      Ip4ConfigData->StationAddress = Ip4ModeData.ConfigData.StationAddress;\r
-      Ip4ConfigData->SubnetMask     = Ip4ModeData.ConfigData.SubnetMask;\r
+        ((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress = Ip4ModeData.ConfigData.StationAddress;\r
+        ((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask     = Ip4ModeData.ConfigData.SubnetMask;\r
     }\r
 \r
-    CopyMem (&IpInfo->Addr, &Ip4ConfigData->StationAddress, sizeof (IP4_ADDR));\r
-    CopyMem (&IpInfo->SubnetMask, &Ip4ConfigData->SubnetMask, sizeof (IP4_ADDR));\r
-\r
-    Status = Ip->Receive (Ip, &IpInfo->DummyRcvToken);\r
+      CopyMem (\r
+        &IpInfo->Addr.Addr, \r
+        &((EFI_IP4_CONFIG_DATA *) IpConfigData)->StationAddress, \r
+        sizeof (IP4_ADDR)\r
+        );\r
+      CopyMem (\r
+        &IpInfo->PreMask.SubnetMask, \r
+        &((EFI_IP4_CONFIG_DATA *) IpConfigData)->SubnetMask,\r
+        sizeof (IP4_ADDR)\r
+        );\r
+\r
+      Status = ((EFI_IP4_PROTOCOL *) Ip)->Receive (\r
+                                            (EFI_IP4_PROTOCOL *) Ip,\r
+                                            &IpInfo->DummyRcvToken.Ip4Token\r
+                                            );\r
     if (EFI_ERROR (Status)) {\r
-      Ip->Configure (Ip, NULL);\r
+        ((EFI_IP4_PROTOCOL*)Ip)->Configure (Ip, NULL);\r
     }\r
   } else {\r
 \r
+      ((EFI_IP6_PROTOCOL *) Ip)->GetModeData (\r
+                                   (EFI_IP6_PROTOCOL *) Ip,\r
+                                   &Ip6ModeData,\r
+                                   NULL,\r
+                                   NULL\r
+                                   );\r
+\r
+      if (Ip6ModeData.IsConfigured) {\r
+        CopyMem (\r
+          &((EFI_IP6_CONFIG_DATA *) IpConfigData)->StationAddress,\r
+          &Ip6ModeData.ConfigData.StationAddress,\r
+          sizeof (EFI_IPv6_ADDRESS)\r
+          );\r
+\r
+        if (Ip6ModeData.AddressList != NULL) {\r
+          FreePool (Ip6ModeData.AddressList);\r
+        }\r
+\r
+        if (Ip6ModeData.GroupTable != NULL) {\r
+          FreePool (Ip6ModeData.GroupTable);\r
+        }\r
+\r
+        if (Ip6ModeData.RouteTable != NULL) {\r
+          FreePool (Ip6ModeData.RouteTable);\r
+        }\r
+\r
+        if (Ip6ModeData.NeighborCache != NULL) {\r
+          FreePool (Ip6ModeData.NeighborCache);\r
+        }\r
+\r
+        if (Ip6ModeData.PrefixTable != NULL) {\r
+          FreePool (Ip6ModeData.PrefixTable);\r
+        }\r
+\r
+        if (Ip6ModeData.IcmpTypeList != NULL) {\r
+          FreePool (Ip6ModeData.IcmpTypeList);\r
+        }\r
+\r
+      } else {\r
+        Status = EFI_NO_MAPPING;\r
+        goto OnExit;\r
+      } \r
+\r
+      CopyMem (\r
+        &IpInfo->Addr, \r
+        &Ip6ModeData.ConfigData.StationAddress, \r
+        sizeof (EFI_IPv6_ADDRESS)\r
+        );\r
+\r
+      Status = ((EFI_IP6_PROTOCOL *) Ip)->Receive (\r
+                                            (EFI_IP6_PROTOCOL *) Ip,\r
+                                            &IpInfo->DummyRcvToken.Ip6Token\r
+                                            );\r
+      if (EFI_ERROR (Status)) {\r
+        ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);\r
+      }\r
+    }  \r
+  } else {\r
     //\r
-    // The IP instance is reseted, set the stored Addr and SubnetMask to zero.\r
+    // The IP instance is reset, set the stored Addr and SubnetMask to zero.\r
     //\r
-    IpInfo->Addr       = 0;\r
-    IpInfo->SubnetMask =0;\r
+    ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr));\r
+    ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask));\r
   }\r
 \r
 OnExit:\r
@@ -1283,6 +1884,9 @@ IpIoRemoveIp (
   IN IP_IO_IP_INFO    *IpInfo\r
   )\r
 {\r
+\r
+  IP_VERSION          IpVersion;\r
+\r
   ASSERT (IpInfo->RefCnt > 0);\r
 \r
   NET_PUT_REF (IpInfo);\r
@@ -1292,37 +1896,69 @@ IpIoRemoveIp (
     return;\r
   }\r
 \r
+  IpVersion = IpIo->IpVersion;\r
+\r
+  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));\r
+\r
   RemoveEntryList (&IpInfo->Entry);\r
 \r
-  IpInfo->Ip->Configure (IpInfo->Ip, NULL);\r
+  if (IpVersion == IP_VERSION_4){\r
+    ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Configure (\r
+                                           (EFI_IP4_PROTOCOL *) (IpInfo->Ip),\r
+                                           NULL\r
+                                           );\r
+    IpIoCloseProtocolDestroyIpChild (\r
+      IpIo->Controller,\r
+      IpIo->Image,\r
+      IpInfo->ChildHandle,\r
+      IP_VERSION_4\r
+      );\r
+\r
+    gBS->CloseEvent (IpInfo->DummyRcvToken.Ip4Token.Event);\r
 \r
-  IpIoCloseProtocolDestroyIpChild (IpIo->Controller, IpIo->Image, IpInfo->ChildHandle);\r
+  } else {\r
 \r
-  gBS->CloseEvent (IpInfo->DummyRcvToken.Event);\r
+    ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Configure (\r
+                                           (EFI_IP6_PROTOCOL *) (IpInfo->Ip),\r
+                                           NULL\r
+                                           );\r
 \r
-  gBS->FreePool (IpInfo);\r
+    IpIoCloseProtocolDestroyIpChild (\r
+      IpIo->Controller,\r
+      IpIo->Image,\r
+      IpInfo->ChildHandle,\r
+      IP_VERSION_6\r
+      );\r
+\r
+    gBS->CloseEvent (IpInfo->DummyRcvToken.Ip6Token.Event);\r
+  }\r
+\r
+  FreePool (IpInfo);\r
 }\r
 \r
 \r
 /**\r
   Find the first IP protocol maintained in IpIo whose local\r
-  address is the same with Src.\r
+  address is the same as Src.\r
   \r
   This function is called when the caller needs the IpIo to send data to the\r
   specified Src. The IpIo was added previously by IpIoAddIp().\r
 \r
   @param[in, out]  IpIo              Pointer to the pointer of the IP_IO instance.\r
+  @param[in]       IpVersion         The version of the IP protocol to use, either\r
+                                     IPv4 or IPv6.\r
   @param[in]       Src               The local IP address.\r
 \r
   @return Pointer to the IP protocol can be used for sending purpose and its local\r
-  @return address is the same with Src.\r
+          address is the same with Src.\r
 \r
 **/\r
 IP_IO_IP_INFO *\r
 EFIAPI\r
 IpIoFindSender (\r
-  IN OUT IP_IO     **IpIo,\r
-  IN     IP4_ADDR  Src\r
+  IN OUT IP_IO           **IpIo,\r
+  IN     IP_VERSION      IpVersion,\r
+  IN     EFI_IP_ADDRESS  *Src\r
   )\r
 {\r
   LIST_ENTRY      *IpIoEntry;\r
@@ -1330,20 +1966,32 @@ IpIoFindSender (
   LIST_ENTRY      *IpInfoEntry;\r
   IP_IO_IP_INFO   *IpInfo;\r
 \r
+  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));  \r
+\r
   NET_LIST_FOR_EACH (IpIoEntry, &mActiveIpIoList) {\r
     IpIoPtr = NET_LIST_USER_STRUCT (IpIoEntry, IP_IO, Entry);\r
 \r
-    if ((*IpIo != NULL) && (*IpIo != IpIoPtr)) {\r
+    if (((*IpIo != NULL) && (*IpIo != IpIoPtr)) || (IpIoPtr->IpVersion != IpVersion)) {\r
       continue;\r
     }\r
 \r
     NET_LIST_FOR_EACH (IpInfoEntry, &IpIoPtr->IpList) {\r
       IpInfo = NET_LIST_USER_STRUCT (IpInfoEntry, IP_IO_IP_INFO, Entry);\r
+      if (IpInfo->IpVersion == IP_VERSION_4){\r
+\r
+        if (EFI_IP4_EQUAL (&IpInfo->Addr.v4, &Src->v4)) {\r
+          *IpIo = IpIoPtr;\r
+          return IpInfo;\r
+        }\r
+\r
+      } else {\r
+\r
+        if (EFI_IP6_EQUAL (&IpInfo->Addr.v6, &Src->v6)) {\r
+          *IpIo = IpIoPtr;\r
+          return IpInfo;       \r
+        }\r
+      }      \r
 \r
-      if (IpInfo->Addr == Src) {\r
-        *IpIo = IpIoPtr;\r
-        return IpInfo;\r
-      }\r
     }\r
   }\r
 \r
@@ -1361,6 +2009,9 @@ IpIoFindSender (
   are not NULL, this routine will fill them.\r
 \r
   @param[in]   IcmpError             IcmpError Type.\r
+  @param[in]   IpVersion             The version of the IP protocol to use,\r
+                                     either IPv4 or IPv6.\r
+  \r
   @param[out]  IsHard                Whether it is a hard error.\r
   @param[out]  Notify                Whether it need to notify SockError.\r
 \r
@@ -1371,10 +2022,12 @@ EFI_STATUS
 EFIAPI\r
 IpIoGetIcmpErrStatus (\r
   IN  ICMP_ERROR  IcmpError,\r
+  IN  IP_VERSION  IpVersion,\r
   OUT BOOLEAN     *IsHard  OPTIONAL,\r
   OUT BOOLEAN     *Notify  OPTIONAL\r
   )\r
 {\r
+  if (IpVersion == IP_VERSION_4 ){\r
   ASSERT ((IcmpError >= ICMP_ERR_UNREACH_NET) && (IcmpError <= ICMP_ERR_PARAMPROB));\r
 \r
   if (IsHard != NULL) {\r
@@ -1385,32 +2038,69 @@ IpIoGetIcmpErrStatus (
     *Notify = mIcmpErrMap[IcmpError].Notify;\r
   }\r
 \r
-  switch (IcmpError) {\r
-  case ICMP_ERR_UNREACH_NET:\r
-    return  EFI_NETWORK_UNREACHABLE;\r
+    return mIcmpErrMap[IcmpError].Error;\r
+  } else if (IpVersion == IP_VERSION_6) {\r
+\r
+    ASSERT ((IcmpError >= ICMP6_ERR_UNREACH_NET) && (IcmpError <= ICMP6_ERR_PARAMPROB_IPV6OPTION));\r
 \r
-  case ICMP_ERR_TIMXCEED_INTRANS:\r
-  case ICMP_ERR_TIMXCEED_REASS:\r
-  case ICMP_ERR_UNREACH_HOST:\r
-    return  EFI_HOST_UNREACHABLE;\r
+    if (IsHard != NULL) {\r
+      *IsHard = mIcmp6ErrMap[IcmpError].IsHard;\r
+    }\r
+\r
+    if (Notify != NULL) {\r
+      *Notify = mIcmp6ErrMap[IcmpError].Notify;\r
+    }\r
+    return mIcmp6ErrMap[IcmpError].Error;\r
+\r
+  } else {\r
+    //\r
+    // Should never be here\r
+    //\r
+    ASSERT (FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+}\r
 \r
-  case ICMP_ERR_UNREACH_PROTOCOL:\r
-    return  EFI_PROTOCOL_UNREACHABLE;\r
 \r
-  case ICMP_ERR_UNREACH_PORT:\r
-    return  EFI_PORT_UNREACHABLE;\r
+/**\r
+  Refresh the remote peer's Neighbor Cache entries.\r
+\r
+  This function is called when the caller needs the IpIo to refresh the existing\r
+  IPv6 neighbor cache entries since the neighbor is considered reachable by the \r
+  node has recently received a confirmation that packets sent recently to the \r
+  neighbor were received by its IP layer. \r
+\r
+  @param[in]   IpIo                  Pointer to an IP_IO instance\r
+  @param[in]   Neighbor              The IP address of the neighbor\r
+  @param[in]   Timeout               Time in 100-ns units that this entry will\r
+                                     remain in the neighbor cache. A value of \r
+                                     zero means that the entry is permanent. \r
+                                     A value of non-zero means that the entry is \r
+                                     dynamic and will be deleted after Timeout.\r
+\r
+  @retval      EFI_SUCCESS           The operation is completed successfully.\r
+  @retval      EFI_NOT_STARTED       The IpIo is not configured.\r
+  @retval      EFI_INVALID_PARAMETER Neighbor Address is invalid.\r
+  @retval      EFI_NOT_FOUND         The neighbor cache entry is not in the \r
+                                     neighbor table.  \r
+  @retval      EFI_OUT_OF_RESOURCES  Failed due to resource limit.\r
 \r
-  case ICMP_ERR_MSGSIZE:\r
-  case ICMP_ERR_UNREACH_SRCFAIL:\r
-  case ICMP_ERR_QUENCH:\r
-  case ICMP_ERR_PARAMPROB:\r
-    return  EFI_ICMP_ERROR;\r
+**/\r
+EFI_STATUS\r
+IpIoRefreshNeighbor (\r
+  IN IP_IO           *IpIo,\r
+  IN EFI_IP_ADDRESS  *Neighbor,\r
+  IN UINT32          Timeout  \r
+  )\r
+{\r
+  EFI_IP6_PROTOCOL  *Ip;\r
+\r
+  if (!IpIo->IsConfigured || IpIo->IpVersion != IP_VERSION_6) {\r
+    return EFI_NOT_STARTED;\r
   }\r
 \r
-  //\r
-  // will never run here!\r
-  //\r
-  ASSERT (FALSE);\r
-  return EFI_UNSUPPORTED;\r
+  Ip = (EFI_IP6_PROTOCOL *) (IpIo->Ip);\r
+\r
+  return Ip->Neighbors (Ip, FALSE, &Neighbor->v6, NULL, Timeout, TRUE);\r
 }\r
 \r
index f18aa41e34a10e15d1f73535763787382ba7ed51..4c7414acfb0a32d31ac35156096bfcd54c1f528d 100644 (file)
@@ -203,6 +203,46 @@ Ip4IsUnicast (
   return TRUE;\r
 }\r
 \r
+/**\r
+  Check whether the incoming IPv6 address is a valid unicast address.\r
+\r
+  If the address is a multicast address has binary 0xFF at the start, it is not\r
+  a valid unicast address. If the address is unspecified ::, it is not a valid\r
+  unicast address to be assigned to any node. If the address is loopback address\r
+  ::1, it is also not a valid unicast address to be assigned to any physical\r
+  interface. \r
+\r
+  @param[in]  Ip6                   The IPv6 address to check against.\r
+\r
+  @return TRUE if Ip6 is a valid unicast address on the network, otherwise FALSE.\r
+\r
+**/ \r
+BOOLEAN\r
+Ip6IsValidUnicast (\r
+  IN EFI_IPv6_ADDRESS       *Ip6\r
+  ) \r
+{\r
+  UINT8 t;\r
+  UINT8 i;\r
+  \r
+  if (Ip6->Addr[0] == 0xFF) {\r
+    return FALSE;\r
+  }\r
+\r
+  for (i = 0; i < 15; i++) {\r
+    if (Ip6->Addr[i] != 0) {\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  t = Ip6->Addr[i];\r
+\r
+  if (t == 0x0 || t == 0x1) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;  \r
+}\r
 \r
 /**\r
   Initialize a random seed using current time.\r
index 49b313615d2ac78216f4e5a443b2609fd7567304..a6acd267ef6f8fd9a0e377e451004a0092468cac 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Tcp request dispatcher implementation.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -357,7 +357,7 @@ Tcp4ConfigurePcb (
   //\r
   // Add Ip for send pkt to the peer\r
   //\r
-  CopyMem (&IpCfgData, &mIpIoDefaultIpConfigData, sizeof (IpCfgData));\r
+  CopyMem (&IpCfgData, &mIp4IoDefaultIpConfigData, sizeof (IpCfgData));\r
   IpCfgData.DefaultProtocol   = EFI_IP_PROTO_TCP;\r
   IpCfgData.UseDefaultAddress = CfgData->AccessPoint.UseDefaultAddress;\r
   IpCfgData.StationAddress    = CfgData->AccessPoint.StationAddress;\r
@@ -605,7 +605,7 @@ Tcp4Dispatcher (
 \r
   switch (Request) {\r
   case SOCK_POLL:\r
-    Ip = ProtoData->TcpService->IpIo->Ip;\r
+    Ip = (EFI_IP4_PROTOCOL *) (ProtoData->TcpService->IpIo->Ip);\r
     Ip->Poll (Ip);\r
     break;\r
 \r
index d4ea65d723d3e3e61aece2c325ecfab94c3d6455..cffd53e9a8e2030664629388b5c5859e3fc3d5b7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Tcp driver function.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -303,7 +303,11 @@ Tcp4DriverBindingStart (
   //\r
   // Create a new IP IO to Consume it\r
   //\r
-  TcpServiceData->IpIo = IpIoCreate (This->DriverBindingHandle, ControllerHandle);\r
+  TcpServiceData->IpIo = IpIoCreate (\r
+                           This->DriverBindingHandle,\r
+                           ControllerHandle,\r
+                           IP_VERSION_4\r
+                           );\r
   if (NULL == TcpServiceData->IpIo) {\r
 \r
     DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough"\r
@@ -318,8 +322,13 @@ Tcp4DriverBindingStart (
   //\r
   ZeroMem (&OpenData, sizeof (IP_IO_OPEN_DATA));\r
 \r
-  CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData));\r
-  OpenData.IpConfigData.DefaultProtocol = EFI_IP_PROTO_TCP;\r
+  CopyMem (\r
+    &OpenData.IpConfigData.Ip4CfgData,\r
+    &mIp4IoDefaultIpConfigData,\r
+    sizeof (EFI_IP4_CONFIG_DATA)\r
+    );\r
+\r
+  OpenData.IpConfigData.Ip4CfgData.DefaultProtocol = EFI_IP_PROTO_TCP;\r
 \r
   OpenData.PktRcvdNotify = Tcp4RxCallback;\r
   Status                 = IpIoOpen (TcpServiceData->IpIo, &OpenData);\r
index cdb35dc2ff2bc9fdc1996b4687fe3c83727ef000..c298f2db0b86d7f797cc78129f61260f3601e6aa 100644 (file)
@@ -2,7 +2,7 @@
 # Component name for module Tcp4\r
 #\r
 # FIX ME!\r
-# Copyright (c) 2006, Intel Corporation.\r
+# Copyright (c) 2006 - 2009, Intel Corporation.\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -77,3 +77,6 @@
   gEfiTcp4ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
   gEfiIp4ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   gEfiTcp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp6ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp6ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
+  \r
index 882a6b70cf112147f814fb0eee0296c203b6a221..a2cf20edf18ce54c2f3d33e8a696db63630890fc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   TCP input process routines.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1441,7 +1441,12 @@ TcpIcmpInput (
     goto CLEAN_EXIT;\r
   }\r
 \r
-  IcmpErrStatus = IpIoGetIcmpErrStatus (IcmpErr, &IcmpErrIsHard, &IcmpErrNotify);\r
+  IcmpErrStatus = IpIoGetIcmpErrStatus (\r
+                    IcmpErr,\r
+                    IP_VERSION_4,\r
+                    &IcmpErrIsHard,\r
+                    &IcmpErrNotify\r
+                    );\r
 \r
   if (IcmpErrNotify) {\r
 \r
index 963d730714c40c3d4c1364c334657024faac1276..39e8fbe9df9192180ea465c48bc68641e95e5b7c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   I/O interfaces between TCP and IpIo.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -37,9 +37,9 @@ Tcp4RxCallback (
   )\r
 {\r
   if (EFI_SUCCESS == Status) {\r
-    TcpInput (Pkt, NetSession->Source, NetSession->Dest);\r
+    TcpInput (Pkt, NetSession->Source.Addr[0], NetSession->Dest.Addr[0]);\r
   } else {\r
-    TcpIcmpInput (Pkt, IcmpErr, NetSession->Source, NetSession->Dest);\r
+    TcpIcmpInput (Pkt, IcmpErr, NetSession->Source.Addr[0], NetSession->Dest.Addr[0]);\r
   }\r
 }\r
 \r
@@ -70,11 +70,16 @@ TcpSendIpPacket (
   SOCKET           *Sock;\r
   VOID             *IpSender;\r
   TCP4_PROTO_DATA  *TcpProto;\r
+  EFI_IP_ADDRESS   Source;\r
+  EFI_IP_ADDRESS   Destination;\r
+\r
+  Source.Addr[0]      = Src;\r
+  Destination.Addr[0] = Dest;\r
 \r
   if (NULL == Tcb) {\r
 \r
     IpIo     = NULL;\r
-    IpSender = IpIoFindSender (&IpIo, Src);\r
+    IpSender = IpIoFindSender (&IpIo, IP_VERSION_4, &Source);\r
 \r
     if (IpSender == NULL) {\r
       DEBUG ((EFI_D_WARN, "TcpSendIpPacket: No appropriate IpSender.\n"));\r
@@ -88,14 +93,14 @@ TcpSendIpPacket (
     IpSender = Tcb->IpInfo;\r
   }\r
 \r
-  Override.TypeOfService            = 0;\r
-  Override.TimeToLive               = 255;\r
-  Override.DoNotFragment            = FALSE;\r
-  Override.Protocol                 = EFI_IP_PROTO_TCP;\r
-  ZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
-  CopyMem (&Override.SourceAddress, &Src, sizeof (EFI_IPv4_ADDRESS));\r
+  Override.Ip4OverrideData.TypeOfService            = 0;\r
+  Override.Ip4OverrideData.TimeToLive               = 255;\r
+  Override.Ip4OverrideData.DoNotFragment            = FALSE;\r
+  Override.Ip4OverrideData.Protocol                 = EFI_IP_PROTO_TCP;\r
+  ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Override.Ip4OverrideData.SourceAddress, &Src, sizeof (EFI_IPv4_ADDRESS));\r
 \r
-  Status = IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, Dest, &Override);\r
+  Status = IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, &Destination, &Override);\r
 \r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "TcpSendIpPacket: return %r error\n", Status));\r
index 1f478290bb4774ae7f696185663d36bc9fabda93..ce66231e226cd3e215f128705586be8320dcfec4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Misc support routines for tcp.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -478,7 +478,7 @@ TcpGetRcvMss (
   ASSERT (Sock != NULL);\r
 \r
   TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
-  Ip       = TcpProto->TcpService->IpIo->Ip;\r
+  Ip       = (EFI_IP4_PROTOCOL *) (TcpProto->TcpService->IpIo->Ip);\r
   ASSERT (Ip != NULL);\r
 \r
   Ip->GetModeData (Ip, NULL, NULL, &SnpMode);\r
index d1c06f3bf11f377f2264f86b8becacee505afcec..eae8c2031c7cd594a679feb3dc2185d2b9d81d7a 100644 (file)
@@ -2,7 +2,7 @@
 # Component name for module Udp4\r
 #\r
 # FIX ME!\r
-# Copyright (c) 2006, Intel Corporation.\r
+# Copyright (c) 2006 - 2009, Intel Corporation.\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -63,3 +63,6 @@
   gEfiUdp4ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
   gEfiIp4ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   gEfiUdp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp6ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp6ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
+  \r
index 8d392eee1c4f16f869c9158b6c63c84fdd6d6126..b0bc0ae43df9f550747f4ff21d5937f8dc472132 100644 (file)
@@ -270,8 +270,9 @@ Udp4CreateService (
   IN     EFI_HANDLE         ControllerHandle\r
   )\r
 {\r
-  EFI_STATUS       Status;\r
-  IP_IO_OPEN_DATA  OpenData;\r
+  EFI_STATUS          Status;\r
+  IP_IO_OPEN_DATA     OpenData;\r
+  EFI_IP4_CONFIG_DATA *Ip4ConfigData;\r
 \r
   ZeroMem (Udp4Service, sizeof (UDP4_SERVICE_DATA));\r
 \r
@@ -286,7 +287,7 @@ Udp4CreateService (
   //\r
   // Create the IpIo for this service context.\r
   //\r
-  Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle);\r
+  Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle, IP_VERSION_4);\r
   if (Udp4Service->IpIo == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -294,12 +295,13 @@ Udp4CreateService (
   //\r
   // Set the OpenData used to open the IpIo.\r
   //\r
-  CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData));\r
-  OpenData.IpConfigData.AcceptBroadcast = TRUE;\r
-  OpenData.RcvdContext                  = (VOID *) Udp4Service;\r
-  OpenData.SndContext                   = NULL;\r
-  OpenData.PktRcvdNotify                = Udp4DgramRcvd;\r
-  OpenData.PktSentNotify                = Udp4DgramSent;\r
+  Ip4ConfigData = &OpenData.IpConfigData.Ip4CfgData;\r
+  CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
+  Ip4ConfigData->AcceptBroadcast = TRUE;\r
+  OpenData.RcvdContext           = (VOID *) Udp4Service;\r
+  OpenData.SndContext            = NULL;\r
+  OpenData.PktRcvdNotify         = Udp4DgramRcvd;\r
+  OpenData.PktSentNotify         = Udp4DgramSent;\r
 \r
   //\r
   // Configure and start the IpIo.\r
@@ -731,7 +733,7 @@ Udp4BuildIp4ConfigData (
   IN OUT EFI_IP4_CONFIG_DATA   *Ip4ConfigData\r
   )\r
 {\r
-  CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
+  CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
 \r
   Ip4ConfigData->DefaultProtocol   = EFI_IP_PROTO_UDP;\r
   Ip4ConfigData->AcceptBroadcast   = Udp4ConfigData->AcceptBroadcast;\r
@@ -1592,7 +1594,7 @@ Udp4Demultiplex (
   IN NET_BUF               *Packet\r
   )\r
 {\r
-  EFI_UDP4_HEADER        *Udp4Header;\r
+  EFI_UDP_HEADER        *Udp4Header;\r
   UINT16                 HeadSum;\r
   EFI_UDP4_RECEIVE_DATA  RxData;\r
   EFI_UDP4_SESSION_DATA  *Udp4Session;\r
@@ -1601,15 +1603,15 @@ Udp4Demultiplex (
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
-  Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
 \r
   if (Udp4Header->Checksum != 0) {\r
     //\r
     // check the checksum.\r
     //\r
     HeadSum = NetPseudoHeadChecksum (\r
-                NetSession->Source,\r
-                NetSession->Dest,\r
+                NetSession->Source.Addr[0],\r
+                NetSession->Dest.Addr[0],\r
                 EFI_IP_PROTO_UDP,\r
                 0\r
                 );\r
@@ -1689,7 +1691,7 @@ Udp4SendPortUnreach (
   IP_IO_OVERRIDE       Override;\r
   IP_IO_IP_INFO        *IpSender;\r
 \r
-  IpSender = IpIoFindSender (&IpIo, NetSession->Dest);\r
+  IpSender = IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest);\r
   if (IpSender == NULL) {\r
     //\r
     // No apropriate sender, since we cannot send out the ICMP message through\r
@@ -1698,7 +1700,7 @@ Udp4SendPortUnreach (
     return;\r
   }\r
 \r
-  IpHdr = NetSession->IpHdr;\r
+  IpHdr = NetSession->IpHdr.Ip4Hdr;\r
 \r
   //\r
   // Calculate the requried length of the icmp error message.\r
@@ -1747,18 +1749,18 @@ Udp4SendPortUnreach (
   //\r
   // Fill the override data.\r
   //\r
-  Override.DoNotFragment = FALSE;\r
-  Override.TypeOfService = 0;\r
-  Override.TimeToLive    = 255;\r
-  Override.Protocol      = EFI_IP_PROTO_ICMP;\r
+  Override.Ip4OverrideData.DoNotFragment = FALSE;\r
+  Override.Ip4OverrideData.TypeOfService = 0;\r
+  Override.Ip4OverrideData.TimeToLive    = 255;\r
+  Override.Ip4OverrideData.Protocol      = EFI_IP_PROTO_ICMP;\r
 \r
-  CopyMem (&Override.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
-  ZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Override.Ip4OverrideData.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
+  ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   //\r
   // Send out this icmp packet.\r
   //\r
-  IpIoSend (IpIo, Packet, IpSender, NULL, NULL, NetSession->Source, &Override);\r
+  IpIoSend (IpIo, Packet, IpSender, NULL, NULL, &NetSession->Source, &Override);\r
 \r
   NetbufFree (Packet);\r
 }\r
@@ -1783,12 +1785,12 @@ Udp4IcmpHandler (
   IN NET_BUF               *Packet\r
   )\r
 {\r
-  EFI_UDP4_HEADER        *Udp4Header;\r
+  EFI_UDP_HEADER        *Udp4Header;\r
   EFI_UDP4_SESSION_DATA  Udp4Session;\r
   LIST_ENTRY             *Entry;\r
   UDP4_INSTANCE_DATA     *Instance;\r
 \r
-  Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
 \r
   CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
   CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
@@ -1819,7 +1821,7 @@ Udp4IcmpHandler (
       //\r
       // Translate the Icmp Error code according to the udp spec.\r
       //\r
-      Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, NULL, NULL);\r
+      Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, IP_VERSION_4, NULL, NULL);\r
 \r
       if (IcmpError > ICMP_ERR_UNREACH_PORT) {\r
         Instance->IcmpError = EFI_ICMP_ERROR;\r
index 0823b6995c67a5ca888000f044d7a774537cc919..f7d6322c2b529af33948cd6d4da041636df1de88 100644 (file)
@@ -45,7 +45,7 @@ extern UINT16                          mUdp4RandomPort;
 \r
 #define UDP4_TIMEOUT_INTERVAL (50 * TICKS_PER_MS)  // 50 milliseconds\r
 \r
-#define UDP4_HEADER_SIZE      sizeof (EFI_UDP4_HEADER)\r
+#define UDP4_HEADER_SIZE      sizeof (EFI_UDP_HEADER)\r
 #define UDP4_MAX_DATA_SIZE    65507\r
 \r
 #define UDP4_PORT_KNOWN       1024\r
index 7bb83b06f66a717b54f9b64ef4020705595aec84..582d6f6d448905a643974861d59bb95d61e853de 100644 (file)
@@ -507,7 +507,7 @@ Udp4Transmit (
   UDP4_INSTANCE_DATA      *Instance;\r
   EFI_TPL                 OldTpl;\r
   NET_BUF                 *Packet;\r
-  EFI_UDP4_HEADER         *Udp4Header;\r
+  EFI_UDP_HEADER         *Udp4Header;\r
   EFI_UDP4_CONFIG_DATA    *ConfigData;\r
   IP4_ADDR                Source;\r
   IP4_ADDR                Destination;\r
@@ -516,6 +516,7 @@ Udp4Transmit (
   UDP4_SERVICE_DATA       *Udp4Service;\r
   IP_IO_OVERRIDE          Override;\r
   UINT16                  HeadSum;\r
+  EFI_IP_ADDRESS          IpDestAddr;\r
 \r
   if ((This == NULL) || (Token == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -575,7 +576,7 @@ Udp4Transmit (
   Udp4Service = Instance->Udp4Service;\r
   *((UINTN *) &Packet->ProtoData[0]) = (UINTN) (Udp4Service->IpIo);\r
 \r
-  Udp4Header = (EFI_UDP4_HEADER *) NetbufAllocSpace (Packet, UDP4_HEADER_SIZE, TRUE);\r
+  Udp4Header = (EFI_UDP_HEADER *) NetbufAllocSpace (Packet, UDP4_HEADER_SIZE, TRUE);\r
   ASSERT (Udp4Header != NULL);\r
 \r
   ConfigData = &Instance->ConfigData;\r
@@ -589,7 +590,7 @@ Udp4Transmit (
   Udp4Header->Checksum     = 0;\r
 \r
   UdpSessionData = TxData->UdpSessionData;\r
-  Override.SourceAddress = ConfigData->StationAddress;\r
+  Override.Ip4OverrideData.SourceAddress = ConfigData->StationAddress;\r
 \r
   if (UdpSessionData != NULL) {\r
     //\r
@@ -597,7 +598,7 @@ Udp4Transmit (
     // UdpSessionData.\r
     //\r
     if (!EFI_IP4_EQUAL (&UdpSessionData->SourceAddress, &mZeroIp4Addr)) {\r
-      CopyMem (&Override.SourceAddress, &UdpSessionData->SourceAddress, sizeof (EFI_IPv4_ADDRESS));\r
+      CopyMem (&Override.Ip4OverrideData.SourceAddress, &UdpSessionData->SourceAddress, sizeof (EFI_IPv4_ADDRESS));\r
     }\r
 \r
     if (UdpSessionData->SourcePort != 0) {\r
@@ -608,7 +609,7 @@ Udp4Transmit (
       Udp4Header->DstPort = HTONS (UdpSessionData->DestinationPort);\r
     }\r
 \r
-    CopyMem (&Source, &Override.SourceAddress, sizeof (IP4_ADDR));\r
+    CopyMem (&Source, &Override.Ip4OverrideData.SourceAddress, sizeof (IP4_ADDR));\r
     CopyMem (&Destination, &UdpSessionData->DestinationAddress, sizeof (IP4_ADDR));\r
 \r
     //\r
@@ -644,15 +645,15 @@ Udp4Transmit (
   // Fill the IpIo Override data.\r
   //\r
   if (TxData->GatewayAddress != NULL) {\r
-    CopyMem (&Override.GatewayAddress, TxData->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+    CopyMem (&Override.Ip4OverrideData.GatewayAddress, TxData->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
   } else {\r
-    ZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+    ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
   }\r
 \r
-  Override.Protocol                 = EFI_IP_PROTO_UDP;\r
-  Override.TypeOfService            = ConfigData->TypeOfService;\r
-  Override.TimeToLive               = ConfigData->TimeToLive;\r
-  Override.DoNotFragment            = ConfigData->DoNotFragment;\r
+  Override.Ip4OverrideData.Protocol                 = EFI_IP_PROTO_UDP;\r
+  Override.Ip4OverrideData.TypeOfService            = ConfigData->TypeOfService;\r
+  Override.Ip4OverrideData.TimeToLive               = ConfigData->TimeToLive;\r
+  Override.Ip4OverrideData.DoNotFragment            = ConfigData->DoNotFragment;\r
 \r
   //\r
   // Save the token into the TxToken map.\r
@@ -665,13 +666,14 @@ Udp4Transmit (
   //\r
   // Send out this datagram through IpIo.\r
   //\r
+  IpDestAddr.Addr[0] = Destination;\r
   Status = IpIoSend (\r
              Udp4Service->IpIo,\r
              Packet,\r
              Instance->IpInfo,\r
              Instance,\r
              Token,\r
-             Destination,\r
+             &IpDestAddr,\r
              &Override\r
              );\r
   if (EFI_ERROR (Status)) {\r