4 Copyright (c) 2005 - 2009, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Protocol/Udp4.h>
18 #include <Library/IpIoLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/DpcLib.h>
27 GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mActiveIpIoList
= {
32 GLOBAL_REMOVE_IF_UNREFERENCED EFI_IP4_CONFIG_DATA mIp4IoDefaultIpConfigData
= {
49 GLOBAL_REMOVE_IF_UNREFERENCED EFI_IP6_CONFIG_DATA mIp6IoDefaultIpConfigData
= {
54 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
55 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
63 GLOBAL_REMOVE_IF_UNREFERENCED ICMP_ERROR_INFO mIcmpErrMap
[10] = {
64 {FALSE
, TRUE
}, // ICMP_ERR_UNREACH_NET
65 {FALSE
, TRUE
}, // ICMP_ERR_UNREACH_HOST
66 {TRUE
, TRUE
}, // ICMP_ERR_UNREACH_PROTOCOL
67 {TRUE
, TRUE
}, // ICMP_ERR_UNREACH_PORT
68 {TRUE
, TRUE
}, // ICMP_ERR_MSGSIZE
69 {FALSE
, TRUE
}, // ICMP_ERR_UNREACH_SRCFAIL
70 {FALSE
, TRUE
}, // ICMP_ERR_TIMXCEED_INTRANS
71 {FALSE
, TRUE
}, // ICMP_ERR_TIMEXCEED_REASS
72 {FALSE
, FALSE
}, // ICMP_ERR_QUENCH
73 {FALSE
, TRUE
} // ICMP_ERR_PARAMPROB
76 GLOBAL_REMOVE_IF_UNREFERENCED ICMP_ERROR_INFO mIcmp6ErrMap
[10] = {
77 {FALSE
, TRUE
}, // ICMP6_ERR_UNREACH_NET
78 {FALSE
, TRUE
}, // ICMP6_ERR_UNREACH_HOST
79 {TRUE
, TRUE
}, // ICMP6_ERR_UNREACH_PROTOCOL
80 {TRUE
, TRUE
}, // ICMP6_ERR_UNREACH_PORT
81 {TRUE
, TRUE
}, // ICMP6_ERR_PACKAGE_TOOBIG
82 {FALSE
, TRUE
}, // ICMP6_ERR_TIMXCEED_HOPLIMIT
83 {FALSE
, TRUE
}, // ICMP6_ERR_TIMXCEED_REASS
84 {FALSE
, TRUE
}, // ICMP6_ERR_PARAMPROB_HEADER
85 {FALSE
, TRUE
}, // ICMP6_ERR_PARAMPROB_NEXHEADER
86 {FALSE
, TRUE
} // ICMP6_ERR_PARAMPROB_IPV6OPTION
91 Notify function for IP transmit token.
93 @param[in] Context The context passed in by the event notifier.
98 IpIoTransmitHandlerDpc (
104 Notify function for IP transmit token.
106 @param[in] Event The event signaled.
107 @param[in] Context The context passed in by the event notifier.
112 IpIoTransmitHandler (
119 This function create an IP child ,open the IP protocol, and return the opened
120 IP protocol as Interface.
122 @param[in] ControllerHandle The controller handle.
123 @param[in] ImageHandle The image handle.
124 @param[in] ChildHandle Pointer to the buffer to save the IP child handle.
125 @param[in] IpVersion The version of the IP protocol to use, either
127 @param[out] Interface Pointer used to get the IP protocol interface.
129 @retval EFI_SUCCESS The IP child is created and the IP protocol
130 interface is retrieved.
131 @retval Others The required operation failed.
135 IpIoCreateIpChildOpenProtocol (
136 IN EFI_HANDLE ControllerHandle
,
137 IN EFI_HANDLE ImageHandle
,
138 IN EFI_HANDLE
*ChildHandle
,
144 EFI_GUID
*ServiceBindingGuid
;
145 EFI_GUID
*IpProtocolGuid
;
147 if (IpVersion
== IP_VERSION_4
) {
148 ServiceBindingGuid
= &gEfiIp4ServiceBindingProtocolGuid
;
149 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
150 } else if (IpVersion
== IP_VERSION_6
){
151 ServiceBindingGuid
= &gEfiIp6ServiceBindingProtocolGuid
;
152 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
154 return EFI_UNSUPPORTED
;
158 // Create an IP child.
160 Status
= NetLibCreateServiceChild (
166 if (EFI_ERROR (Status
)) {
171 // Open the IP protocol installed on the *ChildHandle.
173 Status
= gBS
->OpenProtocol (
179 EFI_OPEN_PROTOCOL_BY_DRIVER
181 if (EFI_ERROR (Status
)) {
183 // On failure, destroy the IP child.
185 NetLibDestroyServiceChild (
198 This function close the previously openned IP protocol and destroy the IP child.
200 @param[in] ControllerHandle The controller handle.
201 @param[in] ImageHandle The image handle.
202 @param[in] ChildHandle The child handle of the IP child.
203 @param[in] IpVersion The version of the IP protocol to use, either
206 @retval EFI_SUCCESS The IP protocol is closed and the relevant IP child
208 @retval Others The required operation failed.
212 IpIoCloseProtocolDestroyIpChild (
213 IN EFI_HANDLE ControllerHandle
,
214 IN EFI_HANDLE ImageHandle
,
215 IN EFI_HANDLE ChildHandle
,
220 EFI_GUID
*ServiceBindingGuid
;
221 EFI_GUID
*IpProtocolGuid
;
223 if (IpVersion
== IP_VERSION_4
) {
224 ServiceBindingGuid
= &gEfiIp4ServiceBindingProtocolGuid
;
225 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
226 } else if (IpVersion
== IP_VERSION_6
) {
227 ServiceBindingGuid
= &gEfiIp6ServiceBindingProtocolGuid
;
228 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
230 return EFI_UNSUPPORTED
;
234 // Close the previously openned IP protocol.
244 // Destroy the IP child.
246 Status
= NetLibDestroyServiceChild (
257 This function handles ICMPv4 packets. It is the worker function of
260 @param[in] IpIo Pointer to the IP_IO instance.
261 @param[in, out] Pkt Pointer to the ICMPv4 packet.
262 @param[in] Session Pointer to the net session of this ICMPv4 packet.
264 @retval EFI_SUCCESS The ICMPv4 packet is handled successfully.
265 @retval EFI_ABORTED This type of ICMPv4 packet is not supported.
272 IN EFI_NET_SESSION_DATA
*Session
275 IP4_ICMP_ERROR_HEAD
*IcmpHdr
;
276 EFI_IP4_HEADER
*IpHdr
;
283 ASSERT (IpIo
->IpVersion
== IP_VERSION_4
);
285 IcmpHdr
= NET_PROTO_HDR (Pkt
, IP4_ICMP_ERROR_HEAD
);
286 IpHdr
= (EFI_IP4_HEADER
*) (&IcmpHdr
->IpHead
);
289 // Check the ICMP packet length.
291 if (Pkt
->TotalSize
< ICMP_ERRLEN (IpHdr
)) {
296 Type
= IcmpHdr
->Head
.Type
;
297 Code
= IcmpHdr
->Head
.Code
;
300 // Analyze the ICMP Error in this ICMP pkt
303 case ICMP_TYPE_UNREACH
:
305 case ICMP_CODE_UNREACH_NET
:
306 case ICMP_CODE_UNREACH_HOST
:
307 case ICMP_CODE_UNREACH_PROTOCOL
:
308 case ICMP_CODE_UNREACH_PORT
:
309 case ICMP_CODE_UNREACH_SRCFAIL
:
310 IcmpErr
= (UINT8
) (ICMP_ERR_UNREACH_NET
+ Code
);
314 case ICMP_CODE_UNREACH_NEEDFRAG
:
315 IcmpErr
= ICMP_ERR_MSGSIZE
;
319 case ICMP_CODE_UNREACH_NET_UNKNOWN
:
320 case ICMP_CODE_UNREACH_NET_PROHIB
:
321 case ICMP_CODE_UNREACH_TOSNET
:
322 IcmpErr
= ICMP_ERR_UNREACH_NET
;
326 case ICMP_CODE_UNREACH_HOST_UNKNOWN
:
327 case ICMP_CODE_UNREACH_ISOLATED
:
328 case ICMP_CODE_UNREACH_HOST_PROHIB
:
329 case ICMP_CODE_UNREACH_TOSHOST
:
330 IcmpErr
= ICMP_ERR_UNREACH_HOST
;
340 case ICMP_TYPE_TIMXCEED
:
345 IcmpErr
= (UINT8
) (Code
+ ICMP_ERR_TIMXCEED_INTRANS
);
349 case ICMP_TYPE_PARAMPROB
:
354 IcmpErr
= ICMP_ERR_PARAMPROB
;
358 case ICMP_TYPE_SOURCEQUENCH
:
363 IcmpErr
= ICMP_ERR_QUENCH
;
372 // Notify user the ICMP pkt only containing payload except
373 // IP and ICMP header
375 PayLoadHdr
= (UINT8
*) ((UINT8
*) IpHdr
+ EFI_IP4_HEADER_LEN (IpHdr
));
376 TrimBytes
= (UINT32
) (PayLoadHdr
- (UINT8
*) IcmpHdr
);
378 NetbufTrim (Pkt
, TrimBytes
, TRUE
);
380 IpIo
->PktRcvdNotify (EFI_ICMP_ERROR
, IcmpErr
, Session
, Pkt
, IpIo
->RcvdContext
);
386 This function handles ICMPv6 packets. It is the worker function of
389 @param[in] IpIo Pointer to the IP_IO instance.
390 @param[in, out] Pkt Pointer to the ICMPv6 packet.
391 @param[in] Session Pointer to the net session of this ICMPv6 packet.
393 @retval EFI_SUCCESS The ICMPv6 packet is handled successfully.
394 @retval EFI_ABORTED This type of ICMPv6 packet is not supported.
401 IN EFI_NET_SESSION_DATA
*Session
404 IP6_ICMP_ERROR_HEAD
*IcmpHdr
;
405 EFI_IP6_HEADER
*IpHdr
;
414 ASSERT (IpIo
->IpVersion
== IP_VERSION_6
);
417 // Check the ICMPv6 packet length.
419 if (Pkt
->TotalSize
< sizeof (IP6_ICMP_ERROR_HEAD
)) {
424 IcmpHdr
= NET_PROTO_HDR (Pkt
, IP6_ICMP_ERROR_HEAD
);
425 Type
= IcmpHdr
->Head
.Type
;
426 Code
= IcmpHdr
->Head
.Code
;
429 // Analyze the ICMPv6 Error in this ICMPv6 packet
432 case ICMP_V6_DEST_UNREACHABLE
:
434 case ICMP_V6_NO_ROUTE_TO_DEST
:
435 case ICMP_V6_BEYOND_SCOPE
:
436 case ICMP_V6_ROUTE_REJECTED
:
437 IcmpErr
= ICMP6_ERR_UNREACH_NET
;
441 case ICMP_V6_COMM_PROHIBITED
:
442 case ICMP_V6_ADDR_UNREACHABLE
:
443 case ICMP_V6_SOURCE_ADDR_FAILED
:
444 IcmpErr
= ICMP6_ERR_UNREACH_HOST
;
448 case ICMP_V6_PORT_UNREACHABLE
:
449 IcmpErr
= ICMP6_ERR_UNREACH_PORT
;
459 case ICMP_V6_PACKET_TOO_BIG
:
464 IcmpErr
= ICMP6_ERR_PACKAGE_TOOBIG
;
468 case ICMP_V6_TIME_EXCEEDED
:
473 IcmpErr
= (UINT8
) (ICMP6_ERR_TIMXCEED_HOPLIMIT
+ Code
);
477 case ICMP_V6_PARAMETER_PROBLEM
:
482 IcmpErr
= (UINT8
) (ICMP6_ERR_PARAMPROB_HEADER
+ Code
);
492 // Notify user the ICMPv6 packet only containing payload except
493 // IPv6 basic header, extension header and ICMP header
496 IpHdr
= (EFI_IP6_HEADER
*) (&IcmpHdr
->IpHead
);
497 NextHeader
= IpHdr
->NextHeader
;
498 PayLoadHdr
= (UINT8
*) ((UINT8
*) IcmpHdr
+ sizeof (IP6_ICMP_ERROR_HEAD
));
502 switch (NextHeader
) {
503 case EFI_IP_PROTO_UDP
:
504 case EFI_IP_PROTO_TCP
:
505 case EFI_IP_PROTO_ICMP
:
506 case IP6_NO_NEXT_HEADER
:
512 case IP6_DESTINATION
:
514 // The Hdr Ext Len is 8-bit unsigned integer in 8-octet units, not including
515 // the first 8 octets.
517 NextHeader
= *(PayLoadHdr
);
518 PayLoadHdr
= (UINT8
*) (PayLoadHdr
+ (*(PayLoadHdr
+ 1) + 1) * 8);
524 // The Fragment Header Length is 8 octets.
526 NextHeader
= *(PayLoadHdr
);
527 PayLoadHdr
= (UINT8
*) (PayLoadHdr
+ 8);
537 TrimBytes
= (UINT32
) (PayLoadHdr
- (UINT8
*) IcmpHdr
);
539 NetbufTrim (Pkt
, TrimBytes
, TRUE
);
541 IpIo
->PktRcvdNotify (EFI_ICMP_ERROR
, IcmpErr
, Session
, Pkt
, IpIo
->RcvdContext
);
547 This function handles ICMP packets.
549 @param[in] IpIo Pointer to the IP_IO instance.
550 @param[in, out] Pkt Pointer to the ICMP packet.
551 @param[in] Session Pointer to the net session of this ICMP packet.
553 @retval EFI_SUCCESS The ICMP packet is handled successfully.
554 @retval EFI_ABORTED This type of ICMP packet is not supported.
555 @retval EFI_UNSUPPORTED The IP protocol version in IP_IO is not supported.
562 IN EFI_NET_SESSION_DATA
*Session
566 if (IpIo
->IpVersion
== IP_VERSION_4
) {
568 return IpIoIcmpv4Handler (IpIo
, Pkt
, Session
);
570 } else if (IpIo
->IpVersion
== IP_VERSION_6
) {
572 return IpIoIcmpv6Handler (IpIo
, Pkt
, Session
);
576 return EFI_UNSUPPORTED
;
582 Free function for receive token of IP_IO. It is used to
583 signal the recycle event to notify IP to recycle the
586 @param[in] Event The event to be signaled.
595 gBS
->SignalEvent ((EFI_EVENT
) Event
);
600 Create a send entry to wrap a packet before sending
603 @param[in, out] IpIo Pointer to the IP_IO instance.
604 @param[in, out] Pkt Pointer to the packet.
605 @param[in] Sender Pointer to the IP sender.
606 @param[in] Context Pointer to the context.
607 @param[in] NotifyData Pointer to the notify data.
608 @param[in] Dest Pointer to the destination IP address.
609 @param[in] Override Pointer to the overriden IP_IO data.
611 @return Pointer to the data structure created to wrap the packet. If NULL,
612 @return resource limit occurred.
620 IN VOID
*Context OPTIONAL
,
621 IN VOID
*NotifyData OPTIONAL
,
622 IN EFI_IP_ADDRESS
*Dest OPTIONAL
,
623 IN IP_IO_OVERRIDE
*Override
626 IP_IO_SEND_ENTRY
*SndEntry
;
629 NET_FRAGMENT
*ExtFragment
;
630 UINT32 FragmentCount
;
631 IP_IO_OVERRIDE
*OverrideData
;
632 IP_IO_IP_TX_DATA
*TxData
;
633 EFI_IP4_TRANSMIT_DATA
*Ip4TxData
;
634 EFI_IP6_TRANSMIT_DATA
*Ip6TxData
;
636 if ((IpIo
->IpVersion
!= IP_VERSION_4
) && (IpIo
->IpVersion
!= IP_VERSION_6
)) {
645 // Allocate resource for SndEntry
647 SndEntry
= AllocatePool (sizeof (IP_IO_SEND_ENTRY
));
648 if (NULL
== SndEntry
) {
652 Status
= gBS
->CreateEvent (
659 if (EFI_ERROR (Status
)) {
663 FragmentCount
= Pkt
->BlockOpNum
;
666 // Allocate resource for TxData
668 TxData
= (IP_IO_IP_TX_DATA
*) AllocatePool (
669 sizeof (IP_IO_IP_TX_DATA
) + sizeof (NET_FRAGMENT
) * (FragmentCount
- 1)
672 if (NULL
== TxData
) {
677 // Build a fragment table to contain the fragments in the packet.
679 if (IpIo
->IpVersion
== IP_VERSION_4
) {
680 ExtFragment
= (NET_FRAGMENT
*) TxData
->Ip4TxData
.FragmentTable
;
682 ExtFragment
= (NET_FRAGMENT
*) TxData
->Ip6TxData
.FragmentTable
;
685 NetbufBuildExt (Pkt
, ExtFragment
, &FragmentCount
);
689 // Allocate resource for OverrideData if needed
691 if (NULL
!= Override
) {
693 OverrideData
= AllocateCopyPool (sizeof (IP_IO_OVERRIDE
), Override
);
694 if (NULL
== OverrideData
) {
700 // Set other fields of TxData except the fragment table
702 if (IpIo
->IpVersion
== IP_VERSION_4
) {
704 Ip4TxData
= &TxData
->Ip4TxData
;
706 CopyMem (&Ip4TxData
->DestinationAddress
, Dest
, sizeof (EFI_IPv4_ADDRESS
));
708 Ip4TxData
->OverrideData
= &OverrideData
->Ip4OverrideData
;
709 Ip4TxData
->OptionsLength
= 0;
710 Ip4TxData
->OptionsBuffer
= NULL
;
711 Ip4TxData
->TotalDataLength
= Pkt
->TotalSize
;
712 Ip4TxData
->FragmentCount
= FragmentCount
;
715 // Set the fields of SndToken
717 SndEntry
->SndToken
.Ip4Token
.Event
= Event
;
718 SndEntry
->SndToken
.Ip4Token
.Packet
.TxData
= Ip4TxData
;
721 Ip6TxData
= &TxData
->Ip6TxData
;
724 CopyMem (&Ip6TxData
->DestinationAddress
, Dest
, sizeof (EFI_IPv6_ADDRESS
));
726 ZeroMem (&Ip6TxData
->DestinationAddress
, sizeof (EFI_IPv6_ADDRESS
));
729 Ip6TxData
->OverrideData
= &OverrideData
->Ip6OverrideData
;
730 Ip6TxData
->DataLength
= Pkt
->TotalSize
;
731 Ip6TxData
->FragmentCount
= FragmentCount
;
732 Ip6TxData
->ExtHdrsLength
= 0;
733 Ip6TxData
->ExtHdrs
= NULL
;
736 // Set the fields of SndToken
738 SndEntry
->SndToken
.Ip6Token
.Event
= Event
;
739 SndEntry
->SndToken
.Ip6Token
.Packet
.TxData
= Ip6TxData
;
743 // Set the fields of SndEntry
745 SndEntry
->IpIo
= IpIo
;
746 SndEntry
->Ip
= Sender
;
747 SndEntry
->Context
= Context
;
748 SndEntry
->NotifyData
= NotifyData
;
753 InsertTailList (&IpIo
->PendingSndList
, &SndEntry
->Entry
);
759 if (OverrideData
!= NULL
) {
760 FreePool (OverrideData
);
763 if (TxData
!= NULL
) {
767 if (SndEntry
!= NULL
) {
772 gBS
->CloseEvent (Event
);
780 Destroy the SndEntry.
782 This function pairs with IpIoCreateSndEntry().
784 @param[in] SndEntry Pointer to the send entry to be destroyed.
788 IpIoDestroySndEntry (
789 IN IP_IO_SEND_ENTRY
*SndEntry
793 IP_IO_IP_TX_DATA
*TxData
;
794 IP_IO_OVERRIDE
*Override
;
796 if (SndEntry
->IpIo
->IpVersion
== IP_VERSION_4
) {
797 Event
= SndEntry
->SndToken
.Ip4Token
.Event
;
798 TxData
= (IP_IO_IP_TX_DATA
*) SndEntry
->SndToken
.Ip4Token
.Packet
.TxData
;
799 Override
= (IP_IO_OVERRIDE
*) TxData
->Ip4TxData
.OverrideData
;
800 } else if (SndEntry
->IpIo
->IpVersion
== IP_VERSION_6
) {
801 Event
= SndEntry
->SndToken
.Ip6Token
.Event
;
802 TxData
= (IP_IO_IP_TX_DATA
*) SndEntry
->SndToken
.Ip6Token
.Packet
.TxData
;
803 Override
= (IP_IO_OVERRIDE
*) TxData
->Ip6TxData
.OverrideData
;
808 gBS
->CloseEvent (Event
);
812 if (NULL
!= Override
) {
816 NetbufFree (SndEntry
->Pkt
);
818 RemoveEntryList (&SndEntry
->Entry
);
825 Notify function for IP transmit token.
827 @param[in] Context The context passed in by the event notifier.
832 IpIoTransmitHandlerDpc (
837 IP_IO_SEND_ENTRY
*SndEntry
;
840 SndEntry
= (IP_IO_SEND_ENTRY
*) Context
;
842 IpIo
= SndEntry
->IpIo
;
844 if (IpIo
->IpVersion
== IP_VERSION_4
) {
845 Status
= SndEntry
->SndToken
.Ip4Token
.Status
;
846 } else if (IpIo
->IpVersion
== IP_VERSION_6
){
847 Status
= SndEntry
->SndToken
.Ip6Token
.Status
;
852 if ((IpIo
->PktSentNotify
!= NULL
) && (SndEntry
->NotifyData
!= NULL
)) {
853 IpIo
->PktSentNotify (
861 IpIoDestroySndEntry (SndEntry
);
866 Notify function for IP transmit token.
868 @param[in] Event The event signaled.
869 @param[in] Context The context passed in by the event notifier.
874 IpIoTransmitHandler (
880 // Request IpIoTransmitHandlerDpc as a DPC at TPL_CALLBACK
882 QueueDpc (TPL_CALLBACK
, IpIoTransmitHandlerDpc
, Context
);
887 The dummy handler for the dummy IP receive token.
889 @param[in] Context The context passed in by the event notifier.
894 IpIoDummyHandlerDpc (
898 IP_IO_IP_INFO
*IpInfo
;
900 EFI_EVENT RecycleEvent
;
902 IpInfo
= (IP_IO_IP_INFO
*) Context
;
904 if ((IpInfo
->IpVersion
!= IP_VERSION_4
) && (IpInfo
->IpVersion
!= IP_VERSION_6
)) {
910 if (IpInfo
->IpVersion
== IP_VERSION_4
) {
911 Status
= IpInfo
->DummyRcvToken
.Ip4Token
.Status
;
913 if (IpInfo
->DummyRcvToken
.Ip4Token
.Packet
.RxData
!= NULL
) {
914 RecycleEvent
= IpInfo
->DummyRcvToken
.Ip4Token
.Packet
.RxData
->RecycleSignal
;
917 Status
= IpInfo
->DummyRcvToken
.Ip6Token
.Status
;
919 if (IpInfo
->DummyRcvToken
.Ip6Token
.Packet
.RxData
!= NULL
) {
920 RecycleEvent
= IpInfo
->DummyRcvToken
.Ip6Token
.Packet
.RxData
->RecycleSignal
;
926 if (EFI_ABORTED
== Status
) {
928 // The reception is actively aborted by the consumer, directly return.
931 } else if (EFI_SUCCESS
== Status
) {
933 // Recycle the RxData.
935 ASSERT (RecycleEvent
!= NULL
);
937 gBS
->SignalEvent (RecycleEvent
);
941 // Continue the receive.
943 if (IpInfo
->IpVersion
== IP_VERSION_4
) {
944 ((EFI_IP4_PROTOCOL
*) (IpInfo
->Ip
))->Receive (
945 (EFI_IP4_PROTOCOL
*) (IpInfo
->Ip
),
946 &IpInfo
->DummyRcvToken
.Ip4Token
949 ((EFI_IP6_PROTOCOL
*) (IpInfo
->Ip
))->Receive (
950 (EFI_IP6_PROTOCOL
*) (IpInfo
->Ip
),
951 &IpInfo
->DummyRcvToken
.Ip6Token
958 This function add IpIoDummyHandlerDpc to the end of the DPC queue.
960 @param[in] Event The event signaled.
961 @param[in] Context The context passed in by the event notifier.
972 // Request IpIoDummyHandlerDpc as a DPC at TPL_CALLBACK
974 QueueDpc (TPL_CALLBACK
, IpIoDummyHandlerDpc
, Context
);
979 Notify function for the IP receive token, used to process
980 the received IP packets.
982 @param[in] Context The context passed in by the event notifier.
987 IpIoListenHandlerDpc (
993 IP_IO_IP_RX_DATA
*RxData
;
995 EFI_NET_SESSION_DATA Session
;
998 IpIo
= (IP_IO
*) Context
;
1001 if (IpIo
->IpVersion
== IP_VERSION_4
) {
1002 Status
= IpIo
->RcvToken
.Ip4Token
.Status
;
1003 RxData
= (IP_IO_IP_RX_DATA
*) IpIo
->RcvToken
.Ip4Token
.Packet
.RxData
;
1004 } else if (IpIo
->IpVersion
== IP_VERSION_6
) {
1005 Status
= IpIo
->RcvToken
.Ip6Token
.Status
;
1006 RxData
= (IP_IO_IP_RX_DATA
*) IpIo
->RcvToken
.Ip6Token
.Packet
.RxData
;
1011 if (EFI_ABORTED
== Status
) {
1013 // The reception is actively aborted by the consumer, directly return.
1018 if (((EFI_SUCCESS
!= Status
) && (EFI_ICMP_ERROR
!= Status
)) || (NULL
== RxData
)) {
1020 // @bug Only process the normal packets and the icmp error packets, if RxData is NULL
1021 // @bug with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although
1022 // @bug this should be a bug of the low layer (IP).
1027 if (NULL
== IpIo
->PktRcvdNotify
) {
1031 if (IpIo
->IpVersion
== IP_VERSION_4
) {
1032 if ((EFI_IP4 (RxData
->Ip4RxData
.Header
->SourceAddress
) != 0) &&
1033 !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA
*) RxData
)->Header
->SourceAddress
), 0)) {
1035 // The source address is not zero and it's not a unicast IP address, discard it.
1041 // Create a netbuffer representing IPv4 packet
1043 Pkt
= NetbufFromExt (
1044 (NET_FRAGMENT
*) RxData
->Ip4RxData
.FragmentTable
,
1045 RxData
->Ip4RxData
.FragmentCount
,
1049 RxData
->Ip4RxData
.RecycleSignal
1056 // Create a net session
1058 Session
.Source
.Addr
[0] = EFI_IP4 (RxData
->Ip4RxData
.Header
->SourceAddress
);
1059 Session
.Dest
.Addr
[0] = EFI_IP4 (RxData
->Ip4RxData
.Header
->DestinationAddress
);
1060 Session
.IpHdr
.Ip4Hdr
= RxData
->Ip4RxData
.Header
;
1061 Session
.IpHdrLen
= RxData
->Ip4RxData
.HeaderLength
;
1062 Session
.IpVersion
= IP_VERSION_4
;
1065 if (!NetIp6IsValidUnicast(&RxData
->Ip6RxData
.Header
->SourceAddress
)) {
1070 // Create a netbuffer representing IPv6 packet
1072 Pkt
= NetbufFromExt (
1073 (NET_FRAGMENT
*) RxData
->Ip6RxData
.FragmentTable
,
1074 RxData
->Ip6RxData
.FragmentCount
,
1078 RxData
->Ip6RxData
.RecycleSignal
1085 // Create a net session
1089 &RxData
->Ip6RxData
.Header
->SourceAddress
,
1090 sizeof(EFI_IPv6_ADDRESS
)
1094 &RxData
->Ip6RxData
.Header
->DestinationAddress
,
1095 sizeof(EFI_IPv6_ADDRESS
)
1097 Session
.IpHdr
.Ip6Hdr
= RxData
->Ip6RxData
.Header
;
1098 Session
.IpHdrLen
= RxData
->Ip6RxData
.HeaderLength
;
1099 Session
.IpVersion
= IP_VERSION_6
;
1102 if (EFI_SUCCESS
== Status
) {
1104 IpIo
->PktRcvdNotify (EFI_SUCCESS
, 0, &Session
, Pkt
, IpIo
->RcvdContext
);
1107 // Status is EFI_ICMP_ERROR
1109 Status
= IpIoIcmpHandler (IpIo
, Pkt
, &Session
);
1110 if (EFI_ERROR (Status
)) {
1119 if (IpIo
->IpVersion
== IP_VERSION_4
){
1120 gBS
->SignalEvent (RxData
->Ip4RxData
.RecycleSignal
);
1122 gBS
->SignalEvent (RxData
->Ip6RxData
.RecycleSignal
);
1127 if (IpIo
->IpVersion
== IP_VERSION_4
){
1128 ((EFI_IP4_PROTOCOL
*) Ip
)->Receive (Ip
, &(IpIo
->RcvToken
.Ip4Token
));
1130 ((EFI_IP6_PROTOCOL
*) Ip
)->Receive (Ip
, &(IpIo
->RcvToken
.Ip6Token
));
1135 This function add IpIoListenHandlerDpc to the end of the DPC queue.
1137 @param[in] Event The event signaled.
1138 @param[in] Context The context passed in by the event notifier.
1149 // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK
1151 QueueDpc (TPL_CALLBACK
, IpIoListenHandlerDpc
, Context
);
1156 Create a new IP_IO instance.
1158 This function uses IP4/IP6 service binding protocol in Controller to create
1159 an IP4/IP6 child (aka IP4/IP6 instance).
1161 @param[in] Image The image handle of the driver or application that
1163 @param[in] Controller The controller handle that has IP4 or IP6 service
1164 binding protocol installed.
1165 @param[in] IpVersion The version of the IP protocol to use, either
1168 @return Pointer to a newly created IP_IO instance, or NULL if failed.
1174 IN EFI_HANDLE Image
,
1175 IN EFI_HANDLE Controller
,
1183 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
1185 IpIo
= AllocateZeroPool (sizeof (IP_IO
));
1190 InitializeListHead (&(IpIo
->PendingSndList
));
1191 InitializeListHead (&(IpIo
->IpList
));
1192 IpIo
->Controller
= Controller
;
1193 IpIo
->Image
= Image
;
1194 IpIo
->IpVersion
= IpVersion
;
1197 Status
= gBS
->CreateEvent (
1204 if (EFI_ERROR (Status
)) {
1208 if (IpVersion
== IP_VERSION_4
) {
1209 IpIo
->RcvToken
.Ip4Token
.Event
= Event
;
1211 IpIo
->RcvToken
.Ip6Token
.Event
= Event
;
1215 // Create an IP child and open IP protocol
1217 Status
= IpIoCreateIpChildOpenProtocol (
1222 (VOID
**)&(IpIo
->Ip
)
1224 if (EFI_ERROR (Status
)) {
1232 if (Event
!= NULL
) {
1233 gBS
->CloseEvent (Event
);
1236 gBS
->FreePool (IpIo
);
1243 Open an IP_IO instance for use.
1245 This function is called after IpIoCreate(). It is used for configuring the IP
1246 instance and register the callbacks and their context data for sending and
1247 receiving IP packets.
1249 @param[in, out] IpIo Pointer to an IP_IO instance that needs
1251 @param[in] OpenData The configuration data and callbacks for
1254 @retval EFI_SUCCESS The IP_IO instance opened with OpenData
1256 @retval EFI_ACCESS_DENIED The IP_IO instance is configured, avoid to
1258 @retval Others Error condition occurred.
1265 IN IP_IO_OPEN_DATA
*OpenData
1272 if (IpIo
->IsConfigured
) {
1273 return EFI_ACCESS_DENIED
;
1276 IpVersion
= IpIo
->IpVersion
;
1278 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
1285 if (IpVersion
== IP_VERSION_4
){
1286 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Configure (
1287 (EFI_IP4_PROTOCOL
*) Ip
,
1288 &OpenData
->IpConfigData
.Ip4CfgData
1292 Status
= ((EFI_IP6_PROTOCOL
*) Ip
)->Configure (
1293 (EFI_IP6_PROTOCOL
*) Ip
,
1294 &OpenData
->IpConfigData
.Ip6CfgData
1298 if (EFI_ERROR (Status
)) {
1303 // @bug To delete the default route entry in this Ip, if it is:
1304 // @bug (0.0.0.0, 0.0.0.0, 0.0.0.0). Delete this statement if Ip modified
1307 if (IpVersion
== IP_VERSION_4
){
1308 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Routes (
1309 (EFI_IP4_PROTOCOL
*) Ip
,
1316 if (EFI_ERROR (Status
) && (EFI_NOT_FOUND
!= Status
)) {
1321 IpIo
->PktRcvdNotify
= OpenData
->PktRcvdNotify
;
1322 IpIo
->PktSentNotify
= OpenData
->PktSentNotify
;
1324 IpIo
->RcvdContext
= OpenData
->RcvdContext
;
1325 IpIo
->SndContext
= OpenData
->SndContext
;
1327 if (IpVersion
== IP_VERSION_4
){
1328 IpIo
->Protocol
= OpenData
->IpConfigData
.Ip4CfgData
.DefaultProtocol
;
1331 // start to listen incoming packet
1333 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Receive (
1334 (EFI_IP4_PROTOCOL
*) Ip
,
1335 &(IpIo
->RcvToken
.Ip4Token
)
1337 if (EFI_ERROR (Status
)) {
1338 ((EFI_IP4_PROTOCOL
*) Ip
)->Configure ((EFI_IP4_PROTOCOL
*) Ip
, NULL
);
1344 IpIo
->Protocol
= OpenData
->IpConfigData
.Ip6CfgData
.DefaultProtocol
;
1345 Status
= ((EFI_IP6_PROTOCOL
*) Ip
)->Receive (
1346 (EFI_IP6_PROTOCOL
*) Ip
,
1347 &(IpIo
->RcvToken
.Ip6Token
)
1349 if (EFI_ERROR (Status
)) {
1350 ((EFI_IP6_PROTOCOL
*) Ip
)->Configure ((EFI_IP6_PROTOCOL
*) Ip
, NULL
);
1355 IpIo
->IsConfigured
= TRUE
;
1356 InsertTailList (&mActiveIpIoList
, &IpIo
->Entry
);
1365 Stop an IP_IO instance.
1367 This function is paired with IpIoOpen(). The IP_IO will be unconfigured and all
1368 the pending send/receive tokens will be canceled.
1370 @param[in, out] IpIo Pointer to the IP_IO instance that needs to stop.
1372 @retval EFI_SUCCESS The IP_IO instance stopped successfully.
1373 @retval Others Error condition occurred.
1384 IP_IO_IP_INFO
*IpInfo
;
1387 if (!IpIo
->IsConfigured
) {
1391 IpVersion
= IpIo
->IpVersion
;
1393 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
1396 // Remove the IpIo from the active IpIo list.
1398 RemoveEntryList (&IpIo
->Entry
);
1403 // Configure NULL Ip
1405 if (IpVersion
== IP_VERSION_4
) {
1406 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Configure ((EFI_IP4_PROTOCOL
*) Ip
, NULL
);
1408 Status
= ((EFI_IP6_PROTOCOL
*) Ip
)->Configure ((EFI_IP6_PROTOCOL
*) Ip
, NULL
);
1410 if (EFI_ERROR (Status
)) {
1414 IpIo
->IsConfigured
= FALSE
;
1417 // Detroy the Ip List used by IpIo
1420 while (!IsListEmpty (&(IpIo
->IpList
))) {
1421 IpInfo
= NET_LIST_HEAD (&(IpIo
->IpList
), IP_IO_IP_INFO
, Entry
);
1423 IpIoRemoveIp (IpIo
, IpInfo
);
1427 // All pending send tokens should be flushed by reseting the IP instances.
1429 ASSERT (IsListEmpty (&IpIo
->PendingSndList
));
1432 // Close the receive event.
1434 if (IpVersion
== IP_VERSION_4
){
1435 gBS
->CloseEvent (IpIo
->RcvToken
.Ip4Token
.Event
);
1437 gBS
->CloseEvent (IpIo
->RcvToken
.Ip6Token
.Event
);
1445 Destroy an IP_IO instance.
1447 This function is paired with IpIoCreate(). The IP_IO will be closed first.
1448 Resource will be freed afterwards. See IpIoCloseProtocolDestroyIpChild().
1450 @param[in, out] IpIo Pointer to the IP_IO instance that needs to be
1453 @retval EFI_SUCCESS The IP_IO instance destroyed successfully.
1454 @retval Others Error condition occurred.
1469 // Close the IP protocol and destroy the child.
1471 IpIoCloseProtocolDestroyIpChild (
1478 gBS
->FreePool (IpIo
);
1485 Send out an IP packet.
1487 This function is called after IpIoOpen(). The data to be sent are wrapped in
1488 Pkt. The IP instance wrapped in IpIo is used for sending by default but can be
1489 overriden by Sender. Other sending configs, like source address and gateway
1490 address etc., are specified in OverrideData.
1492 @param[in, out] IpIo Pointer to an IP_IO instance used for sending IP
1494 @param[in, out] Pkt Pointer to the IP packet to be sent.
1495 @param[in] Sender The IP protocol instance used for sending.
1496 @param[in] Context Optional context data.
1497 @param[in] NotifyData Optional notify data.
1498 @param[in] Dest The destination IP address to send this packet to.
1499 @param[in] OverrideData The data to override some configuration of the IP
1500 instance used for sending.
1502 @retval EFI_SUCCESS The operation is completed successfully.
1503 @retval EFI_NOT_STARTED The IpIo is not configured.
1504 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
1511 IN OUT NET_BUF
*Pkt
,
1512 IN IP_IO_IP_INFO
*Sender OPTIONAL
,
1513 IN VOID
*Context OPTIONAL
,
1514 IN VOID
*NotifyData OPTIONAL
,
1515 IN EFI_IP_ADDRESS
*Dest
,
1516 IN IP_IO_OVERRIDE
*OverrideData OPTIONAL
1521 IP_IO_SEND_ENTRY
*SndEntry
;
1523 ASSERT ((IpIo
->IpVersion
!= IP_VERSION_4
) || (Dest
!= NULL
));
1525 if (!IpIo
->IsConfigured
) {
1526 return EFI_NOT_STARTED
;
1529 Ip
= (NULL
== Sender
) ? IpIo
->Ip
: Sender
->Ip
;
1532 // create a new SndEntry
1534 SndEntry
= IpIoCreateSndEntry (IpIo
, Pkt
, Ip
, Context
, NotifyData
, Dest
, OverrideData
);
1535 if (NULL
== SndEntry
) {
1536 return EFI_OUT_OF_RESOURCES
;
1542 if (IpIo
->IpVersion
== IP_VERSION_4
){
1543 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Transmit (
1544 (EFI_IP4_PROTOCOL
*) Ip
,
1545 &SndEntry
->SndToken
.Ip4Token
1548 Status
= ((EFI_IP6_PROTOCOL
*) Ip
)->Transmit (
1549 (EFI_IP6_PROTOCOL
*) Ip
,
1550 &SndEntry
->SndToken
.Ip6Token
1554 if (EFI_ERROR (Status
)) {
1555 IpIoDestroySndEntry (SndEntry
);
1563 Cancel the IP transmit token which wraps this Packet.
1565 @param[in] IpIo Pointer to the IP_IO instance.
1566 @param[in] Packet Pointer to the packet of NET_BUF to cancel.
1577 IP_IO_SEND_ENTRY
*SndEntry
;
1580 ASSERT ((IpIo
!= NULL
) && (Packet
!= NULL
));
1582 NET_LIST_FOR_EACH (Node
, &IpIo
->PendingSndList
) {
1584 SndEntry
= NET_LIST_USER_STRUCT (Node
, IP_IO_SEND_ENTRY
, Entry
);
1586 if (SndEntry
->Pkt
== Packet
) {
1590 if (IpIo
->IpVersion
== IP_VERSION_4
) {
1591 ((EFI_IP4_PROTOCOL
*) Ip
)->Cancel (
1592 (EFI_IP4_PROTOCOL
*) Ip
,
1593 &SndEntry
->SndToken
.Ip4Token
1596 ((EFI_IP6_PROTOCOL
*) Ip
)->Cancel (
1597 (EFI_IP6_PROTOCOL
*) Ip
,
1598 &SndEntry
->SndToken
.Ip6Token
1610 Add a new IP instance for sending data.
1612 The function is used to add the IP_IO to the IP_IO sending list. The caller
1613 can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to send
1616 @param[in, out] IpIo Pointer to a IP_IO instance to add a new IP
1617 instance for sending purpose.
1619 @return Pointer to the created IP_IO_IP_INFO structure, NULL if failed.
1629 IP_IO_IP_INFO
*IpInfo
;
1632 ASSERT (IpIo
!= NULL
);
1634 IpInfo
= AllocatePool (sizeof (IP_IO_IP_INFO
));
1635 if (IpInfo
== NULL
) {
1640 // Init this IpInfo, set the Addr and SubnetMask to 0 before we configure the IP
1643 InitializeListHead (&IpInfo
->Entry
);
1644 IpInfo
->ChildHandle
= NULL
;
1645 ZeroMem (&IpInfo
->Addr
, sizeof (IpInfo
->Addr
));
1646 ZeroMem (&IpInfo
->PreMask
, sizeof (IpInfo
->PreMask
));
1649 IpInfo
->IpVersion
= IpIo
->IpVersion
;
1652 // Create the IP instance and open the IP protocol.
1654 Status
= IpIoCreateIpChildOpenProtocol (
1657 &IpInfo
->ChildHandle
,
1659 (VOID
**) &IpInfo
->Ip
1661 if (EFI_ERROR (Status
)) {
1666 // Create the event for the DummyRcvToken.
1668 Status
= gBS
->CreateEvent (
1675 if (EFI_ERROR (Status
)) {
1676 goto ReleaseIpChild
;
1679 if (IpInfo
->IpVersion
== IP_VERSION_4
) {
1680 IpInfo
->DummyRcvToken
.Ip4Token
.Event
= Event
;
1682 IpInfo
->DummyRcvToken
.Ip6Token
.Event
= Event
;
1686 // Link this IpInfo into the IpIo.
1688 InsertTailList (&IpIo
->IpList
, &IpInfo
->Entry
);
1694 IpIoCloseProtocolDestroyIpChild (
1697 IpInfo
->ChildHandle
,
1703 gBS
->FreePool (IpInfo
);
1710 Configure the IP instance of this IpInfo and start the receiving if IpConfigData
1713 @param[in, out] IpInfo Pointer to the IP_IO_IP_INFO instance.
1714 @param[in, out] IpConfigData The IP configure data used to configure the IP
1715 instance, if NULL the IP instance is reset. If
1716 UseDefaultAddress is set to TRUE, and the configure
1717 operation succeeds, the default address information
1718 is written back in this IpConfigData.
1720 @retval EFI_SUCCESS The IP instance of this IpInfo is configured successfully
1721 or no need to reconfigure it.
1722 @retval Others Configuration fails.
1728 IN OUT IP_IO_IP_INFO
*IpInfo
,
1729 IN OUT VOID
*IpConfigData OPTIONAL
1735 EFI_IP4_MODE_DATA Ip4ModeData
;
1736 EFI_IP6_MODE_DATA Ip6ModeData
;
1738 ASSERT (IpInfo
!= NULL
);
1740 if (IpInfo
->RefCnt
> 1) {
1742 // This IP instance is shared, don't reconfigure it until it has only one
1743 // consumer. Currently, only the tcp children cloned from their passive parent
1744 // will share the same IP. So this cases only happens while IpConfigData is NULL,
1745 // let the last consumer clean the IP instance.
1750 IpVersion
= IpInfo
->IpVersion
;
1751 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
1755 if (IpInfo
->IpVersion
== IP_VERSION_4
) {
1756 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Configure ((EFI_IP4_PROTOCOL
*) Ip
, IpConfigData
);
1758 Status
= ((EFI_IP6_PROTOCOL
*) Ip
)->Configure ((EFI_IP6_PROTOCOL
*) Ip
, IpConfigData
);
1761 if (EFI_ERROR (Status
)) {
1765 if (IpConfigData
!= NULL
) {
1766 if (IpInfo
->IpVersion
== IP_VERSION_4
){
1768 if (((EFI_IP4_CONFIG_DATA
*) IpConfigData
)->UseDefaultAddress
) {
1769 ((EFI_IP4_PROTOCOL
*) Ip
)->GetModeData (
1770 (EFI_IP4_PROTOCOL
*) Ip
,
1776 ((EFI_IP4_CONFIG_DATA
*) IpConfigData
)->StationAddress
= Ip4ModeData
.ConfigData
.StationAddress
;
1777 ((EFI_IP4_CONFIG_DATA
*) IpConfigData
)->SubnetMask
= Ip4ModeData
.ConfigData
.SubnetMask
;
1782 &((EFI_IP4_CONFIG_DATA
*) IpConfigData
)->StationAddress
,
1786 &IpInfo
->PreMask
.SubnetMask
,
1787 &((EFI_IP4_CONFIG_DATA
*) IpConfigData
)->SubnetMask
,
1791 Status
= ((EFI_IP4_PROTOCOL
*) Ip
)->Receive (
1792 (EFI_IP4_PROTOCOL
*) Ip
,
1793 &IpInfo
->DummyRcvToken
.Ip4Token
1795 if (EFI_ERROR (Status
)) {
1796 ((EFI_IP4_PROTOCOL
*)Ip
)->Configure (Ip
, NULL
);
1800 ((EFI_IP6_PROTOCOL
*) Ip
)->GetModeData (
1801 (EFI_IP6_PROTOCOL
*) Ip
,
1807 if (Ip6ModeData
.IsConfigured
) {
1809 &((EFI_IP6_CONFIG_DATA
*) IpConfigData
)->StationAddress
,
1810 &Ip6ModeData
.ConfigData
.StationAddress
,
1811 sizeof (EFI_IPv6_ADDRESS
)
1814 if (Ip6ModeData
.AddressList
!= NULL
) {
1815 FreePool (Ip6ModeData
.AddressList
);
1818 if (Ip6ModeData
.GroupTable
!= NULL
) {
1819 FreePool (Ip6ModeData
.GroupTable
);
1822 if (Ip6ModeData
.RouteTable
!= NULL
) {
1823 FreePool (Ip6ModeData
.RouteTable
);
1826 if (Ip6ModeData
.NeighborCache
!= NULL
) {
1827 FreePool (Ip6ModeData
.NeighborCache
);
1830 if (Ip6ModeData
.PrefixTable
!= NULL
) {
1831 FreePool (Ip6ModeData
.PrefixTable
);
1834 if (Ip6ModeData
.IcmpTypeList
!= NULL
) {
1835 FreePool (Ip6ModeData
.IcmpTypeList
);
1839 Status
= EFI_NO_MAPPING
;
1845 &Ip6ModeData
.ConfigData
.StationAddress
,
1846 sizeof (EFI_IPv6_ADDRESS
)
1849 Status
= ((EFI_IP6_PROTOCOL
*) Ip
)->Receive (
1850 (EFI_IP6_PROTOCOL
*) Ip
,
1851 &IpInfo
->DummyRcvToken
.Ip6Token
1853 if (EFI_ERROR (Status
)) {
1854 ((EFI_IP6_PROTOCOL
*) Ip
)->Configure ((EFI_IP6_PROTOCOL
*) Ip
, NULL
);
1859 // The IP instance is reset, set the stored Addr and SubnetMask to zero.
1861 ZeroMem (&IpInfo
->Addr
, sizeof (IpInfo
->Addr
));
1862 ZeroMem (&IpInfo
->PreMask
, sizeof (IpInfo
->PreMask
));
1872 Destroy an IP instance maintained in IpIo->IpList for
1875 This function pairs with IpIoAddIp(). The IpInfo is previously created by
1876 IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance
1877 will be dstroyed if the RefCnt is zero.
1879 @param[in] IpIo Pointer to the IP_IO instance.
1880 @param[in] IpInfo Pointer to the IpInfo to be removed.
1887 IN IP_IO_IP_INFO
*IpInfo
1893 ASSERT (IpInfo
->RefCnt
> 0);
1895 NET_PUT_REF (IpInfo
);
1897 if (IpInfo
->RefCnt
> 0) {
1902 IpVersion
= IpIo
->IpVersion
;
1904 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
1906 RemoveEntryList (&IpInfo
->Entry
);
1908 if (IpVersion
== IP_VERSION_4
){
1909 ((EFI_IP4_PROTOCOL
*) (IpInfo
->Ip
))->Configure (
1910 (EFI_IP4_PROTOCOL
*) (IpInfo
->Ip
),
1913 IpIoCloseProtocolDestroyIpChild (
1916 IpInfo
->ChildHandle
,
1920 gBS
->CloseEvent (IpInfo
->DummyRcvToken
.Ip4Token
.Event
);
1924 ((EFI_IP6_PROTOCOL
*) (IpInfo
->Ip
))->Configure (
1925 (EFI_IP6_PROTOCOL
*) (IpInfo
->Ip
),
1929 IpIoCloseProtocolDestroyIpChild (
1932 IpInfo
->ChildHandle
,
1936 gBS
->CloseEvent (IpInfo
->DummyRcvToken
.Ip6Token
.Event
);
1944 Find the first IP protocol maintained in IpIo whose local
1945 address is the same as Src.
1947 This function is called when the caller needs the IpIo to send data to the
1948 specified Src. The IpIo was added previously by IpIoAddIp().
1950 @param[in, out] IpIo Pointer to the pointer of the IP_IO instance.
1951 @param[in] IpVersion The version of the IP protocol to use, either
1953 @param[in] Src The local IP address.
1955 @return Pointer to the IP protocol can be used for sending purpose and its local
1956 address is the same with Src.
1962 IN OUT IP_IO
**IpIo
,
1964 IN EFI_IP_ADDRESS
*Src
1967 LIST_ENTRY
*IpIoEntry
;
1969 LIST_ENTRY
*IpInfoEntry
;
1970 IP_IO_IP_INFO
*IpInfo
;
1972 ASSERT ((IpVersion
== IP_VERSION_4
) || (IpVersion
== IP_VERSION_6
));
1974 NET_LIST_FOR_EACH (IpIoEntry
, &mActiveIpIoList
) {
1975 IpIoPtr
= NET_LIST_USER_STRUCT (IpIoEntry
, IP_IO
, Entry
);
1977 if (((*IpIo
!= NULL
) && (*IpIo
!= IpIoPtr
)) || (IpIoPtr
->IpVersion
!= IpVersion
)) {
1981 NET_LIST_FOR_EACH (IpInfoEntry
, &IpIoPtr
->IpList
) {
1982 IpInfo
= NET_LIST_USER_STRUCT (IpInfoEntry
, IP_IO_IP_INFO
, Entry
);
1983 if (IpInfo
->IpVersion
== IP_VERSION_4
){
1985 if (EFI_IP4_EQUAL (&IpInfo
->Addr
.v4
, &Src
->v4
)) {
1992 if (EFI_IP6_EQUAL (&IpInfo
->Addr
.v6
, &Src
->v6
)) {
2009 Get the ICMP error map information.
2011 The ErrorStatus will be returned. The IsHard and Notify are optional. If they
2012 are not NULL, this routine will fill them.
2014 @param[in] IcmpError IcmpError Type.
2015 @param[in] IpVersion The version of the IP protocol to use,
2016 either IPv4 or IPv6.
2017 @param[out] IsHard If TRUE, indicates that it is a hard error.
2018 @param[out] Notify If TRUE, SockError needs to be notified.
2020 @return ICMP Error Status, such as EFI_NETWORK_UNREACHABLE.
2025 IpIoGetIcmpErrStatus (
2028 OUT BOOLEAN
*IsHard OPTIONAL
,
2029 OUT BOOLEAN
*Notify OPTIONAL
2032 if (IpVersion
== IP_VERSION_4
) {
2033 ASSERT (IcmpError
<= ICMP_ERR_PARAMPROB
);
2035 if (IsHard
!= NULL
) {
2036 *IsHard
= mIcmpErrMap
[IcmpError
].IsHard
;
2039 if (Notify
!= NULL
) {
2040 *Notify
= mIcmpErrMap
[IcmpError
].Notify
;
2043 switch (IcmpError
) {
2044 case ICMP_ERR_UNREACH_NET
:
2045 return EFI_NETWORK_UNREACHABLE
;
2047 case ICMP_ERR_TIMXCEED_INTRANS
:
2048 case ICMP_ERR_TIMXCEED_REASS
:
2049 case ICMP_ERR_UNREACH_HOST
:
2050 return EFI_HOST_UNREACHABLE
;
2052 case ICMP_ERR_UNREACH_PROTOCOL
:
2053 return EFI_PROTOCOL_UNREACHABLE
;
2055 case ICMP_ERR_UNREACH_PORT
:
2056 return EFI_PORT_UNREACHABLE
;
2058 case ICMP_ERR_MSGSIZE
:
2059 case ICMP_ERR_UNREACH_SRCFAIL
:
2060 case ICMP_ERR_QUENCH
:
2061 case ICMP_ERR_PARAMPROB
:
2062 return EFI_ICMP_ERROR
;
2066 return EFI_UNSUPPORTED
;
2069 } else if (IpVersion
== IP_VERSION_6
) {
2071 ASSERT (IcmpError
<= ICMP6_ERR_PARAMPROB_IPV6OPTION
);
2073 if (IsHard
!= NULL
) {
2074 *IsHard
= mIcmp6ErrMap
[IcmpError
].IsHard
;
2077 if (Notify
!= NULL
) {
2078 *Notify
= mIcmp6ErrMap
[IcmpError
].Notify
;
2081 switch (IcmpError
) {
2082 case ICMP6_ERR_UNREACH_NET
:
2083 return EFI_NETWORK_UNREACHABLE
;
2085 case ICMP6_ERR_UNREACH_HOST
:
2086 case ICMP6_ERR_TIMXCEED_HOPLIMIT
:
2087 case ICMP6_ERR_TIMXCEED_REASS
:
2088 return EFI_HOST_UNREACHABLE
;
2090 case ICMP6_ERR_UNREACH_PROTOCOL
:
2091 return EFI_PROTOCOL_UNREACHABLE
;
2093 case ICMP6_ERR_UNREACH_PORT
:
2094 return EFI_PORT_UNREACHABLE
;
2096 case ICMP6_ERR_PACKAGE_TOOBIG
:
2097 case ICMP6_ERR_PARAMPROB_HEADER
:
2098 case ICMP6_ERR_PARAMPROB_NEXHEADER
:
2099 case ICMP6_ERR_PARAMPROB_IPV6OPTION
:
2100 return EFI_ICMP_ERROR
;
2104 return EFI_UNSUPPORTED
;
2109 // Should never be here
2112 return EFI_UNSUPPORTED
;
2118 Refresh the remote peer's Neighbor Cache entries.
2120 This function is called when the caller needs the IpIo to refresh the existing
2121 IPv6 neighbor cache entries since the neighbor is considered reachable by the
2122 node has recently received a confirmation that packets sent recently to the
2123 neighbor were received by its IP layer.
2125 @param[in] IpIo Pointer to an IP_IO instance
2126 @param[in] Neighbor The IP address of the neighbor
2127 @param[in] Timeout Time in 100-ns units that this entry will
2128 remain in the neighbor cache. A value of
2129 zero means that the entry is permanent.
2130 A value of non-zero means that the entry is
2131 dynamic and will be deleted after Timeout.
2133 @retval EFI_SUCCESS The operation is completed successfully.
2134 @retval EFI_NOT_STARTED The IpIo is not configured.
2135 @retval EFI_INVALID_PARAMETER Neighbor Address is invalid.
2136 @retval EFI_NOT_FOUND The neighbor cache entry is not in the
2138 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
2142 IpIoRefreshNeighbor (
2144 IN EFI_IP_ADDRESS
*Neighbor
,
2148 EFI_IP6_PROTOCOL
*Ip
;
2150 if (!IpIo
->IsConfigured
|| IpIo
->IpVersion
!= IP_VERSION_6
) {
2151 return EFI_NOT_STARTED
;
2154 Ip
= (EFI_IP6_PROTOCOL
*) (IpIo
->Ip
);
2156 return Ip
->Neighbors (Ip
, FALSE
, &Neighbor
->v6
, NULL
, Timeout
, TRUE
);