/** @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
{\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
InitializeListHead (&Range->Link);\r
Range->Start = Start;\r
Range->End = End;\r
+ Range->Bound = End;\r
\r
return Range;\r
}\r
\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
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
} 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