tcp4dispatcher.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 709 行 · 第 1/2 页
C
709 行
/*++
Copyright (c) 2005 - 2006, Intel Corporation
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Tcp4Dispatcher.c
Abstract:
--*/
#include "Tcp4Main.h"
#define TCP_COMP_VAL(Min, Max, Default, Val) \
((((Val) <= (Max)) && ((Val) >= (Min))) ? (Val) : (Default))
STATIC
EFI_STATUS
Tcp4Route (
IN TCP_CB *Tcb,
IN TCP4_ROUTE_INFO *RouteInfo
)
/*++
Routine Description:
Add or remove a route entry in the IP route table associated
with this TCP instance.
Arguments:
Tcb - Pointer to the TCP_CB of this TCP instance.
RouteInfo - Pointer to the route info to be processed.
Returns:
EFI_SUCCESS - The operation completed successfully.
EFI_NOT_STARTED - The driver instance has not been started.
EFI_NO_MAPPING - When using the default address, configuration(DHCP,
BOOTP, RARP, etc.) is not finished yet.
EFI_OUT_OF_RESOURCES - Could not add the entry to the routing table.
EFI_NOT_FOUND - This route is not in the routing table
(when RouteInfo->DeleteRoute is TRUE).
EFI_ACCESS_DENIED - The route is already defined in the routing table
(when RouteInfo->DeleteRoute is FALSE).
--*/
{
EFI_IP4_PROTOCOL *Ip;
Ip = Tcb->IpInfo->Ip;
ASSERT (Ip);
return Ip->Routes (
Ip,
RouteInfo->DeleteRoute,
RouteInfo->SubnetAddress,
RouteInfo->SubnetMask,
RouteInfo->GatewayAddress
);
}
STATIC
EFI_STATUS
Tcp4GetMode (
IN TCP_CB *Tcb,
IN TCP4_MODE_DATA *Mode
)
/*++
Routine Description:
Get the operational settings of this TCP instance.
Arguments:
Tcb - Pointer to the TCP_CB of this TCP instance.
Mode - Pointer to the buffer to store the operational settings.
Returns:
EFI_SUCCESS - The mode data is read.
EFI_NOT_STARTED - No configuration data is available because this
instance hasn't been started.
--*/
{
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;
}
if (Mode->Tcp4State) {
*(Mode->Tcp4State) = Tcb->State;
}
if (Mode->Tcp4ConfigData) {
ConfigData = Mode->Tcp4ConfigData;
AccessPoint = &(ConfigData->AccessPoint);
Option = ConfigData->ControlOption;
ConfigData->TypeOfService = Tcb->TOS;
ConfigData->TimeToLive = Tcb->TTL;
AccessPoint->UseDefaultAddress = Tcb->UseDefaultAddr;
EFI_IP4 (AccessPoint->StationAddress) = Tcb->LocalEnd.Ip;
AccessPoint->SubnetMask = Tcb->SubnetMask;
AccessPoint->StationPort = NTOHS (Tcb->LocalEnd.Port);
EFI_IP4 (AccessPoint->RemoteAddress) = Tcb->RemoteEnd.Ip;
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;
Option->EnableNagle = !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_NAGLE);
Option->EnableTimeStamp = !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_TS);
Option->EnableWindowScaling = !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_WS);
Option->EnableSelectiveAck = FALSE;
Option->EnablePathMtuDiscovery = FALSE;
}
}
Ip = Tcb->IpInfo->Ip;
ASSERT (Ip);
return Ip->GetModeData (Ip, Mode->Ip4ModeData, Mode->MnpConfigData, Mode->SnpModeData);
}
STATIC
EFI_STATUS
Tcp4Bind (
IN EFI_TCP4_ACCESS_POINT *AP
)
/*++
Routine Description:
If AP->StationPort isn't zero, check whether the access point
is registered, else generate a random station port for this
access point.
Arguments:
AP - Pointer to the access point.
Returns:
EFI_SUCCESS - The check is passed or the port is assigned.
EFI_INVALID_PARAMETER - The non-zero station port is already used.
EFI_OUT_OF_RESOURCES - No port can be allocated.
--*/
{
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) {
TCP4_DEBUG_ERROR (("Tcp4Bind: no port can be allocated "
"for this pcb\n"));
return EFI_OUT_OF_RESOURCES;
}
mTcp4RandomPort = TCP4_PORT_KNOWN + 1;
Cycle = TRUE;
}
}
AP->StationPort = mTcp4RandomPort;
}
return EFI_SUCCESS;
}
STATIC
VOID
Tcp4FlushPcb (
IN TCP_CB *Tcb
)
/*++
Routine Description:
Flush the Tcb add its associated protocols..
Arguments:
Tcb - Pointer to the TCP_CB to be flushed.
Returns:
EFI_SUCCESS - The operation is completed successfully.
--*/
{
SOCKET *Sock;
TCP4_PROTO_DATA *TcpProto;
IpIoConfigIp (Tcb->IpInfo, NULL);
Sock = Tcb->Sk;
TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
if (SOCK_IS_CONFIGURED (Sock)) {
NetListRemoveEntry (&Tcb->List);
TcpSetVariableData (TcpProto->TcpService);
}
NetbufFreeList (&Tcb->SndQue);
NetbufFreeList (&Tcb->RcvQue);
}
STATIC
EFI_STATUS
Tcp4AttachPcb (
IN SOCKET *Sk
)
{
TCP_CB *Tcb;
TCP4_PROTO_DATA *ProtoData;
IP_IO *IpIo;
Tcb = NetAllocateZeroPool (sizeof (TCP_CB));
if (Tcb == NULL) {
TCP4_DEBUG_ERROR (("Tcp4ConfigurePcb: failed to allocate a TCB\n"));
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) {
NetFreePool (Tcb);
return EFI_OUT_OF_RESOURCES;
}
NetListInit (&Tcb->List);
NetListInit (&Tcb->SndQue);
NetListInit (&Tcb->RcvQue);
Tcb->State = TCP_CLOSED;
Tcb->Sk = Sk;
ProtoData->TcpPcb = Tcb;
return EFI_SUCCESS;
}
STATIC
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);
NetFreePool (Tcb);
ProtoData->TcpPcb = NULL;
}
STATIC
EFI_STATUS
Tcp4ConfigurePcb (
IN SOCKET *Sk,
IN EFI_TCP4_CONFIG_DATA *CfgData
)
/*++
Routine Description:
Configure the Tcb using CfgData.
Arguments:
Sk - Pointer to the socket of this TCP instance.
SkTcb - Pointer to the TCP_CB of this TCP instance.
CfgData - Pointer to the TCP configuration data.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?