2 Implementation of EFI_IP6_PROTOCOL protocol interfaces.
4 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 EFI_IPSEC2_PROTOCOL
*mIpSec
= NULL
;
15 EFI_IP6_PROTOCOL mEfiIp6ProtocolTemplete
= {
28 Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
30 The GetModeData() function returns the current operational mode data for this driver instance.
31 The data fields in EFI_IP6_MODE_DATA are read only. This function is used optionally to
32 retrieve the operational mode data of underlying networks or drivers.
34 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
35 @param[out] Ip6ModeData Pointer to the EFI IPv6 Protocol mode data structure.
36 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
37 @param[out] SnpModeData Pointer to the simple network mode data structure.
39 @retval EFI_SUCCESS The operation completed successfully.
40 @retval EFI_INVALID_PARAMETER This is NULL.
41 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
47 IN EFI_IP6_PROTOCOL
*This
,
48 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
49 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
50 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
53 IP6_PROTOCOL
*IpInstance
;
56 EFI_IP6_CONFIG_DATA
*Config
;
61 return EFI_INVALID_PARAMETER
;
64 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
65 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
66 IpSb
= IpInstance
->Service
;
67 IpIf
= IpInstance
->Interface
;
69 if (IpSb
->LinkLocalDadFail
) {
70 return EFI_INVALID_PARAMETER
;
73 if (Ip6ModeData
!= NULL
) {
75 // IsStarted is "whether the EfiIp6Configure has been called".
76 // IsConfigured is "whether the station address has been configured"
78 Ip6ModeData
->IsStarted
= (BOOLEAN
) (IpInstance
->State
== IP6_STATE_CONFIGED
);
79 Ip6ModeData
->MaxPacketSize
= IpSb
->MaxPacketSize
;
80 CopyMem (&Ip6ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (EFI_IP6_CONFIG_DATA
));
81 Ip6ModeData
->IsConfigured
= FALSE
;
83 Ip6ModeData
->AddressCount
= 0;
84 Ip6ModeData
->AddressList
= NULL
;
86 Ip6ModeData
->GroupCount
= IpInstance
->GroupCount
;
87 Ip6ModeData
->GroupTable
= NULL
;
89 Ip6ModeData
->RouteCount
= 0;
90 Ip6ModeData
->RouteTable
= NULL
;
92 Ip6ModeData
->NeighborCount
= 0;
93 Ip6ModeData
->NeighborCache
= NULL
;
95 Ip6ModeData
->PrefixCount
= 0;
96 Ip6ModeData
->PrefixTable
= NULL
;
98 Ip6ModeData
->IcmpTypeCount
= 23;
99 Ip6ModeData
->IcmpTypeList
= AllocateCopyPool (
100 Ip6ModeData
->IcmpTypeCount
* sizeof (EFI_IP6_ICMP_TYPE
),
103 if (Ip6ModeData
->IcmpTypeList
== NULL
) {
104 Status
= EFI_OUT_OF_RESOURCES
;
109 // Return the currently configured IPv6 addresses and corresponding prefix lengths.
111 Status
= Ip6BuildEfiAddressList (
113 &Ip6ModeData
->AddressCount
,
114 &Ip6ModeData
->AddressList
116 if (EFI_ERROR (Status
)) {
121 // Return the current station address for this IP child.
122 // If UseAnyStationAddress is set to TRUE, IP6 driver will
123 // select a source address from its address list. Otherwise use the
124 // StationAddress in config data.
126 if (Ip6ModeData
->IsStarted
) {
127 Config
= &Ip6ModeData
->ConfigData
;
129 if (IpIf
->Configured
|| NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
130 Ip6ModeData
->IsConfigured
= TRUE
;
132 Ip6ModeData
->IsConfigured
= FALSE
;
136 // Build a EFI route table for user from the internal route table.
138 Status
= Ip6BuildEfiRouteTable (
140 &Ip6ModeData
->RouteCount
,
141 &Ip6ModeData
->RouteTable
144 if (EFI_ERROR (Status
)) {
149 if (Ip6ModeData
->IsConfigured
) {
151 // Return the joined multicast group addresses.
153 if (IpInstance
->GroupCount
!= 0) {
154 Ip6ModeData
->GroupTable
= AllocateCopyPool (
155 IpInstance
->GroupCount
* sizeof (EFI_IPv6_ADDRESS
),
156 IpInstance
->GroupList
158 if (Ip6ModeData
->GroupTable
== NULL
) {
159 Status
= EFI_OUT_OF_RESOURCES
;
164 // Return the neighbor cache entries
166 Status
= Ip6BuildEfiNeighborCache (
168 &Ip6ModeData
->NeighborCount
,
169 &Ip6ModeData
->NeighborCache
171 if (EFI_ERROR (Status
)) {
176 // Return the prefix table entries
178 Status
= Ip6BuildPrefixTable (
180 &Ip6ModeData
->PrefixCount
,
181 &Ip6ModeData
->PrefixTable
183 if (EFI_ERROR (Status
)) {
191 // Get fresh mode data from MNP, since underlying media status may change
193 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, MnpConfigData
, SnpModeData
);
198 if (Ip6ModeData
!= NULL
) {
199 if (Ip6ModeData
->AddressList
!= NULL
) {
200 FreePool (Ip6ModeData
->AddressList
);
203 if (Ip6ModeData
->GroupTable
!= NULL
) {
204 FreePool (Ip6ModeData
->GroupTable
);
207 if (Ip6ModeData
->RouteTable
!= NULL
) {
208 FreePool (Ip6ModeData
->RouteTable
);
211 if (Ip6ModeData
->NeighborCache
!= NULL
) {
212 FreePool (Ip6ModeData
->NeighborCache
);
215 if (Ip6ModeData
->PrefixTable
!= NULL
) {
216 FreePool (Ip6ModeData
->PrefixTable
);
219 if (Ip6ModeData
->IcmpTypeList
!= NULL
) {
220 FreePool (Ip6ModeData
->IcmpTypeList
);
225 gBS
->RestoreTPL (OldTpl
);
230 Validate that Ipv6 address is OK to be used as station address or next hop address/ neighbor.
232 @param[in] IpSb The IP6 service instance.
233 @param[in] Ip The IPv6 address to validate.
234 @param[in] Flag If TRUE, validate if the address is OK to be used
235 as station address. If FALSE, validate if the
236 address is OK to be used as the next hop address/
239 @retval TRUE The Ip address is valid and could be used.
240 @retval FALSE Invalid Ip address.
245 IN IP6_SERVICE
*IpSb
,
246 IN EFI_IPv6_ADDRESS
*Ip
,
250 if (!NetIp6IsUnspecifiedAddr (Ip
)) {
251 if (!NetIp6IsValidUnicast(Ip
)) {
254 if (Ip6IsOneOfSetAddress (IpSb
, Ip
, NULL
, NULL
)) {
261 return (BOOLEAN
) !Flag
;
265 Validate whether the value of protocol is illegal or not. Protocol is the 'Next Header' field
266 in the last IPv6 extension header, or basic IPv6 header is there's no extension header.
268 @param[in] Protocol Default value of 'Next Header'
270 @retval TRUE The protocol is illegal.
271 @retval FALSE The protocol is legal.
275 Ip6IsIllegalProtocol (
279 if (Protocol
== IP6_HOP_BY_HOP
|| Protocol
== EFI_IP_PROTO_ICMP
|| Protocol
== IP4_PROTO_IGMP
) {
283 if (Protocol
== 41 || Protocol
== 43 || Protocol
== 44 || Protocol
== 59 || Protocol
== 60 || Protocol
== 124) {
291 Intiialize the IP6_PROTOCOL structure to the unconfigured states.
293 @param[in] IpSb The IP6 service instance.
294 @param[in, out] IpInstance The IP6 child instance.
299 IN IP6_SERVICE
*IpSb
,
300 IN OUT IP6_PROTOCOL
*IpInstance
303 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
305 ZeroMem (IpInstance
, sizeof (IP6_PROTOCOL
));
307 IpInstance
->Signature
= IP6_PROTOCOL_SIGNATURE
;
308 IpInstance
->State
= IP6_STATE_UNCONFIGED
;
309 IpInstance
->Service
= IpSb
;
310 IpInstance
->GroupList
= NULL
;
311 CopyMem (&IpInstance
->Ip6Proto
, &mEfiIp6ProtocolTemplete
, sizeof (EFI_IP6_PROTOCOL
));
313 NetMapInit (&IpInstance
->RxTokens
);
314 NetMapInit (&IpInstance
->TxTokens
);
315 InitializeListHead (&IpInstance
->Received
);
316 InitializeListHead (&IpInstance
->Delivered
);
318 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
322 Configure the IP6 child. If the child is already configured,
323 change the configuration parameter. Otherwise, configure it
324 for the first time. The caller should validate the configuration
325 before deliver them to it. It also don't do configure NULL.
327 @param[in, out] IpInstance The IP6 child to configure.
328 @param[in] Config The configure data.
330 @retval EFI_SUCCESS The IP6 child is successfully configured.
331 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
332 configure underlying MNP, or other errors.
333 @retval EFI_NO_MAPPING The IP6 child is configured to use the default
334 address, but the default address hasn't been
335 configured. The IP6 child doesn't need to be
336 reconfigured when the default address is configured.
337 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
338 @retval other Other error occurs.
343 IN OUT IP6_PROTOCOL
*IpInstance
,
344 IN EFI_IP6_CONFIG_DATA
*Config
350 EFI_IP6_CONFIG_DATA
*Current
;
351 IP6_ADDRESS_INFO
*AddressInfo
;
354 EFI_IPv6_ADDRESS Source
;
357 IpSb
= IpInstance
->Service
;
358 Current
= &IpInstance
->ConfigData
;
361 // User is changing packet filters. It must be stopped
362 // before the station address can be changed.
364 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
366 // Cancel all the pending transmit/receive from upper layer
368 Status
= Ip6Cancel (IpInstance
, NULL
);
370 if (EFI_ERROR (Status
)) {
371 return EFI_DEVICE_ERROR
;
374 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
379 // Set up the interface.
381 StationZero
= NetIp6IsUnspecifiedAddr (&Config
->StationAddress
);
382 DestZero
= NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
);
384 if (StationZero
&& DestZero
) {
386 // StationAddress is still zero.
389 NET_GET_REF (IpSb
->DefaultInterface
);
390 IpInstance
->Interface
= IpSb
->DefaultInterface
;
391 InsertTailList (&IpSb
->DefaultInterface
->IpInstances
, &IpInstance
->AddrLink
);
393 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
394 IpInstance
->State
= IP6_STATE_CONFIGED
;
399 if (StationZero
&& !DestZero
) {
400 Status
= Ip6SelectSourceAddress (IpSb
, &Config
->DestinationAddress
, &Source
);
401 if (EFI_ERROR (Status
)) {
405 IP6_COPY_ADDRESS (&Source
, &Config
->StationAddress
);
408 AddrOk
= Ip6IsOneOfSetAddress (IpSb
, &Source
, &IpIf
, &AddressInfo
);
410 if (AddressInfo
!= NULL
) {
411 IpInstance
->PrefixLength
= AddressInfo
->PrefixLength
;
413 IpInstance
->PrefixLength
= IP6_LINK_LOCAL_PREFIX_LENGTH
;
417 // The specified source address is not one of the addresses IPv6 maintains.
419 return EFI_INVALID_PARAMETER
;
424 IpInstance
->Interface
= IpIf
;
425 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
427 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
428 IP6_COPY_ADDRESS (&Current
->StationAddress
, &Source
);
429 IpInstance
->State
= IP6_STATE_CONFIGED
;
435 Clean up the IP6 child, and release all the resources used by it.
437 @param[in, out] IpInstance The IP6 child to clean up.
439 @retval EFI_SUCCESS The IP6 child is cleaned up.
440 @retval EFI_DEVICE_ERROR Some resources failed to be released.
445 IN OUT IP6_PROTOCOL
*IpInstance
448 if (EFI_ERROR (Ip6Cancel (IpInstance
, NULL
))) {
449 return EFI_DEVICE_ERROR
;
452 if (EFI_ERROR (Ip6Groups (IpInstance
, FALSE
, NULL
))) {
453 return EFI_DEVICE_ERROR
;
457 // Some packets haven't been recycled. It is because either the
458 // user forgets to recycle the packets, or because the callback
459 // hasn't been called. Just leave it alone.
461 if (!IsListEmpty (&IpInstance
->Delivered
)) {
465 if (IpInstance
->Interface
!= NULL
) {
466 RemoveEntryList (&IpInstance
->AddrLink
);
467 Ip6CleanInterface (IpInstance
->Interface
, IpInstance
);
468 IpInstance
->Interface
= NULL
;
471 if (IpInstance
->GroupList
!= NULL
) {
472 FreePool (IpInstance
->GroupList
);
473 IpInstance
->GroupList
= NULL
;
474 IpInstance
->GroupCount
= 0;
477 NetMapClean (&IpInstance
->TxTokens
);
479 NetMapClean (&IpInstance
->RxTokens
);
485 Configure the MNP parameter used by IP. The IP driver uses one MNP
486 child to transmit/receive frames. By default, it configures MNP
487 to receive unicast/multicast/broadcast. Also, it will enable/disable
488 the promiscuous receive according to whether there is IP child
489 enable that or not. If Force is FALSE, it will iterate through
490 all the IP children to check whether the promiscuous receive
491 setting has been changed. If it hasn't been changed, it won't
492 reconfigure the MNP. If Force is TRUE, the MNP is configured
493 whether that is changed or not.
495 @param[in] IpSb The IP6 service instance that is to be changed.
496 @param[in] Force Force the configuration or not.
498 @retval EFI_SUCCESS The MNP successfully configured/reconfigured.
499 @retval Others Configuration failed.
503 Ip6ServiceConfigMnp (
504 IN IP6_SERVICE
*IpSb
,
509 LIST_ENTRY
*ProtoEntry
;
511 IP6_PROTOCOL
*IpInstance
;
513 BOOLEAN PromiscReceive
;
517 PromiscReceive
= FALSE
;
521 // Iterate through the IP children to check whether promiscuous
522 // receive setting has been changed. Update the interface's receive
525 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
527 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
528 IpIf
->PromiscRecv
= FALSE
;
530 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
531 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP6_PROTOCOL
, AddrLink
);
533 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
534 IpIf
->PromiscRecv
= TRUE
;
535 PromiscReceive
= TRUE
;
541 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
543 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
548 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
551 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
554 // recover the original configuration if failed to set the configure.
556 if (EFI_ERROR (Status
) && Reconfig
) {
557 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
564 Assigns an IPv6 address and subnet mask to this EFI IPv6 Protocol driver instance.
566 The Configure() function is used to set, change, or reset the operational parameters and filter
567 settings for this EFI IPv6 Protocol instance. Until these parameters have been set, no network traffic
568 can be sent or received by this instance. Once the parameters have been reset (by calling this
569 function with Ip6ConfigData set to NULL), no more traffic can be sent or received until these
570 parameters have been set again. Each EFI IPv6 Protocol instance can be started and stopped
571 independently of each other by enabling or disabling their receive filter settings with the
572 Configure() function.
574 If Ip6ConfigData.StationAddress is a valid non-zero IPv6 unicast address, it is required
575 to be one of the currently configured IPv6 addresses listed in the EFI IPv6 drivers, or else
576 EFI_INVALID_PARAMETER will be returned. If Ip6ConfigData.StationAddress is
577 unspecified, the IPv6 driver will bind a source address according to the source address selection
578 algorithm. Clients could frequently call GetModeData() to check get currently configured IPv6
579 address list in the EFI IPv6 driver. If both Ip6ConfigData.StationAddress and
580 Ip6ConfigData.Destination are unspecified, when transmitting the packet afterwards, the
581 source address filled in each outgoing IPv6 packet is decided based on the destination of this packet.
583 If operational parameters are reset or changed, any pending transmit and receive requests will be
584 cancelled. Their completion token status will be set to EFI_ABORTED and their events will be
587 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
588 @param[in] Ip6ConfigData Pointer to the EFI IPv6 Protocol configuration data structure.
589 If NULL, reset the configuration data.
591 @retval EFI_SUCCESS The driver instance was successfully opened.
592 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
594 - Ip6ConfigData.StationAddress is neither zero nor
595 a unicast IPv6 address.
596 - Ip6ConfigData.StationAddress is neither zero nor
597 one of the configured IP addresses in the EFI IPv6 driver.
598 - Ip6ConfigData.DefaultProtocol is illegal.
599 @retval EFI_OUT_OF_RESOURCES The EFI IPv6 Protocol driver instance data could not be allocated.
600 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing a source address for
601 this instance, but no source address was available for use.
602 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the IPv6
603 address or prefix length can be changed.
604 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv6
605 Protocol driver instance was not opened.
606 @retval EFI_UNSUPPORTED Default protocol specified through
607 Ip6ConfigData.DefaulProtocol isn't supported.
613 IN EFI_IP6_PROTOCOL
*This
,
614 IN EFI_IP6_CONFIG_DATA
*Ip6ConfigData OPTIONAL
617 IP6_PROTOCOL
*IpInstance
;
618 EFI_IP6_CONFIG_DATA
*Current
;
624 // First, validate the parameters
627 return EFI_INVALID_PARAMETER
;
630 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
631 IpSb
= IpInstance
->Service
;
633 if (IpSb
->LinkLocalDadFail
&& Ip6ConfigData
!= NULL
) {
634 return EFI_DEVICE_ERROR
;
637 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
639 Status
= EFI_INVALID_PARAMETER
;
642 // Validate the configuration first.
644 if (Ip6ConfigData
!= NULL
) {
646 // Check whether the station address is valid.
648 if (!Ip6IsValidAddress (IpSb
, &Ip6ConfigData
->StationAddress
, TRUE
)) {
652 // Check whether the default protocol is valid.
654 if (Ip6IsIllegalProtocol (Ip6ConfigData
->DefaultProtocol
)) {
659 // User can only update packet filters when already configured.
660 // If it wants to change the station address, it must configure(NULL)
661 // the instance firstly.
663 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
664 Current
= &IpInstance
->ConfigData
;
666 if (!EFI_IP6_EQUAL (&Current
->StationAddress
, &Ip6ConfigData
->StationAddress
)) {
667 Status
= EFI_ALREADY_STARTED
;
671 if (NetIp6IsUnspecifiedAddr (&Current
->StationAddress
) && IP6_NO_MAPPING (IpInstance
)) {
672 Status
= EFI_NO_MAPPING
;
679 // Configure the instance or clean it up.
681 if (Ip6ConfigData
!= NULL
) {
682 Status
= Ip6ConfigProtocol (IpInstance
, Ip6ConfigData
);
684 Status
= Ip6CleanProtocol (IpInstance
);
687 // Don't change the state if it is DESTROY, consider the following
688 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
689 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
690 // the unload fails miserably.
692 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
693 IpInstance
->State
= IP6_STATE_UNCONFIGED
;
698 // Update the MNP's configure data. Ip6ServiceConfigMnp will check
699 // whether it is necessary to reconfigure the MNP.
701 Ip6ServiceConfigMnp (IpInstance
->Service
, FALSE
);
704 gBS
->RestoreTPL (OldTpl
);
709 Joins and leaves multicast groups.
711 The Groups() function is used to join and leave multicast group sessions. Joining a group will
712 enable reception of matching multicast packets. Leaving a group will disable reception of matching
713 multicast packets. Source-Specific Multicast isn't required to be supported.
715 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
717 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
718 @param[in] JoinFlag Set to TRUE to join the multicast group session, and FALSE to leave.
719 @param[in] GroupAddress Pointer to the IPv6 multicast address.
720 This is an optional parameter that may be NULL.
722 @retval EFI_SUCCESS The operation completed successfully.
723 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
725 - JoinFlag is TRUE and GroupAddress is NULL.
726 - GroupAddress is not NULL and *GroupAddress is
727 not a multicast IPv6 address.
728 - GroupAddress is not NULL and *GroupAddress is in the
729 range of SSM destination address.
730 @retval EFI_NOT_STARTED This instance has not been started.
731 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
732 @retval EFI_UNSUPPORTED This EFI IPv6 Protocol implementation does not support multicast groups.
733 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
735 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
736 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
742 IN EFI_IP6_PROTOCOL
*This
,
744 IN EFI_IPv6_ADDRESS
*GroupAddress OPTIONAL
749 IP6_PROTOCOL
*IpInstance
;
752 if ((This
== NULL
) || (JoinFlag
&& GroupAddress
== NULL
)) {
753 return EFI_INVALID_PARAMETER
;
756 if (GroupAddress
!= NULL
&& !IP6_IS_MULTICAST (GroupAddress
)) {
757 return EFI_INVALID_PARAMETER
;
760 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
761 IpSb
= IpInstance
->Service
;
763 if (IpSb
->LinkLocalDadFail
) {
764 return EFI_DEVICE_ERROR
;
767 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
769 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
770 Status
= EFI_NOT_STARTED
;
774 Status
= Ip6Groups (IpInstance
, JoinFlag
, GroupAddress
);
777 gBS
->RestoreTPL (OldTpl
);
782 Adds and deletes routing table entries.
784 The Routes() function adds a route to, or deletes a route from, the routing table.
786 Routes are determined by comparing the leftmost PrefixLength bits of Destination with
787 the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the
788 configured station address.
790 The default route is added with Destination and PrefixLegth both set to all zeros. The
791 default route matches all destination IPv6 addresses that do not match any other routes.
793 All EFI IPv6 Protocol instances share a routing table.
795 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
796 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
797 FALSE to add this route to the routing table. Destination,
798 PrefixLength and Gateway are used as the key to each
800 @param[in] Destination The address prefix of the subnet that needs to be routed.
801 This is an optional parameter that may be NULL.
802 @param[in] PrefixLength The prefix length of Destination. Ignored if Destination
804 @param[in] GatewayAddress The unicast gateway IPv6 address for this route.
805 This is an optional parameter that may be NULL.
807 @retval EFI_SUCCESS The operation completed successfully.
808 @retval EFI_NOT_STARTED The driver instance has not been started.
809 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
811 - When DeleteRoute is TRUE, both Destination and
812 GatewayAddress are NULL.
813 - When DeleteRoute is FALSE, either Destination or
814 GatewayAddress is NULL.
815 - *GatewayAddress is not a valid unicast IPv6 address.
816 - *GatewayAddress is one of the local configured IPv6
818 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
819 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
820 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
821 DeleteRoute is FALSE).
827 IN EFI_IP6_PROTOCOL
*This
,
828 IN BOOLEAN DeleteRoute
,
829 IN EFI_IPv6_ADDRESS
*Destination OPTIONAL
,
830 IN UINT8 PrefixLength
,
831 IN EFI_IPv6_ADDRESS
*GatewayAddress OPTIONAL
834 IP6_PROTOCOL
*IpInstance
;
839 if ((This
== NULL
) || (PrefixLength
> IP6_PREFIX_MAX
)) {
840 return EFI_INVALID_PARAMETER
;
843 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
844 IpSb
= IpInstance
->Service
;
846 if (IpSb
->LinkLocalDadFail
) {
847 return EFI_DEVICE_ERROR
;
850 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
851 return EFI_NOT_STARTED
;
854 if (DeleteRoute
&& (Destination
== NULL
) && (GatewayAddress
== NULL
)) {
855 return EFI_INVALID_PARAMETER
;
858 if (!DeleteRoute
&& (Destination
== NULL
|| GatewayAddress
== NULL
)) {
859 return EFI_INVALID_PARAMETER
;
862 if (GatewayAddress
!= NULL
) {
863 if (!Ip6IsValidAddress (IpSb
, GatewayAddress
, FALSE
)) {
864 return EFI_INVALID_PARAMETER
;
867 if (!NetIp6IsUnspecifiedAddr (GatewayAddress
) &&
868 !NetIp6IsNetEqual (GatewayAddress
, &IpInstance
->ConfigData
.StationAddress
, PrefixLength
)
870 return EFI_INVALID_PARAMETER
;
874 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
877 // Update the route table
880 Status
= Ip6DelRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
882 Status
= Ip6AddRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
885 gBS
->RestoreTPL (OldTpl
);
890 Add or delete Neighbor cache entries.
892 The Neighbors() function is used to add, update, or delete an entry from neighbor cache.
893 IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as
894 network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network
895 traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not
896 timeout) or dynamic (will timeout).
898 The implementation should follow the neighbor cache timeout mechanism which is defined in
899 RFC4861. The default neighbor cache timeout value should be tuned for the expected network
902 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
903 @param[in] DeleteFlag Set to TRUE to delete the specified cache entry, set to FALSE to
904 add (or update, if it already exists and Override is TRUE) the
905 specified cache entry. TargetIp6Address is used as the key
906 to find the requested cache entry.
907 @param[in] TargetIp6Address Pointer to the Target IPv6 address.
908 @param[in] TargetLinkAddress Pointer to the link-layer address of the target. Ignored if NULL.
909 @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
910 cache, it will be deleted after Timeout. A value of zero means that
911 the entry is permanent. A non-zero value means that the entry is
913 @param[in] Override If TRUE, the cached link-layer address of the matching entry will
914 be overridden and updated; if FALSE, EFI_ACCESS_DENIED
915 will be returned if a corresponding cache entry already existed.
917 @retval EFI_SUCCESS The data has been queued for transmission.
918 @retval EFI_NOT_STARTED This instance has not been started.
919 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
921 - TargetIpAddress is NULL.
922 - *TargetLinkAddress is invalid when not NULL.
923 - *TargetIpAddress is not a valid unicast IPv6 address.
924 - *TargetIpAddress is one of the local configured IPv6
926 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache.
927 @retval EFI_NOT_FOUND This entry is not in the neighbor cache (when DeleteFlag is
928 TRUE or when DeleteFlag is FALSE while
929 TargetLinkAddress is NULL.).
930 @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
931 and that entry is tagged as un-overridden (when Override
938 IN EFI_IP6_PROTOCOL
*This
,
939 IN BOOLEAN DeleteFlag
,
940 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
941 IN EFI_MAC_ADDRESS
*TargetLinkAddress OPTIONAL
,
948 IP6_PROTOCOL
*IpInstance
;
951 if (This
== NULL
|| TargetIp6Address
== NULL
) {
952 return EFI_INVALID_PARAMETER
;
955 if (NetIp6IsUnspecifiedAddr (TargetIp6Address
)) {
956 return EFI_INVALID_PARAMETER
;
959 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
960 IpSb
= IpInstance
->Service
;
962 if (IpSb
->LinkLocalDadFail
) {
963 return EFI_DEVICE_ERROR
;
966 if (!Ip6IsValidAddress (IpSb
, TargetIp6Address
, FALSE
)) {
967 return EFI_INVALID_PARAMETER
;
970 if (TargetLinkAddress
!= NULL
) {
971 if (!Ip6IsValidLinkAddress (IpSb
, TargetLinkAddress
)) {
972 return EFI_INVALID_PARAMETER
;
976 if (Ip6IsOneOfSetAddress (IpSb
, TargetIp6Address
, NULL
, NULL
)) {
977 return EFI_INVALID_PARAMETER
;
980 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
981 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
982 Status
= EFI_NOT_STARTED
;
987 Status
= Ip6DelNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
989 Status
= Ip6AddNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
993 gBS
->RestoreTPL (OldTpl
);
998 Check whether the user's token or event has already
999 been enqueue on IP6's list.
1001 @param[in] Map The container of either user's transmit or receive
1003 @param[in] Item Current item to check against.
1004 @param[in] Context The Token to check againist.
1006 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1007 @retval EFI_SUCCESS The current item isn't the same token/event as the
1015 IN NET_MAP_ITEM
*Item
,
1019 EFI_IP6_COMPLETION_TOKEN
*Token
;
1020 EFI_IP6_COMPLETION_TOKEN
*TokenInItem
;
1022 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1023 TokenInItem
= (EFI_IP6_COMPLETION_TOKEN
*) Item
->Key
;
1025 if (Token
== TokenInItem
|| Token
->Event
== TokenInItem
->Event
) {
1026 return EFI_ACCESS_DENIED
;
1033 Validate the user's token against the current station address.
1035 @param[in] Token User's token to validate.
1037 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1038 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1039 @retval EFI_SUCCESS The token is OK.
1044 IN EFI_IP6_COMPLETION_TOKEN
*Token
1047 EFI_IP6_TRANSMIT_DATA
*TxData
;
1051 if (Token
== NULL
|| Token
->Event
== NULL
) {
1052 return EFI_INVALID_PARAMETER
;
1055 TxData
= Token
->Packet
.TxData
;
1057 if (TxData
== NULL
|| (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
== NULL
)) {
1058 return EFI_INVALID_PARAMETER
;
1061 if (TxData
->FragmentCount
== 0 || TxData
->DataLength
== 0) {
1062 return EFI_INVALID_PARAMETER
;
1065 for (DataLength
= 0, Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1066 if (TxData
->FragmentTable
[Index
].FragmentLength
== 0 || TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) {
1067 return EFI_INVALID_PARAMETER
;
1070 DataLength
+= TxData
->FragmentTable
[Index
].FragmentLength
;
1073 if (TxData
->DataLength
!= DataLength
) {
1074 return EFI_INVALID_PARAMETER
;
1078 // TODO: Token.Packet.TxData.DataLength is too short to transmit.
1079 // return EFI_BUFFER_TOO_SMALL;
1083 // If Token.Packet.TxData.DataLength is beyond the maximum that which can be
1084 // described through the Fragment Offset field in Fragment header when performing
1087 if (TxData
->DataLength
> 64 * 1024) {
1088 return EFI_BAD_BUFFER_SIZE
;
1095 The callback function for the net buffer which wraps the user's
1096 transmit token. Although this function seems simple, there
1097 are some subtle aspects.
1098 When user requests the IP to transmit a packet by passing it a
1099 token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data
1100 is wrapped in an net buffer. The net buffer's Free function is
1101 set to Ip6FreeTxToken. The Token and token wrap are added to the
1102 IP child's TxToken map. Then the buffer is passed to Ip6Output for
1103 transmission. If an error happened before that, the buffer
1104 is freed, which in turn frees the token wrap. The wrap may
1105 have been added to the TxToken map or not, and the user's event
1106 shouldn't be fired because we are still in the EfiIp6Transmit. If
1107 the buffer has been sent by Ip6Output, it should be removed from
1108 the TxToken map and user's event signaled. The token wrap and buffer
1109 are bound together. Check the comments in Ip6Output for information
1110 about IP fragmentation.
1112 @param[in] Context The token's wrap.
1121 IP6_TXTOKEN_WRAP
*Wrap
;
1124 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1127 // Signal IpSecRecycleEvent to inform IPsec free the memory
1129 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1130 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1134 // Find the token in the instance's map. EfiIp6Transmit put the
1135 // token to the map. If that failed, NetMapFindKey will return NULL.
1137 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1140 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1144 gBS
->SignalEvent (Wrap
->Token
->Event
);
1147 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1157 The callback function to Ip6Output to update the transmit status.
1159 @param[in] Packet The user's transmit packet.
1160 @param[in] IoStatus The result of the transmission.
1161 @param[in] Flag Not used during transmission.
1162 @param[in] Context The token's wrap.
1168 IN EFI_STATUS IoStatus
,
1173 IP6_TXTOKEN_WRAP
*Wrap
;
1176 // This is the transmission request from upper layer,
1177 // not the IP6 driver itself.
1179 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1180 Wrap
->Token
->Status
= IoStatus
;
1182 NetbufFree (Wrap
->Packet
);
1186 Places outgoing data packets into the transmit queue.
1188 The Transmit() function places a sending request in the transmit queue of this
1189 EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some
1190 errors occur, the event in the token will be signaled, and the status is updated.
1192 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1193 @param[in] Token Pointer to the transmit token.
1195 @retval EFI_SUCCESS The data has been queued for transmission.
1196 @retval EFI_NOT_STARTED This instance has not been started.
1197 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing
1198 a source address for this transmission,
1199 but no source address was available for use.
1200 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1203 - Token.Event is NULL.
1204 - Token.Packet.TxData is NULL.
1205 - Token.Packet.ExtHdrsLength is not zero and
1206 Token.Packet.ExtHdrs is NULL.
1207 - Token.Packet.FragmentCount is zero.
1208 - One or more of the Token.Packet.TxData.
1209 FragmentTable[].FragmentLength fields is zero.
1210 - One or more of the Token.Packet.TxData.
1211 FragmentTable[].FragmentBuffer fields is NULL.
1212 - Token.Packet.TxData.DataLength is zero or not
1213 equal to the sum of fragment lengths.
1214 - Token.Packet.TxData.DestinationAddress is non
1215 zero when DestinationAddress is configured as
1216 non-zero when doing Configure() for this
1217 EFI IPv6 protocol instance.
1218 - Token.Packet.TxData.DestinationAddress is
1219 unspecified when DestinationAddress is unspecified
1220 when doing Configure() for this EFI IPv6 protocol
1222 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.
1223 Event was already in the transmit queue.
1224 @retval EFI_NOT_READY The completion token could not be queued because
1225 the transmit queue is full.
1226 @retval EFI_NOT_FOUND Not route is found to destination address.
1227 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1228 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1230 @retval EFI_BAD_BUFFER_SIZE If Token.Packet.TxData.DataLength is beyond the
1231 maximum that which can be described through the
1232 Fragment Offset field in Fragment header when
1233 performing fragmentation.
1234 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1240 IN EFI_IP6_PROTOCOL
*This
,
1241 IN EFI_IP6_COMPLETION_TOKEN
*Token
1245 IP6_PROTOCOL
*IpInstance
;
1246 EFI_IP6_CONFIG_DATA
*Config
;
1249 EFI_IP6_HEADER Head
;
1250 EFI_IP6_TRANSMIT_DATA
*TxData
;
1251 EFI_IP6_OVERRIDE_DATA
*Override
;
1252 IP6_TXTOKEN_WRAP
*Wrap
;
1256 // Check input parameters.
1259 return EFI_INVALID_PARAMETER
;
1264 Status
= Ip6TxTokenValid (Token
);
1265 if (EFI_ERROR (Status
)) {
1269 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1270 IpSb
= IpInstance
->Service
;
1272 if (IpSb
->LinkLocalDadFail
) {
1273 return EFI_DEVICE_ERROR
;
1276 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1278 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1279 Status
= EFI_NOT_STARTED
;
1283 Config
= &IpInstance
->ConfigData
;
1286 // Check whether the token or signal already existed.
1288 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip6TokenExist
, Token
))) {
1289 Status
= EFI_ACCESS_DENIED
;
1294 // Build the IP header, fill in the information from ConfigData or OverrideData
1296 ZeroMem (&Head
, sizeof(EFI_IP6_HEADER
));
1297 TxData
= Token
->Packet
.TxData
;
1298 IP6_COPY_ADDRESS (&Head
.SourceAddress
, &Config
->StationAddress
);
1299 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &Config
->DestinationAddress
);
1301 Status
= EFI_INVALID_PARAMETER
;
1303 if (NetIp6IsUnspecifiedAddr (&TxData
->DestinationAddress
)) {
1304 if (NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1308 ASSERT (!NetIp6IsUnspecifiedAddr (&Config
->StationAddress
));
1312 // StationAddress is unspecified only when ConfigData.Dest is unspecified.
1313 // Use TxData.Dest to override the DestinationAddress.
1315 if (!NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1319 if (NetIp6IsUnspecifiedAddr (&Config
->StationAddress
)) {
1320 Status
= Ip6SelectSourceAddress (
1322 &TxData
->DestinationAddress
,
1325 if (EFI_ERROR (Status
)) {
1330 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &TxData
->DestinationAddress
);
1334 // Fill in Head infos.
1336 Head
.NextHeader
= Config
->DefaultProtocol
;
1337 if (TxData
->ExtHdrsLength
!= 0) {
1338 Head
.NextHeader
= TxData
->NextHeader
;
1341 if (TxData
->OverrideData
!= NULL
) {
1342 Override
= TxData
->OverrideData
;
1343 Head
.NextHeader
= Override
->Protocol
;
1344 Head
.HopLimit
= Override
->HopLimit
;
1345 Head
.FlowLabelL
= HTONS ((UINT16
) Override
->FlowLabel
);
1346 Head
.FlowLabelH
= (UINT8
) ((Override
->FlowLabel
>> 16) & 0x0F);
1348 Head
.HopLimit
= Config
->HopLimit
;
1349 Head
.FlowLabelL
= HTONS ((UINT16
) Config
->FlowLabel
);
1350 Head
.FlowLabelH
= (UINT8
) ((Config
->FlowLabel
>> 16) & 0x0F);
1353 Head
.PayloadLength
= HTONS ((UINT16
) (TxData
->ExtHdrsLength
+ TxData
->DataLength
));
1356 // OK, it survives all the validation check. Wrap the token in
1357 // a IP6_TXTOKEN_WRAP and the data in a netbuf
1359 Status
= EFI_OUT_OF_RESOURCES
;
1360 Wrap
= AllocateZeroPool (sizeof (IP6_TXTOKEN_WRAP
));
1365 Wrap
->IpInstance
= IpInstance
;
1366 Wrap
->Token
= Token
;
1368 Wrap
->Life
= IP6_US_TO_SEC (Config
->TransmitTimeout
);
1369 Wrap
->Packet
= NetbufFromExt (
1370 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1371 TxData
->FragmentCount
,
1378 if (Wrap
->Packet
== NULL
) {
1383 Token
->Status
= EFI_NOT_READY
;
1385 Status
= NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
);
1386 if (EFI_ERROR (Status
)) {
1388 // NetbufFree will call Ip6FreeTxToken, which in turn will
1389 // free the IP6_TXTOKEN_WRAP. Now, the token wrap hasn't been
1392 NetbufFree (Wrap
->Packet
);
1397 // Allocate a new buffer to store IPv6 extension headers to avoid updating
1398 // the original data in EFI_IP6_COMPLETION_TOKEN.
1400 if (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
!= NULL
) {
1401 ExtHdrs
= (UINT8
*) AllocateCopyPool (TxData
->ExtHdrsLength
, TxData
->ExtHdrs
);
1402 if (ExtHdrs
== NULL
) {
1403 Status
= EFI_OUT_OF_RESOURCES
;
1409 // Mark the packet sent before output it. Mark it not sent again if the
1410 // returned status is not EFI_SUCCESS;
1414 Status
= Ip6Output (
1421 TxData
->ExtHdrsLength
,
1425 if (EFI_ERROR (Status
)) {
1427 NetbufFree (Wrap
->Packet
);
1431 gBS
->RestoreTPL (OldTpl
);
1433 if (ExtHdrs
!= NULL
) {
1441 Places a receiving request into the receiving queue.
1443 The Receive() function places a completion token into the receive packet queue.
1444 This function is always asynchronous.
1446 The Token.Event field in the completion token must be filled in by the caller
1447 and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol
1448 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1451 Current Udp implementation creates an IP child for each Udp child.
1452 It initates a asynchronous receive immediately no matter whether
1453 there is no mapping or not. Therefore, disable the returning EFI_NO_MAPPING for now.
1454 To enable it, the following check must be performed:
1456 if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
1457 Status = EFI_NO_MAPPING;
1461 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1462 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1464 @retval EFI_SUCCESS The receive completion token was cached.
1465 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1466 @retval EFI_NO_MAPPING When IP6 driver responsible for binding source address to this instance,
1467 while no source address is available for use.
1468 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1471 - Token.Event is NULL.
1472 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1473 resources (usually memory).
1474 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1475 The EFI IPv6 Protocol instance has been reset to startup defaults.
1476 @retval EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1477 in the receive queue.
1478 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1484 IN EFI_IP6_PROTOCOL
*This
,
1485 IN EFI_IP6_COMPLETION_TOKEN
*Token
1488 IP6_PROTOCOL
*IpInstance
;
1493 if (This
== NULL
|| Token
== NULL
|| Token
->Event
== NULL
) {
1494 return EFI_INVALID_PARAMETER
;
1497 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1498 IpSb
= IpInstance
->Service
;
1500 if (IpSb
->LinkLocalDadFail
) {
1501 return EFI_DEVICE_ERROR
;
1504 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1506 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1507 Status
= EFI_NOT_STARTED
;
1512 // Check whether the toke is already on the receive queue.
1514 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6TokenExist
, Token
);
1516 if (EFI_ERROR (Status
)) {
1517 Status
= EFI_ACCESS_DENIED
;
1522 // Queue the token then check whether there is pending received packet.
1524 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1526 if (EFI_ERROR (Status
)) {
1530 Status
= Ip6InstanceDeliverPacket (IpInstance
);
1533 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1539 gBS
->RestoreTPL (OldTpl
);
1545 Cancel the transmitted but not recycled packet. If a matching
1546 token is found, it will call Ip6CancelPacket to cancel the
1547 packet. Ip6CancelPacket cancels all the fragments of the
1548 packet. When all the fragments are freed, the IP6_TXTOKEN_WRAP
1549 is deleted from the Map, and user's event is signalled.
1550 Because Ip6CancelPacket and other functions are all called in
1551 line, after Ip6CancelPacket returns, the Item has been freed.
1553 @param[in] Map The IP6 child's transmit queue.
1554 @param[in] Item The current transmitted packet to test.
1555 @param[in] Context The user's token to cancel.
1557 @retval EFI_SUCCESS Continue to check the next Item.
1558 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1565 IN NET_MAP_ITEM
*Item
,
1569 EFI_IP6_COMPLETION_TOKEN
*Token
;
1570 IP6_TXTOKEN_WRAP
*Wrap
;
1572 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1575 // Return EFI_SUCCESS to check the next item in the map if
1576 // this one doesn't match.
1578 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1582 Wrap
= (IP6_TXTOKEN_WRAP
*) Item
->Value
;
1583 ASSERT (Wrap
!= NULL
);
1586 // Don't access the Item, Wrap and Token's members after this point.
1587 // Item and wrap has been freed. And we no longer own the Token.
1589 Ip6CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1592 // If only one item is to be cancel, return EFI_ABORTED to stop
1593 // iterating the map any more.
1595 if (Token
!= NULL
) {
1604 Cancel the receive request. This is simple, because
1605 it is only enqueued in our local receive map.
1607 @param[in] Map The IP6 child's receive queue.
1608 @param[in] Item Current receive request to cancel.
1609 @param[in] Context The user's token to cancel.
1612 @retval EFI_SUCCESS Continue to check the next receive request on the
1614 @retval EFI_ABORTED The user's token (token != NULL) has been
1622 IN NET_MAP_ITEM
*Item
,
1626 EFI_IP6_COMPLETION_TOKEN
*Token
;
1627 EFI_IP6_COMPLETION_TOKEN
*This
;
1629 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1632 if ((Token
!= NULL
) && (Token
!= This
)) {
1636 NetMapRemoveItem (Map
, Item
, NULL
);
1638 This
->Status
= EFI_ABORTED
;
1639 This
->Packet
.RxData
= NULL
;
1640 gBS
->SignalEvent (This
->Event
);
1642 if (Token
!= NULL
) {
1650 Cancel the user's receive/transmit request. It is the worker function of
1653 @param[in] IpInstance The IP6 child.
1654 @param[in] Token The token to cancel. If NULL, all token will be
1657 @retval EFI_SUCCESS The token is cancelled.
1658 @retval EFI_NOT_FOUND The token isn't found on either the
1659 transmit/receive queue.
1660 @retval EFI_DEVICE_ERROR Not all tokens are cancelled when Token is NULL.
1665 IN IP6_PROTOCOL
*IpInstance
,
1666 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1672 // First check the transmitted packet. Ip6CancelTxTokens returns
1673 // EFI_ABORTED to mean that the token has been cancelled when
1674 // token != NULL. So, return EFI_SUCCESS for this condition.
1676 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip6CancelTxTokens
, Token
);
1677 if (EFI_ERROR (Status
)) {
1678 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1686 // Check the receive queue. Ip6CancelRxTokens also returns EFI_ABORT
1687 // for Token!=NULL and it is cancelled.
1689 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6CancelRxTokens
, Token
);
1691 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
1695 if (EFI_ERROR (Status
)) {
1696 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1704 // OK, if the Token is found when Token != NULL, the NetMapIterate
1705 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
1707 if (Token
!= NULL
) {
1708 return EFI_NOT_FOUND
;
1712 // If Token == NULL, cancel all the tokens. return error if not
1713 // all of them are cancelled.
1715 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) || !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
1717 return EFI_DEVICE_ERROR
;
1724 Abort an asynchronous transmit or receive request.
1726 The Cancel() function is used to abort a pending transmit or receive request.
1727 If the token is in the transmit or receive request queues, after calling this
1728 function, Token->Status will be set to EFI_ABORTED, and then Token->Event will
1729 be signaled. If the token is not in one of the queues, which usually means the
1730 asynchronous operation has completed, this function will not signal the token,
1731 and EFI_NOT_FOUND is returned.
1733 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1734 @param[in] Token Pointer to a token that has been issued by
1735 EFI_IP6_PROTOCOL.Transmit() or
1736 EFI_IP6_PROTOCOL.Receive(). If NULL, all pending
1737 tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is
1738 defined in EFI_IP6_PROTOCOL.Transmit().
1740 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
1741 Token->Event was signaled. When Token is NULL, all
1742 pending requests were aborted, and their events were signaled.
1743 @retval EFI_INVALID_PARAMETER This is NULL.
1744 @retval EFI_NOT_STARTED This instance has not been started.
1745 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
1746 not found in the transmit or receive queue. It has either completed
1747 or was not issued by Transmit() and Receive().
1748 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1754 IN EFI_IP6_PROTOCOL
*This
,
1755 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1758 IP6_PROTOCOL
*IpInstance
;
1763 return EFI_INVALID_PARAMETER
;
1766 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1768 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1770 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1771 Status
= EFI_NOT_STARTED
;
1775 Status
= Ip6Cancel (IpInstance
, Token
);
1778 gBS
->RestoreTPL (OldTpl
);
1783 Polls for incoming data packets, and processes outgoing data packets.
1785 The Poll() function polls for incoming data packets and processes outgoing data
1786 packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()
1787 function to increase the rate that data packets are moved between the communications
1788 device and the transmit and receive queues.
1790 In some systems the periodic timer event may not poll the underlying communications
1791 device fast enough to transmit and/or receive all data packets without missing
1792 incoming packets or dropping outgoing packets. Drivers and applications that are
1793 experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function
1796 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1798 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1799 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1800 @retval EFI_INVALID_PARAMETER This is NULL.
1801 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1802 @retval EFI_NOT_READY No incoming or outgoing data was processed.
1803 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
1804 Consider increasing the polling rate.
1810 IN EFI_IP6_PROTOCOL
*This
1813 IP6_PROTOCOL
*IpInstance
;
1815 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
1818 return EFI_INVALID_PARAMETER
;
1821 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1822 IpSb
= IpInstance
->Service
;
1824 if (IpSb
->LinkLocalDadFail
) {
1825 return EFI_DEVICE_ERROR
;
1828 if (IpInstance
->State
== IP6_STATE_UNCONFIGED
) {
1829 return EFI_NOT_STARTED
;
1832 Mnp
= IpInstance
->Service
->Mnp
;
1835 // Don't lock the Poll function to enable the deliver of
1836 // the packet polled up.
1838 return Mnp
->Poll (Mnp
);