]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c
Add 'file not found' debug message to MTFTP.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Option.c
index f413c763053015d0b54d1b83e2e81e12c6e17f14..e40561a96b26b82f52e6ae13453906647f0c3ecd 100644 (file)
@@ -1,22 +1,15 @@
 /** @file\r
+  Routines to process MTFTP4 options.\r
 \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\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
-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
-  Mtftp4Option.c\r
-\r
-Abstract:\r
-  routines to process MTFTP4 options\r
-\r
-\r
 **/\r
 \r
 #include "Mtftp4Impl.h"\r
@@ -29,6 +22,134 @@ CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] = {
 };\r
 \r
 \r
+/**\r
+  Check whether two ascii strings are equel, ignore the case.\r
+\r
+  @param  Str1                   The first ascii string\r
+  @param  Str2                   The second ascii string\r
+\r
+  @retval TRUE                   Two strings are equal when case is ignored.\r
+  @retval FALSE                  Two string are not equal.\r
+\r
+**/\r
+BOOLEAN\r
+NetStringEqualNoCase (\r
+  IN UINT8                 *Str1,\r
+  IN UINT8                 *Str2\r
+  )\r
+{\r
+  UINT8                     Ch1;\r
+  UINT8                     Ch2;\r
+\r
+  ASSERT ((Str1 != NULL) && (Str2 != NULL));\r
+\r
+  for (; (*Str1 != '\0') && (*Str2 != '\0'); Str1++, Str2++) {\r
+    Ch1 = *Str1;\r
+    Ch2 = *Str2;\r
+\r
+    //\r
+    // Convert them to lower case then compare two\r
+    //\r
+    if (('A' <= Ch1) && (Ch1 <= 'Z')) {\r
+      Ch1 += 'a' - 'A';\r
+    }\r
+\r
+    if (('A' <= Ch2) && (Ch2 <= 'Z')) {\r
+      Ch2 += 'a' - 'A';\r
+    }\r
+\r
+    if (Ch1 != Ch2) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return (BOOLEAN) (*Str1 == *Str2);\r
+}\r
+\r
+\r
+/**\r
+  Convert a string to a UINT32 number.\r
+\r
+  @param  Str                    The string to convert from\r
+\r
+  @return The number get from the string\r
+\r
+**/\r
+UINT32\r
+NetStringToU32 (\r
+  IN UINT8                 *Str\r
+  )\r
+{\r
+  UINT32                    Num;\r
+\r
+  ASSERT (Str != NULL);\r
+\r
+  Num = 0;\r
+\r
+  for (; NET_IS_DIGIT (*Str); Str++) {\r
+    Num = Num * 10 + (*Str - '0');\r
+  }\r
+\r
+  return Num;\r
+}\r
+\r
+\r
+/**\r
+  Convert a string of the format "192.168.0.1" to an IP address.\r
+\r
+  @param  Str                    The string representation of IP\r
+  @param  Ip                     The varible to get IP.\r
+\r
+  @retval EFI_INVALID_PARAMETER  The IP string is invalid.\r
+  @retval EFI_SUCCESS            The IP is parsed into the Ip\r
+\r
+**/\r
+EFI_STATUS\r
+NetStringToIp (\r
+  IN     UINT8                 *Str,\r
+     OUT IP4_ADDR              *Ip\r
+  )\r
+{\r
+  UINT32                    Byte;\r
+  UINT32                    Addr;\r
+  UINTN                     Index;\r
+\r
+  *Ip  = 0;\r
+  Addr = 0;\r
+\r
+  for (Index = 0; Index < 4; Index++) {\r
+    if (!NET_IS_DIGIT (*Str)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Byte = NetStringToU32 (Str);\r
+\r
+    if (Byte > 255) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Addr = (Addr << 8) | Byte;\r
+\r
+    //\r
+    // Skip all the digitals and check whether the sepeator is the dot\r
+    //\r
+    while (NET_IS_DIGIT (*Str)) {\r
+      Str++;\r
+    }\r
+\r
+    if ((Index < 3) && (*Str != '.')) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  *Ip = Addr;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   Go through the packet to fill the Options array with the start\r
   addresses of each MTFTP option name/value pair.\r
@@ -44,13 +165,12 @@ CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] = {
   @retval EFI_SUCCESS            The packet has been parsed into the Options array.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Mtftp4FillOptions (\r
-  IN  EFI_MTFTP4_PACKET     *Packet,\r
-  IN  UINT32                PacketLen,\r
-  IN  OUT UINT32            *Count,\r
-  OUT EFI_MTFTP4_OPTION     *Options          OPTIONAL\r
+  IN     EFI_MTFTP4_PACKET     *Packet,\r
+  IN     UINT32                PacketLen,\r
+  IN OUT UINT32                *Count,\r
+     OUT EFI_MTFTP4_OPTION     *Options          OPTIONAL\r
   )\r
 {\r
   UINT8                     *Cur;\r
@@ -104,8 +224,9 @@ Mtftp4FillOptions (
 \r
 \r
 /**\r
-  Allocate and fill in a array of Mtftp options from the Packet. It\r
-  first calls Mtftp4FillOption to get the option number, then allocate\r
+  Allocate and fill in a array of Mtftp options from the Packet.\r
+\r
+  It first calls Mtftp4FillOption to get the option number, then allocate\r
   the array, at last, call Mtftp4FillOption again to save the options.\r
 \r
   @param  Packet                 The packet to parse\r
@@ -121,10 +242,10 @@ Mtftp4FillOptions (
 **/\r
 EFI_STATUS\r
 Mtftp4ExtractOptions (\r
-  IN  EFI_MTFTP4_PACKET     *Packet,\r
-  IN  UINT32                PacketLen,\r
-  IN  OUT UINT32            *OptionCount,\r
-  OUT EFI_MTFTP4_OPTION     **OptionList        OPTIONAL\r
+  IN     EFI_MTFTP4_PACKET     *Packet,\r
+  IN     UINT32                PacketLen,\r
+     OUT UINT32                *OptionCount,\r
+     OUT EFI_MTFTP4_OPTION     **OptionList        OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -178,135 +299,6 @@ Mtftp4ExtractOptions (
 }\r
 \r
 \r
-/**\r
-  Check whether two ascii strings are equel, ignore the case.\r
-\r
-  @param  Str1                   The first ascii string\r
-  @param  Str2                   The second ascii string\r
-\r
-  @retval TRUE                   Two strings are equal when case is ignored.\r
-  @retval FALSE                  Two string are not equal.\r
-\r
-**/\r
-BOOLEAN\r
-NetStringEqualNoCase (\r
-  IN  UINT8                 *Str1,\r
-  IN  UINT8                 *Str2\r
-  )\r
-{\r
-  UINT8                     Ch1;\r
-  UINT8                     Ch2;\r
-\r
-  ASSERT ((Str1 != NULL) && (Str2 != NULL));\r
-\r
-  for (; (*Str1 != '\0') && (*Str2 != '\0'); Str1++, Str2++) {\r
-    Ch1 = *Str1;\r
-    Ch2 = *Str2;\r
-\r
-    //\r
-    // Convert them to lower case then compare two\r
-    //\r
-    if (('A' <= Ch1) && (Ch1 <= 'Z')) {\r
-      Ch1 += 'a' - 'A';\r
-    }\r
-\r
-    if (('A' <= Ch2) && (Ch2 <= 'Z')) {\r
-      Ch2 += 'a' - 'A';\r
-    }\r
-\r
-    if (Ch1 != Ch2) {\r
-      return FALSE;\r
-    }\r
-  }\r
-\r
-  return (BOOLEAN) (*Str1 == *Str2);\r
-}\r
-\r
-\r
-/**\r
-  Convert a string to a UINT32 number.\r
-\r
-  @param  Str                    The string to convert from\r
-\r
-  @return The number get from the string\r
-\r
-**/\r
-UINT32\r
-NetStringToU32 (\r
-  IN  UINT8                 *Str\r
-  )\r
-{\r
-  UINT32                    Num;\r
-\r
-  ASSERT (Str != NULL);\r
-\r
-  Num = 0;\r
-\r
-  for (; NET_IS_DIGIT (*Str); Str++) {\r
-    Num = Num * 10 + (*Str - '0');\r
-  }\r
-\r
-  return Num;\r
-}\r
-\r
-\r
-/**\r
-  Convert a string of the format "192.168.0.1" to an IP address.\r
-\r
-  @param  Str                    The string representation of IP\r
-  @param  Ip                     The varible to get IP.\r
-\r
-  @retval EFI_INVALID_PARAMETER  The IP string is invalid.\r
-  @retval EFI_SUCCESS            The IP is parsed into the Ip\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-NetStringToIp (\r
-  IN  UINT8                 *Str,\r
-  OUT IP4_ADDR              *Ip\r
-  )\r
-{\r
-  UINT32                    Byte;\r
-  UINT32                    Addr;\r
-  UINTN                     Index;\r
-\r
-  *Ip  = 0;\r
-  Addr = 0;\r
-\r
-  for (Index = 0; Index < 4; Index++) {\r
-    if (!NET_IS_DIGIT (*Str)) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    Byte = NetStringToU32 (Str);\r
-\r
-    if (Byte > 255) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    Addr = (Addr << 8) | Byte;\r
-\r
-    //\r
-    // Skip all the digitals and check whether the sepeator is the dot\r
-    //\r
-    while (NET_IS_DIGIT (*Str)) {\r
-      Str++;\r
-    }\r
-\r
-    if ((Index < 3) && (*Str != '.')) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    Str++;\r
-  }\r
-\r
-  *Ip = Addr;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   Parse the MTFTP multicast option.\r
 \r
@@ -317,11 +309,10 @@ NetStringToIp (
   @retval EFI_SUCCESS            The multicast value is parsed into the Option\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Mtftp4ExtractMcast (\r
-  IN UINT8                  *Value,\r
-  IN MTFTP4_OPTION          *Option\r
+  IN     UINT8                  *Value,\r
+  IN OUT MTFTP4_OPTION          *Option\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -340,7 +331,7 @@ Mtftp4ExtractMcast (
       return Status;\r
     }\r
 \r
-    while (*Value && (*Value != ',')) {\r
+    while ((*Value != 0) && (*Value != ',')) {\r
       Value++;\r
     }\r
   }\r
@@ -364,7 +355,7 @@ Mtftp4ExtractMcast (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    Option->McastPort = (UINT16)Num;\r
+    Option->McastPort = (UINT16) Num;\r
 \r
     while (NET_IS_DIGIT (*Value)) {\r
       Value++;\r
@@ -386,7 +377,7 @@ Mtftp4ExtractMcast (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Option->Master = (BOOLEAN)(Num == 1);\r
+  Option->Master = (BOOLEAN) (Num == 1);\r
 \r
   while (NET_IS_DIGIT (*Value)) {\r
     Value++;\r
@@ -405,7 +396,7 @@ Mtftp4ExtractMcast (
   can access directly.\r
 \r
   @param  Options                The option array, which contains addresses of each\r
-                                  option's name/value string.\r
+                                 option's name/value string.\r
   @param  Count                  The number of options in the Options\r
   @param  Request                Whether this is a request or OACK. The format of\r
                                  multicast is different according to this setting.\r
@@ -418,10 +409,10 @@ Mtftp4ExtractMcast (
 **/\r
 EFI_STATUS\r
 Mtftp4ParseOption (\r
-  IN  EFI_MTFTP4_OPTION     *Options,\r
-  IN  UINT32                Count,\r
-  IN  BOOLEAN               Request,\r
-  OUT MTFTP4_OPTION         *MtftpOption\r
+  IN     EFI_MTFTP4_OPTION     *Options,\r
+  IN     UINT32                Count,\r
+  IN     BOOLEAN               Request,\r
+     OUT MTFTP4_OPTION         *MtftpOption\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -518,9 +509,9 @@ Mtftp4ParseOption (
 **/\r
 EFI_STATUS\r
 Mtftp4ParseOptionOack (\r
-  IN  EFI_MTFTP4_PACKET     *Packet,\r
-  IN  UINT32                PacketLen,\r
-  OUT MTFTP4_OPTION         *MtftpOption\r
+  IN     EFI_MTFTP4_PACKET     *Packet,\r
+  IN     UINT32                PacketLen,\r
+     OUT MTFTP4_OPTION         *MtftpOption\r
   )\r
 {\r
   EFI_MTFTP4_OPTION *OptionList;\r
@@ -534,9 +525,10 @@ Mtftp4ParseOptionOack (
   if (EFI_ERROR (Status) || (Count == 0)) {\r
     return Status;\r
   }\r
+  ASSERT (OptionList != NULL);\r
 \r
   Status = Mtftp4ParseOption (OptionList, Count, FALSE, MtftpOption);\r
 \r
-  gBS->FreePool (OptionList);\r
+  FreePool (OptionList);\r
   return Status;\r
 }\r