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
+ (UINT32
) 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
;
152 return EFI_INVALID_PARAMETER
;
156 // Tcp protocol related parameter check will be conducted here
158 if (NULL
!= TcpConfigData
) {
160 NetCopyMem (&Ip
, &TcpConfigData
->AccessPoint
.RemoteAddress
, sizeof (IP4_ADDR
));
161 if ((Ip
!= 0) && !Ip4IsUnicast (NTOHL (Ip
), 0)) {
162 return EFI_INVALID_PARAMETER
;
165 if (TcpConfigData
->AccessPoint
.ActiveFlag
&&
166 (0 == TcpConfigData
->AccessPoint
.RemotePort
|| (Ip
== 0))) {
167 return EFI_INVALID_PARAMETER
;
170 if (!TcpConfigData
->AccessPoint
.UseDefaultAddress
) {
172 NetCopyMem (&Ip
, &TcpConfigData
->AccessPoint
.StationAddress
, sizeof (IP4_ADDR
));
173 NetCopyMem (&SubnetMask
, &TcpConfigData
->AccessPoint
.SubnetMask
, sizeof (IP4_ADDR
));
174 if (!Ip4IsUnicast (NTOHL (Ip
), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask
))) {
175 return EFI_INVALID_PARAMETER
;
179 Option
= TcpConfigData
->ControlOption
;
180 if ((NULL
!= Option
) &&
181 (Option
->EnableSelectiveAck
|| Option
->EnablePathMtuDiscovery
)) {
182 return EFI_UNSUPPORTED
;
186 Sock
= SOCK_FROM_THIS (This
);
188 if (NULL
== TcpConfigData
) {
189 return SockFlush (Sock
);
192 Status
= SockConfigure (Sock
, TcpConfigData
);
194 if (EFI_NO_MAPPING
== Status
) {
195 Sock
->ConfigureState
= SO_NO_MAPPING
;
203 Add or delete routing entries.
205 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
206 @param DeleteRoute If TRUE, delete the specified route from routing
207 table; if FALSE, add the specified route to
209 @param SubnetAddress The destination network.
210 @param SubnetMask The subnet mask for the destination network.
211 @param GatewayAddress The gateway address for this route.
213 @retval EFI_SUCCESS The operation completed successfully.
214 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
216 @retval EFI_NO_MAPPING When using a default address, configuration
217 (through DHCP, BOOTP, RARP, etc.) is not
219 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
220 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
221 entry to the routing table.
222 @retval EFI_NOT_FOUND This route is not in the routing table.
223 @retval EFI_ACCESS_DENIED This route is already in the routing table.
224 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
230 IN EFI_TCP4_PROTOCOL
*This
,
231 IN BOOLEAN DeleteRoute
,
232 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
233 IN EFI_IPv4_ADDRESS
*SubnetMask
,
234 IN EFI_IPv4_ADDRESS
*GatewayAddress
238 TCP4_ROUTE_INFO RouteInfo
;
241 return EFI_INVALID_PARAMETER
;
244 Sock
= SOCK_FROM_THIS (This
);
246 RouteInfo
.DeleteRoute
= DeleteRoute
;
247 RouteInfo
.SubnetAddress
= SubnetAddress
;
248 RouteInfo
.SubnetMask
= SubnetMask
;
249 RouteInfo
.GatewayAddress
= GatewayAddress
;
251 return SockRoute (Sock
, &RouteInfo
);
256 Initiate a nonblocking TCP connection request for an active TCP instance.
258 @param This Pointer to the EFI_TCP4_PROTOCOL instance
259 @param ConnectionToken Pointer to the connection token to return when
260 the TCP three way handshake finishes.
262 @retval EFI_SUCCESS The connection request is successfully
264 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
266 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
267 or it is not in Tcp4StateClosed state.
268 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
269 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
270 initiate the active open.
271 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
277 IN EFI_TCP4_PROTOCOL
*This
,
278 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
284 NULL
== ConnectionToken
||
285 NULL
== ConnectionToken
->CompletionToken
.Event
) {
286 return EFI_INVALID_PARAMETER
;
289 Sock
= SOCK_FROM_THIS (This
);
291 return SockConnect (Sock
, ConnectionToken
);
296 Listen on the passive instance to accept an incoming connection request.
298 @param This Pointer to the EFI_TCP4_PROTOCOL instance
299 @param ListenToken Pointer to the listen token to return when
302 @retval EFI_SUCCESS The listen token has been queued successfully.
303 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
305 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
306 in Tcp4StateListen state or a same listen token
307 has already existed in the listen token queue of
309 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
310 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
312 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
318 IN EFI_TCP4_PROTOCOL
*This
,
319 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
325 NULL
== ListenToken
||
326 NULL
== ListenToken
->CompletionToken
.Event
) {
327 return EFI_INVALID_PARAMETER
;
330 Sock
= SOCK_FROM_THIS (This
);
332 return SockAccept (Sock
, ListenToken
);
337 Queues outgoing data into the transmit queue
339 @param This Pointer to the EFI_TCP4_PROTOCOL instance
340 @param Token Pointer to the completion token to queue to the
343 @retval EFI_SUCCESS The data has been queued for transmission
344 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
346 @retval EFI_NO_MAPPING When using a default address, configuration
347 (DHCP, BOOTP, RARP, etc.) is not finished yet.
348 @retval EFI_INVALID_PARAMETER One or more parameters are invalid
349 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
350 * A transmit completion token with the same
351 Token-> CompletionToken.Event was already in the
352 transmission queue. * The current instance is in
353 Tcp4StateClosed state * The current instance is
354 a passive one and it is in Tcp4StateListen
355 state. * User has called Close() to disconnect
357 @retval EFI_NOT_READY The completion token could not be queued because
358 the transmit queue is full.
359 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
361 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
368 IN EFI_TCP4_PROTOCOL
*This
,
369 IN EFI_TCP4_IO_TOKEN
*Token
377 NULL
== Token
->CompletionToken
.Event
||
378 NULL
== Token
->Packet
.TxData
||
379 0 == Token
->Packet
.TxData
->FragmentCount
||
380 0 == Token
->Packet
.TxData
->DataLength
382 return EFI_INVALID_PARAMETER
;
385 Status
= Tcp4ChkDataBuf (
386 (UINT32
) Token
->Packet
.TxData
->DataLength
,
387 (UINT32
) Token
->Packet
.TxData
->FragmentCount
,
388 Token
->Packet
.TxData
->FragmentTable
390 if (EFI_ERROR (Status
)) {
394 Sock
= SOCK_FROM_THIS (This
);
396 return SockSend (Sock
, Token
);
402 Place an asynchronous receive request into the receiving queue.
404 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
405 @param Token Pointer to a token that is associated with the
406 receive data descriptor.
408 @retval EFI_SUCCESS The receive completion token was cached
409 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
411 @retval EFI_NO_MAPPING When using a default address, configuration
412 (DHCP, BOOTP, RARP, etc.) is not finished yet.
413 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
414 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
415 due to a lack of system resources.
416 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
417 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
418 * A receive completion token with the same
419 Token->CompletionToken.Event was already in the
420 receive queue. * The current instance is in
421 Tcp4StateClosed state. * The current instance is
422 a passive one and it is in Tcp4StateListen
423 state. * User has called Close() to disconnect
425 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
426 and there is no any buffered data in the receive
427 buffer of this instance.
428 @retval EFI_NOT_READY The receive request could not be queued because
429 the receive queue is full.
435 IN EFI_TCP4_PROTOCOL
*This
,
436 IN EFI_TCP4_IO_TOKEN
*Token
444 NULL
== Token
->CompletionToken
.Event
||
445 NULL
== Token
->Packet
.RxData
||
446 0 == Token
->Packet
.RxData
->FragmentCount
||
447 0 == Token
->Packet
.RxData
->DataLength
449 return EFI_INVALID_PARAMETER
;
452 Status
= Tcp4ChkDataBuf (
453 (UINT32
) Token
->Packet
.RxData
->DataLength
,
454 (UINT32
) Token
->Packet
.RxData
->FragmentCount
,
455 Token
->Packet
.RxData
->FragmentTable
457 if (EFI_ERROR (Status
)) {
461 Sock
= SOCK_FROM_THIS (This
);
463 return SockRcv (Sock
, Token
);
469 Disconnecting a TCP connection gracefully or reset a TCP connection.
471 @param This Pointer to the EFI_TCP4_PROTOCOL instance
472 @param CloseToken Pointer to the close token to return when
475 @retval EFI_SUCCESS The operation completed successfully
476 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
478 @retval EFI_ACCESS_DENIED One or more of the following are TRUE: *
479 Configure() has been called with TcpConfigData
480 set to NULL and this function has not returned.
481 * Previous Close() call on this instance has not
483 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid
484 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
486 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
493 IN EFI_TCP4_PROTOCOL
*This
,
494 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
500 NULL
== CloseToken
||
501 NULL
== CloseToken
->CompletionToken
.Event
) {
502 return EFI_INVALID_PARAMETER
;
505 Sock
= SOCK_FROM_THIS (This
);
507 return SockClose (Sock
, CloseToken
, CloseToken
->AbortOnClose
);
512 Abort an asynchronous connection, listen, transmission or receive request.
514 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
515 @param Token Pointer to a token that has been issued by
516 Connect(), Accept(), Transmit() or Receive(). If
517 NULL, all pending tokens issued by above four
518 functions will be aborted.
520 @retval EFI_UNSUPPORTED The operation is not supported in current
527 IN EFI_TCP4_PROTOCOL
* This
,
528 IN EFI_TCP4_COMPLETION_TOKEN
* Token OPTIONAL
531 return EFI_UNSUPPORTED
;
536 Poll to receive incoming data and transmit outgoing segments.
538 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
540 @retval EFI_SUCCESS Incoming or outgoing data was processed.
541 @retval EFI_INVALID_PARAMETER This is NULL.
542 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
543 @retval EFI_NOT_READY No incoming or outgoing data was processed.
544 @retval EFI_TIMEOUT Data was dropped out of the transmission or
545 receive queue. Consider increasing the polling
552 IN EFI_TCP4_PROTOCOL
*This
559 return EFI_INVALID_PARAMETER
;
562 Sock
= SOCK_FROM_THIS (This
);
564 Status
= Sock
->ProtoHandler (Sock
, SOCK_POLL
, NULL
);