]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePke/Mtftp4Dxe: Correct the total received and saved block number.
authorJiaxin Wu <Jiaxin.wu@intel.com>
Thu, 25 Oct 2018 07:31:10 +0000 (15:31 +0800)
committerJiaxin Wu <Jiaxin.wu@intel.com>
Mon, 29 Oct 2018 00:31:10 +0000 (08:31 +0800)
The block returned from Mtftp4RemoveBlockNum 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>
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c

index de304f4e707e94df9dd3b8af25476534b7a65dee..be2f8af6e44527ac138af6be58fcb6eb870477b7 100644 (file)
@@ -126,9 +126,13 @@ struct _MTFTP4_PROTOCOL {
   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
   //\r
index fedf1cde460bf1dec3f8864ff417e2aaab256a53..6960e322a5433a1d06c1f7a1bba033198441af90 100644 (file)
@@ -154,6 +154,7 @@ Mtftp4RrqSaveBlock (
   UINT16                    Block;\r
   UINT64                    Start;\r
   UINT32                    DataLen;\r
+  UINT64                    BlockCounter;\r
   BOOLEAN                   Completed;\r
 \r
   Completed = FALSE;\r
@@ -174,10 +175,10 @@ Mtftp4RrqSaveBlock (
   // Remove this block number from the file hole. If Mtftp4RemoveBlockNum\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 = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &Instance->TotalBlock);\r
+  Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &BlockCounter);\r
 \r
   if (Status == EFI_NOT_FOUND) {\r
     return EFI_SUCCESS;\r
@@ -200,7 +201,7 @@ Mtftp4RrqSaveBlock (
   }\r
 \r
   if (Token->Buffer != NULL) {\r
-     Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize);\r
+     Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize);\r
 \r
     if (Start + DataLen <= Token->BufferSize) {\r
       CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);\r
@@ -271,9 +272,9 @@ Mtftp4RrqHandleData (
   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->Master && (Expected != BlockNum)) {\r
     //\r
@@ -288,6 +289,11 @@ Mtftp4RrqHandleData (
     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\r
   // valid data packet.\r
index 71fd979b3a95111a233a5e80c744179b2ff25bf7..5e282e9c4bbaff1da68b2fba31b6eefa25b3905f 100644 (file)
@@ -158,8 +158,8 @@ Mtftp4SetLastBlockNum (
 \r
   @param  Head                  The block range list to remove from\r
   @param  Num                   The block number to remove\r
-  @param  Completed             Whether Num is the last block number\r
-  @param  TotalBlock            The continuous block number in all\r
+  @param  Completed             Whether Num is the last block number.\r
+  @param  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 @@ Mtftp4RemoveBlockNum (
   IN LIST_ENTRY             *Head,\r
   IN UINT16                 Num,\r
   IN BOOLEAN                Completed,\r
-  OUT UINT64                *TotalBlock\r
+  OUT UINT64                *BlockCounter\r
   )\r
 {\r
   MTFTP4_BLOCK_RANGE        *Range;\r
@@ -220,10 +220,10 @@ Mtftp4RemoveBlockNum (
       // 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 ((UINTN) (Range->Round -1), (UINT32) (Range->Bound + 1)) + 1;\r
+        *BlockCounter += Range->Bound +  MultU64x32 ((UINTN) (Range->Round -1), (UINT32) (Range->Bound + 1)) + 1;\r
       }\r
 \r
       if (Range->Start > Range->Bound) {\r
index 6cc2756bc8a0431ec2fd962bb3fc790c595febef..f7a6755fe8837fb61fbbe4ed7c88abd8fb4e4ad7 100644 (file)
@@ -92,8 +92,8 @@ Mtftp4SetLastBlockNum (
 \r
   @param  Head                  The block range list to remove from\r
   @param  Num                   The block number to remove\r
-  @param  Completed             Wether Num is the last block number\r
-  @param  TotalBlock            The continuous block number in all\r
+  @param  Completed             Whether Num is the last block number.\r
+  @param  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
@@ -105,7 +105,7 @@ Mtftp4RemoveBlockNum (
   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 ea309e2d6b48b5d4730b1311fff33c92b06b4d7c..ee70accbcd71f3f5b1442114dea8f50e3776ef00 100644 (file)
@@ -149,7 +149,7 @@ Mtftp4WrqHandleAck (
 {\r
   UINT16                    AckNum;\r
   INTN                      Expected;\r
-  UINT64                    TotalBlock;\r
+  UINT64                    BlockCounter;\r
 \r
   *Completed  = FALSE;\r
   AckNum      = NTOHS (Packet->Ack.Block[0]);\r
@@ -168,9 +168,9 @@ Mtftp4WrqHandleAck (
   //\r
   // Remove the acked block number, if this is the last block number,\r
   // tell the Mtftp4WrqInput 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
-  Mtftp4RemoveBlockNum (&Instance->Blocks, AckNum, *Completed,&TotalBlock);\r
+  Mtftp4RemoveBlockNum (&Instance->Blocks, AckNum, *Completed, &BlockCounter);\r
 \r
   Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);\r
 \r