3 Copyright (c) 2005 - 2006, Intel Corporation
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
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.
18 Implementation of TCP4 protocol services.
27 Check the integrity of the data buffer.
29 @param DataLen The total length of the data buffer.
30 @param FragmentCount The fragment count of the fragment table.
31 @param FragmentTable Pointer to the fragment table of the data
34 @retval EFI_SUCCESS The integrity check is passed.
35 @retval EFI_INVALID_PARAMETER The integrity check is failed.
41 IN UINT32 FragmentCount
,
42 IN EFI_TCP4_FRAGMENT_DATA
*FragmentTable
49 for (Index
= 0, Len
= 0; Index
< FragmentCount
; Index
++) {
50 Len
= Len
+ (UINT32
) FragmentTable
[Index
].FragmentLength
;
54 return EFI_INVALID_PARAMETER
;
62 Get the current operational status.
64 The GetModeData() function copies the current operational settings of this
65 EFI TCPv4 Protocol instance into user-supplied buffers. This function can
66 also be used to retrieve the operational setting of underlying drivers
67 such as IPv4, MNP, or SNP.
69 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
70 @param Tcp4State Pointer to the buffer to receive the current TCP
72 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP
74 @param Ip4ModeData Pointer to the buffer to receive the current IPv4
75 configuration data used by the TCPv4 instance.
76 @param MnpConfigData Pointer to the buffer to receive the current MNP
77 configuration data indirectly used by the TCPv4
79 @param SnpModeData Pointer to the buffer to receive the current SNP
80 configuration data indirectly used by the TCPv4
83 @retval EFI_SUCCESS The mode data was read.
84 @retval EFI_NOT_STARTED No configuration data is available because this
85 instance hasn't been started.
86 @retval EFI_INVALID_PARAMETER This is NULL.
92 IN CONST EFI_TCP4_PROTOCOL
*This
,
93 OUT EFI_TCP4_CONNECTION_STATE
*Tcp4State OPTIONAL
,
94 OUT EFI_TCP4_CONFIG_DATA
*Tcp4ConfigData OPTIONAL
,
95 OUT EFI_IP4_MODE_DATA
*Ip4ModeData OPTIONAL
,
96 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
,
97 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
100 TCP4_MODE_DATA TcpMode
;
104 return EFI_INVALID_PARAMETER
;
107 Sock
= SOCK_FROM_THIS (This
);
109 TcpMode
.Tcp4State
= Tcp4State
;
110 TcpMode
.Tcp4ConfigData
= Tcp4ConfigData
;
111 TcpMode
.Ip4ModeData
= Ip4ModeData
;
112 TcpMode
.MnpConfigData
= MnpConfigData
;
113 TcpMode
.SnpModeData
= SnpModeData
;
115 return SockGetMode (Sock
, &TcpMode
);
120 Initialize or brutally reset the operational parameters for
121 this EFI TCPv4 instance.
123 The Configure() function does the following:
124 * Initialize this EFI TCPv4 instance, i.e., initialize the communication end
125 setting, specify active open or passive open for an instance.
126 * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous
127 tokens, flush transmission and receiving buffer directly without informing
128 the communication peer.
129 No other TCPv4 Protocol operation can be executed by this instance
130 until it is configured properly. For an active TCP4 instance, after a proper
131 configuration it may call Connect() to initiates the three-way handshake.
132 For a passive TCP4 instance, its state will transit to Tcp4StateListen after
133 configuration, and Accept() may be called to listen the incoming TCP connection
134 request. If TcpConfigData is set to NULL, the instance is reset. Resetting
135 process will be done brutally, the state machine will be set to Tcp4StateClosed
136 directly, the receive queue and transmit queue will be flushed, and no traffic is
137 allowed through this instance.
139 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
140 @param TcpConfigData Pointer to the configure data to configure the
143 @retval EFI_SUCCESS The operational settings are set, changed, or
145 @retval EFI_NO_MAPPING When using a default address, configuration
146 (through DHCP, BOOTP, RARP, etc.) is not
148 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
149 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already
151 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
152 @retval EFI_UNSUPPORTED One or more of the control options are not
153 supported in the implementation.
154 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
160 IN EFI_TCP4_PROTOCOL
*This
,
161 IN EFI_TCP4_CONFIG_DATA
*TcpConfigData OPTIONAL
164 EFI_TCP4_OPTION
*Option
;
171 return EFI_INVALID_PARAMETER
;
175 // Tcp protocol related parameter check will be conducted here
177 if (NULL
!= TcpConfigData
) {
179 CopyMem (&Ip
, &TcpConfigData
->AccessPoint
.RemoteAddress
, sizeof (IP4_ADDR
));
180 if ((Ip
!= 0) && !Ip4IsUnicast (NTOHL (Ip
), 0)) {
181 return EFI_INVALID_PARAMETER
;
184 if (TcpConfigData
->AccessPoint
.ActiveFlag
&&
185 (0 == TcpConfigData
->AccessPoint
.RemotePort
|| (Ip
== 0))) {
186 return EFI_INVALID_PARAMETER
;
189 if (!TcpConfigData
->AccessPoint
.UseDefaultAddress
) {
191 CopyMem (&Ip
, &TcpConfigData
->AccessPoint
.StationAddress
, sizeof (IP4_ADDR
));
192 CopyMem (&SubnetMask
, &TcpConfigData
->AccessPoint
.SubnetMask
, sizeof (IP4_ADDR
));
193 if (!Ip4IsUnicast (NTOHL (Ip
), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask
))) {
194 return EFI_INVALID_PARAMETER
;
198 Option
= TcpConfigData
->ControlOption
;
199 if ((NULL
!= Option
) &&
200 (Option
->EnableSelectiveAck
|| Option
->EnablePathMtuDiscovery
)) {
201 return EFI_UNSUPPORTED
;
205 Sock
= SOCK_FROM_THIS (This
);
207 if (NULL
== TcpConfigData
) {
208 return SockFlush (Sock
);
211 Status
= SockConfigure (Sock
, TcpConfigData
);
213 if (EFI_NO_MAPPING
== Status
) {
214 Sock
->ConfigureState
= SO_NO_MAPPING
;
222 Add or delete routing entries.
224 The Routes() function adds or deletes a route from the instance\92s routing table.
225 The most specific route is selected by comparing the SubnetAddress with the
226 destination IP address\92s arithmetical AND to the SubnetMask.
227 The default route is added with both SubnetAddress and SubnetMask set to 0.0.0.0.
228 The default route matches all destination IP addresses if there is no more specific route.
229 Direct route is added with GatewayAddress set to 0.0.0.0. Packets are sent to
230 the destination host if its address can be found in the Address Resolution Protocol (ARP)
231 cache or it is on the local subnet. If the instance is configured to use default
232 address, a direct route to the local network will be added automatically.
233 Each TCP instance has its own independent routing table. Instance that uses the
234 default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL\92s routing table.
235 The copy will be updated automatically whenever the IP driver reconfigures its
236 instance. As a result, the previous modification to the instance\92s local copy
237 will be lost. The priority of checking the route table is specific with IP
238 implementation and every IP implementation must comply with RFC 1122.
240 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
241 @param DeleteRoute If TRUE, delete the specified route from routing
242 table; if FALSE, add the specified route to
244 DestinationAddress and SubnetMask are used as
245 the keywords to search route entry.
246 @param SubnetAddress The destination network.
247 @param SubnetMask The subnet mask for the destination network.
248 @param GatewayAddress The gateway address for this route.
249 It must be on the same subnet with the station
250 address unless a direct route is specified.
252 @retval EFI_SUCCESS The operation completed successfully.
253 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
255 @retval EFI_NO_MAPPING When using a default address, configuration
256 (through DHCP, BOOTP, RARP, etc.) is not
258 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
259 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
260 entry to the routing table.
261 @retval EFI_NOT_FOUND This route is not in the routing table.
262 @retval EFI_ACCESS_DENIED This route is already in the routing table.
263 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
269 IN EFI_TCP4_PROTOCOL
*This
,
270 IN BOOLEAN DeleteRoute
,
271 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
272 IN EFI_IPv4_ADDRESS
*SubnetMask
,
273 IN EFI_IPv4_ADDRESS
*GatewayAddress
277 TCP4_ROUTE_INFO RouteInfo
;
280 return EFI_INVALID_PARAMETER
;
283 Sock
= SOCK_FROM_THIS (This
);
285 RouteInfo
.DeleteRoute
= DeleteRoute
;
286 RouteInfo
.SubnetAddress
= SubnetAddress
;
287 RouteInfo
.SubnetMask
= SubnetMask
;
288 RouteInfo
.GatewayAddress
= GatewayAddress
;
290 return SockRoute (Sock
, &RouteInfo
);
295 Initiate a nonblocking TCP connection request for an active TCP instance.
297 The Connect() function will initiate an active open to the remote peer configured
298 in current TCP instance if it is configured active. If the connection succeeds
299 or fails due to any error, the ConnectionToken->CompletionToken.Event will be
300 signaled and ConnectionToken->CompletionToken.Status will be updated accordingly.
301 This function can only be called for the TCP instance in Tcp4StateClosed state.
302 The instance will transfer into Tcp4StateSynSent if the function returns EFI_SUCCESS.
303 If TCP three way handshake succeeds, its state will become Tcp4StateEstablished,
304 otherwise, the state will return to Tcp4StateClosed.
306 @param This Pointer to the EFI_TCP4_PROTOCOL instance
307 @param ConnectionToken Pointer to the connection token to return when
308 the TCP three way handshake finishes.
310 @retval EFI_SUCCESS The connection request is successfully initiated
311 and the state of this TCPv4 instance has
312 been changed to Tcp4StateSynSent.
313 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
315 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
316 or it is not in Tcp4StateClosed state.
317 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
318 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
319 initiate the active open.
320 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
326 IN EFI_TCP4_PROTOCOL
*This
,
327 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
333 NULL
== ConnectionToken
||
334 NULL
== ConnectionToken
->CompletionToken
.Event
) {
335 return EFI_INVALID_PARAMETER
;
338 Sock
= SOCK_FROM_THIS (This
);
340 return SockConnect (Sock
, ConnectionToken
);
345 Listen on the passive instance to accept an incoming connection request.
347 The Accept() function initiates an asynchronous accept request to wait for an
348 incoming connection on the passive TCP instance. If a remote peer successfully
349 establishes a connection with this instance, a new TCP instance will be created
350 and its handle will be returned in ListenToken->NewChildHandle. The newly created
351 instance is configured by inheriting the passive instance\92s configuration and is
352 ready for use upon return. The instance is in the Tcp4StateEstablished state.
353 The ListenToken->CompletionToken.Event will be signaled when a new connection
354 is accepted, user aborts the listen or connection is reset. This function only
355 can be called when current TCP instance is in Tcp4StateListen state.
357 @param This Pointer to the EFI_TCP4_PROTOCOL instance
358 @param ListenToken Pointer to the listen token to return when
361 @retval EFI_SUCCESS The listen token has been queued successfully.
362 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
364 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
365 in Tcp4StateListen state or a same listen token
366 has already existed in the listen token queue of
368 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
369 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
371 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above category error.
377 IN EFI_TCP4_PROTOCOL
*This
,
378 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
384 NULL
== ListenToken
||
385 NULL
== ListenToken
->CompletionToken
.Event
) {
386 return EFI_INVALID_PARAMETER
;
389 Sock
= SOCK_FROM_THIS (This
);
391 return SockAccept (Sock
, ListenToken
);
396 Queues outgoing data into the transmit queue.
398 The Transmit() function queues a sending request to this TCPv4 instance along
399 with the user data. The status of the token is updated and the event in the token
400 will be signaled once the data is sent out or some error occurs.
402 @param This Pointer to the EFI_TCP4_PROTOCOL instance
403 @param Token Pointer to the completion token to queue to the
406 @retval EFI_SUCCESS The data has been queued for transmission.
407 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
409 @retval EFI_NO_MAPPING When using a default address, configuration
410 (DHCP, BOOTP, RARP, etc.) is not finished yet.
411 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
412 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
413 * A transmit completion token with the same
414 Token-> CompletionToken.Event was already in the
416 * The current instance is in Tcp4StateClosed state
417 * The current instance is a passive one and
418 it is in Tcp4StateListen state.
419 * User has called Close() to disconnect this
421 @retval EFI_NOT_READY The completion token could not be queued because
422 the transmit queue is full.
423 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
425 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
432 IN EFI_TCP4_PROTOCOL
*This
,
433 IN EFI_TCP4_IO_TOKEN
*Token
441 NULL
== Token
->CompletionToken
.Event
||
442 NULL
== Token
->Packet
.TxData
||
443 0 == Token
->Packet
.TxData
->FragmentCount
||
444 0 == Token
->Packet
.TxData
->DataLength
446 return EFI_INVALID_PARAMETER
;
449 Status
= Tcp4ChkDataBuf (
450 (UINT32
) Token
->Packet
.TxData
->DataLength
,
451 (UINT32
) Token
->Packet
.TxData
->FragmentCount
,
452 Token
->Packet
.TxData
->FragmentTable
454 if (EFI_ERROR (Status
)) {
458 Sock
= SOCK_FROM_THIS (This
);
460 return SockSend (Sock
, Token
);
466 Place an asynchronous receive request into the receiving queue.
468 The Receive() function places a completion token into the receive packet queue.
469 This function is always asynchronous. The caller must allocate the
470 Token->CompletionToken.Event and the FragmentBuffer used to receive data. He also
471 must fill the DataLength which represents the whole length of all FragmentBuffer.
472 When the receive operation completes, the EFI TCPv4 Protocol driver updates the
473 Token->CompletionToken.Status and Token->Packet.RxData fields and the
474 Token->CompletionToken.Event is signaled. If got data the data and its length
475 will be copy into the FragmentTable, in the same time the full length of received
476 data will be recorded in the DataLength fields. Providing a proper notification
477 function and context for the event will enable the user to receive the notification
478 and receiving status. That notification function is guaranteed to not be re-entered.
480 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
481 @param Token Pointer to a token that is associated with the
482 receive data descriptor.
484 @retval EFI_SUCCESS The receive completion token was cached.
485 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
487 @retval EFI_NO_MAPPING When using a default address, configuration
488 (DHCP, BOOTP, RARP, etc.) is not finished yet.
489 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
490 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
491 due to a lack of system resources.
492 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
493 The EFI TCPv4 Protocol instance has been reset
495 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
496 * A receive completion token with the same
497 Token->CompletionToken.Event was already in
499 * The current instance is in Tcp4StateClosed state.
500 * The current instance is a passive one and it
501 is in Tcp4StateListen state.
502 * User has called Close() to disconnect this
504 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
505 and there is no any buffered data in the receive
506 buffer of this instance.
507 @retval EFI_NOT_READY The receive request could not be queued because
508 the receive queue is full.
514 IN EFI_TCP4_PROTOCOL
*This
,
515 IN EFI_TCP4_IO_TOKEN
*Token
523 NULL
== Token
->CompletionToken
.Event
||
524 NULL
== Token
->Packet
.RxData
||
525 0 == Token
->Packet
.RxData
->FragmentCount
||
526 0 == Token
->Packet
.RxData
->DataLength
528 return EFI_INVALID_PARAMETER
;
531 Status
= Tcp4ChkDataBuf (
532 (UINT32
) Token
->Packet
.RxData
->DataLength
,
533 (UINT32
) Token
->Packet
.RxData
->FragmentCount
,
534 Token
->Packet
.RxData
->FragmentTable
536 if (EFI_ERROR (Status
)) {
540 Sock
= SOCK_FROM_THIS (This
);
542 return SockRcv (Sock
, Token
);
548 Disconnecting a TCP connection gracefully or reset a TCP connection.
550 Initiate an asynchronous close token to TCP driver. After Close() is called,
551 any buffered transmission data will be sent by TCP driver and the current
552 instance will have a graceful close working flow described as RFC 793 if
553 AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by TCP
554 driver to fast disconnect this connection. When the close operation completes
555 successfully the TCP instance is in Tcp4StateClosed state, all pending
556 asynchronous operation is signaled and any buffers used for TCP network traffic
559 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
560 @param CloseToken Pointer to the close token to return when
563 @retval EFI_SUCCESS The operation completed successfully.
564 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
566 @retval EFI_ACCESS_DENIED One or more of the following are TRUE:
567 * Configure() has been called with TcpConfigData
568 set to NULL and this function has not returned.
569 * Previous Close() call on this instance has not
571 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.
572 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
574 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
581 IN EFI_TCP4_PROTOCOL
*This
,
582 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
588 NULL
== CloseToken
||
589 NULL
== CloseToken
->CompletionToken
.Event
) {
590 return EFI_INVALID_PARAMETER
;
593 Sock
= SOCK_FROM_THIS (This
);
595 return SockClose (Sock
, CloseToken
, CloseToken
->AbortOnClose
);
600 Abort an asynchronous connection, listen, transmission or receive request.
602 The Cancel() function aborts a pending connection, listen, transmit or receive
603 request. If Token is not NULL and the token is in the connection, listen,
604 transmission or receive queue when it is being cancelled, its Token->Status
605 will be set to EFI_ABORTED and then Token->Event will be signaled. If the token
606 is not in one of the queues, which usually means that the asynchronous operation
607 has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchronous token
608 issued by Connect(), Accept(), Transmit() and Receive()will be aborted.
609 NOTE: It has not been implemented currently.
611 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
612 @param Token Pointer to a token that has been issued by
613 Connect(), Accept(), Transmit() or Receive(). If
614 NULL, all pending tokens issued by above four
615 functions will be aborted.
617 @retval EFI_SUCCESS The asynchronous I/O request is aborted and Token->Event
619 @retval EFI_INVALID_PARAMETER This is NULL.
620 @retval EFI_NOT_STARTED This instance hasn\92t been configured.
621 @retval EFI_NO_MAPPING When using the default address, configuration
622 (DHCP, BOOTP,RARP, etc.) hasn\92t finished yet.
623 @retval EFI_NOT_FOUND The asynchronous I/O request isn\92t found in the
624 transmission or receive queue. It has either
625 completed or wasn\92t issued by Transmit() and Receive().
626 @retval EFI_UNSUPPORTED The operation is not supported in current
633 IN EFI_TCP4_PROTOCOL
*This
,
634 IN EFI_TCP4_COMPLETION_TOKEN
*Token OPTIONAL
637 return EFI_UNSUPPORTED
;
642 Poll to receive incoming data and transmit outgoing segments.
644 The Poll() function increases the rate that data is moved between the network
645 and application and can be called when the TCP instance is created successfully.
646 Its use is optional. In some implementations, the periodical timer in the MNP
647 driver may not poll the underlying communications device fast enough to avoid
648 drop packets. Drivers and applications that are experiencing packet loss should
649 try calling the Poll() function in a high frequency.
651 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
653 @retval EFI_SUCCESS Incoming or outgoing data was processed.
654 @retval EFI_INVALID_PARAMETER This is NULL.
655 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
656 @retval EFI_NOT_READY No incoming or outgoing data was processed.
657 @retval EFI_TIMEOUT Data was dropped out of the transmission or
658 receive queue. Consider increasing the polling
665 IN EFI_TCP4_PROTOCOL
*This
672 return EFI_INVALID_PARAMETER
;
675 Sock
= SOCK_FROM_THIS (This
);
677 Status
= Sock
->ProtoHandler (Sock
, SOCK_POLL
, NULL
);