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