2 TCP4 protocol services header file.
4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
5 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
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 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
80 UINTN NumberOfChildren
;
81 EFI_HANDLE
*ChildHandleBuffer
;
82 } TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
;
85 Get the current operational status of a TCP instance.
87 The GetModeData() function copies the current operational settings of this
88 EFI TCPv4 Protocol instance into user-supplied buffers. This function can
89 also be used to retrieve the operational setting of underlying drivers
90 such as IPv4, MNP, or SNP.
92 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
93 @param Tcp4State Pointer to the buffer to receive the current TCP
95 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP
97 @param Ip4ModeData Pointer to the buffer to receive the current IPv4
98 configuration data used by the TCPv4 instance.
99 @param MnpConfigData Pointer to the buffer to receive the current MNP
100 configuration data indirectly used by the TCPv4
102 @param SnpModeData Pointer to the buffer to receive the current SNP
103 configuration data indirectly used by the TCPv4
106 @retval EFI_SUCCESS The mode data was read.
107 @retval EFI_NOT_STARTED No configuration data is available because this
108 instance hasn't been started.
109 @retval EFI_INVALID_PARAMETER This is NULL.
115 IN EFI_TCP4_PROTOCOL
*This
,
116 OUT EFI_TCP4_CONNECTION_STATE
*Tcp4State OPTIONAL
,
117 OUT EFI_TCP4_CONFIG_DATA
*Tcp4ConfigData OPTIONAL
,
118 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
119 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
120 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
125 Initialize or brutally reset the operational parameters for
126 this EFI TCPv4 instance.
128 The Configure() function does the following:
129 * Initialize this EFI TCPv4 instance, i.e., initialize the communication end
130 setting, specify active open or passive open for an instance.
131 * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous
132 tokens, flush transmission and receiving buffer directly without informing
133 the communication peer.
134 No other TCPv4 Protocol operation can be executed by this instance
135 until it is configured properly. For an active TCP4 instance, after a proper
136 configuration it may call Connect() to initiates the three-way handshake.
137 For a passive TCP4 instance, its state will transit to Tcp4StateListen after
138 configuration, and Accept() may be called to listen the incoming TCP connection
139 request. If TcpConfigData is set to NULL, the instance is reset. Resetting
140 process will be done brutally, the state machine will be set to Tcp4StateClosed
141 directly, the receive queue and transmit queue will be flushed, and no traffic is
142 allowed through this instance.
144 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
145 @param TcpConfigData Pointer to the configure data to configure the
148 @retval EFI_SUCCESS The operational settings are set, changed, or
150 @retval EFI_NO_MAPPING When using a default address, configuration
151 (through DHCP, BOOTP, RARP, etc.) is not
153 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
154 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already
156 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
157 @retval EFI_UNSUPPORTED One or more of the control options are not
158 supported in the implementation.
159 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
165 IN EFI_TCP4_PROTOCOL
*This
,
166 IN EFI_TCP4_CONFIG_DATA
*TcpConfigData OPTIONAL
170 Add or delete routing entries.
172 The Routes() function adds or deletes a route from the instance's routing table.
173 The most specific route is selected by comparing the SubnetAddress with the
174 destination IP address's arithmetical AND to the SubnetMask.
175 The default route is added with both SubnetAddress and SubnetMask set to 0.0.0.0.
176 The default route matches all destination IP addresses if there is no more specific route.
177 Direct route is added with GatewayAddress set to 0.0.0.0. Packets are sent to
178 the destination host if its address can be found in the Address Resolution Protocol (ARP)
179 cache or it is on the local subnet. If the instance is configured to use default
180 address, a direct route to the local network will be added automatically.
181 Each TCP instance has its own independent routing table. Instance that uses the
182 default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's routing table.
183 The copy will be updated automatically whenever the IP driver reconfigures its
184 instance. As a result, the previous modification to the instance's local copy
185 will be lost. The priority of checking the route table is specific with IP
186 implementation and every IP implementation must comply with RFC 1122.
188 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
189 @param DeleteRoute If TRUE, delete the specified route from routing
190 table; if FALSE, add the specified route to
192 DestinationAddress and SubnetMask are used as
193 the keywords to search route entry.
194 @param SubnetAddress The destination network.
195 @param SubnetMask The subnet mask for the destination network.
196 @param GatewayAddress The gateway address for this route.
197 It must be on the same subnet with the station
198 address unless a direct route is specified.
200 @retval EFI_SUCCESS The operation completed successfully.
201 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
203 @retval EFI_NO_MAPPING When using a default address, configuration
204 (through DHCP, BOOTP, RARP, etc.) is not
206 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
207 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
208 entry to the routing table.
209 @retval EFI_NOT_FOUND This route is not in the routing table.
210 @retval EFI_ACCESS_DENIED This route is already in the routing table.
211 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
217 IN EFI_TCP4_PROTOCOL
*This
,
218 IN BOOLEAN DeleteRoute
,
219 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
220 IN EFI_IPv4_ADDRESS
*SubnetMask
,
221 IN EFI_IPv4_ADDRESS
*GatewayAddress
225 Initiate a nonblocking TCP connection request for an active TCP instance.
227 The Connect() function will initiate an active open to the remote peer configured
228 in current TCP instance if it is configured active. If the connection succeeds
229 or fails due to any error, the ConnectionToken->CompletionToken.Event will be
230 signaled and ConnectionToken->CompletionToken.Status will be updated accordingly.
231 This function can only be called for the TCP instance in Tcp4StateClosed state.
232 The instance will transfer into Tcp4StateSynSent if the function returns EFI_SUCCESS.
233 If TCP three way handshake succeeds, its state will become Tcp4StateEstablished,
234 otherwise, the state will return to Tcp4StateClosed.
236 @param This Pointer to the EFI_TCP4_PROTOCOL instance
237 @param ConnectionToken Pointer to the connection token to return when
238 the TCP three way handshake finishes.
240 @retval EFI_SUCCESS The connection request is successfully initiated
241 and the state of this TCPv4 instance has
242 been changed to Tcp4StateSynSent.
243 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
245 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
246 or it is not in Tcp4StateClosed state.
247 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
248 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
249 initiate the active open.
250 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
256 IN EFI_TCP4_PROTOCOL
*This
,
257 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
261 Listen on the passive instance to accept an incoming connection request.
263 The Accept() function initiates an asynchronous accept request to wait for an
264 incoming connection on the passive TCP instance. If a remote peer successfully
265 establishes a connection with this instance, a new TCP instance will be created
266 and its handle will be returned in ListenToken->NewChildHandle. The newly created
267 instance is configured by inheriting the passive instance's configuration and is
268 ready for use upon return. The instance is in the Tcp4StateEstablished state.
269 The ListenToken->CompletionToken.Event will be signaled when a new connection
270 is accepted, user aborts the listen or connection is reset. This function only
271 can be called when current TCP instance is in Tcp4StateListen state.
273 @param This Pointer to the EFI_TCP4_PROTOCOL instance
274 @param ListenToken Pointer to the listen token to return when
277 @retval EFI_SUCCESS The listen token has been queued successfully.
278 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
280 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
281 in Tcp4StateListen state or a same listen token
282 has already existed in the listen token queue of
284 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
285 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
287 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above category error.
293 IN EFI_TCP4_PROTOCOL
*This
,
294 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
298 Queues outgoing data into the transmit queue.
300 The Transmit() function queues a sending request to this TCPv4 instance along
301 with the user data. The status of the token is updated and the event in the token
302 will be signaled once the data is sent out or some error occurs.
304 @param This Pointer to the EFI_TCP4_PROTOCOL instance
305 @param Token Pointer to the completion token to queue to the
308 @retval EFI_SUCCESS The data has been queued for transmission.
309 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
311 @retval EFI_NO_MAPPING When using a default address, configuration
312 (DHCP, BOOTP, RARP, etc.) is not finished yet.
313 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
314 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
315 * A transmit completion token with the same
316 Token-> CompletionToken.Event was already in the
318 * The current instance is in Tcp4StateClosed state
319 * The current instance is a passive one and
320 it is in Tcp4StateListen state.
321 * User has called Close() to disconnect this
323 @retval EFI_NOT_READY The completion token could not be queued because
324 the transmit queue is full.
325 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
327 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
334 IN EFI_TCP4_PROTOCOL
*This
,
335 IN EFI_TCP4_IO_TOKEN
*Token
339 Place an asynchronous receive request into the receiving queue.
341 The Receive() function places a completion token into the receive packet queue.
342 This function is always asynchronous. The caller must allocate the
343 Token->CompletionToken.Event and the FragmentBuffer used to receive data. He also
344 must fill the DataLength which represents the whole length of all FragmentBuffer.
345 When the receive operation completes, the EFI TCPv4 Protocol driver updates the
346 Token->CompletionToken.Status and Token->Packet.RxData fields and the
347 Token->CompletionToken.Event is signaled. If got data the data and its length
348 will be copy into the FragmentTable, in the same time the full length of received
349 data will be recorded in the DataLength fields. Providing a proper notification
350 function and context for the event will enable the user to receive the notification
351 and receiving status. That notification function is guaranteed to not be re-entered.
353 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
354 @param Token Pointer to a token that is associated with the
355 receive data descriptor.
357 @retval EFI_SUCCESS The receive completion token was cached.
358 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
360 @retval EFI_NO_MAPPING When using a default address, configuration
361 (DHCP, BOOTP, RARP, etc.) is not finished yet.
362 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
363 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
364 due to a lack of system resources.
365 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
366 The EFI TCPv4 Protocol instance has been reset
368 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
369 * A receive completion token with the same
370 Token->CompletionToken.Event was already in
372 * The current instance is in Tcp4StateClosed state.
373 * The current instance is a passive one and it
374 is in Tcp4StateListen state.
375 * User has called Close() to disconnect this
377 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
378 and there is no any buffered data in the receive
379 buffer of this instance.
380 @retval EFI_NOT_READY The receive request could not be queued because
381 the receive queue is full.
387 IN EFI_TCP4_PROTOCOL
*This
,
388 IN EFI_TCP4_IO_TOKEN
*Token
392 Disconnecting a TCP connection gracefully or reset a TCP connection.
394 Initiate an asynchronous close token to TCP driver. After Close() is called,
395 any buffered transmission data will be sent by TCP driver and the current
396 instance will have a graceful close working flow described as RFC 793 if
397 AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by TCP
398 driver to fast disconnect this connection. When the close operation completes
399 successfully the TCP instance is in Tcp4StateClosed state, all pending
400 asynchronous operation is signaled and any buffers used for TCP network traffic
403 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
404 @param CloseToken Pointer to the close token to return when
407 @retval EFI_SUCCESS The operation completed successfully.
408 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
410 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:
411 * Configure() has been called with TcpConfigData
412 set to NULL and this function has not returned.
413 * Previous Close() call on this instance has not
415 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.
416 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
418 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
425 IN EFI_TCP4_PROTOCOL
*This
,
426 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
430 Abort an asynchronous connection, listen, transmission or receive request.
432 The Cancel() function aborts a pending connection, listen, transmit or receive
433 request. If Token is not NULL and the token is in the connection, listen,
434 transmission or receive queue when it is being cancelled, its Token->Status
435 will be set to EFI_ABORTED and then Token->Event will be signaled. If the token
436 is not in one of the queues, which usually means that the asynchronous operation
437 has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchronous token
438 issued by Connect(), Accept(), Transmit() and Receive()will be aborted.
439 NOTE: It has not been implemented currently.
441 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
442 @param Token Pointer to a token that has been issued by
443 Connect(), Accept(), Transmit() or Receive(). If
444 NULL, all pending tokens issued by above four
445 functions will be aborted.
447 @retval EFI_SUCCESS The asynchronous I/O request is aborted and Token->Event
449 @retval EFI_INVALID_PARAMETER This is NULL.
450 @retval EFI_NOT_STARTED This instance hasn's been configured.
451 @retval EFI_NO_MAPPING When using the default address, configuration
452 (DHCP, BOOTP,RARP, etc.) hasn's finished yet.
453 @retval EFI_NOT_FOUND The asynchronous I/O request isn's found in the
454 transmission or receive queue. It has either
455 completed or wasn's issued by Transmit() and Receive().
456 @retval EFI_UNSUPPORTED The operation is not supported in current
463 IN EFI_TCP4_PROTOCOL
*This
,
464 IN EFI_TCP4_COMPLETION_TOKEN
*Token OPTIONAL
468 Poll to receive incoming data and transmit outgoing segments.
470 The Poll() function increases the rate that data is moved between the network
471 and application and can be called when the TCP instance is created successfully.
472 Its use is optional. In some implementations, the periodical timer in the MNP
473 driver may not poll the underlying communications device fast enough to avoid
474 drop packets. Drivers and applications that are experiencing packet loss should
475 try calling the Poll() function in a high frequency.
477 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
479 @retval EFI_SUCCESS Incoming or outgoing data was processed.
480 @retval EFI_INVALID_PARAMETER This is NULL.
481 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
482 @retval EFI_NOT_READY No incoming or outgoing data was processed.
483 @retval EFI_TIMEOUT Data was dropped out of the transmission or
484 receive queue. Consider increasing the polling
491 IN EFI_TCP4_PROTOCOL
*This