]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c
Fixed a bug in Mtftp4: to allow the block number to roll over to accept transfers...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Support.c
index 7414bf226dcc3b154376e45f7ea57037ec3038b3..4dcdf827ea57deb3b287574590f495a6e9586f45 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for Mtftp.\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -32,7 +32,7 @@ Mtftp4AllocateRange (
 {\r
   MTFTP4_BLOCK_RANGE        *Range;\r
 \r
-  Range = AllocatePool (sizeof (MTFTP4_BLOCK_RANGE));\r
+  Range = AllocateZeroPool (sizeof (MTFTP4_BLOCK_RANGE));\r
 \r
   if (Range == NULL) {\r
     return NULL;\r
@@ -41,6 +41,7 @@ Mtftp4AllocateRange (
   InitializeListHead (&Range->Link);\r
   Range->Start  = Start;\r
   Range->End    = End;\r
+  Range->Bound  = End;\r
 \r
   return Range;\r
 }\r
@@ -157,6 +158,7 @@ Mtftp4SetLastBlockNum (
 \r
   @param  Head                  The block range list to remove from\r
   @param  Num                   The block number to remove\r
+  @param  TotalBlock            The continuous block number in all \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
@@ -166,7 +168,8 @@ Mtftp4SetLastBlockNum (
 EFI_STATUS\r
 Mtftp4RemoveBlockNum (\r
   IN LIST_ENTRY             *Head,\r
-  IN UINT16                 Num\r
+  IN UINT16                 Num,\r
+  OUT UINT64                *TotalBlock\r
   )\r
 {\r
   MTFTP4_BLOCK_RANGE        *Range;\r
@@ -207,6 +210,25 @@ Mtftp4RemoveBlockNum (
     } else if (Range->Start == Num) {\r
       Range->Start++;\r
 \r
+      //\r
+      // Note that: RFC 1350 does not mention block counter roll-over, \r
+      // but several TFTP hosts implement the roll-over be able to accept \r
+      // transfers of unlimited size. There is no consensus, however, whether \r
+      // the counter should wrap around to zero or to one. Many implementations \r
+      // wrap to zero, because this is the simplest to implement. Here we choose \r
+      // this solution.\r
+      //\r
+         *TotalBlock  = Num;\r
+         \r
+      if (Range->Round > 0) {\r
+           *TotalBlock += Range->Bound +  MultU64x32 (Range->Round -1, (UINT32)(Range->Bound + 1)) + 1;\r
+         }\r
+\r
+      if (Range->Start > Range->Bound) {\r
+                 Range->Start = 0;\r
+                 Range->Round ++;\r
+      }\r
+\r
       if (Range->Start > Range->End) {\r
         RemoveEntryList (&Range->Link);\r
         FreePool (Range);\r