3 Copyright (c) 2005 - 2006, Intel Corporation<BR>
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php<BR>
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "Tcp4Proto.h"
20 #include "Tcp4Driver.h"
23 extern UINT16 mTcp4RandomPort
;
24 extern CHAR16
*mTcpStateName
[];
27 // Driver Produced Protocol Prototypes
31 // Function prototype for the Tcp4 socket request handler
34 The procotol handler provided to the socket layer, used to
35 dispatch the socket level requests by calling the corresponding
38 @param Sock Pointer to the socket of this TCP instance.
39 @param Request The code of this operation request.
40 @param Data Pointer to the operation specific data passed in
41 together with the operation request.
43 @retval EFI_SUCCESS The socket request is completed successfully.
44 @retval other The error status returned by the corresponding TCP
51 IN SOCK_REQUEST Request
,
52 IN VOID
*Data OPTIONAL
58 typedef struct _TCP4_MODE_DATA
{
59 EFI_TCP4_CONNECTION_STATE
*Tcp4State
;
60 EFI_TCP4_CONFIG_DATA
*Tcp4ConfigData
;
61 EFI_IP4_MODE_DATA
*Ip4ModeData
;
62 EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData
;
63 EFI_SIMPLE_NETWORK_MODE
*SnpModeData
;
67 /// TCP route infomation data
69 typedef struct _TCP4_ROUTE_INFO
{
71 EFI_IPv4_ADDRESS
*SubnetAddress
;
72 EFI_IPv4_ADDRESS
*SubnetMask
;
73 EFI_IPv4_ADDRESS
*GatewayAddress
;
77 Get the current operational status of a TCP instance.
79 The GetModeData() function copies the current operational settings of this
80 EFI TCPv4 Protocol instance into user-supplied buffers. This function can
81 also be used to retrieve the operational setting of underlying drivers
82 such as IPv4, MNP, or SNP.
84 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
85 @param Tcp4State Pointer to the buffer to receive the current TCP
87 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP
89 @param Ip4ModeData Pointer to the buffer to receive the current IPv4
90 configuration data used by the TCPv4 instance.
91 @param MnpConfigData Pointer to the buffer to receive the current MNP
92 configuration data indirectly used by the TCPv4
94 @param SnpModeData Pointer to the buffer to receive the current SNP
95 configuration data indirectly used by the TCPv4
98 @retval EFI_SUCCESS The mode data was read.
99 @retval EFI_NOT_STARTED No configuration data is available because this
100 instance hasn't been started.
101 @retval EFI_INVALID_PARAMETER This is NULL.
107 IN CONST EFI_TCP4_PROTOCOL
*This
,
108 OUT EFI_TCP4_CONNECTION_STATE
*Tcp4State OPTIONAL
,
109 OUT EFI_TCP4_CONFIG_DATA
*Tcp4ConfigData OPTIONAL
,
110 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
111 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
112 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
117 Initialize or brutally reset the operational parameters for
118 this EFI TCPv4 instance.
120 The Configure() function does the following:
121 * Initialize this EFI TCPv4 instance, i.e., initialize the communication end
122 setting, specify active open or passive open for an instance.
123 * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous
124 tokens, flush transmission and receiving buffer directly without informing
125 the communication peer.
126 No other TCPv4 Protocol operation can be executed by this instance
127 until it is configured properly. For an active TCP4 instance, after a proper
128 configuration it may call Connect() to initiates the three-way handshake.
129 For a passive TCP4 instance, its state will transit to Tcp4StateListen after
130 configuration, and Accept() may be called to listen the incoming TCP connection
131 request. If TcpConfigData is set to NULL, the instance is reset. Resetting
132 process will be done brutally, the state machine will be set to Tcp4StateClosed
133 directly, the receive queue and transmit queue will be flushed, and no traffic is
134 allowed through this instance.
136 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
137 @param TcpConfigData Pointer to the configure data to configure the
140 @retval EFI_SUCCESS The operational settings are set, changed, or
142 @retval EFI_NO_MAPPING When using a default address, configuration
143 (through DHCP, BOOTP, RARP, etc.) is not
145 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
146 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already
148 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
149 @retval EFI_UNSUPPORTED One or more of the control options are not
150 supported in the implementation.
151 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
157 IN EFI_TCP4_PROTOCOL
*This
,
158 IN EFI_TCP4_CONFIG_DATA
*TcpConfigData OPTIONAL
162 Add or delete routing entries.
164 The Routes() function adds or deletes a route from the instance's routing table.
165 The most specific route is selected by comparing the SubnetAddress with the
166 destination IP address's arithmetical AND to the SubnetMask.
167 The default route is added with both SubnetAddress and SubnetMask set to 0.0.0.0.
168 The default route matches all destination IP addresses if there is no more specific route.
169 Direct route is added with GatewayAddress set to 0.0.0.0. Packets are sent to
170 the destination host if its address can be found in the Address Resolution Protocol (ARP)
171 cache or it is on the local subnet. If the instance is configured to use default
172 address, a direct route to the local network will be added automatically.
173 Each TCP instance has its own independent routing table. Instance that uses the
174 default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's routing table.
175 The copy will be updated automatically whenever the IP driver reconfigures its
176 instance. As a result, the previous modification to the instance's local copy
177 will be lost. The priority of checking the route table is specific with IP
178 implementation and every IP implementation must comply with RFC 1122.
180 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
181 @param DeleteRoute If TRUE, delete the specified route from routing
182 table; if FALSE, add the specified route to
184 DestinationAddress and SubnetMask are used as
185 the keywords to search route entry.
186 @param SubnetAddress The destination network.
187 @param SubnetMask The subnet mask for the destination network.
188 @param GatewayAddress The gateway address for this route.
189 It must be on the same subnet with the station
190 address unless a direct route is specified.
192 @retval EFI_SUCCESS The operation completed successfully.
193 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
195 @retval EFI_NO_MAPPING When using a default address, configuration
196 (through DHCP, BOOTP, RARP, etc.) is not
198 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
199 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
200 entry to the routing table.
201 @retval EFI_NOT_FOUND This route is not in the routing table.
202 @retval EFI_ACCESS_DENIED This route is already in the routing table.
203 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
209 IN EFI_TCP4_PROTOCOL
*This
,
210 IN BOOLEAN DeleteRoute
,
211 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
212 IN EFI_IPv4_ADDRESS
*SubnetMask
,
213 IN EFI_IPv4_ADDRESS
*GatewayAddress
217 Initiate a nonblocking TCP connection request for an active TCP instance.
219 The Connect() function will initiate an active open to the remote peer configured
220 in current TCP instance if it is configured active. If the connection succeeds
221 or fails due to any error, the ConnectionToken->CompletionToken.Event will be
222 signaled and ConnectionToken->CompletionToken.Status will be updated accordingly.
223 This function can only be called for the TCP instance in Tcp4StateClosed state.
224 The instance will transfer into Tcp4StateSynSent if the function returns EFI_SUCCESS.
225 If TCP three way handshake succeeds, its state will become Tcp4StateEstablished,
226 otherwise, the state will return to Tcp4StateClosed.
228 @param This Pointer to the EFI_TCP4_PROTOCOL instance
229 @param ConnectionToken Pointer to the connection token to return when
230 the TCP three way handshake finishes.
232 @retval EFI_SUCCESS The connection request is successfully initiated
233 and the state of this TCPv4 instance has
234 been changed to Tcp4StateSynSent.
235 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
237 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
238 or it is not in Tcp4StateClosed state.
239 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
240 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
241 initiate the active open.
242 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
248 IN EFI_TCP4_PROTOCOL
*This
,
249 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
253 Listen on the passive instance to accept an incoming connection request.
255 The Accept() function initiates an asynchronous accept request to wait for an
256 incoming connection on the passive TCP instance. If a remote peer successfully
257 establishes a connection with this instance, a new TCP instance will be created
258 and its handle will be returned in ListenToken->NewChildHandle. The newly created
259 instance is configured by inheriting the passive instance's configuration and is
260 ready for use upon return. The instance is in the Tcp4StateEstablished state.
261 The ListenToken->CompletionToken.Event will be signaled when a new connection
262 is accepted, user aborts the listen or connection is reset. This function only
263 can be called when current TCP instance is in Tcp4StateListen state.
265 @param This Pointer to the EFI_TCP4_PROTOCOL instance
266 @param ListenToken Pointer to the listen token to return when
269 @retval EFI_SUCCESS The listen token has been queued successfully.
270 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
272 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
273 in Tcp4StateListen state or a same listen token
274 has already existed in the listen token queue of
276 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
277 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
279 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above category error.
285 IN EFI_TCP4_PROTOCOL
*This
,
286 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
290 Queues outgoing data into the transmit queue.
292 The Transmit() function queues a sending request to this TCPv4 instance along
293 with the user data. The status of the token is updated and the event in the token
294 will be signaled once the data is sent out or some error occurs.
296 @param This Pointer to the EFI_TCP4_PROTOCOL instance
297 @param Token Pointer to the completion token to queue to the
300 @retval EFI_SUCCESS The data has been queued for transmission.
301 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
303 @retval EFI_NO_MAPPING When using a default address, configuration
304 (DHCP, BOOTP, RARP, etc.) is not finished yet.
305 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
306 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
307 * A transmit completion token with the same
308 Token-> CompletionToken.Event was already in the
310 * The current instance is in Tcp4StateClosed state
311 * The current instance is a passive one and
312 it is in Tcp4StateListen state.
313 * User has called Close() to disconnect this
315 @retval EFI_NOT_READY The completion token could not be queued because
316 the transmit queue is full.
317 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
319 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
326 IN EFI_TCP4_PROTOCOL
*This
,
327 IN EFI_TCP4_IO_TOKEN
*Token
331 Place an asynchronous receive request into the receiving queue.
333 The Receive() function places a completion token into the receive packet queue.
334 This function is always asynchronous. The caller must allocate the
335 Token->CompletionToken.Event and the FragmentBuffer used to receive data. He also
336 must fill the DataLength which represents the whole length of all FragmentBuffer.
337 When the receive operation completes, the EFI TCPv4 Protocol driver updates the
338 Token->CompletionToken.Status and Token->Packet.RxData fields and the
339 Token->CompletionToken.Event is signaled. If got data the data and its length
340 will be copy into the FragmentTable, in the same time the full length of received
341 data will be recorded in the DataLength fields. Providing a proper notification
342 function and context for the event will enable the user to receive the notification
343 and receiving status. That notification function is guaranteed to not be re-entered.
345 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
346 @param Token Pointer to a token that is associated with the
347 receive data descriptor.
349 @retval EFI_SUCCESS The receive completion token was cached.
350 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
352 @retval EFI_NO_MAPPING When using a default address, configuration
353 (DHCP, BOOTP, RARP, etc.) is not finished yet.
354 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
355 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
356 due to a lack of system resources.
357 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
358 The EFI TCPv4 Protocol instance has been reset
360 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
361 * A receive completion token with the same
362 Token->CompletionToken.Event was already in
364 * The current instance is in Tcp4StateClosed state.
365 * The current instance is a passive one and it
366 is in Tcp4StateListen state.
367 * User has called Close() to disconnect this
369 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
370 and there is no any buffered data in the receive
371 buffer of this instance.
372 @retval EFI_NOT_READY The receive request could not be queued because
373 the receive queue is full.
379 IN EFI_TCP4_PROTOCOL
*This
,
380 IN EFI_TCP4_IO_TOKEN
*Token
384 Disconnecting a TCP connection gracefully or reset a TCP connection.
386 Initiate an asynchronous close token to TCP driver. After Close() is called,
387 any buffered transmission data will be sent by TCP driver and the current
388 instance will have a graceful close working flow described as RFC 793 if
389 AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by TCP
390 driver to fast disconnect this connection. When the close operation completes
391 successfully the TCP instance is in Tcp4StateClosed state, all pending
392 asynchronous operation is signaled and any buffers used for TCP network traffic
395 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
396 @param CloseToken Pointer to the close token to return when
399 @retval EFI_SUCCESS The operation completed successfully.
400 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
402 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:
403 * Configure() has been called with TcpConfigData
404 set to NULL and this function has not returned.
405 * Previous Close() call on this instance has not
407 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.
408 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
410 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
417 IN EFI_TCP4_PROTOCOL
*This
,
418 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
422 Abort an asynchronous connection, listen, transmission or receive request.
424 The Cancel() function aborts a pending connection, listen, transmit or receive
425 request. If Token is not NULL and the token is in the connection, listen,
426 transmission or receive queue when it is being cancelled, its Token->Status
427 will be set to EFI_ABORTED and then Token->Event will be signaled. If the token
428 is not in one of the queues, which usually means that the asynchronous operation
429 has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchronous token
430 issued by Connect(), Accept(), Transmit() and Receive()will be aborted.
431 NOTE: It has not been implemented currently.
433 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
434 @param Token Pointer to a token that has been issued by
435 Connect(), Accept(), Transmit() or Receive(). If
436 NULL, all pending tokens issued by above four
437 functions will be aborted.
439 @retval EFI_SUCCESS The asynchronous I/O request is aborted and Token->Event
441 @retval EFI_INVALID_PARAMETER This is NULL.
442 @retval EFI_NOT_STARTED This instance hasn's been configured.
443 @retval EFI_NO_MAPPING When using the default address, configuration
444 (DHCP, BOOTP,RARP, etc.) hasn's finished yet.
445 @retval EFI_NOT_FOUND The asynchronous I/O request isn's found in the
446 transmission or receive queue. It has either
447 completed or wasn's issued by Transmit() and Receive().
448 @retval EFI_UNSUPPORTED The operation is not supported in current
455 IN EFI_TCP4_PROTOCOL
*This
,
456 IN EFI_TCP4_COMPLETION_TOKEN
*Token OPTIONAL
460 Poll to receive incoming data and transmit outgoing segments.
462 The Poll() function increases the rate that data is moved between the network
463 and application and can be called when the TCP instance is created successfully.
464 Its use is optional. In some implementations, the periodical timer in the MNP
465 driver may not poll the underlying communications device fast enough to avoid
466 drop packets. Drivers and applications that are experiencing packet loss should
467 try calling the Poll() function in a high frequency.
469 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
471 @retval EFI_SUCCESS Incoming or outgoing data was processed.
472 @retval EFI_INVALID_PARAMETER This is NULL.
473 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
474 @retval EFI_NOT_READY No incoming or outgoing data was processed.
475 @retval EFI_TIMEOUT Data was dropped out of the transmission or
476 receive queue. Consider increasing the polling
483 IN EFI_TCP4_PROTOCOL
*This