]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Socket.h
index 11406ed6d020c4fd600a16592d39ccb041882ae0..8c25c63b1161af2de8fd5129828663e538d0875c 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
+  Socket header file.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\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<BR>\r
@@ -14,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef _SOCKET_H_\r
 #define _SOCKET_H_\r
 \r
-#include <PiDxe.h>\r
+#include <Uefi.h>\r
 \r
 #include <Protocol/Ip4.h>\r
 #include <Protocol/Tcp4.h>\r
@@ -22,13 +23,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \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/UefiDriverEntryPoint.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/UefiLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
+#include <Library/DpcLib.h>\r
+#include <Library/PrintLib.h>\r
 \r
 #define SOCK_SND_BUF        0\r
 #define SOCK_RCV_BUF        1\r
@@ -67,73 +69,238 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 ///\r
 /// Socket state\r
 ///\r
-typedef enum {\r
-  SO_CLOSED       = 0,\r
-  SO_LISTENING,\r
-  SO_CONNECTING,\r
-  SO_CONNECTED,\r
-  SO_DISCONNECTING\r
-} SOCK_STATE;\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
-typedef enum {\r
-  SO_UNCONFIGURED       = 0,\r
-  SO_CONFIGURED_ACTIVE,\r
-  SO_CONFIGURED_PASSIVE,\r
-  SO_NO_MAPPING\r
-} SOCK_CONFIGURE_STATE;\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
+  Set socket SO_NO_MORE_DATA flag.\r
+  \r
+  @param 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  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  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  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) \\r
   ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)\r
 \r
+/**\r
+  Check whether the socket is configured to passive mode.\r
+  \r
+  @param  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) \\r
   ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)\r
 \r
+/**\r
+  Check whether the socket is mapped.\r
+  \r
+  @param  Sock               Pointer to the socket\r
+  \r
+  @retval True               The socket is no mapping\r
+  @retval False              The socket is mapped\r
+  \r
+**/\r
 #define SOCK_IS_NO_MAPPING(Sock) \\r
   ((Sock)->ConfigureState == SO_NO_MAPPING)\r
 \r
+/**\r
+  Check whether the socket is closed.\r
+  \r
+  @param  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  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  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  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  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  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
-#define SOCK_SIGNATURE                SIGNATURE_32 ('S', 'O', 'C', 'K')\r
-\r
-#define SOCK_FROM_THIS(a)             CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)\r
+/**\r
+  Set the size of the receive buffer.\r
+  \r
+  @param  Sock               Pointer to the socket\r
+  @param  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  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  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  Sock               Pointer to the socket\r
+  @param  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  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  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  Sock               Pointer to the socket\r
+  @param  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  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  Sock               Pointer to the socket\r
+  @param  Error              The error state\r
+\r
+**/\r
 #define SOCK_ERROR(Sock, Error)       ((Sock)->SockError = (Error))\r
 \r
 #define SND_BUF_HDR_LEN(Sock) \\r
@@ -142,6 +309,10 @@ typedef enum {
 #define RCV_BUF_HDR_LEN(Sock) \\r
   ((SockBufFirst (&((Sock)->RcvBuffer)))->TotalSize)\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) \\r
@@ -157,57 +328,46 @@ typedef struct _SOCK_COMPLETION_TOKEN {
   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
-  union {\r
-    VOID  *RxData;\r
-    VOID  *TxData;\r
-  } Packet;\r
+  SOCK_IO_DATA          Packet;\r
 } SOCK_IO_TOKEN;\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_REQUEST;\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
 ///  The socket type.\r
 ///\r
 typedef enum {\r
-  SOCK_DGRAM, ///< This socket providing datagram service\r
-  SOCK_STREAM ///< This socket providing stream service\r
+  SockDgram, ///< This socket providing datagram service\r
+  SockStream ///< This socket providing stream service\r
 } SOCK_TYPE;\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
-  );\r
-\r
 ///\r
 ///  The buffer structure of rcvd data and send data used by socket.\r
 ///\r
@@ -217,7 +377,27 @@ typedef struct _SOCK_BUFFER {
   NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data\r
 } SOCK_BUFFER;\r
 \r
-\r
+/**\r
+  The handler of protocol for request from socket.\r
+  \r
+  @param Socket              The socket issuing the request to protocol\r
+  @param Request             The request issued by socket\r
+  @param 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
 //\r
 // Socket provided oprerations for low layer protocol\r
 //\r
@@ -230,18 +410,20 @@ typedef struct _SOCK_BUFFER {
   Set the state of the socket.\r
 \r
   @param  Sock                  Pointer to the socket.\r
-  @param  State                 The new state to be set.\r
+  @param  State                 The new socket state to be set.\r
 \r
 **/\r
 VOID\r
 SockSetState (\r
-  IN SOCKET     *Sock,\r
-  IN SOCK_STATE State\r
+  IN OUT SOCKET     *Sock,\r
+  IN     UINT8      State\r
   );\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
+  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  Sock                  Pointer to the socket associated with the\r
@@ -254,9 +436,10 @@ SockConnEstablished (
   );\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
+  Called by the low layer protocol to indicate 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  Sock                  Pointer to the socket associated with the closed\r
                                 connection.\r
@@ -264,11 +447,12 @@ SockConnEstablished (
 **/\r
 VOID\r
 SockConnClosed (\r
-  IN SOCKET *Sock\r
+  IN OUT SOCKET *Sock\r
   );\r
 \r
 /**\r
-  Called by low layer protocol to indicate that some data is sent or processed; \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, signals the data \r
   token if proper.\r
 \r
@@ -305,21 +489,22 @@ SockGetDataToSend (
 \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
+  will be no more data from the communication peer.\r
+  \r
+  This function set the socket's state to SO_NO_MORE_DATA and\r
+  signal all queued IO tokens with the error status EFI_CONNECTION_FIN.\r
 \r
   @param  Sock                  Pointer to the socket.\r
 \r
 **/\r
 VOID\r
 SockNoMoreData (\r
-  IN SOCKET *Sock\r
+  IN OUT SOCKET *Sock\r
   );\r
 \r
 /**\r
-  Called by the low layer protocol to deliver received data to socket layer; \r
+  Called by the low layer protocol to deliver received data to socket layer.\r
+  \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
@@ -331,9 +516,9 @@ SockNoMoreData (
 **/\r
 VOID\r
 SockDataRcvd (\r
-  IN SOCKET    *Sock,\r
-  IN NET_BUF   *NetBuffer,\r
-  IN UINT32    UrgLen\r
+  IN     SOCKET    *Sock,\r
+  IN OUT NET_BUF   *NetBuffer,\r
+  IN     UINT32    UrgLen\r
   );\r
 \r
 /**\r
@@ -375,8 +560,8 @@ SockClone (
 **/\r
 VOID\r
 SockRcvdErr (\r
-  IN SOCKET       *Sock,\r
-  IN EFI_STATUS   Error\r
+  IN OUT SOCKET       *Sock,\r
+  IN     EFI_STATUS   Error\r
   );\r
 \r
 ///\r
@@ -404,7 +589,7 @@ VOID
 ///\r
 typedef struct _SOCK_INIT_DATA {\r
   SOCK_TYPE   Type;\r
-  SOCK_STATE  State;\r
+  UINT8       State;\r
 \r
   SOCKET      *Parent;        ///< The parent of this socket\r
   UINT32      BackLog;        ///< The connection limit for listening socket\r
@@ -453,15 +638,15 @@ struct _SOCKET {
   EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   LIST_ENTRY                Link;  \r
-  SOCK_CONFIGURE_STATE  ConfigureState;\r
+  UINT8                 ConfigureState;\r
   SOCK_TYPE             Type;\r
-  SOCK_STATE            State;\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
+  BOOLEAN               InDestroy;\r
 \r
   //\r
   // Fields used to manage the connection request\r
@@ -539,7 +724,7 @@ SockCreateChild (
   );\r
 \r
 /**\r
-  Destory the socket Sock and its associated protocol control block.\r
+  Destroy the socket Sock and its associated protocol control block.\r
 \r
   @param  Sock                 The socket to be destroyed.\r
 \r
@@ -720,8 +905,8 @@ SockClose (
 **/\r
 EFI_STATUS\r
 SockGetMode (\r
-  IN SOCKET *Sock,\r
-  IN VOID   *Mode\r
+  IN     SOCKET *Sock,\r
+  IN OUT VOID   *Mode\r
   );\r
 \r
 /**\r