]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Option.c
Scrubbed part of the code.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Option.c
index b16f4693d7b4a169f4a62e5ffccb6f36ffb5d976..571c6bbf95db664e8c66c9f3bd0caac66405ac15 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 2008, Intel Corporation\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
@@ -22,14 +22,12 @@ Abstract:
 \r
 #include "Dhcp4Impl.h"\r
 \r
-//\r
-// A list of the format of DHCP Options sorted by option tag\r
-// to validate a dhcp message. Refere the comments of the\r
-// DHCP_OPTION_FORMAT structure.\r
-//\r
-STATIC\r
-DHCP_OPTION_FORMAT\r
-DhcpOptionFormats [] = {\r
+///\r
+/// A list of the format of DHCP Options sorted by option tag\r
+/// to validate a dhcp message. Refere the comments of the\r
+/// DHCP_OPTION_FORMAT structure.\r
+///\r
+DHCP_OPTION_FORMAT DhcpOptionFormats[] = {\r
   {DHCP_TAG_NETMASK,        DHCP_OPTION_IP,     1, 1  , TRUE},\r
   {DHCP_TAG_TIME_OFFSET,    DHCP_OPTION_INT32,  1, 1  , FALSE},\r
   {DHCP_TAG_ROUTER,         DHCP_OPTION_IP,     1, -1 , TRUE},\r
@@ -127,7 +125,6 @@ DhcpOptionFormats [] = {
   @return The point to the option's format, NULL if not found.\r
 \r
 **/\r
-STATIC\r
 DHCP_OPTION_FORMAT *\r
 DhcpFindOptionFormat (\r
   IN UINT8                  Tag\r
@@ -150,7 +147,7 @@ DhcpFindOptionFormat (
     if (Tag < DhcpOptionFormats[Middle].Tag) {\r
       Right = Middle - 1;\r
     } else {\r
-      Left = Middle + 1;\r
+      Left  = Middle + 1;\r
     }\r
   }\r
 \r
@@ -165,10 +162,10 @@ DhcpFindOptionFormat (
   @param  OptValue               The value of the option\r
   @param  Len                    The length of the option value\r
 \r
-  @return TRUE is the option is valid, otherwise FALSE.\r
+  @retval TRUE     The option is valid.\r
+  @retval FALSE    Otherwise.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 DhcpOptionIsValid (\r
   IN DHCP_OPTION_FORMAT     *Format,\r
@@ -217,7 +214,8 @@ DhcpOptionIsValid (
   Occur = Len / Unit;\r
 \r
   if (((Format->MinOccur != -1) && (Occur < Format->MinOccur)) ||\r
-      ((Format->MaxOccur != -1) && (Occur > Format->MaxOccur))) {\r
+      ((Format->MaxOccur != -1) && (Occur > Format->MaxOccur))\r
+      ) {\r
     return FALSE;\r
   }\r
 \r
@@ -249,13 +247,12 @@ DhcpOptionIsValid (
   @retval EFI_INVALID_PARAMETER  The DHCP option is mal-formated\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpGetParameter (\r
-  IN UINT8                  Tag,\r
-  IN INTN                   Len,\r
-  IN UINT8                  *Data,\r
-  IN DHCP_PARAMETER         *Para\r
+  IN  UINT8                  Tag,\r
+  IN  INTN                   Len,\r
+  IN  UINT8                  *Data,\r
+  OUT DHCP_PARAMETER         *Para\r
   )\r
 {\r
   switch (Tag) {\r
@@ -316,14 +313,13 @@ DhcpGetParameter (
   @param  BufLen                 The length of the buffer\r
   @param  Check                  The callback function for each option found\r
   @param  Context                The opaque parameter for the Check\r
-  @param  Overload               variable to save the value of DHCP_TAG_OVERLOAD\r
+  @param  Overload               Variable to save the value of DHCP_TAG_OVERLOAD\r
                                  option.\r
 \r
   @retval EFI_SUCCESS            All the options are valid\r
   @retval EFI_INVALID_PARAMETER  The options are mal-formated.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpIterateBufferOptions (\r
   IN  UINT8                 *Buffer,\r
@@ -395,7 +391,7 @@ DhcpIterateBufferOptions (
   @param  Context                The opaque parameter for Check\r
 \r
   @retval EFI_SUCCESS            The DHCP packet's options are well formated\r
-  @retval Others                 The DHCP packet's options are not well formated\r
+  @retval EFI_INVALID_PARAMETER  The DHCP packet's options are not well formated\r
 \r
 **/\r
 EFI_STATUS\r
@@ -424,7 +420,7 @@ DhcpIterateOptions (
 \r
   if ((Overload == DHCP_OVERLOAD_FILENAME) || (Overload == DHCP_OVERLOAD_BOTH)) {\r
     Status = DhcpIterateBufferOptions (\r
-               Packet->Dhcp4.Header.BootFileName,\r
+               (UINT8 *) Packet->Dhcp4.Header.BootFileName,\r
                128,\r
                Check,\r
                Context,\r
@@ -438,7 +434,7 @@ DhcpIterateOptions (
 \r
   if ((Overload == DHCP_OVERLOAD_SVRNAME) || (Overload == DHCP_OVERLOAD_BOTH)) {\r
     Status = DhcpIterateBufferOptions (\r
-               Packet->Dhcp4.Header.ServerName,\r
+               (UINT8 *) Packet->Dhcp4.Header.ServerName,\r
                64,\r
                Check,\r
                Context,\r
@@ -455,7 +451,7 @@ DhcpIterateOptions (
 \r
 \r
 /**\r
-  Call back function to DhcpiterateOptions to compute each option's\r
+  Call back function to DhcpIterateOptions to compute each option's\r
   length. It just adds the data length of all the occurances of this\r
   Tag. Context is an array of 256 DHCP_OPTION_COUNT.\r
 \r
@@ -468,7 +464,6 @@ DhcpIterateOptions (
   @retval EFI_SUCCESS            It always returns EFI_SUCCESS.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpGetOptionLen (\r
   IN UINT8                  Tag,\r
@@ -480,15 +475,15 @@ DhcpGetOptionLen (
   DHCP_OPTION_COUNT         *OpCount;\r
 \r
   OpCount             = (DHCP_OPTION_COUNT *) Context;\r
-  OpCount[Tag].Offset = OpCount[Tag].Offset + Len;\r
+  OpCount[Tag].Offset = (UINT16) (OpCount[Tag].Offset + Len);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  Call back function to DhcpiterateOptions to consolidate each option's\r
-  data. There are maybe several occurance of the same option.\r
+  Call back function to DhcpIterateOptions to consolidate each option's\r
+  data. There are maybe several occurrence of the same option.\r
 \r
   @param  Tag                    The option to consolidate its data\r
   @param  Len                    The length of option data\r
@@ -499,7 +494,6 @@ DhcpGetOptionLen (
   @retval EFI_SUCCESS            It always returns EFI_SUCCESS\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpFillOption (\r
   IN UINT8                  Tag,\r
@@ -526,10 +520,10 @@ DhcpFillOption (
     Options[Index].Data = Buf + OptCount[Tag].Offset;\r
   }\r
 \r
-  NetCopyMem (Buf + OptCount[Tag].Offset, Data, Len);\r
+  CopyMem (Buf + OptCount[Tag].Offset, Data, Len);\r
 \r
-  OptCount[Tag].Offset  = OptCount[Tag].Offset + Len;\r
-  Options[Index].Len    = Options[Index].Len + Len;\r
+  OptCount[Tag].Offset  = (UINT16) (OptCount[Tag].Offset + Len);\r
+  Options[Index].Len    = (UINT16) (Options[Index].Len + Len);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -544,7 +538,7 @@ DhcpFillOption (
   as a UINT8. It then iterates the DHCP packet to get data length of\r
   each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it\r
   knows the number of present options and their length. It allocates a\r
-  array of DHCP_OPTION and a continous buffer after the array to put\r
+  array of DHCP_OPTION and a continuous buffer after the array to put\r
   all the options' data. Each option's data is pointed to by the Data\r
   field in DHCP_OPTION structure. At last, it call DhcpIterateOptions\r
   with DhcpFillOption to fill each option's data to its position in the\r
@@ -582,7 +576,7 @@ DhcpParseOption (
   // First compute how many options and how long each option is\r
   // with the "Key indexed counting" algorithms.\r
   //\r
-  OptCount = NetAllocateZeroPool (DHCP_MAX_OPTIONS * sizeof (DHCP_OPTION_COUNT));\r
+  OptCount = AllocateZeroPool (DHCP_MAX_OPTIONS * sizeof (DHCP_OPTION_COUNT));\r
 \r
   if (OptCount == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -606,8 +600,8 @@ DhcpParseOption (
     if (OptCount[Index].Offset != 0) {\r
       OptCount[Index].Index   = (UINT8) OptNum;\r
 \r
-      TotalLen                = TotalLen + OptCount[Index].Offset;\r
-      OptCount[Index].Offset  = TotalLen - OptCount[Index].Offset;\r
+      TotalLen                = (UINT16) (TotalLen + OptCount[Index].Offset);\r
+      OptCount[Index].Offset  = (UINT16) (TotalLen - OptCount[Index].Offset);\r
 \r
       OptNum++;\r
     }\r
@@ -624,7 +618,7 @@ DhcpParseOption (
   // Allocate a buffer to hold the DHCP options, and after that, a\r
   // continuous buffer to put all the options' data.\r
   //\r
-  Options = NetAllocateZeroPool (OptNum * sizeof (DHCP_OPTION) + TotalLen);\r
+  Options = AllocateZeroPool (OptNum * sizeof (DHCP_OPTION) + TotalLen);\r
 \r
   if (Options == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -638,14 +632,14 @@ DhcpParseOption (
   Status          = DhcpIterateOptions (Packet, DhcpFillOption, &Context);\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NetFreePool (Options);\r
+    gBS->FreePool (Options);\r
     goto ON_EXIT;\r
   }\r
 \r
   *OptionPoint = Options;\r
 \r
 ON_EXIT:\r
-  NetFreePool (OptCount);\r
+  gBS->FreePool (OptCount);\r
   return Status;\r
 }\r
 \r
@@ -689,7 +683,7 @@ DhcpValidateOptions (
   }\r
 \r
   Updated = FALSE;\r
-  NetZeroMem (&Parameter, sizeof (Parameter));\r
+  ZeroMem (&Parameter, sizeof (Parameter));\r
 \r
   for (Index = 0; Index < Count; Index++) {\r
     Option = &AllOption[Index];\r
@@ -722,16 +716,16 @@ DhcpValidateOptions (
   }\r
 \r
   if (Updated && (Para != NULL)) {\r
-    if ((*Para = NetAllocatePool (sizeof (DHCP_PARAMETER))) == NULL) {\r
+    if ((*Para = AllocatePool (sizeof (DHCP_PARAMETER))) == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ON_EXIT;\r
     }\r
 \r
-    CopyMem (*Para, &Parameter, sizeof (DHCP_PARAMETER));\r
+    CopyMem (*Para, &Parameter, sizeof (**Para));\r
   }\r
 \r
 ON_EXIT:\r
-  NetFreePool (AllOption);\r
+  gBS->FreePool (AllOption);\r
   return Status;\r
 }\r
 \r
@@ -751,10 +745,10 @@ ON_EXIT:
 **/\r
 UINT8 *\r
 DhcpAppendOption (\r
-  IN UINT8                  *Buf,\r
-  IN UINT8                  Tag,\r
-  IN UINT16                 DataLen,\r
-  IN UINT8                  *Data\r
+  OUT UINT8                  *Buf,\r
+  IN  UINT8                  Tag,\r
+  IN  UINT16                 DataLen,\r
+  IN  UINT8                  *Data\r
   )\r
 {\r
   INTN                      Index;\r
@@ -763,11 +757,11 @@ DhcpAppendOption (
   ASSERT (DataLen != 0);\r
 \r
   for (Index = 0; Index < (DataLen + 254) / 255; Index++) {\r
-    Len      = NET_MIN (255, DataLen - Index * 255);\r
+    Len      = MIN (255, DataLen - Index * 255);\r
 \r
     *(Buf++) = Tag;\r
     *(Buf++) = (UINT8) Len;\r
-    NetCopyMem (Buf, Data + Index * 255, Len);\r
+    CopyMem (Buf, Data + Index * 255, Len);\r
 \r
     Buf     += Len;\r
   }\r
@@ -789,6 +783,7 @@ DhcpAppendOption (
                                  function.\r
 \r
   @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory\r
+  @retval EFI_INVALID_PARAMETER  The options in SeekPacket are mal-formated\r
   @retval EFI_SUCCESS            The packet is build.\r
 \r
 **/\r
@@ -815,7 +810,7 @@ DhcpBuild (
   // Use an array of DHCP_OPTION to mark the existance\r
   // and position of each valid options.\r
   //\r
-  Mark = NetAllocatePool (sizeof (DHCP_OPTION) * DHCP_MAX_OPTIONS);\r
+  Mark = AllocatePool (sizeof (DHCP_OPTION) * DHCP_MAX_OPTIONS);\r
 \r
   if (Mark == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -871,7 +866,7 @@ DhcpBuild (
   }\r
 \r
   Status  = EFI_OUT_OF_RESOURCES;\r
-  Packet  = (EFI_DHCP4_PACKET *) NetAllocatePool (Len);\r
+  Packet  = (EFI_DHCP4_PACKET *) AllocatePool (Len);\r
 \r
   if (Packet == NULL) {\r
     goto ON_ERROR;\r
@@ -879,7 +874,7 @@ DhcpBuild (
 \r
   Packet->Size         = Len;\r
   Packet->Length       = 0;\r
-  CopyMem (&Packet->Dhcp4.Header, &SeedPacket->Dhcp4.Header, sizeof (EFI_DHCP4_HEADER));\r
+  CopyMem (&Packet->Dhcp4.Header, &SeedPacket->Dhcp4.Header, sizeof (Packet->Dhcp4.Header));\r
   Packet->Dhcp4.Magik  = DHCP_OPTION_MAGIC;\r
   Buf                  = Packet->Dhcp4.Option;\r
 \r
@@ -898,9 +893,9 @@ DhcpBuild (
 \r
 ON_ERROR:\r
   if (SeedOptions != NULL) {\r
-    NetFreePool (SeedOptions);\r
+    gBS->FreePool (SeedOptions);\r
   }\r
 \r
-  NetFreePool (Mark);\r
+  gBS->FreePool (Mark);\r
   return Status;\r
 }\r