]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
Fix several syntax issue to pass build.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Socket.h
index 2e35f5ecd715ca8e0d53ef1394be8607038daa4a..3c687063c2431803e3beb9ee719003d97d7db5b1 100644 (file)
@@ -1,21 +1,14 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation\r
+Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
 All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php<BR>\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
-Module Name:\r
-\r
-  Socket.h\r
-\r
-Abstract:\r
-\r
-\r
 **/\r
 \r
 #ifndef _SOCKET_H_\r
@@ -23,7 +16,7 @@ Abstract:
 \r
 #include <PiDxe.h>\r
 \r
-#include <Protocol/IP4.h>\r
+#include <Protocol/Ip4.h>\r
 #include <Protocol/Tcp4.h>\r
 #include <Protocol/Udp4.h>\r
 \r
@@ -40,9 +33,9 @@ Abstract:
 #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_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
@@ -70,6 +63,10 @@ Abstract:
 //\r
 //\r
 //\r
+\r
+///\r
+/// Socket state\r
+///\r
 typedef enum {\r
   SO_CLOSED       = 0,\r
   SO_LISTENING,\r
@@ -78,6 +75,9 @@ typedef enum {
   SO_DISCONNECTING\r
 } SOCK_STATE;\r
 \r
+///\r
+/// Socket configure state\r
+///\r
 typedef enum {\r
   SO_UNCONFIGURED       = 0,\r
   SO_CONFIGURED_ACTIVE,\r
@@ -102,21 +102,21 @@ typedef enum {
 #define SOCK_IS_NO_MAPPING(Sock) \\r
   ((Sock)->ConfigureState == SO_NO_MAPPING)\r
 \r
-#define SOCK_IS_CLOSED(Sock)         ((Sock)->State == SO_CLOSED)\r
+#define SOCK_IS_CLOSED(Sock)          ((Sock)->State == SO_CLOSED)\r
 \r
-#define SOCK_IS_LISTENING(Sock)      ((Sock)->State == SO_LISTENING)\r
+#define SOCK_IS_LISTENING(Sock)       ((Sock)->State == SO_LISTENING)\r
 \r
-#define SOCK_IS_CONNECTING(Sock)     ((Sock)->State == SO_CONNECTING)\r
+#define SOCK_IS_CONNECTING(Sock)      ((Sock)->State == SO_CONNECTING)\r
 \r
-#define SOCK_IS_CONNECTED(Sock)      ((Sock)->State == SO_CONNECTED)\r
+#define SOCK_IS_CONNECTED(Sock)       ((Sock)->State == SO_CONNECTED)\r
 \r
-#define SOCK_IS_DISCONNECTING(Sock)  ((Sock)->State == SO_DISCONNECTING)\r
+#define SOCK_IS_DISCONNECTING(Sock)   ((Sock)->State == SO_DISCONNECTING)\r
 \r
-#define SOCK_IS_NO_MORE_DATA(Sock)   (0 != ((Sock)->Flag & SO_NO_MORE_DATA))\r
+#define SOCK_IS_NO_MORE_DATA(Sock)    (0 != ((Sock)->Flag & SO_NO_MORE_DATA))\r
 \r
-#define SOCK_SIGNATURE           EFI_SIGNATURE_32 ('S', 'O', 'C', 'K')\r
+#define SOCK_SIGNATURE                EFI_SIGNATURE_32 ('S', 'O', 'C', 'K')\r
 \r
-#define SOCK_FROM_THIS(a)        CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)\r
+#define SOCK_FROM_THIS(a)             CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)\r
 \r
 #define SET_RCV_BUFFSIZE(Sock, Size)  ((Sock)->RcvBuffer.HighWater = (Size))\r
 \r
@@ -149,11 +149,17 @@ typedef enum {
 \r
 typedef struct _SOCKET SOCKET;\r
 \r
+///\r
+/// Socket completion token\r
+///\r
 typedef struct _SOCK_COMPLETION_TOKEN {\r
-  EFI_EVENT   Event;\r
-  EFI_STATUS  Status;\r
+  EFI_EVENT   Event;            ///< The event to be issued\r
+  EFI_STATUS  Status;           ///< The status to be issued\r
 } SOCK_COMPLETION_TOKEN;\r
 \r
+///\r
+/// The application token with data packet\r
+///\r
 typedef struct _SOCK_IO_TOKEN {\r
   SOCK_COMPLETION_TOKEN Token;\r
   union {\r
@@ -162,150 +168,230 @@ typedef struct _SOCK_IO_TOKEN {
   } Packet;\r
 } SOCK_IO_TOKEN;\r
 \r
-//\r
-// the request issued from socket layer to protocol layer\r
-//\r
+///\r
+///  The request issued from socket layer to protocol layer.  \r
+///\r
 typedef enum {\r
-  SOCK_ATTACH,    // attach current socket to a new PCB\r
-  SOCK_DETACH,    // detach current socket from the PCB\r
-  SOCK_CONFIGURE, // configure attached PCB\r
-  SOCK_FLUSH,     // flush attached PCB\r
-  SOCK_SND,       // need protocol to send something\r
-  SOCK_SNDPUSH,   // need protocol to send pushed data\r
-  SOCK_SNDURG,    // need protocol to send urgent data\r
-  SOCK_CONSUMED,  // application has retrieved data from socket\r
-  SOCK_CONNECT,   // need to connect to a peer\r
-  SOCK_CLOSE,     // need to close the protocol process\r
-  SOCK_ABORT,     // need to reset the protocol process\r
-  SOCK_POLL,      // need to poll to the protocol layer\r
-  SOCK_ROUTE,     // need to add a route information\r
-  SOCK_MODE,      // need to get the mode data of the protocol\r
-  SOCK_GROUP      // need to join a mcast group\r
+  SOCK_ATTACH,    ///< Attach current socket to a new PCB\r
+  SOCK_DETACH,    ///< Detach current socket from the PCB\r
+  SOCK_CONFIGURE, ///< Configure attached PCB\r
+  SOCK_FLUSH,     ///< Flush attached PCB\r
+  SOCK_SND,       ///< Need protocol to send something\r
+  SOCK_SNDPUSH,   ///< Need protocol to send pushed data\r
+  SOCK_SNDURG,    ///< Need protocol to send urgent data\r
+  SOCK_CONSUMED,  ///< Application has retrieved data from socket\r
+  SOCK_CONNECT,   ///< Need to connect to a peer\r
+  SOCK_CLOSE,     ///< Need to close the protocol process\r
+  SOCK_ABORT,     ///< Need to reset the protocol process\r
+  SOCK_POLL,      ///< Need to poll to the protocol layer\r
+  SOCK_ROUTE,     ///< Need to add a route information\r
+  SOCK_MODE,      ///< Need to get the mode data of the protocol\r
+  SOCK_GROUP      ///< Need to join a mcast group\r
 } SOCK_REQUEST;\r
 \r
-//\r
-// the socket type\r
-//\r
+///\r
+///  The socket type.\r
+///\r
 typedef enum {\r
-  SOCK_DGRAM, // this socket providing datagram service\r
-  SOCK_STREAM // this socket providing stream service\r
+  SOCK_DGRAM, ///< This socket providing datagram service\r
+  SOCK_STREAM ///< This socket providing stream service\r
 } SOCK_TYPE;\r
 \r
-//\r
-// the handler of protocol for request from socket\r
-//\r
+///\r
+///  The handler of protocol for request from socket.\r
+///\r
 typedef\r
 EFI_STATUS\r
 (*SOCK_PROTO_HANDLER) (\r
-  IN SOCKET       * Socket,  // the socket issuing the request to protocol\r
-  IN SOCK_REQUEST Request,   // the request issued by socket\r
-  IN VOID *RequestData       // the request related data\r
+  IN SOCKET       *Socket,      ///< The socket issuing the request to protocol\r
+  IN SOCK_REQUEST Request,      ///< The request issued by socket\r
+  IN VOID         *RequestData  ///< The request related data\r
   );\r
 \r
-//\r
-// the buffer structure of rcvd data and send data used by socket\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
+  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
 //\r
-// socket provided oprerations for low layer protocol\r
+// Socket provided oprerations for low layer protocol\r
 //\r
 \r
 //\r
-// socket provided operations for user interface\r
+// Socket provided operations for user interface\r
 //\r
+\r
+/**\r
+  Set the state of the socket.\r
+\r
+  @param  Sock                  Pointer to the socket.\r
+  @param  State                 The new state to be set.\r
+\r
+**/\r
 VOID\r
 SockSetState (\r
   IN SOCKET     *Sock,\r
   IN SOCK_STATE State\r
   );\r
 \r
-//\r
-// when the connection establishment process for a Sock\r
-// is finished low layer protocol calling this function\r
-// to notify socket layer\r
-//\r
+/**\r
+  Called by the low layer protocol to indicate the socket a connection is \r
+  established. This function just changes the socket's state to SO_CONNECTED \r
+  and signals the token used for connection establishment.\r
+\r
+  @param  Sock                  Pointer to the socket associated with the\r
+                                established connection.\r
+                                \r
+**/\r
 VOID\r
 SockConnEstablished (\r
   IN SOCKET *Sock\r
   );\r
 \r
+/**\r
+  Called by the low layer protocol to indicate the connection is closed; This \r
+  function flushes the socket, sets the state to SO_CLOSED and signals the close \r
+  token.\r
+\r
+  @param  Sock                  Pointer to the socket associated with the closed\r
+                                connection.\r
+                                \r
+**/\r
 VOID\r
 SockConnClosed (\r
   IN SOCKET *Sock\r
   );\r
 \r
-//\r
-// called by low layer protocol to trim send buffer of\r
-// Sock, when Count data is sent out completely\r
-//\r
+/**\r
+  Called by low layer protocol to indicate that some data is sent or processed; \r
+  This function trims the sent data in the socket send buffer, signals the data \r
+  token if proper.\r
+\r
+  @param  Sock                  Pointer to the socket.\r
+  @param  Count                 The length of the data processed or sent, in bytes.\r
+\r
+**/\r
 VOID\r
 SockDataSent (\r
-  IN SOCKET  *Sock,\r
-  IN UINT32  Count\r
+  IN SOCKET     *Sock,\r
+  IN UINT32     Count\r
   );\r
 \r
-//\r
-// called by low layer protocol to get Len of data from\r
-// socket to send and copy it in Dest\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  Sock                  Pointer to the socket.\r
+  @param  Offset                The start point of the data to be copied.\r
+  @param  Len                   The length of the data to be copied.\r
+  @param  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
-  IN UINT8  *Dest\r
+  IN SOCKET      *Sock,\r
+  IN UINT32      Offset,\r
+  IN UINT32      Len,\r
+  IN UINT8       *Dest\r
   );\r
 \r
-//\r
-//  called by low layer protocol to notify socket no more data can be\r
-//  received\r
-//\r
+/**\r
+  Called by the low layer protocol to indicate that there\r
+  will be no more data from the communication peer; This\r
+  function set the socket's state to SO_NO_MORE_DATA and\r
+  signal all queued IO tokens with the error status\r
+  EFI_CONNECTION_FIN.\r
+\r
+  @param  Sock                  Pointer to the socket.\r
+\r
+**/\r
 VOID\r
 SockNoMoreData (\r
   IN SOCKET *Sock\r
   );\r
 \r
-//\r
-// called by low layer protocol to append a NetBuffer\r
-// to rcv buffer of sock\r
-//\r
+/**\r
+  Called by the low layer protocol to deliver received data to socket layer; \r
+  This function will append the data to the socket receive buffer, set ther \r
+  urgent data length and then check if any receive token can be signaled.\r
+\r
+  @param  Sock                  Pointer to the socket.\r
+  @param  NetBuffer             Pointer to the buffer that contains the received\r
+                                data.\r
+  @param  UrgLen                The length of the urgent data in the received data.\r
+\r
+**/\r
 VOID\r
 SockDataRcvd (\r
   IN SOCKET    *Sock,\r
   IN NET_BUF   *NetBuffer,\r
-  IN UINT32     UrgLen\r
+  IN UINT32    UrgLen\r
   );\r
 \r
+/**\r
+  Get the length of the free space of the specific socket buffer.\r
+\r
+  @param  Sock                  Pointer to the socket.\r
+  @param  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
+  IN SOCKET  *Sock,\r
+  IN UINT32  Which\r
   );\r
 \r
-SOCKET  *\r
+/**\r
+  Clone a new socket including its associated protocol control block.\r
+\r
+  @param  Sock                  Pointer to the socket to be cloned.\r
+\r
+  @return Pointer to the newly cloned socket. If NULL, error condition occurred.\r
+\r
+**/\r
+SOCKET *\r
 SockClone (\r
   IN SOCKET *Sock\r
   );\r
 \r
+/**\r
+  Signal the receive token with the specific error or\r
+  set socket error code after error is received.\r
+\r
+  @param  Sock                  Pointer to the socket.\r
+  @param  Error                 The error code received.\r
+\r
+**/\r
 VOID\r
 SockRcvdErr (\r
   IN SOCKET       *Sock,\r
   IN EFI_STATUS   Error\r
   );\r
 \r
+///\r
+/// Proto type of the create callback\r
+///\r
 typedef\r
 EFI_STATUS\r
 (*SOCK_CREATE_CALLBACK) (\r
   IN SOCKET  *This,\r
   IN VOID    *Context\r
   );\r
-\r
+  \r
+///\r
+/// Proto type of the destroy callback \r
+///\r
 typedef\r
 VOID\r
 (*SOCK_DESTROY_CALLBACK) (\r
@@ -313,26 +399,26 @@ VOID
   IN VOID    *Context\r
   );\r
 \r
-//\r
-// the initialize data for create a new socket\r
-//\r
+///\r
+///  The initialize data for create a new socket.\r
+///\r
 typedef struct _SOCK_INIT_DATA {\r
   SOCK_TYPE   Type;\r
   SOCK_STATE  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
-  VOID        *Protocol;      // the pointer to protocol function template\r
-                              // wanted to install on socket\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
+  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;\r
-  SOCK_DESTROY_CALLBACK  DestroyCallback;\r
-  VOID                   *Context;\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
@@ -340,168 +426,280 @@ typedef struct _SOCK_INIT_DATA {
   VOID                   *ProtoData;\r
   UINT32                 DataSize;\r
 \r
-  SOCK_PROTO_HANDLER     ProtoHandler;\r
+  SOCK_PROTO_HANDLER     ProtoHandler;  ///< The handler of protocol for socket request\r
 \r
-  EFI_HANDLE   DriverBinding; // the driver binding handle\r
+  EFI_HANDLE   DriverBinding;           ///< The driver binding handle\r
 } SOCK_INIT_DATA;\r
-//\r
-// the socket structure representing a network service access point\r
-//\r
+\r
+///\r
+///  The union type of TCP and UDP protocol.\r
+///  \r
+typedef union _NET_PROTOCOL {\r
+  EFI_TCP4_PROTOCOL TcpProtocol;   ///< Tcp protocol\r
+  EFI_UDP4_PROTOCOL UdpProtocol;   ///< Udp protocol\r
+} NET_PROTOCOL;\r
+\r
+///\r
+/// The socket structure representing a network service access point\r
+///\r
 struct _SOCKET {\r
 \r
   //\r
-  // socket description information\r
+  // Socket description information\r
   //\r
-  UINT32                Signature;\r
-  EFI_HANDLE            SockHandle;     // the virtual handle of the socket\r
-  EFI_HANDLE            DriverBinding;  // socket't driver binding protocol\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
-  NET_LIST_ENTRY            Link;  \r
+  LIST_ENTRY                Link;  \r
   SOCK_CONFIGURE_STATE  ConfigureState;\r
   SOCK_TYPE             Type;\r
   SOCK_STATE            State;\r
   UINT16                Flag;\r
-  NET_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
+  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
+  // 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
-  NET_LIST_ENTRY  ConnectionList; // the connections maintained by this socket\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
   //\r
-  // the queue to buffer application's asynchronous token\r
+  // The queue to buffer application's asynchronous token\r
   //\r
-  NET_LIST_ENTRY  ListenTokenList;\r
-  NET_LIST_ENTRY  RcvTokenList;\r
-  NET_LIST_ENTRY  SndTokenList;\r
-  NET_LIST_ENTRY  ProcessingSndTokenList;\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
+  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
   //\r
-  // interface for low level protocol\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
-  union {\r
-    EFI_TCP4_PROTOCOL TcpProtocol;\r
-    EFI_UDP4_PROTOCOL UdpProtocol;\r
-  } NetProtocol;\r
+  SOCK_PROTO_HANDLER    ProtoHandler;       ///< The request handler of protocol\r
+  UINT8 ProtoReserved[PROTO_RESERVED_LEN];  ///< Data fields reserved for protocol\r
+  NET_PROTOCOL          NetProtocol;        ///< TCP or UDP protocol socket used\r
 \r
   //\r
-  // Callbacks.\r
+  // Callbacks after socket is created and before socket is to be destroyed.\r
   //\r
-  SOCK_CREATE_CALLBACK   CreateCallback;\r
-  SOCK_DESTROY_CALLBACK  DestroyCallback;\r
-  VOID                   *Context;\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
+///\r
+///  The token structure buffered in socket layer.\r
+///\r
 typedef struct _SOCK_TOKEN {\r
-  NET_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
+  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 UDP driver\r
-//\r
+///\r
+/// Reserved data to access the NET_BUF delivered by UDP driver.\r
+///\r
 typedef struct _UDP_RSV_DATA {\r
   EFI_TIME              TimeStamp;\r
   EFI_UDP4_SESSION_DATA Session;\r
 } UDP_RSV_DATA;\r
 \r
-//\r
-// reserved data to access the NET_BUF delivered by TCP driver\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
-// call it to creat a socket and attach it to a PCB\r
-//\r
-SOCKET  *\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  SockInitData         Inital data to setting the socket.\r
+  \r
+  @return Pointer to the newly created socket. If NULL, error condition occured.\r
+\r
+**/\r
+SOCKET *\r
 SockCreateChild (\r
   IN SOCK_INIT_DATA *SockInitData\r
   );\r
 \r
-//\r
-// call it to destroy a socket and its related PCB\r
-//\r
+/**\r
+  Destory the socket Sock and its associated protocol control block.\r
+\r
+  @param  Sock                 The socket to be destroyed.\r
+\r
+  @retval EFI_SUCCESS          The socket Sock is 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 SOCKET *Sock\r
+  IN   SOCKET *Sock\r
   );\r
 \r
-//\r
-// call it to configure a socket and its related PCB\r
-//\r
+/**\r
+  Configure the specific socket Sock using configuration data ConfigData.\r
+\r
+  @param  Sock                 Pointer to the socket to be configured.\r
+  @param  ConfigData           Pointer to the configuration data.\r
+\r
+  @retval EFI_SUCCESS          The socket is 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
-// call it to connect a socket to the peer\r
-//\r
+/**\r
+  Initiate a connection establishment process.\r
+\r
+  @param  Sock                 Pointer to the socket to initiate the initate the\r
+                               connection.\r
+  @param  Token                Pointer to the token used for the connection\r
+                               operation.\r
+\r
+  @retval EFI_SUCCESS          The connection is 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
-// call it to issue an asynchronous listen token to the socket\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  Sock                 Pointer to the socket to accept connections.\r
+  @param  Token                The token to accept a connection.\r
+\r
+  @retval EFI_SUCCESS          Either a connection is accpeted or the Token is\r
+                               buffered for further acception.\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
-// Call it to send data using this socket\r
-//\r
+/**\r
+  Issue a token with data to the socket to send out.\r
+\r
+  @param  Sock                 Pointer to the socket to process the token with\r
+                               data.\r
+  @param  Token                The token with data that needs to send out.\r
+\r
+  @retval EFI_SUCCESS          The token is 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 memory limit.\r
+\r
+**/\r
 EFI_STATUS\r
 SockSend (\r
   IN SOCKET *Sock,\r
   IN VOID   *Token\r
   );\r
 \r
-//\r
-// Call it to receive data from this socket\r
-//\r
+/**\r
+  Issue a token to get data from the socket.\r
+\r
+  @param  Sock                 Pointer to the socket to get data from.\r
+  @param  Token                The token to store the received data from the\r
+                               socket.\r
+\r
+  @retval EFI_SUCCESS          The token is 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 memory limit.\r
+\r
+**/\r
 EFI_STATUS\r
 SockRcv (\r
   IN SOCKET *Sock,\r
   IN VOID   *Token\r
   );\r
 \r
-//\r
-// Call it to flush a socket\r
-//\r
+/**\r
+  Reset the socket and its associated protocol control block.\r
+\r
+  @param  Sock                 Pointer to the socket to be flushed.\r
+\r
+  @retval EFI_SUCCESS          The socket is 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 SOCKET *Sock\r
   );\r
 \r
-//\r
-// Call it to close a socket in the light of policy in Token\r
-//\r
+/**\r
+  Close or abort the socket associated connection.\r
+\r
+  @param  Sock                 Pointer to the socket of the connection to close or\r
+                               abort.\r
+  @param  Token                The token for close operation.\r
+  @param  OnAbort              TRUE for aborting the connection, FALSE to close it.\r
+\r
+  @retval EFI_SUCCESS          The close or abort operation is 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 SOCKET  *Sock,\r
@@ -509,27 +707,57 @@ SockClose (
   IN BOOLEAN OnAbort\r
   );\r
 \r
-//\r
-// Call it to get the mode data of low layer protocol\r
-//\r
+/**\r
+  Get the mode data of the low layer protocol.\r
+\r
+  @param  Sock                 Pointer to the socket to get mode data from.\r
+  @param  Mode                 Pointer to the data to store the low layer mode\r
+                               information.\r
+\r
+  @retval EFI_SUCCESS          The mode data is got successfully.\r
+  @retval EFI_NOT_STARTED      The socket is not configured.\r
+\r
+**/\r
 EFI_STATUS\r
 SockGetMode (\r
   IN SOCKET *Sock,\r
   IN VOID   *Mode\r
   );\r
 \r
-//\r
-// call it to add this socket instance into a group\r
-//\r
+/**\r
+  Configure the low level protocol to join a multicast group for\r
+  this socket's connection.\r
+\r
+  @param  Sock                 Pointer to the socket of the connection to join the\r
+                               specific multicast group.\r
+  @param  GroupInfo            Pointer to the multicast group info.\r
+\r
+  @retval EFI_SUCCESS          The configuration is done 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
-// call it to add a route entry for this socket instance\r
-//\r
+/**\r
+  Add or remove route information in IP route table associated\r
+  with this socket.\r
+\r
+  @param  Sock                 Pointer to the socket associated with the IP route\r
+                               table to operate on.\r
+  @param  RouteInfo            Pointer to the route information to be processed.\r
+\r
+  @retval EFI_SUCCESS          The route table is 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
@@ -539,11 +767,31 @@ SockRoute (
 //\r
 // Supporting function to operate on socket buffer\r
 //\r
+\r
+/**\r
+  Get the first buffer block in the specific socket buffer.\r
+\r
+  @param  Sockbuf               Pointer to the socket buffer.\r
+\r
+  @return Pointer to the first buffer in the queue. NULL if the queue is empty.\r
+\r
+**/\r
 NET_BUF *\r
 SockBufFirst (\r
   IN SOCK_BUFFER *Sockbuf\r
   );\r
 \r
+/**\r
+  Get the next buffer block in the specific socket buffer.\r
+\r
+  @param  Sockbuf               Pointer to the socket buffer.\r
+  @param  SockEntry             Pointer to the buffer block prior to the required\r
+                                one.\r
+\r
+  @return Pointer to the buffer block next to SockEntry. NULL if SockEntry is \r
+          the tail or head entry.\r
+\r
+**/\r
 NET_BUF *\r
 SockBufNext (\r
   IN SOCK_BUFFER *Sockbuf,\r