/** @file
Misc support routines for TCP driver.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "TcpMain.h"
};
};
L"TCP_CLOSED",
L"TCP_LISTEN",
L"TCP_SYN_SENT",
L"TCP_SYN_RCVD",
L"TCP_ESTABLISHED",
L"TCP_FIN_WAIT_1",
L"TCP_FIN_WAIT_2",
L"TCP_CLOSING",
L"TCP_TIME_WAIT",
L"TCP_CLOSE_WAIT",
L"TCP_LAST_ACK"
};
/**
Initialize the Tcb local related members.
@param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.
**/
)
{
//
// Compute the checksum of the fixed parts of pseudo header
//
0x06,
0
);
} else {
0x06,
0
);
}
//
// First window size is never scaled
//
Tcb->RcvWndScale = 0;
}
/**
Initialize the peer related members.
@param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.
@param[in] Seg Pointer to the segment that contains the peer's intial info.
@param[in] Opt Pointer to the options announced by the peer.
**/
)
{
} else {
}
}
} else {
//
// One end doesn't support MSS option, use default.
//
}
} else {
//
// One end doesn't support window scale option. use zero.
//
Tcb->RcvWndScale = 0;
}
//
// Compute the effective SndMss per RFC1122
// section 4.2.2.6. If timestamp option is
// enabled, it will always occupy 12 bytes.
//
}
}
/**
Check whether one IP address equals the other.
@param[in] Ip1 Pointer to IP address to be checked.
@param[in] Ip2 Pointer to IP address to be checked.
@param[in] Version IP_VERSION_4 indicates the IP address is an IPv4 address,
IP_VERSION_6 indicates the IP address is an IPv6 address.
@retval TRUE Ip1 equals Ip2.
@retval FALSE Ip1 does not equal Ip2.
**/
)
{
if (Version == IP_VERSION_4) {
} else {
}
}
/**
Check whether one IP address is filled with ZERO.
@param[in] Ip Pointer to the IP address to be checked.
@param[in] Version IP_VERSION_4 indicates the IP address is an IPv4 address,
IP_VERSION_6 indicates the IP address is an IPv6 address.
@retval TRUE Ip is all zero address.
@retval FALSE Ip is not all zero address.
**/
)
{
if (Version == IP_VERSION_4) {
} else {
}
}
/**
Locate a listen TCB that matchs the Local and Remote.
@param[in] Local Pointer to the local (IP, Port).
@param[in] Remote Pointer to the remote (IP, Port).
@param[in] Version IP_VERSION_4 indicates TCP is running on IP4 stack,
IP_VERSION_6 indicates TCP is running on IP6 stack.
@return Pointer to the TCP_CB with the least number of wildcards,
if NULL no match is found.
**/
TCP_CB *
)
{
Last = 4;
) {
continue;
}
//
// Compute the number of wildcard
//
Cur = 0;
Cur++;
}
Cur++;
}
Cur++;
}
if (Cur == 0) {
return Node;
}
}
}
return Match;
}
/**
Try to find one Tcb whose <Ip, Port> equals to <IN Addr, IN Port>.
@param[in] Addr Pointer to the IP address needs to match.
@param[in] Port The port number needs to match.
@param[in] Version IP_VERSION_4 indicates TCP is running on IP4 stack,
IP_VERSION_6 indicates TCP is running on IP6 stack.
@retval TRUE The Tcb which matches the <Addr Port> pair exists.
@retval FALSE Otherwise
**/
)
{
) {
return TRUE;
}
}
) {
return TRUE;
}
}
return FALSE;
}
/**
Locate the TCP_CB related to the socket pair.
@param[in] LocalPort The local port number.
@param[in] LocalIp The local IP address.
@param[in] RemotePort The remote port number.
@param[in] RemoteIp The remote IP address.
@param[in] Version IP_VERSION_4 indicates TCP is running on IP4 stack,
IP_VERSION_6 indicates TCP is running on IP6 stack.
@param[in] Syn If TRUE, the listen sockets are searched.
@return Pointer to the related TCP_CB. If NULL, no match is found.
**/
TCP_CB *
)
{
//
// First check for exact match.
//
) {
return Tcb;
}
}
//
// Only check the listen queue when the SYN flag is on.
//
if (Syn) {
}
return NULL;
}
/**
Insert a Tcb into the proper queue.
@param[in] Tcb Pointer to the TCP_CB to be inserted.
@retval 0 The Tcb was inserted successfully.
@retval -1 Error condition occurred.
**/
)
{
ASSERT (
(
)
);
return -1;
}
Head = &mTcpRunQue;
Head = &mTcpListenQue;
}
//
// Check that the Tcb isn't already on the list.
//
) {
return -1;
}
}
return 0;
}
/**
Clone a TCP_CB from Tcb.
@param[in] Tcb Pointer to the TCP_CB to be cloned.
@return Pointer to the new cloned TCP_CB; if NULL, error condition occurred.
**/
TCP_CB *
)
{
return NULL;
}
//
// Increase the reference count of the shared IpInfo.
//
return NULL;
}
return Clone;
}
/**
Compute an ISS to be used by a new connection.
@return The resulting ISS.
**/
)
{
return mTcpGlobalIss;
}
/**
Get the local mss.
@param[in] Sock Pointer to the socket to get mss.
@return The mss size.
**/
)
{
} else {
}
}
/**
Set the Tcb's state.
@param[in] Tcb Pointer to the TCP_CB of this TCP instance.
@param[in] State The state to be set.
**/
)
{
DEBUG (
"Tcb (%p) state %s --> %s\n",
Tcb,
);
switch (State) {
case TCP_ESTABLISHED:
//
// A new connection is accepted by a listening socket. Install
// the device path.
//
}
break;
case TCP_CLOSED:
break;
default:
break;
}
}
/**
Compute the TCP segment's checksum.
@param[in] Nbuf Pointer to the buffer that contains the TCP segment.
@param[in] HeadSum The checksum value of the fixed part of pseudo header.
@return The checksum value.
**/
)
{
);
}
/**
Translate the information from the head of the received TCP
segment Nbuf contents and fill it into a TCP_SEG structure.
@param[in] Tcb Pointer to the TCP_CB of this TCP instance.
@param[in, out] Nbuf Pointer to the buffer contains the TCP segment.
@return Pointer to the TCP_SEG that contains the translated TCP head information.
**/
TCP_SEG *
)
{
//
// SYN and FIN flag occupy one sequence space each.
//
//
// RFC requires that the initial window not be scaled.
//
}
}
return Seg;
}
/**
Initialize an active connection.
@param[in, out] Tcb Pointer to the TCP_CB that wants to initiate a
connection.
**/
)
{
}
/**
Initiate the connection close procedure, called when
applications want to close the connection.
@param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.
**/
)
{
DEBUG (
"TcpOnAppClose: connection reset because data is lost for TCB %p\n",
Tcb)
);
return;
}
case TCP_CLOSED:
case TCP_LISTEN:
case TCP_SYN_SENT:
break;
case TCP_SYN_RCVD:
case TCP_ESTABLISHED:
break;
case TCP_CLOSE_WAIT:
break;
default:
break;
}
}
/**
Check whether the application's newly delivered data can be sent out.
@param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.
@retval 0 The data has been sent out successfully.
@retval -1 The Tcb is not in a state that data is permitted to
be sent out.
**/
)
{
case TCP_CLOSED:
return -1;
case TCP_LISTEN:
return -1;
case TCP_SYN_SENT:
case TCP_SYN_RCVD:
return 0;
case TCP_ESTABLISHED:
case TCP_CLOSE_WAIT:
TcpToSendData (Tcb, 0);
return 0;
case TCP_FIN_WAIT_1:
case TCP_FIN_WAIT_2:
case TCP_CLOSING:
case TCP_LAST_ACK:
case TCP_TIME_WAIT:
return -1;
default:
break;
}
return 0;
}
/**
Application has consumed some data. Check whether
to send a window update ack or a delayed ack.
@param[in] Tcb Pointer to the TCP_CB of this TCP instance.
**/
)
{
case TCP_ESTABLISHED:
DEBUG (
"TcpOnAppConsume: send a window update for a window closed Tcb %p\n",
Tcb)
);
TcpSendAck (Tcb);
} else if (Tcb->DelayedAck == 0) {
DEBUG (
"TcpOnAppConsume: scheduled a delayed ACK to update window for Tcb %p\n",
Tcb)
);
}
}
break;
default:
break;
}
}
/**
Abort the connection by sending a reset segment. Called
when the application wants to abort the connection.
@param[in] Tcb Pointer to the TCP_CB of the TCP instance.
**/
)
{
DEBUG (
"TcpOnAppAbort: connection reset issued by application for TCB %p\n",
Tcb)
);
case TCP_SYN_RCVD:
case TCP_ESTABLISHED:
case TCP_FIN_WAIT_1:
case TCP_FIN_WAIT_2:
case TCP_CLOSE_WAIT:
break;
default:
break;
}
}
/**
Reset the connection related with Tcb.
@param[in] Tcb Pointer to the TCP_CB of the connection to be reset.
**/
)
{
return ;
}
Nbuf,
sizeof (TCP_HEAD),
);
NetbufFree (Nbuf);
}
/**
Set the Tcp variable data.
@param[in] TcpService Tcp service data.
@retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.
@retval other Set variable failed.
**/
)
{
} else {
}
//
// Go through the running queue to count the instances.
//
//
// This tcp instance belongs to the TcpService.
//
}
}
//
// Go through the listening queue to count the instances.
//
//
// This tcp instance belongs to the TcpService.
//
}
}
//
// Calculate the size of the Tcp4VariableData. As there may be no Tcp4 child,
// we should add extra buffers for the service points only if the number of configured
// children is more than one.
//
VariableDataSize = sizeof (EFI_TCP4_VARIABLE_DATA);
if (NumConfiguredInstance > 1) {
}
if (Tcp4VariableData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
VariableDataSize = sizeof (EFI_TCP6_VARIABLE_DATA);
if (NumConfiguredInstance > 1) {
}
if (Tcp6VariableData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Go through the running queue to fill the service points.
//
//
// This tcp instance belongs to the TcpService.
//
} else {
}
}
}
//
// Go through the listening queue to fill the service points.
//
//
// This tcp instance belongs to the TcpService.
//
} else {
}
}
}
//
// Get the mac string.
//
);
goto ON_ERROR;
}
//
// The variable is set already. We're going to update it.
//
//
// The mac address is changed. Delete the previous variable first.
//
gRT->SetVariable (
0,
);
}
}
);
return Status;
}
/**
Clear the variable and free the resource.
@param[in] TcpService Tcp service data.
**/
)
{
} else {
}
gRT->SetVariable (
0,
);
}
/**
Install the device path protocol on the TCP instance.
@param[in] Sock Pointer to the socket representing the TCP instance.
@retval EFI_SUCCESS The device path protocol was installed.
@retval other Failed to install the device path protocol.
**/
)
{
);
} else {
);
}
return EFI_OUT_OF_RESOURCES;
}
&Sock->SockHandle,
);
}
return Status;
}