]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Option.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Option.c
index 11b8978b400581dc6add2a2ff943e4eb99d81e8d..dd89beac522241b5e4654ed3153fd86227d761c8 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Function to validate, parse, process the DHCP options.\r
-  \r
-Copyright (c) 2006 - 2009, 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\r
@@ -20,91 +20,91 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /// 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
-  {DHCP_TAG_TIME_SERVER,    DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_NAME_SERVER,    DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_DNS_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_LOG_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_COOKIE_SERVER,  DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_LPR_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_IMPRESS_SERVER, DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_RL_SERVER,      DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_HOSTNAME,       DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_BOOTFILE_LEN,   DHCP_OPTION_INT16,  1, 1  , FALSE},\r
-  {DHCP_TAG_DUMP,           DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_DOMAINNAME,     DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_SWAP_SERVER,    DHCP_OPTION_IP,     1, 1  , FALSE},\r
-  {DHCP_TAG_ROOTPATH,       DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_EXTEND_PATH,    DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_IPFORWARD,      DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_NONLOCAL_SRR,   DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_POLICY_SRR,     DHCP_OPTION_IPPAIR, 1, -1 , FALSE},\r
-  {DHCP_TAG_EMTU,           DHCP_OPTION_INT16,  1, 1  , FALSE},\r
-  {DHCP_TAG_TTL,            DHCP_OPTION_INT8,   1, 1  , FALSE},\r
-  {DHCP_TAG_PATHMTU_AGE,    DHCP_OPTION_INT32,  1, 1  , FALSE},\r
-  {DHCP_TAG_PATHMTU_PLATEAU,DHCP_OPTION_INT16,  1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_IFMTU,          DHCP_OPTION_INT16,  1, 1  , FALSE},\r
-  {DHCP_TAG_SUBNET_LOCAL,   DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_BROADCAST,      DHCP_OPTION_IP,     1, 1  , FALSE},\r
-  {DHCP_TAG_DISCOVER_MASK,  DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_SUPPLY_MASK,    DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_DISCOVER_ROUTE, DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_ROUTER_SOLICIT, DHCP_OPTION_IP,     1, 1  , FALSE},\r
-  {DHCP_TAG_STATIC_ROUTE,   DHCP_OPTION_IPPAIR, 1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_TRAILER,        DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-  {DHCP_TAG_ARPAGE,         DHCP_OPTION_INT32,  1, 1  , FALSE},\r
-  {DHCP_TAG_ETHER_ENCAP,    DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-\r
-  {DHCP_TAG_TCP_TTL,        DHCP_OPTION_INT8,   1, 1  , FALSE},\r
-  {DHCP_TAG_KEEP_INTERVAL,  DHCP_OPTION_INT32,  1, 1  , FALSE},\r
-  {DHCP_TAG_KEEP_GARBAGE,   DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
-\r
-  {DHCP_TAG_NIS_DOMAIN,     DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_NIS_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_NTP_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_VENDOR,         DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_NBNS,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_NBDD,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_NBTYPE,         DHCP_OPTION_INT8,   1, 1  , FALSE},\r
-  {DHCP_TAG_NBSCOPE,        DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_XFONT,          DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_XDM,            DHCP_OPTION_IP,     1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_REQUEST_IP,     DHCP_OPTION_IP,     1, 1  , FALSE},\r
-  {DHCP_TAG_LEASE,          DHCP_OPTION_INT32,  1, 1  , TRUE},\r
-  {DHCP_TAG_OVERLOAD,       DHCP_OPTION_INT8,   1, 1  , TRUE},\r
-  {DHCP_TAG_TYPE,           DHCP_OPTION_INT8,   1, 1  , TRUE},\r
-  {DHCP_TAG_SERVER_ID,      DHCP_OPTION_IP,     1, 1  , TRUE},\r
-  {DHCP_TAG_PARA_LIST,      DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_MESSAGE,        DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_MAXMSG,         DHCP_OPTION_INT16,  1, 1  , FALSE},\r
-  {DHCP_TAG_T1,             DHCP_OPTION_INT32,  1, 1  , TRUE},\r
-  {DHCP_TAG_T2,             DHCP_OPTION_INT32,  1, 1  , TRUE},\r
-  {DHCP_TAG_VENDOR_CLASS,   DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_CLIENT_ID,      DHCP_OPTION_INT8,   2, -1 , FALSE},\r
-\r
-  {DHCP_TAG_NISPLUS,        DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_NISPLUS_SERVER, DHCP_OPTION_IP,     1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_TFTP,           DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-  {DHCP_TAG_BOOTFILE,       DHCP_OPTION_INT8,   1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_MOBILEIP,       DHCP_OPTION_IP,     0, -1 , FALSE},\r
-  {DHCP_TAG_SMTP,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_POP3,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_NNTP,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_WWW,            DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_FINGER,         DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_IRC,            DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_STTALK,         DHCP_OPTION_IP,     1, -1 , FALSE},\r
-  {DHCP_TAG_STDA,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
-\r
-  {DHCP_TAG_CLASSLESS_ROUTE,DHCP_OPTION_INT8,   5, -1 , FALSE},\r
+  {DHCP4_TAG_NETMASK,        DHCP_OPTION_IP,     1, 1  , TRUE},\r
+  {DHCP4_TAG_TIME_OFFSET,    DHCP_OPTION_INT32,  1, 1  , FALSE},\r
+  {DHCP4_TAG_ROUTER,         DHCP_OPTION_IP,     1, -1 , TRUE},\r
+  {DHCP4_TAG_TIME_SERVER,    DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_NAME_SERVER,    DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_DNS_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_LOG_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_COOKIE_SERVER,  DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_LPR_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_IMPRESS_SERVER, DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_RL_SERVER,      DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_HOSTNAME,       DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_BOOTFILE_LEN,   DHCP_OPTION_INT16,  1, 1  , FALSE},\r
+  {DHCP4_TAG_DUMP,           DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_DOMAINNAME,     DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_SWAP_SERVER,    DHCP_OPTION_IP,     1, 1  , FALSE},\r
+  {DHCP4_TAG_ROOTPATH,       DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_EXTEND_PATH,    DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_IPFORWARD,      DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_NONLOCAL_SRR,   DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_POLICY_SRR,     DHCP_OPTION_IPPAIR, 1, -1 , FALSE},\r
+  {DHCP4_TAG_EMTU,           DHCP_OPTION_INT16,  1, 1  , FALSE},\r
+  {DHCP4_TAG_TTL,            DHCP_OPTION_INT8,   1, 1  , FALSE},\r
+  {DHCP4_TAG_PATHMTU_AGE,    DHCP_OPTION_INT32,  1, 1  , FALSE},\r
+  {DHCP4_TAG_PATHMTU_PLATEAU,DHCP_OPTION_INT16,  1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_IFMTU,          DHCP_OPTION_INT16,  1, 1  , FALSE},\r
+  {DHCP4_TAG_SUBNET_LOCAL,   DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_BROADCAST,      DHCP_OPTION_IP,     1, 1  , FALSE},\r
+  {DHCP4_TAG_DISCOVER_MASK,  DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_SUPPLY_MASK,    DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_DISCOVER_ROUTE, DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_ROUTER_SOLICIT, DHCP_OPTION_IP,     1, 1  , FALSE},\r
+  {DHCP4_TAG_STATIC_ROUTE,   DHCP_OPTION_IPPAIR, 1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_TRAILER,        DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+  {DHCP4_TAG_ARPAGE,         DHCP_OPTION_INT32,  1, 1  , FALSE},\r
+  {DHCP4_TAG_ETHER_ENCAP,    DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+\r
+  {DHCP4_TAG_TCP_TTL,        DHCP_OPTION_INT8,   1, 1  , FALSE},\r
+  {DHCP4_TAG_KEEP_INTERVAL,  DHCP_OPTION_INT32,  1, 1  , FALSE},\r
+  {DHCP4_TAG_KEEP_GARBAGE,   DHCP_OPTION_SWITCH, 1, 1  , FALSE},\r
+\r
+  {DHCP4_TAG_NIS_DOMAIN,     DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_NIS_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_NTP_SERVER,     DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_VENDOR,         DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_NBNS,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_NBDD,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_NBTYPE,         DHCP_OPTION_INT8,   1, 1  , FALSE},\r
+  {DHCP4_TAG_NBSCOPE,        DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_XFONT,          DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_XDM,            DHCP_OPTION_IP,     1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_REQUEST_IP,     DHCP_OPTION_IP,     1, 1  , FALSE},\r
+  {DHCP4_TAG_LEASE,          DHCP_OPTION_INT32,  1, 1  , TRUE},\r
+  {DHCP4_TAG_OVERLOAD,       DHCP_OPTION_INT8,   1, 1  , TRUE},\r
+  {DHCP4_TAG_MSG_TYPE,       DHCP_OPTION_INT8,   1, 1  , TRUE},\r
+  {DHCP4_TAG_SERVER_ID,      DHCP_OPTION_IP,     1, 1  , TRUE},\r
+  {DHCP4_TAG_PARA_LIST,      DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_MESSAGE,        DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_MAXMSG,         DHCP_OPTION_INT16,  1, 1  , FALSE},\r
+  {DHCP4_TAG_T1,             DHCP_OPTION_INT32,  1, 1  , TRUE},\r
+  {DHCP4_TAG_T2,             DHCP_OPTION_INT32,  1, 1  , TRUE},\r
+  {DHCP4_TAG_VENDOR_CLASS_ID,DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_CLIENT_ID,      DHCP_OPTION_INT8,   2, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_NISPLUS,        DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_NISPLUS_SERVER, DHCP_OPTION_IP,     1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_TFTP,           DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+  {DHCP4_TAG_BOOTFILE,       DHCP_OPTION_INT8,   1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_MOBILEIP,       DHCP_OPTION_IP,     0, -1 , FALSE},\r
+  {DHCP4_TAG_SMTP,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_POP3,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_NNTP,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_WWW,            DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_FINGER,         DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_IRC,            DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_STTALK,         DHCP_OPTION_IP,     1, -1 , FALSE},\r
+  {DHCP4_TAG_STDA,           DHCP_OPTION_IP,     1, -1 , FALSE},\r
+\r
+  {DHCP4_TAG_CLASSLESS_ROUTE,DHCP_OPTION_INT8,   5, -1 , FALSE},\r
 };\r
 \r
 \r
@@ -248,22 +248,22 @@ DhcpGetParameter (
   )\r
 {\r
   switch (Tag) {\r
-  case DHCP_TAG_NETMASK:\r
+  case DHCP4_TAG_NETMASK:\r
     Para->NetMask = NetGetUint32 (Data);\r
     break;\r
 \r
-  case DHCP_TAG_ROUTER:\r
+  case DHCP4_TAG_ROUTER:\r
     //\r
     // Return the first router to consumer which is the preferred one\r
     //\r
     Para->Router = NetGetUint32 (Data);\r
     break;\r
 \r
-  case DHCP_TAG_LEASE:\r
+  case DHCP4_TAG_LEASE:\r
     Para->Lease = NetGetUint32 (Data);\r
     break;\r
 \r
-  case DHCP_TAG_OVERLOAD:\r
+  case DHCP4_TAG_OVERLOAD:\r
     Para->Overload = *Data;\r
 \r
     if ((Para->Overload < 1) || (Para->Overload > 3)) {\r
@@ -271,7 +271,7 @@ DhcpGetParameter (
     }\r
     break;\r
 \r
-  case DHCP_TAG_TYPE:\r
+  case DHCP4_TAG_MSG_TYPE:\r
     Para->DhcpType = *Data;\r
 \r
     if ((Para->DhcpType < 1) || (Para->DhcpType > 9)) {\r
@@ -279,15 +279,15 @@ DhcpGetParameter (
     }\r
     break;\r
 \r
-  case DHCP_TAG_SERVER_ID:\r
+  case DHCP4_TAG_SERVER_ID:\r
     Para->ServerId = NetGetUint32 (Data);\r
     break;\r
 \r
-  case DHCP_TAG_T1:\r
+  case DHCP4_TAG_T1:\r
     Para->T1 = NetGetUint32 (Data);\r
     break;\r
 \r
-  case DHCP_TAG_T2:\r
+  case DHCP4_TAG_T2:\r
     Para->T2 = NetGetUint32 (Data);\r
     break;\r
   }\r
@@ -299,13 +299,13 @@ DhcpGetParameter (
 /**\r
   Inspect all the options in a single buffer. DHCP options may be contained\r
   in several buffers, such as the BOOTP options filed, boot file or server\r
-  name. Each option buffer is required to end with DHCP_TAG_EOP.\r
+  name. Each option buffer is required to end with DHCP4_TAG_EOP.\r
 \r
   @param[in]  Buffer                 The buffer which contains DHCP options\r
   @param[in]  BufLen                 The length of the buffer\r
   @param[in]  Check                  The callback function for each option found\r
   @param[in]  Context                The opaque parameter for the Check\r
-  @param[out] Overload               Variable to save the value of DHCP_TAG_OVERLOAD\r
+  @param[out] Overload               Variable to save the value of DHCP4_TAG_OVERLOAD\r
                                      option.\r
 \r
   @retval EFI_SUCCESS            All the options are valid\r
@@ -330,10 +330,10 @@ DhcpIterateBufferOptions (
   while (Cur < BufLen) {\r
     Tag = Buffer[Cur];\r
 \r
-    if (Tag == DHCP_TAG_PAD) {\r
+    if (Tag == DHCP4_TAG_PAD) {\r
       Cur++;\r
       continue;\r
-    } else if (Tag == DHCP_TAG_EOP) {\r
+    } else if (Tag == DHCP4_TAG_EOP) {\r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -349,7 +349,7 @@ DhcpIterateBufferOptions (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    if ((Tag == DHCP_TAG_OVERLOAD) && (Overload != NULL)) {\r
+    if ((Tag == DHCP4_TAG_OVERLOAD) && (Overload != NULL)) {\r
       if (Len != 1) {\r
         return EFI_INVALID_PARAMETER;\r
       }\r
@@ -542,6 +542,7 @@ DhcpFillOption (
   @param[out] OptionPoint            The array that contains the DHCP options. Caller\r
                                      should free it.\r
 \r
+  @retval EFI_NOT_FOUND          Cannot find any option.\r
   @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory to parse the packet.\r
   @retval EFI_INVALID_PARAMETER  The options are mal-formated\r
   @retval EFI_SUCCESS            The options are parsed into OptionPoint\r
@@ -610,7 +611,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 = AllocateZeroPool (OptNum * sizeof (DHCP_OPTION) + TotalLen);\r
+  Options = AllocateZeroPool ((UINTN) (OptNum * sizeof (DHCP_OPTION)) + TotalLen);\r
 \r
   if (Options == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -624,14 +625,14 @@ DhcpParseOption (
   Status          = DhcpIterateOptions (Packet, DhcpFillOption, &Context);\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (Options);\r
+    FreePool (Options);\r
     goto ON_EXIT;\r
   }\r
 \r
   *OptionPoint = Options;\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (OptCount);\r
+  FreePool (OptCount);\r
   return Status;\r
 }\r
 \r
@@ -673,13 +674,13 @@ DhcpValidateOptions (
   if (EFI_ERROR (Status) || (Count == 0)) {\r
     return Status;\r
   }\r
+  ASSERT (AllOption != NULL);\r
 \r
   Updated = FALSE;\r
   ZeroMem (&Parameter, sizeof (Parameter));\r
 \r
   for (Index = 0; Index < Count; Index++) {\r
     Option = &AllOption[Index];\r
-    ASSERT (Option != NULL);\r
 \r
     //\r
     // Find the format of the option then validate it.\r
@@ -709,16 +710,15 @@ DhcpValidateOptions (
   }\r
 \r
   if (Updated && (Para != NULL)) {\r
-    if ((*Para = AllocatePool (sizeof (DHCP_PARAMETER))) == NULL) {\r
+    *Para = AllocateCopyPool (sizeof (DHCP_PARAMETER), &Parameter);\r
+    if (*Para == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ON_EXIT;\r
     }\r
-\r
-    CopyMem (*Para, &Parameter, sizeof (**Para));\r
   }\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (AllOption);\r
+  FreePool (AllOption);\r
   return Status;\r
 }\r
 \r
@@ -754,7 +754,7 @@ DhcpAppendOption (
 \r
     *(Buf++) = Tag;\r
     *(Buf++) = (UINT8) Len;\r
-    CopyMem (Buf, Data + Index * 255, Len);\r
+    CopyMem (Buf, Data + Index * 255, (UINTN) Len);\r
 \r
     Buf     += Len;\r
   }\r
@@ -825,8 +825,10 @@ DhcpBuild (
     goto ON_ERROR;\r
   }\r
 \r
-  for (Index = 0; Index < (UINT32) Count; Index++) {\r
-    Mark[SeedOptions[Index].Tag] = SeedOptions[Index];\r
+  if (SeedOptions != NULL) {\r
+    for (Index = 0; Index < (UINT32) Count; Index++) {\r
+      Mark[SeedOptions[Index].Tag] = SeedOptions[Index];\r
+    }\r
   }\r
 \r
   //\r
@@ -877,7 +879,7 @@ DhcpBuild (
     }\r
   }\r
 \r
-  *(Buf++)        = DHCP_TAG_EOP;\r
+  *(Buf++)        = DHCP4_TAG_EOP;\r
   Packet->Length  = sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32)\r
                       + (UINT32) (Buf - Packet->Dhcp4.Option);\r
 \r
@@ -886,9 +888,9 @@ DhcpBuild (
 \r
 ON_ERROR:\r
   if (SeedOptions != NULL) {\r
-    gBS->FreePool (SeedOptions);\r
+    FreePool (SeedOptions);\r
   }\r
 \r
-  gBS->FreePool (Mark);\r
+  FreePool (Mark);\r
   return Status;\r
 }\r