X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FDxeIpIoLib%2FDxeIpIoLib.c;h=c94a79c4dc7f62df11a155d7cf7ca1442af27c22;hp=4674d7d028aa49f8ad9d93ad53dce93ed6fdfded;hb=f6b7393ceb34c9b3a27434268bf2ce517047641f;hpb=e48e37fce2611df7a52aff271835ff72ee396d9b diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c index 4674d7d028..c94a79c4dc 100644 --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c @@ -1,6 +1,7 @@ /** @file + IpIo Library. -Copyright (c) 2005 - 2007, Intel Corporation +Copyright (c) 2005 - 2009, Intel Corporation.
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -8,40 +9,27 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -Module Name: - - IpIo.c - -Abstract: - - The implementation of the IpIo layer. - - **/ -#include +#include #include #include #include #include +#include #include #include -#include - +#include -#define NET_PROTO_HDR(Buf, Type) ((Type *) ((Buf)->BlockOp[0].Head)) -#define ICMP_ERRLEN(IpHdr) \ - (sizeof(IP4_ICMP_HEAD) + EFI_IP4_HEADER_LEN(IpHdr) + 8) LIST_ENTRY mActiveIpIoList = { &mActiveIpIoList, &mActiveIpIoList }; -EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData = { +EFI_IP4_CONFIG_DATA mIp4IoDefaultIpConfigData = { EFI_IP_PROTO_UDP, FALSE, TRUE, @@ -58,27 +46,67 @@ EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData = { 0 }; -STATIC ICMP_ERROR_INFO mIcmpErrMap[10] = { - {FALSE, TRUE}, - {FALSE, TRUE}, - {TRUE, TRUE}, - {TRUE, TRUE}, - {TRUE, TRUE}, - {FALSE, TRUE}, - {FALSE, TRUE}, - {FALSE, TRUE}, - {FALSE, FALSE}, - {FALSE, TRUE} +EFI_IP6_CONFIG_DATA mIp6IoDefaultIpConfigData = { + EFI_IP_PROTO_UDP, + FALSE, + TRUE, + FALSE, + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, + 0, + 255, + 0, + 0, + 0 +}; + +ICMP_ERROR_INFO mIcmpErrMap[10] = { + {FALSE, TRUE }, // ICMP_ERR_UNREACH_NET + {FALSE, TRUE }, // ICMP_ERR_UNREACH_HOST + {TRUE, TRUE }, // ICMP_ERR_UNREACH_PROTOCOL + {TRUE, TRUE }, // ICMP_ERR_UNREACH_PORT + {TRUE, TRUE }, // ICMP_ERR_MSGSIZE + {FALSE, TRUE }, // ICMP_ERR_UNREACH_SRCFAIL + {FALSE, TRUE }, // ICMP_ERR_TIMXCEED_INTRANS + {FALSE, TRUE }, // ICMP_ERR_TIMEXCEED_REASS + {FALSE, FALSE}, // ICMP_ERR_QUENCH + {FALSE, TRUE } // ICMP_ERR_PARAMPROB +}; + +ICMP_ERROR_INFO mIcmp6ErrMap[10] = { + {FALSE, TRUE}, // ICMP6_ERR_UNREACH_NET + {FALSE, TRUE}, // ICMP6_ERR_UNREACH_HOST + {TRUE, TRUE}, // ICMP6_ERR_UNREACH_PROTOCOL + {TRUE, TRUE}, // ICMP6_ERR_UNREACH_PORT + {TRUE, TRUE}, // ICMP6_ERR_PACKAGE_TOOBIG + {FALSE, TRUE}, // ICMP6_ERR_TIMXCEED_HOPLIMIT + {FALSE, TRUE}, // ICMP6_ERR_TIMXCEED_REASS + {FALSE, TRUE}, // ICMP6_ERR_PARAMPROB_HEADER + {FALSE, TRUE}, // ICMP6_ERR_PARAMPROB_NEXHEADER + {FALSE, TRUE} // ICMP6_ERR_PARAMPROB_IPV6OPTION }; -STATIC + +/** + Notify function for IP transmit token. + + @param[in] Context The context passed in by the event notifier. + +**/ VOID EFIAPI IpIoTransmitHandlerDpc ( IN VOID *Context ); -STATIC + +/** + Notify function for IP transmit token. + + @param[in] Event The event signaled. + @param[in] Context The context passed in by the event notifier. + +**/ VOID EFIAPI IpIoTransmitHandler ( @@ -88,37 +116,51 @@ IpIoTransmitHandler ( /** - This function create an ip child ,open the IP protocol, return the opened - Ip protocol to Interface. + This function create an IP child ,open the IP protocol, and return the opened + IP protocol as Interface. - @param ControllerHandle The controller handle. - @param ImageHandle The image handle. - @param ChildHandle Pointer to the buffer to save the ip child handle. - @param Interface Pointer used to get the ip protocol interface. + @param[in] ControllerHandle The controller handle. + @param[in] ImageHandle The image handle. + @param[in] ChildHandle Pointer to the buffer to save the IP child handle. + @param[in] IpVersion The version of the IP protocol to use, either + IPv4 or IPv6. + @param[out] Interface Pointer used to get the IP protocol interface. - @retval EFI_SUCCESS The ip child is created and the ip protocol - interface is retrieved. - @retval other The required operation failed. + @retval EFI_SUCCESS The IP child is created and the IP protocol + interface is retrieved. + @retval Others The required operation failed. **/ -STATIC EFI_STATUS IpIoCreateIpChildOpenProtocol ( IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE *ChildHandle, + IN UINT8 IpVersion, OUT VOID **Interface ) { EFI_STATUS Status; + EFI_GUID *ServiceBindingGuid; + EFI_GUID *IpProtocolGuid; + + if (IpVersion == IP_VERSION_4) { + ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid; + IpProtocolGuid = &gEfiIp4ProtocolGuid; + } else if (IpVersion == IP_VERSION_6){ + ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid; + IpProtocolGuid = &gEfiIp6ProtocolGuid; + } else { + return EFI_UNSUPPORTED; + } // - // Create an ip child. + // Create an IP child. // Status = NetLibCreateServiceChild ( ControllerHandle, ImageHandle, - &gEfiIp4ServiceBindingProtocolGuid, + ServiceBindingGuid, ChildHandle ); if (EFI_ERROR (Status)) { @@ -126,11 +168,11 @@ IpIoCreateIpChildOpenProtocol ( } // - // Open the ip protocol installed on the *ChildHandle. + // Open the IP protocol installed on the *ChildHandle. // Status = gBS->OpenProtocol ( *ChildHandle, - &gEfiIp4ProtocolGuid, + IpProtocolGuid, Interface, ImageHandle, ControllerHandle, @@ -138,12 +180,12 @@ IpIoCreateIpChildOpenProtocol ( ); if (EFI_ERROR (Status)) { // - // On failure, destroy the ip child. + // On failure, destroy the IP child. // NetLibDestroyServiceChild ( ControllerHandle, ImageHandle, - &gEfiIp4ServiceBindingProtocolGuid, + ServiceBindingGuid, *ChildHandle ); } @@ -153,78 +195,93 @@ IpIoCreateIpChildOpenProtocol ( /** - This function close the previously openned ip protocol and destroy the ip child. + This function close the previously openned IP protocol and destroy the IP child. - @param ControllerHandle The controller handle. - @param ImageHandle the image handle. - @param ChildHandle The child handle of the ip child. + @param[in] ControllerHandle The controller handle. + @param[in] ImageHandle The image handle. + @param[in] ChildHandle The child handle of the IP child. + @param[in] IpVersion The version of the IP protocol to use, either + IPv4 or IPv6. - @retval EFI_SUCCESS The ip protocol is closed and the relevant ip child - is destroyed. - @retval other The required operation failed. + @retval EFI_SUCCESS The IP protocol is closed and the relevant IP child + is destroyed. + @retval Others The required operation failed. **/ -STATIC EFI_STATUS IpIoCloseProtocolDestroyIpChild ( IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ImageHandle, - IN EFI_HANDLE ChildHandle + IN EFI_HANDLE ChildHandle, + IN UINT8 IpVersion ) { EFI_STATUS Status; + EFI_GUID *ServiceBindingGuid; + EFI_GUID *IpProtocolGuid; + + if (IpVersion == IP_VERSION_4) { + ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid; + IpProtocolGuid = &gEfiIp4ProtocolGuid; + } else if (IpVersion == IP_VERSION_6) { + ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid; + IpProtocolGuid = &gEfiIp6ProtocolGuid; + } else { + return EFI_UNSUPPORTED; + } // - // Close the previously openned ip protocol. + // Close the previously openned IP protocol. // gBS->CloseProtocol ( ChildHandle, - &gEfiIp4ProtocolGuid, + IpProtocolGuid, ImageHandle, ControllerHandle ); // - // Destroy the ip child. + // Destroy the IP child. // Status = NetLibDestroyServiceChild ( ControllerHandle, ImageHandle, - &gEfiIp4ServiceBindingProtocolGuid, + ServiceBindingGuid, ChildHandle ); return Status; } - /** - Handle ICMP packets. + This function handles ICMPv4 packets. It is the worker function of + IpIoIcmpHandler. - @param IpIo Pointer to the IP_IO instance. - @param Pkt Pointer to the ICMP packet. - @param Session Pointer to the net session of this ICMP packet. + @param[in] IpIo Pointer to the IP_IO instance. + @param[in, out] Pkt Pointer to the ICMPv4 packet. + @param[in] Session Pointer to the net session of this ICMPv4 packet. - @retval EFI_SUCCESS The ICMP packet is handled successfully. - @retval EFI_ABORTED This type of ICMP packet is not supported. + @retval EFI_SUCCESS The ICMPv4 packet is handled successfully. + @retval EFI_ABORTED This type of ICMPv4 packet is not supported. **/ -STATIC EFI_STATUS -IpIoIcmpHandler ( - IN IP_IO *IpIo, - IN NET_BUF *Pkt, - IN EFI_NET_SESSION_DATA *Session +IpIoIcmpv4Handler ( + IN IP_IO *IpIo, + IN OUT NET_BUF *Pkt, + IN EFI_NET_SESSION_DATA *Session ) { IP4_ICMP_ERROR_HEAD *IcmpHdr; EFI_IP4_HEADER *IpHdr; - ICMP_ERROR IcmpErr; + UINT8 IcmpErr; UINT8 *PayLoadHdr; UINT8 Type; UINT8 Code; UINT32 TrimBytes; + ASSERT (IpIo->IpVersion == IP_VERSION_4); + IcmpHdr = NET_PROTO_HDR (Pkt, IP4_ICMP_ERROR_HEAD); IpHdr = (EFI_IP4_HEADER *) (&IcmpHdr->IpHead); @@ -250,7 +307,7 @@ IpIoIcmpHandler ( case ICMP_CODE_UNREACH_PROTOCOL: case ICMP_CODE_UNREACH_PORT: case ICMP_CODE_UNREACH_SRCFAIL: - IcmpErr = (ICMP_ERROR) (ICMP_ERR_UNREACH_NET + Code); + IcmpErr = (UINT8) (ICMP_ERR_UNREACH_NET + Code); break; @@ -276,8 +333,6 @@ IpIoIcmpHandler ( default: return EFI_ABORTED; - - break; } break; @@ -287,7 +342,7 @@ IpIoIcmpHandler ( return EFI_ABORTED; } - IcmpErr = (ICMP_ERROR) (Code + ICMP_ERR_TIMXCEED_INTRANS); + IcmpErr = (UINT8) (Code + ICMP_ERR_TIMXCEED_INTRANS); break; @@ -311,8 +366,6 @@ IpIoIcmpHandler ( default: return EFI_ABORTED; - - break; } // @@ -326,22 +379,213 @@ IpIoIcmpHandler ( IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext); + return EFI_SUCCESS; +} + +/** + This function handles ICMPv6 packets. It is the worker function of + IpIoIcmpHandler. + + @param[in] IpIo Pointer to the IP_IO instance. + @param[in, out] Pkt Pointer to the ICMPv6 packet. + @param[in] Session Pointer to the net session of this ICMPv6 packet. + + @retval EFI_SUCCESS The ICMPv6 packet is handled successfully. + @retval EFI_ABORTED This type of ICMPv6 packet is not supported. + +**/ +EFI_STATUS +IpIoIcmpv6Handler ( + IN IP_IO *IpIo, + IN OUT NET_BUF *Pkt, + IN EFI_NET_SESSION_DATA *Session + ) +{ + IP6_ICMP_ERROR_HEAD *IcmpHdr; + EFI_IP6_HEADER *IpHdr; + UINT8 IcmpErr; + UINT8 *PayLoadHdr; + UINT8 Type; + UINT8 Code; + UINT8 NextHeader; + UINT32 TrimBytes; + BOOLEAN Flag; + + ASSERT (IpIo->IpVersion == IP_VERSION_6); + + // + // Check the ICMPv6 packet length. + // + if (Pkt->TotalSize < sizeof (IP6_ICMP_ERROR_HEAD)) { + + return EFI_ABORTED; + } + + IcmpHdr = NET_PROTO_HDR (Pkt, IP6_ICMP_ERROR_HEAD); + Type = IcmpHdr->Head.Type; + Code = IcmpHdr->Head.Code; + + // + // Analyze the ICMPv6 Error in this ICMPv6 packet + // + switch (Type) { + case ICMP_V6_DEST_UNREACHABLE: + switch (Code) { + case ICMP_V6_NO_ROUTE_TO_DEST: + case ICMP_V6_BEYOND_SCOPE: + case ICMP_V6_ROUTE_REJECTED: + IcmpErr = ICMP6_ERR_UNREACH_NET; + + break; + + case ICMP_V6_COMM_PROHIBITED: + case ICMP_V6_ADDR_UNREACHABLE: + case ICMP_V6_SOURCE_ADDR_FAILED: + IcmpErr = ICMP6_ERR_UNREACH_HOST; + + break; + + case ICMP_V6_PORT_UNREACHABLE: + IcmpErr = ICMP6_ERR_UNREACH_PORT; + + break; + + default: + return EFI_ABORTED; + } + + break; + + case ICMP_V6_PACKET_TOO_BIG: + if (Code >= 1) { + return EFI_ABORTED; + } + + IcmpErr = ICMP6_ERR_PACKAGE_TOOBIG; + + break; + + case ICMP_V6_TIME_EXCEEDED: + if (Code > 1) { + return EFI_ABORTED; + } + + IcmpErr = (UINT8) (ICMP6_ERR_TIMXCEED_HOPLIMIT + Code); + + break; + + case ICMP_V6_PARAMETER_PROBLEM: + if (Code > 3) { + return EFI_ABORTED; + } + + IcmpErr = (UINT8) (ICMP6_ERR_PARAMPROB_HEADER + Code); + + break; + + default: + + return EFI_ABORTED; + } + + // + // Notify user the ICMPv6 packet only containing payload except + // IPv6 basic header, extension header and ICMP header + // + + IpHdr = (EFI_IP6_HEADER *) (&IcmpHdr->IpHead); + NextHeader = IpHdr->NextHeader; + PayLoadHdr = (UINT8 *) ((UINT8 *) IcmpHdr + sizeof (IP6_ICMP_ERROR_HEAD)); + Flag = TRUE; + + do { + switch (NextHeader) { + case EFI_IP_PROTO_UDP: + case EFI_IP_PROTO_TCP: + case EFI_IP_PROTO_ICMP: + case IP6_NO_NEXT_HEADER: + Flag = FALSE; + + break; + + case IP6_HOP_BY_HOP: + case IP6_DESTINATION: + // + // The Hdr Ext Len is 8-bit unsigned integer in 8-octet units, not including + // the first 8 octets. + // + NextHeader = *(PayLoadHdr); + PayLoadHdr = (UINT8 *) (PayLoadHdr + (*(PayLoadHdr + 1) + 1) * 8); + + break; + + case IP6_FRAGMENT: + // + // The Fragment Header Length is 8 octets. + // + NextHeader = *(PayLoadHdr); + PayLoadHdr = (UINT8 *) (PayLoadHdr + 8); + + break; + + default: + + return EFI_ABORTED; + } + } while (Flag); + + TrimBytes = (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr); + + NetbufTrim (Pkt, TrimBytes, TRUE); + + IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext); + return EFI_SUCCESS; } +/** + This function handles ICMP packets. + + @param[in] IpIo Pointer to the IP_IO instance. + @param[in, out] Pkt Pointer to the ICMP packet. + @param[in] Session Pointer to the net session of this ICMP packet. + + @retval EFI_SUCCESS The ICMP packet is handled successfully. + @retval EFI_ABORTED This type of ICMP packet is not supported. + @retval EFI_UNSUPPORTED The IP protocol version in IP_IO is not supported. + +**/ +EFI_STATUS +IpIoIcmpHandler ( + IN IP_IO *IpIo, + IN OUT NET_BUF *Pkt, + IN EFI_NET_SESSION_DATA *Session + ) +{ + + if (IpIo->IpVersion == IP_VERSION_4) { + + return IpIoIcmpv4Handler (IpIo, Pkt, Session); + + } else if (IpIo->IpVersion == IP_VERSION_6) { + + return IpIoIcmpv6Handler (IpIo, Pkt, Session); + + } else { + + return EFI_UNSUPPORTED; + } +} + /** - Ext free function for net buffer. This function is - called when the net buffer is freed. It is used to + Free function for receive token of IP_IO. It is used to signal the recycle event to notify IP to recycle the data buffer. - @param Event The event to be signaled. - - @return None. + @param[in] Event The event to be signaled. **/ -STATIC VOID IpIoExtFree ( IN VOID *Event @@ -355,35 +599,46 @@ IpIoExtFree ( Create a send entry to wrap a packet before sending out it through IP. - @param IpIo Pointer to the IP_IO instance. - @param Pkt Pointer to the packet. - @param Sender Pointer to the IP sender. - @param NotifyData Pointer to the notify data. - @param Dest Pointer to the destination IP address. - @param Override Pointer to the overriden IP_IO data. + @param[in, out] IpIo Pointer to the IP_IO instance. + @param[in, out] Pkt Pointer to the packet. + @param[in] Sender Pointer to the IP sender. + @param[in] Context Pointer to the context. + @param[in] NotifyData Pointer to the notify data. + @param[in] Dest Pointer to the destination IP address. + @param[in] Override Pointer to the overriden IP_IO data. @return Pointer to the data structure created to wrap the packet. If NULL, @return resource limit occurred. **/ -STATIC IP_IO_SEND_ENTRY * IpIoCreateSndEntry ( - IN IP_IO *IpIo, - IN NET_BUF *Pkt, - IN EFI_IP4_PROTOCOL *Sender, - IN VOID *Context OPTIONAL, - IN VOID *NotifyData OPTIONAL, - IN IP4_ADDR Dest, - IN IP_IO_OVERRIDE *Override + IN OUT IP_IO *IpIo, + IN OUT NET_BUF *Pkt, + IN VOID *Sender, + IN VOID *Context OPTIONAL, + IN VOID *NotifyData OPTIONAL, + IN EFI_IP_ADDRESS *Dest OPTIONAL, + IN IP_IO_OVERRIDE *Override ) { IP_IO_SEND_ENTRY *SndEntry; - EFI_IP4_COMPLETION_TOKEN *SndToken; - EFI_IP4_TRANSMIT_DATA *TxData; + EFI_EVENT Event; EFI_STATUS Status; - EFI_IP4_OVERRIDE_DATA *OverrideData; - volatile UINT32 Index; + NET_FRAGMENT *ExtFragment; + UINT32 FragmentCount; + IP_IO_OVERRIDE *OverrideData; + IP_IO_IP_TX_DATA *TxData; + EFI_IP4_TRANSMIT_DATA *Ip4TxData; + EFI_IP6_TRANSMIT_DATA *Ip6TxData; + + if ((IpIo->IpVersion != IP_VERSION_4) && (IpIo->IpVersion != IP_VERSION_6)) { + return NULL; + } + + Event = NULL; + TxData = NULL; + OverrideData = NULL; // // Allocate resource for SndEntry @@ -393,102 +648,128 @@ IpIoCreateSndEntry ( return NULL; } - // - // Allocate resource for SndToken - // - SndToken = AllocatePool (sizeof (EFI_IP4_COMPLETION_TOKEN)); - if (NULL == SndToken) { - goto ReleaseSndEntry; - } - Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY, IpIoTransmitHandler, SndEntry, - &(SndToken->Event) + &Event ); if (EFI_ERROR (Status)) { - goto ReleaseSndToken; + goto ON_ERROR; } + FragmentCount = Pkt->BlockOpNum; + // // Allocate resource for TxData // - TxData = AllocatePool ( - sizeof (EFI_IP4_TRANSMIT_DATA) + - sizeof (EFI_IP4_FRAGMENT_DATA) * (Pkt->BlockOpNum - 1) + TxData = (IP_IO_IP_TX_DATA *) AllocatePool ( + sizeof (IP_IO_IP_TX_DATA) + sizeof (NET_FRAGMENT) * (FragmentCount - 1) ); if (NULL == TxData) { - goto ReleaseEvent; + goto ON_ERROR; } + // + // Build a fragment table to contain the fragments in the packet. + // + if (IpIo->IpVersion == IP_VERSION_4) { + ExtFragment = (NET_FRAGMENT *) TxData->Ip4TxData.FragmentTable; + } else { + ExtFragment = (NET_FRAGMENT *) TxData->Ip6TxData.FragmentTable; + } + + NetbufBuildExt (Pkt, ExtFragment, &FragmentCount); + + // // Allocate resource for OverrideData if needed // - OverrideData = NULL; if (NULL != Override) { - OverrideData = AllocatePool (sizeof (EFI_IP4_OVERRIDE_DATA)); + OverrideData = AllocateCopyPool (sizeof (IP_IO_OVERRIDE), Override); if (NULL == OverrideData) { - goto ReleaseResource; + goto ON_ERROR; } - // - // Set the fields of OverrideData - // - CopyMem (OverrideData, Override, sizeof (*OverrideData)); } // - // Set the fields of TxData + // Set other fields of TxData except the fragment table // - CopyMem (&TxData->DestinationAddress, &Dest, sizeof (EFI_IPv4_ADDRESS)); - TxData->OverrideData = OverrideData; - TxData->OptionsLength = 0; - TxData->OptionsBuffer = NULL; - TxData->TotalDataLength = Pkt->TotalSize; - TxData->FragmentCount = Pkt->BlockOpNum; + if (IpIo->IpVersion == IP_VERSION_4) { + Ip4TxData = &TxData->Ip4TxData; - for (Index = 0; Index < Pkt->BlockOpNum; Index++) { - TxData->FragmentTable[Index].FragmentBuffer = Pkt->BlockOp[Index].Head; - TxData->FragmentTable[Index].FragmentLength = Pkt->BlockOp[Index].Size; - } + CopyMem (&Ip4TxData->DestinationAddress, Dest, sizeof (EFI_IPv4_ADDRESS)); - // - // Set the fields of SndToken - // - SndToken->Packet.TxData = TxData; + Ip4TxData->OverrideData = &OverrideData->Ip4OverrideData; + Ip4TxData->OptionsLength = 0; + Ip4TxData->OptionsBuffer = NULL; + Ip4TxData->TotalDataLength = Pkt->TotalSize; + Ip4TxData->FragmentCount = FragmentCount; + + // + // Set the fields of SndToken + // + SndEntry->SndToken.Ip4Token.Event = Event; + SndEntry->SndToken.Ip4Token.Packet.TxData = Ip4TxData; + } else { + + Ip6TxData = &TxData->Ip6TxData; + + if (Dest != NULL) { + CopyMem (&Ip6TxData->DestinationAddress, Dest, sizeof (EFI_IPv6_ADDRESS)); + } else { + ZeroMem (&Ip6TxData->DestinationAddress, sizeof (EFI_IPv6_ADDRESS)); + } + + Ip6TxData->OverrideData = &OverrideData->Ip6OverrideData; + Ip6TxData->DataLength = Pkt->TotalSize; + Ip6TxData->FragmentCount = FragmentCount; + Ip6TxData->ExtHdrsLength = 0; + Ip6TxData->ExtHdrs = NULL; + + // + // Set the fields of SndToken + // + SndEntry->SndToken.Ip6Token.Event = Event; + SndEntry->SndToken.Ip6Token.Packet.TxData = Ip6TxData; + } // // Set the fields of SndEntry // SndEntry->IpIo = IpIo; - SndEntry->Ip = Sender; + SndEntry->Ip = Sender; SndEntry->Context = Context; SndEntry->NotifyData = NotifyData; SndEntry->Pkt = Pkt; NET_GET_REF (Pkt); - SndEntry->SndToken = SndToken; - InsertTailList (&IpIo->PendingSndList, &SndEntry->Entry); return SndEntry; -ReleaseResource: - gBS->FreePool (TxData); +ON_ERROR: -ReleaseEvent: - gBS->CloseEvent (SndToken->Event); + if (OverrideData != NULL) { + FreePool (OverrideData); + } -ReleaseSndToken: - gBS->FreePool (SndToken); + if (TxData != NULL) { + FreePool (TxData); + } -ReleaseSndEntry: - gBS->FreePool (SndEntry); + if (SndEntry != NULL) { + FreePool (SndEntry); + } + + if (Event != NULL) { + gBS->CloseEvent (Event); + } return NULL; } @@ -496,46 +777,55 @@ ReleaseSndEntry: /** Destroy the SndEntry. + + This function pairs with IpIoCreateSndEntry(). - @param SndEntry Pointer to the send entry to be destroyed. - - @return None. + @param[in] SndEntry Pointer to the send entry to be destroyed. **/ -STATIC VOID IpIoDestroySndEntry ( IN IP_IO_SEND_ENTRY *SndEntry ) { - EFI_IP4_TRANSMIT_DATA *TxData; + EFI_EVENT Event; + IP_IO_IP_TX_DATA *TxData; + IP_IO_OVERRIDE *Override; + + if (SndEntry->IpIo->IpVersion == IP_VERSION_4) { + Event = SndEntry->SndToken.Ip4Token.Event; + TxData = (IP_IO_IP_TX_DATA *) SndEntry->SndToken.Ip4Token.Packet.TxData; + Override = (IP_IO_OVERRIDE *) TxData->Ip4TxData.OverrideData; + } else if (SndEntry->IpIo->IpVersion == IP_VERSION_6) { + Event = SndEntry->SndToken.Ip6Token.Event; + TxData = (IP_IO_IP_TX_DATA *) SndEntry->SndToken.Ip6Token.Packet.TxData; + Override = (IP_IO_OVERRIDE *) TxData->Ip6TxData.OverrideData; + } else { + return ; + } + + gBS->CloseEvent (Event); - TxData = SndEntry->SndToken->Packet.TxData; + FreePool (TxData); - if (NULL != TxData->OverrideData) { - gBS->FreePool (TxData->OverrideData); + if (NULL != Override) { + FreePool (Override); } - gBS->FreePool (TxData); NetbufFree (SndEntry->Pkt); - gBS->CloseEvent (SndEntry->SndToken->Event); - gBS->FreePool (SndEntry->SndToken); RemoveEntryList (&SndEntry->Entry); - gBS->FreePool (SndEntry); + FreePool (SndEntry); } /** Notify function for IP transmit token. - @param Context The context passed in by the event notifier. - - @return None. + @param[in] Context The context passed in by the event notifier. **/ -STATIC VOID EFIAPI IpIoTransmitHandlerDpc ( @@ -544,14 +834,23 @@ IpIoTransmitHandlerDpc ( { IP_IO *IpIo; IP_IO_SEND_ENTRY *SndEntry; + EFI_STATUS Status; SndEntry = (IP_IO_SEND_ENTRY *) Context; IpIo = SndEntry->IpIo; - if (IpIo->PktSentNotify && SndEntry->NotifyData) { + if (IpIo->IpVersion == IP_VERSION_4) { + Status = SndEntry->SndToken.Ip4Token.Status; + } else if (IpIo->IpVersion == IP_VERSION_6){ + Status = SndEntry->SndToken.Ip6Token.Status; + } else { + return ; + } + + if ((IpIo->PktSentNotify != NULL) && (SndEntry->NotifyData != NULL)) { IpIo->PktSentNotify ( - SndEntry->SndToken->Status, + Status, SndEntry->Context, SndEntry->Ip, SndEntry->NotifyData @@ -561,17 +860,14 @@ IpIoTransmitHandlerDpc ( IpIoDestroySndEntry (SndEntry); } + /** Notify function for IP transmit token. - @param Event The event signaled. - @param Context The context passed in by the event notifier. - - @return None. + @param[in] Event The event signaled. + @param[in] Context The context passed in by the event notifier. **/ - -STATIC VOID EFIAPI IpIoTransmitHandler ( @@ -582,19 +878,16 @@ IpIoTransmitHandler ( // // Request IpIoTransmitHandlerDpc as a DPC at TPL_CALLBACK // - NetLibQueueDpc (TPL_CALLBACK, IpIoTransmitHandlerDpc, Context); + QueueDpc (TPL_CALLBACK, IpIoTransmitHandlerDpc, Context); } /** The dummy handler for the dummy IP receive token. - @param Context The context passed in by the event notifier. - - @return None. + @param[in] Context The context passed in by the event notifier. **/ -STATIC VOID EFIAPI IpIoDummyHandlerDpc ( @@ -602,36 +895,71 @@ IpIoDummyHandlerDpc ( ) { IP_IO_IP_INFO *IpInfo; - EFI_IP4_COMPLETION_TOKEN *DummyToken; + EFI_STATUS Status; + EFI_EVENT RecycleEvent; IpInfo = (IP_IO_IP_INFO *) Context; - DummyToken = &(IpInfo->DummyRcvToken); - if (EFI_ABORTED == DummyToken->Status) { + if ((IpInfo->IpVersion != IP_VERSION_4) && (IpInfo->IpVersion != IP_VERSION_6)) { + return ; + } + + RecycleEvent = NULL; + + if (IpInfo->IpVersion == IP_VERSION_4) { + Status = IpInfo->DummyRcvToken.Ip4Token.Status; + + if (IpInfo->DummyRcvToken.Ip4Token.Packet.RxData != NULL) { + RecycleEvent = IpInfo->DummyRcvToken.Ip4Token.Packet.RxData->RecycleSignal; + } + } else { + Status = IpInfo->DummyRcvToken.Ip6Token.Status; + + if (IpInfo->DummyRcvToken.Ip6Token.Packet.RxData != NULL) { + RecycleEvent = IpInfo->DummyRcvToken.Ip6Token.Packet.RxData->RecycleSignal; + } + } + + + + if (EFI_ABORTED == Status) { // // The reception is actively aborted by the consumer, directly return. // return; - } else if (EFI_SUCCESS == DummyToken->Status) { - ASSERT (DummyToken->Packet.RxData); + } else if (EFI_SUCCESS == Status) { + // + // Recycle the RxData. + // + ASSERT (RecycleEvent != NULL); - gBS->SignalEvent (DummyToken->Packet.RxData->RecycleSignal); + gBS->SignalEvent (RecycleEvent); } - IpInfo->Ip->Receive (IpInfo->Ip, DummyToken); + // + // Continue the receive. + // + if (IpInfo->IpVersion == IP_VERSION_4) { + ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Receive ( + (EFI_IP4_PROTOCOL *) (IpInfo->Ip), + &IpInfo->DummyRcvToken.Ip4Token + ); + } else { + ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Receive ( + (EFI_IP6_PROTOCOL *) (IpInfo->Ip), + &IpInfo->DummyRcvToken.Ip6Token + ); + } } /** - Request IpIoDummyHandlerDpc as a DPC at TPL_CALLBACK. - - @param Event The event signaled. - @param Context The context passed in by the event notifier. + This function add IpIoDummyHandlerDpc to the end of the DPC queue. - @return None. + @param[in] Event The event signaled. + @param[in] Context The context passed in by the event notifier. **/ -STATIC VOID EFIAPI IpIoDummyHandler ( @@ -642,7 +970,7 @@ IpIoDummyHandler ( // // Request IpIoDummyHandlerDpc as a DPC at TPL_CALLBACK // - NetLibQueueDpc (TPL_CALLBACK, IpIoDummyHandlerDpc, Context); + QueueDpc (TPL_CALLBACK, IpIoDummyHandlerDpc, Context); } @@ -650,12 +978,9 @@ IpIoDummyHandler ( Notify function for the IP receive token, used to process the received IP packets. - @param Context The context passed in by the event notifier. - - @return None. + @param[in] Context The context passed in by the event notifier. **/ -STATIC VOID EFIAPI IpIoListenHandlerDpc ( @@ -664,16 +989,23 @@ IpIoListenHandlerDpc ( { IP_IO *IpIo; EFI_STATUS Status; - EFI_IP4_RECEIVE_DATA *RxData; - EFI_IP4_PROTOCOL *Ip; + IP_IO_IP_RX_DATA *RxData; + VOID *Ip; EFI_NET_SESSION_DATA Session; NET_BUF *Pkt; - IpIo = (IP_IO *) Context; + IpIo = (IP_IO *) Context; + Ip = IpIo->Ip; - Ip = IpIo->Ip; - Status = IpIo->RcvToken.Status; - RxData = IpIo->RcvToken.Packet.RxData; + if (IpIo->IpVersion == IP_VERSION_4) { + Status = IpIo->RcvToken.Ip4Token.Status; + RxData = (IP_IO_IP_RX_DATA *) IpIo->RcvToken.Ip4Token.Packet.RxData; + } else if (IpIo->IpVersion == IP_VERSION_6) { + Status = IpIo->RcvToken.Ip6Token.Status; + RxData = (IP_IO_IP_RX_DATA *) IpIo->RcvToken.Ip6Token.Packet.RxData; + } else { + return; + } if (EFI_ABORTED == Status) { // @@ -684,9 +1016,9 @@ IpIoListenHandlerDpc ( if (((EFI_SUCCESS != Status) && (EFI_ICMP_ERROR != Status)) || (NULL == RxData)) { // - // Only process the normal packets and the icmp error packets, if RxData is NULL - // with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although - // this should be a bug of the low layer (IP). + // @bug Only process the normal packets and the icmp error packets, if RxData is NULL + // @bug with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although + // @bug this should be a bug of the low layer (IP). // goto Resume; } @@ -695,8 +1027,9 @@ IpIoListenHandlerDpc ( goto CleanUp; } - if ((EFI_IP4 (RxData->Header->SourceAddress) != 0) && - !Ip4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) { + if (IpIo->IpVersion == IP_VERSION_4) { + if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) && + !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) { // // The source address is not zero and it's not a unicast IP address, discard it. // @@ -704,15 +1037,15 @@ IpIoListenHandlerDpc ( } // - // Create a netbuffer representing packet + // Create a netbuffer representing IPv4 packet // Pkt = NetbufFromExt ( - (NET_FRAGMENT *) RxData->FragmentTable, - RxData->FragmentCount, + (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable, + RxData->Ip4RxData.FragmentCount, 0, 0, IpIoExtFree, - RxData->RecycleSignal + RxData->Ip4RxData.RecycleSignal ); if (NULL == Pkt) { goto CleanUp; @@ -721,13 +1054,51 @@ IpIoListenHandlerDpc ( // // Create a net session // - Session.Source = EFI_IP4 (RxData->Header->SourceAddress); - Session.Dest = EFI_IP4 (RxData->Header->DestinationAddress); - Session.IpHdr = RxData->Header; + Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress); + Session.Dest.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress); + Session.IpHdr.Ip4Hdr = RxData->Ip4RxData.Header; + Session.IpVersion = IP_VERSION_4; + } else { + + if (!NetIp6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) { + goto CleanUp; + } + + // + // Create a netbuffer representing IPv6 packet + // + Pkt = NetbufFromExt ( + (NET_FRAGMENT *) RxData->Ip6RxData.FragmentTable, + RxData->Ip6RxData.FragmentCount, + 0, + 0, + IpIoExtFree, + RxData->Ip6RxData.RecycleSignal + ); + if (NULL == Pkt) { + goto CleanUp; + } + + // + // Create a net session + // + CopyMem ( + &Session.Source, + &RxData->Ip6RxData.Header->SourceAddress, + sizeof(EFI_IPv6_ADDRESS) + ); + CopyMem ( + &Session.Dest, + &RxData->Ip6RxData.Header->DestinationAddress, + sizeof(EFI_IPv6_ADDRESS) + ); + Session.IpHdr.Ip6Hdr = RxData->Ip6RxData.Header; + Session.IpVersion = IP_VERSION_6; + } if (EFI_SUCCESS == Status) { - IpIo->PktRcvdNotify (EFI_SUCCESS, (ICMP_ERROR) 0, &Session, Pkt, IpIo->RcvdContext); + IpIo->PktRcvdNotify (EFI_SUCCESS, 0, &Session, Pkt, IpIo->RcvdContext); } else { // // Status is EFI_ICMP_ERROR @@ -741,23 +1112,29 @@ IpIoListenHandlerDpc ( goto Resume; CleanUp: - gBS->SignalEvent (RxData->RecycleSignal); + + if (IpIo->IpVersion == IP_VERSION_4){ + gBS->SignalEvent (RxData->Ip4RxData.RecycleSignal); + } else { + gBS->SignalEvent (RxData->Ip6RxData.RecycleSignal); + } Resume: - Ip->Receive (Ip, &(IpIo->RcvToken)); -} + if (IpIo->IpVersion == IP_VERSION_4){ + ((EFI_IP4_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip4Token)); + } else { + ((EFI_IP6_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip6Token)); + } +} /** - Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK + This function add IpIoListenHandlerDpc to the end of the DPC queue. - @param Event The event signaled. - @param Context The context passed in by the event notifier. - - @return None. + @param[in] Event The event signaled. + @param[in] Context The context passed in by the event notifier. **/ -STATIC VOID EFIAPI IpIoListenHandler ( @@ -768,28 +1145,39 @@ IpIoListenHandler ( // // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK // - NetLibQueueDpc (TPL_CALLBACK, IpIoListenHandlerDpc, Context); + QueueDpc (TPL_CALLBACK, IpIoListenHandlerDpc, Context); } /** Create a new IP_IO instance. + + This function uses IP4/IP6 service binding protocol in Controller to create + an IP4/IP6 child (aka IP4/IP6 instance). - @param Image The image handle of an IP_IO consumer protocol. - @param Controller The controller handle of an IP_IO consumer protocol - installed on. + @param[in] Image The image handle of the driver or application that + consumes IP_IO. + @param[in] Controller The controller handle that has IP4 or IP6 service + binding protocol installed. + @param[in] IpVersion The version of the IP protocol to use, either + IPv4 or IPv6. - @return Pointer to a newly created IP_IO instance. + @return Pointer to a newly created IP_IO instance, or NULL if failed. **/ IP_IO * +EFIAPI IpIoCreate ( IN EFI_HANDLE Image, - IN EFI_HANDLE Controller + IN EFI_HANDLE Controller, + IN UINT8 IpVersion ) { EFI_STATUS Status; IP_IO *IpIo; + EFI_EVENT Event; + + ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); IpIo = AllocateZeroPool (sizeof (IP_IO)); if (NULL == IpIo) { @@ -800,18 +1188,26 @@ IpIoCreate ( InitializeListHead (&(IpIo->IpList)); IpIo->Controller = Controller; IpIo->Image = Image; + IpIo->IpVersion = IpVersion; + Event = NULL; Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY, IpIoListenHandler, IpIo, - &(IpIo->RcvToken.Event) + &Event ); if (EFI_ERROR (Status)) { goto ReleaseIpIo; } + if (IpVersion == IP_VERSION_4) { + IpIo->RcvToken.Ip4Token.Event = Event; + } else { + IpIo->RcvToken.Ip6Token.Event = Event; + } + // // Create an IP child and open IP protocol // @@ -819,6 +1215,7 @@ IpIoCreate ( Controller, Image, &IpIo->ChildHandle, + IpVersion, (VOID **)&(IpIo->Ip) ); if (EFI_ERROR (Status)) { @@ -829,8 +1226,8 @@ IpIoCreate ( ReleaseIpIo: - if (NULL != IpIo->RcvToken.Event) { - gBS->CloseEvent (IpIo->RcvToken.Event); + if (Event != NULL) { + gBS->CloseEvent (Event); } gBS->FreePool (IpIo); @@ -841,47 +1238,81 @@ ReleaseIpIo: /** Open an IP_IO instance for use. - - @param IpIo Pointer to an IP_IO instance that needs to open. - @param OpenData The configuration data for the IP_IO instance. - - @retval EFI_SUCCESS The IP_IO instance opened with OpenData - successfully. - @retval other Error condition occurred. + + This function is called after IpIoCreate(). It is used for configuring the IP + instance and register the callbacks and their context data for sending and + receiving IP packets. + + @param[in, out] IpIo Pointer to an IP_IO instance that needs + to open. + @param[in] OpenData The configuration data and callbacks for + the IP_IO instance. + + @retval EFI_SUCCESS The IP_IO instance opened with OpenData + successfully. + @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to + reopen it. + @retval Others Error condition occurred. **/ EFI_STATUS +EFIAPI IpIoOpen ( - IN IP_IO *IpIo, - IN IP_IO_OPEN_DATA *OpenData + IN OUT IP_IO *IpIo, + IN IP_IO_OPEN_DATA *OpenData ) { EFI_STATUS Status; - EFI_IP4_PROTOCOL *Ip; + VOID *Ip; + UINT8 IpVersion; if (IpIo->IsConfigured) { return EFI_ACCESS_DENIED; } + IpVersion = IpIo->IpVersion; + + ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); + Ip = IpIo->Ip; // // configure ip // - Status = Ip->Configure (Ip, &OpenData->IpConfigData); + if (IpVersion == IP_VERSION_4){ + Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ( + (EFI_IP4_PROTOCOL *) Ip, + &OpenData->IpConfigData.Ip4CfgData + ); + } else { + + Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ( + (EFI_IP6_PROTOCOL *) Ip, + &OpenData->IpConfigData.Ip6CfgData + ); + } + if (EFI_ERROR (Status)) { return Status; } // - // bugbug: to delete the default route entry in this Ip, if it is: - // (0.0.0.0, 0.0.0.0, 0.0.0.0). Delete this statement if Ip modified - // its code + // @bug To delete the default route entry in this Ip, if it is: + // @bug (0.0.0.0, 0.0.0.0, 0.0.0.0). Delete this statement if Ip modified + // @bug its code // - Status = Ip->Routes (Ip, TRUE, &mZeroIp4Addr, &mZeroIp4Addr, &mZeroIp4Addr); + if (IpVersion == IP_VERSION_4){ + Status = ((EFI_IP4_PROTOCOL *) Ip)->Routes ( + (EFI_IP4_PROTOCOL *) Ip, + TRUE, + &mZeroIp4Addr, + &mZeroIp4Addr, + &mZeroIp4Addr + ); - if (EFI_ERROR (Status) && (EFI_NOT_FOUND != Status)) { - return Status; + if (EFI_ERROR (Status) && (EFI_NOT_FOUND != Status)) { + return Status; + } } IpIo->PktRcvdNotify = OpenData->PktRcvdNotify; @@ -890,15 +1321,32 @@ IpIoOpen ( IpIo->RcvdContext = OpenData->RcvdContext; IpIo->SndContext = OpenData->SndContext; - IpIo->Protocol = OpenData->IpConfigData.DefaultProtocol; + if (IpVersion == IP_VERSION_4){ + IpIo->Protocol = OpenData->IpConfigData.Ip4CfgData.DefaultProtocol; - // - // start to listen incoming packet - // - Status = Ip->Receive (Ip, &(IpIo->RcvToken)); - if (EFI_ERROR (Status)) { - Ip->Configure (Ip, NULL); - goto ErrorExit; + // + // start to listen incoming packet + // + Status = ((EFI_IP4_PROTOCOL *) Ip)->Receive ( + (EFI_IP4_PROTOCOL *) Ip, + &(IpIo->RcvToken.Ip4Token) + ); + if (EFI_ERROR (Status)) { + ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL); + goto ErrorExit; + } + + } else { + + IpIo->Protocol = OpenData->IpConfigData.Ip6CfgData.DefaultProtocol; + Status = ((EFI_IP6_PROTOCOL *) Ip)->Receive ( + (EFI_IP6_PROTOCOL *) Ip, + &(IpIo->RcvToken.Ip6Token) + ); + if (EFI_ERROR (Status)) { + ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL); + goto ErrorExit; + } } IpIo->IsConfigured = TRUE; @@ -912,26 +1360,35 @@ ErrorExit: /** Stop an IP_IO instance. + + This function is paired with IpIoOpen(). The IP_IO will be unconfigured and all + the pending send/receive tokens will be canceled. - @param IpIo Pointer to the IP_IO instance that needs to stop. + @param[in, out] IpIo Pointer to the IP_IO instance that needs to stop. - @retval EFI_SUCCESS The IP_IO instance stopped successfully. - @retval other Error condition occurred. + @retval EFI_SUCCESS The IP_IO instance stopped successfully. + @retval Others Error condition occurred. **/ EFI_STATUS +EFIAPI IpIoStop ( - IN IP_IO *IpIo + IN OUT IP_IO *IpIo ) { EFI_STATUS Status; - EFI_IP4_PROTOCOL *Ip; + VOID *Ip; IP_IO_IP_INFO *IpInfo; + UINT8 IpVersion; if (!IpIo->IsConfigured) { return EFI_SUCCESS; } + IpVersion = IpIo->IpVersion; + + ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); + // // Remove the IpIo from the active IpIo list. // @@ -942,7 +1399,11 @@ IpIoStop ( // // Configure NULL Ip // - Status = Ip->Configure (Ip, NULL); + if (IpVersion == IP_VERSION_4) { + Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL); + } else { + Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL); + } if (EFI_ERROR (Status)) { return Status; } @@ -960,14 +1421,18 @@ IpIoStop ( } // - // All pending snd tokens should be flushed by reseting the IP instances. + // All pending send tokens should be flushed by reseting the IP instances. // ASSERT (IsListEmpty (&IpIo->PendingSndList)); // // Close the receive event. // - gBS->CloseEvent (IpIo->RcvToken.Event); + if (IpVersion == IP_VERSION_4){ + gBS->CloseEvent (IpIo->RcvToken.Ip4Token.Event); + } else { + gBS->CloseEvent (IpIo->RcvToken.Ip6Token.Event); + } return EFI_SUCCESS; } @@ -975,17 +1440,21 @@ IpIoStop ( /** Destroy an IP_IO instance. + + This function is paired with IpIoCreate(). The IP_IO will be closed first. + Resource will be freed afterwards. See IpIoCloseProtocolDestroyIpChild(). - @param IpIo Pointer to the IP_IO instance that needs to - destroy. + @param[in, out] IpIo Pointer to the IP_IO instance that needs to be + destroyed. - @retval EFI_SUCCESS The IP_IO instance destroyed successfully. - @retval other Error condition occurred. + @retval EFI_SUCCESS The IP_IO instance destroyed successfully. + @retval Others Error condition occurred. **/ EFI_STATUS +EFIAPI IpIoDestroy ( - IN IP_IO *IpIo + IN OUT IP_IO *IpIo ) { // @@ -996,7 +1465,12 @@ IpIoDestroy ( // // Close the IP protocol and destroy the child. // - IpIoCloseProtocolDestroyIpChild (IpIo->Controller, IpIo->Image, IpIo->ChildHandle); + IpIoCloseProtocolDestroyIpChild ( + IpIo->Controller, + IpIo->Image, + IpIo->ChildHandle, + IpIo->IpVersion + ); gBS->FreePool (IpIo); @@ -1006,36 +1480,45 @@ IpIoDestroy ( /** Send out an IP packet. - - @param IpIo Pointer to an IP_IO instance used for sending IP - packet. - @param Pkt Pointer to the IP packet to be sent. - @param Sender The IP protocol instance used for sending. - @param NotifyData - @param Dest The destination IP address to send this packet to. - @param OverrideData The data to override some configuration of the IP - instance used for sending. - - @retval EFI_SUCCESS The operation is completed successfully. - @retval EFI_NOT_STARTED The IpIo is not configured. - @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. + + This function is called after IpIoOpen(). The data to be sent are wrapped in + Pkt. The IP instance wrapped in IpIo is used for sending by default but can be + overriden by Sender. Other sending configs, like source address and gateway + address etc., are specified in OverrideData. + + @param[in, out] IpIo Pointer to an IP_IO instance used for sending IP + packet. + @param[in, out] Pkt Pointer to the IP packet to be sent. + @param[in] Sender The IP protocol instance used for sending. + @param[in] Context Optional context data. + @param[in] NotifyData Optional notify data. + @param[in] Dest The destination IP address to send this packet to. + @param[in] OverrideData The data to override some configuration of the IP + instance used for sending. + + @retval EFI_SUCCESS The operation is completed successfully. + @retval EFI_NOT_STARTED The IpIo is not configured. + @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. **/ EFI_STATUS +EFIAPI IpIoSend ( - IN IP_IO *IpIo, - IN NET_BUF *Pkt, - IN IP_IO_IP_INFO *Sender, - IN VOID *Context OPTIONAL, - IN VOID *NotifyData OPTIONAL, - IN IP4_ADDR Dest, - IN IP_IO_OVERRIDE *OverrideData + IN OUT IP_IO *IpIo, + IN OUT NET_BUF *Pkt, + IN IP_IO_IP_INFO *Sender OPTIONAL, + IN VOID *Context OPTIONAL, + IN VOID *NotifyData OPTIONAL, + IN EFI_IP_ADDRESS *Dest, + IN IP_IO_OVERRIDE *OverrideData OPTIONAL ) { EFI_STATUS Status; - EFI_IP4_PROTOCOL *Ip; + VOID *Ip; IP_IO_SEND_ENTRY *SndEntry; + ASSERT ((IpIo->IpVersion != IP_VERSION_4) || (Dest != NULL)); + if (!IpIo->IsConfigured) { return EFI_NOT_STARTED; } @@ -1053,7 +1536,18 @@ IpIoSend ( // // Send this Packet // - Status = Ip->Transmit (Ip, SndEntry->SndToken); + if (IpIo->IpVersion == IP_VERSION_4){ + Status = ((EFI_IP4_PROTOCOL *) Ip)->Transmit ( + (EFI_IP4_PROTOCOL *) Ip, + &SndEntry->SndToken.Ip4Token + ); + } else { + Status = ((EFI_IP6_PROTOCOL *) Ip)->Transmit ( + (EFI_IP6_PROTOCOL *) Ip, + &SndEntry->SndToken.Ip6Token + ); + } + if (EFI_ERROR (Status)) { IpIoDestroySndEntry (SndEntry); } @@ -1065,13 +1559,12 @@ IpIoSend ( /** Cancel the IP transmit token which wraps this Packet. - @param IpIo Pointer to the IP_IO instance. - @param Packet Pointer to the packet to cancel. - - @return N/A. + @param[in] IpIo Pointer to the IP_IO instance. + @param[in] Packet Pointer to the packet of NET_BUF to cancel. **/ VOID +EFIAPI IpIoCancelTxToken ( IN IP_IO *IpIo, IN VOID *Packet @@ -1079,9 +1572,9 @@ IpIoCancelTxToken ( { LIST_ENTRY *Node; IP_IO_SEND_ENTRY *SndEntry; - EFI_IP4_PROTOCOL *Ip; + VOID *Ip; - ASSERT (IpIo && Packet); + ASSERT ((IpIo != NULL) && (Packet != NULL)); NET_LIST_FOR_EACH (Node, &IpIo->PendingSndList) { @@ -1090,7 +1583,18 @@ IpIoCancelTxToken ( if (SndEntry->Pkt == Packet) { Ip = SndEntry->Ip; - Ip->Cancel (Ip, SndEntry->SndToken); + + if (IpIo->IpVersion == IP_VERSION_4) { + ((EFI_IP4_PROTOCOL *) Ip)->Cancel ( + (EFI_IP4_PROTOCOL *) Ip, + &SndEntry->SndToken.Ip4Token + ); + } else { + ((EFI_IP6_PROTOCOL *) Ip)->Cancel ( + (EFI_IP6_PROTOCOL *) Ip, + &SndEntry->SndToken.Ip6Token + ); + } break; } @@ -1101,26 +1605,32 @@ IpIoCancelTxToken ( /** Add a new IP instance for sending data. + + The function is used to add the IP_IO to the IP_IO sending list. The caller + can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to send + data. - @param IpIo Pointer to a IP_IO instance to add a new IP - instance for sending purpose. + @param[in, out] IpIo Pointer to a IP_IO instance to add a new IP + instance for sending purpose. - @return Pointer to the created IP_IO_IP_INFO structure, NULL is failed. + @return Pointer to the created IP_IO_IP_INFO structure, NULL if failed. **/ IP_IO_IP_INFO * +EFIAPI IpIoAddIp ( - IN IP_IO *IpIo + IN OUT IP_IO *IpIo ) { EFI_STATUS Status; IP_IO_IP_INFO *IpInfo; + EFI_EVENT Event; - ASSERT (IpIo); + ASSERT (IpIo != NULL); IpInfo = AllocatePool (sizeof (IP_IO_IP_INFO)); if (IpInfo == NULL) { - return IpInfo; + return NULL; } // @@ -1129,17 +1639,20 @@ IpIoAddIp ( // InitializeListHead (&IpInfo->Entry); IpInfo->ChildHandle = NULL; - IpInfo->Addr = 0; - IpInfo->SubnetMask = 0; - IpInfo->RefCnt = 1; + ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr)); + ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask)); + + IpInfo->RefCnt = 1; + IpInfo->IpVersion = IpIo->IpVersion; // - // Create the IP instance and open the Ip4 protocol. + // Create the IP instance and open the IP protocol. // Status = IpIoCreateIpChildOpenProtocol ( IpIo->Controller, IpIo->Image, &IpInfo->ChildHandle, + IpInfo->IpVersion, (VOID **) &IpInfo->Ip ); if (EFI_ERROR (Status)) { @@ -1154,12 +1667,18 @@ IpIoAddIp ( TPL_NOTIFY, IpIoDummyHandler, IpInfo, - &IpInfo->DummyRcvToken.Event + &Event ); if (EFI_ERROR (Status)) { goto ReleaseIpChild; } + if (IpInfo->IpVersion == IP_VERSION_4) { + IpInfo->DummyRcvToken.Ip4Token.Event = Event; + } else { + IpInfo->DummyRcvToken.Ip6Token.Event = Event; + } + // // Link this IpInfo into the IpIo. // @@ -1172,7 +1691,8 @@ ReleaseIpChild: IpIoCloseProtocolDestroyIpChild ( IpIo->Controller, IpIo->Image, - IpInfo->ChildHandle + IpInfo->ChildHandle, + IpInfo->IpVersion ); ReleaseIpInfo: @@ -1184,72 +1704,159 @@ ReleaseIpInfo: /** - Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData + Configure the IP instance of this IpInfo and start the receiving if IpConfigData is not NULL. - @param IpInfo Pointer to the IP_IO_IP_INFO instance. - @param Ip4ConfigData The IP4 configure data used to configure the ip - instance, if NULL the ip instance is reseted. If - UseDefaultAddress is set to TRUE, and the configure - operation succeeds, the default address information - is written back in this Ip4ConfigData. + @param[in, out] IpInfo Pointer to the IP_IO_IP_INFO instance. + @param[in, out] IpConfigData The IP configure data used to configure the IP + instance, if NULL the IP instance is reset. If + UseDefaultAddress is set to TRUE, and the configure + operation succeeds, the default address information + is written back in this IpConfigData. - @retval EFI_STATUS The status returned by IP4->Configure or - IP4->Receive. + @retval EFI_SUCCESS The IP instance of this IpInfo is configured successfully + or no need to reconfigure it. + @retval Others Configuration fails. **/ EFI_STATUS +EFIAPI IpIoConfigIp ( - IN IP_IO_IP_INFO *IpInfo, - IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData OPTIONAL + IN OUT IP_IO_IP_INFO *IpInfo, + IN OUT VOID *IpConfigData OPTIONAL ) { EFI_STATUS Status; - EFI_IP4_PROTOCOL *Ip; + VOID *Ip; + UINT8 IpVersion; EFI_IP4_MODE_DATA Ip4ModeData; + EFI_IP6_MODE_DATA Ip6ModeData; - ASSERT (IpInfo); + ASSERT (IpInfo != NULL); if (IpInfo->RefCnt > 1) { // // This IP instance is shared, don't reconfigure it until it has only one // consumer. Currently, only the tcp children cloned from their passive parent - // will share the same IP. So this cases only happens while Ip4ConfigData is NULL, + // will share the same IP. So this cases only happens while IpConfigData is NULL, // let the last consumer clean the IP instance. // return EFI_SUCCESS; } + IpVersion = IpInfo->IpVersion; + ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); + Ip = IpInfo->Ip; - Status = Ip->Configure (Ip, Ip4ConfigData); + if (IpInfo->IpVersion == IP_VERSION_4) { + Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, IpConfigData); + } else { + Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, IpConfigData); + } + if (EFI_ERROR (Status)) { goto OnExit; } - if (Ip4ConfigData != NULL) { + if (IpConfigData != NULL) { + if (IpInfo->IpVersion == IP_VERSION_4){ - if (Ip4ConfigData->UseDefaultAddress) { - Ip->GetModeData (Ip, &Ip4ModeData, NULL, NULL); + if (((EFI_IP4_CONFIG_DATA *) IpConfigData)->UseDefaultAddress) { + ((EFI_IP4_PROTOCOL *) Ip)->GetModeData ( + (EFI_IP4_PROTOCOL *) Ip, + &Ip4ModeData, + NULL, + NULL + ); - Ip4ConfigData->StationAddress = Ip4ModeData.ConfigData.StationAddress; - Ip4ConfigData->SubnetMask = Ip4ModeData.ConfigData.SubnetMask; + ((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress = Ip4ModeData.ConfigData.StationAddress; + ((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask = Ip4ModeData.ConfigData.SubnetMask; } - CopyMem (&IpInfo->Addr, &Ip4ConfigData->StationAddress, sizeof (IP4_ADDR)); - CopyMem (&IpInfo->SubnetMask, &Ip4ConfigData->SubnetMask, sizeof (IP4_ADDR)); - - Status = Ip->Receive (Ip, &IpInfo->DummyRcvToken); + CopyMem ( + &IpInfo->Addr.Addr, + &((EFI_IP4_CONFIG_DATA *) IpConfigData)->StationAddress, + sizeof (IP4_ADDR) + ); + CopyMem ( + &IpInfo->PreMask.SubnetMask, + &((EFI_IP4_CONFIG_DATA *) IpConfigData)->SubnetMask, + sizeof (IP4_ADDR) + ); + + Status = ((EFI_IP4_PROTOCOL *) Ip)->Receive ( + (EFI_IP4_PROTOCOL *) Ip, + &IpInfo->DummyRcvToken.Ip4Token + ); if (EFI_ERROR (Status)) { - Ip->Configure (Ip, NULL); + ((EFI_IP4_PROTOCOL*)Ip)->Configure (Ip, NULL); } } else { + ((EFI_IP6_PROTOCOL *) Ip)->GetModeData ( + (EFI_IP6_PROTOCOL *) Ip, + &Ip6ModeData, + NULL, + NULL + ); + + if (Ip6ModeData.IsConfigured) { + CopyMem ( + &((EFI_IP6_CONFIG_DATA *) IpConfigData)->StationAddress, + &Ip6ModeData.ConfigData.StationAddress, + sizeof (EFI_IPv6_ADDRESS) + ); + + if (Ip6ModeData.AddressList != NULL) { + FreePool (Ip6ModeData.AddressList); + } + + if (Ip6ModeData.GroupTable != NULL) { + FreePool (Ip6ModeData.GroupTable); + } + + if (Ip6ModeData.RouteTable != NULL) { + FreePool (Ip6ModeData.RouteTable); + } + + if (Ip6ModeData.NeighborCache != NULL) { + FreePool (Ip6ModeData.NeighborCache); + } + + if (Ip6ModeData.PrefixTable != NULL) { + FreePool (Ip6ModeData.PrefixTable); + } + + if (Ip6ModeData.IcmpTypeList != NULL) { + FreePool (Ip6ModeData.IcmpTypeList); + } + + } else { + Status = EFI_NO_MAPPING; + goto OnExit; + } + + CopyMem ( + &IpInfo->Addr, + &Ip6ModeData.ConfigData.StationAddress, + sizeof (EFI_IPv6_ADDRESS) + ); + + Status = ((EFI_IP6_PROTOCOL *) Ip)->Receive ( + (EFI_IP6_PROTOCOL *) Ip, + &IpInfo->DummyRcvToken.Ip6Token + ); + if (EFI_ERROR (Status)) { + ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL); + } + } + } else { // - // The IP instance is reseted, set the stored Addr and SubnetMask to zero. + // The IP instance is reset, set the stored Addr and SubnetMask to zero. // - IpInfo->Addr = 0; - IpInfo->SubnetMask =0; + ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr)); + ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask)); } OnExit: @@ -1261,19 +1868,25 @@ OnExit: /** Destroy an IP instance maintained in IpIo->IpList for sending purpose. + + This function pairs with IpIoAddIp(). The IpInfo is previously created by + IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance + will be dstroyed if the RefCnt is zero. - @param IpIo Pointer to the IP_IO instance. - @param IpInfo Pointer to the IpInfo to be removed. - - @return None. + @param[in] IpIo Pointer to the IP_IO instance. + @param[in] IpInfo Pointer to the IpInfo to be removed. **/ VOID +EFIAPI IpIoRemoveIp ( - IN IP_IO *IpIo, - IN IP_IO_IP_INFO *IpInfo + IN IP_IO *IpIo, + IN IP_IO_IP_INFO *IpInfo ) { + + UINT8 IpVersion; + ASSERT (IpInfo->RefCnt > 0); NET_PUT_REF (IpInfo); @@ -1283,33 +1896,69 @@ IpIoRemoveIp ( return; } + IpVersion = IpIo->IpVersion; + + ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); + RemoveEntryList (&IpInfo->Entry); - IpInfo->Ip->Configure (IpInfo->Ip, NULL); + if (IpVersion == IP_VERSION_4){ + ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Configure ( + (EFI_IP4_PROTOCOL *) (IpInfo->Ip), + NULL + ); + IpIoCloseProtocolDestroyIpChild ( + IpIo->Controller, + IpIo->Image, + IpInfo->ChildHandle, + IP_VERSION_4 + ); + + gBS->CloseEvent (IpInfo->DummyRcvToken.Ip4Token.Event); - IpIoCloseProtocolDestroyIpChild (IpIo->Controller, IpIo->Image, IpInfo->ChildHandle); + } else { - gBS->CloseEvent (IpInfo->DummyRcvToken.Event); + ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Configure ( + (EFI_IP6_PROTOCOL *) (IpInfo->Ip), + NULL + ); - gBS->FreePool (IpInfo); + IpIoCloseProtocolDestroyIpChild ( + IpIo->Controller, + IpIo->Image, + IpInfo->ChildHandle, + IP_VERSION_6 + ); + + gBS->CloseEvent (IpInfo->DummyRcvToken.Ip6Token.Event); + } + + FreePool (IpInfo); } /** Find the first IP protocol maintained in IpIo whose local - address is the same with Src. + address is the same as Src. + + This function is called when the caller needs the IpIo to send data to the + specified Src. The IpIo was added previously by IpIoAddIp(). - @param IpIo Pointer to the pointer of the IP_IO instance. - @param Src The local IP address. + @param[in, out] IpIo Pointer to the pointer of the IP_IO instance. + @param[in] IpVersion The version of the IP protocol to use, either + IPv4 or IPv6. + @param[in] Src The local IP address. @return Pointer to the IP protocol can be used for sending purpose and its local - @return address is the same with Src. + address is the same with Src. **/ IP_IO_IP_INFO * +EFIAPI IpIoFindSender ( - IN OUT IP_IO **IpIo, - IN IP4_ADDR Src + IN OUT IP_IO **IpIo, + IN UINT8 IpVersion, + IN EFI_IP_ADDRESS *Src ) { LIST_ENTRY *IpIoEntry; @@ -1317,20 +1966,32 @@ IpIoFindSender ( LIST_ENTRY *IpInfoEntry; IP_IO_IP_INFO *IpInfo; + ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); + NET_LIST_FOR_EACH (IpIoEntry, &mActiveIpIoList) { IpIoPtr = NET_LIST_USER_STRUCT (IpIoEntry, IP_IO, Entry); - if ((*IpIo != NULL) && (*IpIo != IpIoPtr)) { + if (((*IpIo != NULL) && (*IpIo != IpIoPtr)) || (IpIoPtr->IpVersion != IpVersion)) { continue; } NET_LIST_FOR_EACH (IpInfoEntry, &IpIoPtr->IpList) { IpInfo = NET_LIST_USER_STRUCT (IpInfoEntry, IP_IO_IP_INFO, Entry); + if (IpInfo->IpVersion == IP_VERSION_4){ + + if (EFI_IP4_EQUAL (&IpInfo->Addr.v4, &Src->v4)) { + *IpIo = IpIoPtr; + return IpInfo; + } + + } else { + + if (EFI_IP6_EQUAL (&IpInfo->Addr.v6, &Src->v6)) { + *IpIo = IpIoPtr; + return IpInfo; + } + } - if (IpInfo->Addr == Src) { - *IpIo = IpIoPtr; - return IpInfo; - } } } @@ -1342,61 +2003,154 @@ IpIoFindSender ( /** - Get the ICMP error map information, the ErrorStatus will be returned. - The IsHard and Notify are optional. If they are not NULL, this rouine will - fill them. - We move IcmpErrMap[] to local variable to enable EBC build. + Get the ICMP error map information. + + The ErrorStatus will be returned. The IsHard and Notify are optional. If they + are not NULL, this routine will fill them. - @param IcmpError IcmpError Type - @param IsHard Whether it is a hard error - @param Notify Whether it need to notify SockError + @param[in] IcmpError IcmpError Type. + @param[in] IpVersion The version of the IP protocol to use, + either IPv4 or IPv6. + + @param[out] IsHard Whether it is a hard error. + @param[out] Notify Whether it need to notify SockError. - @return ICMP Error Status + @return ICMP Error Status, such as EFI_NETWORK_UNREACHABLE. **/ EFI_STATUS +EFIAPI IpIoGetIcmpErrStatus ( - IN ICMP_ERROR IcmpError, - OUT BOOLEAN *IsHard, OPTIONAL - OUT BOOLEAN *Notify OPTIONAL + IN UINT8 IcmpError, + IN UINT8 IpVersion, + OUT BOOLEAN *IsHard OPTIONAL, + OUT BOOLEAN *Notify OPTIONAL ) { - ASSERT ((IcmpError >= ICMP_ERR_UNREACH_NET) && (IcmpError <= ICMP_ERR_PARAMPROB)); + if (IpVersion == IP_VERSION_4 ) { + ASSERT (IcmpError <= ICMP_ERR_PARAMPROB); - if (IsHard != NULL) { - *IsHard = mIcmpErrMap[IcmpError].IsHard; - } + if (IsHard != NULL) { + *IsHard = mIcmpErrMap[IcmpError].IsHard; + } - if (Notify != NULL) { - *Notify = mIcmpErrMap[IcmpError].Notify; - } + if (Notify != NULL) { + *Notify = mIcmpErrMap[IcmpError].Notify; + } + + switch (IcmpError) { + case ICMP_ERR_UNREACH_NET: + return EFI_NETWORK_UNREACHABLE; + + case ICMP_ERR_TIMXCEED_INTRANS: + case ICMP_ERR_TIMXCEED_REASS: + case ICMP_ERR_UNREACH_HOST: + return EFI_HOST_UNREACHABLE; + + case ICMP_ERR_UNREACH_PROTOCOL: + return EFI_PROTOCOL_UNREACHABLE; + + case ICMP_ERR_UNREACH_PORT: + return EFI_PORT_UNREACHABLE; + + case ICMP_ERR_MSGSIZE: + case ICMP_ERR_UNREACH_SRCFAIL: + case ICMP_ERR_QUENCH: + case ICMP_ERR_PARAMPROB: + return EFI_ICMP_ERROR; + + default: + ASSERT (FALSE); + return EFI_UNSUPPORTED; + } + + } else if (IpVersion == IP_VERSION_6) { + + ASSERT (IcmpError <= ICMP6_ERR_PARAMPROB_IPV6OPTION); + + if (IsHard != NULL) { + *IsHard = mIcmp6ErrMap[IcmpError].IsHard; + } + + if (Notify != NULL) { + *Notify = mIcmp6ErrMap[IcmpError].Notify; + } + + switch (IcmpError) { + case ICMP6_ERR_UNREACH_NET: + return EFI_NETWORK_UNREACHABLE; - switch (IcmpError) { - case ICMP_ERR_UNREACH_NET: - return EFI_NETWORK_UNREACHABLE; + case ICMP6_ERR_UNREACH_HOST: + case ICMP6_ERR_TIMXCEED_HOPLIMIT: + case ICMP6_ERR_TIMXCEED_REASS: + return EFI_HOST_UNREACHABLE; - case ICMP_ERR_TIMXCEED_INTRANS: - case ICMP_ERR_TIMXCEED_REASS: - case ICMP_ERR_UNREACH_HOST: - return EFI_HOST_UNREACHABLE; + case ICMP6_ERR_UNREACH_PROTOCOL: + return EFI_PROTOCOL_UNREACHABLE; + + case ICMP6_ERR_UNREACH_PORT: + return EFI_PORT_UNREACHABLE; - case ICMP_ERR_UNREACH_PROTOCOL: - return EFI_PROTOCOL_UNREACHABLE; + case ICMP6_ERR_PACKAGE_TOOBIG: + case ICMP6_ERR_PARAMPROB_HEADER: + case ICMP6_ERR_PARAMPROB_NEXHEADER: + case ICMP6_ERR_PARAMPROB_IPV6OPTION: + return EFI_ICMP_ERROR; - case ICMP_ERR_UNREACH_PORT: - return EFI_PORT_UNREACHABLE; + default: + ASSERT (FALSE); + return EFI_UNSUPPORTED; + } - case ICMP_ERR_MSGSIZE: - case ICMP_ERR_UNREACH_SRCFAIL: - case ICMP_ERR_QUENCH: - case ICMP_ERR_PARAMPROB: - return EFI_ICMP_ERROR; + } else { + // + // Should never be here + // + ASSERT (FALSE); + return EFI_UNSUPPORTED; } +} - // - // will never run here! - // - ASSERT (FALSE); - return EFI_UNSUPPORTED; + +/** + Refresh the remote peer's Neighbor Cache entries. + + This function is called when the caller needs the IpIo to refresh the existing + IPv6 neighbor cache entries since the neighbor is considered reachable by the + node has recently received a confirmation that packets sent recently to the + neighbor were received by its IP layer. + + @param[in] IpIo Pointer to an IP_IO instance + @param[in] Neighbor The IP address of the neighbor + @param[in] Timeout Time in 100-ns units that this entry will + remain in the neighbor cache. A value of + zero means that the entry is permanent. + A value of non-zero means that the entry is + dynamic and will be deleted after Timeout. + + @retval EFI_SUCCESS The operation is completed successfully. + @retval EFI_NOT_STARTED The IpIo is not configured. + @retval EFI_INVALID_PARAMETER Neighbor Address is invalid. + @retval EFI_NOT_FOUND The neighbor cache entry is not in the + neighbor table. + @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. + +**/ +EFI_STATUS +IpIoRefreshNeighbor ( + IN IP_IO *IpIo, + IN EFI_IP_ADDRESS *Neighbor, + IN UINT32 Timeout + ) +{ + EFI_IP6_PROTOCOL *Ip; + + if (!IpIo->IsConfigured || IpIo->IpVersion != IP_VERSION_6) { + return EFI_NOT_STARTED; + } + + Ip = (EFI_IP6_PROTOCOL *) (IpIo->Ip); + + return Ip->Neighbors (Ip, FALSE, &Neighbor->v6, NULL, Timeout, TRUE); }