2007-07-24 10:06:37 +02:00
|
|
|
/** @file
|
|
|
|
|
2008-12-16 03:57:53 +01:00
|
|
|
Copyright (c) 2005 - 2006, Intel Corporation<BR>
|
2007-07-24 10:06:37 +02:00
|
|
|
All rights reserved. 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
|
2008-12-16 03:57:53 +01:00
|
|
|
http://opensource.org/licenses/bsd-license.php<BR>
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
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 "Tcp4Main.h"
|
|
|
|
|
|
|
|
#define TCP_COMP_VAL(Min, Max, Default, Val) \
|
|
|
|
((((Val) <= (Max)) && ((Val) >= (Min))) ? (Val) : (Default))
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
|
|
|
Add or remove a route entry in the IP route table associated with this TCP instance.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
@param RouteInfo Pointer to the route info to be processed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation completed successfully.
|
|
|
|
@retval EFI_NOT_STARTED The driver instance has not been started.
|
|
|
|
@retval EFI_NO_MAPPING When using the default address, configuration(DHCP,
|
|
|
|
BOOTP, RARP, etc.) is not finished yet.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
|
|
|
|
@retval EFI_NOT_FOUND This route is not in the routing table
|
|
|
|
(when RouteInfo->DeleteRoute is TRUE).
|
|
|
|
@retval EFI_ACCESS_DENIED The route is already defined in the routing table
|
|
|
|
(when RouteInfo->DeleteRoute is FALSE).
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Tcp4Route (
|
|
|
|
IN TCP_CB *Tcb,
|
|
|
|
IN TCP4_ROUTE_INFO *RouteInfo
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_IP4_PROTOCOL *Ip;
|
|
|
|
|
|
|
|
Ip = Tcb->IpInfo->Ip;
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT (Ip != NULL);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return Ip->Routes (
|
|
|
|
Ip,
|
|
|
|
RouteInfo->DeleteRoute,
|
|
|
|
RouteInfo->SubnetAddress,
|
|
|
|
RouteInfo->SubnetMask,
|
|
|
|
RouteInfo->GatewayAddress
|
|
|
|
);
|
2008-12-06 00:47:55 +01:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the operational settings of this TCP instance.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
@param Mode Pointer to the buffer to store the operational
|
|
|
|
settings.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The mode data is read.
|
|
|
|
@retval EFI_NOT_STARTED No configuration data is available because this
|
|
|
|
instance hasn't been started.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4GetMode (
|
|
|
|
IN TCP_CB *Tcb,
|
|
|
|
IN TCP4_MODE_DATA *Mode
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SOCKET *Sock;
|
|
|
|
EFI_TCP4_CONFIG_DATA *ConfigData;
|
|
|
|
EFI_TCP4_ACCESS_POINT *AccessPoint;
|
|
|
|
EFI_TCP4_OPTION *Option;
|
|
|
|
EFI_IP4_PROTOCOL *Ip;
|
|
|
|
|
|
|
|
Sock = Tcb->Sk;
|
|
|
|
|
|
|
|
if (!SOCK_IS_CONFIGURED (Sock) && (Mode->Tcp4ConfigData != NULL)) {
|
|
|
|
return EFI_NOT_STARTED;
|
|
|
|
}
|
|
|
|
|
2008-11-28 09:32:24 +01:00
|
|
|
if (Mode->Tcp4State != NULL) {
|
2007-07-25 07:32:10 +02:00
|
|
|
*(Mode->Tcp4State) = (EFI_TCP4_CONNECTION_STATE) Tcb->State;
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
2008-11-28 09:32:24 +01:00
|
|
|
if (Mode->Tcp4ConfigData != NULL) {
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
ConfigData = Mode->Tcp4ConfigData;
|
|
|
|
AccessPoint = &(ConfigData->AccessPoint);
|
|
|
|
Option = ConfigData->ControlOption;
|
|
|
|
|
|
|
|
ConfigData->TypeOfService = Tcb->TOS;
|
|
|
|
ConfigData->TimeToLive = Tcb->TTL;
|
|
|
|
|
|
|
|
AccessPoint->UseDefaultAddress = Tcb->UseDefaultAddr;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (&AccessPoint->StationAddress, &Tcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));
|
2007-07-24 10:06:37 +02:00
|
|
|
AccessPoint->SubnetMask = Tcb->SubnetMask;
|
|
|
|
AccessPoint->StationPort = NTOHS (Tcb->LocalEnd.Port);
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (&AccessPoint->RemoteAddress, &Tcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));
|
2007-07-24 10:06:37 +02:00
|
|
|
AccessPoint->RemotePort = NTOHS (Tcb->RemoteEnd.Port);
|
|
|
|
AccessPoint->ActiveFlag = (BOOLEAN) (Tcb->State != TCP_LISTEN);
|
|
|
|
|
|
|
|
if (Option != NULL) {
|
|
|
|
Option->ReceiveBufferSize = GET_RCV_BUFFSIZE (Tcb->Sk);
|
|
|
|
Option->SendBufferSize = GET_SND_BUFFSIZE (Tcb->Sk);
|
|
|
|
Option->MaxSynBackLog = GET_BACKLOG (Tcb->Sk);
|
|
|
|
|
|
|
|
Option->ConnectionTimeout = Tcb->ConnectTimeout / TCP_TICK_HZ;
|
|
|
|
Option->DataRetries = Tcb->MaxRexmit;
|
|
|
|
Option->FinTimeout = Tcb->FinWait2Timeout / TCP_TICK_HZ;
|
|
|
|
Option->TimeWaitTimeout = Tcb->TimeWaitTimeout / TCP_TICK_HZ;
|
|
|
|
Option->KeepAliveProbes = Tcb->MaxKeepAlive;
|
|
|
|
Option->KeepAliveTime = Tcb->KeepAliveIdle / TCP_TICK_HZ;
|
|
|
|
Option->KeepAliveInterval = Tcb->KeepAlivePeriod / TCP_TICK_HZ;
|
|
|
|
|
2007-07-25 07:32:10 +02:00
|
|
|
Option->EnableNagle = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_NAGLE));
|
|
|
|
Option->EnableTimeStamp = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_TS));
|
2008-09-04 11:37:28 +02:00
|
|
|
Option->EnableWindowScaling = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_WS));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
Option->EnableSelectiveAck = FALSE;
|
|
|
|
Option->EnablePathMtuDiscovery = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ip = Tcb->IpInfo->Ip;
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT (Ip != NULL);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return Ip->GetModeData (Ip, Mode->Ip4ModeData, Mode->MnpConfigData, Mode->SnpModeData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
If AP->StationPort isn't zero, check whether the access point
|
|
|
|
is registered, else generate a random station port for this
|
|
|
|
access point.
|
|
|
|
|
|
|
|
@param AP Pointer to the access point.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The check is passed or the port is assigned.
|
|
|
|
@retval EFI_INVALID_PARAMETER The non-zero station port is already used.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES No port can be allocated.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4Bind (
|
|
|
|
IN EFI_TCP4_ACCESS_POINT *AP
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BOOLEAN Cycle;
|
|
|
|
|
|
|
|
if (0 != AP->StationPort) {
|
|
|
|
//
|
|
|
|
// check if a same endpoint is bound
|
|
|
|
//
|
|
|
|
if (TcpFindTcbByPeer (&AP->StationAddress, AP->StationPort)) {
|
|
|
|
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// generate a random port
|
|
|
|
//
|
|
|
|
Cycle = FALSE;
|
|
|
|
|
|
|
|
if (TCP4_PORT_USER_RESERVED == mTcp4RandomPort) {
|
|
|
|
mTcp4RandomPort = TCP4_PORT_KNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTcp4RandomPort++;
|
|
|
|
|
|
|
|
while (TcpFindTcbByPeer (&AP->StationAddress, mTcp4RandomPort)) {
|
|
|
|
|
|
|
|
mTcp4RandomPort++;
|
|
|
|
|
|
|
|
if (mTcp4RandomPort <= TCP4_PORT_KNOWN) {
|
|
|
|
|
|
|
|
if (Cycle) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "Tcp4Bind: no port can be allocated "
|
2007-07-24 10:06:37 +02:00
|
|
|
"for this pcb\n"));
|
|
|
|
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTcp4RandomPort = TCP4_PORT_KNOWN + 1;
|
|
|
|
|
|
|
|
Cycle = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AP->StationPort = mTcp4RandomPort;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-11-28 09:32:24 +01:00
|
|
|
Flush the Tcb add its associated protocols.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB to be flushed.
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
Tcp4FlushPcb (
|
|
|
|
IN TCP_CB *Tcb
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SOCKET *Sock;
|
|
|
|
TCP4_PROTO_DATA *TcpProto;
|
|
|
|
|
|
|
|
IpIoConfigIp (Tcb->IpInfo, NULL);
|
|
|
|
|
|
|
|
Sock = Tcb->Sk;
|
|
|
|
TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
|
|
|
|
|
|
|
|
if (SOCK_IS_CONFIGURED (Sock)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
RemoveEntryList (&Tcb->List);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2007-08-27 11:17:26 +02:00
|
|
|
//
|
|
|
|
// Uninstall the device path protocl.
|
|
|
|
//
|
|
|
|
gBS->UninstallProtocolInterface (
|
|
|
|
Sock->SockHandle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
Sock->DevicePath
|
|
|
|
);
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (Sock->DevicePath);
|
2007-08-27 11:17:26 +02:00
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
TcpSetVariableData (TcpProto->TcpService);
|
|
|
|
}
|
|
|
|
|
|
|
|
NetbufFreeList (&Tcb->SndQue);
|
|
|
|
NetbufFreeList (&Tcb->RcvQue);
|
|
|
|
}
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
2008-12-16 03:57:53 +01:00
|
|
|
Attach a Pcb to the socket.
|
2008-12-06 00:47:55 +01:00
|
|
|
|
|
|
|
@param Sk Pointer to the socket of this TCP instance.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation is completed successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Tcp4AttachPcb (
|
|
|
|
IN SOCKET *Sk
|
|
|
|
)
|
|
|
|
{
|
|
|
|
TCP_CB *Tcb;
|
|
|
|
TCP4_PROTO_DATA *ProtoData;
|
|
|
|
IP_IO *IpIo;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
Tcb = AllocateZeroPool (sizeof (TCP_CB));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
if (Tcb == NULL) {
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "Tcp4ConfigurePcb: failed to allocate a TCB\n"));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProtoData = (TCP4_PROTO_DATA *) Sk->ProtoReserved;
|
|
|
|
IpIo = ProtoData->TcpService->IpIo;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create an IpInfo for this Tcb.
|
|
|
|
//
|
|
|
|
Tcb->IpInfo = IpIoAddIp (IpIo);
|
|
|
|
if (Tcb->IpInfo == NULL) {
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (Tcb);
|
2007-07-24 10:06:37 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
InitializeListHead (&Tcb->List);
|
|
|
|
InitializeListHead (&Tcb->SndQue);
|
|
|
|
InitializeListHead (&Tcb->RcvQue);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
Tcb->State = TCP_CLOSED;
|
|
|
|
Tcb->Sk = Sk;
|
|
|
|
ProtoData->TcpPcb = Tcb;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
2008-12-16 03:57:53 +01:00
|
|
|
Detach the Pcb of the socket.
|
2008-12-06 00:47:55 +01:00
|
|
|
|
|
|
|
@param Sk Pointer to the socket of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
Tcp4DetachPcb (
|
|
|
|
IN SOCKET *Sk
|
|
|
|
)
|
|
|
|
{
|
|
|
|
TCP4_PROTO_DATA *ProtoData;
|
|
|
|
TCP_CB *Tcb;
|
|
|
|
|
|
|
|
ProtoData = (TCP4_PROTO_DATA *) Sk->ProtoReserved;
|
|
|
|
Tcb = ProtoData->TcpPcb;
|
|
|
|
|
|
|
|
ASSERT (Tcb != NULL);
|
|
|
|
|
|
|
|
Tcp4FlushPcb (Tcb);
|
|
|
|
|
|
|
|
IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (Tcb);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
ProtoData->TcpPcb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-16 03:57:53 +01:00
|
|
|
Configure the Pcb using CfgData.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@param Sk Pointer to the socket of this TCP instance.
|
|
|
|
@param CfgData Pointer to the TCP configuration data.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation is completed successfully.
|
|
|
|
@retval EFI_INVALID_PARAMETER A same access point has been configured in
|
|
|
|
another TCP instance.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4ConfigurePcb (
|
|
|
|
IN SOCKET *Sk,
|
|
|
|
IN EFI_TCP4_CONFIG_DATA *CfgData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_IP4_CONFIG_DATA IpCfgData;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_TCP4_OPTION *Option;
|
|
|
|
TCP4_PROTO_DATA *TcpProto;
|
|
|
|
TCP_CB *Tcb;
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT ((CfgData != NULL) && (Sk != NULL) && (Sk->SockHandle != NULL));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
TcpProto = (TCP4_PROTO_DATA *) Sk->ProtoReserved;
|
|
|
|
Tcb = TcpProto->TcpPcb;
|
|
|
|
|
|
|
|
ASSERT (Tcb != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add Ip for send pkt to the peer
|
|
|
|
//
|
2007-08-23 04:19:41 +02:00
|
|
|
CopyMem (&IpCfgData, &mIpIoDefaultIpConfigData, sizeof (IpCfgData));
|
2007-07-24 10:06:37 +02:00
|
|
|
IpCfgData.DefaultProtocol = EFI_IP_PROTO_TCP;
|
|
|
|
IpCfgData.UseDefaultAddress = CfgData->AccessPoint.UseDefaultAddress;
|
|
|
|
IpCfgData.StationAddress = CfgData->AccessPoint.StationAddress;
|
|
|
|
IpCfgData.SubnetMask = CfgData->AccessPoint.SubnetMask;
|
|
|
|
IpCfgData.ReceiveTimeout = (UINT32) (-1);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Configure the IP instance this Tcb consumes.
|
|
|
|
//
|
|
|
|
Status = IpIoConfigIp (Tcb->IpInfo, &IpCfgData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto OnExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the default address info if the instance is configured to use default address.
|
|
|
|
//
|
|
|
|
if (CfgData->AccessPoint.UseDefaultAddress) {
|
|
|
|
CfgData->AccessPoint.StationAddress = IpCfgData.StationAddress;
|
|
|
|
CfgData->AccessPoint.SubnetMask = IpCfgData.SubnetMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// check if we can bind this endpoint in CfgData
|
|
|
|
//
|
|
|
|
Status = Tcp4Bind (&(CfgData->AccessPoint));
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "Tcp4ConfigurePcb: Bind endpoint failed "
|
2007-07-24 10:06:37 +02:00
|
|
|
"with %r\n", Status));
|
|
|
|
|
|
|
|
goto OnExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initalize the operating information in this Tcb
|
|
|
|
//
|
|
|
|
ASSERT (Tcb->State == TCP_CLOSED &&
|
2008-02-14 10:40:22 +01:00
|
|
|
IsListEmpty (&Tcb->SndQue) &&
|
|
|
|
IsListEmpty (&Tcb->RcvQue));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE);
|
|
|
|
Tcb->State = TCP_CLOSED;
|
|
|
|
|
|
|
|
Tcb->SndMss = 536;
|
|
|
|
Tcb->RcvMss = TcpGetRcvMss (Sk);
|
|
|
|
|
|
|
|
Tcb->SRtt = 0;
|
|
|
|
Tcb->Rto = 3 * TCP_TICK_HZ;
|
|
|
|
|
|
|
|
Tcb->CWnd = Tcb->SndMss;
|
|
|
|
Tcb->Ssthresh = 0xffffffff;
|
|
|
|
|
|
|
|
Tcb->CongestState = TCP_CONGEST_OPEN;
|
|
|
|
|
|
|
|
Tcb->KeepAliveIdle = TCP_KEEPALIVE_IDLE_MIN;
|
|
|
|
Tcb->KeepAlivePeriod = TCP_KEEPALIVE_PERIOD;
|
|
|
|
Tcb->MaxKeepAlive = TCP_MAX_KEEPALIVE;
|
|
|
|
Tcb->MaxRexmit = TCP_MAX_LOSS;
|
|
|
|
Tcb->FinWait2Timeout = TCP_FIN_WAIT2_TIME;
|
|
|
|
Tcb->TimeWaitTimeout = TCP_TIME_WAIT_TIME;
|
|
|
|
Tcb->ConnectTimeout = TCP_CONNECT_TIME;
|
|
|
|
|
|
|
|
//
|
|
|
|
// initialize Tcb in the light of CfgData
|
|
|
|
//
|
|
|
|
Tcb->TTL = CfgData->TimeToLive;
|
|
|
|
Tcb->TOS = CfgData->TypeOfService;
|
|
|
|
|
2007-08-27 11:17:26 +02:00
|
|
|
Tcb->UseDefaultAddr = CfgData->AccessPoint.UseDefaultAddress;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (&Tcb->LocalEnd.Ip, &CfgData->AccessPoint.StationAddress, sizeof (IP4_ADDR));
|
2007-07-24 10:06:37 +02:00
|
|
|
Tcb->LocalEnd.Port = HTONS (CfgData->AccessPoint.StationPort);
|
|
|
|
Tcb->SubnetMask = CfgData->AccessPoint.SubnetMask;
|
|
|
|
|
2007-08-27 11:17:26 +02:00
|
|
|
if (CfgData->AccessPoint.ActiveFlag) {
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (&Tcb->RemoteEnd.Ip, &CfgData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));
|
2007-08-27 11:17:26 +02:00
|
|
|
Tcb->RemoteEnd.Port = HTONS (CfgData->AccessPoint.RemotePort);
|
|
|
|
} else {
|
|
|
|
Tcb->RemoteEnd.Ip = 0;
|
|
|
|
Tcb->RemoteEnd.Port = 0;
|
|
|
|
}
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
Option = CfgData->ControlOption;
|
|
|
|
|
|
|
|
if (Option != NULL) {
|
|
|
|
SET_RCV_BUFFSIZE (
|
|
|
|
Sk,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (TCP_COMP_VAL (
|
|
|
|
TCP_RCV_BUF_SIZE_MIN,
|
|
|
|
TCP_RCV_BUF_SIZE,
|
|
|
|
TCP_RCV_BUF_SIZE,
|
|
|
|
Option->ReceiveBufferSize
|
|
|
|
)
|
|
|
|
)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
SET_SND_BUFFSIZE (
|
|
|
|
Sk,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (TCP_COMP_VAL (
|
|
|
|
TCP_SND_BUF_SIZE_MIN,
|
|
|
|
TCP_SND_BUF_SIZE,
|
|
|
|
TCP_SND_BUF_SIZE,
|
|
|
|
Option->SendBufferSize
|
|
|
|
)
|
|
|
|
)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
SET_BACKLOG (
|
|
|
|
Sk,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (TCP_COMP_VAL (
|
|
|
|
TCP_BACKLOG_MIN,
|
|
|
|
TCP_BACKLOG,
|
|
|
|
TCP_BACKLOG,
|
|
|
|
Option->MaxSynBackLog
|
|
|
|
)
|
|
|
|
)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
Tcb->MaxRexmit = (UINT16) TCP_COMP_VAL (
|
|
|
|
TCP_MAX_LOSS_MIN,
|
|
|
|
TCP_MAX_LOSS,
|
|
|
|
TCP_MAX_LOSS,
|
|
|
|
Option->DataRetries
|
|
|
|
);
|
|
|
|
Tcb->FinWait2Timeout = TCP_COMP_VAL (
|
|
|
|
TCP_FIN_WAIT2_TIME,
|
|
|
|
TCP_FIN_WAIT2_TIME_MAX,
|
|
|
|
TCP_FIN_WAIT2_TIME,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (Option->FinTimeout * TCP_TICK_HZ)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (Option->TimeWaitTimeout != 0) {
|
|
|
|
Tcb->TimeWaitTimeout = TCP_COMP_VAL (
|
|
|
|
TCP_TIME_WAIT_TIME,
|
|
|
|
TCP_TIME_WAIT_TIME_MAX,
|
|
|
|
TCP_TIME_WAIT_TIME,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (Option->TimeWaitTimeout * TCP_TICK_HZ)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Tcb->TimeWaitTimeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Option->KeepAliveProbes != 0) {
|
|
|
|
TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE);
|
|
|
|
|
|
|
|
Tcb->MaxKeepAlive = (UINT8) TCP_COMP_VAL (
|
|
|
|
TCP_MAX_KEEPALIVE_MIN,
|
|
|
|
TCP_MAX_KEEPALIVE,
|
|
|
|
TCP_MAX_KEEPALIVE,
|
|
|
|
Option->KeepAliveProbes
|
|
|
|
);
|
|
|
|
Tcb->KeepAliveIdle = TCP_COMP_VAL (
|
|
|
|
TCP_KEEPALIVE_IDLE_MIN,
|
|
|
|
TCP_KEEPALIVE_IDLE_MAX,
|
|
|
|
TCP_KEEPALIVE_IDLE_MIN,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (Option->KeepAliveTime * TCP_TICK_HZ)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
Tcb->KeepAlivePeriod = TCP_COMP_VAL (
|
|
|
|
TCP_KEEPALIVE_PERIOD_MIN,
|
|
|
|
TCP_KEEPALIVE_PERIOD,
|
|
|
|
TCP_KEEPALIVE_PERIOD,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (Option->KeepAliveInterval * TCP_TICK_HZ)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcb->ConnectTimeout = TCP_COMP_VAL (
|
|
|
|
TCP_CONNECT_TIME_MIN,
|
|
|
|
TCP_CONNECT_TIME,
|
|
|
|
TCP_CONNECT_TIME,
|
2007-07-25 07:32:10 +02:00
|
|
|
(UINT32) (Option->ConnectionTimeout * TCP_TICK_HZ)
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (Option->EnableNagle == FALSE) {
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_NAGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Option->EnableTimeStamp == FALSE) {
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_TS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Option->EnableWindowScaling == FALSE) {
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_WS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-27 11:17:26 +02:00
|
|
|
//
|
|
|
|
// The socket is bound, the <SrcIp, SrcPort, DstIp, DstPort> is
|
|
|
|
// determined, construct the IP device path and install it.
|
|
|
|
//
|
|
|
|
Status = TcpInstallDevicePath (Sk);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto OnExit;
|
|
|
|
}
|
|
|
|
|
2007-07-24 10:06:37 +02:00
|
|
|
//
|
|
|
|
// update state of Tcb and socket
|
|
|
|
//
|
|
|
|
if (CfgData->AccessPoint.ActiveFlag == FALSE) {
|
|
|
|
|
|
|
|
TcpSetState (Tcb, TCP_LISTEN);
|
|
|
|
SockSetState (Sk, SO_LISTENING);
|
|
|
|
|
|
|
|
Sk->ConfigureState = SO_CONFIGURED_PASSIVE;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Sk->ConfigureState = SO_CONFIGURED_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpInsertTcb (Tcb);
|
|
|
|
|
|
|
|
OnExit:
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
The procotol handler provided to the socket layer, used to
|
|
|
|
dispatch the socket level requests by calling the corresponding
|
|
|
|
TCP layer functions.
|
|
|
|
|
|
|
|
@param Sock Pointer to the socket of this TCP instance.
|
|
|
|
@param Request The code of this operation request.
|
|
|
|
@param Data Pointer to the operation specific data passed in
|
|
|
|
together with the operation request.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The socket request is completed successfully.
|
|
|
|
@retval other The error status returned by the corresponding TCP
|
|
|
|
layer function.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4Dispatcher (
|
|
|
|
IN SOCKET *Sock,
|
|
|
|
IN SOCK_REQUEST Request,
|
|
|
|
IN VOID *Data OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
TCP_CB *Tcb;
|
|
|
|
TCP4_PROTO_DATA *ProtoData;
|
|
|
|
EFI_IP4_PROTOCOL *Ip;
|
|
|
|
|
|
|
|
ProtoData = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
|
|
|
|
Tcb = ProtoData->TcpPcb;
|
|
|
|
|
|
|
|
switch (Request) {
|
|
|
|
case SOCK_POLL:
|
|
|
|
Ip = ProtoData->TcpService->IpIo->Ip;
|
|
|
|
Ip->Poll (Ip);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_CONSUMED:
|
|
|
|
//
|
|
|
|
// After user received data from socket buffer, socket will
|
|
|
|
// notify TCP using this message to give it a chance to send out
|
|
|
|
// window update information
|
|
|
|
//
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT (Tcb != NULL);
|
2007-07-24 10:06:37 +02:00
|
|
|
TcpOnAppConsume (Tcb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_SND:
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT (Tcb != NULL);
|
2007-07-24 10:06:37 +02:00
|
|
|
TcpOnAppSend (Tcb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_CLOSE:
|
|
|
|
|
|
|
|
TcpOnAppClose (Tcb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_ABORT:
|
|
|
|
|
|
|
|
TcpOnAppAbort (Tcb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_SNDPUSH:
|
|
|
|
Tcb->SndPsh = TcpGetMaxSndNxt (Tcb) + GET_SND_DATASIZE (Tcb->Sk);
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_PSH);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_SNDURG:
|
|
|
|
Tcb->SndUp = TcpGetMaxSndNxt (Tcb) + GET_SND_DATASIZE (Tcb->Sk) - 1;
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_URG);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_CONNECT:
|
|
|
|
|
|
|
|
TcpOnAppConnect (Tcb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_ATTACH:
|
|
|
|
|
|
|
|
return Tcp4AttachPcb (Sock);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_FLUSH:
|
|
|
|
|
|
|
|
Tcp4FlushPcb (Tcb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_DETACH:
|
|
|
|
|
|
|
|
Tcp4DetachPcb (Sock);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_CONFIGURE:
|
|
|
|
|
|
|
|
return Tcp4ConfigurePcb (
|
|
|
|
Sock,
|
|
|
|
(EFI_TCP4_CONFIG_DATA *) Data
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_MODE:
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT ((Data != NULL) && (Tcb != NULL));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return Tcp4GetMode (Tcb, (TCP4_MODE_DATA *) Data);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_ROUTE:
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
ASSERT ((Data != NULL) && (Tcb != NULL));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
return Tcp4Route (Tcb, (TCP4_ROUTE_INFO *) Data);
|
|
|
|
|
2007-08-30 08:58:37 +02:00
|
|
|
default:
|
|
|
|
return EFI_UNSUPPORTED;
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
}
|