2 TCP4 protocol services header file.
4 Copyright (c) 2005 - 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php<BR>
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "Tcp4Proto.h"
22 #include "Tcp4Driver.h"
25 extern UINT16 mTcp4RandomPort
;
26 extern CHAR16
*mTcpStateName
[];
29 // Driver Produced Protocol Prototypes
33 // Function prototype for the Tcp4 socket request handler
36 The procotol handler provided to the socket layer, used to
37 dispatch the socket level requests by calling the corresponding
40 @param Sock Pointer to the socket of this TCP instance.
41 @param Request The code of this operation request.
42 @param Data Pointer to the operation specific data passed in
43 together with the operation request.
45 @retval EFI_SUCCESS The socket request is completed successfully.
46 @retval other The error status returned by the corresponding TCP
53 IN SOCK_REQUEST Request
,
54 IN VOID
*Data OPTIONAL
60 typedef struct _TCP4_MODE_DATA
{
61 EFI_TCP4_CONNECTION_STATE
*Tcp4State
;
62 EFI_TCP4_CONFIG_DATA
*Tcp4ConfigData
;
63 EFI_IP4_MODE_DATA
*Ip4ModeData
;
64 EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData
;
65 EFI_SIMPLE_NETWORK_MODE
*SnpModeData
;
69 /// TCP route infomation data
71 typedef struct _TCP4_ROUTE_INFO
{
73 EFI_IPv4_ADDRESS
*SubnetAddress
;
74 EFI_IPv4_ADDRESS
*SubnetMask
;
75 EFI_IPv4_ADDRESS
*GatewayAddress
;
79 Get the current operational status of a TCP instance.
81 The GetModeData() function copies the current operational settings of this
82 EFI TCPv4 Protocol instance into user-supplied buffers. This function can
83 also be used to retrieve the operational setting of underlying drivers
84 such as IPv4, MNP, or SNP.
86 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
87 @param Tcp4State Pointer to the buffer to receive the current TCP
89 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP
91 @param Ip4ModeData Pointer to the buffer to receive the current IPv4
92 configuration data used by the TCPv4 instance.
93 @param MnpConfigData Pointer to the buffer to receive the current MNP
94 configuration data indirectly used by the TCPv4
96 @param SnpModeData Pointer to the buffer to receive the current SNP
97 configuration data indirectly used by the TCPv4
100 @retval EFI_SUCCESS The mode data was read.
101 @retval EFI_NOT_STARTED No configuration data is available because this
102 instance hasn't been started.
103 @retval EFI_INVALID_PARAMETER This is NULL.
109 IN CONST EFI_TCP4_PROTOCOL
*This
,
110 OUT EFI_TCP4_CONNECTION_STATE
*Tcp4State OPTIONAL
,
111 OUT EFI_TCP4_CONFIG_DATA
*Tcp4ConfigData OPTIONAL
,
112 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
113 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
114 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
119 Initialize or brutally reset the operational parameters for
120 this EFI TCPv4 instance.
122 The Configure() function does the following:
123 * Initialize this EFI TCPv4 instance, i.e., initialize the communication end
124 setting, specify active open or passive open for an instance.
125 * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous
126 tokens, flush transmission and receiving buffer directly without informing
127 the communication peer.
128 No other TCPv4 Protocol operation can be executed by this instance
129 until it is configured properly. For an active TCP4 instance, after a proper
130 configuration it may call Connect() to initiates the three-way handshake.
131 For a passive TCP4 instance, its state will transit to Tcp4StateListen after
132 configuration, and Accept() may be called to listen the incoming TCP connection
133 request. If TcpConfigData is set to NULL, the instance is reset. Resetting
134 process will be done brutally, the state machine will be set to Tcp4StateClosed
135 directly, the receive queue and transmit queue will be flushed, and no traffic is
136 allowed through this instance.
138 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
139 @param TcpConfigData Pointer to the configure data to configure the
142 @retval EFI_SUCCESS The operational settings are set, changed, or
144 @retval EFI_NO_MAPPING When using a default address, configuration
145 (through DHCP, BOOTP, RARP, etc.) is not
147 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
148 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already
150 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
151 @retval EFI_UNSUPPORTED One or more of the control options are not
152 supported in the implementation.
153 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
159 IN EFI_TCP4_PROTOCOL
*This
,
160 IN EFI_TCP4_CONFIG_DATA
*TcpConfigData OPTIONAL
164 Add or delete routing entries.
166 The Routes() function adds or deletes a route from the instance's routing table.
167 The most specific route is selected by comparing the SubnetAddress with the
168 destination IP address's arithmetical AND to the SubnetMask.
169 The default route is added with both SubnetAddress and SubnetMask set to 0.0.0.0.
170 The default route matches all destination IP addresses if there is no more specific route.
171 Direct route is added with GatewayAddress set to 0.0.0.0. Packets are sent to
172 the destination host if its address can be found in the Address Resolution Protocol (ARP)
173 cache or it is on the local subnet. If the instance is configured to use default
174 address, a direct route to the local network will be added automatically.
175 Each TCP instance has its own independent routing table. Instance that uses the
176 default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's routing table.
177 The copy will be updated automatically whenever the IP driver reconfigures its
178 instance. As a result, the previous modification to the instance's local copy
179 will be lost. The priority of checking the route table is specific with IP
180 implementation and every IP implementation must comply with RFC 1122.
182 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
183 @param DeleteRoute If TRUE, delete the specified route from routing
184 table; if FALSE, add the specified route to
186 DestinationAddress and SubnetMask are used as
187 the keywords to search route entry.
188 @param SubnetAddress The destination network.
189 @param SubnetMask The subnet mask for the destination network.
190 @param GatewayAddress The gateway address for this route.
191 It must be on the same subnet with the station
192 address unless a direct route is specified.
194 @retval EFI_SUCCESS The operation completed successfully.
195 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
197 @retval EFI_NO_MAPPING When using a default address, configuration
198 (through DHCP, BOOTP, RARP, etc.) is not
200 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
201 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
202 entry to the routing table.
203 @retval EFI_NOT_FOUND This route is not in the routing table.
204 @retval EFI_ACCESS_DENIED This route is already in the routing table.
205 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
211 IN EFI_TCP4_PROTOCOL
*This
,
212 IN BOOLEAN DeleteRoute
,
213 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
214 IN EFI_IPv4_ADDRESS
*SubnetMask
,
215 IN EFI_IPv4_ADDRESS
*GatewayAddress
219 Initiate a nonblocking TCP connection request for an active TCP instance.
221 The Connect() function will initiate an active open to the remote peer configured
222 in current TCP instance if it is configured active. If the connection succeeds
223 or fails due to any error, the ConnectionToken->CompletionToken.Event will be
224 signaled and ConnectionToken->CompletionToken.Status will be updated accordingly.
225 This function can only be called for the TCP instance in Tcp4StateClosed state.
226 The instance will transfer into Tcp4StateSynSent if the function returns EFI_SUCCESS.
227 If TCP three way handshake succeeds, its state will become Tcp4StateEstablished,
228 otherwise, the state will return to Tcp4StateClosed.
230 @param This Pointer to the EFI_TCP4_PROTOCOL instance
231 @param ConnectionToken Pointer to the connection token to return when
232 the TCP three way handshake finishes.
234 @retval EFI_SUCCESS The connection request is successfully initiated
235 and the state of this TCPv4 instance has
236 been changed to Tcp4StateSynSent.
237 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
239 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
240 or it is not in Tcp4StateClosed state.
241 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
242 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
243 initiate the active open.
244 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
250 IN EFI_TCP4_PROTOCOL
*This
,
251 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
255 Listen on the passive instance to accept an incoming connection request.
257 The Accept() function initiates an asynchronous accept request to wait for an
258 incoming connection on the passive TCP instance. If a remote peer successfully
259 establishes a connection with this instance, a new TCP instance will be created
260 and its handle will be returned in ListenToken->NewChildHandle. The newly created
261 instance is configured by inheriting the passive instance's configuration and is
262 ready for use upon return. The instance is in the Tcp4StateEstablished state.
263 The ListenToken->CompletionToken.Event will be signaled when a new connection
264 is accepted, user aborts the listen or connection is reset. This function only
265 can be called when current TCP instance is in Tcp4StateListen state.
267 @param This Pointer to the EFI_TCP4_PROTOCOL instance
268 @param ListenToken Pointer to the listen token to return when
271 @retval EFI_SUCCESS The listen token has been queued successfully.
272 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
274 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
275 in Tcp4StateListen state or a same listen token
276 has already existed in the listen token queue of
278 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
279 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
281 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above category error.
287 IN EFI_TCP4_PROTOCOL
*This
,
288 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
292 Queues outgoing data into the transmit queue.
294 The Transmit() function queues a sending request to this TCPv4 instance along
295 with the user data. The status of the token is updated and the event in the token
296 will be signaled once the data is sent out or some error occurs.
298 @param This Pointer to the EFI_TCP4_PROTOCOL instance
299 @param Token Pointer to the completion token to queue to the
302 @retval EFI_SUCCESS The data has been queued for transmission.
303 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
305 @retval EFI_NO_MAPPING When using a default address, configuration
306 (DHCP, BOOTP, RARP, etc.) is not finished yet.
307 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
308 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
309 * A transmit completion token with the same
310 Token-> CompletionToken.Event was already in the
312 * The current instance is in Tcp4StateClosed state
313 * The current instance is a passive one and
314 it is in Tcp4StateListen state.
315 * User has called Close() to disconnect this
317 @retval EFI_NOT_READY The completion token could not be queued because
318 the transmit queue is full.
319 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
321 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
328 IN EFI_TCP4_PROTOCOL
*This
,
329 IN EFI_TCP4_IO_TOKEN
*Token
333 Place an asynchronous receive request into the receiving queue.
335 The Receive() function places a completion token into the receive packet queue.
336 This function is always asynchronous. The caller must allocate the
337 Token->CompletionToken.Event and the FragmentBuffer used to receive data. He also
338 must fill the DataLength which represents the whole length of all FragmentBuffer.
339 When the receive operation completes, the EFI TCPv4 Protocol driver updates the
340 Token->CompletionToken.Status and Token->Packet.RxData fields and the
341 Token->CompletionToken.Event is signaled. If got data the data and its length
342 will be copy into the FragmentTable, in the same time the full length of received
343 data will be recorded in the DataLength fields. Providing a proper notification
344 function and context for the event will enable the user to receive the notification
345 and receiving status. That notification function is guaranteed to not be re-entered.
347 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
348 @param Token Pointer to a token that is associated with the
349 receive data descriptor.
351 @retval EFI_SUCCESS The receive completion token was cached.
352 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
354 @retval EFI_NO_MAPPING When using a default address, configuration
355 (DHCP, BOOTP, RARP, etc.) is not finished yet.
356 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
357 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
358 due to a lack of system resources.
359 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
360 The EFI TCPv4 Protocol instance has been reset
362 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
363 * A receive completion token with the same
364 Token->CompletionToken.Event was already in
366 * The current instance is in Tcp4StateClosed state.
367 * The current instance is a passive one and it
368 is in Tcp4StateListen state.
369 * User has called Close() to disconnect this
371 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
372 and there is no any buffered data in the receive
373 buffer of this instance.
374 @retval EFI_NOT_READY The receive request could not be queued because
375 the receive queue is full.
381 IN EFI_TCP4_PROTOCOL
*This
,
382 IN EFI_TCP4_IO_TOKEN
*Token
386 Disconnecting a TCP connection gracefully or reset a TCP connection.
388 Initiate an asynchronous close token to TCP driver. After Close() is called,
389 any buffered transmission data will be sent by TCP driver and the current
390 instance will have a graceful close working flow described as RFC 793 if
391 AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by TCP
392 driver to fast disconnect this connection. When the close operation completes
393 successfully the TCP instance is in Tcp4StateClosed state, all pending
394 asynchronous operation is signaled and any buffers used for TCP network traffic
397 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
398 @param CloseToken Pointer to the close token to return when
401 @retval EFI_SUCCESS The operation completed successfully.
402 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
404 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:
405 * Configure() has been called with TcpConfigData
406 set to NULL and this function has not returned.
407 * Previous Close() call on this instance has not
409 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.
410 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
412 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
419 IN EFI_TCP4_PROTOCOL
*This
,
420 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
424 Abort an asynchronous connection, listen, transmission or receive request.
426 The Cancel() function aborts a pending connection, listen, transmit or receive
427 request. If Token is not NULL and the token is in the connection, listen,
428 transmission or receive queue when it is being cancelled, its Token->Status
429 will be set to EFI_ABORTED and then Token->Event will be signaled. If the token
430 is not in one of the queues, which usually means that the asynchronous operation
431 has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchronous token
432 issued by Connect(), Accept(), Transmit() and Receive()will be aborted.
433 NOTE: It has not been implemented currently.
435 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
436 @param Token Pointer to a token that has been issued by
437 Connect(), Accept(), Transmit() or Receive(). If
438 NULL, all pending tokens issued by above four
439 functions will be aborted.
441 @retval EFI_SUCCESS The asynchronous I/O request is aborted and Token->Event
443 @retval EFI_INVALID_PARAMETER This is NULL.
444 @retval EFI_NOT_STARTED This instance hasn's been configured.
445 @retval EFI_NO_MAPPING When using the default address, configuration
446 (DHCP, BOOTP,RARP, etc.) hasn's finished yet.
447 @retval EFI_NOT_FOUND The asynchronous I/O request isn's found in the
448 transmission or receive queue. It has either
449 completed or wasn's issued by Transmit() and Receive().
450 @retval EFI_UNSUPPORTED The operation is not supported in current
457 IN EFI_TCP4_PROTOCOL
*This
,
458 IN EFI_TCP4_COMPLETION_TOKEN
*Token OPTIONAL
462 Poll to receive incoming data and transmit outgoing segments.
464 The Poll() function increases the rate that data is moved between the network
465 and application and can be called when the TCP instance is created successfully.
466 Its use is optional. In some implementations, the periodical timer in the MNP
467 driver may not poll the underlying communications device fast enough to avoid
468 drop packets. Drivers and applications that are experiencing packet loss should
469 try calling the Poll() function in a high frequency.
471 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
473 @retval EFI_SUCCESS Incoming or outgoing data was processed.
474 @retval EFI_INVALID_PARAMETER This is NULL.
475 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
476 @retval EFI_NOT_READY No incoming or outgoing data was processed.
477 @retval EFI_TIMEOUT Data was dropped out of the transmission or
478 receive queue. Consider increasing the polling
485 IN EFI_TCP4_PROTOCOL
*This