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