]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/Mtftp6Dxe: Correct the total received and saved block number.
authorJiaxin Wu <Jiaxin.wu@intel.com>
Thu, 25 Oct 2018 07:16:13 +0000 (15:16 +0800)
committerJiaxin Wu <Jiaxin.wu@intel.com>
Mon, 29 Oct 2018 00:31:18 +0000 (08:31 +0800)
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>
NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h
NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c
NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
NetworkPkg/Mtftp6Dxe/Mtftp6Support.h
NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c

index cf1b6abacce2c1ba6bb5e233a07422fea9ab998b..57f4cb6f5dace71b71efa9bf8697d7e52430f2b5 100644 (file)
@@ -83,9 +83,13 @@ struct _MTFTP6_INSTANCE {
   UINT16                        WindowSize;\r
 \r
   //\r
-  // Record the total received block number and the already acked block number.\r
+  // Record the total received and saved block number.\r
   //\r
   UINT64                        TotalBlock;\r
+  \r
+  //\r
+  // Record the acked block number.\r
+  //\r
   UINT64                        AckedBlock;\r
 \r
   EFI_IPv6_ADDRESS              ServerIp;\r
index 1f685b2bfe7360d1ed01da48070c42800764abb0..d60b26f6524d4933c8fdfc5b5bc4271f9c27e9b5 100644 (file)
@@ -102,6 +102,7 @@ Mtftp6RrqSaveBlock (
   UINT16                    Block;\r
   UINT64                    Start;\r
   UINT32                    DataLen;\r
+  UINT64                    BlockCounter;\r
   BOOLEAN                   Completed;\r
 \r
   Completed = FALSE;\r
@@ -122,10 +123,10 @@ Mtftp6RrqSaveBlock (
   // Remove this block number from the file hole. If Mtftp6RemoveBlockNum\r
   // returns EFI_NOT_FOUND, the block has been saved, don't save it again.\r
   // Note that : For bigger files, allowing the block counter to roll over\r
-  // to accept transfers of unlimited size. So TotalBlock is memorised as\r
+  // to accept transfers of unlimited size. So BlockCounter is memorised as\r
   // continuous block counter.\r
   //\r
-  Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock);\r
+  Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &BlockCounter);\r
 \r
   if (Status == EFI_NOT_FOUND) {\r
     return EFI_SUCCESS;\r
@@ -161,7 +162,7 @@ Mtftp6RrqSaveBlock (
 \r
   if (Token->Buffer != NULL) {\r
 \r
-    Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize);\r
+    Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize);\r
     if (Start + DataLen <= Token->BufferSize) {\r
       CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);\r
       //\r
@@ -238,9 +239,9 @@ Mtftp6RrqHandleData (
   ASSERT (Expected >= 0);\r
 \r
   //\r
-  // If we are active and received an unexpected packet, transmit\r
+  // If we are active (Master) and received an unexpected packet, transmit\r
   // the ACK for the block we received, then restart receiving the\r
-  // expected one. If we are passive, save the block.\r
+  // expected one. If we are passive (Slave), save the block.\r
   //\r
   if (Instance->IsMaster && (Expected != BlockNum)) {\r
     //\r
@@ -262,6 +263,11 @@ Mtftp6RrqHandleData (
     return Status;\r
   }\r
 \r
+  //\r
+  // Record the total received and saved block number.\r
+  //\r
+  Instance->TotalBlock ++;\r
+\r
   //\r
   // Reset the passive client's timer whenever it received a valid data packet.\r
   //\r
index 275272b89e949e8aeb1f0788178c5e0dd63afdf6..f03216afb7cd9324623559505757452b1800b985 100644 (file)
@@ -158,8 +158,8 @@ Mtftp6SetLastBlockNum (
 \r
   @param[in]  Head                   The block range list to remove from.\r
   @param[in]  Num                    The block number to remove.\r
-  @param[in]  Completed              Whether Num is the last block number\r
-  @param[out] TotalBlock             The continuous block number in all\r
+  @param[in]  Completed              Whether Num is the last block number.\r
+  @param[out] BlockCounter           The continuous block counter instead of the value after roll-over.\r
 \r
   @retval EFI_NOT_FOUND          The block number isn't in the block range list.\r
   @retval EFI_SUCCESS            The block number has been removed from the list.\r
@@ -171,7 +171,7 @@ Mtftp6RemoveBlockNum (
   IN LIST_ENTRY             *Head,\r
   IN UINT16                 Num,\r
   IN BOOLEAN                Completed,\r
-  OUT UINT64                *TotalBlock\r
+  OUT UINT64                *BlockCounter\r
   )\r
 {\r
   MTFTP6_BLOCK_RANGE        *Range;\r
@@ -220,10 +220,10 @@ Mtftp6RemoveBlockNum (
       // wrap to zero, because this is the simplest to implement. Here we choose\r
       // this solution.\r
       //\r
-      *TotalBlock  = Num;\r
+      *BlockCounter  = Num;\r
 \r
       if (Range->Round > 0) {\r
-        *TotalBlock += Range->Bound +  MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1;\r
+        *BlockCounter += Range->Bound +  MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1;\r
       }\r
 \r
       if (Range->Start > Range->Bound) {\r
index 37f03fe29809eb684f27fd9e99d418e90f476f56..319109133229685959c1c8a18cbfd14b5db50be3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mtftp6 support functions declaration.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -96,8 +96,8 @@ Mtftp6SetLastBlockNum (
 \r
   @param[in]  Head                   The block range list to remove from.\r
   @param[in]  Num                    The block number to remove.\r
-  @param[in]  Completed              Whether Num is the last block number\r
-  @param[out] TotalBlock             The continuous block number in all\r
+  @param[in]  Completed              Whether Num is the last block number.\r
+  @param[out] BlockCounter           The continuous block counter instead of the value after roll-over.\r
 \r
   @retval EFI_NOT_FOUND          The block number isn't in the block range list.\r
   @retval EFI_SUCCESS            The block number has been removed from the list.\r
@@ -109,7 +109,7 @@ Mtftp6RemoveBlockNum (
   IN LIST_ENTRY             *Head,\r
   IN UINT16                 Num,\r
   IN BOOLEAN                Completed,\r
-  OUT UINT64                *TotalBlock\r
+  OUT UINT64                *BlockCounter\r
   );\r
 \r
 \r
index 055fbe6d1b821fced0fc5bc36f94b4128431bbe7..604b1f970f7c6dd63430fa828759ee7c4a228a93 100644 (file)
@@ -153,7 +153,7 @@ Mtftp6WrqHandleAck (
 {\r
   UINT16                    AckNum;\r
   INTN                      Expected;\r
-  UINT64                    TotalBlock;\r
+  UINT64                    BlockCounter;\r
 \r
   *IsCompleted = FALSE;\r
   AckNum       = NTOHS (Packet->Ack.Block[0]);\r
@@ -172,9 +172,9 @@ Mtftp6WrqHandleAck (
   //\r
   // Remove the acked block number, if this is the last block number,\r
   // tell the Mtftp6WrqInput to finish the transfer. This is the last\r
-  // block number if the block range are empty..\r
+  // block number if the block range are empty.\r
   //\r
-  Mtftp6RemoveBlockNum (&Instance->BlkList, AckNum, *IsCompleted, &TotalBlock);\r
+  Mtftp6RemoveBlockNum (&Instance->BlkList, AckNum, *IsCompleted, &BlockCounter);\r
 \r
   Expected = Mtftp6GetNextBlockNum (&Instance->BlkList);\r
 \r