]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Support.c
index 282a9c8e4942e54dc385bc5e5038556c38b8ba62..582634fb2ddddd96378f98bb5213031a61e74717 100644 (file)
@@ -3,19 +3,12 @@
 \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
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "Mtftp6Impl.h"\r
 \r
-\r
 /**\r
   Allocate a MTFTP block range, then init it to the range of [Start, End].\r
 \r
 **/\r
 MTFTP6_BLOCK_RANGE *\r
 Mtftp6AllocateRange (\r
-  IN UINT16                 Start,\r
-  IN UINT16                 End\r
+  IN UINT16  Start,\r
+  IN UINT16  End\r
   )\r
 {\r
-  MTFTP6_BLOCK_RANGE        *Range;\r
+  MTFTP6_BLOCK_RANGE  *Range;\r
 \r
   Range = AllocateZeroPool (sizeof (MTFTP6_BLOCK_RANGE));\r
 \r
@@ -40,19 +33,18 @@ Mtftp6AllocateRange (
   }\r
 \r
   InitializeListHead (&Range->Link);\r
-  Range->Start  = Start;\r
-  Range->End    = End;\r
-  Range->Bound  = End;\r
+  Range->Start = Start;\r
+  Range->End   = End;\r
+  Range->Bound = End;\r
 \r
   return Range;\r
 }\r
 \r
-\r
 /**\r
   Initialize the block range for either RRQ or WRQ. RRQ and WRQ have\r
   different requirements for Start and End. For example, during startup,\r
   WRQ initializes its whole valid block range to [0, 0xffff]. This\r
-  is bacause the server will send an ACK0 to inform the user to start the\r
+  is because the server will send an ACK0 to inform the user to start the\r
   upload. When the client receives an ACK0, it will remove 0 from the range,\r
   get the next block number, which is 1, then upload the BLOCK1. For RRQ\r
   without option negotiation, the server will directly send the BLOCK1\r
@@ -70,12 +62,12 @@ Mtftp6AllocateRange (
 **/\r
 EFI_STATUS\r
 Mtftp6InitBlockRange (\r
-  IN LIST_ENTRY             *Head,\r
-  IN UINT16                 Start,\r
-  IN UINT16                 End\r
+  IN LIST_ENTRY  *Head,\r
+  IN UINT16      Start,\r
+  IN UINT16      End\r
   )\r
 {\r
-  MTFTP6_BLOCK_RANGE        *Range;\r
+  MTFTP6_BLOCK_RANGE  *Range;\r
 \r
   Range = Mtftp6AllocateRange (Start, End);\r
 \r
@@ -87,7 +79,6 @@ Mtftp6InitBlockRange (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Get the first valid block number on the range list.\r
 \r
@@ -99,7 +90,7 @@ Mtftp6InitBlockRange (
 **/\r
 INTN\r
 Mtftp6GetNextBlockNum (\r
-  IN LIST_ENTRY              *Head\r
+  IN LIST_ENTRY  *Head\r
   )\r
 {\r
   MTFTP6_BLOCK_RANGE  *Range;\r
@@ -112,7 +103,6 @@ Mtftp6GetNextBlockNum (
   return Range->Start;\r
 }\r
 \r
-\r
 /**\r
   Set the last block number of the block range list. It\r
   removes all the blocks after the Last. MTFTP initialize the\r
@@ -126,11 +116,11 @@ Mtftp6GetNextBlockNum (
 **/\r
 VOID\r
 Mtftp6SetLastBlockNum (\r
-  IN LIST_ENTRY             *Head,\r
-  IN UINT16                 Last\r
+  IN LIST_ENTRY  *Head,\r
+  IN UINT16      Last\r
   )\r
 {\r
-  MTFTP6_BLOCK_RANGE        *Range;\r
+  MTFTP6_BLOCK_RANGE  *Range;\r
 \r
   //\r
   // Iterate from the tail to head to remove the block number\r
@@ -148,18 +138,18 @@ Mtftp6SetLastBlockNum (
     if (Range->End > Last) {\r
       Range->End = Last;\r
     }\r
-    return ;\r
+\r
+    return;\r
   }\r
 }\r
 \r
-\r
 /**\r
   Remove the block number from the block range list.\r
 \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
@@ -168,18 +158,17 @@ Mtftp6SetLastBlockNum (
 **/\r
 EFI_STATUS\r
 Mtftp6RemoveBlockNum (\r
-  IN LIST_ENTRY             *Head,\r
-  IN UINT16                 Num,\r
-  IN BOOLEAN                Completed,\r
-  OUT UINT64                *TotalBlock\r
+  IN LIST_ENTRY  *Head,\r
+  IN UINT16      Num,\r
+  IN BOOLEAN     Completed,\r
+  OUT UINT64     *BlockCounter\r
   )\r
 {\r
-  MTFTP6_BLOCK_RANGE        *Range;\r
-  MTFTP6_BLOCK_RANGE        *NewRange;\r
-  LIST_ENTRY                *Entry;\r
+  MTFTP6_BLOCK_RANGE  *Range;\r
+  MTFTP6_BLOCK_RANGE  *NewRange;\r
+  LIST_ENTRY          *Entry;\r
 \r
   NET_LIST_FOR_EACH (Entry, Head) {\r
-\r
     //\r
     // Each block represents a hole [Start, End] in the file,\r
     // skip to the first range with End >= Num\r
@@ -203,12 +192,11 @@ Mtftp6RemoveBlockNum (
     // 3. (Start < Num) && (End >= Num):\r
     //    if End == Num, only need to decrease the End by one because\r
     //    we have (Start < Num) && (Num == End), so (Start <= End - 1).\r
-    //    if (End > Num), the hold is splited into two holes, with\r
+    //    if (End > Num), the hold is split into two holes, with\r
     //    [Start, Num - 1] and [Num + 1, End].\r
     //\r
     if (Range->Start > Num) {\r
       return EFI_NOT_FOUND;\r
-\r
     } else if (Range->Start == Num) {\r
       Range->Start++;\r
 \r
@@ -220,15 +208,15 @@ 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
         Range->Start = 0;\r
-        Range->Round ++;\r
+        Range->Round++;\r
       }\r
 \r
       if ((Range->Start > Range->End) || Completed) {\r
@@ -237,12 +225,11 @@ Mtftp6RemoveBlockNum (
       }\r
 \r
       return EFI_SUCCESS;\r
-\r
     } else {\r
       if (Range->End == Num) {\r
         Range->End--;\r
       } else {\r
-        NewRange = Mtftp6AllocateRange ((UINT16) (Num + 1), (UINT16) Range->End);\r
+        NewRange = Mtftp6AllocateRange ((UINT16)(Num + 1), (UINT16)Range->End);\r
 \r
         if (NewRange == NULL) {\r
           return EFI_OUT_OF_RESOURCES;\r
@@ -259,7 +246,6 @@ Mtftp6RemoveBlockNum (
   return EFI_NOT_FOUND;\r
 }\r
 \r
-\r
 /**\r
   Configure the opened Udp6 instance until the corresponding Ip6 instance\r
   has been configured.\r
@@ -274,17 +260,17 @@ Mtftp6RemoveBlockNum (
 **/\r
 EFI_STATUS\r
 Mtftp6GetMapping (\r
-  IN UDP_IO                 *UdpIo,\r
-  IN EFI_UDP6_CONFIG_DATA   *UdpCfgData\r
+  IN UDP_IO                *UdpIo,\r
+  IN EFI_UDP6_CONFIG_DATA  *UdpCfgData\r
   )\r
 {\r
-  EFI_IP6_MODE_DATA         Ip6Mode;\r
-  EFI_UDP6_PROTOCOL         *Udp6;\r
-  EFI_STATUS                Status;\r
-  EFI_EVENT                 Event;\r
+  EFI_IP6_MODE_DATA  Ip6Mode;\r
+  EFI_UDP6_PROTOCOL  *Udp6;\r
+  EFI_STATUS         Status;\r
+  EFI_EVENT          Event;\r
 \r
-  Event  = NULL;\r
-  Udp6   = UdpIo->Protocol.Udp6;\r
+  Event = NULL;\r
+  Udp6  = UdpIo->Protocol.Udp6;\r
 \r
   //\r
   // Create a timer to check whether the Ip6 instance configured or not.\r
@@ -313,7 +299,6 @@ Mtftp6GetMapping (
   // Check the Ip6 mode data till timeout.\r
   //\r
   while (EFI_ERROR (gBS->CheckEvent (Event))) {\r
-\r
     Udp6->Poll (Udp6);\r
 \r
     Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL);\r
@@ -343,7 +328,7 @@ Mtftp6GetMapping (
         FreePool (Ip6Mode.IcmpTypeList);\r
       }\r
 \r
-      if  (Ip6Mode.IsConfigured) {\r
+      if (Ip6Mode.IsConfigured) {\r
         //\r
         // Continue to configure the Udp6 instance.\r
         //\r
@@ -363,7 +348,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   The dummy configure routine for create a new Udp6 Io.\r
 \r
@@ -376,14 +360,13 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 Mtftp6ConfigDummyUdpIo (\r
-  IN UDP_IO                 *UdpIo,\r
-  IN VOID                   *Context\r
+  IN UDP_IO  *UdpIo,\r
+  IN VOID    *Context\r
   )\r
 {\r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   The configure routine for Mtftp6 instance to transmit/receive.\r
 \r
@@ -400,16 +383,16 @@ Mtftp6ConfigDummyUdpIo (
 **/\r
 EFI_STATUS\r
 Mtftp6ConfigUdpIo (\r
-  IN UDP_IO                 *UdpIo,\r
-  IN EFI_IPv6_ADDRESS       *ServerIp,\r
-  IN UINT16                 ServerPort,\r
-  IN EFI_IPv6_ADDRESS       *LocalIp,\r
-  IN UINT16                 LocalPort\r
+  IN UDP_IO            *UdpIo,\r
+  IN EFI_IPv6_ADDRESS  *ServerIp,\r
+  IN UINT16            ServerPort,\r
+  IN EFI_IPv6_ADDRESS  *LocalIp,\r
+  IN UINT16            LocalPort\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_UDP6_PROTOCOL         *Udp6;\r
-  EFI_UDP6_CONFIG_DATA      *Udp6Cfg;\r
+  EFI_STATUS            Status;\r
+  EFI_UDP6_PROTOCOL     *Udp6;\r
+  EFI_UDP6_CONFIG_DATA  *Udp6Cfg;\r
 \r
   Udp6    = UdpIo->Protocol.Udp6;\r
   Udp6Cfg = &(UdpIo->Config.Udp6);\r
@@ -447,14 +430,12 @@ Mtftp6ConfigUdpIo (
   Status = Udp6->Configure (Udp6, Udp6Cfg);\r
 \r
   if (Status == EFI_NO_MAPPING) {\r
-\r
     return Mtftp6GetMapping (UdpIo, Udp6Cfg);\r
   }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Build and transmit the request packet for the Mtftp6 instance.\r
 \r
@@ -468,30 +449,30 @@ Mtftp6ConfigUdpIo (
 **/\r
 EFI_STATUS\r
 Mtftp6SendRequest (\r
-  IN MTFTP6_INSTANCE        *Instance,\r
-  IN UINT16                 Operation\r
+  IN MTFTP6_INSTANCE  *Instance,\r
+  IN UINT16           Operation\r
   )\r
 {\r
-  EFI_MTFTP6_PACKET         *Packet;\r
-  EFI_MTFTP6_OPTION         *Options;\r
-  EFI_MTFTP6_TOKEN          *Token;\r
-  RETURN_STATUS             Status;\r
-  NET_BUF                   *Nbuf;\r
-  UINT8                     *Mode;\r
-  UINT8                     *Cur;\r
-  UINTN                     Index;\r
-  UINT32                    BufferLength;\r
-  UINTN                     FileNameLength;\r
-  UINTN                     ModeLength;\r
-  UINTN                     OptionStrLength;\r
-  UINTN                     ValueStrLength;\r
+  EFI_MTFTP6_PACKET  *Packet;\r
+  EFI_MTFTP6_OPTION  *Options;\r
+  EFI_MTFTP6_TOKEN   *Token;\r
+  RETURN_STATUS      Status;\r
+  NET_BUF            *Nbuf;\r
+  UINT8              *Mode;\r
+  UINT8              *Cur;\r
+  UINTN              Index;\r
+  UINT32             BufferLength;\r
+  UINTN              FileNameLength;\r
+  UINTN              ModeLength;\r
+  UINTN              OptionStrLength;\r
+  UINTN              ValueStrLength;\r
 \r
   Token   = Instance->Token;\r
   Options = Token->OptionList;\r
   Mode    = Token->ModeStr;\r
 \r
   if (Mode == NULL) {\r
-    Mode = (UINT8 *) "octet";\r
+    Mode = (UINT8 *)"octet";\r
   }\r
 \r
   //\r
@@ -513,14 +494,14 @@ Mtftp6SendRequest (
   //\r
   // Compute the size of new Mtftp6 packet.\r
   //\r
-  FileNameLength = AsciiStrLen ((CHAR8 *) Token->Filename);\r
-  ModeLength     = AsciiStrLen ((CHAR8 *) Mode);\r
-  BufferLength   = (UINT32) FileNameLength + (UINT32) ModeLength + 4;\r
+  FileNameLength = AsciiStrLen ((CHAR8 *)Token->Filename);\r
+  ModeLength     = AsciiStrLen ((CHAR8 *)Mode);\r
+  BufferLength   = (UINT32)FileNameLength + (UINT32)ModeLength + 4;\r
 \r
   for (Index = 0; Index < Token->OptionCount; Index++) {\r
-    OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);\r
-    ValueStrLength  = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);\r
-    BufferLength   += (UINT32) OptionStrLength + (UINT32) ValueStrLength + 2;\r
+    OptionStrLength = AsciiStrLen ((CHAR8 *)Options[Index].OptionStr);\r
+    ValueStrLength  = AsciiStrLen ((CHAR8 *)Options[Index].ValueStr);\r
+    BufferLength   += (UINT32)OptionStrLength + (UINT32)ValueStrLength + 2;\r
   }\r
 \r
   //\r
@@ -533,39 +514,38 @@ Mtftp6SendRequest (
   //\r
   // Copy the opcode, filename and mode into packet.\r
   //\r
-  Packet         = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, BufferLength, FALSE);\r
+  Packet = (EFI_MTFTP6_PACKET *)NetbufAllocSpace (Nbuf, BufferLength, FALSE);\r
   ASSERT (Packet != NULL);\r
 \r
   Packet->OpCode = HTONS (Operation);\r
   BufferLength  -= sizeof (Packet->OpCode);\r
 \r
-  Cur            = Packet->Rrq.Filename;\r
-  Status         = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Token->Filename);\r
+  Cur    = Packet->Rrq.Filename;\r
+  Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Token->Filename);\r
   ASSERT_EFI_ERROR (Status);\r
-  BufferLength  -= (UINT32) (FileNameLength + 1);\r
-  Cur           += FileNameLength + 1;\r
-  Status         = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Mode);\r
+  BufferLength -= (UINT32)(FileNameLength + 1);\r
+  Cur          += FileNameLength + 1;\r
+  Status        = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Mode);\r
   ASSERT_EFI_ERROR (Status);\r
-  BufferLength  -= (UINT32) (ModeLength + 1);\r
-  Cur           += ModeLength + 1;\r
+  BufferLength -= (UINT32)(ModeLength + 1);\r
+  Cur          += ModeLength + 1;\r
 \r
   //\r
   // Copy all the extension options into the packet.\r
   //\r
   for (Index = 0; Index < Token->OptionCount; ++Index) {\r
-    OptionStrLength = AsciiStrLen ((CHAR8 *) Options[Index].OptionStr);\r
-    ValueStrLength  = AsciiStrLen ((CHAR8 *) Options[Index].ValueStr);\r
+    OptionStrLength = AsciiStrLen ((CHAR8 *)Options[Index].OptionStr);\r
+    ValueStrLength  = AsciiStrLen ((CHAR8 *)Options[Index].ValueStr);\r
 \r
-    Status          = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].OptionStr);\r
+    Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Options[Index].OptionStr);\r
     ASSERT_EFI_ERROR (Status);\r
-    BufferLength   -= (UINT32) (OptionStrLength + 1);\r
-    Cur            += OptionStrLength + 1;\r
+    BufferLength -= (UINT32)(OptionStrLength + 1);\r
+    Cur          += OptionStrLength + 1;\r
 \r
-    Status          = AsciiStrCpyS ((CHAR8 *) Cur, BufferLength, (CHAR8 *) Options[Index].ValueStr);\r
+    Status = AsciiStrCpyS ((CHAR8 *)Cur, BufferLength, (CHAR8 *)Options[Index].ValueStr);\r
     ASSERT_EFI_ERROR (Status);\r
-    BufferLength   -= (UINT32) (ValueStrLength + 1);\r
-    Cur            += ValueStrLength + 1;\r
-\r
+    BufferLength -= (UINT32)(ValueStrLength + 1);\r
+    Cur          += ValueStrLength + 1;\r
   }\r
 \r
   //\r
@@ -581,7 +561,6 @@ Mtftp6SendRequest (
   return Mtftp6TransmitPacket (Instance, Nbuf);\r
 }\r
 \r
-\r
 /**\r
   Build and send an error packet.\r
 \r
@@ -596,26 +575,26 @@ Mtftp6SendRequest (
 **/\r
 EFI_STATUS\r
 Mtftp6SendError (\r
-  IN MTFTP6_INSTANCE        *Instance,\r
-  IN UINT16                 ErrCode,\r
-  IN UINT8*                 ErrInfo\r
+  IN MTFTP6_INSTANCE  *Instance,\r
+  IN UINT16           ErrCode,\r
+  IN UINT8            *ErrInfo\r
   )\r
 {\r
-  NET_BUF                   *Nbuf;\r
-  EFI_MTFTP6_PACKET         *TftpError;\r
-  UINT32                    Len;\r
+  NET_BUF            *Nbuf;\r
+  EFI_MTFTP6_PACKET  *TftpError;\r
+  UINT32             Len;\r
 \r
   //\r
   // Allocate a packet then copy the data.\r
   //\r
-  Len  = (UINT32) (AsciiStrLen ((CHAR8 *) ErrInfo) + sizeof (EFI_MTFTP6_ERROR_HEADER));\r
+  Len  = (UINT32)(AsciiStrLen ((CHAR8 *)ErrInfo) + sizeof (EFI_MTFTP6_ERROR_HEADER));\r
   Nbuf = NetbufAlloc (Len);\r
 \r
   if (Nbuf == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  TftpError = (EFI_MTFTP6_PACKET *) NetbufAllocSpace (Nbuf, Len, FALSE);\r
+  TftpError = (EFI_MTFTP6_PACKET *)NetbufAllocSpace (Nbuf, Len, FALSE);\r
 \r
   if (TftpError == NULL) {\r
     NetbufFree (Nbuf);\r
@@ -625,7 +604,7 @@ Mtftp6SendError (
   TftpError->OpCode          = HTONS (EFI_MTFTP6_OPCODE_ERROR);\r
   TftpError->Error.ErrorCode = HTONS (ErrCode);\r
 \r
-  AsciiStrCpyS ((CHAR8 *) TftpError->Error.ErrorMessage, AsciiStrLen ((CHAR8 *) ErrInfo) + 1 , (CHAR8 *) ErrInfo);\r
+  AsciiStrCpyS ((CHAR8 *)TftpError->Error.ErrorMessage, AsciiStrLen ((CHAR8 *)ErrInfo) + 1, (CHAR8 *)ErrInfo);\r
 \r
   //\r
   // Save the packet buf for retransmit\r
@@ -640,7 +619,6 @@ Mtftp6SendError (
   return Mtftp6TransmitPacket (Instance, Nbuf);\r
 }\r
 \r
-\r
 /**\r
   The callback function called when the packet is transmitted.\r
 \r
@@ -653,17 +631,16 @@ Mtftp6SendError (
 VOID\r
 EFIAPI\r
 Mtftp6OnPacketSent (\r
-  IN NET_BUF                   *Packet,\r
-  IN UDP_END_POINT             *UdpEpt,\r
-  IN EFI_STATUS                IoStatus,\r
-  IN VOID                      *Context\r
+  IN NET_BUF        *Packet,\r
+  IN UDP_END_POINT  *UdpEpt,\r
+  IN EFI_STATUS     IoStatus,\r
+  IN VOID           *Context\r
   )\r
 {\r
   NetbufFree (Packet);\r
-  *(BOOLEAN *) Context = TRUE;\r
+  *(BOOLEAN *)Context = TRUE;\r
 }\r
 \r
-\r
 /**\r
   Send the packet for the Mtftp6 instance.\r
 \r
@@ -676,18 +653,18 @@ Mtftp6OnPacketSent (
 **/\r
 EFI_STATUS\r
 Mtftp6TransmitPacket (\r
-  IN MTFTP6_INSTANCE        *Instance,\r
-  IN NET_BUF                *Packet\r
+  IN MTFTP6_INSTANCE  *Instance,\r
+  IN NET_BUF          *Packet\r
   )\r
 {\r
-  EFI_UDP6_PROTOCOL         *Udp6;\r
-  EFI_UDP6_CONFIG_DATA      Udp6CfgData;\r
-  EFI_STATUS                Status;\r
-  UINT16                    *Temp;\r
-  UINT16                    Value;\r
-  UINT16                    OpCode;\r
-\r
-  ZeroMem (&Udp6CfgData, sizeof(EFI_UDP6_CONFIG_DATA));\r
+  EFI_UDP6_PROTOCOL     *Udp6;\r
+  EFI_UDP6_CONFIG_DATA  Udp6CfgData;\r
+  EFI_STATUS            Status;\r
+  UINT16                *Temp;\r
+  UINT16                Value;\r
+  UINT16                OpCode;\r
+\r
+  ZeroMem (&Udp6CfgData, sizeof (EFI_UDP6_CONFIG_DATA));\r
   Udp6 = Instance->UdpIo->Protocol.Udp6;\r
 \r
   //\r
@@ -695,13 +672,13 @@ Mtftp6TransmitPacket (
   //\r
   Instance->PacketToLive = Instance->IsMaster ? Instance->Timeout : (Instance->Timeout * 2);\r
 \r
-  Temp   = (UINT16 *) NetbufGetByte (Packet, 0, NULL);\r
+  Temp = (UINT16 *)NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Temp != NULL);\r
 \r
   Value  = *Temp;\r
   OpCode = NTOHS (Value);\r
 \r
-  if (OpCode == EFI_MTFTP6_OPCODE_RRQ || OpCode == EFI_MTFTP6_OPCODE_DIR || OpCode == EFI_MTFTP6_OPCODE_WRQ) {\r
+  if ((OpCode == EFI_MTFTP6_OPCODE_RRQ) || (OpCode == EFI_MTFTP6_OPCODE_DIR) || (OpCode == EFI_MTFTP6_OPCODE_WRQ)) {\r
     //\r
     // For the Rrq, Dir, Wrq requests of the operation, configure the Udp6Io as\r
     // (serverip, 69, localip, localport) to send.\r
@@ -792,7 +769,6 @@ Mtftp6TransmitPacket (
     }\r
 \r
     if (Udp6CfgData.RemotePort != Instance->ServerDataPort) {\r
-\r
       Status = Udp6->Configure (Udp6, NULL);\r
 \r
       if (EFI_ERROR (Status)) {\r
@@ -844,7 +820,6 @@ Mtftp6TransmitPacket (
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Check packet for GetInfo callback routine.\r
 \r
@@ -862,32 +837,32 @@ Mtftp6TransmitPacket (
 EFI_STATUS\r
 EFIAPI\r
 Mtftp6CheckPacket (\r
-  IN EFI_MTFTP6_PROTOCOL    *This,\r
-  IN EFI_MTFTP6_TOKEN       *Token,\r
-  IN UINT16                 PacketLen,\r
-  IN EFI_MTFTP6_PACKET      *Packet\r
+  IN EFI_MTFTP6_PROTOCOL  *This,\r
+  IN EFI_MTFTP6_TOKEN     *Token,\r
+  IN UINT16               PacketLen,\r
+  IN EFI_MTFTP6_PACKET    *Packet\r
   )\r
 {\r
-  MTFTP6_GETINFO_CONTEXT    *Context;\r
-  UINT16                    OpCode;\r
+  MTFTP6_GETINFO_CONTEXT  *Context;\r
+  UINT16                  OpCode;\r
 \r
-  Context = (MTFTP6_GETINFO_CONTEXT *) Token->Context;\r
+  Context = (MTFTP6_GETINFO_CONTEXT *)Token->Context;\r
   OpCode  = NTOHS (Packet->OpCode);\r
 \r
   //\r
   // Set the GetInfo's return status according to the OpCode.\r
   //\r
   switch (OpCode) {\r
-  case EFI_MTFTP6_OPCODE_ERROR:\r
-    Context->Status = EFI_TFTP_ERROR;\r
-    break;\r
+    case EFI_MTFTP6_OPCODE_ERROR:\r
+      Context->Status = EFI_TFTP_ERROR;\r
+      break;\r
 \r
-  case EFI_MTFTP6_OPCODE_OACK:\r
-    Context->Status = EFI_SUCCESS;\r
-    break;\r
+    case EFI_MTFTP6_OPCODE_OACK:\r
+      Context->Status = EFI_SUCCESS;\r
+      break;\r
 \r
-  default:\r
-    Context->Status = EFI_PROTOCOL_ERROR;\r
+    default:\r
+      Context->Status = EFI_PROTOCOL_ERROR;\r
   }\r
 \r
   //\r
@@ -907,7 +882,6 @@ Mtftp6CheckPacket (
   return EFI_ABORTED;\r
 }\r
 \r
-\r
 /**\r
   Clean up the current Mtftp6 operation.\r
 \r
@@ -917,13 +891,13 @@ Mtftp6CheckPacket (
 **/\r
 VOID\r
 Mtftp6OperationClean (\r
-  IN MTFTP6_INSTANCE        *Instance,\r
-  IN EFI_STATUS             Result\r
+  IN MTFTP6_INSTANCE  *Instance,\r
+  IN EFI_STATUS       Result\r
   )\r
 {\r
-  LIST_ENTRY                *Entry;\r
-  LIST_ENTRY                *Next;\r
-  MTFTP6_BLOCK_RANGE        *Block;\r
+  LIST_ENTRY          *Entry;\r
+  LIST_ENTRY          *Next;\r
+  MTFTP6_BLOCK_RANGE  *Block;\r
 \r
   //\r
   // Clean up the current token and event.\r
@@ -933,6 +907,7 @@ Mtftp6OperationClean (
     if (Instance->Token->Event != NULL) {\r
       gBS->SignalEvent (Instance->Token->Event);\r
     }\r
+\r
     Instance->Token = NULL;\r
   }\r
 \r
@@ -979,6 +954,10 @@ Mtftp6OperationClean (
   Instance->ServerDataPort = 0;\r
   Instance->McastPort      = 0;\r
   Instance->BlkSize        = 0;\r
+  Instance->Operation      = 0;\r
+  Instance->WindowSize     = 1;\r
+  Instance->TotalBlock     = 0;\r
+  Instance->AckedBlock     = 0;\r
   Instance->LastBlk        = 0;\r
   Instance->PacketToLive   = 0;\r
   Instance->MaxRetry       = 0;\r
@@ -987,13 +966,12 @@ Mtftp6OperationClean (
   Instance->IsMaster       = TRUE;\r
 }\r
 \r
-\r
 /**\r
   Start the Mtftp6 instance to perform the operation, such as read file,\r
   write file, and read directory.\r
 \r
   @param[in]  This                   The MTFTP session.\r
-  @param[in]  Token                  The token than encapsues the user's request.\r
+  @param[in]  Token                  The token than encapsules the user's request.\r
   @param[in]  OpCode                 The operation to perform.\r
 \r
   @retval EFI_INVALID_PARAMETER  Some of the parameters are invalid.\r
@@ -1004,37 +982,39 @@ Mtftp6OperationClean (
 **/\r
 EFI_STATUS\r
 Mtftp6OperationStart (\r
-  IN EFI_MTFTP6_PROTOCOL    *This,\r
-  IN EFI_MTFTP6_TOKEN       *Token,\r
-  IN UINT16                 OpCode\r
+  IN EFI_MTFTP6_PROTOCOL  *This,\r
+  IN EFI_MTFTP6_TOKEN     *Token,\r
+  IN UINT16               OpCode\r
   )\r
 {\r
-  MTFTP6_INSTANCE           *Instance;\r
-  EFI_STATUS                Status;\r
-\r
-  if (This == NULL ||\r
-      Token == NULL ||\r
-      Token->Filename == NULL ||\r
-      (Token->OptionCount != 0 && Token->OptionList == NULL) ||\r
-      (Token->OverrideData != NULL && !NetIp6IsValidUnicast (&Token->OverrideData->ServerIp))\r
-      ) {\r
+  MTFTP6_INSTANCE  *Instance;\r
+  EFI_STATUS       Status;\r
+\r
+  if ((This == NULL) ||\r
+      (Token == NULL) ||\r
+      (Token->Filename == NULL) ||\r
+      ((Token->OptionCount != 0) && (Token->OptionList == NULL)) ||\r
+      ((Token->OverrideData != NULL) && !NetIp6IsValidUnicast (&Token->OverrideData->ServerIp))\r
+      )\r
+  {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   //\r
   // At least define one method to collect the data for download.\r
   //\r
-  if ((OpCode == EFI_MTFTP6_OPCODE_RRQ || OpCode == EFI_MTFTP6_OPCODE_DIR) &&\r
-      Token->Buffer == NULL &&\r
-      Token->CheckPacket == NULL\r
-      ) {\r
+  if (((OpCode == EFI_MTFTP6_OPCODE_RRQ) || (OpCode == EFI_MTFTP6_OPCODE_DIR)) &&\r
+      (Token->Buffer == NULL) &&\r
+      (Token->CheckPacket == NULL)\r
+      )\r
+  {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   //\r
   // At least define one method to provide the data for upload.\r
   //\r
-  if (OpCode == EFI_MTFTP6_OPCODE_WRQ && Token->Buffer == NULL && Token->PacketNeeded == NULL) {\r
+  if ((OpCode == EFI_MTFTP6_OPCODE_WRQ) && (Token->Buffer == NULL) && (Token->PacketNeeded == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1051,15 +1031,17 @@ Mtftp6OperationStart (
   Status           = EFI_SUCCESS;\r
   Instance->OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
+  Instance->Operation = OpCode;\r
+\r
   //\r
   // Parse the extension options in the request packet.\r
   //\r
   if (Token->OptionCount != 0) {\r
-\r
     Status = Mtftp6ParseExtensionOption (\r
                Token->OptionList,\r
                Token->OptionCount,\r
                TRUE,\r
+               Instance->Operation,\r
                &Instance->ExtInfo\r
                );\r
 \r
@@ -1071,12 +1053,12 @@ Mtftp6OperationStart (
   //\r
   // Initialize runtime data from config data or override data.\r
   //\r
-  Instance->Token           = Token;\r
-  Instance->ServerCmdPort   = Instance->Config->InitialServerPort;\r
-  Instance->ServerDataPort  = 0;\r
-  Instance->MaxRetry        = Instance->Config->TryCount;\r
-  Instance->Timeout         = Instance->Config->TimeoutValue;\r
-  Instance->IsMaster        = TRUE;\r
+  Instance->Token          = Token;\r
+  Instance->ServerCmdPort  = Instance->Config->InitialServerPort;\r
+  Instance->ServerDataPort = 0;\r
+  Instance->MaxRetry       = Instance->Config->TryCount;\r
+  Instance->Timeout        = Instance->Config->TimeoutValue;\r
+  Instance->IsMaster       = TRUE;\r
 \r
   CopyMem (\r
     &Instance->ServerIp,\r
@@ -1102,12 +1084,19 @@ Mtftp6OperationStart (
   if (Instance->ServerCmdPort == 0) {\r
     Instance->ServerCmdPort = MTFTP6_DEFAULT_SERVER_CMD_PORT;\r
   }\r
+\r
   if (Instance->BlkSize == 0) {\r
     Instance->BlkSize = MTFTP6_DEFAULT_BLK_SIZE;\r
   }\r
+\r
+  if (Instance->WindowSize == 0) {\r
+    Instance->WindowSize = MTFTP6_DEFAULT_WINDOWSIZE;\r
+  }\r
+\r
   if (Instance->MaxRetry == 0) {\r
     Instance->MaxRetry = MTFTP6_DEFAULT_MAX_RETRY;\r
   }\r
+\r
   if (Instance->Timeout == 0) {\r
     Instance->Timeout = MTFTP6_DEFAULT_TIMEOUT;\r
   }\r
@@ -1118,21 +1107,21 @@ Mtftp6OperationStart (
   // Switch the routines by the operation code.\r
   //\r
   switch (OpCode) {\r
-  case EFI_MTFTP6_OPCODE_RRQ:\r
-    Status = Mtftp6RrqStart (Instance, OpCode);\r
-    break;\r
+    case EFI_MTFTP6_OPCODE_RRQ:\r
+      Status = Mtftp6RrqStart (Instance, OpCode);\r
+      break;\r
 \r
-  case EFI_MTFTP6_OPCODE_DIR:\r
-    Status = Mtftp6RrqStart (Instance, OpCode);\r
-    break;\r
+    case EFI_MTFTP6_OPCODE_DIR:\r
+      Status = Mtftp6RrqStart (Instance, OpCode);\r
+      break;\r
 \r
-  case EFI_MTFTP6_OPCODE_WRQ:\r
-    Status = Mtftp6WrqStart (Instance, OpCode);\r
-    break;\r
+    case EFI_MTFTP6_OPCODE_WRQ:\r
+      Status = Mtftp6WrqStart (Instance, OpCode);\r
+      break;\r
 \r
-  default:\r
-    Status = EFI_DEVICE_ERROR;\r
-    goto ON_ERROR;\r
+    default:\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_ERROR;\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -1148,6 +1137,7 @@ Mtftp6OperationStart (
     while (Token->Status == EFI_NOT_READY) {\r
       This->Poll (This);\r
     }\r
+\r
     return Token->Status;\r
   }\r
 \r
@@ -1161,7 +1151,6 @@ ON_ERROR:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   The timer ticking routine for the Mtftp6 instance.\r
 \r
@@ -1172,25 +1161,24 @@ ON_ERROR:
 VOID\r
 EFIAPI\r
 Mtftp6OnTimerTick (\r
-  IN EFI_EVENT              Event,\r
-  IN VOID                   *Context\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
   )\r
 {\r
-  MTFTP6_SERVICE            *Service;\r
-  MTFTP6_INSTANCE           *Instance;\r
-  LIST_ENTRY                *Entry;\r
-  LIST_ENTRY                *Next;\r
-  EFI_MTFTP6_TOKEN          *Token;\r
-  EFI_STATUS                Status;\r
+  MTFTP6_SERVICE    *Service;\r
+  MTFTP6_INSTANCE   *Instance;\r
+  LIST_ENTRY        *Entry;\r
+  LIST_ENTRY        *Next;\r
+  EFI_MTFTP6_TOKEN  *Token;\r
+  EFI_STATUS        Status;\r
 \r
-  Service = (MTFTP6_SERVICE *) Context;\r
+  Service = (MTFTP6_SERVICE *)Context;\r
 \r
   //\r
   // Iterate through all the children of the Mtftp service instance. Time\r
   // out the packet. If maximum retries reached, clean the session up.\r
   //\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &Service->Children) {\r
-\r
     Instance = NET_LIST_USER_STRUCT (Entry, MTFTP6_INSTANCE, Link);\r
 \r
     if (Instance->Token == NULL) {\r
@@ -1213,17 +1201,17 @@ Mtftp6OnTimerTick (
 \r
       if (EFI_ERROR (Status)) {\r
         Mtftp6SendError (\r
-           Instance,\r
-           EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,\r
-           (UINT8 *) "User aborted the transfer in time out"\r
-           );\r
+          Instance,\r
+          EFI_MTFTP6_ERRORCODE_REQUEST_DENIED,\r
+          (UINT8 *)"User aborted the transfer in time out"\r
+          );\r
         Mtftp6OperationClean (Instance, EFI_ABORTED);\r
         continue;\r
       }\r
     }\r
 \r
     //\r
-    // Retransmit the packet if haven't reach the maxmium retry count,\r
+    // Retransmit the packet if haven't reach the maximum retry count,\r
     // otherwise exit the transfer.\r
     //\r
     if (Instance->CurRetry < Instance->MaxRetry) {\r