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