]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c
NetworkPkg/Mtftp6Dxe: Support windowsize in read request operation.
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Rrq.c
index 2aadef076cf0d55fe81a8ea71b7171d794e67be3..1f685b2bfe7360d1ed01da48070c42800764abb0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mtftp6 Rrq process functions implementation.\r
 \r
-  Copyright (c) 2009 - 2014, 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
@@ -35,6 +35,9 @@ Mtftp6RrqSendAck (
 {\r
   EFI_MTFTP6_PACKET         *Ack;\r
   NET_BUF                   *Packet;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = EFI_SUCCESS;\r
 \r
   //\r
   // Allocate net buffer to create ack packet.\r
@@ -61,7 +64,12 @@ Mtftp6RrqSendAck (
   Instance->CurRetry = 0;\r
   Instance->LastPacket = Packet;\r
 \r
-  return Mtftp6TransmitPacket (Instance, Packet);\r
+  Status = Mtftp6TransmitPacket (Instance, Packet);\r
+  if (!EFI_ERROR (Status)) {\r
+    Instance->AckedBlock = Instance->TotalBlock;\r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -94,7 +102,6 @@ Mtftp6RrqSaveBlock (
   UINT16                    Block;\r
   UINT64                    Start;\r
   UINT32                    DataLen;\r
-  UINT64                    TotalBlock;\r
   BOOLEAN                   Completed;\r
 \r
   Completed = FALSE;\r
@@ -118,7 +125,7 @@ Mtftp6RrqSaveBlock (
   // to accept transfers of unlimited size. So TotalBlock is memorised as\r
   // continuous block counter.\r
   //\r
-  Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &TotalBlock);\r
+  Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock);\r
 \r
   if (Status == EFI_NOT_FOUND) {\r
     return EFI_SUCCESS;\r
@@ -154,7 +161,7 @@ Mtftp6RrqSaveBlock (
 \r
   if (Token->Buffer != NULL) {\r
 \r
-    Start = MultU64x32 (TotalBlock - 1, Instance->BlkSize);\r
+    Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize);\r
     if (Start + DataLen <= Token->BufferSize) {\r
       CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);\r
       //\r
@@ -224,15 +231,16 @@ Mtftp6RrqHandleData (
   INTN                      Expected;\r
 \r
   *IsCompleted = FALSE;\r
+  Status       = EFI_SUCCESS;\r
   BlockNum     = NTOHS (Packet->Data.Block);\r
   Expected     = Mtftp6GetNextBlockNum (&Instance->BlkList);\r
 \r
   ASSERT (Expected >= 0);\r
 \r
   //\r
-  // If we are active and received an unexpected packet, retransmit\r
-  // the last ACK then restart receiving. If we are passive, save\r
-  // the block.\r
+  // If we are active 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
   //\r
   if (Instance->IsMaster && (Expected != BlockNum)) {\r
     //\r
@@ -242,8 +250,10 @@ Mtftp6RrqHandleData (
     NetbufFree (*UdpPacket);\r
     *UdpPacket = NULL;\r
 \r
-    Mtftp6TransmitPacket (Instance, Instance->LastPacket);\r
-    return EFI_SUCCESS;\r
+    //\r
+    // If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).\r
+    //\r
+    return Mtftp6RrqSendAck (Instance,  (UINT16) (Expected - 1));\r
   }\r
 \r
   Status = Mtftp6RrqSaveBlock (Instance, Packet, Len, UdpPacket);\r
@@ -288,10 +298,12 @@ Mtftp6RrqHandleData (
     NetbufFree (*UdpPacket);\r
     *UdpPacket = NULL;\r
 \r
-    Mtftp6RrqSendAck (Instance, BlockNum);\r
+    if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {\r
+      Status = Mtftp6RrqSendAck (Instance, BlockNum);\r
+    }\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 \r
@@ -326,12 +338,13 @@ Mtftp6RrqOackValid (
   }\r
 \r
   //\r
-  // Server can only specify a smaller block size to be used and\r
+  // Server can only specify a smaller block size and windowsize to be used and\r
   // return the timeout matches that requested.\r
   //\r
   if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||\r
+      (((ReplyInfo->BitMap & MTFTP6_OPT_WINDOWSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||\r
       (((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))\r
-      ) {\r
+     ) {\r
     return FALSE;\r
   }\r
 \r
@@ -485,7 +498,7 @@ Mtftp6RrqHandleOack (
   //\r
   // Parse the extensive options in the packet.\r
   //\r
-  Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, &ExtInfo);\r
+  Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, Instance->Operation, &ExtInfo);\r
 \r
   if (EFI_ERROR (Status) || !Mtftp6RrqOackValid (Instance, &ExtInfo, &Instance->ExtInfo)) {\r
     //\r
@@ -515,7 +528,7 @@ Mtftp6RrqHandleOack (
 \r
     //\r
     // Save the multicast info. Always update the Master, only update the\r
-    // multicast IP address, block size, timeoute at the first time. If IP\r
+    // multicast IP address, block size, window size, timeoute at the first time. If IP\r
     // address is updated, create a UDP child to receive the multicast.\r
     //\r
     Instance->IsMaster = ExtInfo.IsMaster;\r
@@ -612,6 +625,10 @@ Mtftp6RrqHandleOack (
         Instance->BlkSize = ExtInfo.BlkSize;\r
       }\r
 \r
+      if (ExtInfo.WindowSize != 0) {\r
+        Instance->WindowSize = ExtInfo.WindowSize;\r
+      }\r
+\r
       if (ExtInfo.Timeout != 0) {\r
         Instance->Timeout = ExtInfo.Timeout;\r
       }\r
@@ -625,6 +642,10 @@ Mtftp6RrqHandleOack (
       Instance->BlkSize = ExtInfo.BlkSize;\r
     }\r
 \r
+    if (ExtInfo.WindowSize != 0) {\r
+      Instance->WindowSize = ExtInfo.WindowSize;\r
+    }\r
+\r
     if (ExtInfo.Timeout != 0) {\r
       Instance->Timeout = ExtInfo.Timeout;\r
     }\r