2008-04-17 10:28:51 +02:00
|
|
|
/** @file
|
2008-12-10 07:13:51 +01:00
|
|
|
The wrap of TCP/IP Socket interface.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2010-04-24 11:33:45 +02:00
|
|
|
Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials
|
2008-01-22 09:07:35 +01:00
|
|
|
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.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
#include "IScsiImpl.h"
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
The common notify function associated with various Tcp4Io events.
|
|
|
|
|
2008-12-10 07:13:51 +01:00
|
|
|
@param[in] Event The event signaled.
|
|
|
|
@param[in] Context The context.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
Tcp4IoCommonNotify (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
2008-04-17 10:28:51 +02:00
|
|
|
{
|
|
|
|
*((BOOLEAN *) Context) = TRUE;
|
|
|
|
}
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Create a TCP socket with the specified configuration data.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-12-10 07:13:51 +01:00
|
|
|
@param[in] Image The handle of the driver image.
|
|
|
|
@param[in] Controller The handle of the controller.
|
|
|
|
@param[in] ConfigData The Tcp4 configuration data.
|
|
|
|
@param[in] Tcp4Io The Tcp4Io.
|
2008-04-17 10:28:51 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The TCP socket is created and configured.
|
2008-12-10 07:13:51 +01:00
|
|
|
@retval Others Failed to create the TCP socket or configure it.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
EFI_STATUS
|
|
|
|
Tcp4IoCreateSocket (
|
|
|
|
IN EFI_HANDLE Image,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN TCP4_IO_CONFIG_DATA *ConfigData,
|
|
|
|
IN TCP4_IO *Tcp4Io
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_TCP4_PROTOCOL *Tcp4;
|
|
|
|
EFI_TCP4_CONFIG_DATA Tcp4ConfigData;
|
|
|
|
EFI_TCP4_OPTION ControlOption;
|
|
|
|
EFI_TCP4_ACCESS_POINT *AccessPoint;
|
|
|
|
|
|
|
|
Tcp4Io->Handle = NULL;
|
|
|
|
Tcp4Io->ConnToken.CompletionToken.Event = NULL;
|
|
|
|
Tcp4Io->TxToken.CompletionToken.Event = NULL;
|
|
|
|
Tcp4Io->RxToken.CompletionToken.Event = NULL;
|
|
|
|
Tcp4Io->CloseToken.CompletionToken.Event = NULL;
|
|
|
|
Tcp4 = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create the TCP4 child instance and get the TCP4 protocol.
|
|
|
|
//
|
|
|
|
Status = NetLibCreateServiceChild (
|
|
|
|
Controller,
|
|
|
|
Image,
|
|
|
|
&gEfiTcp4ServiceBindingProtocolGuid,
|
|
|
|
&Tcp4Io->Handle
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Tcp4Io->Handle,
|
|
|
|
&gEfiTcp4ProtocolGuid,
|
|
|
|
(VOID **)&Tcp4Io->Tcp4,
|
|
|
|
Image,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcp4Io->Image = Image;
|
|
|
|
Tcp4Io->Controller = Controller;
|
|
|
|
Tcp4 = Tcp4Io->Tcp4;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set the configuration parameters.
|
|
|
|
//
|
|
|
|
ControlOption.ReceiveBufferSize = 0x200000;
|
|
|
|
ControlOption.SendBufferSize = 0x200000;
|
|
|
|
ControlOption.MaxSynBackLog = 0;
|
|
|
|
ControlOption.ConnectionTimeout = 0;
|
|
|
|
ControlOption.DataRetries = 6;
|
|
|
|
ControlOption.FinTimeout = 0;
|
|
|
|
ControlOption.TimeWaitTimeout = 0;
|
|
|
|
ControlOption.KeepAliveProbes = 4;
|
|
|
|
ControlOption.KeepAliveTime = 0;
|
|
|
|
ControlOption.KeepAliveInterval = 0;
|
|
|
|
ControlOption.EnableNagle = FALSE;
|
|
|
|
ControlOption.EnableTimeStamp = FALSE;
|
|
|
|
ControlOption.EnableWindowScaling = TRUE;
|
|
|
|
ControlOption.EnableSelectiveAck = FALSE;
|
|
|
|
ControlOption.EnablePathMtuDiscovery = FALSE;
|
|
|
|
|
|
|
|
Tcp4ConfigData.TypeOfService = 8;
|
|
|
|
Tcp4ConfigData.TimeToLive = 255;
|
|
|
|
Tcp4ConfigData.ControlOption = &ControlOption;
|
|
|
|
|
|
|
|
AccessPoint = &Tcp4ConfigData.AccessPoint;
|
|
|
|
|
|
|
|
AccessPoint->UseDefaultAddress = FALSE;
|
|
|
|
AccessPoint->StationPort = 0;
|
|
|
|
AccessPoint->RemotePort = ConfigData->RemotePort;
|
|
|
|
AccessPoint->ActiveFlag = TRUE;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (&AccessPoint->StationAddress, &ConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));
|
|
|
|
CopyMem (&AccessPoint->SubnetMask, &ConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
|
|
|
|
CopyMem (&AccessPoint->RemoteAddress, &ConfigData->RemoteIp, sizeof (EFI_IPv4_ADDRESS));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Configure the TCP4 protocol.
|
|
|
|
//
|
|
|
|
Status = Tcp4->Configure (Tcp4, &Tcp4ConfigData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_IP4_EQUAL (&ConfigData->Gateway, &mZeroIp4Addr)) {
|
|
|
|
//
|
|
|
|
// the gateway is not zero, add the default route by hand
|
|
|
|
//
|
|
|
|
Status = Tcp4->Routes (Tcp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, &ConfigData->Gateway);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Create events for variuos asynchronous operations.
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEvent (
|
2008-09-04 09:42:38 +02:00
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_NOTIFY,
|
2007-12-24 03:20:21 +01:00
|
|
|
Tcp4IoCommonNotify,
|
|
|
|
&Tcp4Io->IsConnDone,
|
|
|
|
&Tcp4Io->ConnToken.CompletionToken.Event
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->CreateEvent (
|
2008-09-04 09:42:38 +02:00
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_NOTIFY,
|
2007-12-24 03:20:21 +01:00
|
|
|
Tcp4IoCommonNotify,
|
|
|
|
&Tcp4Io->IsTxDone,
|
|
|
|
&Tcp4Io->TxToken.CompletionToken.Event
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->CreateEvent (
|
2008-09-04 09:42:38 +02:00
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_NOTIFY,
|
2007-12-24 03:20:21 +01:00
|
|
|
Tcp4IoCommonNotify,
|
|
|
|
&Tcp4Io->IsRxDone,
|
|
|
|
&Tcp4Io->RxToken.CompletionToken.Event
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->CreateEvent (
|
2008-09-04 09:42:38 +02:00
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_NOTIFY,
|
2007-12-24 03:20:21 +01:00
|
|
|
Tcp4IoCommonNotify,
|
|
|
|
&Tcp4Io->IsCloseDone,
|
|
|
|
&Tcp4Io->CloseToken.CompletionToken.Event
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcp4Io->IsTxDone = FALSE;
|
|
|
|
Tcp4Io->IsRxDone = FALSE;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
ON_ERROR:
|
|
|
|
|
|
|
|
if (Tcp4Io->RxToken.CompletionToken.Event != NULL) {
|
|
|
|
gBS->CloseEvent (Tcp4Io->RxToken.CompletionToken.Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tcp4Io->TxToken.CompletionToken.Event != NULL) {
|
|
|
|
gBS->CloseEvent (Tcp4Io->TxToken.CompletionToken.Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tcp4Io->ConnToken.CompletionToken.Event != NULL) {
|
|
|
|
gBS->CloseEvent (Tcp4Io->ConnToken.CompletionToken.Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tcp4 != NULL) {
|
|
|
|
Tcp4->Configure (Tcp4, NULL);
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Tcp4Io->Handle,
|
|
|
|
&gEfiTcp4ProtocolGuid,
|
|
|
|
Image,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
NetLibDestroyServiceChild (
|
|
|
|
Controller,
|
|
|
|
Image,
|
|
|
|
&gEfiTcp4ServiceBindingProtocolGuid,
|
|
|
|
Tcp4Io->Handle
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
2007-12-24 03:20:21 +01:00
|
|
|
Destroy the socket.
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
@param[in] Tcp4Io The Tcp4Io which wraps the socket to be destroyeds.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
Tcp4IoDestroySocket (
|
|
|
|
IN TCP4_IO *Tcp4Io
|
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_TCP4_PROTOCOL *Tcp4;
|
|
|
|
|
|
|
|
Tcp4 = Tcp4Io->Tcp4;
|
|
|
|
|
|
|
|
Tcp4->Configure (Tcp4, NULL);
|
|
|
|
|
|
|
|
gBS->CloseEvent (Tcp4Io->TxToken.CompletionToken.Event);
|
|
|
|
gBS->CloseEvent (Tcp4Io->RxToken.CompletionToken.Event);
|
|
|
|
gBS->CloseEvent (Tcp4Io->ConnToken.CompletionToken.Event);
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Tcp4Io->Handle,
|
|
|
|
&gEfiTcp4ProtocolGuid,
|
|
|
|
Tcp4Io->Image,
|
|
|
|
Tcp4Io->Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
NetLibDestroyServiceChild (
|
|
|
|
Tcp4Io->Controller,
|
|
|
|
Tcp4Io->Image,
|
|
|
|
&gEfiTcp4ServiceBindingProtocolGuid,
|
|
|
|
Tcp4Io->Handle
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
2007-12-24 03:20:21 +01:00
|
|
|
Connect to the other endpoint of the TCP socket.
|
|
|
|
|
2008-12-14 13:25:48 +01:00
|
|
|
@param[in, out] Tcp4Io The Tcp4Io wrapping the TCP socket.
|
|
|
|
@param[in] Timeout The time to wait for connection done.
|
2008-12-10 07:13:51 +01:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS Connect to the other endpoint of the TCP socket successfully.
|
|
|
|
@retval EFI_TIMEOUT Failed to connect to the other endpoint of the TCP socket in the specified time period.
|
2008-12-12 08:03:44 +01:00
|
|
|
@retval Others Other errors as indicated.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4IoConnect (
|
2008-12-14 13:25:48 +01:00
|
|
|
IN OUT TCP4_IO *Tcp4Io,
|
|
|
|
IN EFI_EVENT Timeout
|
2008-04-17 10:28:51 +02:00
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_TCP4_PROTOCOL *Tcp4;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Tcp4Io->IsConnDone = FALSE;
|
|
|
|
Tcp4 = Tcp4Io->Tcp4;
|
|
|
|
Status = Tcp4->Connect (Tcp4, &Tcp4Io->ConnToken);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!Tcp4Io->IsConnDone && EFI_ERROR (gBS->CheckEvent (Timeout))) {
|
|
|
|
Tcp4->Poll (Tcp4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Tcp4Io->IsConnDone) {
|
|
|
|
Status = EFI_TIMEOUT;
|
|
|
|
} else {
|
|
|
|
Status = Tcp4Io->ConnToken.CompletionToken.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
2007-12-24 03:20:21 +01:00
|
|
|
Reset the socket.
|
|
|
|
|
2008-12-14 13:25:48 +01:00
|
|
|
@param[in, out] Tcp4Io The Tcp4Io wrapping the TCP socket.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
Tcp4IoReset (
|
2008-12-14 13:25:48 +01:00
|
|
|
IN OUT TCP4_IO *Tcp4Io
|
2008-04-17 10:28:51 +02:00
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_TCP4_PROTOCOL *Tcp4;
|
|
|
|
|
|
|
|
Tcp4Io->CloseToken.AbortOnClose = TRUE;
|
|
|
|
Tcp4Io->IsCloseDone = FALSE;
|
|
|
|
|
|
|
|
Tcp4 = Tcp4Io->Tcp4;
|
|
|
|
Status = Tcp4->Close (Tcp4, &Tcp4Io->CloseToken);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!Tcp4Io->IsCloseDone) {
|
|
|
|
Tcp4->Poll (Tcp4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
2007-12-24 03:20:21 +01:00
|
|
|
Transmit the Packet to the other endpoint of the socket.
|
|
|
|
|
2008-12-10 07:13:51 +01:00
|
|
|
@param[in] Tcp4Io The Tcp4Io wrapping the TCP socket.
|
|
|
|
@param[in] Packet The packet to transmit.
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
@retval EFI_SUCCESS The packet is trasmitted.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
|
2008-12-12 08:03:44 +01:00
|
|
|
@retval Others Other errors as indicated.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4IoTransmit (
|
|
|
|
IN TCP4_IO *Tcp4Io,
|
|
|
|
IN NET_BUF *Packet
|
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_TCP4_TRANSMIT_DATA *TxData;
|
|
|
|
EFI_TCP4_PROTOCOL *Tcp4;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
TxData = AllocatePool (sizeof (EFI_TCP4_TRANSMIT_DATA) + (Packet->BlockOpNum - 1) * sizeof (EFI_TCP4_FRAGMENT_DATA));
|
2007-12-24 03:20:21 +01:00
|
|
|
if (TxData == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
TxData->Push = TRUE;
|
|
|
|
TxData->Urgent = FALSE;
|
|
|
|
TxData->DataLength = Packet->TotalSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Build the fragment table.
|
|
|
|
//
|
|
|
|
TxData->FragmentCount = Packet->BlockOpNum;
|
|
|
|
NetbufBuildExt (Packet, (NET_FRAGMENT *) &TxData->FragmentTable[0], &TxData->FragmentCount);
|
|
|
|
|
|
|
|
Tcp4Io->TxToken.Packet.TxData = TxData;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Trasnmit the packet.
|
|
|
|
//
|
|
|
|
Tcp4 = Tcp4Io->Tcp4;
|
|
|
|
Status = Tcp4->Transmit (Tcp4, &Tcp4Io->TxToken);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!Tcp4Io->IsTxDone) {
|
|
|
|
Tcp4->Poll (Tcp4);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcp4Io->IsTxDone = FALSE;
|
|
|
|
|
|
|
|
Status = Tcp4Io->TxToken.CompletionToken.Status;
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
|
2009-11-13 07:13:59 +01:00
|
|
|
FreePool (TxData);
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Receive data from the socket.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-12-10 07:13:51 +01:00
|
|
|
@param[in] Tcp4Io The Tcp4Io which wraps the socket to be destroyed.
|
|
|
|
@param[in] Packet The buffer to hold the data copy from the soket rx buffer.
|
|
|
|
@param[in] AsyncMode Is this receive asyncronous or not.
|
|
|
|
@param[in] Timeout The time to wait for receiving the amount of data the Packet
|
2008-04-17 10:28:51 +02:00
|
|
|
can hold.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
@retval EFI_SUCCESS The required amount of data is received from the socket.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate momery.
|
|
|
|
@retval EFI_TIMEOUT Failed to receive the required amount of data in the
|
|
|
|
specified time period.
|
2008-12-12 08:03:44 +01:00
|
|
|
@retval Others Other errors as indicated.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
Tcp4IoReceive (
|
|
|
|
IN TCP4_IO *Tcp4Io,
|
|
|
|
IN NET_BUF *Packet,
|
|
|
|
IN BOOLEAN AsyncMode,
|
|
|
|
IN EFI_EVENT Timeout
|
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_TCP4_PROTOCOL *Tcp4;
|
|
|
|
EFI_TCP4_RECEIVE_DATA RxData;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
NET_FRAGMENT *Fragment;
|
|
|
|
UINT32 FragmentCount;
|
|
|
|
UINT32 CurrentFragment;
|
|
|
|
|
|
|
|
FragmentCount = Packet->BlockOpNum;
|
2008-02-14 10:40:22 +01:00
|
|
|
Fragment = AllocatePool (FragmentCount * sizeof (NET_FRAGMENT));
|
2007-12-24 03:20:21 +01:00
|
|
|
if (Fragment == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Build the fragment table.
|
|
|
|
//
|
|
|
|
NetbufBuildExt (Packet, Fragment, &FragmentCount);
|
|
|
|
|
|
|
|
RxData.FragmentCount = 1;
|
|
|
|
Tcp4Io->RxToken.Packet.RxData = &RxData;
|
|
|
|
CurrentFragment = 0;
|
|
|
|
Tcp4 = Tcp4Io->Tcp4;
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
|
|
|
|
while (CurrentFragment < FragmentCount) {
|
|
|
|
RxData.DataLength = Fragment[CurrentFragment].Len;
|
|
|
|
RxData.FragmentTable[0].FragmentLength = Fragment[CurrentFragment].Len;
|
|
|
|
RxData.FragmentTable[0].FragmentBuffer = Fragment[CurrentFragment].Bulk;
|
|
|
|
|
|
|
|
Status = Tcp4->Receive (Tcp4, &Tcp4Io->RxToken);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!Tcp4Io->IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout)))) {
|
|
|
|
//
|
|
|
|
// Poll until some data is received or something error happens.
|
|
|
|
//
|
|
|
|
Tcp4->Poll (Tcp4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Tcp4Io->IsRxDone) {
|
|
|
|
//
|
|
|
|
// Timeout occurs, cancel the receive request.
|
|
|
|
//
|
|
|
|
Tcp4->Cancel (Tcp4, &Tcp4Io->RxToken.CompletionToken);
|
|
|
|
|
|
|
|
Status = EFI_TIMEOUT;
|
|
|
|
goto ON_EXIT;
|
|
|
|
} else {
|
|
|
|
Tcp4Io->IsRxDone = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Tcp4Io->RxToken.CompletionToken.Status)) {
|
|
|
|
Status = Tcp4Io->RxToken.CompletionToken.Status;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Fragment[CurrentFragment].Len -= RxData.FragmentTable[0].FragmentLength;
|
|
|
|
if (Fragment[CurrentFragment].Len == 0) {
|
|
|
|
CurrentFragment++;
|
|
|
|
} else {
|
|
|
|
Fragment[CurrentFragment].Bulk += RxData.FragmentTable[0].FragmentLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
2009-06-30 09:29:19 +02:00
|
|
|
Tcp4Io->RxToken.Packet.RxData = NULL;
|
2009-11-13 07:13:59 +01:00
|
|
|
FreePool (Fragment);
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|