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 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
65 @param Tcp4State Pointer to the buffer to receive the current TCP
67 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP
69 @param Ip4ModeData Pointer to the buffer to receive the current
71 @param MnpConfigData Pointer to the buffer to receive the current MNP
72 configuration data indirectly used by the TCPv4
74 @param SnpModeData Pointer to the buffer to receive the current SNP
75 configuration data indirectly used by the TCPv4
78 @retval EFI_SUCCESS The mode data was read.
79 @retval EFI_NOT_STARTED No configuration data is available because this
80 instance hasn't been started.
81 @retval EFI_INVALID_PARAMETER This is NULL.
87 IN CONST EFI_TCP4_PROTOCOL
* This
,
88 OUT EFI_TCP4_CONNECTION_STATE
* Tcp4State OPTIONAL
,
89 OUT EFI_TCP4_CONFIG_DATA
* Tcp4ConfigData OPTIONAL
,
90 OUT EFI_IP4_MODE_DATA
* Ip4ModeData OPTIONAL
,
91 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
* MnpConfigData OPTIONAL
,
92 OUT EFI_SIMPLE_NETWORK_MODE
* SnpModeData OPTIONAL
95 TCP4_MODE_DATA TcpMode
;
99 return EFI_INVALID_PARAMETER
;
102 Sock
= SOCK_FROM_THIS (This
);
104 TcpMode
.Tcp4State
= Tcp4State
;
105 TcpMode
.Tcp4ConfigData
= Tcp4ConfigData
;
106 TcpMode
.Ip4ModeData
= Ip4ModeData
;
107 TcpMode
.MnpConfigData
= MnpConfigData
;
108 TcpMode
.SnpModeData
= SnpModeData
;
110 return SockGetMode (Sock
, &TcpMode
);
115 Initialize or brutally reset the operational parameters for
116 this EFI TCPv4 instance.
118 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
119 @param TcpConfigData Pointer to the configure data to configure the
122 @retval EFI_SUCCESS The operational settings are set, changed, or
124 @retval EFI_NO_MAPPING When using a default address, configuration
125 (through DHCP, BOOTP, RARP, etc.) is not
127 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
128 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already
130 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
131 @retval EFI_UNSUPPORTED One or more of the control options are not
132 supported in the implementation.
133 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
139 IN EFI_TCP4_PROTOCOL
* This
,
140 IN EFI_TCP4_CONFIG_DATA
* TcpConfigData OPTIONAL
143 EFI_TCP4_OPTION
*Option
;
150 return EFI_INVALID_PARAMETER
;
154 // Tcp protocol related parameter check will be conducted here
156 if (NULL
!= TcpConfigData
) {
158 CopyMem (&Ip
, &TcpConfigData
->AccessPoint
.RemoteAddress
, sizeof (IP4_ADDR
));
159 if ((Ip
!= 0) && !Ip4IsUnicast (NTOHL (Ip
), 0)) {
160 return EFI_INVALID_PARAMETER
;
163 if (TcpConfigData
->AccessPoint
.ActiveFlag
&&
164 (0 == TcpConfigData
->AccessPoint
.RemotePort
|| (Ip
== 0))) {
165 return EFI_INVALID_PARAMETER
;
168 if (!TcpConfigData
->AccessPoint
.UseDefaultAddress
) {
170 CopyMem (&Ip
, &TcpConfigData
->AccessPoint
.StationAddress
, sizeof (IP4_ADDR
));
171 CopyMem (&SubnetMask
, &TcpConfigData
->AccessPoint
.SubnetMask
, sizeof (IP4_ADDR
));
172 if (!Ip4IsUnicast (NTOHL (Ip
), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask
))) {
173 return EFI_INVALID_PARAMETER
;
177 Option
= TcpConfigData
->ControlOption
;
178 if ((NULL
!= Option
) &&
179 (Option
->EnableSelectiveAck
|| Option
->EnablePathMtuDiscovery
)) {
180 return EFI_UNSUPPORTED
;
184 Sock
= SOCK_FROM_THIS (This
);
186 if (NULL
== TcpConfigData
) {
187 return SockFlush (Sock
);
190 Status
= SockConfigure (Sock
, TcpConfigData
);
192 if (EFI_NO_MAPPING
== Status
) {
193 Sock
->ConfigureState
= SO_NO_MAPPING
;
201 Add or delete routing entries.
203 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
204 @param DeleteRoute If TRUE, delete the specified route from routing
205 table; if FALSE, add the specified route to
207 @param SubnetAddress The destination network.
208 @param SubnetMask The subnet mask for the destination network.
209 @param GatewayAddress The gateway address for this route.
211 @retval EFI_SUCCESS The operation completed successfully.
212 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
214 @retval EFI_NO_MAPPING When using a default address, configuration
215 (through DHCP, BOOTP, RARP, etc.) is not
217 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
218 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
219 entry to the routing table.
220 @retval EFI_NOT_FOUND This route is not in the routing table.
221 @retval EFI_ACCESS_DENIED This route is already in the routing table.
222 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
228 IN EFI_TCP4_PROTOCOL
*This
,
229 IN BOOLEAN DeleteRoute
,
230 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
231 IN EFI_IPv4_ADDRESS
*SubnetMask
,
232 IN EFI_IPv4_ADDRESS
*GatewayAddress
236 TCP4_ROUTE_INFO RouteInfo
;
239 return EFI_INVALID_PARAMETER
;
242 Sock
= SOCK_FROM_THIS (This
);
244 RouteInfo
.DeleteRoute
= DeleteRoute
;
245 RouteInfo
.SubnetAddress
= SubnetAddress
;
246 RouteInfo
.SubnetMask
= SubnetMask
;
247 RouteInfo
.GatewayAddress
= GatewayAddress
;
249 return SockRoute (Sock
, &RouteInfo
);
254 Initiate a nonblocking TCP connection request for an active TCP instance.
256 @param This Pointer to the EFI_TCP4_PROTOCOL instance
257 @param ConnectionToken Pointer to the connection token to return when
258 the TCP three way handshake finishes.
260 @retval EFI_SUCCESS The connection request is successfully
262 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
264 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
265 or it is not in Tcp4StateClosed state.
266 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
267 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
268 initiate the active open.
269 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
275 IN EFI_TCP4_PROTOCOL
*This
,
276 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
282 NULL
== ConnectionToken
||
283 NULL
== ConnectionToken
->CompletionToken
.Event
) {
284 return EFI_INVALID_PARAMETER
;
287 Sock
= SOCK_FROM_THIS (This
);
289 return SockConnect (Sock
, ConnectionToken
);
294 Listen on the passive instance to accept an incoming connection request.
296 @param This Pointer to the EFI_TCP4_PROTOCOL instance
297 @param ListenToken Pointer to the listen token to return when
300 @retval EFI_SUCCESS The listen token has been queued successfully.
301 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
303 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
304 in Tcp4StateListen state or a same listen token
305 has already existed in the listen token queue of
307 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
308 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
310 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
316 IN EFI_TCP4_PROTOCOL
*This
,
317 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
323 NULL
== ListenToken
||
324 NULL
== ListenToken
->CompletionToken
.Event
) {
325 return EFI_INVALID_PARAMETER
;
328 Sock
= SOCK_FROM_THIS (This
);
330 return SockAccept (Sock
, ListenToken
);
335 Queues outgoing data into the transmit queue
337 @param This Pointer to the EFI_TCP4_PROTOCOL instance
338 @param Token Pointer to the completion token to queue to the
341 @retval EFI_SUCCESS The data has been queued for transmission
342 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
344 @retval EFI_NO_MAPPING When using a default address, configuration
345 (DHCP, BOOTP, RARP, etc.) is not finished yet.
346 @retval EFI_INVALID_PARAMETER One or more parameters are invalid
347 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
348 * A transmit completion token with the same
349 Token-> CompletionToken.Event was already in the
350 transmission queue. * The current instance is in
351 Tcp4StateClosed state * The current instance is
352 a passive one and it is in Tcp4StateListen
353 state. * User has called Close() to disconnect
355 @retval EFI_NOT_READY The completion token could not be queued because
356 the transmit queue is full.
357 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
359 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
366 IN EFI_TCP4_PROTOCOL
*This
,
367 IN EFI_TCP4_IO_TOKEN
*Token
375 NULL
== Token
->CompletionToken
.Event
||
376 NULL
== Token
->Packet
.TxData
||
377 0 == Token
->Packet
.TxData
->FragmentCount
||
378 0 == Token
->Packet
.TxData
->DataLength
380 return EFI_INVALID_PARAMETER
;
383 Status
= Tcp4ChkDataBuf (
384 (UINT32
) Token
->Packet
.TxData
->DataLength
,
385 (UINT32
) Token
->Packet
.TxData
->FragmentCount
,
386 Token
->Packet
.TxData
->FragmentTable
388 if (EFI_ERROR (Status
)) {
392 Sock
= SOCK_FROM_THIS (This
);
394 return SockSend (Sock
, Token
);
400 Place an asynchronous receive request into the receiving queue.
402 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
403 @param Token Pointer to a token that is associated with the
404 receive data descriptor.
406 @retval EFI_SUCCESS The receive completion token was cached
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_OUT_OF_RESOURCES The receive completion token could not be queued
413 due to a lack of system resources.
414 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
415 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
416 * A receive completion token with the same
417 Token->CompletionToken.Event was already in the
418 receive queue. * The current instance is in
419 Tcp4StateClosed state. * The current instance is
420 a passive one and it is in Tcp4StateListen
421 state. * User has called Close() to disconnect
423 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
424 and there is no any buffered data in the receive
425 buffer of this instance.
426 @retval EFI_NOT_READY The receive request could not be queued because
427 the receive queue is full.
433 IN EFI_TCP4_PROTOCOL
*This
,
434 IN EFI_TCP4_IO_TOKEN
*Token
442 NULL
== Token
->CompletionToken
.Event
||
443 NULL
== Token
->Packet
.RxData
||
444 0 == Token
->Packet
.RxData
->FragmentCount
||
445 0 == Token
->Packet
.RxData
->DataLength
447 return EFI_INVALID_PARAMETER
;
450 Status
= Tcp4ChkDataBuf (
451 (UINT32
) Token
->Packet
.RxData
->DataLength
,
452 (UINT32
) Token
->Packet
.RxData
->FragmentCount
,
453 Token
->Packet
.RxData
->FragmentTable
455 if (EFI_ERROR (Status
)) {
459 Sock
= SOCK_FROM_THIS (This
);
461 return SockRcv (Sock
, Token
);
467 Disconnecting a TCP connection gracefully or reset a TCP connection.
469 @param This Pointer to the EFI_TCP4_PROTOCOL instance
470 @param CloseToken Pointer to the close token to return when
473 @retval EFI_SUCCESS The operation completed successfully
474 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
476 @retval EFI_ACCESS_DENIED One or more of the following are TRUE: *
477 Configure() has been called with TcpConfigData
478 set to NULL and this function has not returned.
479 * Previous Close() call on this instance has not
481 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid
482 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
484 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
491 IN EFI_TCP4_PROTOCOL
*This
,
492 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
498 NULL
== CloseToken
||
499 NULL
== CloseToken
->CompletionToken
.Event
) {
500 return EFI_INVALID_PARAMETER
;
503 Sock
= SOCK_FROM_THIS (This
);
505 return SockClose (Sock
, CloseToken
, CloseToken
->AbortOnClose
);
510 Abort an asynchronous connection, listen, transmission or receive request.
512 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
513 @param Token Pointer to a token that has been issued by
514 Connect(), Accept(), Transmit() or Receive(). If
515 NULL, all pending tokens issued by above four
516 functions will be aborted.
518 @retval EFI_UNSUPPORTED The operation is not supported in current
525 IN EFI_TCP4_PROTOCOL
* This
,
526 IN EFI_TCP4_COMPLETION_TOKEN
* Token OPTIONAL
529 return EFI_UNSUPPORTED
;
534 Poll to receive incoming data and transmit outgoing segments.
536 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
538 @retval EFI_SUCCESS Incoming or outgoing data was processed.
539 @retval EFI_INVALID_PARAMETER This is NULL.
540 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
541 @retval EFI_NOT_READY No incoming or outgoing data was processed.
542 @retval EFI_TIMEOUT Data was dropped out of the transmission or
543 receive queue. Consider increasing the polling
550 IN EFI_TCP4_PROTOCOL
*This
557 return EFI_INVALID_PARAMETER
;
560 Sock
= SOCK_FROM_THIS (This
);
562 Status
= Sock
->ProtoHandler (Sock
, SOCK_POLL
, NULL
);