3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The implementation of the IpIo layer.
25 #include <Protocol/Udp4.h>
27 #include <Library/IpIoLib.h>
28 #include <Library/BaseLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/BaseMemoryLib.h>
35 #define NET_PROTO_HDR(Buf, Type) ((Type *) ((Buf)->BlockOp[0].Head))
36 #define ICMP_ERRLEN(IpHdr) \
37 (sizeof(IP4_ICMP_HEAD) + EFI_IP4_HEADER_LEN(IpHdr) + 8)
39 NET_LIST_ENTRY mActiveIpIoList
= {
44 EFI_IP4_CONFIG_DATA mIpIoDefaultIpConfigData
= {
71 This function create an ip child ,open the IP protocol, return the opened
72 Ip protocol to Interface.
74 @param ControllerHandle The controller handle.
75 @param ImageHandle The image handle.
76 @param ChildHandle Pointer to the buffer to save the ip child handle.
77 @param Interface Pointer used to get the ip protocol interface.
79 @retval EFI_SUCCESS The ip child is created and the ip protocol
80 interface is retrieved.
81 @retval other The required operation failed.
86 IpIoCreateIpChildOpenProtocol (
87 IN EFI_HANDLE ControllerHandle
,
88 IN EFI_HANDLE ImageHandle
,
89 IN EFI_HANDLE
*ChildHandle
,
96 // Create an ip child.
98 Status
= NetLibCreateServiceChild (
101 &gEfiIp4ServiceBindingProtocolGuid
,
104 if (EFI_ERROR (Status
)) {
109 // Open the ip protocol installed on the *ChildHandle.
111 Status
= gBS
->OpenProtocol (
113 &gEfiIp4ProtocolGuid
,
117 EFI_OPEN_PROTOCOL_BY_DRIVER
119 if (EFI_ERROR (Status
)) {
121 // On failure, destroy the ip child.
123 NetLibDestroyServiceChild (
126 &gEfiIp4ServiceBindingProtocolGuid
,
136 This function close the previously openned ip protocol and destroy the ip child.
138 @param ControllerHandle The controller handle.
139 @param ImageHandle the image handle.
140 @param ChildHandle The child handle of the ip child.
142 @retval EFI_SUCCESS The ip protocol is closed and the relevant ip child
144 @retval other The required operation failed.
149 IpIoCloseProtocolDestroyIpChild (
150 IN EFI_HANDLE ControllerHandle
,
151 IN EFI_HANDLE ImageHandle
,
152 IN EFI_HANDLE ChildHandle
158 // Close the previously openned ip protocol.
162 &gEfiIp4ProtocolGuid
,
168 // Destroy the ip child.
170 Status
= NetLibDestroyServiceChild (
173 &gEfiIp4ServiceBindingProtocolGuid
,
184 @param IpIo Pointer to the IP_IO instance.
185 @param Pkt Pointer to the ICMP packet.
186 @param Session Pointer to the net session of this ICMP packet.
188 @retval EFI_SUCCESS The ICMP packet is handled successfully.
189 @retval EFI_ABORTED This type of ICMP packet is not supported.
197 IN EFI_NET_SESSION_DATA
*Session
200 IP4_ICMP_ERROR_HEAD
*IcmpHdr
;
201 EFI_IP4_HEADER
*IpHdr
;
208 IcmpHdr
= NET_PROTO_HDR (Pkt
, IP4_ICMP_ERROR_HEAD
);
209 IpHdr
= (EFI_IP4_HEADER
*) (&IcmpHdr
->IpHead
);
212 // Check the ICMP packet length.
214 if (Pkt
->TotalSize
< ICMP_ERRLEN (IpHdr
)) {
219 Type
= IcmpHdr
->Head
.Type
;
220 Code
= IcmpHdr
->Head
.Code
;
223 // Analyze the ICMP Error in this ICMP pkt
226 case ICMP_TYPE_UNREACH
:
228 case ICMP_CODE_UNREACH_NET
:
229 case ICMP_CODE_UNREACH_HOST
:
230 case ICMP_CODE_UNREACH_PROTOCOL
:
231 case ICMP_CODE_UNREACH_PORT
:
232 case ICMP_CODE_UNREACH_SRCFAIL
:
233 IcmpErr
= (ICMP_ERROR
) (ICMP_ERR_UNREACH_NET
+ Code
);
237 case ICMP_CODE_UNREACH_NEEDFRAG
:
238 IcmpErr
= ICMP_ERR_MSGSIZE
;
242 case ICMP_CODE_UNREACH_NET_UNKNOWN
:
243 case ICMP_CODE_UNREACH_NET_PROHIB
:
244 case ICMP_CODE_UNREACH_TOSNET
:
245 IcmpErr
= ICMP_ERR_UNREACH_NET
;
249 case ICMP_CODE_UNREACH_HOST_UNKNOWN
:
250 case ICMP_CODE_UNREACH_ISOLATED
:
251 case ICMP_CODE_UNREACH_HOST_PROHIB
:
252 case ICMP_CODE_UNREACH_TOSHOST
:
253 IcmpErr
= ICMP_ERR_UNREACH_HOST
;
265 case ICMP_TYPE_TIMXCEED
:
270 IcmpErr
= (ICMP_ERROR
) (Code
+ ICMP_ERR_TIMXCEED_INTRANS
);
274 case ICMP_TYPE_PARAMPROB
:
279 IcmpErr
= ICMP_ERR_PARAMPROB
;
283 case ICMP_TYPE_SOURCEQUENCH
:
288 IcmpErr
= ICMP_ERR_QUENCH
;
299 // Notify user the ICMP pkt only containing payload except
300 // IP and ICMP header
302 PayLoadHdr
= (UINT8
*) ((UINT8
*) IpHdr
+ EFI_IP4_HEADER_LEN (IpHdr
));
303 TrimBytes
= (UINT32
) (PayLoadHdr
- (UINT8
*) IcmpHdr
);
305 NetbufTrim (Pkt
, TrimBytes
, TRUE
);
307 IpIo
->PktRcvdNotify (EFI_ICMP_ERROR
, IcmpErr
, Session
, Pkt
, IpIo
->RcvdContext
);
314 Ext free function for net buffer. This function is
315 called when the net buffer is freed. It is used to
316 signal the recycle event to notify IP to recycle the
319 @param Event The event to be signaled.
330 gBS
->SignalEvent ((EFI_EVENT
) Event
);
335 Create a send entry to wrap a packet before sending
338 @param IpIo Pointer to the IP_IO instance.
339 @param Pkt Pointer to the packet.
340 @param Sender Pointer to the IP sender.
341 @param NotifyData Pointer to the notify data.
342 @param Dest Pointer to the destination IP address.
343 @param Override Pointer to the overriden IP_IO data.
345 @return Pointer to the data structure created to wrap the packet. If NULL,
346 @return resource limit occurred.
354 IN EFI_IP4_PROTOCOL
*Sender
,
355 IN VOID
*Context OPTIONAL
,
356 IN VOID
*NotifyData OPTIONAL
,
358 IN IP_IO_OVERRIDE
*Override
361 IP_IO_SEND_ENTRY
*SndEntry
;
362 EFI_IP4_COMPLETION_TOKEN
*SndToken
;
363 EFI_IP4_TRANSMIT_DATA
*TxData
;
365 EFI_IP4_OVERRIDE_DATA
*OverrideData
;
366 volatile UINT32 Index
;
369 // Allocate resource for SndEntry
371 SndEntry
= NetAllocatePool (sizeof (IP_IO_SEND_ENTRY
));
372 if (NULL
== SndEntry
) {
377 // Allocate resource for SndToken
379 SndToken
= NetAllocatePool (sizeof (EFI_IP4_COMPLETION_TOKEN
));
380 if (NULL
== SndToken
) {
381 goto ReleaseSndEntry
;
384 Status
= gBS
->CreateEvent (
391 if (EFI_ERROR (Status
)) {
392 goto ReleaseSndToken
;
396 // Allocate resource for TxData
398 TxData
= NetAllocatePool (
399 sizeof (EFI_IP4_TRANSMIT_DATA
) +
400 sizeof (EFI_IP4_FRAGMENT_DATA
) * (Pkt
->BlockOpNum
- 1)
403 if (NULL
== TxData
) {
408 // Allocate resource for OverrideData if needed
411 if (NULL
!= Override
) {
413 OverrideData
= NetAllocatePool (sizeof (EFI_IP4_OVERRIDE_DATA
));
414 if (NULL
== OverrideData
) {
415 goto ReleaseResource
;
418 // Set the fields of OverrideData
420 NetCopyMem (OverrideData
, Override
, sizeof (*OverrideData
));
424 // Set the fields of TxData
426 NetCopyMem (&TxData
->DestinationAddress
, &Dest
, sizeof (EFI_IPv4_ADDRESS
));
427 TxData
->OverrideData
= OverrideData
;
428 TxData
->OptionsLength
= 0;
429 TxData
->OptionsBuffer
= NULL
;
430 TxData
->TotalDataLength
= Pkt
->TotalSize
;
431 TxData
->FragmentCount
= Pkt
->BlockOpNum
;
434 for (Index
= 0; Index
< Pkt
->BlockOpNum
; Index
++) {
435 TxData
->FragmentTable
[Index
].FragmentBuffer
= Pkt
->BlockOp
[Index
].Head
;
436 TxData
->FragmentTable
[Index
].FragmentLength
= Pkt
->BlockOp
[Index
].Size
;
440 // Set the fields of SndToken
442 SndToken
->Packet
.TxData
= TxData
;
445 // Set the fields of SndEntry
447 SndEntry
->IpIo
= IpIo
;
448 SndEntry
->Ip
= Sender
;
449 SndEntry
->Context
= Context
;
450 SndEntry
->NotifyData
= NotifyData
;
455 SndEntry
->SndToken
= SndToken
;
457 NetListInsertTail (&IpIo
->PendingSndList
, &SndEntry
->Entry
);
462 NetFreePool (TxData
);
465 gBS
->CloseEvent (SndToken
->Event
);
468 NetFreePool (SndToken
);
471 NetFreePool (SndEntry
);
478 Destroy the SndEntry.
480 @param SndEntry Pointer to the send entry to be destroyed.
487 IpIoDestroySndEntry (
488 IN IP_IO_SEND_ENTRY
*SndEntry
491 EFI_IP4_TRANSMIT_DATA
*TxData
;
493 TxData
= SndEntry
->SndToken
->Packet
.TxData
;
495 if (NULL
!= TxData
->OverrideData
) {
496 NetFreePool (TxData
->OverrideData
);
499 NetFreePool (TxData
);
500 NetbufFree (SndEntry
->Pkt
);
501 gBS
->CloseEvent (SndEntry
->SndToken
->Event
);
503 NetFreePool (SndEntry
->SndToken
);
504 NetListRemoveEntry (&SndEntry
->Entry
);
506 NetFreePool (SndEntry
);
511 Notify function for IP transmit token.
513 @param Event The event signaled.
514 @param Context The context passed in by the event notifier.
522 IpIoTransmitHandler (
528 IP_IO_SEND_ENTRY
*SndEntry
;
530 SndEntry
= (IP_IO_SEND_ENTRY
*) Context
;
532 IpIo
= SndEntry
->IpIo
;
534 if (IpIo
->PktSentNotify
&& SndEntry
->NotifyData
) {
535 IpIo
->PktSentNotify (
536 SndEntry
->SndToken
->Status
,
543 IpIoDestroySndEntry (SndEntry
);
548 The dummy handler for the dummy IP receive token.
550 @param Evt The event signaled.
551 @param Context The context passed in by the event notifier.
564 IP_IO_IP_INFO
*IpInfo
;
565 EFI_IP4_COMPLETION_TOKEN
*DummyToken
;
567 ASSERT (Event
&& Context
);
569 IpInfo
= (IP_IO_IP_INFO
*) Context
;
570 DummyToken
= &(IpInfo
->DummyRcvToken
);
572 if (EFI_SUCCESS
== DummyToken
->Status
) {
573 ASSERT (DummyToken
->Packet
.RxData
);
575 gBS
->SignalEvent (DummyToken
->Packet
.RxData
->RecycleSignal
);
578 IpInfo
->Ip
->Receive (IpInfo
->Ip
, DummyToken
);
583 Notify function for the IP receive token, used to process
584 the received IP packets.
586 @param Event The event signaled.
587 @param Context The context passed in by the event notifier.
602 EFI_IP4_RECEIVE_DATA
*RxData
;
603 EFI_IP4_PROTOCOL
*Ip
;
604 EFI_NET_SESSION_DATA Session
;
607 IpIo
= (IP_IO
*) Context
;
610 Status
= IpIo
->RcvToken
.Status
;
611 RxData
= IpIo
->RcvToken
.Packet
.RxData
;
613 if (((EFI_SUCCESS
!= Status
) && (EFI_ICMP_ERROR
!= Status
)) || (NULL
== RxData
)) {
615 // Only process the normal packets and the icmp error packets, if RxData is NULL
616 // with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although
617 // this should be a bug of the low layer (IP).
622 if (NULL
== IpIo
->PktRcvdNotify
) {
626 if ((EFI_IP4 (RxData
->Header
->SourceAddress
) != 0) &&
627 !Ip4IsUnicast (EFI_NTOHL (RxData
->Header
->SourceAddress
), 0)) {
629 // The source address is not zero and it's not a unicast IP address, discard it.
635 // Create a netbuffer representing packet
637 Pkt
= NetbufFromExt (
638 (NET_FRAGMENT
*) RxData
->FragmentTable
,
639 RxData
->FragmentCount
,
643 RxData
->RecycleSignal
650 // Create a net session
652 Session
.Source
= EFI_IP4 (RxData
->Header
->SourceAddress
);
653 Session
.Dest
= EFI_IP4 (RxData
->Header
->DestinationAddress
);
654 Session
.IpHdr
= RxData
->Header
;
656 if (EFI_SUCCESS
== Status
) {
658 IpIo
->PktRcvdNotify (EFI_SUCCESS
, (ICMP_ERROR
) 0, &Session
, Pkt
, IpIo
->RcvdContext
);
661 // Status is EFI_ICMP_ERROR
663 Status
= IpIoIcmpHandler (IpIo
, Pkt
, &Session
);
664 if (EFI_ERROR (Status
)) {
672 gBS
->SignalEvent (RxData
->RecycleSignal
);
675 Ip
->Receive (Ip
, &(IpIo
->RcvToken
));
680 Create a new IP_IO instance.
682 @param Image The image handle of an IP_IO consumer protocol.
683 @param Controller The controller handle of an IP_IO consumer protocol
686 @return Pointer to a newly created IP_IO instance.
692 IN EFI_HANDLE Controller
698 IpIo
= NetAllocateZeroPool (sizeof (IP_IO
));
703 NetListInit (&(IpIo
->PendingSndList
));
704 NetListInit (&(IpIo
->IpList
));
705 IpIo
->Controller
= Controller
;
708 Status
= gBS
->CreateEvent (
713 &(IpIo
->RcvToken
.Event
)
715 if (EFI_ERROR (Status
)) {
720 // Create an IP child and open IP protocol
722 Status
= IpIoCreateIpChildOpenProtocol (
728 if (EFI_ERROR (Status
)) {
736 if (NULL
!= IpIo
->RcvToken
.Event
) {
737 gBS
->CloseEvent (IpIo
->RcvToken
.Event
);
747 Open an IP_IO instance for use.
749 @param IpIo Pointer to an IP_IO instance that needs to open.
750 @param OpenData The configuration data for the IP_IO instance.
752 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
754 @retval other Error condition occurred.
760 IN IP_IO_OPEN_DATA
*OpenData
764 EFI_IP4_PROTOCOL
*Ip
;
766 if (IpIo
->IsConfigured
) {
767 return EFI_ACCESS_DENIED
;
775 Status
= Ip
->Configure (Ip
, &OpenData
->IpConfigData
);
776 if (EFI_ERROR (Status
)) {
781 // bugbug: to delete the default route entry in this Ip, if it is:
782 // (0.0.0.0, 0.0.0.0, 0.0.0.0). Delete this statement if Ip modified
785 Status
= Ip
->Routes (Ip
, TRUE
, &mZeroIp4Addr
, &mZeroIp4Addr
, &mZeroIp4Addr
);
787 if (EFI_ERROR (Status
) && (EFI_NOT_FOUND
!= Status
)) {
791 IpIo
->PktRcvdNotify
= OpenData
->PktRcvdNotify
;
792 IpIo
->PktSentNotify
= OpenData
->PktSentNotify
;
794 IpIo
->RcvdContext
= OpenData
->RcvdContext
;
795 IpIo
->SndContext
= OpenData
->SndContext
;
797 IpIo
->Protocol
= OpenData
->IpConfigData
.DefaultProtocol
;
800 // start to listen incoming packet
802 Status
= Ip
->Receive (Ip
, &(IpIo
->RcvToken
));
803 if (EFI_ERROR (Status
)) {
804 Ip
->Configure (Ip
, NULL
);
808 IpIo
->IsConfigured
= TRUE
;
809 NetListInsertTail (&mActiveIpIoList
, &IpIo
->Entry
);
818 Stop an IP_IO instance.
820 @param IpIo Pointer to the IP_IO instance that needs to stop.
822 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
823 @retval other Error condition occurred.
832 EFI_IP4_PROTOCOL
*Ip
;
833 IP_IO_IP_INFO
*IpInfo
;
835 if (!IpIo
->IsConfigured
) {
840 // Remove the IpIo from the active IpIo list.
842 NetListRemoveEntry (&IpIo
->Entry
);
849 Status
= Ip
->Configure (Ip
, NULL
);
850 if (EFI_ERROR (Status
)) {
854 IpIo
->IsConfigured
= FALSE
;
857 // Detroy the Ip List used by IpIo
860 while (!NetListIsEmpty (&(IpIo
->IpList
))) {
861 IpInfo
= NET_LIST_HEAD (&(IpIo
->IpList
), IP_IO_IP_INFO
, Entry
);
863 IpIoRemoveIp (IpIo
, IpInfo
);
867 // All pending snd tokens should be flushed by reseting the IP instances.
869 ASSERT (NetListIsEmpty (&IpIo
->PendingSndList
));
872 // Close the receive event.
874 gBS
->CloseEvent (IpIo
->RcvToken
.Event
);
881 Destroy an IP_IO instance.
883 @param IpIo Pointer to the IP_IO instance that needs to
886 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
887 @retval other Error condition occurred.
901 // Close the IP protocol and destroy the child.
903 IpIoCloseProtocolDestroyIpChild (IpIo
->Controller
, IpIo
->Image
, IpIo
->ChildHandle
);
912 Send out an IP packet.
914 @param IpIo Pointer to an IP_IO instance used for sending IP
916 @param Pkt Pointer to the IP packet to be sent.
917 @param Sender The IP protocol instance used for sending.
919 @param Dest The destination IP address to send this packet to.
920 @param OverrideData The data to override some configuration of the IP
921 instance used for sending.
923 @retval EFI_SUCCESS The operation is completed successfully.
924 @retval EFI_NOT_STARTED The IpIo is not configured.
925 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
932 IN IP_IO_IP_INFO
*Sender
,
933 IN VOID
*Context OPTIONAL
,
934 IN VOID
*NotifyData OPTIONAL
,
936 IN IP_IO_OVERRIDE
*OverrideData
940 EFI_IP4_PROTOCOL
*Ip
;
941 IP_IO_SEND_ENTRY
*SndEntry
;
943 if (!IpIo
->IsConfigured
) {
944 return EFI_NOT_STARTED
;
947 Ip
= (NULL
== Sender
) ? IpIo
->Ip
: Sender
->Ip
;
950 // create a new SndEntry
952 SndEntry
= IpIoCreateSndEntry (IpIo
, Pkt
, Ip
, Context
, NotifyData
, Dest
, OverrideData
);
953 if (NULL
== SndEntry
) {
954 return EFI_OUT_OF_RESOURCES
;
960 Status
= Ip
->Transmit (Ip
, SndEntry
->SndToken
);
961 if (EFI_ERROR (Status
)) {
962 IpIoDestroySndEntry (SndEntry
);
970 Cancel the IP transmit token which wraps this Packet.
972 @param IpIo Pointer to the IP_IO instance.
973 @param Packet Pointer to the packet to cancel.
984 NET_LIST_ENTRY
*Node
;
985 IP_IO_SEND_ENTRY
*SndEntry
;
986 EFI_IP4_PROTOCOL
*Ip
;
988 ASSERT (IpIo
&& Packet
);
990 NET_LIST_FOR_EACH (Node
, &IpIo
->PendingSndList
) {
992 SndEntry
= NET_LIST_USER_STRUCT (Node
, IP_IO_SEND_ENTRY
, Entry
);
994 if (SndEntry
->Pkt
== Packet
) {
997 Ip
->Cancel (Ip
, SndEntry
->SndToken
);
1000 // Abort the user token.
1002 SndEntry
->SndToken
->Status
= EFI_ABORTED
;
1003 IpIoTransmitHandler (NULL
, SndEntry
);
1013 Add a new IP instance for sending data.
1015 @param IpIo Pointer to a IP_IO instance to add a new IP
1016 instance for sending purpose.
1018 @return Pointer to the created IP_IO_IP_INFO structure, NULL is failed.
1027 IP_IO_IP_INFO
*IpInfo
;
1031 IpInfo
= NetAllocatePool (sizeof (IP_IO_IP_INFO
));
1032 if (IpInfo
== NULL
) {
1037 // Init this IpInfo, set the Addr and SubnetMask to 0 before we configure the IP
1040 NetListInit (&IpInfo
->Entry
);
1041 IpInfo
->ChildHandle
= NULL
;
1043 IpInfo
->SubnetMask
= 0;
1047 // Create the IP instance and open the Ip4 protocol.
1049 Status
= IpIoCreateIpChildOpenProtocol (
1052 &IpInfo
->ChildHandle
,
1053 (VOID
**) &IpInfo
->Ip
1055 if (EFI_ERROR (Status
)) {
1060 // Create the event for the DummyRcvToken.
1062 Status
= gBS
->CreateEvent (
1067 &IpInfo
->DummyRcvToken
.Event
1069 if (EFI_ERROR (Status
)) {
1070 goto ReleaseIpChild
;
1074 // Link this IpInfo into the IpIo.
1076 NetListInsertTail (&IpIo
->IpList
, &IpInfo
->Entry
);
1082 IpIoCloseProtocolDestroyIpChild (
1090 NetFreePool (IpInfo
);
1097 Configure the IP instance of this IpInfo and start the receiving if Ip4ConfigData
1100 @param IpInfo Pointer to the IP_IO_IP_INFO instance.
1101 @param Ip4ConfigData The IP4 configure data used to configure the ip
1102 instance, if NULL the ip instance is reseted. If
1103 UseDefaultAddress is set to TRUE, and the configure
1104 operation succeeds, the default address information
1105 is written back in this Ip4ConfigData.
1107 @retval EFI_STATUS The status returned by IP4->Configure or
1113 IN IP_IO_IP_INFO
*IpInfo
,
1114 IN OUT EFI_IP4_CONFIG_DATA
*Ip4ConfigData OPTIONAL
1118 EFI_IP4_PROTOCOL
*Ip
;
1119 EFI_IP4_MODE_DATA Ip4ModeData
;
1123 if (IpInfo
->RefCnt
> 1) {
1125 // This IP instance is shared, don't reconfigure it until it has only one
1126 // consumer. Currently, only the tcp children cloned from their passive parent
1127 // will share the same IP. So this cases only happens while Ip4ConfigData is NULL,
1128 // let the last consumer clean the IP instance.
1135 Status
= Ip
->Configure (Ip
, Ip4ConfigData
);
1136 if (EFI_ERROR (Status
)) {
1140 if (Ip4ConfigData
!= NULL
) {
1142 if (Ip4ConfigData
->UseDefaultAddress
) {
1143 Ip
->GetModeData (Ip
, &Ip4ModeData
, NULL
, NULL
);
1145 Ip4ConfigData
->StationAddress
= Ip4ModeData
.ConfigData
.StationAddress
;
1146 Ip4ConfigData
->SubnetMask
= Ip4ModeData
.ConfigData
.SubnetMask
;
1149 NetCopyMem (&IpInfo
->Addr
, &Ip4ConfigData
->StationAddress
, sizeof (IP4_ADDR
));
1150 NetCopyMem (&IpInfo
->SubnetMask
, &Ip4ConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
1152 Status
= Ip
->Receive (Ip
, &IpInfo
->DummyRcvToken
);
1153 if (EFI_ERROR (Status
)) {
1154 Ip
->Configure (Ip
, NULL
);
1159 // The IP instance is reseted, set the stored Addr and SubnetMask to zero.
1162 IpInfo
->SubnetMask
=0;
1172 Destroy an IP instance maintained in IpIo->IpList for
1175 @param IpIo Pointer to the IP_IO instance.
1176 @param IpInfo Pointer to the IpInfo to be removed.
1184 IN IP_IO_IP_INFO
*IpInfo
1187 ASSERT (IpInfo
->RefCnt
> 0);
1189 NET_PUT_REF (IpInfo
);
1191 if (IpInfo
->RefCnt
> 0) {
1196 NetListRemoveEntry (&IpInfo
->Entry
);
1198 IpInfo
->Ip
->Configure (IpInfo
->Ip
, NULL
);
1200 IpIoCloseProtocolDestroyIpChild (IpIo
->Controller
, IpIo
->Image
, IpInfo
->ChildHandle
);
1202 gBS
->CloseEvent (IpInfo
->DummyRcvToken
.Event
);
1204 NetFreePool (IpInfo
);
1209 Find the first IP protocol maintained in IpIo whose local
1210 address is the same with Src.
1212 @param IpIo Pointer to the pointer of the IP_IO instance.
1213 @param Src The local IP address.
1215 @return Pointer to the IP protocol can be used for sending purpose and its local
1216 @return address is the same with Src.
1221 IN OUT IP_IO
**IpIo
,
1225 NET_LIST_ENTRY
*IpIoEntry
;
1227 NET_LIST_ENTRY
*IpInfoEntry
;
1228 IP_IO_IP_INFO
*IpInfo
;
1230 NET_LIST_FOR_EACH (IpIoEntry
, &mActiveIpIoList
) {
1231 IpIoPtr
= NET_LIST_USER_STRUCT (IpIoEntry
, IP_IO
, Entry
);
1233 if ((*IpIo
!= NULL
) && (*IpIo
!= IpIoPtr
)) {
1237 NET_LIST_FOR_EACH (IpInfoEntry
, &IpIoPtr
->IpList
) {
1238 IpInfo
= NET_LIST_USER_STRUCT (IpInfoEntry
, IP_IO_IP_INFO
, Entry
);
1240 if (IpInfo
->Addr
== Src
) {
1255 Get the ICMP error map information, the ErrorStatus will be returned.
1256 The IsHard and Notify are optional. If they are not NULL, this rouine will
1258 We move IcmpErrMap[] to local variable to enable EBC build.
1260 @param IcmpError IcmpError Type
1261 @param IsHard Whether it is a hard error
1262 @param Notify Whether it need to notify SockError
1264 @return ICMP Error Status
1268 IpIoGetIcmpErrStatus (
1269 IN ICMP_ERROR IcmpError
,
1270 OUT BOOLEAN
*IsHard
, OPTIONAL
1271 OUT BOOLEAN
*Notify OPTIONAL
1274 ICMP_ERROR_INFO IcmpErrMap
[10];
1276 IcmpErrMap
[0].Error
= EFI_NETWORK_UNREACHABLE
;
1277 IcmpErrMap
[0].IsHard
= FALSE
;
1278 IcmpErrMap
[0].Notify
= TRUE
;
1280 IcmpErrMap
[1].Error
= EFI_HOST_UNREACHABLE
;
1281 IcmpErrMap
[1].IsHard
= FALSE
;
1282 IcmpErrMap
[1].Notify
= TRUE
;
1284 IcmpErrMap
[2].Error
= EFI_PROTOCOL_UNREACHABLE
;
1285 IcmpErrMap
[2].IsHard
= TRUE
;
1286 IcmpErrMap
[2].Notify
= TRUE
;
1288 IcmpErrMap
[3].Error
= EFI_PORT_UNREACHABLE
;
1289 IcmpErrMap
[3].IsHard
= TRUE
;
1290 IcmpErrMap
[3].Notify
= TRUE
;
1292 IcmpErrMap
[4].Error
= EFI_ICMP_ERROR
;
1293 IcmpErrMap
[4].IsHard
= TRUE
;
1294 IcmpErrMap
[4].Notify
= TRUE
;
1296 IcmpErrMap
[5].Error
= EFI_ICMP_ERROR
;
1297 IcmpErrMap
[5].IsHard
= FALSE
;
1298 IcmpErrMap
[5].Notify
= TRUE
;
1300 IcmpErrMap
[6].Error
= EFI_HOST_UNREACHABLE
;
1301 IcmpErrMap
[6].IsHard
= FALSE
;
1302 IcmpErrMap
[6].Notify
= TRUE
;
1304 IcmpErrMap
[7].Error
= EFI_HOST_UNREACHABLE
;
1305 IcmpErrMap
[7].IsHard
= FALSE
;
1306 IcmpErrMap
[7].Notify
= TRUE
;
1308 IcmpErrMap
[8].Error
= EFI_ICMP_ERROR
;
1309 IcmpErrMap
[8].IsHard
= FALSE
;
1310 IcmpErrMap
[8].Notify
= FALSE
;
1312 IcmpErrMap
[9].Error
= EFI_ICMP_ERROR
;
1313 IcmpErrMap
[9].IsHard
= FALSE
;
1314 IcmpErrMap
[9].Notify
= TRUE
;
1316 ASSERT ((IcmpError
>= ICMP_ERR_UNREACH_NET
) && (IcmpError
<= ICMP_ERR_PARAMPROB
));
1318 if (IsHard
!= NULL
) {
1319 *IsHard
= IcmpErrMap
[IcmpError
].IsHard
;
1322 if (Notify
!= NULL
) {
1323 *Notify
= IcmpErrMap
[IcmpError
].Notify
;
1326 return IcmpErrMap
[IcmpError
].Error
;