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