/** @file\r
IpIo Library.\r
\r
-Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
+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
http://opensource.org/licenses/bsd-license.php\r
#include <Library/DpcLib.h>\r
\r
\r
-LIST_ENTRY mActiveIpIoList = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mActiveIpIoList = {\r
&mActiveIpIoList,\r
&mActiveIpIoList\r
};\r
\r
-EFI_IP4_CONFIG_DATA mIp4IoDefaultIpConfigData = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_IP4_CONFIG_DATA mIp4IoDefaultIpConfigData = {\r
EFI_IP_PROTO_UDP,\r
FALSE,\r
TRUE,\r
0\r
};\r
\r
-EFI_IP6_CONFIG_DATA mIp6IoDefaultIpConfigData = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_IP6_CONFIG_DATA mIp6IoDefaultIpConfigData = {\r
EFI_IP_PROTO_UDP,\r
FALSE,\r
TRUE,\r
0\r
};\r
\r
-ICMP_ERROR_INFO mIcmpErrMap[10] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED ICMP_ERROR_INFO mIcmpErrMap[10] = {\r
{FALSE, TRUE }, // ICMP_ERR_UNREACH_NET\r
{FALSE, TRUE }, // ICMP_ERR_UNREACH_HOST\r
{TRUE, TRUE }, // ICMP_ERR_UNREACH_PROTOCOL\r
{FALSE, TRUE } // ICMP_ERR_PARAMPROB\r
};\r
\r
-ICMP_ERROR_INFO mIcmp6ErrMap[10] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED ICMP_ERROR_INFO mIcmp6ErrMap[10] = {\r
{FALSE, TRUE}, // ICMP6_ERR_UNREACH_NET\r
{FALSE, TRUE}, // ICMP6_ERR_UNREACH_HOST\r
{TRUE, TRUE}, // ICMP6_ERR_UNREACH_PROTOCOL\r
\r
@retval EFI_SUCCESS The IP child is created and the IP protocol\r
interface is retrieved.\r
+ @retval EFI_UNSUPPORTED Upsupported IpVersion.\r
@retval Others The required operation failed.\r
\r
**/\r
\r
@retval EFI_SUCCESS The IP protocol is closed and the relevant IP child\r
is destroyed.\r
+ @retval EFI_UNSUPPORTED Upsupported IpVersion.\r
@retval Others The required operation failed.\r
\r
**/\r
//\r
// Close the previously openned IP protocol.\r
//\r
- gBS->CloseProtocol (\r
- ChildHandle,\r
- IpProtocolGuid,\r
- ImageHandle,\r
- ControllerHandle\r
- );\r
+ Status = gBS->CloseProtocol (\r
+ ChildHandle,\r
+ IpProtocolGuid,\r
+ ImageHandle,\r
+ ControllerHandle\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
//\r
// Destroy the IP child.\r
//\r
- Status = NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- ImageHandle,\r
- ServiceBindingGuid,\r
- ChildHandle\r
- );\r
-\r
- return Status;\r
+ return NetLibDestroyServiceChild (\r
+ ControllerHandle,\r
+ ImageHandle,\r
+ ServiceBindingGuid,\r
+ ChildHandle\r
+ );\r
}\r
\r
/**\r
UINT8 Type;\r
UINT8 Code;\r
UINT32 TrimBytes;\r
-\r
+ \r
+ ASSERT (IpIo != NULL);\r
+ ASSERT (Pkt != NULL);\r
+ ASSERT (Session != NULL);\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
+ \r
//\r
// Check the ICMP packet length.\r
//\r
+ if (Pkt->TotalSize < sizeof (IP4_ICMP_ERROR_HEAD)) {\r
+ return EFI_ABORTED;\r
+ }\r
+ \r
+ IcmpHdr = NET_PROTO_HDR (Pkt, IP4_ICMP_ERROR_HEAD);\r
+ IpHdr = (EFI_IP4_HEADER *) (&IcmpHdr->IpHead);\r
+\r
if (Pkt->TotalSize < ICMP_ERRLEN (IpHdr)) {\r
\r
return EFI_ABORTED;\r
TrimBytes = (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr);\r
\r
NetbufTrim (Pkt, TrimBytes, TRUE);\r
-\r
- IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+ \r
+ //\r
+ // If the input packet has invalid format, and TrimBytes is larger than \r
+ // the packet size, the NetbufTrim might trim the packet to zero.\r
+ //\r
+ if (Pkt->TotalSize != 0) {\r
+ IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+ }\r
\r
return EFI_SUCCESS; \r
}\r
UINT32 TrimBytes;\r
BOOLEAN Flag;\r
\r
+ ASSERT (IpIo != NULL);\r
+ ASSERT (Pkt != NULL);\r
+ ASSERT (Session != NULL);\r
ASSERT (IpIo->IpVersion == IP_VERSION_6);\r
\r
//\r
\r
NetbufTrim (Pkt, TrimBytes, TRUE);\r
\r
- IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+ //\r
+ // If the input packet has invalid format, and TrimBytes is larger than \r
+ // the packet size, the NetbufTrim might trim the packet to zero.\r
+ //\r
+ if (Pkt->TotalSize != 0) {\r
+ IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+ }\r
\r
return EFI_SUCCESS;\r
}\r
\r
**/\r
VOID\r
+EFIAPI\r
IpIoExtFree (\r
IN VOID *Event\r
)\r
IpIoCreateSndEntry (\r
IN OUT IP_IO *IpIo,\r
IN OUT NET_BUF *Pkt,\r
- IN VOID *Sender,\r
+ IN IP_IO_IP_PROTOCOL Sender,\r
IN VOID *Context OPTIONAL,\r
IN VOID *NotifyData OPTIONAL,\r
IN EFI_IP_ADDRESS *Dest OPTIONAL,\r
\r
Ip4TxData = &TxData->Ip4TxData;\r
\r
- CopyMem (&Ip4TxData->DestinationAddress, Dest, sizeof (EFI_IPv4_ADDRESS));\r
+ IP4_COPY_ADDRESS (&Ip4TxData->DestinationAddress, Dest);\r
\r
Ip4TxData->OverrideData = &OverrideData->Ip4OverrideData;\r
Ip4TxData->OptionsLength = 0;\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
+ IpInfo->Ip.Ip4->Receive (\r
+ IpInfo->Ip.Ip4,\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
+ IpInfo->Ip.Ip6->Receive (\r
+ IpInfo->Ip.Ip6,\r
+ &IpInfo->DummyRcvToken.Ip6Token\r
+ );\r
}\r
}\r
\r
IP_IO *IpIo;\r
EFI_STATUS Status;\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
- Ip = IpIo->Ip;\r
\r
if (IpIo->IpVersion == IP_VERSION_4) {\r
Status = IpIo->RcvToken.Ip4Token.Status;\r
}\r
\r
if (IpIo->IpVersion == IP_VERSION_4) {\r
+ ASSERT (RxData->Ip4RxData.Header != NULL);\r
+ if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress))) {\r
+ //\r
+ // The source address is a broadcast address, discard it.\r
+ //\r
+ goto CleanUp;\r
+ }\r
if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&\r
- !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) {\r
+ (IpIo->SubnetMask != 0) &&\r
+ IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), IpIo->SubnetMask) &&\r
+ !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), IpIo->SubnetMask)) {\r
+ //\r
+ // The source address is not zero and it's not a unicast IP address, discard it.\r
+ //\r
+ goto CleanUp;\r
+ }\r
+\r
+ if (RxData->Ip4RxData.DataLength == 0) {\r
+ //\r
+ // Discard zero length data payload packet.\r
+ //\r
+ goto CleanUp;\r
+ }\r
+\r
//\r
- // The source address is not zero and it's not a unicast IP address, discard it.\r
+ // The fragment should always be valid for non-zero length packet.\r
//\r
- goto CleanUp;\r
- }\r
+ ASSERT (RxData->Ip4RxData.FragmentCount != 0);\r
\r
- //\r
- // Create a netbuffer representing IPv4 packet\r
- //\r
- Pkt = NetbufFromExt (\r
- (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,\r
- RxData->Ip4RxData.FragmentCount,\r
- 0,\r
- 0,\r
- IpIoExtFree,\r
- RxData->Ip4RxData.RecycleSignal\r
- );\r
- if (NULL == Pkt) {\r
- goto CleanUp;\r
- }\r
+ //\r
+ // Create a netbuffer representing IPv4 packet\r
+ //\r
+ Pkt = NetbufFromExt (\r
+ (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,\r
+ RxData->Ip4RxData.FragmentCount,\r
+ 0,\r
+ 0,\r
+ IpIoExtFree,\r
+ RxData->Ip4RxData.RecycleSignal\r
+ );\r
+ if (NULL == Pkt) {\r
+ goto CleanUp;\r
+ }\r
\r
- //\r
- // Create a net session\r
- //\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
+ //\r
+ // Create a net session\r
+ //\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.IpHdrLen = RxData->Ip4RxData.HeaderLength;\r
+ Session.IpVersion = IP_VERSION_4;\r
} else {\r
-\r
+ ASSERT (RxData->Ip6RxData.Header != NULL);\r
if (!NetIp6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) {\r
goto CleanUp;\r
}\r
\r
+ if (RxData->Ip6RxData.DataLength == 0) {\r
+ //\r
+ // Discard zero length data payload packet.\r
+ //\r
+ goto CleanUp;\r
+ }\r
+ \r
+ //\r
+ // The fragment should always be valid for non-zero length packet.\r
+ //\r
+ ASSERT (RxData->Ip6RxData.FragmentCount != 0);\r
+ \r
//\r
// Create a netbuffer representing IPv6 packet\r
//\r
sizeof(EFI_IPv6_ADDRESS)\r
);\r
Session.IpHdr.Ip6Hdr = RxData->Ip6RxData.Header;\r
+ Session.IpHdrLen = RxData->Ip6RxData.HeaderLength;\r
Session.IpVersion = IP_VERSION_6;\r
} \r
\r
Resume:\r
\r
if (IpIo->IpVersion == IP_VERSION_4){\r
- ((EFI_IP4_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip4Token));\r
+ IpIo->Ip.Ip4->Receive (IpIo->Ip.Ip4, &(IpIo->RcvToken.Ip4Token));\r
} else {\r
- ((EFI_IP6_PROTOCOL *) Ip)->Receive (Ip, &(IpIo->RcvToken.Ip6Token));\r
+ IpIo->Ip.Ip6->Receive (IpIo->Ip.Ip6, &(IpIo->RcvToken.Ip6Token));\r
}\r
}\r
\r
@param[in] OpenData The configuration data and callbacks for\r
the IP_IO instance.\r
\r
- @retval EFI_SUCCESS The IP_IO instance opened with OpenData\r
- successfully.\r
- @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to \r
- reopen it.\r
- @retval Others Error condition occurred.\r
+ @retval EFI_SUCCESS The IP_IO instance opened with OpenData\r
+ successfully.\r
+ @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to \r
+ reopen it.\r
+ @retval EFI_UNSUPPORTED IPv4 RawData mode is no supported.\r
+ @retval EFI_INVALID_PARAMETER Invalid input parameter.\r
+ @retval Others Error condition occurred.\r
\r
**/\r
EFI_STATUS\r
)\r
{\r
EFI_STATUS Status;\r
- VOID *Ip;\r
UINT8 IpVersion;\r
\r
+ if (IpIo == NULL || OpenData == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
if (IpIo->IsConfigured) {\r
return EFI_ACCESS_DENIED;\r
}\r
\r
ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));\r
\r
- Ip = IpIo->Ip;\r
-\r
//\r
// configure ip\r
//\r
if (IpVersion == IP_VERSION_4){\r
- Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure (\r
- (EFI_IP4_PROTOCOL *) Ip,\r
- &OpenData->IpConfigData.Ip4CfgData\r
- );\r
+ //\r
+ // RawData mode is no supported.\r
+ //\r
+ ASSERT (!OpenData->IpConfigData.Ip4CfgData.RawData);\r
+ if (OpenData->IpConfigData.Ip4CfgData.RawData) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) {\r
+ IpIo->StationIp = EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.StationAddress);\r
+ IpIo->SubnetMask = EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.SubnetMask);\r
+ }\r
+ \r
+ Status = IpIo->Ip.Ip4->Configure (\r
+ IpIo->Ip.Ip4,\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
+ Status = IpIo->Ip.Ip6->Configure (\r
+ IpIo->Ip.Ip6, \r
+ &OpenData->IpConfigData.Ip6CfgData\r
+ );\r
}\r
\r
if (EFI_ERROR (Status)) {\r
// @bug its code\r
//\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
+ Status = IpIo->Ip.Ip4->Routes (\r
+ IpIo->Ip.Ip4,\r
+ TRUE,\r
+ &mZeroIp4Addr,\r
+ &mZeroIp4Addr,\r
+ &mZeroIp4Addr\r
+ );\r
\r
if (EFI_ERROR (Status) && (EFI_NOT_FOUND != Status)) {\r
return Status;\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
+ Status = IpIo->Ip.Ip4->Receive (\r
+ IpIo->Ip.Ip4,\r
+ &(IpIo->RcvToken.Ip4Token)\r
+ );\r
if (EFI_ERROR (Status)) {\r
- ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL);\r
+ IpIo->Ip.Ip4->Configure (IpIo->Ip.Ip4, 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
+ Status = IpIo->Ip.Ip6->Receive (\r
+ IpIo->Ip.Ip6,\r
+ &(IpIo->RcvToken.Ip6Token)\r
+ );\r
if (EFI_ERROR (Status)) {\r
- ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);\r
+ IpIo->Ip.Ip6->Configure (IpIo->Ip.Ip6, NULL);\r
goto ErrorExit;\r
}\r
}\r
\r
@param[in, out] IpIo Pointer to the IP_IO instance that needs to stop.\r
\r
- @retval EFI_SUCCESS The IP_IO instance stopped successfully.\r
- @retval Others Error condition occurred.\r
+ @retval EFI_SUCCESS The IP_IO instance stopped successfully.\r
+ @retval EFI_INVALID_PARAMETER Invalid input parameter.\r
+ @retval Others Error condition occurred.\r
\r
**/\r
EFI_STATUS\r
)\r
{\r
EFI_STATUS Status;\r
- VOID *Ip;\r
IP_IO_IP_INFO *IpInfo;\r
UINT8 IpVersion;\r
\r
+ if (IpIo == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
if (!IpIo->IsConfigured) {\r
return EFI_SUCCESS;\r
}\r
//\r
RemoveEntryList (&IpIo->Entry);\r
\r
- Ip = IpIo->Ip;\r
-\r
//\r
// Configure NULL Ip\r
//\r
if (IpVersion == IP_VERSION_4) {\r
- Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, NULL);\r
+ Status = IpIo->Ip.Ip4->Configure (IpIo->Ip.Ip4, NULL);\r
} else {\r
- Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);\r
+ Status = IpIo->Ip.Ip6->Configure (IpIo->Ip.Ip6, NULL);\r
}\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
//\r
- // All pending send tokens should be flushed by reseting the IP instances.\r
+ // All pending send tokens should be flushed by resetting the IP instances.\r
//\r
ASSERT (IsListEmpty (&IpIo->PendingSndList));\r
\r
IN OUT IP_IO *IpIo\r
)\r
{\r
+ EFI_STATUS Status;\r
+ \r
//\r
// Stop the IpIo.\r
//\r
- IpIoStop (IpIo);\r
+ Status = IpIoStop (IpIo);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
//\r
// Close the IP protocol and destroy the child.\r
//\r
- IpIoCloseProtocolDestroyIpChild (\r
- IpIo->Controller,\r
- IpIo->Image,\r
- IpIo->ChildHandle,\r
- IpIo->IpVersion\r
- );\r
+ Status = IpIoCloseProtocolDestroyIpChild (\r
+ IpIo->Controller,\r
+ IpIo->Image,\r
+ IpIo->ChildHandle,\r
+ IpIo->IpVersion\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
gBS->FreePool (IpIo);\r
\r
@param[in] Context Optional context data.\r
@param[in] NotifyData Optional notify data.\r
@param[in] Dest The destination IP address to send this packet to.\r
+ This parameter is optional when using IPv6.\r
@param[in] OverrideData The data to override some configuration of the IP\r
instance used for sending.\r
\r
@retval EFI_SUCCESS The operation is completed successfully.\r
+ @retval EFI_INVALID_PARAMETER The input parameter is not correct.\r
@retval EFI_NOT_STARTED The IpIo is not configured.\r
@retval EFI_OUT_OF_RESOURCES Failed due to resource limit.\r
+ @retval Others Error condition occurred.\r
\r
**/\r
EFI_STATUS\r
IN IP_IO_IP_INFO *Sender OPTIONAL,\r
IN VOID *Context OPTIONAL,\r
IN VOID *NotifyData OPTIONAL,\r
- IN EFI_IP_ADDRESS *Dest,\r
+ IN EFI_IP_ADDRESS *Dest OPTIONAL,\r
IN IP_IO_OVERRIDE *OverrideData OPTIONAL\r
)\r
{\r
EFI_STATUS Status;\r
- VOID *Ip;\r
+ IP_IO_IP_PROTOCOL Ip;\r
IP_IO_SEND_ENTRY *SndEntry;\r
\r
- ASSERT ((IpIo->IpVersion != IP_VERSION_4) || (Dest != NULL));\r
+ if ((IpIo == NULL) || (Pkt == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if ((IpIo->IpVersion == IP_VERSION_4) && (Dest == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
\r
if (!IpIo->IsConfigured) {\r
return EFI_NOT_STARTED;\r
// Send this Packet\r
//\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
+ Status = Ip.Ip4->Transmit (\r
+ Ip.Ip4,\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
+ Status = Ip.Ip6->Transmit (\r
+ Ip.Ip6,\r
+ &SndEntry->SndToken.Ip6Token\r
+ );\r
}\r
\r
if (EFI_ERROR (Status)) {\r
{\r
LIST_ENTRY *Node;\r
IP_IO_SEND_ENTRY *SndEntry;\r
- VOID *Ip;\r
+ IP_IO_IP_PROTOCOL Ip;\r
\r
ASSERT ((IpIo != NULL) && (Packet != NULL));\r
\r
Ip = SndEntry->Ip;\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
+ Ip.Ip4->Cancel (\r
+ Ip.Ip4,\r
+ &SndEntry->SndToken.Ip4Token\r
+ );\r
} else {\r
- ((EFI_IP6_PROTOCOL *) Ip)->Cancel (\r
- (EFI_IP6_PROTOCOL *) Ip,\r
- &SndEntry->SndToken.Ip6Token\r
- );\r
+ Ip.Ip6->Cancel (\r
+ Ip.Ip6,\r
+ &SndEntry->SndToken.Ip6Token\r
+ );\r
}\r
\r
break;\r
)\r
{\r
EFI_STATUS Status;\r
- VOID *Ip;\r
+ IP_IO_IP_PROTOCOL Ip;\r
UINT8 IpVersion;\r
EFI_IP4_MODE_DATA Ip4ModeData;\r
EFI_IP6_MODE_DATA Ip6ModeData;\r
Ip = IpInfo->Ip;\r
\r
if (IpInfo->IpVersion == IP_VERSION_4) {\r
- Status = ((EFI_IP4_PROTOCOL *) Ip)->Configure ((EFI_IP4_PROTOCOL *) Ip, IpConfigData);\r
+ Status = Ip.Ip4->Configure (Ip.Ip4, IpConfigData);\r
} else {\r
- Status = ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, IpConfigData);\r
+ Status = Ip.Ip6->Configure (Ip.Ip6, IpConfigData);\r
}\r
\r
if (EFI_ERROR (Status)) {\r
}\r
\r
if (IpConfigData != NULL) {\r
- if (IpInfo->IpVersion == IP_VERSION_4){\r
+ if (IpInfo->IpVersion == IP_VERSION_4) {\r
\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
- ((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress = Ip4ModeData.ConfigData.StationAddress;\r
- ((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask = Ip4ModeData.ConfigData.SubnetMask;\r
- }\r
+ Status = Ip.Ip4->GetModeData (\r
+ Ip.Ip4, \r
+ &Ip4ModeData, \r
+ NULL, \r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Ip.Ip4->Configure (Ip.Ip4, NULL);\r
+ goto OnExit;\r
+ }\r
+\r
+ IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress, &Ip4ModeData.ConfigData.StationAddress);\r
+ IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask, &Ip4ModeData.ConfigData.SubnetMask);\r
+ }\r
\r
CopyMem (\r
&IpInfo->Addr.Addr, \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
- ((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
+ Status = Ip.Ip4->Receive (\r
+ Ip.Ip4,\r
+ &IpInfo->DummyRcvToken.Ip4Token\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Ip.Ip4->Configure (Ip.Ip4, NULL);\r
+ }\r
+ } else {\r
+ Status = Ip.Ip6->GetModeData (\r
+ Ip.Ip6,\r
+ &Ip6ModeData,\r
+ NULL,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Ip.Ip6->Configure (Ip.Ip6, NULL);\r
+ goto OnExit;\r
+ }\r
\r
if (Ip6ModeData.IsConfigured) {\r
CopyMem (\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
+ Status = Ip.Ip6->Receive (\r
+ Ip.Ip6,\r
+ &IpInfo->DummyRcvToken.Ip6Token\r
+ );\r
if (EFI_ERROR (Status)) {\r
- ((EFI_IP6_PROTOCOL *) Ip)->Configure ((EFI_IP6_PROTOCOL *) Ip, NULL);\r
+ Ip.Ip6->Configure (Ip.Ip6, NULL);\r
}\r
} \r
} else {\r
{\r
\r
UINT8 IpVersion;\r
+ \r
+ if (IpIo == NULL || IpInfo == NULL) {\r
+ return;\r
+ }\r
\r
ASSERT (IpInfo->RefCnt > 0);\r
\r
RemoveEntryList (&IpInfo->Entry);\r
\r
if (IpVersion == IP_VERSION_4){\r
- ((EFI_IP4_PROTOCOL *) (IpInfo->Ip))->Configure (\r
- (EFI_IP4_PROTOCOL *) (IpInfo->Ip),\r
- NULL\r
- );\r
+ IpInfo->Ip.Ip4->Configure (\r
+ IpInfo->Ip.Ip4,\r
+ NULL\r
+ );\r
IpIoCloseProtocolDestroyIpChild (\r
IpIo->Controller,\r
IpIo->Image,\r
\r
} else {\r
\r
- ((EFI_IP6_PROTOCOL *) (IpInfo->Ip))->Configure (\r
- (EFI_IP6_PROTOCOL *) (IpInfo->Ip),\r
- NULL\r
- );\r
+ IpInfo->Ip.Ip6->Configure (\r
+ IpInfo->Ip.Ip6,\r
+ NULL\r
+ );\r
\r
IpIoCloseProtocolDestroyIpChild (\r
IpIo->Controller,\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
- address is the same with Src.\r
+ address is the same with Src. NULL if failed.\r
\r
**/\r
IP_IO_IP_INFO *\r
LIST_ENTRY *IpInfoEntry;\r
IP_IO_IP_INFO *IpInfo;\r
\r
- ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6)); \r
+ if (IpIo == NULL || Src == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ if ((IpVersion != IP_VERSION_4) && (IpVersion != IP_VERSION_6)) {\r
+ return NULL;\r
+ }\r
\r
NET_LIST_FOR_EACH (IpIoEntry, &mActiveIpIoList) {\r
IpIoPtr = NET_LIST_USER_STRUCT (IpIoEntry, IP_IO, Entry);\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
+ either IPv4 or IPv6. \r
+ @param[out] IsHard If TRUE, indicates that it is a hard error.\r
+ @param[out] Notify If TRUE, SockError needs to be notified.\r
\r
+ @retval EFI_UNSUPPORTED Unrecognizable ICMP error code.\r
@return ICMP Error Status, such as EFI_NETWORK_UNREACHABLE.\r
\r
**/\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_UNSUPPORTED IP version is IPv4, which doesn't support neighbor cache refresh.\r
@retval EFI_OUT_OF_RESOURCES Failed due to resource limit.\r
\r
**/\r
{\r
EFI_IP6_PROTOCOL *Ip;\r
\r
- if (!IpIo->IsConfigured || IpIo->IpVersion != IP_VERSION_6) {\r
+ if (!IpIo->IsConfigured) {\r
return EFI_NOT_STARTED;\r
}\r
\r
- Ip = (EFI_IP6_PROTOCOL *) (IpIo->Ip);\r
+ if (IpIo->IpVersion != IP_VERSION_6) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ Ip = IpIo->Ip.Ip6;\r
\r
return Ip->Neighbors (Ip, FALSE, &Neighbor->v6, NULL, Timeout, TRUE);\r
}\r