1 /** @file
2   Implementation of EFI_IP6_PROTOCOL protocol interfaces and type definitions.
3 
4   Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
5   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
6 
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.
11 
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.
14 
15 **/
16 
17 #ifndef __EFI_IP6_IMPL_H__
18 #define __EFI_IP6_IMPL_H__
19 
20 #include <Uefi.h>
21 
22 #include <IndustryStandard/Dhcp.h>
23 
24 #include <Protocol/ServiceBinding.h>
25 #include <Protocol/ManagedNetwork.h>
26 #include <Protocol/IpSec.h>
27 #include <Protocol/Ip6.h>
28 #include <Protocol/Ip6Config.h>
29 #include <Protocol/Dhcp6.h>
30 #include <Protocol/DevicePath.h>
31 #include <Protocol/HiiConfigRouting.h>
32 #include <Protocol/HiiConfigAccess.h>
33 
34 #include <Library/DebugLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/UefiRuntimeServicesTableLib.h>
37 #include <Library/BaseLib.h>
38 #include <Library/UefiLib.h>
39 #include <Library/NetLib.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/DpcLib.h>
43 #include <Library/HiiLib.h>
44 #include <Library/UefiHiiServicesLib.h>
45 #include <Library/DevicePathLib.h>
46 #include <Library/PrintLib.h>
47 
48 #include <Guid/MdeModuleHii.h>
49 
50 #include "Ip6Common.h"
51 #include "Ip6Driver.h"
52 #include "Ip6Icmp.h"
53 #include "Ip6If.h"
54 #include "Ip6Input.h"
55 #include "Ip6Mld.h"
56 #include "Ip6Nd.h"
57 #include "Ip6Option.h"
58 #include "Ip6Output.h"
59 #include "Ip6Route.h"
60 #include "Ip6ConfigNv.h"
61 #include "Ip6ConfigImpl.h"
62 
63 #define IP6_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '6', 'P')
64 #define IP6_SERVICE_SIGNATURE  SIGNATURE_32 ('I', 'P', '6', 'S')
65 
66 //
67 // The state of IP6 protocol. It starts from UNCONFIGED. if it is
68 // successfully configured, it goes to CONFIGED. if configure NULL
69 // is called, it becomes UNCONFIGED again. If (partly) destroyed, it
70 // becomes DESTROY.
71 //
72 #define IP6_STATE_UNCONFIGED   0
73 #define IP6_STATE_CONFIGED     1
74 
75 //
76 // The state of IP6 service. It starts from UNSTARTED. It transits
77 // to STARTED if autoconfigure is started. If default address is
78 // configured, it becomes CONFIGED. and if partly destroyed, it goes
79 // to DESTROY.
80 //
81 #define IP6_SERVICE_UNSTARTED  0
82 #define IP6_SERVICE_STARTED    1
83 #define IP6_SERVICE_CONFIGED   2
84 #define IP6_SERVICE_DESTROY    3
85 
86 #define IP6_INSTANCE_FROM_PROTOCOL(Ip6) \
87           CR ((Ip6), IP6_PROTOCOL, Ip6Proto, IP6_PROTOCOL_SIGNATURE)
88 
89 #define IP6_SERVICE_FROM_PROTOCOL(Sb)   \
90           CR ((Sb), IP6_SERVICE, ServiceBinding, IP6_SERVICE_SIGNATURE)
91 
92 #define IP6_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)
93 
94 extern EFI_IPSEC2_PROTOCOL *mIpSec;
95 extern BOOLEAN             mIpSec2Installed;
96 
97 //
98 // IP6_TXTOKEN_WRAP wraps the upper layer's transmit token.
99 // The user's data is kept in the Packet. When fragment is
100 // needed, each fragment of the Packet has a reference to the
101 // Packet, no data is actually copied. The Packet will be
102 // released when all the fragments of it have been recycled by
103 // MNP. Upon then, the IP6_TXTOKEN_WRAP will be released, and
104 // user's event signalled.
105 //
106 typedef struct {
107   IP6_PROTOCOL              *IpInstance;
108   EFI_IP6_COMPLETION_TOKEN  *Token;
109   EFI_EVENT                 IpSecRecycleSignal;
110   NET_BUF                   *Packet;
111   BOOLEAN                   Sent;
112   INTN                      Life;
113 } IP6_TXTOKEN_WRAP;
114 
115 typedef struct {
116   EFI_EVENT                 IpSecRecycleSignal;
117   NET_BUF                   *Packet;
118 } IP6_IPSEC_WRAP;
119 
120 //
121 // IP6_RXDATA_WRAP wraps the data IP6 child delivers to the
122 // upper layers. The received packet is kept in the Packet.
123 // The Packet itself may be constructured from some fragments.
124 // All the fragments of the Packet is organized by a
125 // IP6_ASSEMBLE_ENTRY structure. If the Packet is recycled by
126 // the upper layer, the assemble entry and its associated
127 // fragments will be freed at last.
128 //
129 typedef struct {
130   LIST_ENTRY                Link;
131   IP6_PROTOCOL              *IpInstance;
132   NET_BUF                   *Packet;
133   EFI_IP6_RECEIVE_DATA      RxData;
134 } IP6_RXDATA_WRAP;
135 
136 struct _IP6_PROTOCOL {
137   UINT32                    Signature;
138 
139   EFI_IP6_PROTOCOL          Ip6Proto;
140   EFI_HANDLE                Handle;
141   INTN                      State;
142 
143   IP6_SERVICE               *Service;
144   LIST_ENTRY                Link; // Link to all the IP protocol from the service
145 
146   UINT8                     PrefixLength; // PrefixLength of the configured station address.
147   //
148   // User's transmit/receive tokens, and received/deliverd packets
149   //
150   NET_MAP                   RxTokens;
151   NET_MAP                   TxTokens;   // map between (User's Token, IP6_TXTOKE_WRAP)
152   LIST_ENTRY                Received;   // Received but not delivered packet
153   LIST_ENTRY                Delivered;  // Delivered and to be recycled packets
154   EFI_LOCK                  RecycleLock;
155 
156   IP6_INTERFACE             *Interface;
157   LIST_ENTRY                AddrLink;   // Ip instances with the same IP address.
158 
159   EFI_IPv6_ADDRESS          *GroupList; // stored in network order.
160   UINT32                    GroupCount;
161 
162   EFI_IP6_CONFIG_DATA       ConfigData;
163   BOOLEAN                   InDestroy;
164 };
165 
166 struct _IP6_SERVICE {
167   UINT32                          Signature;
168   EFI_SERVICE_BINDING_PROTOCOL    ServiceBinding;
169   INTN                            State;
170 
171   //
172   // List of all the IP instances and interfaces, and default
173   // interface and route table and caches.
174   //
175   UINTN                           NumChildren;
176   LIST_ENTRY                      Children;
177 
178   LIST_ENTRY                      Interfaces;
179 
180   IP6_INTERFACE                   *DefaultInterface;
181   IP6_ROUTE_TABLE                 *RouteTable;
182 
183   IP6_LINK_RX_TOKEN               RecvRequest;
184 
185   //
186   // Ip reassemble utilities and MLD data
187   //
188   IP6_ASSEMBLE_TABLE              Assemble;
189   IP6_MLD_SERVICE_DATA            MldCtrl;
190 
191   EFI_IPv6_ADDRESS                LinkLocalAddr;
192   BOOLEAN                         LinkLocalOk;
193   BOOLEAN                         LinkLocalDadFail;
194   BOOLEAN                         Dhcp6NeedStart;
195   BOOLEAN                         Dhcp6NeedInfoRequest;
196 
197   //
198   // ND data
199   //
200   UINT8                           CurHopLimit;
201   UINT32                          LinkMTU;
202   UINT32                          BaseReachableTime;
203   UINT32                          ReachableTime;
204   UINT32                          RetransTimer;
205   LIST_ENTRY                      NeighborTable;
206 
207   LIST_ENTRY                      OnlinkPrefix;
208   LIST_ENTRY                      AutonomousPrefix;
209 
210   LIST_ENTRY                      DefaultRouterList;
211   UINT32                          RoundRobin;
212 
213   UINT8                           InterfaceIdLen;
214   UINT8                           *InterfaceId;
215 
216   BOOLEAN                         RouterAdvertiseReceived;
217   UINT8                           SolicitTimer;
218   UINT32                          Ticks;
219 
220   //
221   // Low level protocol used by this service instance
222   //
223   EFI_HANDLE                      Image;
224   EFI_HANDLE                      Controller;
225 
226   EFI_HANDLE                      MnpChildHandle;
227   EFI_MANAGED_NETWORK_PROTOCOL    *Mnp;
228 
229   EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;
230   EFI_SIMPLE_NETWORK_MODE         SnpMode;
231 
232   EFI_EVENT                       Timer;
233   EFI_EVENT                       FasterTimer;
234 
235   //
236   // IPv6 Configuration Protocol instance
237   //
238   IP6_CONFIG_INSTANCE             Ip6ConfigInstance;
239 
240   //
241   // The string representation of the current mac address of the
242   // NIC this IP6_SERVICE works on.
243   //
244   CHAR16                          *MacString;
245   UINT32                          MaxPacketSize;
246   UINT32                          OldMaxPacketSize;
247 };
248 
249 /**
250   The callback function for the net buffer which wraps the user's
251   transmit token. Although this function seems simple,
252   there are some subtle aspects.
253   When a user requests the IP to transmit a packet by passing it a
254   token, the token is wrapped in an IP6_TXTOKEN_WRAP and the data
255   is wrapped in a net buffer. The net buffer's Free function is
256   set to Ip6FreeTxToken. The Token and token wrap are added to the
257   IP child's TxToken map. Then the buffer is passed to Ip6Output for
258   transmission. If an error occurs before that, the buffer
259   is freed, which in turn frees the token wrap. The wrap may
260   have been added to the TxToken map or not, and the user's event
261   shouldn't be signaled because we are still in the EfiIp6Transmit. If
262   the buffer has been sent by Ip6Output, it should be removed from
263   the TxToken map and the user's event signaled. The token wrap and buffer
264   are bound together. Refer to the comments in Ip6Output for information
265   about IP fragmentation.
266 
267   @param[in]  Context                The token's wrap.
268 
269 **/
270 VOID
271 EFIAPI
272 Ip6FreeTxToken (
273   IN VOID                   *Context
274   );
275 
276 /**
277   Config the MNP parameter used by IP. The IP driver use one MNP
278   child to transmit/receive frames. By default, it configures MNP
279   to receive unicast/multicast/broadcast. And it will enable/disable
280   the promiscuous receive according to whether there is IP child
281   enable that or not. If Force is FALSE, it will iterate through
282   all the IP children to check whether the promiscuous receive
283   setting has been changed. If it hasn't been changed, it won't
284   reconfigure the MNP. If Force is TRUE, the MNP is configured
285   whether that is changed or not.
286 
287   @param[in]  IpSb               The IP6 service instance that is to be changed.
288   @param[in]  Force              Force the configuration or not.
289 
290   @retval EFI_SUCCESS            The MNP successfully configured/reconfigured.
291   @retval Others                 The configuration failed.
292 
293 **/
294 EFI_STATUS
295 Ip6ServiceConfigMnp (
296   IN IP6_SERVICE            *IpSb,
297   IN BOOLEAN                Force
298   );
299 
300 /**
301   Cancel the user's receive/transmit request. It is the worker function of
302   EfiIp6Cancel API.
303 
304   @param[in]  IpInstance         The IP6 child.
305   @param[in]  Token              The token to cancel. If NULL, all tokens will be
306                                  cancelled.
307 
308   @retval EFI_SUCCESS            The token was cancelled.
309   @retval EFI_NOT_FOUND          The token isn't found on either the
310                                  transmit or receive queue.
311   @retval EFI_DEVICE_ERROR       Not all tokens are cancelled when Token is NULL.
312 
313 **/
314 EFI_STATUS
315 Ip6Cancel (
316   IN IP6_PROTOCOL             *IpInstance,
317   IN EFI_IP6_COMPLETION_TOKEN *Token          OPTIONAL
318   );
319 
320 /**
321   Initialize the IP6_PROTOCOL structure to the unconfigured states.
322 
323   @param[in]       IpSb                   The IP6 service instance.
324   @param[in, out]  IpInstance             The IP6 child instance.
325 
326 **/
327 VOID
328 Ip6InitProtocol (
329   IN IP6_SERVICE            *IpSb,
330   IN OUT IP6_PROTOCOL       *IpInstance
331   );
332 
333 /**
334   Clean up the IP6 child, release all the resources used by it.
335 
336   @param[in, out]  IpInstance    The IP6 child to clean up.
337 
338   @retval EFI_SUCCESS            The IP6 child was cleaned up
339   @retval EFI_DEVICE_ERROR       Some resources failed to be released.
340 
341 **/
342 EFI_STATUS
343 Ip6CleanProtocol (
344   IN OUT IP6_PROTOCOL            *IpInstance
345   );
346 
347 //
348 // EFI_IP6_PROTOCOL interface prototypes
349 //
350 
351 /**
352   Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
353 
354   The GetModeData() function returns the current operational mode data for this driver instance.
355   The data fields in EFI_IP6_MODE_DATA are read only. This function is used optionally to
356   retrieve the operational mode data of underlying networks or drivers.
357 
358   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
359   @param[out] Ip6ModeData        The pointer to the EFI IPv6 Protocol mode data structure.
360   @param[out] MnpConfigData      The pointer to the managed network configuration data structure.
361   @param[out] SnpModeData        The pointer to the simple network mode data structure.
362 
363   @retval EFI_SUCCESS            The operation completed successfully.
364   @retval EFI_INVALID_PARAMETER  This is NULL.
365   @retval EFI_OUT_OF_RESOURCES   The required mode data could not be allocated.
366 
367 **/
368 EFI_STATUS
369 EFIAPI
370 EfiIp6GetModeData (
371   IN EFI_IP6_PROTOCOL                 *This,
372   OUT EFI_IP6_MODE_DATA               *Ip6ModeData     OPTIONAL,
373   OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData   OPTIONAL,
374   OUT EFI_SIMPLE_NETWORK_MODE         *SnpModeData     OPTIONAL
375   );
376 
377 /**
378   Assigns an IPv6 address and subnet mask to this EFI IPv6 Protocol driver instance.
379 
380   The Configure() function is used to set, change, or reset the operational parameters and filter
381   settings for this EFI IPv6 Protocol instance. Until these parameters have been set, no network traffic
382   can be sent or received by this instance. Once the parameters have been reset (by calling this
383   function with Ip6ConfigData set to NULL), no more traffic can be sent or received until these
384   parameters have been set again. Each EFI IPv6 Protocol instance can be started and stopped
385   independently of each other by enabling or disabling their receive filter settings with the
386   Configure() function.
387 
388   If Ip6ConfigData.StationAddress is a valid non-zero IPv6 unicast address, it is required
389   to be one of the currently configured IPv6 addresses list in the EFI IPv6 drivers, or else
390   EFI_INVALID_PARAMETER will be returned. If Ip6ConfigData.StationAddress is
391   unspecified, the IPv6 driver will bind a source address according to the source address selection
392   algorithm. Clients could frequently call GetModeData() to check get a currently configured IPv6.
393   If both Ip6ConfigData.StationAddress and Ip6ConfigData.Destination are unspecified, when
394   transmitting the packet afterwards, the source address filled in each outgoing IPv6 packet
395   is decided based on the destination of this packet.
396 
397   If operational parameters are reset or changed, any pending transmit and receive requests will be
398   cancelled. Their completion token status will be set to EFI_ABORTED, and their events will be
399   signaled.
400 
401   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
402   @param[in]  Ip6ConfigData      The pointer to the EFI IPv6 Protocol configuration data structure.
403                                  If NULL, reset the configuration data.
404 
405   @retval EFI_SUCCESS            The driver instance was successfully opened.
406   @retval EFI_INVALID_PARAMETER  One or more of the following conditions is TRUE:
407                                  - This is NULL.
408                                  - Ip6ConfigData.StationAddress is neither zero nor
409                                    a unicast IPv6 address.
410                                  - Ip6ConfigData.StationAddress is neither zero nor
411                                    one of the configured IP addresses in the EFI IPv6 driver.
412                                  - Ip6ConfigData.DefaultProtocol is illegal.
413   @retval EFI_OUT_OF_RESOURCES   The EFI IPv6 Protocol driver instance data could not be allocated.
414   @retval EFI_NO_MAPPING         The IPv6 driver was responsible for choosing a source address for
415                                  this instance, but no source address was available for use.
416   @retval EFI_ALREADY_STARTED    The interface is already open and must be stopped before the IPv6
417                                  address or prefix length can be changed.
418   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred. The EFI IPv6
419                                  Protocol driver instance was not opened.
420   @retval EFI_UNSUPPORTED        Default protocol specified through
421                                  Ip6ConfigData.DefaulProtocol isn't supported.
422 
423 **/
424 EFI_STATUS
425 EFIAPI
426 EfiIp6Configure (
427   IN EFI_IP6_PROTOCOL          *This,
428   IN EFI_IP6_CONFIG_DATA       *Ip6ConfigData OPTIONAL
429   );
430 
431 /**
432   Joins and leaves multicast groups.
433 
434   The Groups() function is used to join and leave multicast group sessions. Joining a group will
435   enable reception of matching multicast packets. Leaving a group will disable reception of matching
436   multicast packets. Source-Specific Multicast isn't required to be supported.
437 
438   If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.
439 
440   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
441   @param[in]  JoinFlag           Set to TRUE to join the multicast group session and FALSE to leave.
442   @param[in]  GroupAddress       The pointer to the IPv6 multicast address.
443                                  This is an optional parameter that may be NULL.
444 
445   @retval EFI_SUCCESS            The operation completed successfully.
446   @retval EFI_INVALID_PARAMETER  One or more of the following is TRUE:
447                                  - This is NULL.
448                                  - JoinFlag is TRUE and GroupAddress is NULL.
449                                  - GroupAddress is not NULL and *GroupAddress is
450                                    not a multicast IPv6 address.
451                                  - GroupAddress is not NULL and *GroupAddress is in the
452                                    range of SSM destination address.
453   @retval EFI_NOT_STARTED        This instance has not been started.
454   @retval EFI_OUT_OF_RESOURCES   System resources could not be allocated.
455   @retval EFI_UNSUPPORTED        This EFI IPv6 Protocol implementation does not support multicast groups.
456   @retval EFI_ALREADY_STARTED    The group address is already in the group table (when
457                                  JoinFlag is TRUE).
458   @retval EFI_NOT_FOUND          The group address is not in the group table (when JoinFlag is FALSE).
459   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
460 
461 **/
462 EFI_STATUS
463 EFIAPI
464 EfiIp6Groups (
465   IN EFI_IP6_PROTOCOL  *This,
466   IN BOOLEAN           JoinFlag,
467   IN EFI_IPv6_ADDRESS  *GroupAddress  OPTIONAL
468   );
469 
470 /**
471   Adds and deletes routing table entries.
472 
473   The Routes() function adds a route to or deletes a route from the routing table.
474 
475   Routes are determined by comparing the leftmost PrefixLength bits of Destination with
476   the destination IPv6 address arithmetically. The gateway address must be on the same subnet as the
477   configured station address.
478 
479   The default route is added with Destination and PrefixLegth both set to all zeros. The
480   default route matches all destination IPv6 addresses that do not match any other routes.
481 
482   All EFI IPv6 Protocol instances share a routing table.
483 
484   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
485   @param[in]  DeleteRoute        Set to TRUE to delete this route from the routing table. Set to
486                                  FALSE to add this route to the routing table. Destination,
487                                  PrefixLength and Gateway are used as the key to each
488                                  route entry.
489   @param[in]  Destination        The address prefix of the subnet that needs to be routed.
490                                  This is an optional parameter that may be NULL.
491   @param[in]  PrefixLength       The prefix length of Destination. Ignored if Destination
492                                  is NULL.
493   @param[in]  GatewayAddress     The unicast gateway IPv6 address for this route.
494                                  This is an optional parameter that may be NULL.
495 
496   @retval EFI_SUCCESS            The operation completed successfully.
497   @retval EFI_NOT_STARTED        The driver instance has not been started.
498   @retval EFI_INVALID_PARAMETER  One or more of the following conditions is TRUE:
499                                  - This is NULL.
500                                  - When DeleteRoute is TRUE, both Destination and
501                                    GatewayAddress are NULL.
502                                  - When DeleteRoute is FALSE, either Destination or
503                                    GatewayAddress is NULL.
504                                  - *GatewayAddress is not a valid unicast IPv6 address.
505                                  - *GatewayAddress is one of the local configured IPv6
506                                    addresses.
507   @retval EFI_OUT_OF_RESOURCES   Could not add the entry to the routing table.
508   @retval EFI_NOT_FOUND          This route is not in the routing table (when DeleteRoute is TRUE).
509   @retval EFI_ACCESS_DENIED      The route is already defined in the routing table (when
510                                  DeleteRoute is FALSE).
511 
512 **/
513 EFI_STATUS
514 EFIAPI
515 EfiIp6Routes (
516   IN EFI_IP6_PROTOCOL    *This,
517   IN BOOLEAN             DeleteRoute,
518   IN EFI_IPv6_ADDRESS    *Destination    OPTIONAL,
519   IN UINT8               PrefixLength,
520   IN EFI_IPv6_ADDRESS    *GatewayAddress OPTIONAL
521   );
522 
523 /**
524   Add or delete Neighbor cache entries.
525 
526   The Neighbors() function is used to add, update, or delete an entry from a neighbor cache.
527   IPv6 neighbor cache entries are typically inserted and updated by the network protocol driver as
528   network traffic is processed. Most neighbor cache entries will timeout and be deleted if the network
529   traffic stops. Neighbor cache entries that were inserted by Neighbors() may be static (will not
530   timeout) or dynamic (will timeout).
531 
532   The implementation should follow the neighbor cache timeout mechanism defined in
533   RFC4861. The default neighbor cache timeout value should be tuned for the expected network
534   environment.
535 
536   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
537   @param[in]  DeleteFlag         Set to TRUE to delete the specified cache entry. Set to FALSE to
538                                  add (or update, if it already exists and Override is TRUE) the
539                                  specified cache entry. TargetIp6Address is used as the key
540                                  to find the requested cache entry.
541   @param[in]  TargetIp6Address   The pointer to the Target IPv6 address.
542   @param[in]  TargetLinkAddress  The pointer to link-layer address of the target. Ignored if NULL.
543   @param[in]  Timeout            Time in 100-ns units that this entry will remain in the neighbor
544                                  cache, it will be deleted after Timeout. A value of zero means that
545                                  the entry is permanent. A non-zero value means that the entry is
546                                  dynamic.
547   @param[in]  Override           If TRUE, the cached link-layer address of the matching entry will
548                                  be overridden and updated; if FALSE, EFI_ACCESS_DENIED
549                                  will be returned if a corresponding cache entry already exists.
550 
551   @retval  EFI_SUCCESS           The data has been queued for transmission.
552   @retval  EFI_NOT_STARTED       This instance has not been started.
553   @retval  EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
554                                  - This is NULL.
555                                  - TargetIpAddress is NULL.
556                                  - *TargetLinkAddress is invalid when not NULL.
557                                  - *TargetIpAddress is not a valid unicast IPv6 address.
558                                  - *TargetIpAddress is one of the local configured IPv6
559                                    addresses.
560   @retval  EFI_OUT_OF_RESOURCES  Could not add the entry to the neighbor cache.
561   @retval  EFI_NOT_FOUND         This entry is not in the neighbor cache (when DeleteFlag  is
562                                  TRUE or when DeleteFlag  is FALSE while
563                                  TargetLinkAddress is NULL.).
564   @retval  EFI_ACCESS_DENIED     The to-be-added entry is already defined in the neighbor cache,
565                                  and that entry is tagged as un-overridden (when Override
566                                  is FALSE).
567 
568 **/
569 EFI_STATUS
570 EFIAPI
571 EfiIp6Neighbors (
572   IN EFI_IP6_PROTOCOL          *This,
573   IN BOOLEAN                   DeleteFlag,
574   IN EFI_IPv6_ADDRESS          *TargetIp6Address,
575   IN EFI_MAC_ADDRESS           *TargetLinkAddress OPTIONAL,
576   IN UINT32                    Timeout,
577   IN BOOLEAN                   Override
578   );
579 
580 /**
581   Places outgoing data packets into the transmit queue.
582 
583   The Transmit() function places a sending request in the transmit queue of this
584   EFI IPv6 Protocol instance. Whenever the packet in the token is sent out or some
585   errors occur, the event in the token will be signaled and the status is updated.
586 
587   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
588   @param[in]  Token              The pointer to the transmit token.
589 
590   @retval  EFI_SUCCESS           The data has been queued for transmission.
591   @retval  EFI_NOT_STARTED       This instance has not been started.
592   @retval  EFI_NO_MAPPING        The IPv6 driver was responsible for choosing
593                                  a source address for this transmission,
594                                  but no source address was available for use.
595   @retval  EFI_INVALID_PARAMETER One or more of the following is TRUE:
596                                  - This is NULL.
597                                  - Token is NULL.
598                                  - Token.Event is NULL.
599                                  - Token.Packet.TxData is NULL.
600                                  - Token.Packet.ExtHdrsLength is not zero and
601                                    Token.Packet.ExtHdrs is NULL.
602                                  - Token.Packet.FragmentCount is zero.
603                                  - One or more of the Token.Packet.TxData.
604                                    FragmentTable[].FragmentLength fields is zero.
605                                  - One or more of the Token.Packet.TxData.
606                                    FragmentTable[].FragmentBuffer fields is NULL.
607                                  - Token.Packet.TxData.DataLength is zero or not
608                                    equal to the sum of fragment lengths.
609                                  - Token.Packet.TxData.DestinationAddress is non-
610                                    zero when DestinationAddress is configured as
611                                    non-zero when doing Configure() for this
612                                    EFI IPv6 protocol instance.
613                                  - Token.Packet.TxData.DestinationAddress is
614                                    unspecified when DestinationAddress is unspecified
615                                    when doing Configure() for this EFI IPv6 protocol
616                                    instance.
617   @retval  EFI_ACCESS_DENIED     The transmit completion token with the same Token.
618                                  The event was already in the transmit queue.
619   @retval  EFI_NOT_READY         The completion token could not be queued because
620                                  the transmit queue is full.
621   @retval  EFI_NOT_FOUND         Not route is found to the destination address.
622   @retval  EFI_OUT_OF_RESOURCES  Could not queue the transmit data.
623   @retval  EFI_BUFFER_TOO_SMALL  Token.Packet.TxData.TotalDataLength is too
624                                  short to transmit.
625   @retval  EFI_BAD_BUFFER_SIZE   If Token.Packet.TxData.DataLength is beyond the
626                                  maximum that which can be described through the
627                                  Fragment Offset field in Fragment header when
628                                  performing fragmentation.
629   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
630 
631 **/
632 EFI_STATUS
633 EFIAPI
634 EfiIp6Transmit (
635   IN EFI_IP6_PROTOCOL          *This,
636   IN EFI_IP6_COMPLETION_TOKEN  *Token
637   );
638 
639 /**
640   Places a receiving request into the receiving queue.
641 
642   The Receive() function places a completion token into the receive packet queue.
643   This function is always asynchronous.
644 
645   The Token.Event field in the completion token must be filled in by the caller
646   and cannot be NULL. When the receive operation completes, the EFI IPv6 Protocol
647   driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
648   is signaled.
649 
650   Current Udp implementation creates an IP child for each Udp child.
651   It initates a asynchronous receive immediately whether or not
652   there is no mapping. Therefore, disable the returning EFI_NO_MAPPING for now.
653   To enable it, the following check must be performed:
654 
655   if (NetIp6IsUnspecifiedAddr (&Config->StationAddress) && IP6_NO_MAPPING (IpInstance)) {
656     Status = EFI_NO_MAPPING;
657     goto Exit;
658   }
659 
660   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
661   @param[in]  Token              The pointer to a token that is associated with the
662                                  receive data descriptor.
663 
664   @retval EFI_SUCCESS            The receive completion token was cached.
665   @retval EFI_NOT_STARTED        This EFI IPv6 Protocol instance has not been started.
666   @retval EFI_NO_MAPPING         When IP6 driver responsible for binding source address to this instance,
667                                  while no source address is available for use.
668   @retval EFI_INVALID_PARAMETER  One or more of the following conditions is TRUE:
669                                  - This is NULL.
670                                  - Token is NULL.
671                                  - Token.Event is NULL.
672   @retval EFI_OUT_OF_RESOURCES   The receive completion token could not be queued due to a lack of system
673                                  resources (usually memory).
674   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
675                                  The EFI IPv6 Protocol instance has been reset to startup defaults.
676   @retval EFI_ACCESS_DENIED      The receive completion token with the same Token.Event was already
677                                  in the receive queue.
678   @retval EFI_NOT_READY          The receive request could not be queued because the receive queue is full.
679 
680 **/
681 EFI_STATUS
682 EFIAPI
683 EfiIp6Receive (
684   IN EFI_IP6_PROTOCOL          *This,
685   IN EFI_IP6_COMPLETION_TOKEN  *Token
686   );
687 
688 /**
689   Abort an asynchronous transmit or receive request.
690 
691   The Cancel() function is used to abort a pending transmit or receive request.
692   If the token is in the transmit or receive request queues, after calling this
693   function, Token->Status will be set to EFI_ABORTED, and then Token->Event will
694   be signaled. If the token is not in one of the queues, which usually means the
695   asynchronous operation has completed, this function will not signal the token,
696   and EFI_NOT_FOUND is returned.
697 
698   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
699   @param[in]  Token              The pointer to a token that has been issued by
700                                  EFI_IP6_PROTOCOL.Transmit() or
701                                  EFI_IP6_PROTOCOL.Receive(). If NULL, all pending
702                                  tokens are aborted. Type EFI_IP6_COMPLETION_TOKEN is
703                                  defined in EFI_IP6_PROTOCOL.Transmit().
704 
705   @retval EFI_SUCCESS            The asynchronous I/O request was aborted and
706                                  Token->Event was signaled. When Token is NULL, all
707                                  pending requests were aborted, and their events were signaled.
708   @retval EFI_INVALID_PARAMETER  This is NULL.
709   @retval EFI_NOT_STARTED        This instance has not been started.
710   @retval EFI_NOT_FOUND          When Token is not NULL, the asynchronous I/O request was
711                                  not found in the transmit or receive queue. It has either completed
712                                  or was not issued by Transmit() and Receive().
713   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
714 
715 **/
716 EFI_STATUS
717 EFIAPI
718 EfiIp6Cancel (
719   IN EFI_IP6_PROTOCOL          *This,
720   IN EFI_IP6_COMPLETION_TOKEN  *Token    OPTIONAL
721   );
722 
723 /**
724   Polls for incoming data packets and processes outgoing data packets.
725 
726   The Poll() function polls for incoming data packets and processes outgoing data
727   packets. Network drivers and applications can call the EFI_IP6_PROTOCOL.Poll()
728   function to increase the rate that data packets are moved between the communications
729   device and the transmit and receive queues.
730 
731   In some systems the periodic timer event may not poll the underlying communications
732   device fast enough to transmit and/or receive all data packets without missing
733   incoming packets or dropping outgoing packets. Drivers and applications that are
734   experiencing packet loss should try calling the EFI_IP6_PROTOCOL.Poll() function
735   more often.
736 
737   @param[in]  This               The pointer to the EFI_IP6_PROTOCOL instance.
738 
739   @retval  EFI_SUCCESS           Incoming or outgoing data was processed.
740   @retval  EFI_NOT_STARTED       This EFI IPv6 Protocol instance has not been started.
741   @retval  EFI_INVALID_PARAMETER This is NULL.
742   @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred.
743   @retval  EFI_NOT_READY         No incoming or outgoing data was processed.
744   @retval  EFI_TIMEOUT           Data was dropped out of the transmit and/or receive queue.
745                                  Consider increasing the polling rate.
746 
747 **/
748 EFI_STATUS
749 EFIAPI
750 EfiIp6Poll (
751   IN EFI_IP6_PROTOCOL          *This
752   );
753 
754 #endif
755