mirror of https://github.com/acidanthera/audk.git
MdeModulePke/Mtftp4Dxe: Support windowsize in read request operation.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=886 This patch is to support the TFTP windowsize option described in RFC 7440. The feature allows the client and server to negotiate a window size of consecutive blocks to send as an alternative for replacing the single-block lockstep schema. Currently, the windowsize for write request operation is not supported since there is no real use cases. Cc: Ye Ting <ting.ye@intel.com> Cc: Fu Siyuan <siyuan.fu@intel.com> Cc: Shao Ming <ming.shao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com> Tested-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com>
This commit is contained in:
parent
6a147d6dae
commit
6c047cfab1
|
@ -80,6 +80,9 @@ Mtftp4CleanOperation (
|
|||
Instance->Operation = 0;
|
||||
|
||||
Instance->BlkSize = MTFTP4_DEFAULT_BLKSIZE;
|
||||
Instance->WindowSize = 1;
|
||||
Instance->TotalBlock = 0;
|
||||
Instance->AckedBlock = 0;
|
||||
Instance->LastBlock = 0;
|
||||
Instance->ServerIp = 0;
|
||||
Instance->ListeningPort = 0;
|
||||
|
@ -428,6 +431,7 @@ Mtftp4Start (
|
|||
Token->OptionList,
|
||||
Token->OptionCount,
|
||||
TRUE,
|
||||
Instance->Operation,
|
||||
&Instance->RequestOption
|
||||
);
|
||||
|
||||
|
@ -443,6 +447,7 @@ Mtftp4Start (
|
|||
Config = &Instance->Config;
|
||||
Instance->Token = Token;
|
||||
Instance->BlkSize = MTFTP4_DEFAULT_BLKSIZE;
|
||||
Instance->WindowSize = MTFTP4_DEFAULT_WINDOWSIZE;
|
||||
|
||||
CopyMem (&Instance->ServerIp, &Config->ServerIp, sizeof (IP4_ADDR));
|
||||
Instance->ServerIp = NTOHL (Instance->ServerIp);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
RFC2347 - TFTP Option Extension
|
||||
RFC2348 - TFTP Blocksize Option
|
||||
RFC2349 - TFTP Timeout Interval and Transfer Size Options
|
||||
RFC7440 - TFTP Windowsize Option
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
|
@ -56,6 +57,7 @@ typedef struct _MTFTP4_PROTOCOL MTFTP4_PROTOCOL;
|
|||
#define MTFTP4_DEFAULT_TIMEOUT 3
|
||||
#define MTFTP4_DEFAULT_RETRY 5
|
||||
#define MTFTP4_DEFAULT_BLKSIZE 512
|
||||
#define MTFTP4_DEFAULT_WINDOWSIZE 1
|
||||
#define MTFTP4_TIME_TO_GETMAP 5
|
||||
|
||||
#define MTFTP4_STATE_UNCONFIGED 0
|
||||
|
@ -121,6 +123,14 @@ struct _MTFTP4_PROTOCOL {
|
|||
UINT16 LastBlock;
|
||||
LIST_ENTRY Blocks;
|
||||
|
||||
UINT16 WindowSize;
|
||||
|
||||
//
|
||||
// Record the total received block number and the already acked block number.
|
||||
//
|
||||
UINT64 TotalBlock;
|
||||
UINT64 AckedBlock;
|
||||
|
||||
//
|
||||
// The server's communication end point: IP and two ports. one for
|
||||
// initial request, one for its selected port.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
Routines to process MTFTP4 options.
|
||||
|
||||
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2018, 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
|
||||
|
@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
|
||||
CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] = {
|
||||
"blksize",
|
||||
"windowsize",
|
||||
"timeout",
|
||||
"tsize",
|
||||
"multicast"
|
||||
|
@ -400,6 +401,7 @@ Mtftp4ExtractMcast (
|
|||
@param Count The number of options in the Options
|
||||
@param Request Whether this is a request or OACK. The format of
|
||||
multicast is different according to this setting.
|
||||
@param Operation The current performed operation.
|
||||
@param MtftpOption The MTFTP4_OPTION for easy access.
|
||||
|
||||
@retval EFI_INVALID_PARAMETER The option is mal-formated
|
||||
|
@ -412,6 +414,7 @@ Mtftp4ParseOption (
|
|||
IN EFI_MTFTP4_OPTION *Options,
|
||||
IN UINT32 Count,
|
||||
IN BOOLEAN Request,
|
||||
IN UINT16 Operation,
|
||||
OUT MTFTP4_OPTION *MtftpOption
|
||||
)
|
||||
{
|
||||
|
@ -481,6 +484,22 @@ Mtftp4ParseOption (
|
|||
|
||||
MtftpOption->Exist |= MTFTP4_MCAST_EXIST;
|
||||
|
||||
} else if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "windowsize")) {
|
||||
if (Operation == EFI_MTFTP4_OPCODE_WRQ) {
|
||||
//
|
||||
// Currently, windowsize is not supported in the write operation.
|
||||
//
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Value = NetStringToU32 (This->ValueStr);
|
||||
|
||||
if (Value < 1) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
MtftpOption->WindowSize = (UINT16) Value;
|
||||
MtftpOption->Exist |= MTFTP4_WINDOWSIZE_EXIST;
|
||||
} else if (Request) {
|
||||
//
|
||||
// Ignore the unsupported option if it is a reply, and return
|
||||
|
@ -500,6 +519,7 @@ Mtftp4ParseOption (
|
|||
|
||||
@param Packet The OACK packet to parse
|
||||
@param PacketLen The length of the packet
|
||||
@param Operation The current performed operation.
|
||||
@param MtftpOption The MTFTP_OPTION for easy access.
|
||||
|
||||
@retval EFI_INVALID_PARAMETER The packet option is mal-formated
|
||||
|
@ -511,6 +531,7 @@ EFI_STATUS
|
|||
Mtftp4ParseOptionOack (
|
||||
IN EFI_MTFTP4_PACKET *Packet,
|
||||
IN UINT32 PacketLen,
|
||||
IN UINT16 Operation,
|
||||
OUT MTFTP4_OPTION *MtftpOption
|
||||
)
|
||||
{
|
||||
|
@ -527,7 +548,7 @@ Mtftp4ParseOptionOack (
|
|||
}
|
||||
ASSERT (OptionList != NULL);
|
||||
|
||||
Status = Mtftp4ParseOption (OptionList, Count, FALSE, MtftpOption);
|
||||
Status = Mtftp4ParseOption (OptionList, Count, FALSE, Operation, MtftpOption);
|
||||
|
||||
FreePool (OptionList);
|
||||
return Status;
|
||||
|
|
|
@ -16,7 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#ifndef __EFI_MTFTP4_OPTION_H__
|
||||
#define __EFI_MTFTP4_OPTION_H__
|
||||
|
||||
#define MTFTP4_SUPPORTED_OPTIONS 4
|
||||
#define MTFTP4_SUPPORTED_OPTIONS 5
|
||||
#define MTFTP4_OPCODE_LEN 2
|
||||
#define MTFTP4_ERRCODE_LEN 2
|
||||
#define MTFTP4_BLKNO_LEN 2
|
||||
|
@ -26,9 +26,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#define MTFTP4_TIMEOUT_EXIST 0x02
|
||||
#define MTFTP4_TSIZE_EXIST 0x04
|
||||
#define MTFTP4_MCAST_EXIST 0x08
|
||||
#define MTFTP4_WINDOWSIZE_EXIST 0x10
|
||||
|
||||
typedef struct {
|
||||
UINT16 BlkSize;
|
||||
UINT16 WindowSize;
|
||||
UINT8 Timeout;
|
||||
UINT32 Tsize;
|
||||
IP4_ADDR McastIp;
|
||||
|
@ -71,6 +73,7 @@ Mtftp4ExtractOptions (
|
|||
@param Count The number of options in the Options
|
||||
@param Request Whether this is a request or OACK. The format of
|
||||
multicast is different according to this setting.
|
||||
@param Operation The current performed operation.
|
||||
@param MtftpOption The MTFTP4_OPTION for easy access.
|
||||
|
||||
@retval EFI_INVALID_PARAMETER The option is mal-formated
|
||||
|
@ -83,6 +86,7 @@ Mtftp4ParseOption (
|
|||
IN EFI_MTFTP4_OPTION *Options,
|
||||
IN UINT32 Count,
|
||||
IN BOOLEAN Request,
|
||||
IN UINT16 Operation,
|
||||
OUT MTFTP4_OPTION *MtftpOption
|
||||
);
|
||||
|
||||
|
@ -92,6 +96,7 @@ Mtftp4ParseOption (
|
|||
|
||||
@param Packet The OACK packet to parse
|
||||
@param PacketLen The length of the packet
|
||||
@param Operation The current performed operation.
|
||||
@param MtftpOption The MTFTP_OPTION for easy access.
|
||||
|
||||
@retval EFI_INVALID_PARAMETER The packet option is mal-formated
|
||||
|
@ -103,6 +108,7 @@ EFI_STATUS
|
|||
Mtftp4ParseOptionOack (
|
||||
IN EFI_MTFTP4_PACKET *Packet,
|
||||
IN UINT32 PacketLen,
|
||||
IN UINT16 Operation,
|
||||
OUT MTFTP4_OPTION *MtftpOption
|
||||
);
|
||||
|
||||
|
|
|
@ -99,6 +99,9 @@ Mtftp4RrqSendAck (
|
|||
{
|
||||
EFI_MTFTP4_PACKET *Ack;
|
||||
NET_BUF *Packet;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
Packet = NetbufAlloc (sizeof (EFI_MTFTP4_ACK_HEADER));
|
||||
if (Packet == NULL) {
|
||||
|
@ -115,7 +118,12 @@ Mtftp4RrqSendAck (
|
|||
Ack->Ack.OpCode = HTONS (EFI_MTFTP4_OPCODE_ACK);
|
||||
Ack->Ack.Block[0] = HTONS (BlkNo);
|
||||
|
||||
return Mtftp4SendPacket (Instance, Packet);
|
||||
Status = Mtftp4SendPacket (Instance, Packet);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Instance->AckedBlock = Instance->TotalBlock;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,7 +154,6 @@ Mtftp4RrqSaveBlock (
|
|||
UINT16 Block;
|
||||
UINT64 Start;
|
||||
UINT32 DataLen;
|
||||
UINT64 TotalBlock;
|
||||
BOOLEAN Completed;
|
||||
|
||||
Completed = FALSE;
|
||||
|
@ -158,7 +165,7 @@ Mtftp4RrqSaveBlock (
|
|||
// This is the last block, save the block no
|
||||
//
|
||||
if (DataLen < Instance->BlkSize) {
|
||||
Completed = TRUE;
|
||||
Completed = TRUE;
|
||||
Instance->LastBlock = Block;
|
||||
Mtftp4SetLastBlockNum (&Instance->Blocks, Block);
|
||||
}
|
||||
|
@ -170,7 +177,7 @@ Mtftp4RrqSaveBlock (
|
|||
// to accept transfers of unlimited size. So TotalBlock is memorised as
|
||||
// continuous block counter.
|
||||
//
|
||||
Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &TotalBlock);
|
||||
Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &Instance->TotalBlock);
|
||||
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
return EFI_SUCCESS;
|
||||
|
@ -193,7 +200,7 @@ Mtftp4RrqSaveBlock (
|
|||
}
|
||||
|
||||
if (Token->Buffer != NULL) {
|
||||
Start = MultU64x32 (TotalBlock - 1, Instance->BlkSize);
|
||||
Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize);
|
||||
|
||||
if (Start + DataLen <= Token->BufferSize) {
|
||||
CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);
|
||||
|
@ -257,19 +264,22 @@ Mtftp4RrqHandleData (
|
|||
INTN Expected;
|
||||
|
||||
*Completed = FALSE;
|
||||
Status = EFI_SUCCESS;
|
||||
BlockNum = NTOHS (Packet->Data.Block);
|
||||
Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
|
||||
|
||||
ASSERT (Expected >= 0);
|
||||
|
||||
//
|
||||
// If we are active and received an unexpected packet, retransmit
|
||||
// the last ACK then restart receiving. If we are passive, save
|
||||
// the block.
|
||||
// If we are active and received an unexpected packet, transmit
|
||||
// the ACK for the block we received, then restart receiving the
|
||||
// expected one. If we are passive, save the block.
|
||||
//
|
||||
if (Instance->Master && (Expected != BlockNum)) {
|
||||
Mtftp4Retransmit (Instance);
|
||||
return EFI_SUCCESS;
|
||||
//
|
||||
// If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).
|
||||
//
|
||||
return Mtftp4RrqSendAck (Instance, (UINT16) (Expected - 1));
|
||||
}
|
||||
|
||||
Status = Mtftp4RrqSaveBlock (Instance, Packet, Len);
|
||||
|
@ -309,10 +319,13 @@ Mtftp4RrqHandleData (
|
|||
BlockNum = (UINT16) (Expected - 1);
|
||||
}
|
||||
|
||||
Mtftp4RrqSendAck (Instance, BlockNum);
|
||||
if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {
|
||||
Status = Mtftp4RrqSendAck (Instance, BlockNum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -349,11 +362,13 @@ Mtftp4RrqOackValid (
|
|||
}
|
||||
|
||||
//
|
||||
// Server can only specify a smaller block size to be used and
|
||||
// Server can only specify a smaller block size and window size to be used and
|
||||
// return the timeout matches that requested.
|
||||
//
|
||||
if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) != 0)&& (Reply->BlkSize > Request->BlkSize)) ||
|
||||
(((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))) {
|
||||
(((Reply->Exist & MTFTP4_WINDOWSIZE_EXIST) != 0)&& (Reply->WindowSize > Request->WindowSize)) ||
|
||||
(((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))
|
||||
) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -507,7 +522,7 @@ Mtftp4RrqHandleOack (
|
|||
//
|
||||
ZeroMem (&Reply, sizeof (MTFTP4_OPTION));
|
||||
|
||||
Status = Mtftp4ParseOptionOack (Packet, Len, &Reply);
|
||||
Status = Mtftp4ParseOptionOack (Packet, Len, Instance->Operation, &Reply);
|
||||
|
||||
if (EFI_ERROR (Status) ||
|
||||
!Mtftp4RrqOackValid (Instance, &Reply, &Instance->RequestOption)) {
|
||||
|
@ -529,7 +544,7 @@ Mtftp4RrqHandleOack (
|
|||
|
||||
//
|
||||
// Save the multicast info. Always update the Master, only update the
|
||||
// multicast IP address, block size, timeoute at the first time. If IP
|
||||
// multicast IP address, block size, window size, timeoute at the first time. If IP
|
||||
// address is updated, create a UDP child to receive the multicast.
|
||||
//
|
||||
Instance->Master = Reply.Master;
|
||||
|
@ -599,6 +614,10 @@ Mtftp4RrqHandleOack (
|
|||
Instance->BlkSize = Reply.BlkSize;
|
||||
}
|
||||
|
||||
if (Reply.WindowSize != 0) {
|
||||
Instance->WindowSize = Reply.WindowSize;
|
||||
}
|
||||
|
||||
if (Reply.Timeout != 0) {
|
||||
Instance->Timeout = Reply.Timeout;
|
||||
}
|
||||
|
@ -611,6 +630,10 @@ Mtftp4RrqHandleOack (
|
|||
Instance->BlkSize = Reply.BlkSize;
|
||||
}
|
||||
|
||||
if (Reply.WindowSize != 0) {
|
||||
Instance->WindowSize = Reply.WindowSize;
|
||||
}
|
||||
|
||||
if (Reply.Timeout != 0) {
|
||||
Instance->Timeout = Reply.Timeout;
|
||||
}
|
||||
|
|
|
@ -220,15 +220,15 @@ Mtftp4RemoveBlockNum (
|
|||
// wrap to zero, because this is the simplest to implement. Here we choose
|
||||
// this solution.
|
||||
//
|
||||
*TotalBlock = Num;
|
||||
*TotalBlock = Num;
|
||||
|
||||
if (Range->Round > 0) {
|
||||
*TotalBlock += Range->Bound + MultU64x32 ((UINTN) (Range->Round -1), (UINT32) (Range->Bound + 1)) + 1;
|
||||
}
|
||||
*TotalBlock += Range->Bound + MultU64x32 ((UINTN) (Range->Round -1), (UINT32) (Range->Bound + 1)) + 1;
|
||||
}
|
||||
|
||||
if (Range->Start > Range->Bound) {
|
||||
Range->Start = 0;
|
||||
Range->Round ++;
|
||||
Range->Round ++;
|
||||
}
|
||||
|
||||
if ((Range->Start > Range->End) || Completed) {
|
||||
|
|
|
@ -173,19 +173,6 @@ Mtftp4SendError (
|
|||
IN UINT8 *ErrInfo
|
||||
);
|
||||
|
||||
/**
|
||||
Retransmit the last packet for the instance.
|
||||
|
||||
@param Instance The Mtftp instance
|
||||
|
||||
@retval EFI_SUCCESS The last packet is retransmitted.
|
||||
@retval Others Failed to retransmit.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
Mtftp4Retransmit (
|
||||
IN MTFTP4_PROTOCOL *Instance
|
||||
);
|
||||
|
||||
/**
|
||||
The timer ticking function in TPL_NOTIFY level for the Mtftp service instance.
|
||||
|
|
|
@ -286,7 +286,7 @@ Mtftp4WrqHandleOack (
|
|||
// Parse and validate the options from server
|
||||
//
|
||||
ZeroMem (&Reply, sizeof (MTFTP4_OPTION));
|
||||
Status = Mtftp4ParseOptionOack (Packet, Len, &Reply);
|
||||
Status = Mtftp4ParseOptionOack (Packet, Len, Instance->Operation, &Reply);
|
||||
|
||||
if (EFI_ERROR (Status) || !Mtftp4WrqOackValid (&Reply, &Instance->RequestOption)) {
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue