2 Implementation of EFI_IP6_PROTOCOL protocol interfaces.
4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_IPSEC2_PROTOCOL
*mIpSec
= NULL
;
20 EFI_IP6_PROTOCOL mEfiIp6ProtocolTemplete
= {
33 Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
35 The GetModeData() function returns the current operational mode data for this driver instance.
36 The data fields in EFI_IP6_MODE_DATA are read only. This function is used optionally to
37 retrieve the operational mode data of underlying networks or drivers.
39 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
40 @param[out] Ip6ModeData Pointer to the EFI IPv6 Protocol mode data structure.
41 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
42 @param[out] SnpModeData Pointer to the simple network mode data structure.
44 @retval EFI_SUCCESS The operation completed successfully.
45 @retval EFI_INVALID_PARAMETER This is NULL.
46 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
52 IN EFI_IP6_PROTOCOL
*This
,
53 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
54 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
55 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
58 IP6_PROTOCOL
*IpInstance
;
61 EFI_IP6_CONFIG_DATA
*Config
;
66 return EFI_INVALID_PARAMETER
;
69 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
70 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
71 IpSb
= IpInstance
->Service
;
72 IpIf
= IpInstance
->Interface
;
74 if (IpSb
->LinkLocalDadFail
) {
75 return EFI_INVALID_PARAMETER
;
78 if (Ip6ModeData
!= NULL
) {
80 // IsStarted is "whether the EfiIp6Configure has been called".
81 // IsConfigured is "whether the station address has been configured"
83 Ip6ModeData
->IsStarted
= (BOOLEAN
) (IpInstance
->State
== IP6_STATE_CONFIGED
);
84 Ip6ModeData
->MaxPacketSize
= IpSb
->MaxPacketSize
;
85 CopyMem (&Ip6ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (EFI_IP6_CONFIG_DATA
));
86 Ip6ModeData
->IsConfigured
= FALSE
;
88 Ip6ModeData
->AddressCount
= 0;
89 Ip6ModeData
->AddressList
= NULL
;
91 Ip6ModeData
->GroupCount
= IpInstance
->GroupCount
;
92 Ip6ModeData
->GroupTable
= NULL
;
94 Ip6ModeData
->RouteCount
= 0;
95 Ip6ModeData
->RouteTable
= NULL
;
97 Ip6ModeData
->NeighborCount
= 0;
98 Ip6ModeData
->NeighborCache
= NULL
;
100 Ip6ModeData
->PrefixCount
= 0;
101 Ip6ModeData
->PrefixTable
= NULL
;
103 Ip6ModeData
->IcmpTypeCount
= 23;
104 Ip6ModeData
->IcmpTypeList
= AllocateCopyPool (
105 Ip6ModeData
->IcmpTypeCount
* sizeof (EFI_IP6_ICMP_TYPE
),
108 if (Ip6ModeData
->IcmpTypeList
== NULL
) {
109 Status
= EFI_OUT_OF_RESOURCES
;
114 // Return the currently configured IPv6 addresses and corresponding prefix lengths.
116 Status
= Ip6BuildEfiAddressList (
118 &Ip6ModeData
->AddressCount
,
119 &Ip6ModeData
->AddressList
121 if (EFI_ERROR (Status
)) {
126 // Return the current station address for this IP child.
127 // If UseAnyStationAddress is set to TRUE, IP6 driver will
128 // select a source address from its address list. Otherwise use the
129 // StationAddress in config data.
131 if (Ip6ModeData
->IsStarted
) {
132 Config
= &Ip6ModeData
->ConfigData
;
134 if (IpIf
->Configured
|| NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
135 Ip6ModeData
->IsConfigured
= TRUE
;
137 Ip6ModeData
->IsConfigured
= FALSE
;
141 // Build a EFI route table for user from the internal route table.
143 Status
= Ip6BuildEfiRouteTable (
145 &Ip6ModeData
->RouteCount
,
146 &Ip6ModeData
->RouteTable
149 if (EFI_ERROR (Status
)) {
154 if (Ip6ModeData
->IsConfigured
) {
156 // Return the joined multicast group addresses.
158 if (IpInstance
->GroupCount
!= 0) {
159 Ip6ModeData
->GroupTable
= AllocateCopyPool (
160 IpInstance
->GroupCount
* sizeof (EFI_IPv6_ADDRESS
),
161 IpInstance
->GroupList
163 if (Ip6ModeData
->GroupTable
== NULL
) {
164 Status
= EFI_OUT_OF_RESOURCES
;
169 // Return the neighbor cache entries
171 Status
= Ip6BuildEfiNeighborCache (
173 &Ip6ModeData
->NeighborCount
,
174 &Ip6ModeData
->NeighborCache
176 if (EFI_ERROR (Status
)) {
181 // Return the prefix table entries
183 Status
= Ip6BuildPrefixTable (
185 &Ip6ModeData
->PrefixCount
,
186 &Ip6ModeData
->PrefixTable
188 if (EFI_ERROR (Status
)) {
196 // Get fresh mode data from MNP, since underlying media status may change
198 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, MnpConfigData
, SnpModeData
);
203 if (Ip6ModeData
!= NULL
) {
204 if (Ip6ModeData
->AddressList
!= NULL
) {
205 FreePool (Ip6ModeData
->AddressList
);
208 if (Ip6ModeData
->GroupTable
!= NULL
) {
209 FreePool (Ip6ModeData
->GroupTable
);
212 if (Ip6ModeData
->RouteTable
!= NULL
) {
213 FreePool (Ip6ModeData
->RouteTable
);
216 if (Ip6ModeData
->NeighborCache
!= NULL
) {
217 FreePool (Ip6ModeData
->NeighborCache
);
220 if (Ip6ModeData
->PrefixTable
!= NULL
) {
221 FreePool (Ip6ModeData
->PrefixTable
);
224 if (Ip6ModeData
->IcmpTypeList
!= NULL
) {
225 FreePool (Ip6ModeData
->IcmpTypeList
);
230 gBS
->RestoreTPL (OldTpl
);
235 Validate that Ipv6 address is OK to be used as station address or next hop address/ neighbor.
237 @param[in] IpSb The IP6 service instance.
238 @param[in] Ip The IPv6 address to validate.
239 @param[in] Flag If TRUE, validate if the address is OK to be used
240 as station address. If FALSE, validate if the
241 address is OK to be used as the next hop address/
244 @retval TRUE The Ip address is valid and could be used.
245 @retval FALSE Invalid Ip address.
250 IN IP6_SERVICE
*IpSb
,
251 IN EFI_IPv6_ADDRESS
*Ip
,
255 if (!NetIp6IsUnspecifiedAddr (Ip
)) {
256 if (!NetIp6IsValidUnicast(Ip
)) {
259 if (Ip6IsOneOfSetAddress (IpSb
, Ip
, NULL
, NULL
)) {
266 return (BOOLEAN
) !Flag
;
270 Validate whether the value of protocol is illegal or not. Protocol is the 'Next Header' field
271 in the last IPv6 extension header, or basic IPv6 header is there's no extension header.
273 @param[in] Protocol Default value of 'Next Header'
275 @retval TRUE The protocol is illegal.
276 @retval FALSE The protocol is legal.
280 Ip6IsIllegalProtocol (
284 if (Protocol
== IP6_HOP_BY_HOP
|| Protocol
== EFI_IP_PROTO_ICMP
|| Protocol
== IP4_PROTO_IGMP
) {
288 if (Protocol
== 41 || Protocol
== 43 || Protocol
== 44 || Protocol
== 59 || Protocol
== 60 || Protocol
== 124) {
296 Intiialize the IP6_PROTOCOL structure to the unconfigured states.
298 @param[in] IpSb The IP6 service instance.
299 @param[in, out] IpInstance The IP6 child instance.
304 IN IP6_SERVICE
*IpSb
,
305 IN OUT IP6_PROTOCOL
*IpInstance
308 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
310 ZeroMem (IpInstance
, sizeof (IP6_PROTOCOL
));
312 IpInstance
->Signature
= IP6_PROTOCOL_SIGNATURE
;
313 IpInstance
->State
= IP6_STATE_UNCONFIGED
;
314 IpInstance
->Service
= IpSb
;
315 IpInstance
->GroupList
= NULL
;
316 CopyMem (&IpInstance
->Ip6Proto
, &mEfiIp6ProtocolTemplete
, sizeof (EFI_IP6_PROTOCOL
));
318 NetMapInit (&IpInstance
->RxTokens
);
319 NetMapInit (&IpInstance
->TxTokens
);
320 InitializeListHead (&IpInstance
->Received
);
321 InitializeListHead (&IpInstance
->Delivered
);
323 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
327 Configure the IP6 child. If the child is already configured,
328 change the configuration parameter. Otherwise, configure it
329 for the first time. The caller should validate the configuration
330 before deliver them to it. It also don't do configure NULL.
332 @param[in, out] IpInstance The IP6 child to configure.
333 @param[in] Config The configure data.
335 @retval EFI_SUCCESS The IP6 child is successfully configured.
336 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
337 configure underlying MNP, or other errors.
338 @retval EFI_NO_MAPPING The IP6 child is configured to use the default
339 address, but the default address hasn't been
340 configured. The IP6 child doesn't need to be
341 reconfigured when the default address is configured.
342 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
343 @retval other Other error occurs.
348 IN OUT IP6_PROTOCOL
*IpInstance
,
349 IN EFI_IP6_CONFIG_DATA
*Config
355 EFI_IP6_CONFIG_DATA
*Current
;
356 IP6_ADDRESS_INFO
*AddressInfo
;
359 EFI_IPv6_ADDRESS Source
;
362 IpSb
= IpInstance
->Service
;
363 Current
= &IpInstance
->ConfigData
;
366 // User is changing packet filters. It must be stopped
367 // before the station address can be changed.
369 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
371 // Cancel all the pending transmit/receive from upper layer
373 Status
= Ip6Cancel (IpInstance
, NULL
);
375 if (EFI_ERROR (Status
)) {
376 return EFI_DEVICE_ERROR
;
379 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
384 // Set up the interface.
386 StationZero
= NetIp6IsUnspecifiedAddr (&Config
->StationAddress
);
387 DestZero
= NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
);
389 if (StationZero
&& DestZero
) {
391 // StationAddress is still zero.
394 NET_GET_REF (IpSb
->DefaultInterface
);
395 IpInstance
->Interface
= IpSb
->DefaultInterface
;
396 InsertTailList (&IpSb
->DefaultInterface
->IpInstances
, &IpInstance
->AddrLink
);
398 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
399 IpInstance
->State
= IP6_STATE_CONFIGED
;
404 if (StationZero
&& !DestZero
) {
405 Status
= Ip6SelectSourceAddress (IpSb
, &Config
->DestinationAddress
, &Source
);
406 if (EFI_ERROR (Status
)) {
410 IP6_COPY_ADDRESS (&Source
, &Config
->StationAddress
);
413 AddrOk
= Ip6IsOneOfSetAddress (IpSb
, &Source
, &IpIf
, &AddressInfo
);
415 if (AddressInfo
!= NULL
) {
416 IpInstance
->PrefixLength
= AddressInfo
->PrefixLength
;
418 IpInstance
->PrefixLength
= IP6_LINK_LOCAL_PREFIX_LENGTH
;
422 // The specified source address is not one of the addresses IPv6 maintains.
424 return EFI_INVALID_PARAMETER
;
429 IpInstance
->Interface
= IpIf
;
430 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
432 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
433 IP6_COPY_ADDRESS (&Current
->StationAddress
, &Source
);
434 IpInstance
->State
= IP6_STATE_CONFIGED
;
440 Clean up the IP6 child, and release all the resources used by it.
442 @param[in, out] IpInstance The IP6 child to clean up.
444 @retval EFI_SUCCESS The IP6 child is cleaned up.
445 @retval EFI_DEVICE_ERROR Some resources failed to be released.
450 IN OUT IP6_PROTOCOL
*IpInstance
453 if (EFI_ERROR (Ip6Cancel (IpInstance
, NULL
))) {
454 return EFI_DEVICE_ERROR
;
457 if (EFI_ERROR (Ip6Groups (IpInstance
, FALSE
, NULL
))) {
458 return EFI_DEVICE_ERROR
;
462 // Some packets haven't been recycled. It is because either the
463 // user forgets to recycle the packets, or because the callback
464 // hasn't been called. Just leave it alone.
466 if (!IsListEmpty (&IpInstance
->Delivered
)) {
470 if (IpInstance
->Interface
!= NULL
) {
471 RemoveEntryList (&IpInstance
->AddrLink
);
472 Ip6CleanInterface (IpInstance
->Interface
, IpInstance
);
473 IpInstance
->Interface
= NULL
;
476 if (IpInstance
->GroupList
!= NULL
) {
477 FreePool (IpInstance
->GroupList
);
478 IpInstance
->GroupList
= NULL
;
479 IpInstance
->GroupCount
= 0;
482 NetMapClean (&IpInstance
->TxTokens
);
484 NetMapClean (&IpInstance
->RxTokens
);
490 Configure the MNP parameter used by IP. The IP driver uses one MNP
491 child to transmit/receive frames. By default, it configures MNP
492 to receive unicast/multicast/broadcast. Also, it will enable/disable
493 the promiscuous receive according to whether there is IP child
494 enable that or not. If Force is FALSE, it will iterate through
495 all the IP children to check whether the promiscuous receive
496 setting has been changed. If it hasn't been changed, it won't
497 reconfigure the MNP. If Force is TRUE, the MNP is configured
498 whether that is changed or not.
500 @param[in] IpSb The IP6 service instance that is to be changed.
501 @param[in] Force Force the configuration or not.
503 @retval EFI_SUCCESS The MNP successfully configured/reconfigured.
504 @retval Others Configuration failed.
508 Ip6ServiceConfigMnp (
509 IN IP6_SERVICE
*IpSb
,
514 LIST_ENTRY
*ProtoEntry
;
516 IP6_PROTOCOL
*IpInstance
;
518 BOOLEAN PromiscReceive
;
522 PromiscReceive
= FALSE
;
526 // Iterate through the IP children to check whether promiscuous
527 // receive setting has been changed. Update the interface's receive
530 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
532 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
533 IpIf
->PromiscRecv
= FALSE
;
535 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
536 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP6_PROTOCOL
, AddrLink
);
538 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
539 IpIf
->PromiscRecv
= TRUE
;
540 PromiscReceive
= TRUE
;
546 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
548 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
553 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
556 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
559 // recover the original configuration if failed to set the configure.
561 if (EFI_ERROR (Status
) && Reconfig
) {
562 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
569 Assigns an IPv6 address and subnet mask to this EFI IPv6 Protocol driver instance.
571 The Configure() function is used to set, change, or reset the operational parameters and filter
572 settings for this EFI IPv6 Protocol instance. Until these parameters have been set, no network traffic
573 can be sent or received by this instance. Once the parameters have been reset (by calling this
574 function with Ip6ConfigData set to NULL), no more traffic can be sent or received until these
575 parameters have been set again. Each EFI IPv6 Protocol instance can be started and stopped
576 independently of each other by enabling or disabling their receive filter settings with the
577 Configure() function.
579 If Ip6ConfigData.StationAddress is a valid non-zero IPv6 unicast address, it is required
580 to be one of the currently configured IPv6 addresses listed in the EFI IPv6 drivers, or else
581 EFI_INVALID_PARAMETER will be returned. If Ip6ConfigData.StationAddress is
582 unspecified, the IPv6 driver will bind a source address according to the source address selection
583 algorithm. Clients could frequently call GetModeData() to check get currently configured IPv6
584 address list in the EFI IPv6 driver. If both Ip6ConfigData.StationAddress and
585 Ip6ConfigData.Destination are unspecified, when transmitting the packet afterwards, the
586 source address filled in each outgoing IPv6 packet is decided based on the destination of this packet.
588 If operational parameters are reset or changed, any pending transmit and receive requests will be
589 cancelled. Their completion token status will be set to EFI_ABORTED and their events will be
592 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
593 @param[in] Ip6ConfigData Pointer to the EFI IPv6 Protocol configuration data structure.
594 If NULL, reset the configuration data.
596 @retval EFI_SUCCESS The driver instance was successfully opened.
597 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
599 - Ip6ConfigData.StationAddress is neither zero nor
600 a unicast IPv6 address.
601 - Ip6ConfigData.StationAddress is neither zero nor
602 one of the configured IP addresses in the EFI IPv6 driver.
603 - Ip6ConfigData.DefaultProtocol is illegal.
604 @retval EFI_OUT_OF_RESOURCES The EFI IPv6 Protocol driver instance data could not be allocated.
605 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing a source address for
606 this instance, but no source address was available for use.
607 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the IPv6
608 address or prefix length can be changed.
609 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv6
610 Protocol driver instance was not opened.
611 @retval EFI_UNSUPPORTED Default protocol specified through
612 Ip6ConfigData.DefaulProtocol isn't supported.
618 IN EFI_IP6_PROTOCOL
*This
,
619 IN EFI_IP6_CONFIG_DATA
*Ip6ConfigData OPTIONAL
622 IP6_PROTOCOL
*IpInstance
;
623 EFI_IP6_CONFIG_DATA
*Current
;
629 // First, validate the parameters
632 return EFI_INVALID_PARAMETER
;
635 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
636 IpSb
= IpInstance
->Service
;
638 if (IpSb
->LinkLocalDadFail
&& Ip6ConfigData
!= NULL
) {
639 return EFI_DEVICE_ERROR
;
642 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
644 Status
= EFI_INVALID_PARAMETER
;
647 // Validate the configuration first.
649 if (Ip6ConfigData
!= NULL
) {
651 // Check whether the station address is valid.
653 if (!Ip6IsValidAddress (IpSb
, &Ip6ConfigData
->StationAddress
, TRUE
)) {
657 // Check whether the default protocol is valid.
659 if (Ip6IsIllegalProtocol (Ip6ConfigData
->DefaultProtocol
)) {
664 // User can only update packet filters when already configured.
665 // If it wants to change the station address, it must configure(NULL)
666 // the instance firstly.
668 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
669 Current
= &IpInstance
->ConfigData
;
671 if (!EFI_IP6_EQUAL (&Current
->StationAddress
, &Ip6ConfigData
->StationAddress
)) {
672 Status
= EFI_ALREADY_STARTED
;
676 if (NetIp6IsUnspecifiedAddr (&Current
->StationAddress
) && IP6_NO_MAPPING (IpInstance
)) {
677 Status
= EFI_NO_MAPPING
;
684 // Configure the instance or clean it up.
686 if (Ip6ConfigData
!= NULL
) {
687 Status
= Ip6ConfigProtocol (IpInstance
, Ip6ConfigData
);
689 Status
= Ip6CleanProtocol (IpInstance
);
692 // Don't change the state if it is DESTROY, consider the following
693 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
694 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
695 // the unload fails miserably.
697 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
698 IpInstance
->State
= IP6_STATE_UNCONFIGED
;
703 // Update the MNP's configure data. Ip6ServiceConfigMnp will check
704 // whether it is necessary to reconfigure the MNP.
706 Ip6ServiceConfigMnp (IpInstance
->Service
, FALSE
);
709 gBS
->RestoreTPL (OldTpl
);
714 Joins and leaves multicast groups.
716 The Groups() function is used to join and leave multicast group sessions. Joining a group will
717 enable reception of matching multicast packets. Leaving a group will disable reception of matching
718 multicast packets. Source-Specific Multicast isn't required to be supported.
720 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
722 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
723 @param[in] JoinFlag Set to TRUE to join the multicast group session, and FALSE to leave.
724 @param[in] GroupAddress Pointer to the IPv6 multicast address.
725 This is an optional parameter that may be NULL.
727 @retval EFI_SUCCESS The operation completed successfully.
728 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
730 - JoinFlag is TRUE and GroupAddress is NULL.
731 - GroupAddress is not NULL and *GroupAddress is
732 not a multicast IPv6 address.
733 - GroupAddress is not NULL and *GroupAddress is in the
734 range of SSM destination address.
735 @retval EFI_NOT_STARTED This instance has not been started.
736 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
737 @retval EFI_UNSUPPORTED This EFI IPv6 Protocol implementation does not support multicast groups.
738 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
740 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
741 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
747 IN EFI_IP6_PROTOCOL
*This
,
749 IN EFI_IPv6_ADDRESS
*GroupAddress OPTIONAL
754 IP6_PROTOCOL
*IpInstance
;
757 if ((This
== NULL
) || (JoinFlag
&& GroupAddress
== NULL
)) {
758 return EFI_INVALID_PARAMETER
;
761 if (GroupAddress
!= NULL
&& !IP6_IS_MULTICAST (GroupAddress
)) {
762 return EFI_INVALID_PARAMETER
;
765 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
766 IpSb
= IpInstance
->Service
;
768 if (IpSb
->LinkLocalDadFail
) {
769 return EFI_DEVICE_ERROR
;
772 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
774 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
775 Status
= EFI_NOT_STARTED
;
779 Status
= Ip6Groups (IpInstance
, JoinFlag
, GroupAddress
);
782 gBS
->RestoreTPL (OldTpl
);
787 Adds and deletes routing table entries.
789 The Routes() function adds a route to, or deletes a route from, the routing table.
791 Routes are determined by comparing the leftmost PrefixLength bits of Destination with
792 the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the
793 configured station address.
795 The default route is added with Destination and PrefixLegth both set to all zeros. The
796 default route matches all destination IPv6 addresses that do not match any other routes.
798 All EFI IPv6 Protocol instances share a routing table.
800 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
801 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
802 FALSE to add this route to the routing table. Destination,
803 PrefixLength and Gateway are used as the key to each
805 @param[in] Destination The address prefix of the subnet that needs to be routed.
806 This is an optional parameter that may be NULL.
807 @param[in] PrefixLength The prefix length of Destination. Ignored if Destination
809 @param[in] GatewayAddress The unicast gateway IPv6 address for this route.
810 This is an optional parameter that may be NULL.
812 @retval EFI_SUCCESS The operation completed successfully.
813 @retval EFI_NOT_STARTED The driver instance has not been started.
814 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
816 - When DeleteRoute is TRUE, both Destination and
817 GatewayAddress are NULL.
818 - When DeleteRoute is FALSE, either Destination or
819 GatewayAddress is NULL.
820 - *GatewayAddress is not a valid unicast IPv6 address.
821 - *GatewayAddress is one of the local configured IPv6
823 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
824 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
825 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
826 DeleteRoute is FALSE).
832 IN EFI_IP6_PROTOCOL
*This
,
833 IN BOOLEAN DeleteRoute
,
834 IN EFI_IPv6_ADDRESS
*Destination OPTIONAL
,
835 IN UINT8 PrefixLength
,
836 IN EFI_IPv6_ADDRESS
*GatewayAddress OPTIONAL
839 IP6_PROTOCOL
*IpInstance
;
844 if ((This
== NULL
) || (PrefixLength
>= IP6_PREFIX_NUM
)) {
845 return EFI_INVALID_PARAMETER
;
848 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
849 IpSb
= IpInstance
->Service
;
851 if (IpSb
->LinkLocalDadFail
) {
852 return EFI_DEVICE_ERROR
;
855 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
856 return EFI_NOT_STARTED
;
859 if (DeleteRoute
&& (Destination
== NULL
) && (GatewayAddress
== NULL
)) {
860 return EFI_INVALID_PARAMETER
;
863 if (!DeleteRoute
&& (Destination
== NULL
|| GatewayAddress
== NULL
)) {
864 return EFI_INVALID_PARAMETER
;
867 if (GatewayAddress
!= NULL
) {
868 if (!Ip6IsValidAddress (IpSb
, GatewayAddress
, FALSE
)) {
869 return EFI_INVALID_PARAMETER
;
872 if (!NetIp6IsUnspecifiedAddr (GatewayAddress
) &&
873 !NetIp6IsNetEqual (GatewayAddress
, &IpInstance
->ConfigData
.StationAddress
, PrefixLength
)
875 return EFI_INVALID_PARAMETER
;
879 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
882 // Update the route table
885 Status
= Ip6DelRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
887 Status
= Ip6AddRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
890 gBS
->RestoreTPL (OldTpl
);
895 Add or delete Neighbor cache entries.
897 The Neighbors() function is used to add, update, or delete an entry from neighbor cache.
898 IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as
899 network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network
900 traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not
901 timeout) or dynamic (will timeout).
903 The implementation should follow the neighbor cache timeout mechanism which is defined in
904 RFC4861. The default neighbor cache timeout value should be tuned for the expected network
907 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
908 @param[in] DeleteFlag Set to TRUE to delete the specified cache entry, set to FALSE to
909 add (or update, if it already exists and Override is TRUE) the
910 specified cache entry. TargetIp6Address is used as the key
911 to find the requested cache entry.
912 @param[in] TargetIp6Address Pointer to the Target IPv6 address.
913 @param[in] TargetLinkAddress Pointer to the link-layer address of the target. Ignored if NULL.
914 @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
915 cache, it will be deleted after Timeout. A value of zero means that
916 the entry is permanent. A non-zero value means that the entry is
918 @param[in] Override If TRUE, the cached link-layer address of the matching entry will
919 be overridden and updated; if FALSE, EFI_ACCESS_DENIED
920 will be returned if a corresponding cache entry already existed.
922 @retval EFI_SUCCESS The data has been queued for transmission.
923 @retval EFI_NOT_STARTED This instance has not been started.
924 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
926 - TargetIpAddress is NULL.
927 - *TargetLinkAddress is invalid when not NULL.
928 - *TargetIpAddress is not a valid unicast IPv6 address.
929 - *TargetIpAddress is one of the local configured IPv6
931 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache.
932 @retval EFI_NOT_FOUND This entry is not in the neighbor cache (when DeleteFlag is
933 TRUE or when DeleteFlag is FALSE while
934 TargetLinkAddress is NULL.).
935 @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
936 and that entry is tagged as un-overridden (when Override
943 IN EFI_IP6_PROTOCOL
*This
,
944 IN BOOLEAN DeleteFlag
,
945 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
946 IN EFI_MAC_ADDRESS
*TargetLinkAddress OPTIONAL
,
953 IP6_PROTOCOL
*IpInstance
;
956 if (This
== NULL
|| TargetIp6Address
== NULL
) {
957 return EFI_INVALID_PARAMETER
;
960 if (NetIp6IsUnspecifiedAddr (TargetIp6Address
)) {
961 return EFI_INVALID_PARAMETER
;
964 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
965 IpSb
= IpInstance
->Service
;
967 if (IpSb
->LinkLocalDadFail
) {
968 return EFI_DEVICE_ERROR
;
971 if (!Ip6IsValidAddress (IpSb
, TargetIp6Address
, FALSE
)) {
972 return EFI_INVALID_PARAMETER
;
975 if (TargetLinkAddress
!= NULL
) {
976 if (!Ip6IsValidLinkAddress (IpSb
, TargetLinkAddress
)) {
977 return EFI_INVALID_PARAMETER
;
981 if (Ip6IsOneOfSetAddress (IpSb
, TargetIp6Address
, NULL
, NULL
)) {
982 return EFI_INVALID_PARAMETER
;
985 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
986 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
987 Status
= EFI_NOT_STARTED
;
992 Status
= Ip6DelNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
994 Status
= Ip6AddNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
998 gBS
->RestoreTPL (OldTpl
);
1003 Check whether the user's token or event has already
1004 been enqueue on IP6's list.
1006 @param[in] Map The container of either user's transmit or receive
1008 @param[in] Item Current item to check against.
1009 @param[in] Context The Token to check againist.
1011 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1012 @retval EFI_SUCCESS The current item isn't the same token/event as the
1020 IN NET_MAP_ITEM
*Item
,
1024 EFI_IP6_COMPLETION_TOKEN
*Token
;
1025 EFI_IP6_COMPLETION_TOKEN
*TokenInItem
;
1027 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1028 TokenInItem
= (EFI_IP6_COMPLETION_TOKEN
*) Item
->Key
;
1030 if (Token
== TokenInItem
|| Token
->Event
== TokenInItem
->Event
) {
1031 return EFI_ACCESS_DENIED
;
1038 Validate the user's token against the current station address.
1040 @param[in] Token User's token to validate.
1042 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1043 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1044 @retval EFI_SUCCESS The token is OK.
1049 IN EFI_IP6_COMPLETION_TOKEN
*Token
1052 EFI_IP6_TRANSMIT_DATA
*TxData
;
1056 if (Token
== NULL
|| Token
->Event
== NULL
) {
1057 return EFI_INVALID_PARAMETER
;
1060 TxData
= Token
->Packet
.TxData
;
1062 if (TxData
== NULL
|| (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
== NULL
)) {
1063 return EFI_INVALID_PARAMETER
;
1066 if (TxData
->FragmentCount
== 0 || TxData
->DataLength
== 0) {
1067 return EFI_INVALID_PARAMETER
;
1070 for (DataLength
= 0, Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1071 if (TxData
->FragmentTable
[Index
].FragmentLength
== 0 || TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) {
1072 return EFI_INVALID_PARAMETER
;
1075 DataLength
+= TxData
->FragmentTable
[Index
].FragmentLength
;
1078 if (TxData
->DataLength
!= DataLength
) {
1079 return EFI_INVALID_PARAMETER
;
1083 // TODO: Token.Packet.TxData.DataLength is too short to transmit.
1084 // return EFI_BUFFER_TOO_SMALL;
1088 // If Token.Packet.TxData.DataLength is beyond the maximum that which can be
1089 // described through the Fragment Offset field in Fragment header when performing
1092 if (TxData
->DataLength
> 64 * 1024) {
1093 return EFI_BAD_BUFFER_SIZE
;
1100 The callback function for the net buffer which wraps the user's
1101 transmit token. Although this function seems simple, there
1102 are some subtle aspects.
1103 When user requests the IP to transmit a packet by passing it a
1104 token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data
1105 is wrapped in an net buffer. The net buffer's Free function is
1106 set to Ip6FreeTxToken. The Token and token wrap are added to the
1107 IP child's TxToken map. Then the buffer is passed to Ip6Output for
1108 transmission. If an error happened before that, the buffer
1109 is freed, which in turn frees the token wrap. The wrap may
1110 have been added to the TxToken map or not, and the user's event
1111 shouldn't be fired because we are still in the EfiIp6Transmit. If
1112 the buffer has been sent by Ip6Output, it should be removed from
1113 the TxToken map and user's event signaled. The token wrap and buffer
1114 are bound together. Check the comments in Ip6Output for information
1115 about IP fragmentation.
1117 @param[in] Context The token's wrap.
1126 IP6_TXTOKEN_WRAP
*Wrap
;
1129 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1132 // Signal IpSecRecycleEvent to inform IPsec free the memory
1134 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1135 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1139 // Find the token in the instance's map. EfiIp6Transmit put the
1140 // token to the map. If that failed, NetMapFindKey will return NULL.
1142 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1145 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1149 gBS
->SignalEvent (Wrap
->Token
->Event
);
1152 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1162 The callback function to Ip6Output to update the transmit status.
1164 @param[in] Packet The user's transmit packet.
1165 @param[in] IoStatus The result of the transmission.
1166 @param[in] Flag Not used during transmission.
1167 @param[in] Context The token's wrap.
1173 IN EFI_STATUS IoStatus
,
1178 IP6_TXTOKEN_WRAP
*Wrap
;
1181 // This is the transmission request from upper layer,
1182 // not the IP6 driver itself.
1184 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1185 Wrap
->Token
->Status
= IoStatus
;
1187 NetbufFree (Wrap
->Packet
);
1191 Places outgoing data packets into the transmit queue.
1193 The Transmit() function places a sending request in the transmit queue of this
1194 EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some
1195 errors occur, the event in the token will be signaled, and the status is updated.
1197 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1198 @param[in] Token Pointer to the transmit token.
1200 @retval EFI_SUCCESS The data has been queued for transmission.
1201 @retval EFI_NOT_STARTED This instance has not been started.
1202 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing
1203 a source address for this transmission,
1204 but no source address was available for use.
1205 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1208 - Token.Event is NULL.
1209 - Token.Packet.TxData is NULL.
1210 - Token.Packet.ExtHdrsLength is not zero and
1211 Token.Packet.ExtHdrs is NULL.
1212 - Token.Packet.FragmentCount is zero.
1213 - One or more of the Token.Packet.TxData.
1214 FragmentTable[].FragmentLength fields is zero.
1215 - One or more of the Token.Packet.TxData.
1216 FragmentTable[].FragmentBuffer fields is NULL.
1217 - Token.Packet.TxData.DataLength is zero or not
1218 equal to the sum of fragment lengths.
1219 - Token.Packet.TxData.DestinationAddress is non
1220 zero when DestinationAddress is configured as
1221 non-zero when doing Configure() for this
1222 EFI IPv6 protocol instance.
1223 - Token.Packet.TxData.DestinationAddress is
1224 unspecified when DestinationAddress is unspecified
1225 when doing Configure() for this EFI IPv6 protocol
1227 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.
1228 Event was already in the transmit queue.
1229 @retval EFI_NOT_READY The completion token could not be queued because
1230 the transmit queue is full.
1231 @retval EFI_NOT_FOUND Not route is found to destination address.
1232 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1233 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1235 @retval EFI_BAD_BUFFER_SIZE If Token.Packet.TxData.DataLength is beyond the
1236 maximum that which can be described through the
1237 Fragment Offset field in Fragment header when
1238 performing fragmentation.
1239 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1245 IN EFI_IP6_PROTOCOL
*This
,
1246 IN EFI_IP6_COMPLETION_TOKEN
*Token
1250 IP6_PROTOCOL
*IpInstance
;
1251 EFI_IP6_CONFIG_DATA
*Config
;
1254 EFI_IP6_HEADER Head
;
1255 EFI_IP6_TRANSMIT_DATA
*TxData
;
1256 EFI_IP6_OVERRIDE_DATA
*Override
;
1257 IP6_TXTOKEN_WRAP
*Wrap
;
1261 // Check input parameters.
1264 return EFI_INVALID_PARAMETER
;
1269 Status
= Ip6TxTokenValid (Token
);
1270 if (EFI_ERROR (Status
)) {
1274 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1275 IpSb
= IpInstance
->Service
;
1277 if (IpSb
->LinkLocalDadFail
) {
1278 return EFI_DEVICE_ERROR
;
1281 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1283 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1284 Status
= EFI_NOT_STARTED
;
1288 Config
= &IpInstance
->ConfigData
;
1291 // Check whether the token or signal already existed.
1293 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip6TokenExist
, Token
))) {
1294 Status
= EFI_ACCESS_DENIED
;
1299 // Build the IP header, fill in the information from ConfigData or OverrideData
1301 ZeroMem (&Head
, sizeof(EFI_IP6_HEADER
));
1302 TxData
= Token
->Packet
.TxData
;
1303 IP6_COPY_ADDRESS (&Head
.SourceAddress
, &Config
->StationAddress
);
1304 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &Config
->DestinationAddress
);
1306 Status
= EFI_INVALID_PARAMETER
;
1308 if (NetIp6IsUnspecifiedAddr (&TxData
->DestinationAddress
)) {
1309 if (NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1313 ASSERT (!NetIp6IsUnspecifiedAddr (&Config
->StationAddress
));
1317 // StationAddress is unspecified only when ConfigData.Dest is unspecified.
1318 // Use TxData.Dest to override the DestinationAddress.
1320 if (!NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1324 if (NetIp6IsUnspecifiedAddr (&Config
->StationAddress
)) {
1325 Status
= Ip6SelectSourceAddress (
1327 &TxData
->DestinationAddress
,
1330 if (EFI_ERROR (Status
)) {
1335 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &TxData
->DestinationAddress
);
1339 // Fill in Head infos.
1341 Head
.NextHeader
= Config
->DefaultProtocol
;
1342 if (TxData
->ExtHdrsLength
!= 0) {
1343 Head
.NextHeader
= TxData
->NextHeader
;
1346 if (TxData
->OverrideData
!= NULL
) {
1347 Override
= TxData
->OverrideData
;
1348 Head
.NextHeader
= Override
->Protocol
;
1349 Head
.HopLimit
= Override
->HopLimit
;
1350 Head
.FlowLabelL
= HTONS ((UINT16
) Override
->FlowLabel
);
1351 Head
.FlowLabelH
= (UINT8
) ((Override
->FlowLabel
>> 16) & 0x0F);
1353 Head
.HopLimit
= Config
->HopLimit
;
1354 Head
.FlowLabelL
= HTONS ((UINT16
) Config
->FlowLabel
);
1355 Head
.FlowLabelH
= (UINT8
) ((Config
->FlowLabel
>> 16) & 0x0F);
1358 Head
.PayloadLength
= HTONS ((UINT16
) (TxData
->ExtHdrsLength
+ TxData
->DataLength
));
1361 // OK, it survives all the validation check. Wrap the token in
1362 // a IP6_TXTOKEN_WRAP and the data in a netbuf
1364 Status
= EFI_OUT_OF_RESOURCES
;
1365 Wrap
= AllocateZeroPool (sizeof (IP6_TXTOKEN_WRAP
));
1370 Wrap
->IpInstance
= IpInstance
;
1371 Wrap
->Token
= Token
;
1373 Wrap
->Life
= IP6_US_TO_SEC (Config
->TransmitTimeout
);
1374 Wrap
->Packet
= NetbufFromExt (
1375 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1376 TxData
->FragmentCount
,
1383 if (Wrap
->Packet
== NULL
) {
1388 Token
->Status
= EFI_NOT_READY
;
1390 Status
= NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
);
1391 if (EFI_ERROR (Status
)) {
1393 // NetbufFree will call Ip6FreeTxToken, which in turn will
1394 // free the IP6_TXTOKEN_WRAP. Now, the token wrap hasn't been
1397 NetbufFree (Wrap
->Packet
);
1402 // Allocate a new buffer to store IPv6 extension headers to avoid updating
1403 // the original data in EFI_IP6_COMPLETION_TOKEN.
1405 if (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
!= NULL
) {
1406 ExtHdrs
= (UINT8
*) AllocateCopyPool (TxData
->ExtHdrsLength
, TxData
->ExtHdrs
);
1407 if (ExtHdrs
== NULL
) {
1408 Status
= EFI_OUT_OF_RESOURCES
;
1414 // Mark the packet sent before output it. Mark it not sent again if the
1415 // returned status is not EFI_SUCCESS;
1419 Status
= Ip6Output (
1426 TxData
->ExtHdrsLength
,
1430 if (EFI_ERROR (Status
)) {
1432 NetbufFree (Wrap
->Packet
);
1436 gBS
->RestoreTPL (OldTpl
);
1438 if (ExtHdrs
!= NULL
) {
1446 Places a receiving request into the receiving queue.
1448 The Receive() function places a completion token into the receive packet queue.
1449 This function is always asynchronous.
1451 The Token.Event field in the completion token must be filled in by the caller
1452 and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol
1453 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1456 Current Udp implementation creates an IP child for each Udp child.
1457 It initates a asynchronous receive immediately no matter whether
1458 there is no mapping or not. Therefore, disable the returning EFI_NO_MAPPING for now.
1459 To enable it, the following check must be performed:
1461 if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
1462 Status = EFI_NO_MAPPING;
1466 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1467 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1469 @retval EFI_SUCCESS The receive completion token was cached.
1470 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1471 @retval EFI_NO_MAPPING When IP6 driver responsible for binding source address to this instance,
1472 while no source address is available for use.
1473 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1476 - Token.Event is NULL.
1477 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1478 resources (usually memory).
1479 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1480 The EFI IPv6 Protocol instance has been reset to startup defaults.
1481 @retval EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1482 in the receive queue.
1483 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1489 IN EFI_IP6_PROTOCOL
*This
,
1490 IN EFI_IP6_COMPLETION_TOKEN
*Token
1493 IP6_PROTOCOL
*IpInstance
;
1498 if (This
== NULL
|| Token
== NULL
|| Token
->Event
== NULL
) {
1499 return EFI_INVALID_PARAMETER
;
1502 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1503 IpSb
= IpInstance
->Service
;
1505 if (IpSb
->LinkLocalDadFail
) {
1506 return EFI_DEVICE_ERROR
;
1509 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1511 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1512 Status
= EFI_NOT_STARTED
;
1517 // Check whether the toke is already on the receive queue.
1519 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6TokenExist
, Token
);
1521 if (EFI_ERROR (Status
)) {
1522 Status
= EFI_ACCESS_DENIED
;
1527 // Queue the token then check whether there is pending received packet.
1529 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1531 if (EFI_ERROR (Status
)) {
1535 Status
= Ip6InstanceDeliverPacket (IpInstance
);
1538 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1544 gBS
->RestoreTPL (OldTpl
);
1550 Cancel the transmitted but not recycled packet. If a matching
1551 token is found, it will call Ip6CancelPacket to cancel the
1552 packet. Ip6CancelPacket cancels all the fragments of the
1553 packet. When all the fragments are freed, the IP6_TXTOKEN_WRAP
1554 is deleted from the Map, and user's event is signalled.
1555 Because Ip6CancelPacket and other functions are all called in
1556 line, after Ip6CancelPacket returns, the Item has been freed.
1558 @param[in] Map The IP6 child's transmit queue.
1559 @param[in] Item The current transmitted packet to test.
1560 @param[in] Context The user's token to cancel.
1562 @retval EFI_SUCCESS Continue to check the next Item.
1563 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1570 IN NET_MAP_ITEM
*Item
,
1574 EFI_IP6_COMPLETION_TOKEN
*Token
;
1575 IP6_TXTOKEN_WRAP
*Wrap
;
1577 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1580 // Return EFI_SUCCESS to check the next item in the map if
1581 // this one doesn't match.
1583 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1587 Wrap
= (IP6_TXTOKEN_WRAP
*) Item
->Value
;
1588 ASSERT (Wrap
!= NULL
);
1591 // Don't access the Item, Wrap and Token's members after this point.
1592 // Item and wrap has been freed. And we no longer own the Token.
1594 Ip6CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1597 // If only one item is to be cancel, return EFI_ABORTED to stop
1598 // iterating the map any more.
1600 if (Token
!= NULL
) {
1609 Cancel the receive request. This is simple, because
1610 it is only enqueued in our local receive map.
1612 @param[in] Map The IP6 child's receive queue.
1613 @param[in] Item Current receive request to cancel.
1614 @param[in] Context The user's token to cancel.
1617 @retval EFI_SUCCESS Continue to check the next receive request on the
1619 @retval EFI_ABORTED The user's token (token != NULL) has been
1627 IN NET_MAP_ITEM
*Item
,
1631 EFI_IP6_COMPLETION_TOKEN
*Token
;
1632 EFI_IP6_COMPLETION_TOKEN
*This
;
1634 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1637 if ((Token
!= NULL
) && (Token
!= This
)) {
1641 NetMapRemoveItem (Map
, Item
, NULL
);
1643 This
->Status
= EFI_ABORTED
;
1644 This
->Packet
.RxData
= NULL
;
1645 gBS
->SignalEvent (This
->Event
);
1647 if (Token
!= NULL
) {
1655 Cancel the user's receive/transmit request. It is the worker function of
1658 @param[in] IpInstance The IP6 child.
1659 @param[in] Token The token to cancel. If NULL, all token will be
1662 @retval EFI_SUCCESS The token is cancelled.
1663 @retval EFI_NOT_FOUND The token isn't found on either the
1664 transmit/receive queue.
1665 @retval EFI_DEVICE_ERROR Not all tokens are cancelled when Token is NULL.
1670 IN IP6_PROTOCOL
*IpInstance
,
1671 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1677 // First check the transmitted packet. Ip6CancelTxTokens returns
1678 // EFI_ABORTED to mean that the token has been cancelled when
1679 // token != NULL. So, return EFI_SUCCESS for this condition.
1681 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip6CancelTxTokens
, Token
);
1682 if (EFI_ERROR (Status
)) {
1683 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1691 // Check the receive queue. Ip6CancelRxTokens also returns EFI_ABORT
1692 // for Token!=NULL and it is cancelled.
1694 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6CancelRxTokens
, Token
);
1696 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
1700 if (EFI_ERROR (Status
)) {
1701 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1709 // OK, if the Token is found when Token != NULL, the NetMapIterate
1710 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
1712 if (Token
!= NULL
) {
1713 return EFI_NOT_FOUND
;
1717 // If Token == NULL, cancel all the tokens. return error if not
1718 // all of them are cancelled.
1720 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) || !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
1722 return EFI_DEVICE_ERROR
;
1729 Abort an asynchronous transmit or receive request.
1731 The Cancel() function is used to abort a pending transmit or receive request.
1732 If the token is in the transmit or receive request queues, after calling this
1733 function, Token->Status will be set to EFI_ABORTED, and then Token->Event will
1734 be signaled. If the token is not in one of the queues, which usually means the
1735 asynchronous operation has completed, this function will not signal the token,
1736 and EFI_NOT_FOUND is returned.
1738 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1739 @param[in] Token Pointer to a token that has been issued by
1740 EFI_IP6_PROTOCOL.Transmit() or
1741 EFI_IP6_PROTOCOL.Receive(). If NULL, all pending
1742 tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is
1743 defined in EFI_IP6_PROTOCOL.Transmit().
1745 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
1746 Token->Event was signaled. When Token is NULL, all
1747 pending requests were aborted, and their events were signaled.
1748 @retval EFI_INVALID_PARAMETER This is NULL.
1749 @retval EFI_NOT_STARTED This instance has not been started.
1750 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
1751 not found in the transmit or receive queue. It has either completed
1752 or was not issued by Transmit() and Receive().
1753 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1759 IN EFI_IP6_PROTOCOL
*This
,
1760 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1763 IP6_PROTOCOL
*IpInstance
;
1769 return EFI_INVALID_PARAMETER
;
1772 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1773 IpSb
= IpInstance
->Service
;
1775 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1777 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1778 Status
= EFI_NOT_STARTED
;
1782 Status
= Ip6Cancel (IpInstance
, Token
);
1785 gBS
->RestoreTPL (OldTpl
);
1790 Polls for incoming data packets, and processes outgoing data packets.
1792 The Poll() function polls for incoming data packets and processes outgoing data
1793 packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()
1794 function to increase the rate that data packets are moved between the communications
1795 device and the transmit and receive queues.
1797 In some systems the periodic timer event may not poll the underlying communications
1798 device fast enough to transmit and/or receive all data packets without missing
1799 incoming packets or dropping outgoing packets. Drivers and applications that are
1800 experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function
1803 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1805 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1806 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1807 @retval EFI_INVALID_PARAMETER This is NULL.
1808 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1809 @retval EFI_NOT_READY No incoming or outgoing data was processed.
1810 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
1811 Consider increasing the polling rate.
1817 IN EFI_IP6_PROTOCOL
*This
1820 IP6_PROTOCOL
*IpInstance
;
1822 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
1825 return EFI_INVALID_PARAMETER
;
1828 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1829 IpSb
= IpInstance
->Service
;
1831 if (IpSb
->LinkLocalDadFail
) {
1832 return EFI_DEVICE_ERROR
;
1835 if (IpInstance
->State
== IP6_STATE_UNCONFIGED
) {
1836 return EFI_NOT_STARTED
;
1839 Mnp
= IpInstance
->Service
->Mnp
;
1842 // Don't lock the Poll function to enable the deliver of
1843 // the packet polled up.
1845 return Mnp
->Poll (Mnp
);