1 /** @file 2 This library is used to share code between UEFI network stack modules. 3 It provides the helper routines to access TCP service. 4 5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> 6 SPDX-License-Identifier: BSD-2-Clause-Patent 7 8 **/ 9 10 #ifndef _TCP_IO_H_ 11 #define _TCP_IO_H_ 12 13 14 #include <Protocol/Tcp4.h> 15 #include <Protocol/Tcp6.h> 16 17 #include <Library/NetLib.h> 18 19 #define TCP_VERSION_4 IP_VERSION_4 20 #define TCP_VERSION_6 IP_VERSION_6 21 22 /// 23 /// 10 seconds 24 /// 25 #define TCP_GET_MAPPING_TIMEOUT 100000000U 26 27 28 typedef struct { 29 EFI_IPv4_ADDRESS LocalIp; 30 EFI_IPv4_ADDRESS SubnetMask; 31 EFI_IPv4_ADDRESS Gateway; 32 33 UINT16 StationPort; 34 EFI_IPv4_ADDRESS RemoteIp; 35 UINT16 RemotePort; 36 BOOLEAN ActiveFlag; 37 } TCP4_IO_CONFIG_DATA; 38 39 typedef struct { 40 UINT16 StationPort; 41 EFI_IPv6_ADDRESS RemoteIp; 42 UINT16 RemotePort; 43 BOOLEAN ActiveFlag; 44 } TCP6_IO_CONFIG_DATA; 45 46 typedef union { 47 TCP4_IO_CONFIG_DATA Tcp4IoConfigData; 48 TCP6_IO_CONFIG_DATA Tcp6IoConfigData; 49 } TCP_IO_CONFIG_DATA; 50 51 typedef union { 52 EFI_TCP4_PROTOCOL *Tcp4; 53 EFI_TCP6_PROTOCOL *Tcp6; 54 } TCP_IO_PROTOCOL; 55 56 typedef union { 57 EFI_TCP4_CONNECTION_TOKEN Tcp4Token; 58 EFI_TCP6_CONNECTION_TOKEN Tcp6Token; 59 } TCP_IO_CONNECTION_TOKEN; 60 61 typedef union { 62 EFI_TCP4_IO_TOKEN Tcp4Token; 63 EFI_TCP6_IO_TOKEN Tcp6Token; 64 } TCP_IO_IO_TOKEN; 65 66 typedef union { 67 EFI_TCP4_CLOSE_TOKEN Tcp4Token; 68 EFI_TCP6_CLOSE_TOKEN Tcp6Token; 69 } TCP_IO_CLOSE_TOKEN; 70 71 typedef union { 72 EFI_TCP4_LISTEN_TOKEN Tcp4Token; 73 EFI_TCP6_LISTEN_TOKEN Tcp6Token; 74 } TCP_IO_LISTEN_TOKEN; 75 76 77 typedef struct { 78 UINT8 TcpVersion; 79 EFI_HANDLE Image; 80 EFI_HANDLE Controller; 81 EFI_HANDLE Handle; 82 83 TCP_IO_PROTOCOL Tcp; 84 TCP_IO_PROTOCOL NewTcp; 85 TCP_IO_CONNECTION_TOKEN ConnToken; 86 TCP_IO_IO_TOKEN TxToken; 87 TCP_IO_IO_TOKEN RxToken; 88 TCP_IO_CLOSE_TOKEN CloseToken; 89 TCP_IO_LISTEN_TOKEN ListenToken; 90 91 BOOLEAN IsConnDone; 92 BOOLEAN IsTxDone; 93 BOOLEAN IsRxDone; 94 BOOLEAN IsCloseDone; 95 BOOLEAN IsListenDone; 96 } TCP_IO; 97 98 /** 99 Create a TCP socket with the specified configuration data. 100 101 @param[in] Image The handle of the driver image. 102 @param[in] Controller The handle of the controller. 103 @param[in] TcpVersion The version of Tcp, TCP_VERSION_4 or TCP_VERSION_6. 104 @param[in] ConfigData The Tcp configuration data. 105 @param[out] TcpIo The TcpIo. 106 107 @retval EFI_SUCCESS The TCP socket is created and configured. 108 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 109 @retval EFI_UNSUPPORTED One or more of the control options are not 110 supported in the implementation. 111 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. 112 @retval Others Failed to create the TCP socket or configure it. 113 114 **/ 115 EFI_STATUS 116 EFIAPI 117 TcpIoCreateSocket ( 118 IN EFI_HANDLE Image, 119 IN EFI_HANDLE Controller, 120 IN UINT8 TcpVersion, 121 IN TCP_IO_CONFIG_DATA *ConfigData, 122 OUT TCP_IO *TcpIo 123 ); 124 125 /** 126 Destroy the socket. 127 128 @param[in] TcpIo The TcpIo which wraps the socket to be destroyed. 129 130 **/ 131 VOID 132 EFIAPI 133 TcpIoDestroySocket ( 134 IN TCP_IO *TcpIo 135 ); 136 137 /** 138 Connect to the other endpoint of the TCP socket. 139 140 @param[in, out] TcpIo The TcpIo wrapping the TCP socket. 141 @param[in] Timeout The time to wait for connection done. Set to NULL for infinite wait. 142 143 @retval EFI_SUCCESS Connect to the other endpoint of the TCP socket 144 successfully. 145 @retval EFI_TIMEOUT Failed to connect to the other endpoint of the 146 TCP socket in the specified time period. 147 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 148 @retval EFI_UNSUPPORTED One or more of the control options are not 149 supported in the implementation. 150 @retval Others Other errors as indicated. 151 152 **/ 153 EFI_STATUS 154 EFIAPI 155 TcpIoConnect ( 156 IN OUT TCP_IO *TcpIo, 157 IN EFI_EVENT Timeout OPTIONAL 158 ); 159 160 /** 161 Accept the incomding request from the other endpoint of the TCP socket. 162 163 @param[in, out] TcpIo The TcpIo wrapping the TCP socket. 164 @param[in] Timeout The time to wait for connection done. Set to NULL for infinite wait. 165 166 167 @retval EFI_SUCCESS Connect to the other endpoint of the TCP socket 168 successfully. 169 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 170 @retval EFI_UNSUPPORTED One or more of the control options are not 171 supported in the implementation. 172 173 @retval EFI_TIMEOUT Failed to connect to the other endpoint of the 174 TCP socket in the specified time period. 175 @retval Others Other errors as indicated. 176 177 **/ 178 EFI_STATUS 179 EFIAPI 180 TcpIoAccept ( 181 IN OUT TCP_IO *TcpIo, 182 IN EFI_EVENT Timeout OPTIONAL 183 ); 184 185 /** 186 Reset the socket. 187 188 @param[in, out] TcpIo The TcpIo wrapping the TCP socket. 189 190 **/ 191 VOID 192 EFIAPI 193 TcpIoReset ( 194 IN OUT TCP_IO *TcpIo 195 ); 196 197 /** 198 Transmit the Packet to the other endpoint of the socket. 199 200 @param[in] TcpIo The TcpIo wrapping the TCP socket. 201 @param[in] Packet The packet to transmit. 202 203 @retval EFI_SUCCESS The packet is transmitted. 204 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 205 @retval EFI_UNSUPPORTED One or more of the control options are not 206 supported in the implementation. 207 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. 208 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred. 209 @retval Others Other errors as indicated. 210 211 **/ 212 EFI_STATUS 213 EFIAPI 214 TcpIoTransmit ( 215 IN TCP_IO *TcpIo, 216 IN NET_BUF *Packet 217 ); 218 219 /** 220 Receive data from the socket. 221 222 @param[in, out] TcpIo The TcpIo which wraps the socket to be destroyed. 223 @param[in] Packet The buffer to hold the data copy from the socket rx buffer. 224 @param[in] AsyncMode Is this receive asynchronous or not. 225 @param[in] Timeout The time to wait for receiving the amount of data the Packet 226 can hold. Set to NULL for infinite wait. 227 228 @retval EFI_SUCCESS The required amount of data is received from the socket. 229 @retval EFI_INVALID_PARAMETER One or more parameters are invalid. 230 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred. 231 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. 232 @retval EFI_TIMEOUT Failed to receive the required amount of data in the 233 specified time period. 234 @retval Others Other errors as indicated. 235 236 **/ 237 EFI_STATUS 238 EFIAPI 239 TcpIoReceive ( 240 IN OUT TCP_IO *TcpIo, 241 IN NET_BUF *Packet, 242 IN BOOLEAN AsyncMode, 243 IN EFI_EVENT Timeout OPTIONAL 244 ); 245 246 #endif 247 248