Home | History | Annotate | Download | only in TcpDxe
      1 /** @file
      2   Common head file for TCP socket.
      3 
      4   Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
      5 
      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.
     10 
     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.
     13 
     14 **/
     15 
     16 #ifndef _SOCKET_H_
     17 #define _SOCKET_H_
     18 
     19 #include <Uefi.h>
     20 
     21 #include <Protocol/Tcp4.h>
     22 #include <Protocol/Tcp6.h>
     23 
     24 #include <Library/NetLib.h>
     25 #include <Library/DebugLib.h>
     26 #include <Library/BaseMemoryLib.h>
     27 #include <Library/MemoryAllocationLib.h>
     28 #include <Library/UefiRuntimeServicesTableLib.h>
     29 #include <Library/UefiBootServicesTableLib.h>
     30 #include <Library/UefiLib.h>
     31 #include <Library/DpcLib.h>
     32 
     33 #define SOCK_SND_BUF        0
     34 #define SOCK_RCV_BUF        1
     35 
     36 #define SOCK_BUFF_LOW_WATER (2 * 1024)
     37 #define SOCK_RCV_BUFF_SIZE  (8 * 1024)
     38 #define SOCK_SND_BUFF_SIZE  (8 * 1024)
     39 #define SOCK_BACKLOG        5
     40 
     41 #define PROTO_RESERVED_LEN  20
     42 
     43 #define SO_NO_MORE_DATA     0x0001
     44 
     45 //
     46 //
     47 //
     48 // When a socket is created it enters into SO_UNCONFIGURED,
     49 // no actions can be taken on this socket, only after calling
     50 // SockConfigure. The state transition diagram of socket is
     51 // as following:
     52 //
     53 // SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING
     54 //  ^      |                                    |
     55 //  |      --->  SO_LISTENING                   |
     56 //  |                                           |
     57 //  |------------------SO_DISCONNECTING<-- SO_CONNECTED
     58 //
     59 // A passive socket can only go into SO_LISTENING and
     60 // SO_UNCONFIGURED state. SO_XXXING state is a middle state
     61 // when a socket is undergoing a protocol procedure such
     62 // as requesting a TCP connection.
     63 //
     64 //
     65 //
     66 
     67 ///
     68 /// Socket state
     69 ///
     70 #define SO_CLOSED        0
     71 #define SO_LISTENING     1
     72 #define SO_CONNECTING    2
     73 #define SO_CONNECTED     3
     74 #define SO_DISCONNECTING 4
     75 
     76 ///
     77 /// Socket configure state
     78 ///
     79 #define SO_UNCONFIGURED        0
     80 #define SO_CONFIGURED_ACTIVE   1
     81 #define SO_CONFIGURED_PASSIVE  2
     82 #define SO_NO_MAPPING          3
     83 
     84 ///
     85 ///  The request issued from socket layer to protocol layer.
     86 ///
     87 #define SOCK_ATTACH     0    ///< Attach current socket to a new PCB
     88 #define SOCK_DETACH     1    ///< Detach current socket from the PCB
     89 #define SOCK_CONFIGURE  2    ///< Configure attached PCB
     90 #define SOCK_FLUSH      3    ///< Flush attached PCB
     91 #define SOCK_SND        4    ///< Need protocol to send something
     92 #define SOCK_SNDPUSH    5    ///< Need protocol to send pushed data
     93 #define SOCK_SNDURG     6    ///< Need protocol to send urgent data
     94 #define SOCK_CONSUMED   7    ///< Application has retrieved data from socket
     95 #define SOCK_CONNECT    8    ///< Need to connect to a peer
     96 #define SOCK_CLOSE      9    ///< Need to close the protocol process
     97 #define SOCK_ABORT      10   ///< Need to reset the protocol process
     98 #define SOCK_POLL       11   ///< Need to poll to the protocol layer
     99 #define SOCK_ROUTE      12   ///< Need to add a route information
    100 #define SOCK_MODE       13   ///< Need to get the mode data of the protocol
    101 #define SOCK_GROUP      14   ///< Need to join a mcast group
    102 
    103 /**
    104   Set socket SO_NO_MORE_DATA flag.
    105 
    106   @param[in] Sock            Pointer to the socket
    107 
    108 **/
    109 #define SOCK_NO_MORE_DATA(Sock)     ((Sock)->Flag |= SO_NO_MORE_DATA)
    110 
    111 /**
    112   Check whether the socket is unconfigured.
    113 
    114   @param[in]  Sock           Pointer to the socket.
    115 
    116   @retval TRUE               The socket is unconfigued.
    117   @retval FALSE              The socket is not unconfigued.
    118 
    119 **/
    120 #define SOCK_IS_UNCONFIGURED(Sock)  ((Sock)->ConfigureState == SO_UNCONFIGURED)
    121 
    122 /**
    123   Check whether the socket is configured.
    124 
    125   @param[in] Sock            Pointer to the socket
    126 
    127   @retval TRUE               The socket is configued
    128   @retval FALSE              The socket is not configued
    129 
    130 **/
    131 #define SOCK_IS_CONFIGURED(Sock) \
    132     (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \
    133     ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))
    134 
    135 /**
    136   Check whether the socket is configured to active mode.
    137 
    138   @param[in] Sock            Pointer to the socket.
    139 
    140   @retval TRUE               The socket is configued to active mode.
    141   @retval FALSE              The socket is not configued to active mode.
    142 
    143 **/
    144 #define SOCK_IS_CONFIGURED_ACTIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)
    145 
    146 /**
    147   Check whether the socket is configured to passive mode.
    148 
    149   @param[in] Sock            Pointer to the socket.
    150 
    151   @retval TRUE               The socket is configued to passive mode.
    152   @retval FALSE              The socket is not configued to passive mode.
    153 
    154 **/
    155 #define SOCK_IS_CONNECTED_PASSIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)
    156 
    157 /**
    158   Check whether the socket is mapped.
    159 
    160   @param[in] Sock            Pointer to the socket.
    161 
    162   @retval TRUE               The socket is not mapping.
    163   @retval FALSE              The socket is mapped.
    164 
    165 **/
    166 #define SOCK_IS_NO_MAPPING(Sock)  ((Sock)->ConfigureState == SO_NO_MAPPING)
    167 
    168 /**
    169   Check whether the socket is closed.
    170 
    171   @param[in] Sock            Pointer to the socket.
    172 
    173   @retval TRUE               The socket is closed.
    174   @retval FALSE              The socket is not closed.
    175 
    176 **/
    177 #define SOCK_IS_CLOSED(Sock)          ((Sock)->State == SO_CLOSED)
    178 
    179 /**
    180   Check whether the socket is listening.
    181 
    182   @param[in] Sock            Pointer to the socket.
    183 
    184   @retval TRUE               The socket is listening.
    185   @retval FALSE              The socket is not listening.
    186 
    187 **/
    188 #define SOCK_IS_LISTENING(Sock)       ((Sock)->State == SO_LISTENING)
    189 
    190 /**
    191   Check whether the socket is connecting.
    192 
    193   @param[in] Sock            Pointer to the socket.
    194 
    195   @retval TRUE               The socket is connecting.
    196   @retval FALSE              The socket is not connecting.
    197 
    198 **/
    199 #define SOCK_IS_CONNECTING(Sock)      ((Sock)->State == SO_CONNECTING)
    200 
    201 /**
    202   Check whether the socket has connected.
    203 
    204   @param[in] Sock            Pointer to the socket.
    205 
    206   @retval TRUE               The socket has connected.
    207   @retval FALSE              The socket has not connected.
    208 
    209 **/
    210 #define SOCK_IS_CONNECTED(Sock)       ((Sock)->State == SO_CONNECTED)
    211 
    212 /**
    213   Check whether the socket is disconnecting.
    214 
    215   @param[in] Sock            Pointer to the socket.
    216 
    217   @retval TRUE               The socket is disconnecting.
    218   @retval FALSE              The socket is not disconnecting.
    219 
    220 **/
    221 #define SOCK_IS_DISCONNECTING(Sock)   ((Sock)->State == SO_DISCONNECTING)
    222 
    223 /**
    224   Check whether the socket is no more data.
    225 
    226   @param[in] Sock            Pointer to the socket.
    227 
    228   @retval TRUE               The socket is no more data.
    229   @retval FALSE              The socket still has data.
    230 
    231 **/
    232 #define SOCK_IS_NO_MORE_DATA(Sock)    (0 != ((Sock)->Flag & SO_NO_MORE_DATA))
    233 
    234 /**
    235   Set the size of the receive buffer.
    236 
    237   @param[in] Sock            Pointer to the socket.
    238   @param[in] Size            The size to set.
    239 
    240 **/
    241 #define SET_RCV_BUFFSIZE(Sock, Size)  ((Sock)->RcvBuffer.HighWater = (Size))
    242 
    243 /**
    244   Get the size of the receive buffer.
    245 
    246   @param[in] Sock            Pointer to the socket.
    247 
    248   @return The receive buffer size.
    249 
    250 **/
    251 #define GET_RCV_BUFFSIZE(Sock)        ((Sock)->RcvBuffer.HighWater)
    252 
    253 /**
    254   Get the size of the receive data.
    255 
    256   @param[in] Sock            Pointer to the socket.
    257 
    258   @return The received data size.
    259 
    260 **/
    261 #define GET_RCV_DATASIZE(Sock)        (((Sock)->RcvBuffer.DataQueue)->BufSize)
    262 
    263 /**
    264   Set the size of the send buffer.
    265 
    266   @param[in] Sock            Pointer to the socket.
    267   @param[in] Size            The size to set.
    268 
    269 **/
    270 #define SET_SND_BUFFSIZE(Sock, Size)  ((Sock)->SndBuffer.HighWater = (Size))
    271 
    272 /**
    273   Get the size of the send buffer.
    274 
    275   @param[in] Sock            Pointer to the socket.
    276 
    277   @return The send buffer size.
    278 
    279 **/
    280 #define GET_SND_BUFFSIZE(Sock)        ((Sock)->SndBuffer.HighWater)
    281 
    282 /**
    283   Get the size of the send data.
    284 
    285   @param[in] Sock            Pointer to the socket.
    286 
    287   @return The send data size.
    288 
    289 **/
    290 #define GET_SND_DATASIZE(Sock)        (((Sock)->SndBuffer.DataQueue)->BufSize)
    291 
    292 /**
    293   Set the backlog value of the socket.
    294 
    295   @param[in] Sock            Pointer to the socket.
    296   @param[in] Value           The value to set.
    297 
    298 **/
    299 #define SET_BACKLOG(Sock, Value)      ((Sock)->BackLog = (Value))
    300 
    301 /**
    302   Get the backlog value of the socket.
    303 
    304   @param[in] Sock            Pointer to the socket.
    305 
    306   @return The backlog value.
    307 
    308 **/
    309 #define GET_BACKLOG(Sock)             ((Sock)->BackLog)
    310 
    311 /**
    312   Set the socket with error state.
    313 
    314   @param[in] Sock            Pointer to the socket.
    315   @param[in] Error           The error state.
    316 
    317 **/
    318 #define SOCK_ERROR(Sock, Error)       ((Sock)->SockError = (Error))
    319 
    320 #define SOCK_SIGNATURE                SIGNATURE_32 ('S', 'O', 'C', 'K')
    321 
    322 #define SOCK_FROM_THIS(a)             CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)
    323 
    324 #define SOCK_FROM_TOKEN(Token)        (((SOCK_TOKEN *) (Token))->Sock)
    325 
    326 #define PROTO_TOKEN_FORM_SOCK(SockToken, Type)  ((Type *) (((SOCK_TOKEN *) (SockToken))->Token))
    327 
    328 typedef struct _TCP_SOCKET SOCKET;
    329 
    330 ///
    331 /// Socket completion token
    332 ///
    333 typedef struct _SOCK_COMPLETION_TOKEN {
    334   EFI_EVENT   Event;            ///< The event to be issued
    335   EFI_STATUS  Status;           ///< The status to be issued
    336 } SOCK_COMPLETION_TOKEN;
    337 
    338 typedef union {
    339   VOID  *RxData;
    340   VOID  *TxData;
    341 } SOCK_IO_DATA;
    342 
    343 ///
    344 /// The application token with data packet
    345 ///
    346 typedef struct _SOCK_IO_TOKEN {
    347   SOCK_COMPLETION_TOKEN Token;
    348   SOCK_IO_DATA          Packet;
    349 } SOCK_IO_TOKEN;
    350 
    351 ///
    352 ///  The socket type.
    353 ///
    354 typedef enum {
    355   SockDgram, ///< This socket providing datagram service
    356   SockStream ///< This socket providing stream service
    357 } SOCK_TYPE;
    358 
    359 ///
    360 ///  The buffer structure of rcvd data and send data used by socket.
    361 ///
    362 typedef struct _SOCK_BUFFER {
    363   UINT32        HighWater;  ///< The buffersize upper limit of sock_buffer
    364   UINT32        LowWater;   ///< The low warter mark of sock_buffer
    365   NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data
    366 } SOCK_BUFFER;
    367 
    368 /**
    369   The handler of protocol for request from socket.
    370 
    371   @param[in] Socket          The socket issuing the request to protocol.
    372   @param[in] Request         The request issued by socket.
    373   @param[in] RequestData     The request related data.
    374 
    375   @retval EFI_SUCCESS        The socket request is completed successfully.
    376   @retval other              The error status returned by the corresponding TCP
    377                              layer function.
    378 
    379 **/
    380 typedef
    381 EFI_STATUS
    382 (*SOCK_PROTO_HANDLER) (
    383   IN SOCKET       *Socket,
    384   IN UINT8        Request,
    385   IN VOID         *RequestData
    386   );
    387 
    388 /**
    389   The Callback funtion called after the TCP socket is created.
    390 
    391   @param[in]  This            Pointer to the socket just created.
    392   @param[in]  Context         Context of the socket.
    393 
    394   @retval EFI_SUCCESS         This protocol installed successfully.
    395   @retval other               Some error occured.
    396 
    397 **/
    398 typedef
    399 EFI_STATUS
    400 (*SOCK_CREATE_CALLBACK) (
    401   IN SOCKET  *This,
    402   IN VOID    *Context
    403   );
    404 
    405 /**
    406   The callback function called before the TCP socket is to be destroyed.
    407 
    408   @param[in]  This                   The TCP socket to be destroyed.
    409   @param[in]  Context                The context.
    410 
    411 **/
    412 typedef
    413 VOID
    414 (*SOCK_DESTROY_CALLBACK) (
    415   IN SOCKET  *This,
    416   IN VOID    *Context
    417   );
    418 
    419 ///
    420 ///  The initialize data for create a new socket.
    421 ///
    422 typedef struct _SOCK_INIT_DATA {
    423   SOCK_TYPE              Type;
    424   UINT8                  State;
    425 
    426   SOCKET                 *Parent;        ///< The parent of this socket
    427   UINT32                 BackLog;        ///< The connection limit for listening socket
    428   UINT32                 SndBufferSize;  ///< The high warter mark of send buffer
    429   UINT32                 RcvBufferSize;  ///< The high warter mark of receive buffer
    430   UINT8                  IpVersion;
    431   VOID                   *Protocol;      ///< The pointer to protocol function template
    432                                          ///< wanted to install on socket
    433 
    434   //
    435   // Callbacks after socket is created and before socket is to be destroyed.
    436   //
    437   SOCK_CREATE_CALLBACK   CreateCallback;  ///< Callback after created
    438   SOCK_DESTROY_CALLBACK  DestroyCallback; ///< Callback before destroied
    439   VOID                   *Context;        ///< The context of the callback
    440 
    441   //
    442   // Opaque protocol data.
    443   //
    444   VOID                   *ProtoData;
    445   UINT32                 DataSize;
    446 
    447   SOCK_PROTO_HANDLER     ProtoHandler;    ///< The handler of protocol for socket request
    448 
    449   EFI_HANDLE             DriverBinding;   ///< The driver binding handle
    450 } SOCK_INIT_DATA;
    451 
    452 ///
    453 ///  The union type of TCP and UDP protocol.
    454 ///
    455 typedef union _NET_PROTOCOL {
    456   EFI_TCP4_PROTOCOL      Tcp4Protocol;    ///< Tcp4 protocol
    457   EFI_TCP6_PROTOCOL      Tcp6Protocol;    ///< Tcp6 protocol
    458 } NET_PROTOCOL;
    459 ///
    460 /// The socket structure representing a network service access point.
    461 ///
    462 struct _TCP_SOCKET {
    463   //
    464   // Socket description information
    465   //
    466   UINT32                    Signature;      ///< Signature of the socket
    467   EFI_HANDLE                SockHandle;     ///< The virtual handle of the socket
    468   EFI_HANDLE                DriverBinding;  ///< Socket's driver binding protocol
    469   EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;
    470   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    471   LIST_ENTRY                Link;
    472   UINT8                     ConfigureState;
    473   SOCK_TYPE                 Type;
    474   UINT8                     State;
    475   UINT16                    Flag;
    476   EFI_LOCK                  Lock;           ///< The lock of socket
    477   SOCK_BUFFER               SndBuffer;      ///< Send buffer of application's data
    478   SOCK_BUFFER               RcvBuffer;      ///< Receive buffer of received data
    479   EFI_STATUS                SockError;      ///< The error returned by low layer protocol
    480   BOOLEAN                   InDestroy;
    481 
    482   //
    483   // Fields used to manage the connection request
    484   //
    485   UINT32                    BackLog;        ///< the limit of connection to this socket
    486   UINT32                    ConnCnt;        ///< the current count of connections to it
    487   SOCKET                    *Parent;        ///< listening parent that accept the connection
    488   LIST_ENTRY                ConnectionList; ///< the connections maintained by this socket
    489   //
    490   // The queue to buffer application's asynchronous token
    491   //
    492   LIST_ENTRY                ListenTokenList;
    493   LIST_ENTRY                RcvTokenList;
    494   LIST_ENTRY                SndTokenList;
    495   LIST_ENTRY                ProcessingSndTokenList;
    496 
    497   SOCK_COMPLETION_TOKEN     *ConnectionToken; ///< app's token to signal if connected
    498   SOCK_COMPLETION_TOKEN     *CloseToken;      ///< app's token to signal if closed
    499   //
    500   // Interface for low level protocol
    501   //
    502   SOCK_PROTO_HANDLER        ProtoHandler;     ///< The request handler of protocol
    503   UINT8                     ProtoReserved[PROTO_RESERVED_LEN];  ///< Data fields reserved for protocol
    504   UINT8                     IpVersion;
    505   NET_PROTOCOL              NetProtocol;                        ///< TCP or UDP protocol socket used
    506   //
    507   // Callbacks after socket is created and before socket is to be destroyed.
    508   //
    509   SOCK_CREATE_CALLBACK      CreateCallback;   ///< Callback after created
    510   SOCK_DESTROY_CALLBACK     DestroyCallback;  ///< Callback before destroied
    511   VOID                      *Context;         ///< The context of the callback
    512 };
    513 
    514 ///
    515 ///  The token structure buffered in socket layer.
    516 ///
    517 typedef struct _SOCK_TOKEN {
    518   LIST_ENTRY            TokenList;      ///< The entry to add in the token list
    519   SOCK_COMPLETION_TOKEN *Token;         ///< The application's token
    520   UINT32                RemainDataLen;  ///< Unprocessed data length
    521   SOCKET                *Sock;          ///< The poninter to the socket this token
    522                                         ///< belongs to
    523 } SOCK_TOKEN;
    524 
    525 ///
    526 /// Reserved data to access the NET_BUF delivered by TCP driver.
    527 ///
    528 typedef struct _TCP_RSV_DATA {
    529   UINT32 UrgLen;
    530 } TCP_RSV_DATA;
    531 
    532 //
    533 // Socket provided oprerations for low layer protocol implemented in SockImpl.c
    534 //
    535 
    536 /**
    537   Set the state of the socket.
    538 
    539   @param[in, out]  Sock                  Pointer to the socket.
    540   @param[in]       State                 The new socket state to be set.
    541 
    542 **/
    543 VOID
    544 SockSetState (
    545   IN OUT SOCKET     *Sock,
    546   IN     UINT8      State
    547   );
    548 
    549 /**
    550   Clone a new socket including its associated protocol control block.
    551 
    552   @param[in]  Sock                  Pointer to the socket to be cloned.
    553 
    554   @return Pointer to the newly cloned socket. If NULL, an error condition occurred.
    555 
    556 **/
    557 SOCKET *
    558 SockClone (
    559   IN SOCKET *Sock
    560   );
    561 
    562 /**
    563   Called by the low layer protocol to indicate the socket a connection is
    564   established.
    565 
    566   This function just changes the socket's state to SO_CONNECTED
    567   and signals the token used for connection establishment.
    568 
    569   @param[in, out]  Sock         Pointer to the socket associated with the
    570                                 established connection.
    571 
    572 **/
    573 VOID
    574 SockConnEstablished (
    575   IN OUT SOCKET *Sock
    576   );
    577 
    578 /**
    579   Called by the low layer protocol to indicate that the connection is closed.
    580 
    581   This function flushes the socket, sets the state to SO_CLOSED, and signals
    582   the close token.
    583 
    584   @param[in, out]  Sock         Pointer to the socket associated with the closed
    585                                 connection.
    586 
    587 **/
    588 VOID
    589 SockConnClosed (
    590   IN OUT SOCKET *Sock
    591   );
    592 
    593 /**
    594   Called by low layer protocol to indicate that some data is sent or processed.
    595 
    596   This function trims the sent data in the socket send buffer and signals the data
    597   token, if proper.
    598 
    599   @param[in, out]  Sock      Pointer to the socket.
    600   @param[in]       Count     The length of the data processed or sent, in bytes.
    601 
    602 **/
    603 VOID
    604 SockDataSent (
    605   IN OUT SOCKET     *Sock,
    606   IN     UINT32     Count
    607   );
    608 
    609 /**
    610   Called by the low layer protocol to copy some data in socket send
    611   buffer starting from the specific offset to a buffer provided by
    612   the caller.
    613 
    614   @param[in]  Sock                  Pointer to the socket.
    615   @param[in]  Offset                The start point of the data to be copied.
    616   @param[in]  Len                   The length of the data to be copied.
    617   @param[out] Dest                  Pointer to the destination to copy the data.
    618 
    619   @return The data size copied.
    620 
    621 **/
    622 UINT32
    623 SockGetDataToSend (
    624   IN  SOCKET      *Sock,
    625   IN  UINT32      Offset,
    626   IN  UINT32      Len,
    627   OUT UINT8       *Dest
    628   );
    629 
    630 /**
    631   Called by the low layer protocol to deliver received data to socket layer.
    632 
    633   This function appends the data to the socket receive buffer, set the
    634   urgent data length, then checks if any receive token can be signaled.
    635 
    636   @param[in, out]  Sock       Pointer to the socket.
    637   @param[in, out]  NetBuffer  Pointer to the buffer that contains the received data.
    638   @param[in]       UrgLen     The length of the urgent data in the received data.
    639 
    640 **/
    641 VOID
    642 SockDataRcvd (
    643   IN OUT SOCKET    *Sock,
    644   IN OUT NET_BUF   *NetBuffer,
    645   IN     UINT32    UrgLen
    646   );
    647 
    648 /**
    649   Get the length of the free space of the specific socket buffer.
    650 
    651   @param[in]  Sock              Pointer to the socket.
    652   @param[in]  Which             Flag to indicate which socket buffer to check:
    653                                 either send buffer or receive buffer.
    654 
    655   @return The length of the free space, in bytes.
    656 
    657 **/
    658 UINT32
    659 SockGetFreeSpace (
    660   IN SOCKET  *Sock,
    661   IN UINT32  Which
    662   );
    663 
    664 /**
    665   Called by the low layer protocol to indicate that there will be no more data
    666   from the communication peer.
    667 
    668   This function sets the socket's state to SO_NO_MORE_DATA and signals all queued
    669   IO tokens with the error status EFI_CONNECTION_FIN.
    670 
    671   @param[in, out]  Sock                  Pointer to the socket.
    672 
    673 **/
    674 VOID
    675 SockNoMoreData (
    676   IN OUT SOCKET *Sock
    677   );
    678 
    679 //
    680 // Socket provided operations for user interface implemented in SockInterface.c
    681 //
    682 
    683 /**
    684   Create a socket and its associated protocol control block
    685   with the intial data SockInitData and protocol specific
    686   data ProtoData.
    687 
    688   @param[in]  SockInitData         Inital data to setting the socket.
    689 
    690   @return Pointer to the newly created socket. If NULL, an error condition occured.
    691 
    692 **/
    693 SOCKET *
    694 SockCreateChild (
    695   IN SOCK_INIT_DATA *SockInitData
    696   );
    697 
    698 /**
    699   Destroy the socket Sock and its associated protocol control block.
    700 
    701   @param[in, out]  Sock                 The socket to be destroyed.
    702 
    703   @retval EFI_SUCCESS          The socket Sock was destroyed successfully.
    704   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.
    705 
    706 **/
    707 EFI_STATUS
    708 SockDestroyChild (
    709   IN OUT SOCKET *Sock
    710   );
    711 
    712 /**
    713   Configure the specific socket Sock using configuration data ConfigData.
    714 
    715   @param[in]  Sock             Pointer to the socket to be configured.
    716   @param[in]  ConfigData       Pointer to the configuration data.
    717 
    718   @retval EFI_SUCCESS          The socket configured successfully.
    719   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the
    720                                socket is already configured.
    721 
    722 **/
    723 EFI_STATUS
    724 SockConfigure (
    725   IN SOCKET *Sock,
    726   IN VOID   *ConfigData
    727   );
    728 
    729 /**
    730   Initiate a connection establishment process.
    731 
    732   @param[in]  Sock             Pointer to the socket to initiate the initate the
    733                                connection.
    734   @param[in]  Token            Pointer to the token used for the connection
    735                                operation.
    736 
    737   @retval EFI_SUCCESS          The connection initialized successfully.
    738   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the
    739                                socket is closed, or the socket is not configured to
    740                                be an active one, or the token is already in one of
    741                                this socket's lists.
    742   @retval EFI_NO_MAPPING       The IP address configuration operation is not
    743                                finished.
    744   @retval EFI_NOT_STARTED      The socket is not configured.
    745 
    746 **/
    747 EFI_STATUS
    748 SockConnect (
    749   IN SOCKET *Sock,
    750   IN VOID   *Token
    751   );
    752 
    753 /**
    754   Issue a listen token to get an existed connected network instance,
    755   or wait for a connection if there is none.
    756 
    757   @param[in]  Sock             Pointer to the socket to accept connections.
    758   @param[in]  Token            The token to accept a connection.
    759 
    760   @retval EFI_SUCCESS          Either a connection is accepted or the Token is
    761                                buffered for further acceptance.
    762   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the
    763                                socket is closed, or the socket is not configured to
    764                                be a passive one, or the token is already in one of
    765                                this socket's lists.
    766   @retval EFI_NO_MAPPING       The IP address configuration operation is not
    767                                finished.
    768   @retval EFI_NOT_STARTED      The socket is not configured.
    769   @retval EFI_OUT_OF_RESOURCE  Failed to buffer the Token due to memory limit.
    770 
    771 **/
    772 EFI_STATUS
    773 SockAccept (
    774   IN SOCKET *Sock,
    775   IN VOID   *Token
    776   );
    777 
    778 /**
    779   Issue a token with data to the socket to send out.
    780 
    781   @param[in]  Sock             Pointer to the socket to process the token with
    782                                data.
    783   @param[in]  Token            The token with data that needs to send out.
    784 
    785   @retval EFI_SUCCESS          The token processed successfully.
    786   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the
    787                                socket is closed, or the socket is not in a
    788                                synchronized state , or the token is already in one
    789                                of this socket's lists.
    790   @retval EFI_NO_MAPPING       The IP address configuration operation is not
    791                                finished.
    792   @retval EFI_NOT_STARTED      The socket is not configured.
    793   @retval EFI_OUT_OF_RESOURCE  Failed to buffer the token due to a memory limit.
    794 
    795 **/
    796 EFI_STATUS
    797 SockSend (
    798   IN SOCKET *Sock,
    799   IN VOID   *Token
    800   );
    801 
    802 /**
    803   Issue a token to get data from the socket.
    804 
    805   @param[in]  Sock             Pointer to the socket to get data from.
    806   @param[in]  Token            The token to store the received data from the
    807                                socket.
    808 
    809   @retval EFI_SUCCESS          The token processed successfully.
    810   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the
    811                                socket is closed, or the socket is not in a
    812                                synchronized state , or the token is already in one
    813                                of this socket's lists.
    814   @retval EFI_NO_MAPPING       The IP address configuration operation is not
    815                                finished.
    816   @retval EFI_NOT_STARTED      The socket is not configured.
    817   @retval EFI_CONNECTION_FIN   The connection is closed and there is no more data.
    818   @retval EFI_OUT_OF_RESOURCE  Failed to buffer the token due to a memory limit.
    819 
    820 **/
    821 EFI_STATUS
    822 SockRcv (
    823   IN SOCKET *Sock,
    824   IN VOID   *Token
    825   );
    826 
    827 /**
    828   Reset the socket and its associated protocol control block.
    829 
    830   @param[in, out]  Sock        Pointer to the socket to be flushed.
    831 
    832   @retval EFI_SUCCESS          The socket flushed successfully.
    833   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.
    834 
    835 **/
    836 EFI_STATUS
    837 SockFlush (
    838   IN OUT SOCKET *Sock
    839   );
    840 
    841 /**
    842   Close or abort the socket associated connection.
    843 
    844   @param[in, out]  Sock        Pointer to the socket of the connection to close
    845                                or abort.
    846   @param[in]  Token            The token for close operation.
    847   @param[in]  OnAbort          TRUE for aborting the connection, FALSE to close it.
    848 
    849   @retval EFI_SUCCESS          The close or abort operation initialized
    850                                successfully.
    851   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the
    852                                socket is closed, or the socket is not in a
    853                                synchronized state , or the token is already in one
    854                                of this socket's lists.
    855   @retval EFI_NO_MAPPING       The IP address configuration operation is not
    856                                finished.
    857   @retval EFI_NOT_STARTED      The socket is not configured.
    858 
    859 **/
    860 EFI_STATUS
    861 SockClose (
    862   IN OUT SOCKET  *Sock,
    863   IN     VOID    *Token,
    864   IN     BOOLEAN OnAbort
    865   );
    866 
    867 /**
    868   Abort the socket associated connection, listen, transmission or receive request.
    869 
    870   @param[in, out]  Sock        Pointer to the socket to abort.
    871   @param[in]       Token       Pointer to a token that has been issued by
    872                                Connect(), Accept(), Transmit() or Receive(). If
    873                                NULL, all pending tokens issued by the four
    874                                functions listed above will be aborted.
    875 
    876   @retval EFI_UNSUPPORTED      The operation is not supported in the current
    877                                implementation.
    878 **/
    879 EFI_STATUS
    880 SockCancel (
    881   IN OUT SOCKET  *Sock,
    882   IN     VOID    *Token
    883   );
    884 
    885 /**
    886   Get the mode data of the low layer protocol.
    887 
    888   @param[in]       Sock        Pointer to the socket to get mode data from.
    889   @param[in, out]  Mode        Pointer to the data to store the low layer mode
    890                                information.
    891 
    892   @retval EFI_SUCCESS          The mode data was obtained successfully.
    893   @retval EFI_NOT_STARTED      The socket is not configured.
    894 
    895 **/
    896 EFI_STATUS
    897 SockGetMode (
    898   IN     SOCKET *Sock,
    899   IN OUT VOID   *Mode
    900   );
    901 
    902 /**
    903   Configure the low level protocol to join a multicast group for
    904   this socket's connection.
    905 
    906   @param[in]  Sock             Pointer to the socket of the connection to join the
    907                                specific multicast group.
    908   @param[in]  GroupInfo        Pointer to the multicast group information.
    909 
    910   @retval EFI_SUCCESS          The configuration completed successfully.
    911   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.
    912   @retval EFI_NOT_STARTED      The socket is not configured.
    913 
    914 **/
    915 EFI_STATUS
    916 SockGroup (
    917   IN SOCKET *Sock,
    918   IN VOID   *GroupInfo
    919   );
    920 
    921 /**
    922   Add or remove route information in IP route table associated
    923   with this socket.
    924 
    925   @param[in]  Sock             Pointer to the socket associated with the IP route
    926                                table to operate on.
    927   @param[in]  RouteInfo        Pointer to the route information to be processed.
    928 
    929   @retval EFI_SUCCESS          The route table updated successfully.
    930   @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.
    931   @retval EFI_NO_MAPPING       The IP address configuration operation is  not
    932                                finished.
    933   @retval EFI_NOT_STARTED      The socket is not configured.
    934 
    935 **/
    936 EFI_STATUS
    937 SockRoute (
    938   IN SOCKET    *Sock,
    939   IN VOID      *RouteInfo
    940   );
    941 
    942 #endif
    943