1 /** @file
2   EFI TCPv6(Transmission Control Protocol version 6) Protocol Definition
3   The EFI TCPv6 Service Binding Protocol is used to locate EFI TCPv6 Protocol drivers to create
4   and destroy child of the driver to communicate with other host using TCP protocol.
5   The EFI TCPv6 Protocol provides services to send and receive data stream.
6 
7   Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
8   This program and the accompanying materials
9   are licensed and made available under the terms and conditions of the BSD License
10   which accompanies this distribution.  The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 
16   @par Revision Reference:
17   This Protocol is introduced in UEFI Specification 2.2
18 
19 **/
20 
21 #ifndef __EFI_TCP6_PROTOCOL_H__
22 #define __EFI_TCP6_PROTOCOL_H__
23 
24 #include <Protocol/ManagedNetwork.h>
25 #include <Protocol/Ip6.h>
26 
27 #define EFI_TCP6_SERVICE_BINDING_PROTOCOL_GUID \
28   { \
29     0xec20eb79, 0x6c1a, 0x4664, {0x9a, 0x0d, 0xd2, 0xe4, 0xcc, 0x16, 0xd6, 0x64 } \
30   }
31 
32 #define EFI_TCP6_PROTOCOL_GUID \
33   { \
34     0x46e44855, 0xbd60, 0x4ab7, {0xab, 0x0d, 0xa6, 0x79, 0xb9, 0x44, 0x7d, 0x77 } \
35   }
36 
37 
38 typedef struct _EFI_TCP6_PROTOCOL EFI_TCP6_PROTOCOL;
39 
40 ///
41 /// EFI_TCP6_SERVICE_POINT is deprecated in the UEFI 2.4B and should not be used any more.
42 /// The definition in here is only present to provide backwards compatability.
43 ///
44 typedef struct {
45   ///
46   /// The EFI TCPv6 Protocol instance handle that is using this
47   /// address/port pair.
48   ///
49   EFI_HANDLE        InstanceHandle;
50   ///
51   /// The local IPv6 address to which this TCP instance is bound. Set
52   /// to 0::/128, if this TCP instance is configured to listen on all
53   /// available source addresses.
54   ///
55   EFI_IPv6_ADDRESS  LocalAddress;
56   ///
57   /// The local port number in host byte order.
58   ///
59   UINT16            LocalPort;
60   ///
61   /// The remote IPv6 address. It may be 0::/128 if this TCP instance is
62   /// not connected to any remote host.
63   ///
64   EFI_IPv6_ADDRESS  RemoteAddress;
65   ///
66   /// The remote port number in host byte order. It may be zero if this
67   /// TCP instance is not connected to any remote host.
68   ///
69   UINT16            RemotePort;
70 } EFI_TCP6_SERVICE_POINT;
71 
72 ///
73 /// EFI_TCP6_VARIABLE_DATA is deprecated in the UEFI 2.4B and should not be used any more.
74 /// The definition in here is only present to provide backwards compatability.
75 ///
76 typedef struct {
77   EFI_HANDLE             DriverHandle; ///< The handle of the driver that creates this entry.
78   UINT32                 ServiceCount; ///< The number of address/port pairs following this data structure.
79   EFI_TCP6_SERVICE_POINT Services[1];  ///< List of address/port pairs that are currently in use.
80 } EFI_TCP6_VARIABLE_DATA;
81 
82 ///
83 /// EFI_TCP6_ACCESS_POINT
84 ///
85 typedef struct {
86   ///
87   /// The local IP address assigned to this TCP instance. The EFI
88   /// TCPv6 driver will only deliver incoming packets whose
89   /// destination addresses exactly match the IP address. Set to zero to
90   /// let the underlying IPv6 driver choose a source address. If not zero
91   /// it must be one of the configured IP addresses in the underlying
92   /// IPv6 driver.
93   ///
94   EFI_IPv6_ADDRESS  StationAddress;
95   ///
96   /// The local port number to which this EFI TCPv6 Protocol instance
97   /// is bound. If the instance doesn't care the local port number, set
98   /// StationPort to zero to use an ephemeral port.
99   ///
100   UINT16            StationPort;
101   ///
102   /// The remote IP address to which this EFI TCPv6 Protocol instance
103   /// is connected. If ActiveFlag is FALSE (i.e. a passive TCPv6
104   /// instance), the instance only accepts connections from the
105   /// RemoteAddress. If ActiveFlag is TRUE the instance will
106   /// connect to the RemoteAddress, i.e., outgoing segments will be
107   /// sent to this address and only segments from this address will be
108   /// delivered to the application. When ActiveFlag is FALSE, it
109   /// can be set to zero and means that incoming connection requests
110   /// from any address will be accepted.
111   ///
112   EFI_IPv6_ADDRESS  RemoteAddress;
113   ///
114   /// The remote port to which this EFI TCPv6 Protocol instance
115   /// connects or from which connection request will be accepted by
116   /// this EFI TCPv6 Protocol instance. If ActiveFlag is FALSE it
117   /// can be zero and means that incoming connection request from
118   /// any port will be accepted. Its value can not be zero when
119   /// ActiveFlag is TRUE.
120   ///
121   UINT16            RemotePort;
122   ///
123   /// Set it to TRUE to initiate an active open. Set it to FALSE to
124   /// initiate a passive open to act as a server.
125   ///
126   BOOLEAN           ActiveFlag;
127 } EFI_TCP6_ACCESS_POINT;
128 
129 ///
130 /// EFI_TCP6_OPTION
131 ///
132 typedef struct {
133   ///
134   /// The size of the TCP receive buffer.
135   ///
136   UINT32   ReceiveBufferSize;
137   ///
138   /// The size of the TCP send buffer.
139   ///
140   UINT32   SendBufferSize;
141   ///
142   /// The length of incoming connect request queue for a passive
143   /// instance. When set to zero, the value is implementation specific.
144   ///
145   UINT32   MaxSynBackLog;
146   ///
147   /// The maximum seconds a TCP instance will wait for before a TCP
148   /// connection established. When set to zero, the value is
149   /// implementation specific.
150   ///
151   UINT32   ConnectionTimeout;
152   ///
153   ///The number of times TCP will attempt to retransmit a packet on
154   ///an established connection. When set to zero, the value is
155   ///implementation specific.
156   ///
157   UINT32   DataRetries;
158   ///
159   /// How many seconds to wait in the FIN_WAIT_2 states for a final
160   /// FIN flag before the TCP instance is closed. This timeout is in
161   /// effective only if the application has called Close() to
162   /// disconnect the connection completely. It is also called
163   /// FIN_WAIT_2 timer in other implementations. When set to zero,
164   /// it should be disabled because the FIN_WAIT_2 timer itself is
165   /// against the standard. The default value is 60.
166   ///
167   UINT32   FinTimeout;
168   ///
169   /// How many seconds to wait in TIME_WAIT state before the TCP
170   /// instance is closed. The timer is disabled completely to provide a
171   /// method to close the TCP connection quickly if it is set to zero. It
172   /// is against the related RFC documents.
173   ///
174   UINT32   TimeWaitTimeout;
175   ///
176   /// The maximum number of TCP keep-alive probes to send before
177   /// giving up and resetting the connection if no response from the
178   /// other end. Set to zero to disable keep-alive probe.
179   ///
180   UINT32   KeepAliveProbes;
181   ///
182   /// The number of seconds a connection needs to be idle before TCP
183   /// sends out periodical keep-alive probes. When set to zero, the
184   /// value is implementation specific. It should be ignored if keep-
185   /// alive probe is disabled.
186   ///
187   UINT32   KeepAliveTime;
188   ///
189   /// The number of seconds between TCP keep-alive probes after the
190   /// periodical keep-alive probe if no response. When set to zero, the
191   /// value is implementation specific. It should be ignored if keep-
192   /// alive probe is disabled.
193   ///
194   UINT32   KeepAliveInterval;
195   ///
196   /// Set it to TRUE to enable the Nagle algorithm as defined in
197   /// RFC896. Set it to FALSE to disable it.
198   ///
199   BOOLEAN  EnableNagle;
200   ///
201   /// Set it to TRUE to enable TCP timestamps option as defined in
202   /// RFC1323. Set to FALSE to disable it.
203   ///
204   BOOLEAN  EnableTimeStamp;
205   ///
206   /// Set it to TRUE to enable TCP window scale option as defined in
207   /// RFC1323. Set it to FALSE to disable it.
208   ///
209   BOOLEAN  EnableWindowScaling;
210   ///
211   /// Set it to TRUE to enable selective acknowledge mechanism
212   /// described in RFC 2018. Set it to FALSE to disable it.
213   /// Implementation that supports SACK can optionally support
214   /// DSAK as defined in RFC 2883.
215   ///
216   BOOLEAN  EnableSelectiveAck;
217   ///
218   /// Set it to TRUE to enable path MTU discovery as defined in
219   /// RFC 1191. Set to FALSE to disable it.
220   ///
221   BOOLEAN  EnablePathMtuDiscovery;
222 } EFI_TCP6_OPTION;
223 
224 ///
225 /// EFI_TCP6_CONFIG_DATA
226 ///
227 typedef struct {
228   ///
229   /// TrafficClass field in transmitted IPv6 packets.
230   ///
231   UINT8                 TrafficClass;
232   ///
233   /// HopLimit field in transmitted IPv6 packets.
234   ///
235   UINT8                 HopLimit;
236   ///
237   /// Used to specify TCP communication end settings for a TCP instance.
238   ///
239   EFI_TCP6_ACCESS_POINT AccessPoint;
240   ///
241   /// Used to configure the advance TCP option for a connection. If set
242   /// to NULL, implementation specific options for TCP connection will be used.
243   ///
244   EFI_TCP6_OPTION       *ControlOption;
245 } EFI_TCP6_CONFIG_DATA;
246 
247 ///
248 /// EFI_TCP6_CONNECTION_STATE
249 ///
250 typedef enum {
251   Tcp6StateClosed      = 0,
252   Tcp6StateListen      = 1,
253   Tcp6StateSynSent     = 2,
254   Tcp6StateSynReceived = 3,
255   Tcp6StateEstablished = 4,
256   Tcp6StateFinWait1    = 5,
257   Tcp6StateFinWait2    = 6,
258   Tcp6StateClosing     = 7,
259   Tcp6StateTimeWait    = 8,
260   Tcp6StateCloseWait   = 9,
261   Tcp6StateLastAck     = 10
262 } EFI_TCP6_CONNECTION_STATE;
263 
264 ///
265 /// EFI_TCP6_COMPLETION_TOKEN
266 /// is used as a common header for various asynchronous tokens.
267 ///
268 typedef struct {
269   ///
270   /// The Event to signal after request is finished and Status field is
271   /// updated by the EFI TCPv6 Protocol driver.
272   ///
273   EFI_EVENT   Event;
274   ///
275   /// The result of the completed operation.
276   ///
277   EFI_STATUS  Status;
278 } EFI_TCP6_COMPLETION_TOKEN;
279 
280 ///
281 /// EFI_TCP6_CONNECTION_TOKEN
282 /// will be set if the active open succeeds or an unexpected
283 /// error happens.
284 ///
285 typedef struct {
286   ///
287   /// The Status in the CompletionToken will be set to one of
288   /// the following values if the active open succeeds or an unexpected
289   /// error happens:
290   /// EFI_SUCCESS:              The active open succeeds and the instance's
291   ///                           state is Tcp6StateEstablished.
292   /// EFI_CONNECTION_RESET:     The connect fails because the connection is reset
293   ///                           either by instance itself or the communication peer.
294   /// EFI_CONNECTION_REFUSED:   The receiving or transmission operation fails because this
295   ///                           connection is refused.
296   /// EFI_ABORTED:              The active open is aborted.
297   /// EFI_TIMEOUT:              The connection establishment timer expires and
298   ///                           no more specific information is available.
299   /// EFI_NETWORK_UNREACHABLE:  The active open fails because
300   ///                           an ICMP network unreachable error is received.
301   /// EFI_HOST_UNREACHABLE:     The active open fails because an
302   ///                           ICMP host unreachable error is received.
303   /// EFI_PROTOCOL_UNREACHABLE: The active open fails
304   ///                           because an ICMP protocol unreachable error is received.
305   /// EFI_PORT_UNREACHABLE:     The connection establishment
306   ///                           timer times out and an ICMP port unreachable error is received.
307   /// EFI_ICMP_ERROR:           The connection establishment timer times
308   ///                           out and some other ICMP error is received.
309   /// EFI_DEVICE_ERROR:         An unexpected system or network error occurred.
310   /// EFI_SECURITY_VIOLATION:   The active open was failed because of IPSec policy check.
311   /// EFI_NO_MEDIA:             There was a media error.
312   ///
313   EFI_TCP6_COMPLETION_TOKEN CompletionToken;
314 } EFI_TCP6_CONNECTION_TOKEN;
315 
316 ///
317 /// EFI_TCP6_LISTEN_TOKEN
318 /// returns when list operation finishes.
319 ///
320 typedef struct {
321   ///
322   /// The Status in CompletionToken will be set to the
323   /// following value if accept finishes:
324   /// EFI_SUCCESS:            A remote peer has successfully established a
325   ///                         connection to this instance. A new TCP instance has also been
326   ///                         created for the connection.
327   /// EFI_CONNECTION_RESET:   The accept fails because the connection is reset either
328   ///                         by instance itself or communication peer.
329   /// EFI_ABORTED:            The accept request has been aborted.
330   /// EFI_SECURITY_VIOLATION: The accept operation was failed because of IPSec policy check.
331   ///
332   EFI_TCP6_COMPLETION_TOKEN CompletionToken;
333   EFI_HANDLE                NewChildHandle;
334 } EFI_TCP6_LISTEN_TOKEN;
335 
336 ///
337 /// EFI_TCP6_FRAGMENT_DATA
338 /// allows multiple receive or transmit buffers to be specified. The
339 /// purpose of this structure is to provide scattered read and write.
340 ///
341 typedef struct {
342   UINT32 FragmentLength;   ///< Length of data buffer in the fragment.
343   VOID   *FragmentBuffer;  ///< Pointer to the data buffer in the fragment.
344 } EFI_TCP6_FRAGMENT_DATA;
345 
346 ///
347 /// EFI_TCP6_RECEIVE_DATA
348 /// When TCPv6 driver wants to deliver received data to the application,
349 /// it will pick up the first queued receiving token, update its
350 /// Token->Packet.RxData then signal the Token->CompletionToken.Event.
351 ///
352 typedef struct {
353   ///
354   /// Whether the data is urgent. When this flag is set, the instance is in
355   /// urgent mode.
356   ///
357   BOOLEAN                 UrgentFlag;
358   ///
359   /// When calling Receive() function, it is the byte counts of all
360   /// Fragmentbuffer in FragmentTable allocated by user.
361   /// When the token is signaled by TCPv6 driver it is the length of
362   /// received data in the fragments.
363   ///
364   UINT32                  DataLength;
365   ///
366   /// Number of fragments.
367   ///
368   UINT32                  FragmentCount;
369   ///
370   /// An array of fragment descriptors.
371   ///
372   EFI_TCP6_FRAGMENT_DATA  FragmentTable[1];
373 } EFI_TCP6_RECEIVE_DATA;
374 
375 ///
376 /// EFI_TCP6_TRANSMIT_DATA
377 /// The EFI TCPv6 Protocol user must fill this data structure before sending a packet.
378 /// The packet may contain multiple buffers in non-continuous memory locations.
379 ///
380 typedef struct {
381   ///
382   /// Push If TRUE, data must be transmitted promptly, and the PUSH bit in
383   /// the last TCP segment created will be set. If FALSE, data
384   /// transmission may be delayed to combine with data from
385   /// subsequent Transmit()s for efficiency.
386   ///
387   BOOLEAN                 Push;
388   ///
389   /// The data in the fragment table are urgent and urgent point is in
390   /// effect if TRUE. Otherwise those data are NOT considered urgent.
391   ///
392   BOOLEAN                 Urgent;
393   ///
394   /// Length of the data in the fragments.
395   ///
396   UINT32                  DataLength;
397   ///
398   /// Number of fragments.
399   ///
400   UINT32                  FragmentCount;
401   ///
402   /// An array of fragment descriptors.
403   ///
404   EFI_TCP6_FRAGMENT_DATA  FragmentTable[1];
405 } EFI_TCP6_TRANSMIT_DATA;
406 
407 ///
408 /// EFI_TCP6_IO_TOKEN
409 /// returns When transmission finishes or meets any unexpected error.
410 ///
411 typedef struct {
412   ///
413   /// When transmission finishes or meets any unexpected error it will
414   /// be set to one of the following values:
415   /// EFI_SUCCESS:              The receiving or transmission operation
416   ///                           completes successfully.
417   /// EFI_CONNECTION_FIN:       The receiving operation fails because the communication peer
418   ///                           has closed the connection and there is no more data in the
419   ///                           receive buffer of the instance.
420   /// EFI_CONNECTION_RESET:     The receiving or transmission operation fails
421   ///                           because this connection is reset either by instance
422   ///                           itself or the communication peer.
423   /// EFI_ABORTED:              The receiving or transmission is aborted.
424   /// EFI_TIMEOUT:              The transmission timer expires and no more
425   ///                           specific information is available.
426   /// EFI_NETWORK_UNREACHABLE:  The transmission fails
427   ///                           because an ICMP network unreachable error is received.
428   /// EFI_HOST_UNREACHABLE:     The transmission fails because an
429   ///                           ICMP host unreachable error is received.
430   /// EFI_PROTOCOL_UNREACHABLE: The transmission fails
431   ///                           because an ICMP protocol unreachable error is received.
432   /// EFI_PORT_UNREACHABLE:     The transmission fails and an
433   ///                           ICMP port unreachable error is received.
434   /// EFI_ICMP_ERROR:           The transmission fails and some other
435   ///                           ICMP error is received.
436   /// EFI_DEVICE_ERROR:         An unexpected system or network error occurs.
437   /// EFI_SECURITY_VIOLATION:   The receiving or transmission
438   ///                           operation was failed because of IPSec policy check
439   /// EFI_NO_MEDIA:             There was a media error.
440   ///
441   EFI_TCP6_COMPLETION_TOKEN CompletionToken;
442   union {
443     ///
444     /// When this token is used for receiving, RxData is a pointer to
445     /// EFI_TCP6_RECEIVE_DATA.
446     ///
447     EFI_TCP6_RECEIVE_DATA   *RxData;
448     ///
449     /// When this token is used for transmitting, TxData is a pointer to
450     /// EFI_TCP6_TRANSMIT_DATA.
451     ///
452     EFI_TCP6_TRANSMIT_DATA  *TxData;
453   } Packet;
454 } EFI_TCP6_IO_TOKEN;
455 
456 ///
457 /// EFI_TCP6_CLOSE_TOKEN
458 /// returns when close operation finishes.
459 ///
460 typedef struct {
461   ///
462   /// When close finishes or meets any unexpected error it will be set
463   /// to one of the following values:
464   /// EFI_SUCCESS:            The close operation completes successfully.
465   /// EFI_ABORTED:            User called configure with NULL without close stopping.
466   /// EFI_SECURITY_VIOLATION: The close operation was failed because of IPSec policy check.
467   ///
468   EFI_TCP6_COMPLETION_TOKEN CompletionToken;
469   ///
470   /// Abort the TCP connection on close instead of the standard TCP
471   /// close process when it is set to TRUE. This option can be used to
472   /// satisfy a fast disconnect.
473   ///
474   BOOLEAN                   AbortOnClose;
475 } EFI_TCP6_CLOSE_TOKEN;
476 
477 /**
478   Get the current operational status.
479 
480   The GetModeData() function copies the current operational settings of this EFI TCPv6
481   Protocol instance into user-supplied buffers. This function can also be used to retrieve
482   the operational setting of underlying drivers such as IPv6, MNP, or SNP.
483 
484   @param[in]  This              Pointer to the EFI_TCP6_PROTOCOL instance.
485   @param[out] Tcp6State         The buffer in which the current TCP state is returned.
486   @param[out] Tcp6ConfigData    The buffer in which the current TCP configuration is returned.
487   @param[out] Ip6ModeData       The buffer in which the current IPv6 configuration data used by
488                                 the TCP instance is returned.
489   @param[out] MnpConfigData     The buffer in which the current MNP configuration data used
490                                 indirectly by the TCP instance is returned.
491   @param[out] SnpModeData       The buffer in which the current SNP mode data used indirectly by
492                                 the TCP instance is returned.
493 
494   @retval EFI_SUCCESS           The mode data was read.
495   @retval EFI_NOT_STARTED       No configuration data is available because this instance hasn't
496                                 been started.
497   @retval EFI_INVALID_PARAMETER This is NULL.
498 
499 **/
500 typedef
501 EFI_STATUS
502 (EFIAPI *EFI_TCP6_GET_MODE_DATA)(
503   IN  EFI_TCP6_PROTOCOL                  *This,
504   OUT EFI_TCP6_CONNECTION_STATE          *Tcp6State OPTIONAL,
505   OUT EFI_TCP6_CONFIG_DATA               *Tcp6ConfigData OPTIONAL,
506   OUT EFI_IP6_MODE_DATA                  *Ip6ModeData OPTIONAL,
507   OUT EFI_MANAGED_NETWORK_CONFIG_DATA    *MnpConfigData OPTIONAL,
508   OUT EFI_SIMPLE_NETWORK_MODE            *SnpModeData OPTIONAL
509   );
510 
511 /**
512   Initialize or brutally reset the operational parameters for this EFI TCPv6 instance.
513 
514   The Configure() function does the following:
515   - Initialize this TCP instance, i.e., initialize the communication end settings and
516     specify active open or passive open for an instance.
517   - Reset this TCP instance brutally, i.e., cancel all pending asynchronous tokens, flush
518     transmission and receiving buffer directly without informing the communication peer.
519 
520   No other TCPv6 Protocol operation except Poll() can be executed by this instance until
521   it is configured properly. For an active TCP instance, after a proper configuration it
522   may call Connect() to initiates the three-way handshake. For a passive TCP instance,
523   its state will transit to Tcp6StateListen after configuration, and Accept() may be
524   called to listen the incoming TCP connection requests. If Tcp6ConfigData is set to NULL,
525   the instance is reset. Resetting process will be done brutally, the state machine will
526   be set to Tcp6StateClosed directly, the receive queue and transmit queue will be flushed,
527   and no traffic is allowed through this instance.
528 
529   @param[in] This               Pointer to the EFI_TCP6_PROTOCOL instance.
530   @param[in] Tcp6ConfigData     Pointer to the configure data to configure the instance.
531                                 If Tcp6ConfigData is set to NULL, the instance is reset.
532 
533   @retval EFI_SUCCESS           The operational settings are set, changed, or reset
534                                 successfully.
535   @retval EFI_NO_MAPPING        The underlying IPv6 driver was responsible for choosing a source
536                                 address for this instance, but no source address was available for
537                                 use.
538   @retval EFI_INVALID_PARAMETER One or more of the following conditions are TRUE:
539                                 - This is NULL.
540                                 - Tcp6ConfigData->AccessPoint.StationAddress is neither zero nor
541                                   one of the configured IP addresses in the underlying IPv6 driver.
542                                 - Tcp6ConfigData->AccessPoint.RemoteAddress isn't a valid unicast
543                                   IPv6 address.
544                                 - Tcp6ConfigData->AccessPoint.RemoteAddress is zero or
545                                   Tcp6ConfigData->AccessPoint.RemotePort is zero when
546                                   Tcp6ConfigData->AccessPoint.ActiveFlag is TRUE.
547                                 - A same access point has been configured in other TCP
548                                   instance properly.
549   @retval EFI_ACCESS_DENIED     Configuring TCP instance when it is configured without
550                                 calling Configure() with NULL to reset it.
551   @retval EFI_UNSUPPORTED       One or more of the control options are not supported in
552                                 the implementation.
553   @retval EFI_OUT_OF_RESOURCES  Could not allocate enough system resources when
554                                 executing Configure().
555   @retval EFI_DEVICE_ERROR      An unexpected network or system error occurred.
556 
557 **/
558 typedef
559 EFI_STATUS
560 (EFIAPI *EFI_TCP6_CONFIGURE)(
561   IN EFI_TCP6_PROTOCOL        *This,
562   IN EFI_TCP6_CONFIG_DATA     *Tcp6ConfigData OPTIONAL
563   );
564 
565 /**
566   Initiate a nonblocking TCP connection request for an active TCP instance.
567 
568   The Connect() function will initiate an active open to the remote peer configured
569   in current TCP instance if it is configured active. If the connection succeeds or
570   fails due to any error, the ConnectionToken->CompletionToken.Event will be signaled
571   and ConnectionToken->CompletionToken.Status will be updated accordingly. This
572   function can only be called for the TCP instance in Tcp6StateClosed state. The
573   instance will transfer into Tcp6StateSynSent if the function returns EFI_SUCCESS.
574   If TCP three-way handshake succeeds, its state will become Tcp6StateEstablished,
575   otherwise, the state will return to Tcp6StateClosed.
576 
577   @param[in] This                Pointer to the EFI_TCP6_PROTOCOL instance.
578   @param[in] ConnectionToken     Pointer to the connection token to return when the TCP three
579                                  way handshake finishes.
580 
581   @retval EFI_SUCCESS            The connection request is successfully initiated and the state of
582                                  this TCP instance has been changed to Tcp6StateSynSent.
583   @retval EFI_NOT_STARTED        This EFI TCPv6 Protocol instance has not been configured.
584   @retval EFI_ACCESS_DENIED      One or more of the following conditions are TRUE:
585                                  - This instance is not configured as an active one.
586                                  - This instance is not in Tcp6StateClosed state.
587   @retval EFI_INVALID_PARAMETER  One or more of the following are TRUE:
588                                  - This is NULL.
589                                  - ConnectionToken is NULL.
590                                  - ConnectionToken->CompletionToken.Event is NULL.
591   @retval EFI_OUT_OF_RESOURCES   The driver can't allocate enough resource to initiate the active open.
592   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
593 
594 **/
595 typedef
596 EFI_STATUS
597 (EFIAPI *EFI_TCP6_CONNECT)(
598   IN EFI_TCP6_PROTOCOL           *This,
599   IN EFI_TCP6_CONNECTION_TOKEN   *ConnectionToken
600   );
601 
602 /**
603   Listen on the passive instance to accept an incoming connection request. This is a
604   nonblocking operation.
605 
606   The Accept() function initiates an asynchronous accept request to wait for an incoming
607   connection on the passive TCP instance. If a remote peer successfully establishes a
608   connection with this instance, a new TCP instance will be created and its handle will
609   be returned in ListenToken->NewChildHandle. The newly created instance is configured
610   by inheriting the passive instance's configuration and is ready for use upon return.
611   The new instance is in the Tcp6StateEstablished state.
612 
613   The ListenToken->CompletionToken.Event will be signaled when a new connection is
614   accepted, user aborts the listen or connection is reset.
615 
616   This function only can be called when current TCP instance is in Tcp6StateListen state.
617 
618   @param[in] This                Pointer to the EFI_TCP6_PROTOCOL instance.
619   @param[in] ListenToken         Pointer to the listen token to return when operation finishes.
620 
621 
622   @retval EFI_SUCCESS            The listen token has been queued successfully.
623   @retval EFI_NOT_STARTED        This EFI TCPv6 Protocol instance has not been configured.
624   @retval EFI_ACCESS_DENIED      One or more of the following are TRUE:
625                                  - This instance is not a passive instance.
626                                  - This instance is not in Tcp6StateListen state.
627                                  - The same listen token has already existed in the listen
628                                    token queue of this TCP instance.
629   @retval EFI_INVALID_PARAMETER  One or more of the following are TRUE:
630                                  - This is NULL.
631                                  - ListenToken is NULL.
632                                  - ListentToken->CompletionToken.Event is NULL.
633   @retval EFI_OUT_OF_RESOURCES   Could not allocate enough resource to finish the operation.
634   @retval EFI_DEVICE_ERROR       Any unexpected and not belonged to above category error.
635 
636 **/
637 typedef
638 EFI_STATUS
639 (EFIAPI *EFI_TCP6_ACCEPT)(
640   IN EFI_TCP6_PROTOCOL             *This,
641   IN EFI_TCP6_LISTEN_TOKEN         *ListenToken
642   );
643 
644 /**
645   Queues outgoing data into the transmit queue.
646 
647   The Transmit() function queues a sending request to this TCP instance along with the
648   user data. The status of the token is updated and the event in the token will be
649   signaled once the data is sent out or some error occurs.
650 
651   @param[in] This                 Pointer to the EFI_TCP6_PROTOCOL instance.
652   @param[in] Token                Pointer to the completion token to queue to the transmit queue.
653 
654   @retval EFI_SUCCESS             The data has been queued for transmission.
655   @retval EFI_NOT_STARTED         This EFI TCPv6 Protocol instance has not been configured.
656   @retval EFI_NO_MAPPING          The underlying IPv6 driver was responsible for choosing a
657                                   source address for this instance, but no source address was
658                                   available for use.
659   @retval EFI_INVALID_PARAMETER   One or more of the following are TRUE:
660                                   - This is NULL.
661                                   - Token is NULL.
662                                   - Token->CompletionToken.Event is NULL.
663                                   - Token->Packet.TxData is NULL.
664                                   - Token->Packet.FragmentCount is zero.
665                                   - Token->Packet.DataLength is not equal to the sum of fragment lengths.
666   @retval EFI_ACCESS_DENIED       One or more of the following conditions are TRUE:
667                                   - A transmit completion token with the same Token->
668                                     CompletionToken.Event was already in the
669                                     transmission queue.
670                                   - The current instance is in Tcp6StateClosed state.
671                                   - The current instance is a passive one and it is in
672                                     Tcp6StateListen state.
673                                   - User has called Close() to disconnect this connection.
674   @retval EFI_NOT_READY           The completion token could not be queued because the
675                                   transmit queue is full.
676   @retval EFI_OUT_OF_RESOURCES    Could not queue the transmit data because of resource
677                                   shortage.
678   @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or address.
679 
680 **/
681 typedef
682 EFI_STATUS
683 (EFIAPI *EFI_TCP6_TRANSMIT)(
684   IN EFI_TCP6_PROTOCOL            *This,
685   IN EFI_TCP6_IO_TOKEN            *Token
686   );
687 
688 /**
689   Places an asynchronous receive request into the receiving queue.
690 
691   The Receive() function places a completion token into the receive packet queue. This
692   function is always asynchronous. The caller must allocate the Token->CompletionToken.Event
693   and the FragmentBuffer used to receive data. The caller also must fill the DataLength which
694   represents the whole length of all FragmentBuffer. When the receive operation completes, the
695   EFI TCPv6 Protocol driver updates the Token->CompletionToken.Status and Token->Packet.RxData
696   fields and the Token->CompletionToken.Event is signaled. If got data the data and its length
697   will be copied into the FragmentTable, at the same time the full length of received data will
698   be recorded in the DataLength fields. Providing a proper notification function and context
699   for the event will enable the user to receive the notification and receiving status. That
700   notification function is guaranteed to not be re-entered.
701 
702   @param[in] This               Pointer to the EFI_TCP6_PROTOCOL instance.
703   @param[in] Token              Pointer to a token that is associated with the receive data
704                                 descriptor.
705 
706   @retval EFI_SUCCESS            The receive completion token was cached.
707   @retval EFI_NOT_STARTED        This EFI TCPv6 Protocol instance has not been configured.
708   @retval EFI_NO_MAPPING         The underlying IPv6 driver was responsible for choosing a source
709                                  address for this instance, but no source address was available for use.
710   @retval EFI_INVALID_PARAMETER  One or more of the following conditions is TRUE:
711                                  - This is NULL.
712                                  - Token is NULL.
713                                  - Token->CompletionToken.Event is NULL.
714                                  - Token->Packet.RxData is NULL.
715                                  - Token->Packet.RxData->DataLength is 0.
716                                  - The Token->Packet.RxData->DataLength is not the
717                                    sum of all FragmentBuffer length in FragmentTable.
718   @retval EFI_OUT_OF_RESOURCES   The receive completion token could not be queued due to a lack of
719                                  system resources (usually memory).
720   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
721                                  The EFI TCPv6 Protocol instance has been reset to startup defaults.
722   @retval EFI_ACCESS_DENIED      One or more of the following conditions is TRUE:
723                                  - A receive completion token with the same Token->CompletionToken.Event
724                                    was already in the receive queue.
725                                  - The current instance is in Tcp6StateClosed state.
726                                  - The current instance is a passive one and it is in
727                                    Tcp6StateListen state.
728                                  - User has called Close() to disconnect this connection.
729   @retval EFI_CONNECTION_FIN     The communication peer has closed the connection and there is no
730                                  any buffered data in the receive buffer of this instance
731   @retval EFI_NOT_READY          The receive request could not be queued because the receive queue is full.
732 
733 **/
734 typedef
735 EFI_STATUS
736 (EFIAPI *EFI_TCP6_RECEIVE)(
737   IN EFI_TCP6_PROTOCOL           *This,
738   IN EFI_TCP6_IO_TOKEN           *Token
739   );
740 
741 /**
742   Disconnecting a TCP connection gracefully or reset a TCP connection. This function is a
743   nonblocking operation.
744 
745   Initiate an asynchronous close token to TCP driver. After Close() is called, any buffered
746   transmission data will be sent by TCP driver and the current instance will have a graceful close
747   working flow described as RFC 793 if AbortOnClose is set to FALSE, otherwise, a rest packet
748   will be sent by TCP driver to fast disconnect this connection. When the close operation completes
749   successfully the TCP instance is in Tcp6StateClosed state, all pending asynchronous
750   operations are signaled and any buffers used for TCP network traffic are flushed.
751 
752   @param[in] This                Pointer to the EFI_TCP6_PROTOCOL instance.
753   @param[in] CloseToken          Pointer to the close token to return when operation finishes.
754 
755   @retval EFI_SUCCESS            The Close() is called successfully.
756   @retval EFI_NOT_STARTED        This EFI TCPv6 Protocol instance has not been configured.
757   @retval EFI_ACCESS_DENIED      One or more of the following are TRUE:
758                                  - CloseToken or CloseToken->CompletionToken.Event is already in use.
759                                  - Previous Close() call on this instance has not finished.
760   @retval EFI_INVALID_PARAMETER  One or more of the following are TRUE:
761                                  - This is NULL.
762                                  - CloseToken is NULL.
763                                  - CloseToken->CompletionToken.Event is NULL.
764   @retval EFI_OUT_OF_RESOURCES   Could not allocate enough resource to finish the operation.
765   @retval EFI_DEVICE_ERROR       Any unexpected and not belonged to above category error.
766 
767 **/
768 typedef
769 EFI_STATUS
770 (EFIAPI *EFI_TCP6_CLOSE)(
771   IN EFI_TCP6_PROTOCOL           *This,
772   IN EFI_TCP6_CLOSE_TOKEN        *CloseToken
773   );
774 
775 /**
776   Abort an asynchronous connection, listen, transmission or receive request.
777 
778   The Cancel() function aborts a pending connection, listen, transmit or
779   receive request.
780 
781   If Token is not NULL and the token is in the connection, listen, transmission
782   or receive queue when it is being cancelled, its Token->Status will be set
783   to EFI_ABORTED and then Token->Event will be signaled.
784 
785   If the token is not in one of the queues, which usually means that the
786   asynchronous operation has completed, EFI_NOT_FOUND is returned.
787 
788   If Token is NULL all asynchronous token issued by Connect(), Accept(),
789   Transmit() and Receive() will be aborted.
790 
791   @param[in] This                Pointer to the EFI_TCP6_PROTOCOL instance.
792   @param[in] Token               Pointer to a token that has been issued by
793                                  EFI_TCP6_PROTOCOL.Connect(),
794                                  EFI_TCP6_PROTOCOL.Accept(),
795                                  EFI_TCP6_PROTOCOL.Transmit() or
796                                  EFI_TCP6_PROTOCOL.Receive(). If NULL, all pending
797                                  tokens issued by above four functions will be aborted. Type
798                                  EFI_TCP6_COMPLETION_TOKEN is defined in
799                                  EFI_TCP_PROTOCOL.Connect().
800 
801   @retval EFI_SUCCESS            The asynchronous I/O request is aborted and Token->Event
802                                  is signaled.
803   @retval EFI_INVALID_PARAMETER  This is NULL.
804   @retval EFI_NOT_STARTED        This instance hasn't been configured.
805   @retval EFI_NOT_FOUND          The asynchronous I/O request isn't found in the transmission or
806                                  receive queue. It has either completed or wasn't issued by
807                                  Transmit() and Receive().
808   @retval EFI_UNSUPPORTED        The implementation does not support this function.
809 
810 **/
811 typedef
812 EFI_STATUS
813 (EFIAPI *EFI_TCP6_CANCEL)(
814   IN EFI_TCP6_PROTOCOL           *This,
815   IN EFI_TCP6_COMPLETION_TOKEN   *Token OPTIONAL
816   );
817 
818 /**
819   Poll to receive incoming data and transmit outgoing segments.
820 
821   The Poll() function increases the rate that data is moved between the network
822   and application and can be called when the TCP instance is created successfully.
823   Its use is optional.
824 
825   @param[in] This                Pointer to the EFI_TCP6_PROTOCOL instance.
826 
827   @retval EFI_SUCCESS            Incoming or outgoing data was processed.
828   @retval EFI_INVALID_PARAMETER  This is NULL.
829   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.
830   @retval EFI_NOT_READY          No incoming or outgoing data is processed.
831   @retval EFI_TIMEOUT            Data was dropped out of the transmission or receive queue.
832                                  Consider increasing the polling rate.
833 
834 **/
835 typedef
836 EFI_STATUS
837 (EFIAPI *EFI_TCP6_POLL)(
838   IN EFI_TCP6_PROTOCOL        *This
839   );
840 
841 ///
842 /// EFI_TCP6_PROTOCOL
843 /// defines the EFI TCPv6 Protocol child to be used by any network drivers or
844 /// applications to send or receive data stream. It can either listen on a
845 /// specified port as a service or actively connect to remote peer as a client.
846 /// Each instance has its own independent settings.
847 ///
848 struct _EFI_TCP6_PROTOCOL {
849   EFI_TCP6_GET_MODE_DATA  GetModeData;
850   EFI_TCP6_CONFIGURE      Configure;
851   EFI_TCP6_CONNECT        Connect;
852   EFI_TCP6_ACCEPT         Accept;
853   EFI_TCP6_TRANSMIT       Transmit;
854   EFI_TCP6_RECEIVE        Receive;
855   EFI_TCP6_CLOSE          Close;
856   EFI_TCP6_CANCEL         Cancel;
857   EFI_TCP6_POLL           Poll;
858 };
859 
860 extern EFI_GUID gEfiTcp6ServiceBindingProtocolGuid;
861 extern EFI_GUID gEfiTcp6ProtocolGuid;
862 
863 #endif
864 
865