2 Implementation of EFI_IP6_PROTOCOL protocol interfaces.
4 Copyright (c) 2009 - 2010, 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
) {
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 DESTORY, 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 // Update the variable data.
711 Ip6SetVariableData (IpInstance
->Service
);
714 gBS
->RestoreTPL (OldTpl
);
719 Joins and leaves multicast groups.
721 The Groups() function is used to join and leave multicast group sessions. Joining a group will
722 enable reception of matching multicast packets. Leaving a group will disable reception of matching
723 multicast packets. Source-Specific Multicast isn't required to be supported.
725 If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
727 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
728 @param[in] JoinFlag Set to TRUE to join the multicast group session, and FALSE to leave.
729 @param[in] GroupAddress Pointer to the IPv6 multicast address.
730 This is an optional parameter that may be NULL.
732 @retval EFI_SUCCESS The operation completed successfully.
733 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
735 - JoinFlag is TRUE and GroupAddress is NULL.
736 - GroupAddress is not NULL and *GroupAddress is
737 not a multicast IPv6 address.
738 - GroupAddress is not NULL and *GroupAddress is in the
739 range of SSM destination address.
740 @retval EFI_NOT_STARTED This instance has not been started.
741 @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.
742 @retval EFI_UNSUPPORTED This EFI IPv6 Protocol implementation does not support multicast groups.
743 @retval EFI_ALREADY_STARTED The group address is already in the group table (when
745 @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).
746 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
752 IN EFI_IP6_PROTOCOL
*This
,
754 IN EFI_IPv6_ADDRESS
*GroupAddress OPTIONAL
759 IP6_PROTOCOL
*IpInstance
;
762 if ((This
== NULL
) || (JoinFlag
&& GroupAddress
== NULL
)) {
763 return EFI_INVALID_PARAMETER
;
766 if (GroupAddress
!= NULL
&& !IP6_IS_MULTICAST (GroupAddress
)) {
767 return EFI_INVALID_PARAMETER
;
770 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
771 IpSb
= IpInstance
->Service
;
773 if (IpSb
->LinkLocalDadFail
) {
774 return EFI_DEVICE_ERROR
;
777 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
779 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
780 Status
= EFI_NOT_STARTED
;
784 Status
= Ip6Groups (IpInstance
, JoinFlag
, GroupAddress
);
787 gBS
->RestoreTPL (OldTpl
);
792 Adds and deletes routing table entries.
794 The Routes() function adds a route to, or deletes a route from, the routing table.
796 Routes are determined by comparing the leftmost PrefixLength bits of Destination with
797 the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the
798 configured station address.
800 The default route is added with Destination and PrefixLegth both set to all zeros. The
801 default route matches all destination IPv6 addresses that do not match any other routes.
803 All EFI IPv6 Protocol instances share a routing table.
805 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
806 @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to
807 FALSE to add this route to the routing table. Destination,
808 PrefixLength and Gateway are used as the key to each
810 @param[in] Destination The address prefix of the subnet that needs to be routed.
811 This is an optional parameter that may be NULL.
812 @param[in] PrefixLength The prefix length of Destination. Ignored if Destination
814 @param[in] GatewayAddress The unicast gateway IPv6 address for this route.
815 This is an optional parameter that may be NULL.
817 @retval EFI_SUCCESS The operation completed successfully.
818 @retval EFI_NOT_STARTED The driver instance has not been started.
819 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
821 - When DeleteRoute is TRUE, both Destination and
822 GatewayAddress are NULL.
823 - When DeleteRoute is FALSE, either Destination or
824 GatewayAddress is NULL.
825 - *GatewayAddress is not a valid unicast IPv6 address.
826 - *GatewayAddress is one of the local configured IPv6
828 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
829 @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).
830 @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when
831 DeleteRoute is FALSE).
837 IN EFI_IP6_PROTOCOL
*This
,
838 IN BOOLEAN DeleteRoute
,
839 IN EFI_IPv6_ADDRESS
*Destination OPTIONAL
,
840 IN UINT8 PrefixLength
,
841 IN EFI_IPv6_ADDRESS
*GatewayAddress OPTIONAL
844 IP6_PROTOCOL
*IpInstance
;
849 if ((This
== NULL
) || (PrefixLength
>= IP6_PREFIX_NUM
)) {
850 return EFI_INVALID_PARAMETER
;
853 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
854 IpSb
= IpInstance
->Service
;
856 if (IpSb
->LinkLocalDadFail
) {
857 return EFI_DEVICE_ERROR
;
860 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
861 return EFI_NOT_STARTED
;
864 if (DeleteRoute
&& (Destination
== NULL
) && (GatewayAddress
== NULL
)) {
865 return EFI_INVALID_PARAMETER
;
868 if (!DeleteRoute
&& (Destination
== NULL
|| GatewayAddress
== NULL
)) {
869 return EFI_INVALID_PARAMETER
;
872 if (GatewayAddress
!= NULL
) {
873 if (!Ip6IsValidAddress (IpSb
, GatewayAddress
, FALSE
)) {
874 return EFI_INVALID_PARAMETER
;
877 if (!NetIp6IsUnspecifiedAddr (GatewayAddress
) &&
878 !NetIp6IsNetEqual (GatewayAddress
, &IpInstance
->ConfigData
.StationAddress
, PrefixLength
)
880 return EFI_INVALID_PARAMETER
;
884 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
887 // Update the route table
890 Status
= Ip6DelRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
892 Status
= Ip6AddRoute (IpSb
->RouteTable
, Destination
, PrefixLength
, GatewayAddress
);
895 gBS
->RestoreTPL (OldTpl
);
900 Add or delete Neighbor cache entries.
902 The Neighbors() function is used to add, update, or delete an entry from neighbor cache.
903 IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as
904 network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network
905 traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not
906 timeout) or dynamic (will timeout).
908 The implementation should follow the neighbor cache timeout mechanism which is defined in
909 RFC4861. The default neighbor cache timeout value should be tuned for the expected network
912 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
913 @param[in] DeleteFlag Set to TRUE to delete the specified cache entry, set to FALSE to
914 add (or update, if it already exists and Override is TRUE) the
915 specified cache entry. TargetIp6Address is used as the key
916 to find the requested cache entry.
917 @param[in] TargetIp6Address Pointer to the Target IPv6 address.
918 @param[in] TargetLinkAddress Pointer to the link-layer address of the target. Ignored if NULL.
919 @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
920 cache, it will be deleted after Timeout. A value of zero means that
921 the entry is permanent. A non-zero value means that the entry is
923 @param[in] Override If TRUE, the cached link-layer address of the matching entry will
924 be overridden and updated; if FALSE, EFI_ACCESS_DENIED
925 will be returned if a corresponding cache entry already existed.
927 @retval EFI_SUCCESS The data has been queued for transmission.
928 @retval EFI_NOT_STARTED This instance has not been started.
929 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
931 - TargetIpAddress is NULL.
932 - *TargetLinkAddress is invalid when not NULL.
933 - *TargetIpAddress is not a valid unicast IPv6 address.
934 - *TargetIpAddress is one of the local configured IPv6
936 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache.
937 @retval EFI_NOT_FOUND This entry is not in the neighbor cache (when DeleteFlag is
938 TRUE or when DeleteFlag is FALSE while
939 TargetLinkAddress is NULL.).
940 @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
941 and that entry is tagged as un-overridden (when Override
948 IN EFI_IP6_PROTOCOL
*This
,
949 IN BOOLEAN DeleteFlag
,
950 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
951 IN EFI_MAC_ADDRESS
*TargetLinkAddress OPTIONAL
,
958 IP6_PROTOCOL
*IpInstance
;
961 if (This
== NULL
|| TargetIp6Address
== NULL
) {
962 return EFI_INVALID_PARAMETER
;
965 if (NetIp6IsUnspecifiedAddr (TargetIp6Address
)) {
966 return EFI_INVALID_PARAMETER
;
969 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
970 IpSb
= IpInstance
->Service
;
972 if (IpSb
->LinkLocalDadFail
) {
973 return EFI_DEVICE_ERROR
;
976 if (!Ip6IsValidAddress (IpSb
, TargetIp6Address
, FALSE
)) {
977 return EFI_INVALID_PARAMETER
;
980 if (TargetLinkAddress
!= NULL
) {
981 if (!Ip6IsValidLinkAddress (IpSb
, TargetLinkAddress
)) {
982 return EFI_INVALID_PARAMETER
;
986 if (Ip6IsOneOfSetAddress (IpSb
, TargetIp6Address
, NULL
, NULL
)) {
987 return EFI_INVALID_PARAMETER
;
990 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
991 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
992 Status
= EFI_NOT_STARTED
;
997 Status
= Ip6DelNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
999 Status
= Ip6AddNeighbor (IpInstance
->Service
, TargetIp6Address
, TargetLinkAddress
, Timeout
, Override
);
1003 gBS
->RestoreTPL (OldTpl
);
1008 Check whether the user's token or event has already
1009 been enqueue on IP6's list.
1011 @param[in] Map The container of either user's transmit or receive
1013 @param[in] Item Current item to check against.
1014 @param[in] Context The Token to check againist.
1016 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
1017 @retval EFI_SUCCESS The current item isn't the same token/event as the
1025 IN NET_MAP_ITEM
*Item
,
1029 EFI_IP6_COMPLETION_TOKEN
*Token
;
1030 EFI_IP6_COMPLETION_TOKEN
*TokenInItem
;
1032 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1033 TokenInItem
= (EFI_IP6_COMPLETION_TOKEN
*) Item
->Key
;
1035 if (Token
== TokenInItem
|| Token
->Event
== TokenInItem
->Event
) {
1036 return EFI_ACCESS_DENIED
;
1043 Validate the user's token against the current station address.
1045 @param[in] Token User's token to validate.
1047 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
1048 @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.
1049 @retval EFI_SUCCESS The token is OK.
1054 IN EFI_IP6_COMPLETION_TOKEN
*Token
1057 EFI_IP6_TRANSMIT_DATA
*TxData
;
1061 if (Token
== NULL
|| Token
->Event
== NULL
) {
1062 return EFI_INVALID_PARAMETER
;
1065 TxData
= Token
->Packet
.TxData
;
1067 if (TxData
== NULL
|| (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
== NULL
)) {
1068 return EFI_INVALID_PARAMETER
;
1071 if (TxData
->FragmentCount
== 0 || TxData
->DataLength
== 0) {
1072 return EFI_INVALID_PARAMETER
;
1075 for (DataLength
= 0, Index
= 0; Index
< TxData
->FragmentCount
; Index
++) {
1076 if (TxData
->FragmentTable
[Index
].FragmentLength
== 0 || TxData
->FragmentTable
[Index
].FragmentBuffer
== NULL
) {
1077 return EFI_INVALID_PARAMETER
;
1080 DataLength
+= TxData
->FragmentTable
[Index
].FragmentLength
;
1083 if (TxData
->DataLength
!= DataLength
) {
1084 return EFI_INVALID_PARAMETER
;
1088 // TODO: Token.Packet.TxData.DataLength is too short to transmit.
1089 // return EFI_BUFFER_TOO_SMALL;
1093 // If Token.Packet.TxData.DataLength is beyond the maximum that which can be
1094 // described through the Fragment Offset field in Fragment header when performing
1097 if (TxData
->DataLength
> 64 * 1024) {
1098 return EFI_BAD_BUFFER_SIZE
;
1105 The callback function for the net buffer which wraps the user's
1106 transmit token. Although this function seems simple, there
1107 are some subtle aspects.
1108 When user requests the IP to transmit a packet by passing it a
1109 token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data
1110 is wrapped in an net buffer. The net buffer's Free function is
1111 set to Ip6FreeTxToken. The Token and token wrap are added to the
1112 IP child's TxToken map. Then the buffer is passed to Ip6Output for
1113 transmission. If an error happened before that, the buffer
1114 is freed, which in turn frees the token wrap. The wrap may
1115 have been added to the TxToken map or not, and the user's event
1116 shouldn't be fired because we are still in the EfiIp6Transmit. If
1117 the buffer has been sent by Ip6Output, it should be removed from
1118 the TxToken map and user's event signaled. The token wrap and buffer
1119 are bound together. Check the comments in Ip6Output for information
1120 about IP fragmentation.
1122 @param[in] Context The token's wrap.
1131 IP6_TXTOKEN_WRAP
*Wrap
;
1134 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1137 // Signal IpSecRecycleEvent to inform IPsec free the memory
1139 if (Wrap
->IpSecRecycleSignal
!= NULL
) {
1140 gBS
->SignalEvent (Wrap
->IpSecRecycleSignal
);
1144 // Find the token in the instance's map. EfiIp6Transmit put the
1145 // token to the map. If that failed, NetMapFindKey will return NULL.
1147 Item
= NetMapFindKey (&Wrap
->IpInstance
->TxTokens
, Wrap
->Token
);
1150 NetMapRemoveItem (&Wrap
->IpInstance
->TxTokens
, Item
, NULL
);
1154 gBS
->SignalEvent (Wrap
->Token
->Event
);
1157 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
1167 The callback function to Ip6Output to update the transmit status.
1169 @param[in] Packet The user's transmit packet.
1170 @param[in] IoStatus The result of the transmission.
1171 @param[in] Flag Not used during transmission.
1172 @param[in] Context The token's wrap.
1178 IN EFI_STATUS IoStatus
,
1183 IP6_TXTOKEN_WRAP
*Wrap
;
1186 // This is the transmission request from upper layer,
1187 // not the IP6 driver itself.
1189 Wrap
= (IP6_TXTOKEN_WRAP
*) Context
;
1190 Wrap
->Token
->Status
= IoStatus
;
1192 NetbufFree (Wrap
->Packet
);
1196 Places outgoing data packets into the transmit queue.
1198 The Transmit() function places a sending request in the transmit queue of this
1199 EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some
1200 errors occur, the event in the token will be signaled, and the status is updated.
1202 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1203 @param[in] Token Pointer to the transmit token.
1205 @retval EFI_SUCCESS The data has been queued for transmission.
1206 @retval EFI_NOT_STARTED This instance has not been started.
1207 @retval EFI_NO_MAPPING The IPv6 driver was responsible for choosing
1208 a source address for this transmission,
1209 but no source address was available for use.
1210 @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:
1213 - Token.Event is NULL.
1214 - Token.Packet.TxData is NULL.
1215 - Token.Packet.ExtHdrsLength is not zero and
1216 Token.Packet.ExtHdrs is NULL.
1217 - Token.Packet.FragmentCount is zero.
1218 - One or more of the Token.Packet.TxData.
1219 FragmentTable[].FragmentLength fields is zero.
1220 - One or more of the Token.Packet.TxData.
1221 FragmentTable[].FragmentBuffer fields is NULL.
1222 - Token.Packet.TxData.DataLength is zero or not
1223 equal to the sum of fragment lengths.
1224 - Token.Packet.TxData.DestinationAddress is non
1225 zero when DestinationAddress is configured as
1226 non-zero when doing Configure() for this
1227 EFI IPv6 protocol instance.
1228 - Token.Packet.TxData.DestinationAddress is
1229 unspecified when DestinationAddress is unspecified
1230 when doing Configure() for this EFI IPv6 protocol
1232 @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.
1233 Event was already in the transmit queue.
1234 @retval EFI_NOT_READY The completion token could not be queued because
1235 the transmit queue is full.
1236 @retval EFI_NOT_FOUND Not route is found to destination address.
1237 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
1238 @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too
1240 @retval EFI_BAD_BUFFER_SIZE If Token.Packet.TxData.DataLength is beyond the
1241 maximum that which can be described through the
1242 Fragment Offset field in Fragment header when
1243 performing fragmentation.
1244 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1250 IN EFI_IP6_PROTOCOL
*This
,
1251 IN EFI_IP6_COMPLETION_TOKEN
*Token
1255 IP6_PROTOCOL
*IpInstance
;
1256 EFI_IP6_CONFIG_DATA
*Config
;
1259 EFI_IP6_HEADER Head
;
1260 EFI_IP6_TRANSMIT_DATA
*TxData
;
1261 EFI_IP6_OVERRIDE_DATA
*Override
;
1262 IP6_TXTOKEN_WRAP
*Wrap
;
1266 // Check input parameters.
1269 return EFI_INVALID_PARAMETER
;
1274 Status
= Ip6TxTokenValid (Token
);
1275 if (EFI_ERROR (Status
)) {
1279 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1280 IpSb
= IpInstance
->Service
;
1282 if (IpSb
->LinkLocalDadFail
) {
1283 return EFI_DEVICE_ERROR
;
1286 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1288 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1289 Status
= EFI_NOT_STARTED
;
1293 Config
= &IpInstance
->ConfigData
;
1296 // Check whether the token or signal already existed.
1298 if (EFI_ERROR (NetMapIterate (&IpInstance
->TxTokens
, Ip6TokenExist
, Token
))) {
1299 Status
= EFI_ACCESS_DENIED
;
1304 // Build the IP header, fill in the information from ConfigData or OverrideData
1306 ZeroMem (&Head
, sizeof(EFI_IP6_HEADER
));
1307 TxData
= Token
->Packet
.TxData
;
1308 IP6_COPY_ADDRESS (&Head
.SourceAddress
, &Config
->StationAddress
);
1309 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &Config
->DestinationAddress
);
1311 Status
= EFI_INVALID_PARAMETER
;
1313 if (NetIp6IsUnspecifiedAddr (&TxData
->DestinationAddress
)) {
1314 if (NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1318 ASSERT (!NetIp6IsUnspecifiedAddr (&Config
->StationAddress
));
1322 // StationAddress is unspecified only when ConfigData.Dest is unspecified.
1323 // Use TxData.Dest to override the DestinationAddress.
1325 if (!NetIp6IsUnspecifiedAddr (&Config
->DestinationAddress
)) {
1329 if (NetIp6IsUnspecifiedAddr (&Config
->StationAddress
)) {
1330 Status
= Ip6SelectSourceAddress (
1332 &TxData
->DestinationAddress
,
1335 if (EFI_ERROR (Status
)) {
1340 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, &TxData
->DestinationAddress
);
1344 // Fill in Head infos.
1346 Head
.NextHeader
= Config
->DefaultProtocol
;
1347 if (TxData
->ExtHdrsLength
!= 0) {
1348 Head
.NextHeader
= TxData
->NextHeader
;
1351 if (TxData
->OverrideData
!= NULL
) {
1352 Override
= TxData
->OverrideData
;
1353 Head
.NextHeader
= Override
->Protocol
;
1354 Head
.HopLimit
= Override
->HopLimit
;
1355 Head
.FlowLabelL
= HTONS ((UINT16
) Override
->FlowLabel
);
1356 Head
.FlowLabelH
= (UINT8
) ((Override
->FlowLabel
>> 16) & 0x0F);
1358 Head
.HopLimit
= Config
->HopLimit
;
1359 Head
.FlowLabelL
= HTONS ((UINT16
) Config
->FlowLabel
);
1360 Head
.FlowLabelH
= (UINT8
) ((Config
->FlowLabel
>> 16) & 0x0F);
1363 Head
.PayloadLength
= HTONS ((UINT16
) (TxData
->ExtHdrsLength
+ TxData
->DataLength
));
1366 // OK, it survives all the validation check. Wrap the token in
1367 // a IP6_TXTOKEN_WRAP and the data in a netbuf
1369 Status
= EFI_OUT_OF_RESOURCES
;
1370 Wrap
= AllocateZeroPool (sizeof (IP6_TXTOKEN_WRAP
));
1375 Wrap
->IpInstance
= IpInstance
;
1376 Wrap
->Token
= Token
;
1378 Wrap
->Life
= IP6_US_TO_SEC (Config
->TransmitTimeout
);
1379 Wrap
->Packet
= NetbufFromExt (
1380 (NET_FRAGMENT
*) TxData
->FragmentTable
,
1381 TxData
->FragmentCount
,
1388 if (Wrap
->Packet
== NULL
) {
1393 Token
->Status
= EFI_NOT_READY
;
1395 Status
= NetMapInsertTail (&IpInstance
->TxTokens
, Token
, Wrap
);
1396 if (EFI_ERROR (Status
)) {
1398 // NetbufFree will call Ip6FreeTxToken, which in turn will
1399 // free the IP6_TXTOKEN_WRAP. Now, the token wrap hasn't been
1402 NetbufFree (Wrap
->Packet
);
1407 // Allocate a new buffer to store IPv6 extension headers to avoid updating
1408 // the original data in EFI_IP6_COMPLETION_TOKEN.
1410 if (TxData
->ExtHdrsLength
!= 0 && TxData
->ExtHdrs
!= NULL
) {
1411 ExtHdrs
= (UINT8
*) AllocateCopyPool (TxData
->ExtHdrsLength
, TxData
->ExtHdrs
);
1412 if (ExtHdrs
== NULL
) {
1413 Status
= EFI_OUT_OF_RESOURCES
;
1419 // Mark the packet sent before output it. Mark it not sent again if the
1420 // returned status is not EFI_SUCCESS;
1424 Status
= Ip6Output (
1431 TxData
->ExtHdrsLength
,
1435 if (EFI_ERROR (Status
)) {
1437 NetbufFree (Wrap
->Packet
);
1441 gBS
->RestoreTPL (OldTpl
);
1443 if (ExtHdrs
!= NULL
) {
1451 Places a receiving request into the receiving queue.
1453 The Receive() function places a completion token into the receive packet queue.
1454 This function is always asynchronous.
1456 The Token.Event field in the completion token must be filled in by the caller
1457 and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol
1458 driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
1461 Current Udp implementation creates an IP child for each Udp child.
1462 It initates a asynchronous receive immediately no matter whether
1463 there is no mapping or not. Therefore, disable the returning EFI_NO_MAPPING for now.
1464 To enable it, the following check must be performed:
1466 if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
1467 Status = EFI_NO_MAPPING;
1471 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1472 @param[in] Token Pointer to a token that is associated with the receive data descriptor.
1474 @retval EFI_SUCCESS The receive completion token was cached.
1475 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1476 @retval EFI_NO_MAPPING When IP6 driver responsible for binding source address to this instance,
1477 while no source address is available for use.
1478 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1481 - Token.Event is NULL.
1482 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
1483 resources (usually memory).
1484 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1485 The EFI IPv6 Protocol instance has been reset to startup defaults.
1486 @retval EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already
1487 in the receive queue.
1488 @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
1494 IN EFI_IP6_PROTOCOL
*This
,
1495 IN EFI_IP6_COMPLETION_TOKEN
*Token
1498 IP6_PROTOCOL
*IpInstance
;
1503 if (This
== NULL
|| Token
== NULL
|| Token
->Event
== NULL
) {
1504 return EFI_INVALID_PARAMETER
;
1507 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1508 IpSb
= IpInstance
->Service
;
1510 if (IpSb
->LinkLocalDadFail
) {
1511 return EFI_DEVICE_ERROR
;
1514 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1516 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1517 Status
= EFI_NOT_STARTED
;
1522 // Check whether the toke is already on the receive queue.
1524 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6TokenExist
, Token
);
1526 if (EFI_ERROR (Status
)) {
1527 Status
= EFI_ACCESS_DENIED
;
1532 // Queue the token then check whether there is pending received packet.
1534 Status
= NetMapInsertTail (&IpInstance
->RxTokens
, Token
, NULL
);
1536 if (EFI_ERROR (Status
)) {
1540 Status
= Ip6InstanceDeliverPacket (IpInstance
);
1543 // Dispatch the DPC queued by the NotifyFunction of this instane's receive
1549 gBS
->RestoreTPL (OldTpl
);
1555 Cancel the transmitted but not recycled packet. If a matching
1556 token is found, it will call Ip6CancelPacket to cancel the
1557 packet. Ip6CancelPacket cancels all the fragments of the
1558 packet. When all the fragments are freed, the IP6_TXTOKEN_WRAP
1559 is deleted from the Map, and user's event is signalled.
1560 Because Ip6CancelPacket and other functions are all called in
1561 line, after Ip6CancelPacket returns, the Item has been freed.
1563 @param[in] Map The IP6 child's transmit queue.
1564 @param[in] Item The current transmitted packet to test.
1565 @param[in] Context The user's token to cancel.
1567 @retval EFI_SUCCESS Continue to check the next Item.
1568 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
1575 IN NET_MAP_ITEM
*Item
,
1579 EFI_IP6_COMPLETION_TOKEN
*Token
;
1580 IP6_TXTOKEN_WRAP
*Wrap
;
1582 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1585 // Return EFI_SUCCESS to check the next item in the map if
1586 // this one doesn't match.
1588 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
1592 Wrap
= (IP6_TXTOKEN_WRAP
*) Item
->Value
;
1593 ASSERT (Wrap
!= NULL
);
1596 // Don't access the Item, Wrap and Token's members after this point.
1597 // Item and wrap has been freed. And we no longer own the Token.
1599 Ip6CancelPacket (Wrap
->IpInstance
->Interface
, Wrap
->Packet
, EFI_ABORTED
);
1602 // If only one item is to be cancel, return EFI_ABORTED to stop
1603 // iterating the map any more.
1605 if (Token
!= NULL
) {
1614 Cancel the receive request. This is simple, because
1615 it is only enqueued in our local receive map.
1617 @param[in] Map The IP6 child's receive queue.
1618 @param[in] Item Current receive request to cancel.
1619 @param[in] Context The user's token to cancel.
1622 @retval EFI_SUCCESS Continue to check the next receive request on the
1624 @retval EFI_ABORTED The user's token (token != NULL) has been
1632 IN NET_MAP_ITEM
*Item
,
1636 EFI_IP6_COMPLETION_TOKEN
*Token
;
1637 EFI_IP6_COMPLETION_TOKEN
*This
;
1639 Token
= (EFI_IP6_COMPLETION_TOKEN
*) Context
;
1642 if ((Token
!= NULL
) && (Token
!= This
)) {
1646 NetMapRemoveItem (Map
, Item
, NULL
);
1648 This
->Status
= EFI_ABORTED
;
1649 This
->Packet
.RxData
= NULL
;
1650 gBS
->SignalEvent (This
->Event
);
1652 if (Token
!= NULL
) {
1660 Cancel the user's receive/transmit request. It is the worker function of
1663 @param[in] IpInstance The IP6 child.
1664 @param[in] Token The token to cancel. If NULL, all token will be
1667 @retval EFI_SUCCESS The token is cancelled.
1668 @retval EFI_NOT_FOUND The token isn't found on either the
1669 transmit/receive queue.
1670 @retval EFI_DEVICE_ERROR Not all tokens are cancelled when Token is NULL.
1675 IN IP6_PROTOCOL
*IpInstance
,
1676 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1682 // First check the transmitted packet. Ip6CancelTxTokens returns
1683 // EFI_ABORTED to mean that the token has been cancelled when
1684 // token != NULL. So, return EFI_SUCCESS for this condition.
1686 Status
= NetMapIterate (&IpInstance
->TxTokens
, Ip6CancelTxTokens
, Token
);
1687 if (EFI_ERROR (Status
)) {
1688 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1696 // Check the receive queue. Ip6CancelRxTokens also returns EFI_ABORT
1697 // for Token!=NULL and it is cancelled.
1699 Status
= NetMapIterate (&IpInstance
->RxTokens
, Ip6CancelRxTokens
, Token
);
1701 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
1705 if (EFI_ERROR (Status
)) {
1706 if ((Token
!= NULL
) && (Status
== EFI_ABORTED
)) {
1714 // OK, if the Token is found when Token != NULL, the NetMapIterate
1715 // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.
1717 if (Token
!= NULL
) {
1718 return EFI_NOT_FOUND
;
1722 // If Token == NULL, cancel all the tokens. return error if not
1723 // all of them are cancelled.
1725 if (!NetMapIsEmpty (&IpInstance
->TxTokens
) || !NetMapIsEmpty (&IpInstance
->RxTokens
)) {
1727 return EFI_DEVICE_ERROR
;
1734 Abort an asynchronous transmit or receive request.
1736 The Cancel() function is used to abort a pending transmit or receive request.
1737 If the token is in the transmit or receive request queues, after calling this
1738 function, Token->Status will be set to EFI_ABORTED, and then Token->Event will
1739 be signaled. If the token is not in one of the queues, which usually means the
1740 asynchronous operation has completed, this function will not signal the token,
1741 and EFI_NOT_FOUND is returned.
1743 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1744 @param[in] Token Pointer to a token that has been issued by
1745 EFI_IP6_PROTOCOL.Transmit() or
1746 EFI_IP6_PROTOCOL.Receive(). If NULL, all pending
1747 tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is
1748 defined in EFI_IP6_PROTOCOL.Transmit().
1750 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
1751 Token->Event was signaled. When Token is NULL, all
1752 pending requests were aborted, and their events were signaled.
1753 @retval EFI_INVALID_PARAMETER This is NULL.
1754 @retval EFI_NOT_STARTED This instance has not been started.
1755 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
1756 not found in the transmit or receive queue. It has either completed
1757 or was not issued by Transmit() and Receive().
1758 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1764 IN EFI_IP6_PROTOCOL
*This
,
1765 IN EFI_IP6_COMPLETION_TOKEN
*Token OPTIONAL
1768 IP6_PROTOCOL
*IpInstance
;
1774 return EFI_INVALID_PARAMETER
;
1777 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1778 IpSb
= IpInstance
->Service
;
1780 if (IpSb
->LinkLocalDadFail
) {
1781 return EFI_DEVICE_ERROR
;
1784 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1786 if (IpInstance
->State
!= IP6_STATE_CONFIGED
) {
1787 Status
= EFI_NOT_STARTED
;
1791 Status
= Ip6Cancel (IpInstance
, Token
);
1794 gBS
->RestoreTPL (OldTpl
);
1799 Polls for incoming data packets, and processes outgoing data packets.
1801 The Poll() function polls for incoming data packets and processes outgoing data
1802 packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()
1803 function to increase the rate that data packets are moved between the communications
1804 device and the transmit and receive queues.
1806 In some systems the periodic timer event may not poll the underlying communications
1807 device fast enough to transmit and/or receive all data packets without missing
1808 incoming packets or dropping outgoing packets. Drivers and applications that are
1809 experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function
1812 @param[in] This Pointer to the EFI_IP6_PROTOCOL instance.
1814 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1815 @retval EFI_NOT_STARTED This EFI IPv6 Protocol instance has not been started.
1816 @retval EFI_INVALID_PARAMETER This is NULL.
1817 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1818 @retval EFI_NOT_READY No incoming or outgoing data was processed.
1819 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
1820 Consider increasing the polling rate.
1826 IN EFI_IP6_PROTOCOL
*This
1829 IP6_PROTOCOL
*IpInstance
;
1831 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
1834 return EFI_INVALID_PARAMETER
;
1837 IpInstance
= IP6_INSTANCE_FROM_PROTOCOL (This
);
1838 IpSb
= IpInstance
->Service
;
1840 if (IpSb
->LinkLocalDadFail
) {
1841 return EFI_DEVICE_ERROR
;
1844 if (IpInstance
->State
== IP6_STATE_UNCONFIGED
) {
1845 return EFI_NOT_STARTED
;
1848 Mnp
= IpInstance
->Service
->Mnp
;
1851 // Don't lock the Poll function to enable the deliver of
1852 // the packet polled up.
1854 return Mnp
->Poll (Mnp
);