NetworkPkg/Mtftp6Dxe: 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:
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Mtftp6 Rrq process functions implementation.
|
||||
|
||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 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
|
||||
@@ -35,6 +35,9 @@ Mtftp6RrqSendAck (
|
||||
{
|
||||
EFI_MTFTP6_PACKET *Ack;
|
||||
NET_BUF *Packet;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// Allocate net buffer to create ack packet.
|
||||
@@ -61,7 +64,12 @@ Mtftp6RrqSendAck (
|
||||
Instance->CurRetry = 0;
|
||||
Instance->LastPacket = Packet;
|
||||
|
||||
return Mtftp6TransmitPacket (Instance, Packet);
|
||||
Status = Mtftp6TransmitPacket (Instance, Packet);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Instance->AckedBlock = Instance->TotalBlock;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +102,6 @@ Mtftp6RrqSaveBlock (
|
||||
UINT16 Block;
|
||||
UINT64 Start;
|
||||
UINT32 DataLen;
|
||||
UINT64 TotalBlock;
|
||||
BOOLEAN Completed;
|
||||
|
||||
Completed = FALSE;
|
||||
@@ -118,7 +125,7 @@ Mtftp6RrqSaveBlock (
|
||||
// to accept transfers of unlimited size. So TotalBlock is memorised as
|
||||
// continuous block counter.
|
||||
//
|
||||
Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &TotalBlock);
|
||||
Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock);
|
||||
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
return EFI_SUCCESS;
|
||||
@@ -154,7 +161,7 @@ Mtftp6RrqSaveBlock (
|
||||
|
||||
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);
|
||||
//
|
||||
@@ -224,15 +231,16 @@ Mtftp6RrqHandleData (
|
||||
INTN Expected;
|
||||
|
||||
*IsCompleted = FALSE;
|
||||
Status = EFI_SUCCESS;
|
||||
BlockNum = NTOHS (Packet->Data.Block);
|
||||
Expected = Mtftp6GetNextBlockNum (&Instance->BlkList);
|
||||
|
||||
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->IsMaster && (Expected != BlockNum)) {
|
||||
//
|
||||
@@ -242,8 +250,10 @@ Mtftp6RrqHandleData (
|
||||
NetbufFree (*UdpPacket);
|
||||
*UdpPacket = NULL;
|
||||
|
||||
Mtftp6TransmitPacket (Instance, Instance->LastPacket);
|
||||
return EFI_SUCCESS;
|
||||
//
|
||||
// If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).
|
||||
//
|
||||
return Mtftp6RrqSendAck (Instance, (UINT16) (Expected - 1));
|
||||
}
|
||||
|
||||
Status = Mtftp6RrqSaveBlock (Instance, Packet, Len, UdpPacket);
|
||||
@@ -288,10 +298,12 @@ Mtftp6RrqHandleData (
|
||||
NetbufFree (*UdpPacket);
|
||||
*UdpPacket = NULL;
|
||||
|
||||
Mtftp6RrqSendAck (Instance, BlockNum);
|
||||
if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {
|
||||
Status = Mtftp6RrqSendAck (Instance, BlockNum);
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
@@ -326,12 +338,13 @@ Mtftp6RrqOackValid (
|
||||
}
|
||||
|
||||
//
|
||||
// Server can only specify a smaller block size to be used and
|
||||
// Server can only specify a smaller block size and windowsize to be used and
|
||||
// return the timeout matches that requested.
|
||||
//
|
||||
if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||
|
||||
(((ReplyInfo->BitMap & MTFTP6_OPT_WINDOWSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||
|
||||
(((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))
|
||||
) {
|
||||
) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -485,7 +498,7 @@ Mtftp6RrqHandleOack (
|
||||
//
|
||||
// Parse the extensive options in the packet.
|
||||
//
|
||||
Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, &ExtInfo);
|
||||
Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, Instance->Operation, &ExtInfo);
|
||||
|
||||
if (EFI_ERROR (Status) || !Mtftp6RrqOackValid (Instance, &ExtInfo, &Instance->ExtInfo)) {
|
||||
//
|
||||
@@ -515,7 +528,7 @@ Mtftp6RrqHandleOack (
|
||||
|
||||
//
|
||||
// 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->IsMaster = ExtInfo.IsMaster;
|
||||
@@ -612,6 +625,10 @@ Mtftp6RrqHandleOack (
|
||||
Instance->BlkSize = ExtInfo.BlkSize;
|
||||
}
|
||||
|
||||
if (ExtInfo.WindowSize != 0) {
|
||||
Instance->WindowSize = ExtInfo.WindowSize;
|
||||
}
|
||||
|
||||
if (ExtInfo.Timeout != 0) {
|
||||
Instance->Timeout = ExtInfo.Timeout;
|
||||
}
|
||||
@@ -625,6 +642,10 @@ Mtftp6RrqHandleOack (
|
||||
Instance->BlkSize = ExtInfo.BlkSize;
|
||||
}
|
||||
|
||||
if (ExtInfo.WindowSize != 0) {
|
||||
Instance->WindowSize = ExtInfo.WindowSize;
|
||||
}
|
||||
|
||||
if (ExtInfo.Timeout != 0) {
|
||||
Instance->Timeout = ExtInfo.Timeout;
|
||||
}
|
||||
|
Reference in New Issue
Block a user