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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 EFI_IPSEC2_PROTOCOL
*mIpSec
= NULL
;
21 EFI_IP6_PROTOCOL mEfiIp6ProtocolTemplete
= {
34 Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
36 The GetModeData() function returns the current operational mode data for this driver instance.
37 The data fields in EFI_IP6_MODE_DATA are read only. This function is used optionally to
38 retrieve the operational mode data of underlying networks or drivers.
40 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
41 @param[out] Ip6ModeData Pointer to the EFI IPv6 Protocol mode data structure.
42 @param[out] MnpConfigData Pointer to the managed network configuration data structure.
43 @param[out] SnpModeData Pointer to the simple network mode data structure.
45 @retval EFI_SUCCESS The operation completed successfully.
46 @retval EFI_INVALID_PARAMETER This is NULL.
47 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
53 IN EFI_IP6_PROTOCOL
*This
,
54 OUT EFI_IP6_MODE_DATA
*Ip6ModeData OPTIONAL
,
55 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
56 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
59 IP6_PROTOCOL
*IpInstance
;
62 EFI_IP6_CONFIG_DATA
*Config
;
67 return EFI_INVALID_PARAMETER
;
70 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
71 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
72 IpSb
= IpInstance
->Service
;
73 IpIf
= IpInstance
->Interface
;
75 if (IpSb
->LinkLocalDadFail
) {
76 return EFI_INVALID_PARAMETER
;
79 if (Ip6ModeData
!= NULL
) {
81 // IsStarted is "whether the EfiIp6Configure has been called".
82 // IsConfigured is "whether the station address has been configured"
84 Ip6ModeData
->IsStarted
= (BOOLEAN
) (IpInstance
->State
== IP6_STATE_CONFIGED
);
85 Ip6ModeData
->MaxPacketSize
= IpSb
->MaxPacketSize
;
86 CopyMem (&Ip6ModeData
->ConfigData
, &IpInstance
->ConfigData
, sizeof (EFI_IP6_CONFIG_DATA
));
87 Ip6ModeData
->IsConfigured
= FALSE
;
89 Ip6ModeData
->AddressCount
= 0;
90 Ip6ModeData
->AddressList
= NULL
;
92 Ip6ModeData
->GroupCount
= IpInstance
->GroupCount
;
93 Ip6ModeData
->GroupTable
= NULL
;
95 Ip6ModeData
->RouteCount
= 0;
96 Ip6ModeData
->RouteTable
= NULL
;
98 Ip6ModeData
->NeighborCount
= 0;
99 Ip6ModeData
->NeighborCache
= NULL
;
101 Ip6ModeData
->PrefixCount
= 0;
102 Ip6ModeData
->PrefixTable
= NULL
;
104 Ip6ModeData
->IcmpTypeCount
= 23;
105 Ip6ModeData
->IcmpTypeList
= AllocateCopyPool (
106 Ip6ModeData
->IcmpTypeCount
* sizeof (EFI_IP6_ICMP_TYPE
),
109 if (Ip6ModeData
->IcmpTypeList
== NULL
) {
110 Status
= EFI_OUT_OF_RESOURCES
;
115 // Return the currently configured IPv6 addresses and corresponding prefix lengths.
117 Status
= Ip6BuildEfiAddressList (
119 &Ip6ModeData
->AddressCount
,
120 &Ip6ModeData
->AddressList
122 if (EFI_ERROR (Status
)) {
127 // Return the current station address for this IP child.
128 // If UseAnyStationAddress is set to TRUE, IP6 driver will
129 // select a source address from its address list. Otherwise use the
130 // StationAddress in config data.
132 if (Ip6ModeData
->IsStarted
) {
133 Config
= &Ip6ModeData
->ConfigData
;
135 if (IpIf
->Configured
|| NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
136 Ip6ModeData
->IsConfigured
= TRUE
;
138 Ip6ModeData
->IsConfigured
= FALSE
;
142 // Build a EFI route table for user from the internal route table.
144 Status
= Ip6BuildEfiRouteTable (
146 &Ip6ModeData
->RouteCount
,
147 &Ip6ModeData
->RouteTable
150 if (EFI_ERROR (Status
)) {
155 if (Ip6ModeData
->IsConfigured
) {
157 // Return the joined multicast group addresses.
159 if (IpInstance
->GroupCount
!= 0) {
160 Ip6ModeData
->GroupTable
= AllocateCopyPool (
161 IpInstance
->GroupCount
* sizeof (EFI_IPv6_ADDRESS
),
162 IpInstance
->GroupList
164 if (Ip6ModeData
->GroupTable
== NULL
) {
165 Status
= EFI_OUT_OF_RESOURCES
;
170 // Return the neighbor cache entries
172 Status
= Ip6BuildEfiNeighborCache (
174 &Ip6ModeData
->NeighborCount
,
175 &Ip6ModeData
->NeighborCache
177 if (EFI_ERROR (Status
)) {
182 // Return the prefix table entries
184 Status
= Ip6BuildPrefixTable (
186 &Ip6ModeData
->PrefixCount
,
187 &Ip6ModeData
->PrefixTable
189 if (EFI_ERROR (Status
)) {
197 // Get fresh mode data from MNP, since underlying media status may change
199 Status
= IpSb
->Mnp
->GetModeData (IpSb
->Mnp
, MnpConfigData
, SnpModeData
);
204 if (Ip6ModeData
!= NULL
) {
205 if (Ip6ModeData
->AddressList
!= NULL
) {
206 FreePool (Ip6ModeData
->AddressList
);
209 if (Ip6ModeData
->GroupTable
!= NULL
) {
210 FreePool (Ip6ModeData
->GroupTable
);
213 if (Ip6ModeData
->RouteTable
!= NULL
) {
214 FreePool (Ip6ModeData
->RouteTable
);
217 if (Ip6ModeData
->NeighborCache
!= NULL
) {
218 FreePool (Ip6ModeData
->NeighborCache
);
221 if (Ip6ModeData
->PrefixTable
!= NULL
) {
222 FreePool (Ip6ModeData
->PrefixTable
);
225 if (Ip6ModeData
->IcmpTypeList
!= NULL
) {
226 FreePool (Ip6ModeData
->IcmpTypeList
);
231 gBS
->RestoreTPL (OldTpl
);
236 Validate that Ipv6 address is OK to be used as station address or next hop address/ neighbor.
238 @param[in] IpSb The IP6 service instance.
239 @param[in] Ip The IPv6 address to validate.
240 @param[in] Flag If TRUE, validate if the address is OK to be used
241 as station address. If FALSE, validate if the
242 address is OK to be used as the next hop address/
245 @retval TRUE The Ip address is valid and could be used.
246 @retval FALSE Invalid Ip address.
251 IN IP6_SERVICE
*IpSb
,
252 IN EFI_IPv6_ADDRESS
*Ip
,
256 if (!NetIp6IsUnspecifiedAddr (Ip
)) {
257 if (!NetIp6IsValidUnicast(Ip
)) {
260 if (Ip6IsOneOfSetAddress (IpSb
, Ip
, NULL
, NULL
)) {
267 return (BOOLEAN
) !Flag
;
271 Validate whether the value of protocol is illegal or not. Protocol is the 'Next Header' field
272 in the last IPv6 extension header, or basic IPv6 header is there's no extension header.
274 @param[in] Protocol Default value of 'Next Header'
276 @retval TRUE The protocol is illegal.
277 @retval FALSE The protocol is legal.
281 Ip6IsIllegalProtocol (
285 if (Protocol
== IP6_HOP_BY_HOP
|| Protocol
== EFI_IP_PROTO_ICMP
|| Protocol
== IP4_PROTO_IGMP
) {
289 if (Protocol
== 41 || Protocol
== 43 || Protocol
== 44 || Protocol
== 59 || Protocol
== 60 || Protocol
== 124) {
297 Intiialize the IP6_PROTOCOL structure to the unconfigured states.
299 @param[in] IpSb The IP6 service instance.
300 @param[in, out] IpInstance The IP6 child instance.
305 IN IP6_SERVICE
*IpSb
,
306 IN OUT IP6_PROTOCOL
*IpInstance
309 ASSERT ((IpSb
!= NULL
) && (IpInstance
!= NULL
));
311 ZeroMem (IpInstance
, sizeof (IP6_PROTOCOL
));
313 IpInstance
->Signature
= IP6_PROTOCOL_SIGNATURE
;
314 IpInstance
->State
= IP6_STATE_UNCONFIGED
;
315 IpInstance
->Service
= IpSb
;
316 IpInstance
->GroupList
= NULL
;
317 CopyMem (&IpInstance
->Ip6Proto
, &mEfiIp6ProtocolTemplete
, sizeof (EFI_IP6_PROTOCOL
));
319 NetMapInit (&IpInstance
->RxTokens
);
320 NetMapInit (&IpInstance
->TxTokens
);
321 InitializeListHead (&IpInstance
->Received
);
322 InitializeListHead (&IpInstance
->Delivered
);
324 EfiInitializeLock (&IpInstance
->RecycleLock
, TPL_NOTIFY
);
328 Configure the IP6 child. If the child is already configured,
329 change the configuration parameter. Otherwise, configure it
330 for the first time. The caller should validate the configuration
331 before deliver them to it. It also don't do configure NULL.
333 @param[in, out] IpInstance The IP6 child to configure.
334 @param[in] Config The configure data.
336 @retval EFI_SUCCESS The IP6 child is successfully configured.
337 @retval EFI_DEVICE_ERROR Failed to free the pending transive or to
338 configure underlying MNP, or other errors.
339 @retval EFI_NO_MAPPING The IP6 child is configured to use the default
340 address, but the default address hasn't been
341 configured. The IP6 child doesn't need to be
342 reconfigured when the default address is configured.
343 @retval EFI_OUT_OF_RESOURCES No more memory space is available.
344 @retval other Other error occurs.
349 IN OUT IP6_PROTOCOL
*IpInstance
,
350 IN EFI_IP6_CONFIG_DATA
*Config
356 EFI_IP6_CONFIG_DATA
*Current
;
357 IP6_ADDRESS_INFO
*AddressInfo
;
360 EFI_IPv6_ADDRESS Source
;
363 IpSb
= IpInstance
->Service
;
364 Current
= &IpInstance
->ConfigData
;
367 // User is changing packet filters. It must be stopped
368 // before the station address can be changed.
370 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
372 // Cancel all the pending transmit/receive from upper layer
374 Status
= Ip6Cancel (IpInstance
, NULL
);
376 if (EFI_ERROR (Status
)) {
377 return EFI_DEVICE_ERROR
;
380 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
385 // Set up the interface.
387 StationZero
= NetIp6IsUnspecifiedAddr (&Config
->StationAddress
);
388 DestZero
= NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
);
390 if (StationZero
&& DestZero
) {
392 // StationAddress is still zero.
395 NET_GET_REF (IpSb
->DefaultInterface
);
396 IpInstance
->Interface
= IpSb
->DefaultInterface
;
397 InsertTailList (&IpSb
->DefaultInterface
->IpInstances
, &IpInstance
->AddrLink
);
399 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
400 IpInstance
->State
= IP6_STATE_CONFIGED
;
405 if (StationZero
&& !DestZero
) {
406 Status
= Ip6SelectSourceAddress (IpSb
, &Config
->DestinationAddress
, &Source
);
407 if (EFI_ERROR (Status
)) {
411 IP6_COPY_ADDRESS (&Source
, &Config
->StationAddress
);
414 AddrOk
= Ip6IsOneOfSetAddress (IpSb
, &Source
, &IpIf
, &AddressInfo
);
416 if (AddressInfo
!= NULL
) {
417 IpInstance
->PrefixLength
= AddressInfo
->PrefixLength
;
419 IpInstance
->PrefixLength
= IP6_LINK_LOCAL_PREFIX_LENGTH
;
423 // The specified source address is not one of the addresses IPv6 maintains.
425 return EFI_INVALID_PARAMETER
;
430 IpInstance
->Interface
= IpIf
;
431 InsertTailList (&IpIf
->IpInstances
, &IpInstance
->AddrLink
);
433 CopyMem (Current
, Config
, sizeof (EFI_IP6_CONFIG_DATA
));
434 IP6_COPY_ADDRESS (&Current
->StationAddress
, &Source
);
435 IpInstance
->State
= IP6_STATE_CONFIGED
;
441 Clean up the IP6 child, and release all the resources used by it.
443 @param[in, out] IpInstance The IP6 child to clean up.
445 @retval EFI_SUCCESS The IP6 child is cleaned up.
446 @retval EFI_DEVICE_ERROR Some resources failed to be released.
451 IN OUT IP6_PROTOCOL
*IpInstance
454 if (EFI_ERROR (Ip6Cancel (IpInstance
, NULL
))) {
455 return EFI_DEVICE_ERROR
;
458 if (EFI_ERROR (Ip6Groups (IpInstance
, FALSE
, NULL
))) {
459 return EFI_DEVICE_ERROR
;
463 // Some packets haven't been recycled. It is because either the
464 // user forgets to recycle the packets, or because the callback
465 // hasn't been called. Just leave it alone.
467 if (!IsListEmpty (&IpInstance
->Delivered
)) {
471 if (IpInstance
->Interface
!= NULL
) {
472 RemoveEntryList (&IpInstance
->AddrLink
);
473 Ip6CleanInterface (IpInstance
->Interface
, IpInstance
);
474 IpInstance
->Interface
= NULL
;
477 if (IpInstance
->GroupList
!= NULL
) {
478 FreePool (IpInstance
->GroupList
);
479 IpInstance
->GroupList
= NULL
;
480 IpInstance
->GroupCount
= 0;
483 NetMapClean (&IpInstance
->TxTokens
);
485 NetMapClean (&IpInstance
->RxTokens
);
491 Configure the MNP parameter used by IP. The IP driver uses one MNP
492 child to transmit/receive frames. By default, it configures MNP
493 to receive unicast/multicast/broadcast. Also, it will enable/disable
494 the promiscuous receive according to whether there is IP child
495 enable that or not. If Force is FALSE, it will iterate through
496 all the IP children to check whether the promiscuous receive
497 setting has been changed. If it hasn't been changed, it won't
498 reconfigure the MNP. If Force is TRUE, the MNP is configured
499 whether that is changed or not.
501 @param[in] IpSb The IP6 service instance that is to be changed.
502 @param[in] Force Force the configuration or not.
504 @retval EFI_SUCCESS The MNP successfully configured/reconfigured.
505 @retval Others Configuration failed.
509 Ip6ServiceConfigMnp (
510 IN IP6_SERVICE
*IpSb
,
515 LIST_ENTRY
*ProtoEntry
;
517 IP6_PROTOCOL
*IpInstance
;
519 BOOLEAN PromiscReceive
;
523 PromiscReceive
= FALSE
;
527 // Iterate through the IP children to check whether promiscuous
528 // receive setting has been changed. Update the interface's receive
531 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
533 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
534 IpIf
->PromiscRecv
= FALSE
;
536 NET_LIST_FOR_EACH (ProtoEntry
, &IpIf
->IpInstances
) {
537 IpInstance
= NET_LIST_USER_STRUCT (ProtoEntry
, IP6_PROTOCOL
, AddrLink
);
539 if (IpInstance
->ConfigData
.AcceptPromiscuous
) {
540 IpIf
->PromiscRecv
= TRUE
;
541 PromiscReceive
= TRUE
;
547 // If promiscuous receive isn't changed, it isn't necessary to reconfigure.
549 if (PromiscReceive
== IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
554 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= PromiscReceive
;
557 Status
= IpSb
->Mnp
->Configure (IpSb
->Mnp
, &IpSb
->MnpConfigData
);
560 // recover the original configuration if failed to set the configure.
562 if (EFI_ERROR (Status
) && Reconfig
) {
563 IpSb
->MnpConfigData
.EnablePromiscuousReceive
= (BOOLEAN
) !PromiscReceive
;
570 Assigns an IPv6 address and subnet mask to this EFI IPv6 Protocol driver instance.
572 The Configure() function is used to set, change, or reset the operational parameters and filter
573 settings for this EFI IPv6 Protocol instance. Until these parameters have been set, no network traffic
574 can be sent or received by this instance. Once the parameters have been reset (by calling this
575 function with Ip6ConfigData set to NULL), no more traffic can be sent or received until these
576 parameters have been set again. Each EFI IPv6 Protocol instance can be started and stopped
577 independently of each other by enabling or disabling their receive filter settings with the
578 Configure() function.
580 If Ip6ConfigData.StationAddress is a valid non-zero IPv6 unicast address, it is required
581 to be one of the currently configured IPv6 addresses listed in the EFI IPv6 drivers, or else
582 EFI_INVALID_PARAMETER will be returned. If Ip6ConfigData.StationAddress is
583 unspecified, the IPv6 driver will bind a source address according to the source address selection
584 algorithm. Clients could frequently call GetModeData() to check get currently configured IPv6
585 address list in the EFI IPv6 driver. If both Ip6ConfigData.StationAddress and
586 Ip6ConfigData.Destination are unspecified, when transmitting the packet afterwards, the
587 source address filled in each outgoing IPv6 packet is decided based on the destination of this packet.
589 If operational parameters are reset or changed, any pending transmit and receive requests will be
590 cancelled. Their completion token status will be set to EFI_ABORTED and their events will be
593 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
594 @param[in] Ip6ConfigData Pointer to the EFI IPv6 Protocol configuration data structure.
595 If NULL, reset the configuration data.
597 @retval EFI_SUCCESS The driver instance was successfully opened.
598 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
600 - Ip6ConfigData.StationAddress is neither zero nor
601 a unicast IPv6 address.
602 - Ip6ConfigData.StationAddress is neither zero nor
603 one of the configured IP addresses in the EFI IPv6 driver.
604 - Ip6ConfigData.DefaultProtocol is illegal.
605 @retval EFI_OUT_OF_RESOURCES The EFI IPv6 Protocol driver instance data could not be allocated.
606 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing a source address for
607 this instance, but no source address was available for use.
608 @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the IPv6
609 address or prefix length can be changed.
610 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv6
611 Protocol driver instance was not opened.
612 @retval EFI_UNSUPPORTED Default protocol specified through
613 Ip6ConfigData.DefaulProtocol isn't supported.
619 IN EFI_IP6_PROTOCOL
*This
,
620 IN EFI_IP6_CONFIG_DATA
*Ip6ConfigData OPTIONAL
623 IP6_PROTOCOL
*IpInstance
;
624 EFI_IP6_CONFIG_DATA
*Current
;
630 // First, validate the parameters
633 return EFI_INVALID_PARAMETER
;
636 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
637 IpSb
= IpInstance
->Service
;
639 if (IpSb
->LinkLocalDadFail
&& Ip6ConfigData
!= NULL
) {
640 return EFI_DEVICE_ERROR
;
643 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
645 Status
= EFI_INVALID_PARAMETER
;
648 // Validate the configuration first.
650 if (Ip6ConfigData
!= NULL
) {
652 // Check whether the station address is valid.
654 if (!Ip6IsValidAddress (IpSb
, &Ip6ConfigData
->StationAddress
, TRUE
)) {
658 // Check whether the default protocol is valid.
660 if (Ip6IsIllegalProtocol (Ip6ConfigData
->DefaultProtocol
)) {
665 // User can only update packet filters when already configured.
666 // If it wants to change the station address, it must configure(NULL)
667 // the instance firstly.
669 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
670 Current
= &IpInstance
->ConfigData
;
672 if (!EFI_IP6_EQUAL (&Current
->StationAddress
, &Ip6ConfigData
->StationAddress
)) {
673 Status
= EFI_ALREADY_STARTED
;
677 if (NetIp6IsUnspecifiedAddr (&Current
->StationAddress
) && IP6_NO_MAPPING (IpInstance
)) {
678 Status
= EFI_NO_MAPPING
;
685 // Configure the instance or clean it up.
687 if (Ip6ConfigData
!= NULL
) {
688 Status
= Ip6ConfigProtocol (IpInstance
, Ip6ConfigData
);
690 Status
= Ip6CleanProtocol (IpInstance
);
693 // Don't change the state if it is DESTROY, consider the following
694 // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,
695 // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,
696 // the unload fails miserably.
698 if (IpInstance
->State
== IP6_STATE_CONFIGED
) {
699 IpInstance
->State
= IP6_STATE_UNCONFIGED
;
704 // Update the MNP's configure data. Ip6ServiceConfigMnp will check
705 // whether it is necessary to reconfigure the MNP.
707 Ip6ServiceConfigMnp (IpInstance
->Service
, FALSE
);
710 gBS
->RestoreTPL (OldTpl
);
715 Joins and leaves multicast groups.
717 The Groups() function is used to join and leave multicast group sessions. Joining a group will
718 enable reception of matching multicast packets. Leaving a group will disable reception of matching
719 multicast packets. Source-Specific Multicast isn't required to be supported.
721 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
723 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
724 @param[in] JoinFlag Set to TRUE to join the multicast group session, and FALSE to leave.
725 @param[in] GroupAddress Pointer to the IPv6 multicast address.
726 This is an optional parameter that may be NULL.
728 @retval EFI_SUCCESS The operation completed successfully.
729 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
731 - JoinFlag is TRUE and GroupAddress is NULL.
732 - GroupAddress is not NULL and *GroupAddress is
733 not a multicast IPv6 address.
734 - GroupAddress is not NULL and *GroupAddress is in the
735 range of SSM destination address.
736 @retval EFI_NOT_STARTED This instance has not been started.
737 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
738 @retval EFI_UNSUPPORTED This EFI IPv6 Protocol implementation does not support multicast groups.
739 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
741 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
742 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
748 IN EFI_IP6_PROTOCOL
*This
,
750 IN EFI_IPv6_ADDRESS
*GroupAddress OPTIONAL
755 IP6_PROTOCOL
*IpInstance
;
758 if ((This
== NULL
) || (JoinFlag
&& GroupAddress
== NULL
)) {
759 return EFI_INVALID_PARAMETER
;
762 if (GroupAddress
!= NULL
&& !IP6_IS_MULTICAST (GroupAddress
)) {
763 return EFI_INVALID_PARAMETER
;
766 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
767 IpSb
= IpInstance
->Service
;
769 if (IpSb
->LinkLocalDadFail
) {
770 return EFI_DEVICE_ERROR
;
773 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
775 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
776 Status
= EFI_NOT_STARTED
;
780 Status
= Ip6Groups (IpInstance
, JoinFlag
, GroupAddress
);
783 gBS
->RestoreTPL (OldTpl
);
788 Adds and deletes routing table entries.
790 The Routes() function adds a route to, or deletes a route from, the routing table.
792 Routes are determined by comparing the leftmost PrefixLength bits of Destination with
793 the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the
794 configured station address.
796 The default route is added with Destination and PrefixLegth both set to all zeros. The
797 default route matches all destination IPv6 addresses that do not match any other routes.
799 All EFI IPv6 Protocol instances share a routing table.
801 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
802 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
803 FALSE to add this route to the routing table. Destination,
804 PrefixLength and Gateway are used as the key to each
806 @param[in] Destination The address prefix of the subnet that needs to be routed.
807 This is an optional parameter that may be NULL.
808 @param[in] PrefixLength The prefix length of Destination. Ignored if Destination
810 @param[in] GatewayAddress The unicast gateway IPv6 address for this route.
811 This is an optional parameter that may be NULL.
813 @retval EFI_SUCCESS The operation completed successfully.
814 @retval EFI_NOT_STARTED The driver instance has not been started.
815 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
817 - When DeleteRoute is TRUE, both Destination and
818 GatewayAddress are NULL.
819 - When DeleteRoute is FALSE, either Destination or
820 GatewayAddress is NULL.
821 - *GatewayAddress is not a valid unicast IPv6 address.
822 - *GatewayAddress is one of the local configured IPv6
824 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
825 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
826 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
827 DeleteRoute is FALSE).
833 IN EFI_IP6_PROTOCOL
*This
,
834 IN BOOLEAN DeleteRoute
,
835 IN EFI_IPv6_ADDRESS
*Destination OPTIONAL
,
836 IN UINT8 PrefixLength
,
837 IN EFI_IPv6_ADDRESS
*GatewayAddress OPTIONAL
840 IP6_PROTOCOL
*IpInstance
;
845 if ((This
== NULL
) || (PrefixLength
> IP6_PREFIX_MAX
)) {
846 return EFI_INVALID_PARAMETER
;
849 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
850 IpSb
= IpInstance
->Service
;
852 if (IpSb
->LinkLocalDadFail
) {
853 return EFI_DEVICE_ERROR
;
856 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
857 return EFI_NOT_STARTED
;
860 if (DeleteRoute
&& (Destination
== NULL
) && (GatewayAddress
== NULL
)) {
861 return EFI_INVALID_PARAMETER
;
864 if (!DeleteRoute
&& (Destination
== NULL
|| GatewayAddress
== NULL
)) {
865 return EFI_INVALID_PARAMETER
;
868 if (GatewayAddress
!= NULL
) {
869 if (!Ip6IsValidAddress (IpSb
, GatewayAddress
, FALSE
)) {
870 return EFI_INVALID_PARAMETER
;
873 if (!NetIp6IsUnspecifiedAddr (GatewayAddress
) &&
874 !NetIp6IsNetEqual (GatewayAddress
, &IpInstance
->ConfigData
.StationAddress
, PrefixLength
)
876 return EFI_INVALID_PARAMETER
;
880 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
883 // Update the route table
886 Status
= Ip6DelRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
888 Status
= Ip6AddRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
891 gBS
->RestoreTPL (OldTpl
);
896 Add or delete Neighbor cache entries.
898 The Neighbors() function is used to add, update, or delete an entry from neighbor cache.
899 IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as
900 network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network
901 traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not
902 timeout) or dynamic (will timeout).
904 The implementation should follow the neighbor cache timeout mechanism which is defined in
905 RFC4861. The default neighbor cache timeout value should be tuned for the expected network
908 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
909 @param[in] DeleteFlag Set to TRUE to delete the specified cache entry, set to FALSE to
910 add (or update, if it already exists and Override is TRUE) the
911 specified cache entry. TargetIp6Address is used as the key
912 to find the requested cache entry.
913 @param[in] TargetIp6Address Pointer to the Target IPv6 address.
914 @param[in] TargetLinkAddress Pointer to the link-layer address of the target. Ignored if NULL.
915 @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
916 cache, it will be deleted after Timeout. A value of zero means that
917 the entry is permanent. A non-zero value means that the entry is
919 @param[in] Override If TRUE, the cached link-layer address of the matching entry will
920 be overridden and updated; if FALSE, EFI_ACCESS_DENIED
921 will be returned if a corresponding cache entry already existed.
923 @retval EFI_SUCCESS The data has been queued for transmission.
924 @retval EFI_NOT_STARTED This instance has not been started.
925 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
927 - TargetIpAddress is NULL.
928 - *TargetLinkAddress is invalid when not NULL.
929 - *TargetIpAddress is not a valid unicast IPv6 address.
930 - *TargetIpAddress is one of the local configured IPv6
932 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache.
933 @retval EFI_NOT_FOUND This entry is not in the neighbor cache (when DeleteFlag is
934 TRUE or when DeleteFlag is FALSE while
935 TargetLinkAddress is NULL.).
936 @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
937 and that entry is tagged as un-overridden (when Override
944 IN EFI_IP6_PROTOCOL
*This
,
945 IN BOOLEAN DeleteFlag
,
946 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
947 IN EFI_MAC_ADDRESS
*TargetLinkAddress OPTIONAL
,
954 IP6_PROTOCOL
*IpInstance
;
957 if (This
== NULL
|| TargetIp6Address
== NULL
) {
958 return EFI_INVALID_PARAMETER
;
961 if (NetIp6IsUnspecifiedAddr (TargetIp6Address
)) {
962 return EFI_INVALID_PARAMETER
;
965 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
966 IpSb
= IpInstance
->Service
;
968 if (IpSb
->LinkLocalDadFail
) {
969 return EFI_DEVICE_ERROR
;
972 if (!Ip6IsValidAddress (IpSb
, TargetIp6Address
, FALSE
)) {
973 return EFI_INVALID_PARAMETER
;
976 if (TargetLinkAddress
!= NULL
) {
977 if (!Ip6IsValidLinkAddress (IpSb
, TargetLinkAddress
)) {
978 return EFI_INVALID_PARAMETER
;
982 if (Ip6IsOneOfSetAddress (IpSb
, TargetIp6Address
, NULL
, NULL
)) {
983 return EFI_INVALID_PARAMETER
;
986 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
987 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
988 Status
= EFI_NOT_STARTED
;
993 Status
= Ip6DelNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
995 Status
= Ip6AddNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
999 gBS
->RestoreTPL (OldTpl
);
1004 Check whether the user's token or event has already
1005 been enqueue on IP6's list.
1007 @param[in] Map The container of either user's transmit or receive
1009 @param[in] Item Current item to check against.
1010 @param[in] Context The Token to check againist.
1012 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1013 @retval EFI_SUCCESS The current item isn't the same token/event as the
1021 IN NET_MAP_ITEM
*Item
,
1025 EFI_IP6_COMPLETION_TOKEN
*Token
;
1026 EFI_IP6_COMPLETION_TOKEN
*TokenInItem
;
1028 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1029 TokenInItem
= (EFI_IP6_COMPLETION_TOKEN
*) Item
->Key
;
1031 if (Token
== TokenInItem
|| Token
->Event
== TokenInItem
->Event
) {
1032 return EFI_ACCESS_DENIED
;
1039 Validate the user's token against the current station address.
1041 @param[in] Token User's token to validate.
1043 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1044 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1045 @retval EFI_SUCCESS The token is OK.
1050 IN EFI_IP6_COMPLETION_TOKEN
*Token
1053 EFI_IP6_TRANSMIT_DATA
*TxData
;
1057 if (Token
== NULL
|| Token
->Event
== NULL
) {
1058 return EFI_INVALID_PARAMETER
;
1061 TxData
= Token
->Packet
.TxData
;
1063 if (TxData
== NULL
|| (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
== NULL
)) {
1064 return EFI_INVALID_PARAMETER
;
1067 if (TxData
->FragmentCount
== 0 || TxData
->DataLength
== 0) {
1068 return EFI_INVALID_PARAMETER
;
1071 for (DataLength
= 0, Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1072 if (TxData
->FragmentTable
[Index
].FragmentLength
== 0 || TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) {
1073 return EFI_INVALID_PARAMETER
;
1076 DataLength
+= TxData
->FragmentTable
[Index
].FragmentLength
;
1079 if (TxData
->DataLength
!= DataLength
) {
1080 return EFI_INVALID_PARAMETER
;
1084 // TODO: Token.Packet.TxData.DataLength is too short to transmit.
1085 // return EFI_BUFFER_TOO_SMALL;
1089 // If Token.Packet.TxData.DataLength is beyond the maximum that which can be
1090 // described through the Fragment Offset field in Fragment header when performing
1093 if (TxData
->DataLength
> 64 * 1024) {
1094 return EFI_BAD_BUFFER_SIZE
;
1101 The callback function for the net buffer which wraps the user's
1102 transmit token. Although this function seems simple, there
1103 are some subtle aspects.
1104 When user requests the IP to transmit a packet by passing it a
1105 token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data
1106 is wrapped in an net buffer. The net buffer's Free function is
1107 set to Ip6FreeTxToken. The Token and token wrap are added to the
1108 IP child's TxToken map. Then the buffer is passed to Ip6Output for
1109 transmission. If an error happened before that, the buffer
1110 is freed, which in turn frees the token wrap. The wrap may
1111 have been added to the TxToken map or not, and the user's event
1112 shouldn't be fired because we are still in the EfiIp6Transmit. If
1113 the buffer has been sent by Ip6Output, it should be removed from
1114 the TxToken map and user's event signaled. The token wrap and buffer
1115 are bound together. Check the comments in Ip6Output for information
1116 about IP fragmentation.
1118 @param[in] Context The token's wrap.
1127 IP6_TXTOKEN_WRAP
*Wrap
;
1130 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1133 // Signal IpSecRecycleEvent to inform IPsec free the memory
1135 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1136 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1140 // Find the token in the instance's map. EfiIp6Transmit put the
1141 // token to the map. If that failed, NetMapFindKey will return NULL.
1143 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1146 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1150 gBS
->SignalEvent (Wrap
->Token
->Event
);
1153 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1163 The callback function to Ip6Output to update the transmit status.
1165 @param[in] Packet The user's transmit packet.
1166 @param[in] IoStatus The result of the transmission.
1167 @param[in] Flag Not used during transmission.
1168 @param[in] Context The token's wrap.
1174 IN EFI_STATUS IoStatus
,
1179 IP6_TXTOKEN_WRAP
*Wrap
;
1182 // This is the transmission request from upper layer,
1183 // not the IP6 driver itself.
1185 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1186 Wrap
->Token
->Status
= IoStatus
;
1188 NetbufFree (Wrap
->Packet
);
1192 Places outgoing data packets into the transmit queue.
1194 The Transmit() function places a sending request in the transmit queue of this
1195 EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some
1196 errors occur, the event in the token will be signaled, and the status is updated.
1198 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1199 @param[in] Token Pointer to the transmit token.
1201 @retval EFI_SUCCESS The data has been queued for transmission.
1202 @retval EFI_NOT_STARTED This instance has not been started.
1203 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing
1204 a source address for this transmission,
1205 but no source address was available for use.
1206 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1209 - Token.Event is NULL.
1210 - Token.Packet.TxData is NULL.
1211 - Token.Packet.ExtHdrsLength is not zero and
1212 Token.Packet.ExtHdrs is NULL.
1213 - Token.Packet.FragmentCount is zero.
1214 - One or more of the Token.Packet.TxData.
1215 FragmentTable[].FragmentLength fields is zero.
1216 - One or more of the Token.Packet.TxData.
1217 FragmentTable[].FragmentBuffer fields is NULL.
1218 - Token.Packet.TxData.DataLength is zero or not
1219 equal to the sum of fragment lengths.
1220 - Token.Packet.TxData.DestinationAddress is non
1221 zero when DestinationAddress is configured as
1222 non-zero when doing Configure() for this
1223 EFI IPv6 protocol instance.
1224 - Token.Packet.TxData.DestinationAddress is
1225 unspecified when DestinationAddress is unspecified
1226 when doing Configure() for this EFI IPv6 protocol
1228 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.
1229 Event was already in the transmit queue.
1230 @retval EFI_NOT_READY The completion token could not be queued because
1231 the transmit queue is full.
1232 @retval EFI_NOT_FOUND Not route is found to destination address.
1233 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1234 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1236 @retval EFI_BAD_BUFFER_SIZE If Token.Packet.TxData.DataLength is beyond the
1237 maximum that which can be described through the
1238 Fragment Offset field in Fragment header when
1239 performing fragmentation.
1240 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1246 IN EFI_IP6_PROTOCOL
*This
,
1247 IN EFI_IP6_COMPLETION_TOKEN
*Token
1251 IP6_PROTOCOL
*IpInstance
;
1252 EFI_IP6_CONFIG_DATA
*Config
;
1255 EFI_IP6_HEADER Head
;
1256 EFI_IP6_TRANSMIT_DATA
*TxData
;
1257 EFI_IP6_OVERRIDE_DATA
*Override
;
1258 IP6_TXTOKEN_WRAP
*Wrap
;
1262 // Check input parameters.
1265 return EFI_INVALID_PARAMETER
;
1270 Status
= Ip6TxTokenValid (Token
);
1271 if (EFI_ERROR (Status
)) {
1275 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1276 IpSb
= IpInstance
->Service
;
1278 if (IpSb
->LinkLocalDadFail
) {
1279 return EFI_DEVICE_ERROR
;
1282 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1284 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1285 Status
= EFI_NOT_STARTED
;
1289 Config
= &IpInstance
->ConfigData
;
1292 // Check whether the token or signal already existed.
1294 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip6TokenExist
, Token
))) {
1295 Status
= EFI_ACCESS_DENIED
;
1300 // Build the IP header, fill in the information from ConfigData or OverrideData
1302 ZeroMem (&Head
, sizeof(EFI_IP6_HEADER
));
1303 TxData
= Token
->Packet
.TxData
;
1304 IP6_COPY_ADDRESS (&Head
.SourceAddress
, &Config
->StationAddress
);
1305 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &Config
->DestinationAddress
);
1307 Status
= EFI_INVALID_PARAMETER
;
1309 if (NetIp6IsUnspecifiedAddr (&TxData
->DestinationAddress
)) {
1310 if (NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1314 ASSERT (!NetIp6IsUnspecifiedAddr (&Config
->StationAddress
));
1318 // StationAddress is unspecified only when ConfigData.Dest is unspecified.
1319 // Use TxData.Dest to override the DestinationAddress.
1321 if (!NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1325 if (NetIp6IsUnspecifiedAddr (&Config
->StationAddress
)) {
1326 Status
= Ip6SelectSourceAddress (
1328 &TxData
->DestinationAddress
,
1331 if (EFI_ERROR (Status
)) {
1336 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &TxData
->DestinationAddress
);
1340 // Fill in Head infos.
1342 Head
.NextHeader
= Config
->DefaultProtocol
;
1343 if (TxData
->ExtHdrsLength
!= 0) {
1344 Head
.NextHeader
= TxData
->NextHeader
;
1347 if (TxData
->OverrideData
!= NULL
) {
1348 Override
= TxData
->OverrideData
;
1349 Head
.NextHeader
= Override
->Protocol
;
1350 Head
.HopLimit
= Override
->HopLimit
;
1351 Head
.FlowLabelL
= HTONS ((UINT16
) Override
->FlowLabel
);
1352 Head
.FlowLabelH
= (UINT8
) ((Override
->FlowLabel
>> 16) & 0x0F);
1354 Head
.HopLimit
= Config
->HopLimit
;
1355 Head
.FlowLabelL
= HTONS ((UINT16
) Config
->FlowLabel
);
1356 Head
.FlowLabelH
= (UINT8
) ((Config
->FlowLabel
>> 16) & 0x0F);
1359 Head
.PayloadLength
= HTONS ((UINT16
) (TxData
->ExtHdrsLength
+ TxData
->DataLength
));
1362 // OK, it survives all the validation check. Wrap the token in
1363 // a IP6_TXTOKEN_WRAP and the data in a netbuf
1365 Status
= EFI_OUT_OF_RESOURCES
;
1366 Wrap
= AllocateZeroPool (sizeof (IP6_TXTOKEN_WRAP
));
1371 Wrap
->IpInstance
= IpInstance
;
1372 Wrap
->Token
= Token
;
1374 Wrap
->Life
= IP6_US_TO_SEC (Config
->TransmitTimeout
);
1375 Wrap
->Packet
= NetbufFromExt (
1376 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1377 TxData
->FragmentCount
,
1384 if (Wrap
->Packet
== NULL
) {
1389 Token
->Status
= EFI_NOT_READY
;
1391 Status
= NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
);
1392 if (EFI_ERROR (Status
)) {
1394 // NetbufFree will call Ip6FreeTxToken, which in turn will
1395 // free the IP6_TXTOKEN_WRAP. Now, the token wrap hasn't been
1398 NetbufFree (Wrap
->Packet
);
1403 // Allocate a new buffer to store IPv6 extension headers to avoid updating
1404 // the original data in EFI_IP6_COMPLETION_TOKEN.
1406 if (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
!= NULL
) {
1407 ExtHdrs
= (UINT8
*) AllocateCopyPool (TxData
->ExtHdrsLength
, TxData
->ExtHdrs
);
1408 if (ExtHdrs
== NULL
) {
1409 Status
= EFI_OUT_OF_RESOURCES
;
1415 // Mark the packet sent before output it. Mark it not sent again if the
1416 // returned status is not EFI_SUCCESS;
1420 Status
= Ip6Output (
1427 TxData
->ExtHdrsLength
,
1431 if (EFI_ERROR (Status
)) {
1433 NetbufFree (Wrap
->Packet
);
1437 gBS
->RestoreTPL (OldTpl
);
1439 if (ExtHdrs
!= NULL
) {
1447 Places a receiving request into the receiving queue.
1449 The Receive() function places a completion token into the receive packet queue.
1450 This function is always asynchronous.
1452 The Token.Event field in the completion token must be filled in by the caller
1453 and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol
1454 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1457 Current Udp implementation creates an IP child for each Udp child.
1458 It initates a asynchronous receive immediately no matter whether
1459 there is no mapping or not. Therefore, disable the returning EFI_NO_MAPPING for now.
1460 To enable it, the following check must be performed:
1462 if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
1463 Status = EFI_NO_MAPPING;
1467 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1468 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1470 @retval EFI_SUCCESS The receive completion token was cached.
1471 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1472 @retval EFI_NO_MAPPING When IP6 driver responsible for binding source address to this instance,
1473 while no source address is available for use.
1474 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1477 - Token.Event is NULL.
1478 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1479 resources (usually memory).
1480 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1481 The EFI IPv6 Protocol instance has been reset to startup defaults.
1482 @retval EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1483 in the receive queue.
1484 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1490 IN EFI_IP6_PROTOCOL
*This
,
1491 IN EFI_IP6_COMPLETION_TOKEN
*Token
1494 IP6_PROTOCOL
*IpInstance
;
1499 if (This
== NULL
|| Token
== NULL
|| Token
->Event
== NULL
) {
1500 return EFI_INVALID_PARAMETER
;
1503 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1504 IpSb
= IpInstance
->Service
;
1506 if (IpSb
->LinkLocalDadFail
) {
1507 return EFI_DEVICE_ERROR
;
1510 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1512 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1513 Status
= EFI_NOT_STARTED
;
1518 // Check whether the toke is already on the receive queue.
1520 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6TokenExist
, Token
);
1522 if (EFI_ERROR (Status
)) {
1523 Status
= EFI_ACCESS_DENIED
;
1528 // Queue the token then check whether there is pending received packet.
1530 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1532 if (EFI_ERROR (Status
)) {
1536 Status
= Ip6InstanceDeliverPacket (IpInstance
);
1539 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1545 gBS
->RestoreTPL (OldTpl
);
1551 Cancel the transmitted but not recycled packet. If a matching
1552 token is found, it will call Ip6CancelPacket to cancel the
1553 packet. Ip6CancelPacket cancels all the fragments of the
1554 packet. When all the fragments are freed, the IP6_TXTOKEN_WRAP
1555 is deleted from the Map, and user's event is signalled.
1556 Because Ip6CancelPacket and other functions are all called in
1557 line, after Ip6CancelPacket returns, the Item has been freed.
1559 @param[in] Map The IP6 child's transmit queue.
1560 @param[in] Item The current transmitted packet to test.
1561 @param[in] Context The user's token to cancel.
1563 @retval EFI_SUCCESS Continue to check the next Item.
1564 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1571 IN NET_MAP_ITEM
*Item
,
1575 EFI_IP6_COMPLETION_TOKEN
*Token
;
1576 IP6_TXTOKEN_WRAP
*Wrap
;
1578 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1581 // Return EFI_SUCCESS to check the next item in the map if
1582 // this one doesn't match.
1584 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1588 Wrap
= (IP6_TXTOKEN_WRAP
*) Item
->Value
;
1589 ASSERT (Wrap
!= NULL
);
1592 // Don't access the Item, Wrap and Token's members after this point.
1593 // Item and wrap has been freed. And we no longer own the Token.
1595 Ip6CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1598 // If only one item is to be cancel, return EFI_ABORTED to stop
1599 // iterating the map any more.
1601 if (Token
!= NULL
) {
1610 Cancel the receive request. This is simple, because
1611 it is only enqueued in our local receive map.
1613 @param[in] Map The IP6 child's receive queue.
1614 @param[in] Item Current receive request to cancel.
1615 @param[in] Context The user's token to cancel.
1618 @retval EFI_SUCCESS Continue to check the next receive request on the
1620 @retval EFI_ABORTED The user's token (token != NULL) has been
1628 IN NET_MAP_ITEM
*Item
,
1632 EFI_IP6_COMPLETION_TOKEN
*Token
;
1633 EFI_IP6_COMPLETION_TOKEN
*This
;
1635 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1638 if ((Token
!= NULL
) && (Token
!= This
)) {
1642 NetMapRemoveItem (Map
, Item
, NULL
);
1644 This
->Status
= EFI_ABORTED
;
1645 This
->Packet
.RxData
= NULL
;
1646 gBS
->SignalEvent (This
->Event
);
1648 if (Token
!= NULL
) {
1656 Cancel the user's receive/transmit request. It is the worker function of
1659 @param[in] IpInstance The IP6 child.
1660 @param[in] Token The token to cancel. If NULL, all token will be
1663 @retval EFI_SUCCESS The token is cancelled.
1664 @retval EFI_NOT_FOUND The token isn't found on either the
1665 transmit/receive queue.
1666 @retval EFI_DEVICE_ERROR Not all tokens are cancelled when Token is NULL.
1671 IN IP6_PROTOCOL
*IpInstance
,
1672 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1678 // First check the transmitted packet. Ip6CancelTxTokens returns
1679 // EFI_ABORTED to mean that the token has been cancelled when
1680 // token != NULL. So, return EFI_SUCCESS for this condition.
1682 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip6CancelTxTokens
, Token
);
1683 if (EFI_ERROR (Status
)) {
1684 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1692 // Check the receive queue. Ip6CancelRxTokens also returns EFI_ABORT
1693 // for Token!=NULL and it is cancelled.
1695 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6CancelRxTokens
, Token
);
1697 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
1701 if (EFI_ERROR (Status
)) {
1702 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1710 // OK, if the Token is found when Token != NULL, the NetMapIterate
1711 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
1713 if (Token
!= NULL
) {
1714 return EFI_NOT_FOUND
;
1718 // If Token == NULL, cancel all the tokens. return error if not
1719 // all of them are cancelled.
1721 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) || !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
1723 return EFI_DEVICE_ERROR
;
1730 Abort an asynchronous transmit or receive request.
1732 The Cancel() function is used to abort a pending transmit or receive request.
1733 If the token is in the transmit or receive request queues, after calling this
1734 function, Token->Status will be set to EFI_ABORTED, and then Token->Event will
1735 be signaled. If the token is not in one of the queues, which usually means the
1736 asynchronous operation has completed, this function will not signal the token,
1737 and EFI_NOT_FOUND is returned.
1739 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1740 @param[in] Token Pointer to a token that has been issued by
1741 EFI_IP6_PROTOCOL.Transmit() or
1742 EFI_IP6_PROTOCOL.Receive(). If NULL, all pending
1743 tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is
1744 defined in EFI_IP6_PROTOCOL.Transmit().
1746 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
1747 Token->Event was signaled. When Token is NULL, all
1748 pending requests were aborted, and their events were signaled.
1749 @retval EFI_INVALID_PARAMETER This is NULL.
1750 @retval EFI_NOT_STARTED This instance has not been started.
1751 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
1752 not found in the transmit or receive queue. It has either completed
1753 or was not issued by Transmit() and Receive().
1754 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1760 IN EFI_IP6_PROTOCOL
*This
,
1761 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1764 IP6_PROTOCOL
*IpInstance
;
1769 return EFI_INVALID_PARAMETER
;
1772 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1774 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1776 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1777 Status
= EFI_NOT_STARTED
;
1781 Status
= Ip6Cancel (IpInstance
, Token
);
1784 gBS
->RestoreTPL (OldTpl
);
1789 Polls for incoming data packets, and processes outgoing data packets.
1791 The Poll() function polls for incoming data packets and processes outgoing data
1792 packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()
1793 function to increase the rate that data packets are moved between the communications
1794 device and the transmit and receive queues.
1796 In some systems the periodic timer event may not poll the underlying communications
1797 device fast enough to transmit and/or receive all data packets without missing
1798 incoming packets or dropping outgoing packets. Drivers and applications that are
1799 experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function
1802 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1804 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1805 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1806 @retval EFI_INVALID_PARAMETER This is NULL.
1807 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1808 @retval EFI_NOT_READY No incoming or outgoing data was processed.
1809 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
1810 Consider increasing the polling rate.
1816 IN EFI_IP6_PROTOCOL
*This
1819 IP6_PROTOCOL
*IpInstance
;
1821 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
1824 return EFI_INVALID_PARAMETER
;
1827 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1828 IpSb
= IpInstance
->Service
;
1830 if (IpSb
->LinkLocalDadFail
) {
1831 return EFI_DEVICE_ERROR
;
1834 if (IpInstance
->State
== IP6_STATE_UNCONFIGED
) {
1835 return EFI_NOT_STARTED
;
1838 Mnp
= IpInstance
->Service
->Mnp
;
1841 // Don't lock the Poll function to enable the deliver of
1842 // the packet polled up.
1844 return Mnp
->Poll (Mnp
);