tcp4main.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 618 行 · 第 1/2 页
C
618 行
/*++
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:
Tcp4Main.c
Abstract:
Implementation of TCP4 protocol services.
--*/
#include "Tcp4Main.h"
STATIC
EFI_STATUS
Tcp4ChkDataBuf (
IN UINT32 DataLen,
IN UINT32 FragmentCount,
IN EFI_TCP4_FRAGMENT_DATA *FragmentTable
)
/*++
Routine Description:
Check the integrity of the data buffer.
Arguments:
DataLen - The total length of the data buffer.
FragmentCount - The fragment count of the fragment table.
FragmentTable - Pointer to the fragment table of the data buffer.
Returns:
EFI_SUCCESS - The integrity check is passed.
EFI_INVALID_PARAMETER - The integrity check is failed.
--*/
{
UINT32 Index;
UINT32 Len;
for (Index = 0, Len = 0; Index < FragmentCount; Index++) {
Len = Len + FragmentTable[Index].FragmentLength;
}
if (DataLen != Len) {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
Tcp4GetModeData (
IN EFI_TCP4_PROTOCOL * This,
OUT EFI_TCP4_CONNECTION_STATE * Tcp4State OPTIONAL,
OUT EFI_TCP4_CONFIG_DATA * Tcp4ConfigData OPTIONAL,
OUT EFI_IP4_MODE_DATA * Ip4ModeData OPTIONAL,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA * MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE * SnpModeData OPTIONAL
)
/*++
Routine Description:
Get the current operational status.
Arguments:
This - Pointer to the EFI_TCP4_PROTOCOL instance.
Tcp4State - Pointer to the buffer to receive the current TCP state.
Tcp4ConfigData - Pointer to the buffer to receive the current TCP
configuration.
Ip4ModeData - Pointer to the buffer to receive the current IPv4
configuration.
MnpConfigData - Pointer to the buffer to receive the current MNP
configuration data indirectly used by the TCPv4 Instance.
SnpModeData - Pointer to the buffer to receive the current SNP
configuration data indirectly used by the TCPv4 Instance.
Returns:
EFI_SUCCESS - The mode data was read.
EFI_NOT_STARTED - No configuration data is available because this
instance hasn't been started.
EFI_INVALID_PARAMETER - This is NULL.
--*/
{
TCP4_MODE_DATA TcpMode;
SOCKET *Sock;
if (NULL == This) {
return EFI_INVALID_PARAMETER;
}
Sock = SOCK_FROM_THIS (This);
TcpMode.Tcp4State = Tcp4State;
TcpMode.Tcp4ConfigData = Tcp4ConfigData;
TcpMode.Ip4ModeData = Ip4ModeData;
TcpMode.MnpConfigData = MnpConfigData;
TcpMode.SnpModeData = SnpModeData;
return SockGetMode (Sock, &TcpMode);
}
EFI_STATUS
EFIAPI
Tcp4Configure (
IN EFI_TCP4_PROTOCOL * This,
IN EFI_TCP4_CONFIG_DATA * TcpConfigData OPTIONAL
)
/*++
Routine Description:
Initialize or brutally reset the operational parameters for
this EFI TCPv4 instance.
Arguments:
This - Pointer to the EFI_TCP4_PROTOCOL instance.
TcpConfigData - Pointer to the configure data to configure the instance.
Returns:
EFI_SUCCESS - The operational settings are set, changed, or
reset successfully.
EFI_NO_MAPPING - When using a default address, configuration
(through DHCP, BOOTP, RARP, etc.) is not finished.
EFI_INVALID_PARAMETER - One or more parameters are invalid.
EFI_ACCESS_DENIED - Configuring TCP instance when it is already
configured.
EFI_DEVICE_ERROR - An unexpected network or system error occurred.
EFI_UNSUPPORTED - One or more of the control options are not
supported in the implementation.
EFI_OUT_OF_RESOURCES - Could not allocate enough system resources.
--*/
{
EFI_TCP4_OPTION *Option;
SOCKET *Sock;
EFI_STATUS Status;
if (NULL == This) {
return EFI_INVALID_PARAMETER;
}
//
// Tcp protocol related parameter check will be conducted here
//
if (NULL != TcpConfigData) {
if ((EFI_IP4 (TcpConfigData->AccessPoint.RemoteAddress) != 0) &&
!Ip4IsUnicast (EFI_NTOHL (TcpConfigData->AccessPoint.RemoteAddress), 0)) {
return EFI_INVALID_PARAMETER;
}
if (!TcpConfigData->AccessPoint.UseDefaultAddress) {
if (!Ip4IsUnicast (EFI_NTOHL (TcpConfigData->AccessPoint.StationAddress), 0) ||
!IP4_IS_VALID_NETMASK (EFI_NTOHL (TcpConfigData->AccessPoint.SubnetMask))
) {
return EFI_INVALID_PARAMETER;
}
}
if (TcpConfigData->AccessPoint.ActiveFlag &&
(0 == TcpConfigData->AccessPoint.RemotePort ||
(EFI_IP4 (TcpConfigData->AccessPoint.RemoteAddress) == 0))
) {
return EFI_INVALID_PARAMETER;
}
Option = TcpConfigData->ControlOption;
if ((NULL != Option) &&
(Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {
return EFI_UNSUPPORTED;
}
}
Sock = SOCK_FROM_THIS (This);
if (NULL == TcpConfigData) {
return SockFlush (Sock);
}
Status = SockConfigure (Sock, TcpConfigData);
if (EFI_NO_MAPPING == Status) {
Sock->ConfigureState = SO_NO_MAPPING;
}
return Status;
}
EFI_STATUS
EFIAPI
Tcp4Routes (
IN EFI_TCP4_PROTOCOL *This,
IN BOOLEAN DeleteRoute,
IN EFI_IPv4_ADDRESS *SubnetAddress,
IN EFI_IPv4_ADDRESS *SubnetMask,
IN EFI_IPv4_ADDRESS *GatewayAddress
)
/*++
Routine Description:
Add or delete routing entries.
Arguments:
This - Pointer to the EFI_TCP4_PROTOCOL instance.
DeleteRoute - If TRUE, delete the specified route from routing table;
if FALSE, add the specified route to routing table.
SubnetAddress - The destination network.
SubnetMask - The subnet mask for the destination network.
GatewayAddress - The gateway address for this route.
Returns:
EFI_SUCCESS - The operation completed successfully.
EFI_NOT_STARTED - The EFI_TCP4_PROTOCOL instance has not been
configured.
EFI_NO_MAPPING - When using a default address, configuration
(through DHCP, BOOTP, RARP, etc.) is not finished.
EFI_INVALID_PARAMETER - One or more parameters are invalid.
EFI_OUT_OF_RESOURCES - Could not allocate enough resources to add the
entry to the routing table.
EFI_NOT_FOUND - This route is not in the routing table.
EFI_ACCESS_DENIED - This route is already in the routing table.
EFI_UNSUPPORTED - The TCP driver does not support this operation.
--*/
{
SOCKET *Sock;
TCP4_ROUTE_INFO RouteInfo;
if (NULL == This) {
return EFI_INVALID_PARAMETER;
}
Sock = SOCK_FROM_THIS (This);
RouteInfo.DeleteRoute = DeleteRoute;
RouteInfo.SubnetAddress = SubnetAddress;
RouteInfo.SubnetMask = SubnetMask;
RouteInfo.GatewayAddress = GatewayAddress;
return SockRoute (Sock, &RouteInfo);
}
EFI_STATUS
EFIAPI
Tcp4Connect (
IN EFI_TCP4_PROTOCOL *This,
IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken
)
/*++
Routine Description:
Initiate a nonblocking TCP connection request for an active TCP instance.
Arguments:
This - Pointer to the EFI_TCP4_PROTOCOL instance
ConnectionToken - Pointer to the connection token to return when the TCP
three way handshake finishes.
Returns:
EFI_SUCCESS - The connection request is successfully initiated.
EFI_NOT_STARTED - This EFI_TCP4_PROTOCOL instance hasn't been
configured.
EFI_ACCESS_DENIED - The instance is not configured as an active one
or it is not in Tcp4StateClosed state.
EFI_INVALID_PARAMETER - One or more parameters are invalid.
EFI_OUT_OF_RESOURCES - The driver can't allocate enough resource to
initiate the active open.
EFI_DEVICE_ERROR - An unexpected system or network error occurred.
--*/
{
SOCKET *Sock;
if (NULL == This ||
NULL == ConnectionToken ||
NULL == ConnectionToken->CompletionToken.Event) {
return EFI_INVALID_PARAMETER;
}
Sock = SOCK_FROM_THIS (This);
return SockConnect (Sock, ConnectionToken);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?