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.
42 IN UINT32 FragmentCount
,
43 IN EFI_TCP4_FRAGMENT_DATA
*FragmentTable
50 for (Index
= 0, Len
= 0; Index
< FragmentCount
; Index
++) {
51 Len
= Len
+ FragmentTable
[Index
].FragmentLength
;
55 return EFI_INVALID_PARAMETER
;
63 Get the current operational status.
65 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
66 @param Tcp4State Pointer to the buffer to receive the current TCP
68 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP
70 @param Ip4ModeData Pointer to the buffer to receive the current
72 @param MnpConfigData Pointer to the buffer to receive the current MNP
73 configuration data indirectly used by the TCPv4
75 @param SnpModeData Pointer to the buffer to receive the current SNP
76 configuration data indirectly used by the TCPv4
79 @retval EFI_SUCCESS The mode data was read.
80 @retval EFI_NOT_STARTED No configuration data is available because this
81 instance hasn't been started.
82 @retval EFI_INVALID_PARAMETER This is NULL.
88 IN CONST EFI_TCP4_PROTOCOL
* This
,
89 OUT EFI_TCP4_CONNECTION_STATE
* Tcp4State OPTIONAL
,
90 OUT EFI_TCP4_CONFIG_DATA
* Tcp4ConfigData OPTIONAL
,
91 OUT EFI_IP4_MODE_DATA
* Ip4ModeData OPTIONAL
,
92 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
* MnpConfigData OPTIONAL
,
93 OUT EFI_SIMPLE_NETWORK_MODE
* SnpModeData OPTIONAL
96 TCP4_MODE_DATA TcpMode
;
100 return EFI_INVALID_PARAMETER
;
103 Sock
= SOCK_FROM_THIS (This
);
105 TcpMode
.Tcp4State
= Tcp4State
;
106 TcpMode
.Tcp4ConfigData
= Tcp4ConfigData
;
107 TcpMode
.Ip4ModeData
= Ip4ModeData
;
108 TcpMode
.MnpConfigData
= MnpConfigData
;
109 TcpMode
.SnpModeData
= SnpModeData
;
111 return SockGetMode (Sock
, &TcpMode
);
116 Initialize or brutally reset the operational parameters for
117 this EFI TCPv4 instance.
119 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
120 @param TcpConfigData Pointer to the configure data to configure the
123 @retval EFI_SUCCESS The operational settings are set, changed, or
125 @retval EFI_NO_MAPPING When using a default address, configuration
126 (through DHCP, BOOTP, RARP, etc.) is not
128 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
129 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already
131 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
132 @retval EFI_UNSUPPORTED One or more of the control options are not
133 supported in the implementation.
134 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
140 IN EFI_TCP4_PROTOCOL
* This
,
141 IN EFI_TCP4_CONFIG_DATA
* TcpConfigData OPTIONAL
144 EFI_TCP4_OPTION
*Option
;
149 return EFI_INVALID_PARAMETER
;
153 // Tcp protocol related parameter check will be conducted here
155 if (NULL
!= TcpConfigData
) {
156 if ((EFI_IP4 (TcpConfigData
->AccessPoint
.RemoteAddress
) != 0) &&
157 !Ip4IsUnicast (EFI_NTOHL (TcpConfigData
->AccessPoint
.RemoteAddress
), 0)) {
158 return EFI_INVALID_PARAMETER
;
161 if (!TcpConfigData
->AccessPoint
.UseDefaultAddress
) {
162 if (!Ip4IsUnicast (EFI_NTOHL (TcpConfigData
->AccessPoint
.StationAddress
), 0) ||
163 !IP4_IS_VALID_NETMASK (EFI_NTOHL (TcpConfigData
->AccessPoint
.SubnetMask
))
165 return EFI_INVALID_PARAMETER
;
169 if (TcpConfigData
->AccessPoint
.ActiveFlag
&&
170 (0 == TcpConfigData
->AccessPoint
.RemotePort
||
171 (EFI_IP4 (TcpConfigData
->AccessPoint
.RemoteAddress
) == 0))
173 return EFI_INVALID_PARAMETER
;
176 Option
= TcpConfigData
->ControlOption
;
177 if ((NULL
!= Option
) &&
178 (Option
->EnableSelectiveAck
|| Option
->EnablePathMtuDiscovery
)) {
179 return EFI_UNSUPPORTED
;
183 Sock
= SOCK_FROM_THIS (This
);
185 if (NULL
== TcpConfigData
) {
186 return SockFlush (Sock
);
189 Status
= SockConfigure (Sock
, TcpConfigData
);
191 if (EFI_NO_MAPPING
== Status
) {
192 Sock
->ConfigureState
= SO_NO_MAPPING
;
200 Add or delete routing entries.
202 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
203 @param DeleteRoute If TRUE, delete the specified route from routing
204 table; if FALSE, add the specified route to
206 @param SubnetAddress The destination network.
207 @param SubnetMask The subnet mask for the destination network.
208 @param GatewayAddress The gateway address for this route.
210 @retval EFI_SUCCESS The operation completed successfully.
211 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
213 @retval EFI_NO_MAPPING When using a default address, configuration
214 (through DHCP, BOOTP, RARP, etc.) is not
216 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
217 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
218 entry to the routing table.
219 @retval EFI_NOT_FOUND This route is not in the routing table.
220 @retval EFI_ACCESS_DENIED This route is already in the routing table.
221 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
227 IN EFI_TCP4_PROTOCOL
*This
,
228 IN BOOLEAN DeleteRoute
,
229 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
230 IN EFI_IPv4_ADDRESS
*SubnetMask
,
231 IN EFI_IPv4_ADDRESS
*GatewayAddress
235 TCP4_ROUTE_INFO RouteInfo
;
238 return EFI_INVALID_PARAMETER
;
241 Sock
= SOCK_FROM_THIS (This
);
243 RouteInfo
.DeleteRoute
= DeleteRoute
;
244 RouteInfo
.SubnetAddress
= SubnetAddress
;
245 RouteInfo
.SubnetMask
= SubnetMask
;
246 RouteInfo
.GatewayAddress
= GatewayAddress
;
248 return SockRoute (Sock
, &RouteInfo
);
253 Initiate a nonblocking TCP connection request for an active TCP instance.
255 @param This Pointer to the EFI_TCP4_PROTOCOL instance
256 @param ConnectionToken Pointer to the connection token to return when
257 the TCP three way handshake finishes.
259 @retval EFI_SUCCESS The connection request is successfully
261 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
263 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
264 or it is not in Tcp4StateClosed state.
265 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
266 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
267 initiate the active open.
268 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
274 IN EFI_TCP4_PROTOCOL
*This
,
275 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
281 NULL
== ConnectionToken
||
282 NULL
== ConnectionToken
->CompletionToken
.Event
) {
283 return EFI_INVALID_PARAMETER
;
286 Sock
= SOCK_FROM_THIS (This
);
288 return SockConnect (Sock
, ConnectionToken
);
293 Listen on the passive instance to accept an incoming connection request.
295 @param This Pointer to the EFI_TCP4_PROTOCOL instance
296 @param ListenToken Pointer to the listen token to return when
299 @retval EFI_SUCCESS The listen token has been queued successfully.
300 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
302 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
303 in Tcp4StateListen state or a same listen token
304 has already existed in the listen token queue of
306 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
307 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
309 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
315 IN EFI_TCP4_PROTOCOL
*This
,
316 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
322 NULL
== ListenToken
||
323 NULL
== ListenToken
->CompletionToken
.Event
) {
324 return EFI_INVALID_PARAMETER
;
327 Sock
= SOCK_FROM_THIS (This
);
329 return SockAccept (Sock
, ListenToken
);
334 Queues outgoing data into the transmit queue
336 @param This Pointer to the EFI_TCP4_PROTOCOL instance
337 @param Token Pointer to the completion token to queue to the
340 @retval EFI_SUCCESS The data has been queued for transmission
341 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
343 @retval EFI_NO_MAPPING When using a default address, configuration
344 (DHCP, BOOTP, RARP, etc.) is not finished yet.
345 @retval EFI_INVALID_PARAMETER One or more parameters are invalid
346 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
347 * A transmit completion token with the same
348 Token-> CompletionToken.Event was already in the
349 transmission queue. * The current instance is in
350 Tcp4StateClosed state * The current instance is
351 a passive one and it is in Tcp4StateListen
352 state. * User has called Close() to disconnect
354 @retval EFI_NOT_READY The completion token could not be queued because
355 the transmit queue is full.
356 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
358 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
365 IN EFI_TCP4_PROTOCOL
*This
,
366 IN EFI_TCP4_IO_TOKEN
*Token
374 NULL
== Token
->CompletionToken
.Event
||
375 NULL
== Token
->Packet
.TxData
||
376 0 == Token
->Packet
.TxData
->FragmentCount
||
377 0 == Token
->Packet
.TxData
->DataLength
379 return EFI_INVALID_PARAMETER
;
382 Status
= Tcp4ChkDataBuf (
383 Token
->Packet
.TxData
->DataLength
,
384 Token
->Packet
.TxData
->FragmentCount
,
385 Token
->Packet
.TxData
->FragmentTable
387 if (EFI_ERROR (Status
)) {
391 Sock
= SOCK_FROM_THIS (This
);
393 return SockSend (Sock
, Token
);
399 Place an asynchronous receive request into the receiving queue.
401 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
402 @param Token Pointer to a token that is associated with the
403 receive data descriptor.
405 @retval EFI_SUCCESS The receive completion token was cached
406 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
408 @retval EFI_NO_MAPPING When using a default address, configuration
409 (DHCP, BOOTP, RARP, etc.) is not finished yet.
410 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
411 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
412 due to a lack of system resources.
413 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
414 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
415 * A receive completion token with the same
416 Token->CompletionToken.Event was already in the
417 receive queue. * The current instance is in
418 Tcp4StateClosed state. * The current instance is
419 a passive one and it is in Tcp4StateListen
420 state. * User has called Close() to disconnect
422 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
423 and there is no any buffered data in the receive
424 buffer of this instance.
425 @retval EFI_NOT_READY The receive request could not be queued because
426 the receive queue is full.
432 IN EFI_TCP4_PROTOCOL
*This
,
433 IN EFI_TCP4_IO_TOKEN
*Token
441 NULL
== Token
->CompletionToken
.Event
||
442 NULL
== Token
->Packet
.RxData
||
443 0 == Token
->Packet
.RxData
->FragmentCount
||
444 0 == Token
->Packet
.RxData
->DataLength
446 return EFI_INVALID_PARAMETER
;
449 Status
= Tcp4ChkDataBuf (
450 Token
->Packet
.RxData
->DataLength
,
451 Token
->Packet
.RxData
->FragmentCount
,
452 Token
->Packet
.RxData
->FragmentTable
454 if (EFI_ERROR (Status
)) {
458 Sock
= SOCK_FROM_THIS (This
);
460 return SockRcv (Sock
, Token
);
466 Disconnecting a TCP connection gracefully or reset a TCP connection.
468 @param This Pointer to the EFI_TCP4_PROTOCOL instance
469 @param CloseToken Pointer to the close token to return when
472 @retval EFI_SUCCESS The operation completed successfully
473 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
475 @retval EFI_ACCESS_DENIED One or more of the following are TRUE: *
476 Configure() has been called with TcpConfigData
477 set to NULL and this function has not returned.
478 * Previous Close() call on this instance has not
480 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid
481 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
483 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
490 IN EFI_TCP4_PROTOCOL
*This
,
491 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
497 NULL
== CloseToken
||
498 NULL
== CloseToken
->CompletionToken
.Event
) {
499 return EFI_INVALID_PARAMETER
;
502 Sock
= SOCK_FROM_THIS (This
);
504 return SockClose (Sock
, CloseToken
, CloseToken
->AbortOnClose
);
509 Abort an asynchronous connection, listen, transmission or receive request.
511 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
512 @param Token Pointer to a token that has been issued by
513 Connect(), Accept(), Transmit() or Receive(). If
514 NULL, all pending tokens issued by above four
515 functions will be aborted.
517 @retval EFI_UNSUPPORTED The operation is not supported in current
524 IN EFI_TCP4_PROTOCOL
* This
,
525 IN EFI_TCP4_COMPLETION_TOKEN
* Token OPTIONAL
528 return EFI_UNSUPPORTED
;
533 Poll to receive incoming data and transmit outgoing segments.
535 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
537 @retval EFI_SUCCESS Incoming or outgoing data was processed.
538 @retval EFI_INVALID_PARAMETER This is NULL.
539 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
540 @retval EFI_NOT_READY No incoming or outgoing data was processed.
541 @retval EFI_TIMEOUT Data was dropped out of the transmission or
542 receive queue. Consider increasing the polling
549 IN EFI_TCP4_PROTOCOL
*This
556 return EFI_INVALID_PARAMETER
;
559 Sock
= SOCK_FROM_THIS (This
);
561 Status
= Sock
->ProtoHandler (Sock
, SOCK_POLL
, NULL
);