NetworkPkg/Mtftp6Dxe: Correct the total received and saved block number.

The block returned from Mtftp6RemoveBlockNum is not the total received and
saved block number if it works in passive (Slave) mode.

The issue was exposed by the EMS test.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
This commit is contained in:
Jiaxin Wu 2018-10-25 15:16:13 +08:00
parent 9202304c18
commit 2f6693c283
5 changed files with 28 additions and 18 deletions

View File

@ -83,9 +83,13 @@ struct _MTFTP6_INSTANCE {
UINT16 WindowSize; UINT16 WindowSize;
// //
// Record the total received block number and the already acked block number. // Record the total received and saved block number.
// //
UINT64 TotalBlock; UINT64 TotalBlock;
//
// Record the acked block number.
//
UINT64 AckedBlock; UINT64 AckedBlock;
EFI_IPv6_ADDRESS ServerIp; EFI_IPv6_ADDRESS ServerIp;

View File

@ -102,6 +102,7 @@ Mtftp6RrqSaveBlock (
UINT16 Block; UINT16 Block;
UINT64 Start; UINT64 Start;
UINT32 DataLen; UINT32 DataLen;
UINT64 BlockCounter;
BOOLEAN Completed; BOOLEAN Completed;
Completed = FALSE; Completed = FALSE;
@ -122,10 +123,10 @@ Mtftp6RrqSaveBlock (
// Remove this block number from the file hole. If Mtftp6RemoveBlockNum // Remove this block number from the file hole. If Mtftp6RemoveBlockNum
// returns EFI_NOT_FOUND, the block has been saved, don't save it again. // returns EFI_NOT_FOUND, the block has been saved, don't save it again.
// Note that : For bigger files, allowing the block counter to roll over // Note that : For bigger files, allowing the block counter to roll over
// to accept transfers of unlimited size. So TotalBlock is memorised as // to accept transfers of unlimited size. So BlockCounter is memorised as
// continuous block counter. // continuous block counter.
// //
Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock); Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &BlockCounter);
if (Status == EFI_NOT_FOUND) { if (Status == EFI_NOT_FOUND) {
return EFI_SUCCESS; return EFI_SUCCESS;
@ -161,7 +162,7 @@ Mtftp6RrqSaveBlock (
if (Token->Buffer != NULL) { if (Token->Buffer != NULL) {
Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize); Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize);
if (Start + DataLen <= Token->BufferSize) { if (Start + DataLen <= Token->BufferSize) {
CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen); CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);
// //
@ -238,9 +239,9 @@ Mtftp6RrqHandleData (
ASSERT (Expected >= 0); ASSERT (Expected >= 0);
// //
// If we are active and received an unexpected packet, transmit // If we are active (Master) and received an unexpected packet, transmit
// the ACK for the block we received, then restart receiving the // the ACK for the block we received, then restart receiving the
// expected one. If we are passive, save the block. // expected one. If we are passive (Slave), save the block.
// //
if (Instance->IsMaster && (Expected != BlockNum)) { if (Instance->IsMaster && (Expected != BlockNum)) {
// //
@ -262,6 +263,11 @@ Mtftp6RrqHandleData (
return Status; return Status;
} }
//
// Record the total received and saved block number.
//
Instance->TotalBlock ++;
// //
// Reset the passive client's timer whenever it received a valid data packet. // Reset the passive client's timer whenever it received a valid data packet.
// //

View File

@ -158,8 +158,8 @@ Mtftp6SetLastBlockNum (
@param[in] Head The block range list to remove from. @param[in] Head The block range list to remove from.
@param[in] Num The block number to remove. @param[in] Num The block number to remove.
@param[in] Completed Whether Num is the last block number @param[in] Completed Whether Num is the last block number.
@param[out] TotalBlock The continuous block number in all @param[out] BlockCounter The continuous block counter instead of the value after roll-over.
@retval EFI_NOT_FOUND The block number isn't in the block range list. @retval EFI_NOT_FOUND The block number isn't in the block range list.
@retval EFI_SUCCESS The block number has been removed from the list. @retval EFI_SUCCESS The block number has been removed from the list.
@ -171,7 +171,7 @@ Mtftp6RemoveBlockNum (
IN LIST_ENTRY *Head, IN LIST_ENTRY *Head,
IN UINT16 Num, IN UINT16 Num,
IN BOOLEAN Completed, IN BOOLEAN Completed,
OUT UINT64 *TotalBlock OUT UINT64 *BlockCounter
) )
{ {
MTFTP6_BLOCK_RANGE *Range; MTFTP6_BLOCK_RANGE *Range;
@ -220,10 +220,10 @@ Mtftp6RemoveBlockNum (
// wrap to zero, because this is the simplest to implement. Here we choose // wrap to zero, because this is the simplest to implement. Here we choose
// this solution. // this solution.
// //
*TotalBlock = Num; *BlockCounter = Num;
if (Range->Round > 0) { if (Range->Round > 0) {
*TotalBlock += Range->Bound + MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1; *BlockCounter += Range->Bound + MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1;
} }
if (Range->Start > Range->Bound) { if (Range->Start > Range->Bound) {

View File

@ -1,7 +1,7 @@
/** @file /** @file
Mtftp6 support functions declaration. Mtftp6 support functions declaration.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -96,8 +96,8 @@ Mtftp6SetLastBlockNum (
@param[in] Head The block range list to remove from. @param[in] Head The block range list to remove from.
@param[in] Num The block number to remove. @param[in] Num The block number to remove.
@param[in] Completed Whether Num is the last block number @param[in] Completed Whether Num is the last block number.
@param[out] TotalBlock The continuous block number in all @param[out] BlockCounter The continuous block counter instead of the value after roll-over.
@retval EFI_NOT_FOUND The block number isn't in the block range list. @retval EFI_NOT_FOUND The block number isn't in the block range list.
@retval EFI_SUCCESS The block number has been removed from the list. @retval EFI_SUCCESS The block number has been removed from the list.
@ -109,7 +109,7 @@ Mtftp6RemoveBlockNum (
IN LIST_ENTRY *Head, IN LIST_ENTRY *Head,
IN UINT16 Num, IN UINT16 Num,
IN BOOLEAN Completed, IN BOOLEAN Completed,
OUT UINT64 *TotalBlock OUT UINT64 *BlockCounter
); );

View File

@ -153,7 +153,7 @@ Mtftp6WrqHandleAck (
{ {
UINT16 AckNum; UINT16 AckNum;
INTN Expected; INTN Expected;
UINT64 TotalBlock; UINT64 BlockCounter;
*IsCompleted = FALSE; *IsCompleted = FALSE;
AckNum = NTOHS (Packet->Ack.Block[0]); AckNum = NTOHS (Packet->Ack.Block[0]);
@ -172,9 +172,9 @@ Mtftp6WrqHandleAck (
// //
// Remove the acked block number, if this is the last block number, // Remove the acked block number, if this is the last block number,
// tell the Mtftp6WrqInput to finish the transfer. This is the last // tell the Mtftp6WrqInput to finish the transfer. This is the last
// block number if the block range are empty.. // block number if the block range are empty.
// //
Mtftp6RemoveBlockNum (&Instance->BlkList, AckNum, *IsCompleted, &TotalBlock); Mtftp6RemoveBlockNum (&Instance->BlkList, AckNum, *IsCompleted, &BlockCounter);
Expected = Mtftp6GetNextBlockNum (&Instance->BlkList); Expected = Mtftp6GetNextBlockNum (&Instance->BlkList);