]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c
MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Option.c
index 0f66fe5433676df8ff7d13da0bbfe01cf985bcd0..e40561a96b26b82f52e6ae13453906647f0c3ecd 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Routines to process MTFTP4 options.\r
-  \r
-Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+\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<BR>\r
@@ -22,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
@@ -96,8 +224,8 @@ Mtftp4FillOptions (
 \r
 \r
 /**\r
-  Allocate and fill in a array of Mtftp options from the Packet. \r
-  \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
@@ -171,134 +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
-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
@@ -525,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