diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h b/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h index cf1b6abacc..57f4cb6f5d 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h @@ -83,9 +83,13 @@ struct _MTFTP6_INSTANCE { UINT16 WindowSize; // - // Record the total received block number and the already acked block number. + // Record the total received and saved block number. // UINT64 TotalBlock; + + // + // Record the acked block number. + // UINT64 AckedBlock; EFI_IPv6_ADDRESS ServerIp; diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c index 1f685b2bfe..d60b26f652 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c @@ -102,6 +102,7 @@ Mtftp6RrqSaveBlock ( UINT16 Block; UINT64 Start; UINT32 DataLen; + UINT64 BlockCounter; BOOLEAN Completed; Completed = FALSE; @@ -122,10 +123,10 @@ Mtftp6RrqSaveBlock ( // Remove this block number from the file hole. If Mtftp6RemoveBlockNum // 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 - // 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. // - Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock); + Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &BlockCounter); if (Status == EFI_NOT_FOUND) { return EFI_SUCCESS; @@ -161,7 +162,7 @@ Mtftp6RrqSaveBlock ( if (Token->Buffer != NULL) { - Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize); + Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize); if (Start + DataLen <= Token->BufferSize) { CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen); // @@ -238,9 +239,9 @@ Mtftp6RrqHandleData ( 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 - // expected one. If we are passive, save the block. + // expected one. If we are passive (Slave), save the block. // if (Instance->IsMaster && (Expected != BlockNum)) { // @@ -262,6 +263,11 @@ Mtftp6RrqHandleData ( 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. // diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c index 275272b89e..f03216afb7 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c @@ -158,8 +158,8 @@ Mtftp6SetLastBlockNum ( @param[in] Head The block range list to remove from. @param[in] Num The block number to remove. - @param[in] Completed Whether Num is the last block number - @param[out] TotalBlock The continuous block number in all + @param[in] Completed Whether Num is the last block number. + @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_SUCCESS The block number has been removed from the list. @@ -171,7 +171,7 @@ Mtftp6RemoveBlockNum ( IN LIST_ENTRY *Head, IN UINT16 Num, IN BOOLEAN Completed, - OUT UINT64 *TotalBlock + OUT UINT64 *BlockCounter ) { MTFTP6_BLOCK_RANGE *Range; @@ -220,10 +220,10 @@ Mtftp6RemoveBlockNum ( // wrap to zero, because this is the simplest to implement. Here we choose // this solution. // - *TotalBlock = Num; + *BlockCounter = Num; 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) { diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.h b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.h index 37f03fe298..3191091332 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.h +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.h @@ -1,7 +1,7 @@ /** @file Mtftp6 support functions declaration. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, 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 @@ -96,8 +96,8 @@ Mtftp6SetLastBlockNum ( @param[in] Head The block range list to remove from. @param[in] Num The block number to remove. - @param[in] Completed Whether Num is the last block number - @param[out] TotalBlock The continuous block number in all + @param[in] Completed Whether Num is the last block number. + @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_SUCCESS The block number has been removed from the list. @@ -109,7 +109,7 @@ Mtftp6RemoveBlockNum ( IN LIST_ENTRY *Head, IN UINT16 Num, IN BOOLEAN Completed, - OUT UINT64 *TotalBlock + OUT UINT64 *BlockCounter ); diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c index 055fbe6d1b..604b1f970f 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c @@ -153,7 +153,7 @@ Mtftp6WrqHandleAck ( { UINT16 AckNum; INTN Expected; - UINT64 TotalBlock; + UINT64 BlockCounter; *IsCompleted = FALSE; AckNum = NTOHS (Packet->Ack.Block[0]); @@ -172,9 +172,9 @@ Mtftp6WrqHandleAck ( // // Remove the acked block number, if this is the last block number, // 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);