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
;
151 return EFI_INVALID_PARAMETER
;
155 // Tcp protocol related parameter check will be conducted here
157 if (NULL
!= TcpConfigData
) {
159 CopyMem (&Ip
, &TcpConfigData
->AccessPoint
.RemoteAddress
, sizeof (IP4_ADDR
));
160 if ((Ip
!= 0) && !Ip4IsUnicast (NTOHL (Ip
), 0)) {
161 return EFI_INVALID_PARAMETER
;
164 if (TcpConfigData
->AccessPoint
.ActiveFlag
&&
165 (0 == TcpConfigData
->AccessPoint
.RemotePort
|| (Ip
== 0))) {
166 return EFI_INVALID_PARAMETER
;
169 if (!TcpConfigData
->AccessPoint
.UseDefaultAddress
) {
171 CopyMem (&Ip
, &TcpConfigData
->AccessPoint
.StationAddress
, sizeof (IP4_ADDR
));
172 CopyMem (&SubnetMask
, &TcpConfigData
->AccessPoint
.SubnetMask
, sizeof (IP4_ADDR
));
173 if (!Ip4IsUnicast (NTOHL (Ip
), 0) || !IP4_IS_VALID_NETMASK (NTOHL (SubnetMask
))) {
174 return EFI_INVALID_PARAMETER
;
178 Option
= TcpConfigData
->ControlOption
;
179 if ((NULL
!= Option
) &&
180 (Option
->EnableSelectiveAck
|| Option
->EnablePathMtuDiscovery
)) {
181 return EFI_UNSUPPORTED
;
185 Sock
= SOCK_FROM_THIS (This
);
187 if (NULL
== TcpConfigData
) {
188 return SockFlush (Sock
);
191 Status
= SockConfigure (Sock
, TcpConfigData
);
193 if (EFI_NO_MAPPING
== Status
) {
194 Sock
->ConfigureState
= SO_NO_MAPPING
;
202 Add or delete routing entries.
204 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
205 @param DeleteRoute If TRUE, delete the specified route from routing
206 table; if FALSE, add the specified route to
208 @param SubnetAddress The destination network.
209 @param SubnetMask The subnet mask for the destination network.
210 @param GatewayAddress The gateway address for this route.
212 @retval EFI_SUCCESS The operation completed successfully.
213 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been
215 @retval EFI_NO_MAPPING When using a default address, configuration
216 (through DHCP, BOOTP, RARP, etc.) is not
218 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
219 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the
220 entry to the routing table.
221 @retval EFI_NOT_FOUND This route is not in the routing table.
222 @retval EFI_ACCESS_DENIED This route is already in the routing table.
223 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.
229 IN EFI_TCP4_PROTOCOL
*This
,
230 IN BOOLEAN DeleteRoute
,
231 IN EFI_IPv4_ADDRESS
*SubnetAddress
,
232 IN EFI_IPv4_ADDRESS
*SubnetMask
,
233 IN EFI_IPv4_ADDRESS
*GatewayAddress
237 TCP4_ROUTE_INFO RouteInfo
;
240 return EFI_INVALID_PARAMETER
;
243 Sock
= SOCK_FROM_THIS (This
);
245 RouteInfo
.DeleteRoute
= DeleteRoute
;
246 RouteInfo
.SubnetAddress
= SubnetAddress
;
247 RouteInfo
.SubnetMask
= SubnetMask
;
248 RouteInfo
.GatewayAddress
= GatewayAddress
;
250 return SockRoute (Sock
, &RouteInfo
);
255 Initiate a nonblocking TCP connection request for an active TCP instance.
257 @param This Pointer to the EFI_TCP4_PROTOCOL instance
258 @param ConnectionToken Pointer to the connection token to return when
259 the TCP three way handshake finishes.
261 @retval EFI_SUCCESS The connection request is successfully
263 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been
265 @retval EFI_ACCESS_DENIED The instance is not configured as an active one
266 or it is not in Tcp4StateClosed state.
267 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
268 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to
269 initiate the active open.
270 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
276 IN EFI_TCP4_PROTOCOL
*This
,
277 IN EFI_TCP4_CONNECTION_TOKEN
*ConnectionToken
283 NULL
== ConnectionToken
||
284 NULL
== ConnectionToken
->CompletionToken
.Event
) {
285 return EFI_INVALID_PARAMETER
;
288 Sock
= SOCK_FROM_THIS (This
);
290 return SockConnect (Sock
, ConnectionToken
);
295 Listen on the passive instance to accept an incoming connection request.
297 @param This Pointer to the EFI_TCP4_PROTOCOL instance
298 @param ListenToken Pointer to the listen token to return when
301 @retval EFI_SUCCESS The listen token has been queued successfully.
302 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
304 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not
305 in Tcp4StateListen state or a same listen token
306 has already existed in the listen token queue of
308 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
309 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish
311 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
317 IN EFI_TCP4_PROTOCOL
*This
,
318 IN EFI_TCP4_LISTEN_TOKEN
*ListenToken
324 NULL
== ListenToken
||
325 NULL
== ListenToken
->CompletionToken
.Event
) {
326 return EFI_INVALID_PARAMETER
;
329 Sock
= SOCK_FROM_THIS (This
);
331 return SockAccept (Sock
, ListenToken
);
336 Queues outgoing data into the transmit queue
338 @param This Pointer to the EFI_TCP4_PROTOCOL instance
339 @param Token Pointer to the completion token to queue to the
342 @retval EFI_SUCCESS The data has been queued for transmission
343 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
345 @retval EFI_NO_MAPPING When using a default address, configuration
346 (DHCP, BOOTP, RARP, etc.) is not finished yet.
347 @retval EFI_INVALID_PARAMETER One or more parameters are invalid
348 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
349 * A transmit completion token with the same
350 Token-> CompletionToken.Event was already in the
351 transmission queue. * The current instance is in
352 Tcp4StateClosed state * The current instance is
353 a passive one and it is in Tcp4StateListen
354 state. * User has called Close() to disconnect
356 @retval EFI_NOT_READY The completion token could not be queued because
357 the transmit queue is full.
358 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of
360 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or
367 IN EFI_TCP4_PROTOCOL
*This
,
368 IN EFI_TCP4_IO_TOKEN
*Token
376 NULL
== Token
->CompletionToken
.Event
||
377 NULL
== Token
->Packet
.TxData
||
378 0 == Token
->Packet
.TxData
->FragmentCount
||
379 0 == Token
->Packet
.TxData
->DataLength
381 return EFI_INVALID_PARAMETER
;
384 Status
= Tcp4ChkDataBuf (
385 (UINT32
) Token
->Packet
.TxData
->DataLength
,
386 (UINT32
) Token
->Packet
.TxData
->FragmentCount
,
387 Token
->Packet
.TxData
->FragmentTable
389 if (EFI_ERROR (Status
)) {
393 Sock
= SOCK_FROM_THIS (This
);
395 return SockSend (Sock
, Token
);
401 Place an asynchronous receive request into the receiving queue.
403 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
404 @param Token Pointer to a token that is associated with the
405 receive data descriptor.
407 @retval EFI_SUCCESS The receive completion token was cached
408 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
410 @retval EFI_NO_MAPPING When using a default address, configuration
411 (DHCP, BOOTP, RARP, etc.) is not finished yet.
412 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
413 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued
414 due to a lack of system resources.
415 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
416 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:
417 * A receive completion token with the same
418 Token->CompletionToken.Event was already in the
419 receive queue. * The current instance is in
420 Tcp4StateClosed state. * The current instance is
421 a passive one and it is in Tcp4StateListen
422 state. * User has called Close() to disconnect
424 @retval EFI_CONNECTION_FIN The communication peer has closed the connection
425 and there is no any buffered data in the receive
426 buffer of this instance.
427 @retval EFI_NOT_READY The receive request could not be queued because
428 the receive queue is full.
434 IN EFI_TCP4_PROTOCOL
*This
,
435 IN EFI_TCP4_IO_TOKEN
*Token
443 NULL
== Token
->CompletionToken
.Event
||
444 NULL
== Token
->Packet
.RxData
||
445 0 == Token
->Packet
.RxData
->FragmentCount
||
446 0 == Token
->Packet
.RxData
->DataLength
448 return EFI_INVALID_PARAMETER
;
451 Status
= Tcp4ChkDataBuf (
452 (UINT32
) Token
->Packet
.RxData
->DataLength
,
453 (UINT32
) Token
->Packet
.RxData
->FragmentCount
,
454 Token
->Packet
.RxData
->FragmentTable
456 if (EFI_ERROR (Status
)) {
460 Sock
= SOCK_FROM_THIS (This
);
462 return SockRcv (Sock
, Token
);
468 Disconnecting a TCP connection gracefully or reset a TCP connection.
470 @param This Pointer to the EFI_TCP4_PROTOCOL instance
471 @param CloseToken Pointer to the close token to return when
474 @retval EFI_SUCCESS The operation completed successfully
475 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been
477 @retval EFI_ACCESS_DENIED One or more of the following are TRUE: *
478 Configure() has been called with TcpConfigData
479 set to NULL and this function has not returned.
480 * Previous Close() call on this instance has not
482 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid
483 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the
485 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above
492 IN EFI_TCP4_PROTOCOL
*This
,
493 IN EFI_TCP4_CLOSE_TOKEN
*CloseToken
499 NULL
== CloseToken
||
500 NULL
== CloseToken
->CompletionToken
.Event
) {
501 return EFI_INVALID_PARAMETER
;
504 Sock
= SOCK_FROM_THIS (This
);
506 return SockClose (Sock
, CloseToken
, CloseToken
->AbortOnClose
);
511 Abort an asynchronous connection, listen, transmission or receive request.
513 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
514 @param Token Pointer to a token that has been issued by
515 Connect(), Accept(), Transmit() or Receive(). If
516 NULL, all pending tokens issued by above four
517 functions will be aborted.
519 @retval EFI_UNSUPPORTED The operation is not supported in current
526 IN EFI_TCP4_PROTOCOL
* This
,
527 IN EFI_TCP4_COMPLETION_TOKEN
* Token OPTIONAL
530 return EFI_UNSUPPORTED
;
535 Poll to receive incoming data and transmit outgoing segments.
537 @param This Pointer to the EFI_TCP4_PROTOCOL instance.
539 @retval EFI_SUCCESS Incoming or outgoing data was processed.
540 @retval EFI_INVALID_PARAMETER This is NULL.
541 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
542 @retval EFI_NOT_READY No incoming or outgoing data was processed.
543 @retval EFI_TIMEOUT Data was dropped out of the transmission or
544 receive queue. Consider increasing the polling
551 IN EFI_TCP4_PROTOCOL
*This
558 return EFI_INVALID_PARAMETER
;
561 Sock
= SOCK_FROM_THIS (This
);
563 Status
= Sock
->ProtoHandler (Sock
, SOCK_POLL
, NULL
);