]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/TcpDxe/Socket.h
Add NetworkPkg (P.UDK2010.UP3.Network.P1)
[mirror_edk2.git] / NetworkPkg / TcpDxe / Socket.h
diff --git a/NetworkPkg/TcpDxe/Socket.h b/NetworkPkg/TcpDxe/Socket.h
new file mode 100644 (file)
index 0000000..a006252
--- /dev/null
@@ -0,0 +1,924 @@
+/** @file\r
+  Common head file for TCP socket.\r
+\r
+  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _SOCKET_H_\r
+#define _SOCKET_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/Tcp4.h>\r
+#include <Protocol/Tcp6.h>\r
+\r
+#include <Library/NetLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/DpcLib.h>\r
+\r
+#define SOCK_SND_BUF        0\r
+#define SOCK_RCV_BUF        1\r
+\r
+#define SOCK_BUFF_LOW_WATER (2 * 1024)\r
+#define SOCK_RCV_BUFF_SIZE  (8 * 1024)\r
+#define SOCK_SND_BUFF_SIZE  (8 * 1024)\r
+#define SOCK_BACKLOG        5\r
+\r
+#define PROTO_RESERVED_LEN  20\r
+\r
+#define SO_NO_MORE_DATA     0x0001\r
+\r
+//\r
+//\r
+//\r
+// When a socket is created it enters into SO_UNCONFIGURED,\r
+// no actions can be taken on this socket, only after calling\r
+// SockConfigure. The state transition diagram of socket is\r
+// as following:\r
+//\r
+// SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING\r
+//  ^      |                                    |\r
+//  |      --->  SO_LISTENING                   |\r
+//  |                                           |\r
+//  |------------------SO_DISCONNECTING<-- SO_CONNECTED\r
+//\r
+// A passive socket can only go into SO_LISTENING and\r
+// SO_UNCONFIGURED state. SO_XXXING state is a middle state\r
+// when a socket is undergoing a protocol procedure such\r
+// as requesting a TCP connection.\r
+//\r
+//\r
+//\r
+\r
+///\r
+/// Socket state\r
+///\r
+#define SO_CLOSED        0\r
+#define SO_LISTENING     1\r
+#define SO_CONNECTING    2\r
+#define SO_CONNECTED     3\r
+#define SO_DISCONNECTING 4\r
+\r
+///\r
+/// Socket configure state\r
+///\r
+#define SO_UNCONFIGURED        0\r
+#define SO_CONFIGURED_ACTIVE   1\r
+#define SO_CONFIGURED_PASSIVE  2\r
+#define SO_NO_MAPPING          3\r
+\r
+///\r
+///  The request issued from socket layer to protocol layer.\r
+///\r
+#define SOCK_ATTACH     0    ///< Attach current socket to a new PCB\r
+#define SOCK_DETACH     1    ///< Detach current socket from the PCB\r
+#define SOCK_CONFIGURE  2    ///< Configure attached PCB\r
+#define SOCK_FLUSH      3    ///< Flush attached PCB\r
+#define SOCK_SND        4    ///< Need protocol to send something\r
+#define SOCK_SNDPUSH    5    ///< Need protocol to send pushed data\r
+#define SOCK_SNDURG     6    ///< Need protocol to send urgent data\r
+#define SOCK_CONSUMED   7    ///< Application has retrieved data from socket\r
+#define SOCK_CONNECT    8    ///< Need to connect to a peer\r
+#define SOCK_CLOSE      9    ///< Need to close the protocol process\r
+#define SOCK_ABORT      10   ///< Need to reset the protocol process\r
+#define SOCK_POLL       11   ///< Need to poll to the protocol layer\r
+#define SOCK_ROUTE      12   ///< Need to add a route information\r
+#define SOCK_MODE       13   ///< Need to get the mode data of the protocol\r
+#define SOCK_GROUP      14   ///< Need to join a mcast group\r
+\r
+/**\r
+  Set socket SO_NO_MORE_DATA flag.\r
+\r
+  @param[in] Sock            Pointer to the socket\r
+\r
+**/\r
+#define SOCK_NO_MORE_DATA(Sock)     ((Sock)->Flag |= SO_NO_MORE_DATA)\r
+\r
+/**\r
+  Check whether the socket is unconfigured.\r
+\r
+  @param[in]  Sock           Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is unconfigued.\r
+  @retval FALSE              The socket is not unconfigued.\r
+\r
+**/\r
+#define SOCK_IS_UNCONFIGURED(Sock)  ((Sock)->ConfigureState == SO_UNCONFIGURED)\r
+\r
+/**\r
+  Check whether the socket is configured.\r
+\r
+  @param[in] Sock            Pointer to the socket\r
+\r
+  @retval TRUE               The socket is configued\r
+  @retval FALSE              The socket is not configued\r
+\r
+**/\r
+#define SOCK_IS_CONFIGURED(Sock) \\r
+    (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \\r
+    ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))\r
+\r
+/**\r
+  Check whether the socket is configured to active mode.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is configued to active mode.\r
+  @retval FALSE              The socket is not configued to active mode.\r
+\r
+**/\r
+#define SOCK_IS_CONFIGURED_ACTIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)\r
+\r
+/**\r
+  Check whether the socket is configured to passive mode.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is configued to passive mode.\r
+  @retval FALSE              The socket is not configued to passive mode.\r
+\r
+**/\r
+#define SOCK_IS_CONNECTED_PASSIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)\r
+\r
+/**\r
+  Check whether the socket is mapped.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is not mapping.\r
+  @retval FALSE              The socket is mapped.\r
+\r
+**/\r
+#define SOCK_IS_NO_MAPPING(Sock)  ((Sock)->ConfigureState == SO_NO_MAPPING)\r
+\r
+/**\r
+  Check whether the socket is closed.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is closed.\r
+  @retval FALSE              The socket is not closed.\r
+\r
+**/\r
+#define SOCK_IS_CLOSED(Sock)          ((Sock)->State == SO_CLOSED)\r
+\r
+/**\r
+  Check whether the socket is listening.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is listening.\r
+  @retval FALSE              The socket is not listening.\r
+\r
+**/\r
+#define SOCK_IS_LISTENING(Sock)       ((Sock)->State == SO_LISTENING)\r
+\r
+/**\r
+  Check whether the socket is connecting.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is connecting.\r
+  @retval FALSE              The socket is not connecting.\r
+\r
+**/\r
+#define SOCK_IS_CONNECTING(Sock)      ((Sock)->State == SO_CONNECTING)\r
+\r
+/**\r
+  Check whether the socket has connected.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket has connected.\r
+  @retval FALSE              The socket has not connected.\r
+\r
+**/\r
+#define SOCK_IS_CONNECTED(Sock)       ((Sock)->State == SO_CONNECTED)\r
+\r
+/**\r
+  Check whether the socket is disconnecting.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is disconnecting.\r
+  @retval FALSE              The socket is not disconnecting.\r
+\r
+**/\r
+#define SOCK_IS_DISCONNECTING(Sock)   ((Sock)->State == SO_DISCONNECTING)\r
+\r
+/**\r
+  Check whether the socket is no more data.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @retval TRUE               The socket is no more data.\r
+  @retval FALSE              The socket still has data.\r
+\r
+**/\r
+#define SOCK_IS_NO_MORE_DATA(Sock)    (0 != ((Sock)->Flag & SO_NO_MORE_DATA))\r
+\r
+/**\r
+  Set the size of the receive buffer.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+  @param[in] Size            The size to set.\r
+\r
+**/\r
+#define SET_RCV_BUFFSIZE(Sock, Size)  ((Sock)->RcvBuffer.HighWater = (Size))\r
+\r
+/**\r
+  Get the size of the receive buffer.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @return The receive buffer size.\r
+\r
+**/\r
+#define GET_RCV_BUFFSIZE(Sock)        ((Sock)->RcvBuffer.HighWater)\r
+\r
+/**\r
+  Get the size of the receive data.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @return The received data size.\r
+\r
+**/\r
+#define GET_RCV_DATASIZE(Sock)        (((Sock)->RcvBuffer.DataQueue)->BufSize)\r
+\r
+/**\r
+  Set the size of the send buffer.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+  @param[in] Size            The size to set.\r
+\r
+**/\r
+#define SET_SND_BUFFSIZE(Sock, Size)  ((Sock)->SndBuffer.HighWater = (Size))\r
+\r
+/**\r
+  Get the size of the send buffer.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @return The send buffer size.\r
+\r
+**/\r
+#define GET_SND_BUFFSIZE(Sock)        ((Sock)->SndBuffer.HighWater)\r
+\r
+/**\r
+  Get the size of the send data.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @return The send data size.\r
+\r
+**/\r
+#define GET_SND_DATASIZE(Sock)        (((Sock)->SndBuffer.DataQueue)->BufSize)\r
+\r
+/**\r
+  Set the backlog value of the socket.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+  @param[in] Value           The value to set.\r
+\r
+**/\r
+#define SET_BACKLOG(Sock, Value)      ((Sock)->BackLog = (Value))\r
+\r
+/**\r
+  Get the backlog value of the socket.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+\r
+  @return The backlog value.\r
+\r
+**/\r
+#define GET_BACKLOG(Sock)             ((Sock)->BackLog)\r
+\r
+/**\r
+  Set the socket with error state.\r
+\r
+  @param[in] Sock            Pointer to the socket.\r
+  @param[in] Error           The error state.\r
+\r
+**/\r
+#define SOCK_ERROR(Sock, Error)       ((Sock)->SockError = (Error))\r
+\r
+#define SOCK_SIGNATURE                SIGNATURE_32 ('S', 'O', 'C', 'K')\r
+\r
+#define SOCK_FROM_THIS(a)             CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)\r
+\r
+#define SOCK_FROM_TOKEN(Token)        (((SOCK_TOKEN *) (Token))->Sock)\r
+\r
+#define PROTO_TOKEN_FORM_SOCK(SockToken, Type)  ((Type *) (((SOCK_TOKEN *) (SockToken))->Token))\r
+\r
+typedef struct _TCP_SOCKET SOCKET;\r
+\r
+///\r
+/// Socket completion token\r
+///\r
+typedef struct _SOCK_COMPLETION_TOKEN {\r
+  EFI_EVENT   Event;            ///< The event to be issued\r
+  EFI_STATUS  Status;           ///< The status to be issued\r
+} SOCK_COMPLETION_TOKEN;\r
+\r
+typedef union {\r
+  VOID  *RxData;\r
+  VOID  *TxData;\r
+} SOCK_IO_DATA;\r
+\r
+///\r
+/// The application token with data packet\r
+///\r
+typedef struct _SOCK_IO_TOKEN {\r
+  SOCK_COMPLETION_TOKEN Token;\r
+  SOCK_IO_DATA          Packet;\r
+} SOCK_IO_TOKEN;\r
+\r
+///\r
+///  The socket type.\r
+///\r
+typedef enum {\r
+  SockDgram, ///< This socket providing datagram service\r
+  SockStream ///< This socket providing stream service\r
+} SOCK_TYPE;\r
+\r
+///\r
+///  The buffer structure of rcvd data and send data used by socket.\r
+///\r
+typedef struct _SOCK_BUFFER {\r
+  UINT32        HighWater;  ///< The buffersize upper limit of sock_buffer\r
+  UINT32        LowWater;   ///< The low warter mark of sock_buffer\r
+  NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data\r
+} SOCK_BUFFER;\r
+\r
+/**\r
+  The handler of protocol for request from socket.\r
+\r
+  @param[in] Socket          The socket issuing the request to protocol.\r
+  @param[in] Request         The request issued by socket.\r
+  @param[in] RequestData     The request related data.\r
+\r
+  @retval EFI_SUCCESS        The socket request is completed successfully.\r
+  @retval other              The error status returned by the corresponding TCP\r
+                             layer function.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(*SOCK_PROTO_HANDLER) (\r
+  IN SOCKET       *Socket,\r
+  IN UINT8        Request,\r
+  IN VOID         *RequestData\r
+  );\r
+\r
+/**\r
+  The Callback funtion called after the TCP socket is created.\r
+\r
+  @param[in]  This            Pointer to the socket just created.\r
+  @param[in]  Context         Context of the socket.\r
+\r
+  @retval EFI_SUCCESS         This protocol installed successfully.\r
+  @retval other               Some error occured.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(*SOCK_CREATE_CALLBACK) (\r
+  IN SOCKET  *This,\r
+  IN VOID    *Context\r
+  );\r
+\r
+/**\r
+  The callback function called before the TCP socket is to be destroyed.\r
+\r
+  @param[in]  This                   The TCP socket to be destroyed.\r
+  @param[in]  Context                The context.\r
+\r
+**/\r
+typedef\r
+VOID\r
+(*SOCK_DESTROY_CALLBACK) (\r
+  IN SOCKET  *This,\r
+  IN VOID    *Context\r
+  );\r
+\r
+///\r
+///  The initialize data for create a new socket.\r
+///\r
+typedef struct _SOCK_INIT_DATA {\r
+  SOCK_TYPE              Type;\r
+  UINT8                  State;\r
+\r
+  SOCKET                 *Parent;        ///< The parent of this socket\r
+  UINT32                 BackLog;        ///< The connection limit for listening socket\r
+  UINT32                 SndBufferSize;  ///< The high warter mark of send buffer\r
+  UINT32                 RcvBufferSize;  ///< The high warter mark of receive buffer\r
+  UINT8                  IpVersion;\r
+  VOID                   *Protocol;      ///< The pointer to protocol function template\r
+                                         ///< wanted to install on socket\r
+\r
+  //\r
+  // Callbacks after socket is created and before socket is to be destroyed.\r
+  //\r
+  SOCK_CREATE_CALLBACK   CreateCallback;  ///< Callback after created\r
+  SOCK_DESTROY_CALLBACK  DestroyCallback; ///< Callback before destroied\r
+  VOID                   *Context;        ///< The context of the callback\r
+\r
+  //\r
+  // Opaque protocol data.\r
+  //\r
+  VOID                   *ProtoData;\r
+  UINT32                 DataSize;\r
+\r
+  SOCK_PROTO_HANDLER     ProtoHandler;    ///< The handler of protocol for socket request\r
+\r
+  EFI_HANDLE             DriverBinding;   ///< The driver binding handle\r
+} SOCK_INIT_DATA;\r
+\r
+///\r
+///  The union type of TCP and UDP protocol.\r
+///\r
+typedef union _NET_PROTOCOL {\r
+  EFI_TCP4_PROTOCOL      Tcp4Protocol;    ///< Tcp4 protocol\r
+  EFI_TCP6_PROTOCOL      Tcp6Protocol;    ///< Tcp6 protocol\r
+} NET_PROTOCOL;\r
+///\r
+/// The socket structure representing a network service access point.\r
+///\r
+struct _TCP_SOCKET {\r
+  //\r
+  // Socket description information\r
+  //\r
+  UINT32                    Signature;      ///< Signature of the socket\r
+  EFI_HANDLE                SockHandle;     ///< The virtual handle of the socket\r
+  EFI_HANDLE                DriverBinding;  ///< Socket's driver binding protocol\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  LIST_ENTRY                Link;\r
+  UINT8                     ConfigureState;\r
+  SOCK_TYPE                 Type;\r
+  UINT8                     State;\r
+  UINT16                    Flag;\r
+  EFI_LOCK                  Lock;           ///< The lock of socket\r
+  SOCK_BUFFER               SndBuffer;      ///< Send buffer of application's data\r
+  SOCK_BUFFER               RcvBuffer;      ///< Receive buffer of received data\r
+  EFI_STATUS                SockError;      ///< The error returned by low layer protocol\r
+  BOOLEAN                   IsDestroyed;\r
+\r
+  //\r
+  // Fields used to manage the connection request\r
+  //\r
+  UINT32                    BackLog;        ///< the limit of connection to this socket\r
+  UINT32                    ConnCnt;        ///< the current count of connections to it\r
+  SOCKET                    *Parent;        ///< listening parent that accept the connection\r
+  LIST_ENTRY                ConnectionList; ///< the connections maintained by this socket\r
+  //\r
+  // The queue to buffer application's asynchronous token\r
+  //\r
+  LIST_ENTRY                ListenTokenList;\r
+  LIST_ENTRY                RcvTokenList;\r
+  LIST_ENTRY                SndTokenList;\r
+  LIST_ENTRY                ProcessingSndTokenList;\r
+\r
+  SOCK_COMPLETION_TOKEN     *ConnectionToken; ///< app's token to signal if connected\r
+  SOCK_COMPLETION_TOKEN     *CloseToken;      ///< app's token to signal if closed\r
+  //\r
+  // Interface for low level protocol\r
+  //\r
+  SOCK_PROTO_HANDLER        ProtoHandler;     ///< The request handler of protocol\r
+  UINT8                     ProtoReserved[PROTO_RESERVED_LEN];  ///< Data fields reserved for protocol\r
+  UINT8                     IpVersion;\r
+  NET_PROTOCOL              NetProtocol;                        ///< TCP or UDP protocol socket used\r
+  //\r
+  // Callbacks after socket is created and before socket is to be destroyed.\r
+  //\r
+  SOCK_CREATE_CALLBACK      CreateCallback;   ///< Callback after created\r
+  SOCK_DESTROY_CALLBACK     DestroyCallback;  ///< Callback before destroied\r
+  VOID                      *Context;         ///< The context of the callback\r
+};\r
+\r
+///\r
+///  The token structure buffered in socket layer.\r
+///\r
+typedef struct _SOCK_TOKEN {\r
+  LIST_ENTRY            TokenList;      ///< The entry to add in the token list\r
+  SOCK_COMPLETION_TOKEN *Token;         ///< The application's token\r
+  UINT32                RemainDataLen;  ///< Unprocessed data length\r
+  SOCKET                *Sock;          ///< The poninter to the socket this token\r
+                                        ///< belongs to\r
+} SOCK_TOKEN;\r
+\r
+///\r
+/// Reserved data to access the NET_BUF delivered by TCP driver.\r
+///\r
+typedef struct _TCP_RSV_DATA {\r
+  UINT32 UrgLen;\r
+} TCP_RSV_DATA;\r
+\r
+//\r
+// Socket provided oprerations for low layer protocol implemented in SockImpl.c\r
+//\r
+\r
+/**\r
+  Set the state of the socket.\r
+\r
+  @param[in, out]  Sock                  Pointer to the socket.\r
+  @param[in]       State                 The new socket state to be set.\r
+\r
+**/\r
+VOID\r
+SockSetState (\r
+  IN OUT SOCKET     *Sock,\r
+  IN     UINT8      State\r
+  );\r
+\r
+/**\r
+  Clone a new socket including its associated protocol control block.\r
+\r
+  @param[in]  Sock                  Pointer to the socket to be cloned.\r
+\r
+  @return Pointer to the newly cloned socket. If NULL, an error condition occurred.\r
+\r
+**/\r
+SOCKET *\r
+SockClone (\r
+  IN SOCKET *Sock\r
+  );\r
+\r
+/**\r
+  Called by the low layer protocol to indicate the socket a connection is\r
+  established.\r
+\r
+  This function just changes the socket's state to SO_CONNECTED\r
+  and signals the token used for connection establishment.\r
+\r
+  @param[in, out]  Sock         Pointer to the socket associated with the\r
+                                established connection.\r
+\r
+**/\r
+VOID\r
+SockConnEstablished (\r
+  IN OUT SOCKET *Sock\r
+  );\r
+\r
+/**\r
+  Called by the low layer protocol to indicate that the connection is closed.\r
+\r
+  This function flushes the socket, sets the state to SO_CLOSED, and signals\r
+  the close token.\r
+\r
+  @param[in, out]  Sock         Pointer to the socket associated with the closed\r
+                                connection.\r
+\r
+**/\r
+VOID\r
+SockConnClosed (\r
+  IN OUT SOCKET *Sock\r
+  );\r
+\r
+/**\r
+  Called by low layer protocol to indicate that some data is sent or processed.\r
+\r
+  This function trims the sent data in the socket send buffer and signals the data\r
+  token, if proper.\r
+\r
+  @param[in, out]  Sock      Pointer to the socket.\r
+  @param[in]       Count     The length of the data processed or sent, in bytes.\r
+\r
+**/\r
+VOID\r
+SockDataSent (\r
+  IN OUT SOCKET     *Sock,\r
+  IN     UINT32     Count\r
+  );\r
+\r
+/**\r
+  Called by the low layer protocol to copy some data in socket send\r
+  buffer starting from the specific offset to a buffer provided by\r
+  the caller.\r
+\r
+  @param[in]  Sock                  Pointer to the socket.\r
+  @param[in]  Offset                The start point of the data to be copied.\r
+  @param[in]  Len                   The length of the data to be copied.\r
+  @param[out] Dest                  Pointer to the destination to copy the data.\r
+\r
+  @return The data size copied.\r
+\r
+**/\r
+UINT32\r
+SockGetDataToSend (\r
+  IN  SOCKET      *Sock,\r
+  IN  UINT32      Offset,\r
+  IN  UINT32      Len,\r
+  OUT UINT8       *Dest\r
+  );\r
+\r
+/**\r
+  Called by the low layer protocol to deliver received data to socket layer.\r
+\r
+  This function appends the data to the socket receive buffer, set the\r
+  urgent data length, then checks if any receive token can be signaled.\r
+\r
+  @param[in, out]  Sock       Pointer to the socket.\r
+  @param[in, out]  NetBuffer  Pointer to the buffer that contains the received data.\r
+  @param[in]       UrgLen     The length of the urgent data in the received data.\r
+\r
+**/\r
+VOID\r
+SockDataRcvd (\r
+  IN OUT SOCKET    *Sock,\r
+  IN OUT NET_BUF   *NetBuffer,\r
+  IN     UINT32    UrgLen\r
+  );\r
+\r
+/**\r
+  Get the length of the free space of the specific socket buffer.\r
+\r
+  @param[in]  Sock              Pointer to the socket.\r
+  @param[in]  Which             Flag to indicate which socket buffer to check:\r
+                                either send buffer or receive buffer.\r
+\r
+  @return The length of the free space, in bytes.\r
+\r
+**/\r
+UINT32\r
+SockGetFreeSpace (\r
+  IN SOCKET  *Sock,\r
+  IN UINT32  Which\r
+  );\r
+\r
+/**\r
+  Called by the low layer protocol to indicate that there will be no more data\r
+  from the communication peer.\r
+\r
+  This function sets the socket's state to SO_NO_MORE_DATA and signals all queued\r
+  IO tokens with the error status EFI_CONNECTION_FIN.\r
+\r
+  @param[in, out]  Sock                  Pointer to the socket.\r
+\r
+**/\r
+VOID\r
+SockNoMoreData (\r
+  IN OUT SOCKET *Sock\r
+  );\r
+\r
+//\r
+// Socket provided operations for user interface implemented in SockInterface.c\r
+//\r
+\r
+/**\r
+  Create a socket and its associated protocol control block\r
+  with the intial data SockInitData and protocol specific\r
+  data ProtoData.\r
+\r
+  @param[in]  SockInitData         Inital data to setting the socket.\r
+\r
+  @return Pointer to the newly created socket. If NULL, an error condition occured.\r
+\r
+**/\r
+SOCKET *\r
+SockCreateChild (\r
+  IN SOCK_INIT_DATA *SockInitData\r
+  );\r
+\r
+/**\r
+  Destory the socket Sock and its associated protocol control block.\r
+\r
+  @param[in, out]  Sock                 The socket to be destroyed.\r
+\r
+  @retval EFI_SUCCESS          The socket Sock was destroyed successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.\r
+\r
+**/\r
+EFI_STATUS\r
+SockDestroyChild (\r
+  IN OUT SOCKET *Sock\r
+  );\r
+\r
+/**\r
+  Configure the specific socket Sock using configuration data ConfigData.\r
+\r
+  @param[in]  Sock             Pointer to the socket to be configured.\r
+  @param[in]  ConfigData       Pointer to the configuration data.\r
+\r
+  @retval EFI_SUCCESS          The socket configured successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the\r
+                               socket is already configured.\r
+\r
+**/\r
+EFI_STATUS\r
+SockConfigure (\r
+  IN SOCKET *Sock,\r
+  IN VOID   *ConfigData\r
+  );\r
+\r
+/**\r
+  Initiate a connection establishment process.\r
+\r
+  @param[in]  Sock             Pointer to the socket to initiate the initate the\r
+                               connection.\r
+  @param[in]  Token            Pointer to the token used for the connection\r
+                               operation.\r
+\r
+  @retval EFI_SUCCESS          The connection initialized successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the\r
+                               socket is closed, or the socket is not configured to\r
+                               be an active one, or the token is already in one of\r
+                               this socket's lists.\r
+  @retval EFI_NO_MAPPING       The IP address configuration operation is not\r
+                               finished.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+\r
+**/\r
+EFI_STATUS\r
+SockConnect (\r
+  IN SOCKET *Sock,\r
+  IN VOID   *Token\r
+  );\r
+\r
+/**\r
+  Issue a listen token to get an existed connected network instance,\r
+  or wait for a connection if there is none.\r
+\r
+  @param[in]  Sock             Pointer to the socket to accept connections.\r
+  @param[in]  Token            The token to accept a connection.\r
+\r
+  @retval EFI_SUCCESS          Either a connection is accepted or the Token is\r
+                               buffered for further acceptance.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the\r
+                               socket is closed, or the socket is not configured to\r
+                               be a passive one, or the token is already in one of\r
+                               this socket's lists.\r
+  @retval EFI_NO_MAPPING       The IP address configuration operation is not\r
+                               finished.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+  @retval EFI_OUT_OF_RESOURCE  Failed to buffer the Token due to memory limit.\r
+\r
+**/\r
+EFI_STATUS\r
+SockAccept (\r
+  IN SOCKET *Sock,\r
+  IN VOID   *Token\r
+  );\r
+\r
+/**\r
+  Issue a token with data to the socket to send out.\r
+\r
+  @param[in]  Sock             Pointer to the socket to process the token with\r
+                               data.\r
+  @param[in]  Token            The token with data that needs to send out.\r
+\r
+  @retval EFI_SUCCESS          The token processed successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the\r
+                               socket is closed, or the socket is not in a\r
+                               synchronized state , or the token is already in one\r
+                               of this socket's lists.\r
+  @retval EFI_NO_MAPPING       The IP address configuration operation is not\r
+                               finished.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+  @retval EFI_OUT_OF_RESOURCE  Failed to buffer the token due to a memory limit.\r
+\r
+**/\r
+EFI_STATUS\r
+SockSend (\r
+  IN SOCKET *Sock,\r
+  IN VOID   *Token\r
+  );\r
+\r
+/**\r
+  Issue a token to get data from the socket.\r
+\r
+  @param[in]  Sock             Pointer to the socket to get data from.\r
+  @param[in]  Token            The token to store the received data from the\r
+                               socket.\r
+\r
+  @retval EFI_SUCCESS          The token processed successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the\r
+                               socket is closed, or the socket is not in a\r
+                               synchronized state , or the token is already in one\r
+                               of this socket's lists.\r
+  @retval EFI_NO_MAPPING       The IP address configuration operation is not\r
+                               finished.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+  @retval EFI_CONNECTION_FIN   The connection is closed and there is no more data.\r
+  @retval EFI_OUT_OF_RESOURCE  Failed to buffer the token due to a memory limit.\r
+\r
+**/\r
+EFI_STATUS\r
+SockRcv (\r
+  IN SOCKET *Sock,\r
+  IN VOID   *Token\r
+  );\r
+\r
+/**\r
+  Reset the socket and its associated protocol control block.\r
+\r
+  @param[in, out]  Sock        Pointer to the socket to be flushed.\r
+\r
+  @retval EFI_SUCCESS          The socket flushed successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.\r
+\r
+**/\r
+EFI_STATUS\r
+SockFlush (\r
+  IN OUT SOCKET *Sock\r
+  );\r
+\r
+/**\r
+  Close or abort the socket associated connection.\r
+\r
+  @param[in, out]  Sock        Pointer to the socket of the connection to close\r
+                               or abort.\r
+  @param[in]  Token            The token for close operation.\r
+  @param[in]  OnAbort          TRUE for aborting the connection, FALSE to close it.\r
+\r
+  @retval EFI_SUCCESS          The close or abort operation initialized\r
+                               successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket, or the\r
+                               socket is closed, or the socket is not in a\r
+                               synchronized state , or the token is already in one\r
+                               of this socket's lists.\r
+  @retval EFI_NO_MAPPING       The IP address configuration operation is not\r
+                               finished.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+\r
+**/\r
+EFI_STATUS\r
+SockClose (\r
+  IN OUT SOCKET  *Sock,\r
+  IN     VOID    *Token,\r
+  IN     BOOLEAN OnAbort\r
+  );\r
+\r
+/**\r
+  Get the mode data of the low layer protocol.\r
+\r
+  @param[in]       Sock        Pointer to the socket to get mode data from.\r
+  @param[in, out]  Mode        Pointer to the data to store the low layer mode\r
+                               information.\r
+\r
+  @retval EFI_SUCCESS          The mode data was obtained successfully.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+\r
+**/\r
+EFI_STATUS\r
+SockGetMode (\r
+  IN     SOCKET *Sock,\r
+  IN OUT VOID   *Mode\r
+  );\r
+\r
+/**\r
+  Configure the low level protocol to join a multicast group for\r
+  this socket's connection.\r
+\r
+  @param[in]  Sock             Pointer to the socket of the connection to join the\r
+                               specific multicast group.\r
+  @param[in]  GroupInfo        Pointer to the multicast group information.\r
+\r
+  @retval EFI_SUCCESS          The configuration completed successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+\r
+**/\r
+EFI_STATUS\r
+SockGroup (\r
+  IN SOCKET *Sock,\r
+  IN VOID   *GroupInfo\r
+  );\r
+\r
+/**\r
+  Add or remove route information in IP route table associated\r
+  with this socket.\r
+\r
+  @param[in]  Sock             Pointer to the socket associated with the IP route\r
+                               table to operate on.\r
+  @param[in]  RouteInfo        Pointer to the route information to be processed.\r
+\r
+  @retval EFI_SUCCESS          The route table updated successfully.\r
+  @retval EFI_ACCESS_DENIED    Failed to get the lock to access the socket.\r
+  @retval EFI_NO_MAPPING       The IP address configuration operation is  not\r
+                               finished.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+\r
+**/\r
+EFI_STATUS\r
+SockRoute (\r
+  IN SOCKET    *Sock,\r
+  IN VOID      *RouteInfo\r
+  );\r
+\r
+#endif\r