]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c
MdeModulePke/Mtftp4Dxe: Support windowsize in read request operation.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Wrq.c
index cb39da48c8d451349d76a03e00d4a85e4c4ec5d3..ea309e2d6b48b5d4730b1311fff33c92b06b4d7c 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Routines to process Wrq (upload).\r
-  \r
-Copyright (c) 2006, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+\r
+Copyright (c) 2006 - 2018, 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
 http://opensource.org/licenses/bsd-license.php<BR>\r
@@ -52,6 +52,7 @@ Mtftp4WrqSendBlock (
   }\r
 \r
   Packet = (EFI_MTFTP4_PACKET *) NetbufAllocSpace (UdpPacket, MTFTP4_DATA_HEAD_LEN, FALSE);\r
+  ASSERT (Packet != NULL);\r
 \r
   Packet->Data.OpCode = HTONS (EFI_MTFTP4_OPCODE_DATA);\r
   Packet->Data.Block  = HTONS (BlockNum);\r
@@ -90,7 +91,11 @@ Mtftp4WrqSendBlock (
 \r
     if (EFI_ERROR (Status) || (DataLen > Instance->BlkSize)) {\r
       if (DataBuf != NULL) {\r
-        gBS->FreePool (DataBuf);\r
+        FreePool (DataBuf);\r
+      }\r
+\r
+      if (UdpPacket != NULL) {\r
+        NetbufFree (UdpPacket);\r
       }\r
 \r
       Mtftp4SendError (\r
@@ -110,7 +115,7 @@ Mtftp4WrqSendBlock (
     if (DataLen > 0) {\r
       NetbufAllocSpace (UdpPacket, DataLen, FALSE);\r
       CopyMem (Packet->Data.Data, DataBuf, DataLen);\r
-      gBS->FreePool (DataBuf);\r
+      FreePool (DataBuf);\r
     }\r
   }\r
 \r
@@ -119,9 +124,9 @@ Mtftp4WrqSendBlock (
 \r
 \r
 /**\r
-  Function to handle received ACK packet. \r
-  \r
-  If the ACK number matches the expected block number, and there are more \r
+  Function to handle received ACK packet.\r
+\r
+  If the ACK number matches the expected block number, and there are more\r
   data pending, send the next block. Otherwise tell the caller that we are done.\r
 \r
   @param  Instance              The MTFTP upload session\r
@@ -144,6 +149,7 @@ Mtftp4WrqHandleAck (
 {\r
   UINT16                    AckNum;\r
   INTN                      Expected;\r
+  UINT64                    TotalBlock;\r
 \r
   *Completed  = FALSE;\r
   AckNum      = NTOHS (Packet->Ack.Block[0]);\r
@@ -164,12 +170,12 @@ Mtftp4WrqHandleAck (
   // tell the Mtftp4WrqInput to finish the transfer. This is the last\r
   // block number if the block range are empty..\r
   //\r
-  Mtftp4RemoveBlockNum (&Instance->Blocks, AckNum);\r
+  Mtftp4RemoveBlockNum (&Instance->Blocks, AckNum, *Completed,&TotalBlock);\r
 \r
   Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);\r
 \r
   if (Expected < 0) {\r
-  \r
+\r
     //\r
     // The block range is empty. It may either because the the last\r
     // block has been ACKed, or the sequence number just looped back,\r
@@ -196,8 +202,8 @@ Mtftp4WrqHandleAck (
 \r
 \r
 /**\r
-  Check whether the received OACK is valid. \r
-  \r
+  Check whether the received OACK is valid.\r
+\r
   The OACK is valid only if:\r
   1. It only include options requested by us\r
   2. It can only include a smaller block size\r
@@ -238,8 +244,8 @@ Mtftp4WrqOackValid (
 \r
 \r
 /**\r
-  Function to handle the MTFTP OACK packet. \r
-  \r
+  Function to handle the MTFTP OACK packet.\r
+\r
   It parses the packet's options, and update the internal states of the session.\r
 \r
   @param  Instance              The MTFTP session\r
@@ -280,7 +286,7 @@ Mtftp4WrqHandleOack (
   // Parse and validate the options from server\r
   //\r
   ZeroMem (&Reply, sizeof (MTFTP4_OPTION));\r
-  Status = Mtftp4ParseOptionOack (Packet, Len, &Reply);\r
+  Status = Mtftp4ParseOptionOack (Packet, Len, Instance->Operation, &Reply);\r
 \r
   if (EFI_ERROR (Status) || !Mtftp4WrqOackValid (&Reply, &Instance->RequestOption)) {\r
     //\r
@@ -328,15 +334,16 @@ Mtftp4WrqHandleOack (
   The input process routine for MTFTP upload.\r
 \r
   @param  UdpPacket             The received MTFTP packet.\r
-  @param  Points                The local/remote access point\r
+  @param  EndPoint              The local/remote access point\r
   @param  IoStatus              The result of the packet receiving\r
   @param  Context               Opaque parameter for the callback, which is the\r
                                 MTFTP session.\r
 **/\r
 VOID\r
+EFIAPI\r
 Mtftp4WrqInput (\r
   IN NET_BUF                *UdpPacket,\r
-  IN UDP_POINTS             *Points,\r
+  IN UDP_END_POINT          *EndPoint,\r
   IN EFI_STATUS             IoStatus,\r
   IN VOID                   *Context\r
   )\r
@@ -370,11 +377,11 @@ Mtftp4WrqInput (
   // Client send initial request to server's listening port. Server\r
   // will select a UDP port to communicate with the client.\r
   //\r
-  if (Points->RemotePort != Instance->ConnectedPort) {\r
+  if (EndPoint->RemotePort != Instance->ConnectedPort) {\r
     if (Instance->ConnectedPort != 0) {\r
       goto ON_EXIT;\r
     } else {\r
-      Instance->ConnectedPort = Points->RemotePort;\r
+      Instance->ConnectedPort = EndPoint->RemotePort;\r
     }\r
   }\r
 \r
@@ -395,6 +402,7 @@ Mtftp4WrqInput (
 \r
   } else {\r
     Packet = (EFI_MTFTP4_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);\r
+    ASSERT (Packet != NULL);\r
   }\r
 \r
   Opcode = NTOHS (Packet->OpCode);\r
@@ -450,7 +458,7 @@ Mtftp4WrqInput (
   case EFI_MTFTP4_OPCODE_ERROR:\r
     Status = EFI_TFTP_ERROR;\r
     break;\r
-    \r
+\r
   default:\r
     break;\r
   }\r
@@ -461,7 +469,7 @@ ON_EXIT:
   // restart the receive, otherwise end the session.\r
   //\r
   if ((Packet != NULL) && (UdpPacket->BlockOpNum > 1)) {\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
   }\r
 \r
   if (UdpPacket != NULL) {\r
@@ -484,8 +492,8 @@ ON_EXIT:
 \r
 /**\r
   Start the MTFTP session for upload.\r
-  \r
-  It will first init some states, then send the WRQ request packet, \r
+\r
+  It will first init some states, then send the WRQ request packet,\r
   and start receiving the packet.\r
 \r
   @param  Instance              The MTFTP session\r