]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Include/Library/TcpIoLib.h
NetworkPkg: Move Network library header file from MdeModulePkg to NetworkPkg
[mirror_edk2.git] / NetworkPkg / Include / Library / TcpIoLib.h
diff --git a/NetworkPkg/Include/Library/TcpIoLib.h b/NetworkPkg/Include/Library/TcpIoLib.h
new file mode 100644 (file)
index 0000000..63872f6
--- /dev/null
@@ -0,0 +1,247 @@
+/** @file\r
+  This library is used to share code between UEFI network stack modules.\r
+  It provides the helper routines to access TCP service.\r
+\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef _TCP_IO_H_\r
+#define _TCP_IO_H_\r
+\r
+\r
+#include <Protocol/Tcp4.h>\r
+#include <Protocol/Tcp6.h>\r
+\r
+#include <Library/NetLib.h>\r
+\r
+#define TCP_VERSION_4 IP_VERSION_4\r
+#define TCP_VERSION_6 IP_VERSION_6\r
+\r
+///\r
+/// 10 seconds\r
+///\r
+#define TCP_GET_MAPPING_TIMEOUT 100000000U\r
+\r
+\r
+typedef struct {\r
+  EFI_IPv4_ADDRESS          LocalIp;\r
+  EFI_IPv4_ADDRESS          SubnetMask;\r
+  EFI_IPv4_ADDRESS          Gateway;\r
+\r
+  UINT16                    StationPort;\r
+  EFI_IPv4_ADDRESS          RemoteIp;\r
+  UINT16                    RemotePort;\r
+  BOOLEAN                   ActiveFlag;\r
+} TCP4_IO_CONFIG_DATA;\r
+\r
+typedef struct {\r
+  UINT16                    StationPort;\r
+  EFI_IPv6_ADDRESS          RemoteIp;\r
+  UINT16                    RemotePort;\r
+  BOOLEAN                   ActiveFlag;\r
+} TCP6_IO_CONFIG_DATA;\r
+\r
+typedef union {\r
+  TCP4_IO_CONFIG_DATA       Tcp4IoConfigData;\r
+  TCP6_IO_CONFIG_DATA       Tcp6IoConfigData;\r
+} TCP_IO_CONFIG_DATA;\r
+\r
+typedef union {\r
+  EFI_TCP4_PROTOCOL         *Tcp4;\r
+  EFI_TCP6_PROTOCOL         *Tcp6;\r
+} TCP_IO_PROTOCOL;\r
+\r
+typedef union {\r
+  EFI_TCP4_CONNECTION_TOKEN Tcp4Token;\r
+  EFI_TCP6_CONNECTION_TOKEN Tcp6Token;\r
+} TCP_IO_CONNECTION_TOKEN;\r
+\r
+typedef union {\r
+  EFI_TCP4_IO_TOKEN         Tcp4Token;\r
+  EFI_TCP6_IO_TOKEN         Tcp6Token;\r
+} TCP_IO_IO_TOKEN;\r
+\r
+typedef union {\r
+  EFI_TCP4_CLOSE_TOKEN      Tcp4Token;\r
+  EFI_TCP6_CLOSE_TOKEN      Tcp6Token;\r
+} TCP_IO_CLOSE_TOKEN;\r
+\r
+typedef union {\r
+  EFI_TCP4_LISTEN_TOKEN     Tcp4Token;\r
+  EFI_TCP6_LISTEN_TOKEN     Tcp6Token;\r
+} TCP_IO_LISTEN_TOKEN;\r
+\r
+\r
+typedef struct {\r
+  UINT8                     TcpVersion;\r
+  EFI_HANDLE                Image;\r
+  EFI_HANDLE                Controller;\r
+  EFI_HANDLE                Handle;\r
+\r
+  TCP_IO_PROTOCOL           Tcp;\r
+  TCP_IO_PROTOCOL           NewTcp;\r
+  TCP_IO_CONNECTION_TOKEN   ConnToken;\r
+  TCP_IO_IO_TOKEN           TxToken;\r
+  TCP_IO_IO_TOKEN           RxToken;\r
+  TCP_IO_CLOSE_TOKEN        CloseToken;\r
+  TCP_IO_LISTEN_TOKEN       ListenToken;\r
+\r
+  BOOLEAN                   IsConnDone;\r
+  BOOLEAN                   IsTxDone;\r
+  BOOLEAN                   IsRxDone;\r
+  BOOLEAN                   IsCloseDone;\r
+  BOOLEAN                   IsListenDone;\r
+} TCP_IO;\r
+\r
+/**\r
+  Create a TCP socket with the specified configuration data.\r
+\r
+  @param[in]  Image      The handle of the driver image.\r
+  @param[in]  Controller The handle of the controller.\r
+  @param[in]  TcpVersion The version of Tcp, TCP_VERSION_4 or TCP_VERSION_6.\r
+  @param[in]  ConfigData The Tcp configuration data.\r
+  @param[out] TcpIo      The TcpIo.\r
+\r
+  @retval EFI_SUCCESS            The TCP socket is created and configured.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED        One or more of the control options are not\r
+                                 supported in the implementation.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+  @retval Others                 Failed to create the TCP socket or configure it.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcpIoCreateSocket (\r
+  IN EFI_HANDLE             Image,\r
+  IN EFI_HANDLE             Controller,\r
+  IN UINT8                  TcpVersion,\r
+  IN TCP_IO_CONFIG_DATA     *ConfigData,\r
+  OUT TCP_IO                *TcpIo\r
+  );\r
+\r
+/**\r
+  Destroy the socket.\r
+\r
+  @param[in]  TcpIo The TcpIo which wraps the socket to be destroyed.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TcpIoDestroySocket (\r
+  IN TCP_IO                 *TcpIo\r
+  );\r
+\r
+/**\r
+  Connect to the other endpoint of the TCP socket.\r
+\r
+  @param[in, out]  TcpIo     The TcpIo wrapping the TCP socket.\r
+  @param[in]       Timeout   The time to wait for connection done. Set to NULL for infinite wait.\r
+\r
+  @retval EFI_SUCCESS            Connect to the other endpoint of the TCP socket\r
+                                 successfully.\r
+  @retval EFI_TIMEOUT            Failed to connect to the other endpoint of the\r
+                                 TCP socket in the specified time period.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED        One or more of the control options are not\r
+                                 supported in the implementation.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcpIoConnect (\r
+  IN OUT TCP_IO             *TcpIo,\r
+  IN     EFI_EVENT          Timeout        OPTIONAL\r
+  );\r
+\r
+/**\r
+  Accept the incomding request from the other endpoint of the TCP socket.\r
+\r
+  @param[in, out]  TcpIo     The TcpIo wrapping the TCP socket.\r
+  @param[in]       Timeout   The time to wait for connection done. Set to NULL for infinite wait.\r
+\r
+\r
+  @retval EFI_SUCCESS            Connect to the other endpoint of the TCP socket\r
+                                 successfully.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED        One or more of the control options are not\r
+                                 supported in the implementation.\r
+\r
+  @retval EFI_TIMEOUT            Failed to connect to the other endpoint of the\r
+                                 TCP socket in the specified time period.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcpIoAccept (\r
+  IN OUT TCP_IO             *TcpIo,\r
+  IN     EFI_EVENT          Timeout        OPTIONAL\r
+  );\r
+\r
+/**\r
+  Reset the socket.\r
+\r
+  @param[in, out]  TcpIo The TcpIo wrapping the TCP socket.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TcpIoReset (\r
+  IN OUT TCP_IO             *TcpIo\r
+  );\r
+\r
+/**\r
+  Transmit the Packet to the other endpoint of the socket.\r
+\r
+  @param[in]   TcpIo           The TcpIo wrapping the TCP socket.\r
+  @param[in]   Packet          The packet to transmit.\r
+\r
+  @retval EFI_SUCCESS            The packet is trasmitted.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_UNSUPPORTED        One or more of the control options are not\r
+                                 supported in the implementation.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
+  @retval EFI_DEVICE_ERROR       An unexpected network or system error occurred.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcpIoTransmit (\r
+  IN TCP_IO                 *TcpIo,\r
+  IN NET_BUF                *Packet\r
+  );\r
+\r
+/**\r
+  Receive data from the socket.\r
+\r
+  @param[in, out]  TcpIo       The TcpIo which wraps the socket to be destroyed.\r
+  @param[in]       Packet      The buffer to hold the data copy from the socket rx buffer.\r
+  @param[in]       AsyncMode   Is this receive asyncronous or not.\r
+  @param[in]       Timeout     The time to wait for receiving the amount of data the Packet\r
+                               can hold. Set to NULL for infinite wait.\r
+\r
+  @retval EFI_SUCCESS            The required amount of data is received from the socket.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
+  @retval EFI_DEVICE_ERROR       An unexpected network or system error occurred.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate momery.\r
+  @retval EFI_TIMEOUT            Failed to receive the required amount of data in the\r
+                                 specified time period.\r
+  @retval Others                 Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TcpIoReceive (\r
+  IN OUT TCP_IO             *TcpIo,\r
+  IN     NET_BUF            *Packet,\r
+  IN     BOOLEAN            AsyncMode,\r
+  IN     EFI_EVENT          Timeout       OPTIONAL\r
+  );\r
+\r
+#endif\r
+\r