]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c
Insert comments for functions/macros and add the file headers.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Wrq.c
index 12b4c4a4a15d81f0f82abc5075ad9f0a2c753e55..cb39da48c8d451349d76a03e00d4a85e4c4ec5d3 100644 (file)
@@ -1,95 +1,37 @@
 /** @file\r
-\r
-Copyright (c) 2006, Intel Corporation\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
 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
+http://opensource.org/licenses/bsd-license.php<BR>\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
 \r
-Module Name:\r
-\r
-  Mtftp4Wrq.c\r
-\r
-Abstract:\r
-\r
-  Routines to process Wrq (upload)\r
-\r
-\r
 **/\r
 \r
 #include "Mtftp4Impl.h"\r
 \r
-VOID\r
-Mtftp4WrqInput (\r
-  IN NET_BUF                *UdpPacket,\r
-  IN UDP_POINTS             *Points,\r
-  IN EFI_STATUS             IoStatus,\r
-  IN VOID                   *Context\r
-  );\r
-\r
-\r
-/**\r
-  Start the MTFTP session for pload. It will first init some states,\r
-  then send the WRQ request packet, and start receiving the  packet.\r
-\r
-  @param  Instance              The MTFTP session\r
-  @param  Operation             Redundant parameter, which is always\r
-                                EFI_MTFTP4_OPCODE_WRQ here.\r
-\r
-  @retval EFI_SUCCESS           The upload process has been started.\r
-  @retval Others                Failed to start the upload.\r
-\r
-**/\r
-EFI_STATUS\r
-Mtftp4WrqStart (\r
-  IN MTFTP4_PROTOCOL        *Instance,\r
-  IN UINT16                 Operation\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-\r
-  //\r
-  // The valid block number range are [0, 0xffff]. For example:\r
-  // the client sends an WRQ request to the server, the server\r
-  // ACK with an ACK0 to let client start transfer the first\r
-  // packet.\r
-  //\r
-  Status = Mtftp4InitBlockRange (&Instance->Blocks, 0, 0xffff);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = Mtftp4SendRequest (Instance);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  return UdpIoRecvDatagram (Instance->UnicastPort, Mtftp4WrqInput, Instance, 0);\r
-}\r
 \r
 \r
 /**\r
   Build then send a MTFTP data packet for the MTFTP upload session.\r
 \r
-  @param  Instance              The MTFTP upload session\r
-  @param  BlockNum              The block number to send\r
+  @param  Instance              The MTFTP upload session.\r
+  @param  BlockNum              The block number to send.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  Failed to build the packet\r
+  @retval EFI_OUT_OF_RESOURCES  Failed to build the packet.\r
   @retval EFI_ABORTED           The consumer of this child directs to abort the\r
-                                transmission by return an error through\r
-                                PacketNeeded\r
+                                transmission by return an error through PacketNeeded.\r
   @retval EFI_SUCCESS           The data is sent.\r
 \r
 **/\r
 EFI_STATUS\r
 Mtftp4WrqSendBlock (\r
-  IN MTFTP4_PROTOCOL        *Instance,\r
-  IN UINT16                 BlockNum\r
+  IN OUT MTFTP4_PROTOCOL        *Instance,\r
+  IN     UINT16                 BlockNum\r
   )\r
 {\r
   EFI_MTFTP4_PACKET         *Packet;\r
@@ -109,7 +51,7 @@ Mtftp4WrqSendBlock (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Packet = (EFI_MTFTP4_PACKET *)NetbufAllocSpace (UdpPacket, MTFTP4_DATA_HEAD_LEN, FALSE);\r
+  Packet = (EFI_MTFTP4_PACKET *) NetbufAllocSpace (UdpPacket, MTFTP4_DATA_HEAD_LEN, FALSE);\r
 \r
   Packet->Data.OpCode = HTONS (EFI_MTFTP4_OPCODE_DATA);\r
   Packet->Data.Block  = HTONS (BlockNum);\r
@@ -139,7 +81,12 @@ Mtftp4WrqSendBlock (
     // Get data from PacketNeeded\r
     //\r
     DataBuf = NULL;\r
-    Status  = Token->PacketNeeded (&Instance->Mtftp4, Token, &DataLen, (VOID **) &DataBuf);\r
+    Status  = Token->PacketNeeded (\r
+                       &Instance->Mtftp4,\r
+                       Token,\r
+                       &DataLen,\r
+                       (VOID **) &DataBuf\r
+                       );\r
 \r
     if (EFI_ERROR (Status) || (DataLen > Instance->BlkSize)) {\r
       if (DataBuf != NULL) {\r
@@ -172,9 +119,10 @@ Mtftp4WrqSendBlock (
 \r
 \r
 /**\r
-  Function to handle received ACK packet. If the ACK number matches the\r
-  expected block number, and there are more data pending, send the next\r
-  block. Otherwise tell the caller that we are done.\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
   @param  Packet                The MTFTP packet received\r
@@ -188,10 +136,10 @@ Mtftp4WrqSendBlock (
 **/\r
 EFI_STATUS\r
 Mtftp4WrqHandleAck (\r
-  IN  MTFTP4_PROTOCOL       *Instance,\r
-  IN  EFI_MTFTP4_PACKET     *Packet,\r
-  IN  UINT32                Len,\r
-  OUT BOOLEAN               *Completed\r
+  IN     MTFTP4_PROTOCOL       *Instance,\r
+  IN     EFI_MTFTP4_PACKET     *Packet,\r
+  IN     UINT32                Len,\r
+     OUT BOOLEAN               *Completed\r
   )\r
 {\r
   UINT16                    AckNum;\r
@@ -221,6 +169,7 @@ Mtftp4WrqHandleAck (
   Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);\r
 \r
   if (Expected < 0) {\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
@@ -247,17 +196,19 @@ Mtftp4WrqHandleAck (
 \r
 \r
 /**\r
-  Check whether the received OACK is valid. The OACK is valid\r
-  only if:\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
   3. It can't change the proposed time out value.\r
-  4. Other requirements of the individal MTFTP options as required.s\r
+  4. Other requirements of the individal MTFTP options as required.\r
 \r
   @param  Reply                 The options included in the OACK\r
   @param  Request               The options we requested\r
 \r
-  @return TRUE if the options included in OACK is valid, otherwise FALSE.\r
+  @retval TRUE                  The options included in OACK is valid.\r
+  @retval FALSE                 The options included in OACK is invalid.\r
 \r
 **/\r
 BOOLEAN\r
@@ -269,7 +220,7 @@ Mtftp4WrqOackValid (
   //\r
   // It is invalid for server to return options we don't request\r
   //\r
-  if ((Reply->Exist &~Request->Exist) != 0) {\r
+  if ((Reply->Exist & ~Request->Exist) != 0) {\r
     return FALSE;\r
   }\r
 \r
@@ -277,8 +228,8 @@ Mtftp4WrqOackValid (
   // Server can only specify a smaller block size to be used and\r
   // return the timeout matches that requested.\r
   //\r
-  if (((Reply->Exist & MTFTP4_BLKSIZE_EXIST) && (Reply->BlkSize > Request->BlkSize)) ||\r
-      ((Reply->Exist & MTFTP4_TIMEOUT_EXIST) && (Reply->Timeout != Request->Timeout))) {\r
+  if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) != 0) && (Reply->BlkSize > Request->BlkSize)) ||\r
+      (((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))) {\r
     return FALSE;\r
   }\r
 \r
@@ -287,8 +238,9 @@ Mtftp4WrqOackValid (
 \r
 \r
 /**\r
-  Function to handle the MTFTP OACK packet. It parses the packet's\r
-  options, and update the internal states of the session\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
   @param  Packet                The received OACK packet\r
@@ -302,10 +254,10 @@ Mtftp4WrqOackValid (
 **/\r
 EFI_STATUS\r
 Mtftp4WrqHandleOack (\r
-  IN  MTFTP4_PROTOCOL       *Instance,\r
-  IN  EFI_MTFTP4_PACKET     *Packet,\r
-  IN  UINT32                Len,\r
-  OUT BOOLEAN               *Completed\r
+  IN OUT MTFTP4_PROTOCOL       *Instance,\r
+  IN     EFI_MTFTP4_PACKET     *Packet,\r
+  IN     UINT32                Len,\r
+     OUT BOOLEAN               *Completed\r
   )\r
 {\r
   MTFTP4_OPTION             Reply;\r
@@ -361,7 +313,14 @@ Mtftp4WrqHandleOack (
   Bogus.Ack.OpCode    = HTONS (EFI_MTFTP4_OPCODE_ACK);\r
   Bogus.Ack.Block[0]  = 0;\r
 \r
-  return Mtftp4WrqHandleAck (Instance, &Bogus, sizeof (EFI_MTFTP4_ACK_HEADER), Completed);\r
+  Status = Mtftp4WrqHandleAck (\r
+             Instance,\r
+             &Bogus,\r
+             sizeof (EFI_MTFTP4_ACK_HEADER),\r
+             Completed\r
+             );\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -373,9 +332,6 @@ Mtftp4WrqHandleOack (
   @param  IoStatus              The result of the packet receiving\r
   @param  Context               Opaque parameter for the callback, which is the\r
                                 MTFTP session.\r
-\r
-  @return None\r
-\r
 **/\r
 VOID\r
 Mtftp4WrqInput (\r
@@ -494,6 +450,9 @@ Mtftp4WrqInput (
   case EFI_MTFTP4_OPCODE_ERROR:\r
     Status = EFI_TFTP_ERROR;\r
     break;\r
+    \r
+  default:\r
+    break;\r
   }\r
 \r
 ON_EXIT:\r
@@ -520,3 +479,49 @@ ON_EXIT:
     Mtftp4CleanOperation (Instance, Status);\r
   }\r
 }\r
+\r
+\r
+\r
+/**\r
+  Start the MTFTP session for upload.\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
+  @param  Operation             Redundant parameter, which is always\r
+                                EFI_MTFTP4_OPCODE_WRQ here.\r
+\r
+  @retval EFI_SUCCESS           The upload process has been started.\r
+  @retval Others                Failed to start the upload.\r
+\r
+**/\r
+EFI_STATUS\r
+Mtftp4WrqStart (\r
+  IN MTFTP4_PROTOCOL        *Instance,\r
+  IN UINT16                 Operation\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+\r
+  //\r
+  // The valid block number range are [0, 0xffff]. For example:\r
+  // the client sends an WRQ request to the server, the server\r
+  // ACK with an ACK0 to let client start transfer the first\r
+  // packet.\r
+  //\r
+  Status = Mtftp4InitBlockRange (&Instance->Blocks, 0, 0xffff);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Mtftp4SendRequest (Instance);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return UdpIoRecvDatagram (Instance->UnicastPort, Mtftp4WrqInput, Instance, 0);\r
+}\r
+\r