]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
Scrubbed part of the code.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index d021d1c02e1d0d06d37209c08ea37eb27dcbab01..da42e670b5ce381f4770df7febe2c722a2a064e6 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
 /** @file\r
 \r
-Copyright (c) 2006 - 2007, 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
 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
@@ -33,6 +33,7 @@ UINT32  mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 };
   @param  DhcpSb                The DHCP service instance\r
 \r
   @retval EFI_SUCCESS           The request has been sent\r
   @param  DhcpSb                The DHCP service instance\r
 \r
   @retval EFI_SUCCESS           The request has been sent\r
+  @retval other                 Some error occurs when sending the request.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
@@ -82,7 +83,6 @@ DhcpInitRequest (
   @retval EFI_ABORTED           The user function ask it to abort.\r
 \r
 **/\r
   @retval EFI_ABORTED           The user function ask it to abort.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpCallUser (\r
   IN  DHCP_SERVICE          *DhcpSb,\r
 EFI_STATUS\r
 DhcpCallUser (\r
   IN  DHCP_SERVICE          *DhcpSb,\r
@@ -141,7 +141,7 @@ DhcpCallUser (
   Notify the user about the operation result.\r
 \r
   @param  DhcpSb                DHCP service instance\r
   Notify the user about the operation result.\r
 \r
   @param  DhcpSb                DHCP service instance\r
-  @param  Which                 which notify function to signal\r
+  @param  Which                 Which notify function to signal\r
 \r
   @return None\r
 \r
 \r
   @return None\r
 \r
@@ -159,14 +159,16 @@ DhcpNotifyUser (
   }\r
 \r
   if ((Child->CompletionEvent != NULL) &&\r
   }\r
 \r
   if ((Child->CompletionEvent != NULL) &&\r
-     ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))) {\r
+      ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))\r
+      ) {\r
 \r
     gBS->SignalEvent (Child->CompletionEvent);\r
     Child->CompletionEvent = NULL;\r
   }\r
 \r
   if ((Child->RenewRebindEvent != NULL) &&\r
 \r
     gBS->SignalEvent (Child->CompletionEvent);\r
     Child->CompletionEvent = NULL;\r
   }\r
 \r
   if ((Child->RenewRebindEvent != NULL) &&\r
-     ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))) {\r
+      ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))\r
+      ) {\r
 \r
     gBS->SignalEvent (Child->RenewRebindEvent);\r
     Child->RenewRebindEvent = NULL;\r
 \r
     gBS->SignalEvent (Child->RenewRebindEvent);\r
     Child->RenewRebindEvent = NULL;\r
@@ -192,9 +194,9 @@ DhcpNotifyUser (
 **/\r
 EFI_STATUS\r
 DhcpSetState (\r
 **/\r
 EFI_STATUS\r
 DhcpSetState (\r
-  IN DHCP_SERVICE           *DhcpSb,\r
-  IN INTN                   State,\r
-  IN BOOLEAN                CallUser\r
+  IN OUT DHCP_SERVICE           *DhcpSb,\r
+  IN     INTN                   State,\r
+  IN     BOOLEAN                CallUser\r
   )\r
 {\r
   EFI_STATUS                Status;\r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -250,10 +252,9 @@ DhcpSetState (
   @return None\r
 \r
 **/\r
   @return None\r
 \r
 **/\r
-STATIC\r
 VOID\r
 DhcpSetTransmitTimer (\r
 VOID\r
 DhcpSetTransmitTimer (\r
-  IN DHCP_SERVICE           *DhcpSb\r
+  IN OUT DHCP_SERVICE           *DhcpSb\r
   )\r
 {\r
   UINT32                    *Times;\r
   )\r
 {\r
   UINT32                    *Times;\r
@@ -272,9 +273,7 @@ DhcpSetTransmitTimer (
 \r
   DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
 \r
 \r
   DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
 \r
-  if (DhcpSb->DhcpState == Dhcp4Selecting) {\r
-    DhcpSb->WaitOffer = DhcpSb->PacketToLive;\r
-  }\r
+  return;\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -289,11 +288,10 @@ DhcpSetTransmitTimer (
   @return None\r
 \r
 **/\r
   @return None\r
 \r
 **/\r
-STATIC\r
 VOID\r
 DhcpComputeLease (\r
 VOID\r
 DhcpComputeLease (\r
-  IN DHCP_SERVICE           *DhcpSb,\r
-  IN DHCP_PARAMETER         *Para\r
+  IN OUT DHCP_SERVICE           *DhcpSb,\r
+  IN     DHCP_PARAMETER         *Para\r
   )\r
 {\r
   ASSERT (Para != NULL);\r
   )\r
 {\r
   ASSERT (Para != NULL);\r
@@ -322,7 +320,7 @@ DhcpComputeLease (
   such as DHCP release.\r
 \r
   @param  UdpIo                 The UDP IO port to configure\r
   such as DHCP release.\r
 \r
   @param  UdpIo                 The UDP IO port to configure\r
-  @param  Context               The opaque parameter to the function.\r
+  @param  Context               Dhcp service instance.\r
 \r
   @retval EFI_SUCCESS           The UDP IO port is successfully configured.\r
   @retval Others                It failed to configure the port.\r
 \r
   @retval EFI_SUCCESS           The UDP IO port is successfully configured.\r
   @retval Others                It failed to configure the port.\r
@@ -358,12 +356,12 @@ DhcpConfigLeaseIoPort (
   UdpConfigData.RemotePort          = DHCP_SERVER_PORT;\r
 \r
   Ip = HTONL (DhcpSb->ClientAddr);\r
   UdpConfigData.RemotePort          = DHCP_SERVER_PORT;\r
 \r
   Ip = HTONL (DhcpSb->ClientAddr);\r
-  NetCopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   Ip = HTONL (DhcpSb->Netmask);\r
 \r
   Ip = HTONL (DhcpSb->Netmask);\r
-  NetCopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
 \r
-  NetZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);\r
 \r
 \r
   Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);\r
 \r
@@ -375,10 +373,10 @@ DhcpConfigLeaseIoPort (
   // Add a default route if received from the server.\r
   //\r
   if ((DhcpSb->Para != NULL) && (DhcpSb->Para->Router != 0)) {\r
   // Add a default route if received from the server.\r
   //\r
   if ((DhcpSb->Para != NULL) && (DhcpSb->Para->Router != 0)) {\r
-    NetZeroMem (&Subnet, sizeof (EFI_IPv4_ADDRESS));\r
+    ZeroMem (&Subnet, sizeof (EFI_IPv4_ADDRESS));\r
 \r
     Ip = HTONL (DhcpSb->Para->Router);\r
 \r
     Ip = HTONL (DhcpSb->Para->Router);\r
-    NetCopyMem (&Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+    CopyMem (&Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
     UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &Subnet, &Subnet, &Gateway);\r
   }\r
 \r
     UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &Subnet, &Subnet, &Gateway);\r
   }\r
@@ -398,10 +396,9 @@ DhcpConfigLeaseIoPort (
   @retval EFI_SUCCESS           The lease is recorded.\r
 \r
 **/\r
   @retval EFI_SUCCESS           The lease is recorded.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpLeaseAcquired (\r
 EFI_STATUS\r
 DhcpLeaseAcquired (\r
-  IN DHCP_SERVICE           *DhcpSb\r
+  IN OUT DHCP_SERVICE           *DhcpSb\r
   )\r
 {\r
   INTN                      Class;\r
   )\r
 {\r
   INTN                      Class;\r
@@ -415,7 +412,7 @@ DhcpLeaseAcquired (
 \r
   if (DhcpSb->Netmask == 0) {\r
     Class           = NetGetIpClass (DhcpSb->ClientAddr);\r
 \r
   if (DhcpSb->Netmask == 0) {\r
     Class           = NetGetIpClass (DhcpSb->ClientAddr);\r
-    DhcpSb->Netmask = mIp4AllMasks[Class << 3];\r
+    DhcpSb->Netmask = gIp4AllMasks[Class << 3];\r
   }\r
 \r
   if (DhcpSb->LeaseIoPort != NULL) {\r
   }\r
 \r
   if (DhcpSb->LeaseIoPort != NULL) {\r
@@ -465,17 +462,17 @@ DhcpCleanLease (
   DhcpSb->ServerAddr  = 0;\r
 \r
   if (DhcpSb->LastOffer != NULL) {\r
   DhcpSb->ServerAddr  = 0;\r
 \r
   if (DhcpSb->LastOffer != NULL) {\r
-    NetFreePool (DhcpSb->LastOffer);\r
+    gBS->FreePool (DhcpSb->LastOffer);\r
     DhcpSb->LastOffer = NULL;\r
   }\r
 \r
   if (DhcpSb->Selected != NULL) {\r
     DhcpSb->LastOffer = NULL;\r
   }\r
 \r
   if (DhcpSb->Selected != NULL) {\r
-    NetFreePool (DhcpSb->Selected);\r
+    gBS->FreePool (DhcpSb->Selected);\r
     DhcpSb->Selected = NULL;\r
   }\r
 \r
   if (DhcpSb->Para != NULL) {\r
     DhcpSb->Selected = NULL;\r
   }\r
 \r
   if (DhcpSb->Para != NULL) {\r
-    NetFreePool (DhcpSb->Para);\r
+    gBS->FreePool (DhcpSb->Para);\r
     DhcpSb->Para = NULL;\r
   }\r
 \r
     DhcpSb->Para = NULL;\r
   }\r
 \r
@@ -497,7 +494,6 @@ DhcpCleanLease (
   DhcpSb->PacketToLive  = 0;\r
   DhcpSb->CurRetry      = 0;\r
   DhcpSb->MaxRetries    = 0;\r
   DhcpSb->PacketToLive  = 0;\r
   DhcpSb->CurRetry      = 0;\r
   DhcpSb->MaxRetries    = 0;\r
-  DhcpSb->WaitOffer     = 0;\r
   DhcpSb->LeaseLife     = 0;\r
 }\r
 \r
   DhcpSb->LeaseLife     = 0;\r
 }\r
 \r
@@ -512,7 +508,6 @@ DhcpCleanLease (
   @retval EFI_SUCCESS           One of the offer is selected.\r
 \r
 **/\r
   @retval EFI_SUCCESS           One of the offer is selected.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpChooseOffer (\r
   IN DHCP_SERVICE           *DhcpSb\r
 EFI_STATUS\r
 DhcpChooseOffer (\r
   IN DHCP_SERVICE           *DhcpSb\r
@@ -525,11 +520,6 @@ DhcpChooseOffer (
 \r
   ASSERT (DhcpSb->LastOffer != NULL);\r
 \r
 \r
   ASSERT (DhcpSb->LastOffer != NULL);\r
 \r
-  //\r
-  // Stop waiting more offers\r
-  //\r
-  DhcpSb->WaitOffer = 0;\r
-\r
   //\r
   // User will cache previous offers if he wants to select\r
   // from multiple offers. If user provides an invalid packet,\r
   //\r
   // User will cache previous offers if he wants to select\r
   // from multiple offers. If user provides an invalid packet,\r
@@ -545,10 +535,10 @@ DhcpChooseOffer (
   Selected = DhcpSb->LastOffer;\r
 \r
   if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) {\r
   Selected = DhcpSb->LastOffer;\r
 \r
   if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) {\r
-    TempPacket = (EFI_DHCP4_PACKET *) NetAllocatePool (NewPacket->Size);\r
+    TempPacket = (EFI_DHCP4_PACKET *) AllocatePool (NewPacket->Size);\r
     if (TempPacket != NULL) {\r
     if (TempPacket != NULL) {\r
-      NetCopyMem (TempPacket, NewPacket, NewPacket->Size);\r
-      NetFreePool (Selected);\r
+      CopyMem (TempPacket, NewPacket, NewPacket->Size);\r
+      gBS->FreePool (Selected);\r
       Selected = TempPacket;\r
     }\r
   }\r
       Selected = TempPacket;\r
     }\r
   }\r
@@ -599,7 +589,6 @@ DhcpChooseOffer (
   @return None\r
 \r
 **/\r
   @return None\r
 \r
 **/\r
-STATIC\r
 VOID\r
 DhcpEndSession (\r
   IN DHCP_SERVICE           *DhcpSb,\r
 VOID\r
 DhcpEndSession (\r
   IN DHCP_SERVICE           *DhcpSb,\r
@@ -631,7 +620,6 @@ DhcpEndSession (
   @retval Others                Some error occured.\r
 \r
 **/\r
   @retval Others                Some error occured.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpHandleSelect (\r
   IN DHCP_SERVICE           *DhcpSb,\r
 EFI_STATUS\r
 DhcpHandleSelect (\r
   IN DHCP_SERVICE           *DhcpSb,\r
@@ -650,7 +638,8 @@ DhcpHandleSelect (
   // Don't return a error for these two case otherwise the session is ended.\r
   //\r
   if (!DHCP_IS_BOOTP (Para) &&\r
   // Don't return a error for these two case otherwise the session is ended.\r
   //\r
   if (!DHCP_IS_BOOTP (Para) &&\r
-     ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))) {\r
+      ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))\r
+      ) {\r
     goto ON_EXIT;\r
   }\r
 \r
     goto ON_EXIT;\r
   }\r
 \r
@@ -664,7 +653,7 @@ DhcpHandleSelect (
 \r
   if (Status == EFI_SUCCESS) {\r
     if (DhcpSb->LastOffer != NULL) {\r
 \r
   if (Status == EFI_SUCCESS) {\r
     if (DhcpSb->LastOffer != NULL) {\r
-      NetFreePool (DhcpSb->LastOffer);\r
+      gBS->FreePool (DhcpSb->LastOffer);\r
     }\r
 \r
     DhcpSb->LastOffer = Packet;\r
     }\r
 \r
     DhcpSb->LastOffer = Packet;\r
@@ -673,7 +662,7 @@ DhcpHandleSelect (
 \r
   } else if (Status == EFI_NOT_READY) {\r
     if (DhcpSb->LastOffer != NULL) {\r
 \r
   } else if (Status == EFI_NOT_READY) {\r
     if (DhcpSb->LastOffer != NULL) {\r
-      NetFreePool (DhcpSb->LastOffer);\r
+      gBS->FreePool (DhcpSb->LastOffer);\r
     }\r
 \r
     DhcpSb->LastOffer = Packet;\r
     }\r
 \r
     DhcpSb->LastOffer = Packet;\r
@@ -689,7 +678,7 @@ DhcpHandleSelect (
   return EFI_SUCCESS;\r
 \r
 ON_EXIT:\r
   return EFI_SUCCESS;\r
 \r
 ON_EXIT:\r
-  NetFreePool (Packet);\r
+  gBS->FreePool (Packet);\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
@@ -706,7 +695,6 @@ ON_EXIT:
   @retval Others                Some error occured.\r
 \r
 **/\r
   @retval Others                Some error occured.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpHandleRequest (\r
   IN DHCP_SERVICE           *DhcpSb,\r
 EFI_STATUS\r
 DhcpHandleRequest (\r
   IN DHCP_SERVICE           *DhcpSb,\r
@@ -728,8 +716,9 @@ DhcpHandleRequest (
   // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK.\r
   //\r
   if (DHCP_IS_BOOTP (Para) ||\r
   // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK.\r
   //\r
   if (DHCP_IS_BOOTP (Para) ||\r
-     (Para->ServerId != DhcpSb->Para->ServerId) ||\r
-     ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) {\r
+      (Para->ServerId != DhcpSb->Para->ServerId) ||\r
+      ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
+      ) {\r
 \r
     Status = EFI_SUCCESS;\r
     goto ON_EXIT;\r
 \r
     Status = EFI_SUCCESS;\r
     goto ON_EXIT;\r
@@ -775,14 +764,14 @@ DhcpHandleRequest (
   DhcpSb->IoStatus = EFI_SUCCESS;\r
   DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_COMPLETION);\r
 \r
   DhcpSb->IoStatus = EFI_SUCCESS;\r
   DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_COMPLETION);\r
 \r
-  NetFreePool (Packet);\r
+  gBS->FreePool (Packet);\r
   return EFI_SUCCESS;\r
 \r
 REJECT:\r
   DhcpSendMessage (DhcpSb, DhcpSb->Selected, DhcpSb->Para, DHCP_MSG_DECLINE, Message);\r
 \r
 ON_EXIT:\r
   return EFI_SUCCESS;\r
 \r
 REJECT:\r
   DhcpSendMessage (DhcpSb, DhcpSb->Selected, DhcpSb->Para, DHCP_MSG_DECLINE, Message);\r
 \r
 ON_EXIT:\r
-  NetFreePool (Packet);\r
+  gBS->FreePool (Packet);\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
@@ -799,7 +788,6 @@ ON_EXIT:
   @retval Others                Some error occured.\r
 \r
 **/\r
   @retval Others                Some error occured.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpHandleRenewRebind (\r
   IN DHCP_SERVICE           *DhcpSb,\r
 EFI_STATUS\r
 DhcpHandleRenewRebind (\r
   IN DHCP_SERVICE           *DhcpSb,\r
@@ -820,8 +808,9 @@ DhcpHandleRenewRebind (
   // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
   //\r
   if (DHCP_IS_BOOTP (Para) ||\r
   // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
   //\r
   if (DHCP_IS_BOOTP (Para) ||\r
-     (Para->ServerId != DhcpSb->Para->ServerId) ||\r
-     ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) {\r
+      (Para->ServerId != DhcpSb->Para->ServerId) ||\r
+      ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
+      ) {\r
 \r
     Status = EFI_SUCCESS;\r
     goto ON_EXIT;\r
 \r
     Status = EFI_SUCCESS;\r
     goto ON_EXIT;\r
@@ -858,7 +847,7 @@ DhcpHandleRenewRebind (
   DhcpSb->LeaseLife = 0;\r
   DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);\r
 \r
   DhcpSb->LeaseLife = 0;\r
   DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);\r
 \r
-  if (DhcpSb->ExtraRefresh) {\r
+  if (DhcpSb->ExtraRefresh != 0) {\r
     DhcpSb->ExtraRefresh  = FALSE;\r
 \r
     DhcpSb->IoStatus      = EFI_SUCCESS;\r
     DhcpSb->ExtraRefresh  = FALSE;\r
 \r
     DhcpSb->IoStatus      = EFI_SUCCESS;\r
@@ -866,7 +855,7 @@ DhcpHandleRenewRebind (
   }\r
 \r
 ON_EXIT:\r
   }\r
 \r
 ON_EXIT:\r
-  NetFreePool (Packet);\r
+  gBS->FreePool (Packet);\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
@@ -883,7 +872,6 @@ ON_EXIT:
   @retval Others                Some error occured.\r
 \r
 **/\r
   @retval Others                Some error occured.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 DhcpHandleReboot (\r
   IN DHCP_SERVICE           *DhcpSb,\r
 EFI_STATUS\r
 DhcpHandleReboot (\r
   IN DHCP_SERVICE           *DhcpSb,\r
@@ -900,7 +888,8 @@ DhcpHandleReboot (
   // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
   //\r
   if (DHCP_IS_BOOTP (Para) ||\r
   // Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
   //\r
   if (DHCP_IS_BOOTP (Para) ||\r
-     ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) {\r
+      ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
+      ) {\r
 \r
     Status = EFI_SUCCESS;\r
     goto ON_EXIT;\r
 \r
     Status = EFI_SUCCESS;\r
     goto ON_EXIT;\r
@@ -935,7 +924,7 @@ DhcpHandleReboot (
   //\r
   // OK, get the parameter from server, record the lease\r
   //\r
   //\r
   // OK, get the parameter from server, record the lease\r
   //\r
-  DhcpSb->Para = NetAllocatePool (sizeof (DHCP_PARAMETER));\r
+  DhcpSb->Para = AllocatePool (sizeof (DHCP_PARAMETER));\r
 \r
   if (DhcpSb->Para == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
 \r
   if (DhcpSb->Para == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -956,13 +945,13 @@ DhcpHandleReboot (
   return EFI_SUCCESS;\r
 \r
 ON_EXIT:\r
   return EFI_SUCCESS;\r
 \r
 ON_EXIT:\r
-  NetFreePool (Packet);\r
+  gBS->FreePool (Packet);\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Handle the received DHCP packets. This function drivers the DHCP\r
+  Handle the received DHCP packets. This function drives the DHCP\r
   state machine.\r
 \r
   @param  UdpPacket             The UDP packets received.\r
   state machine.\r
 \r
   @param  UdpPacket             The UDP packets received.\r
@@ -1018,7 +1007,7 @@ DhcpInput (
   // Copy the DHCP message to a continuous memory block\r
   //\r
   Len     = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER);\r
   // Copy the DHCP message to a continuous memory block\r
   //\r
   Len     = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER);\r
-  Packet  = (EFI_DHCP4_PACKET *) NetAllocatePool (Len);\r
+  Packet  = (EFI_DHCP4_PACKET *) AllocatePool (Len);\r
 \r
   if (Packet == NULL) {\r
     goto RESTART;\r
 \r
   if (Packet == NULL) {\r
     goto RESTART;\r
@@ -1037,7 +1026,7 @@ DhcpInput (
   //\r
   if ((Head->OpCode != BOOTP_REPLY) ||\r
       (NTOHL (Head->Xid) != DhcpSb->Xid) ||\r
   //\r
   if ((Head->OpCode != BOOTP_REPLY) ||\r
       (NTOHL (Head->Xid) != DhcpSb->Xid) ||\r
-      !NET_MAC_EQUAL (&DhcpSb->Mac, Head->ClientHwAddr, DhcpSb->HwLen)) {\r
+      (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) {\r
     goto RESTART;\r
   }\r
 \r
     goto RESTART;\r
   }\r
 \r
@@ -1078,7 +1067,7 @@ DhcpInput (
     //\r
     // Ignore the packet in INITREBOOT, INIT and BOUND states\r
     //\r
     //\r
     // Ignore the packet in INITREBOOT, INIT and BOUND states\r
     //\r
-    NetFreePool (Packet);\r
+    gBS->FreePool (Packet);\r
     Status = EFI_SUCCESS;\r
     break;\r
 \r
     Status = EFI_SUCCESS;\r
     break;\r
 \r
@@ -1093,7 +1082,7 @@ DhcpInput (
   }\r
 \r
   if (Para != NULL) {\r
   }\r
 \r
   if (Para != NULL) {\r
-    NetFreePool (Para);\r
+    gBS->FreePool (Para);\r
   }\r
 \r
   Packet = NULL;\r
   }\r
 \r
   Packet = NULL;\r
@@ -1108,7 +1097,7 @@ RESTART:
   NetbufFree (UdpPacket);\r
 \r
   if (Packet != NULL) {\r
   NetbufFree (UdpPacket);\r
 \r
   if (Packet != NULL) {\r
-    NetFreePool (Packet);\r
+    gBS->FreePool (Packet);\r
   }\r
 \r
   Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
   }\r
 \r
   Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
@@ -1132,7 +1121,7 @@ DhcpReleasePacket (
   IN VOID                   *Arg\r
   )\r
 {\r
   IN VOID                   *Arg\r
   )\r
 {\r
-  NetFreePool (Arg);\r
+  gBS->FreePool (Arg);\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -1176,6 +1165,7 @@ DhcpOnPacketSent (
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate resources for the packet\r
   @retval EFI_ACCESS_DENIED     Failed to transmit the packet through UDP\r
   @retval EFI_SUCCESS           The message is sent\r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate resources for the packet\r
   @retval EFI_ACCESS_DENIED     Failed to transmit the packet through UDP\r
   @retval EFI_SUCCESS           The message is sent\r
+  @retval other                 Other error occurs\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1212,7 +1202,7 @@ DhcpSendMessage (
     Len += (UINT32)AsciiStrLen ((CHAR8 *) Msg);\r
   }\r
 \r
     Len += (UINT32)AsciiStrLen ((CHAR8 *) Msg);\r
   }\r
 \r
-  Packet = NetAllocatePool (Len);\r
+  Packet = AllocatePool (Len);\r
 \r
   if (Packet == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
 \r
   if (Packet == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -1232,7 +1222,7 @@ DhcpSendMessage (
   }\r
 \r
   Head = &Packet->Dhcp4.Header;\r
   }\r
 \r
   Head = &Packet->Dhcp4.Header;\r
-  NetZeroMem (Head, sizeof (EFI_DHCP4_HEADER));\r
+  ZeroMem (Head, sizeof (EFI_DHCP4_HEADER));\r
 \r
   Head->OpCode       = BOOTP_REQUEST;\r
   Head->HwType       = DhcpSb->HwType;\r
 \r
   Head->OpCode       = BOOTP_REQUEST;\r
   Head->HwType       = DhcpSb->HwType;\r
@@ -1241,7 +1231,7 @@ DhcpSendMessage (
   Head->Reserved     = HTONS (0x8000);  //Server, broadcast the message please.\r
 \r
   EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);\r
   Head->Reserved     = HTONS (0x8000);  //Server, broadcast the message please.\r
 \r
   EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);\r
-  NetCopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);\r
+  CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);\r
 \r
   //\r
   // Append the DHCP message type\r
 \r
   //\r
   // Append the DHCP message type\r
@@ -1257,7 +1247,8 @@ DhcpSendMessage (
   //   3. DHCP request to confirm one lease.\r
   //\r
   if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) ||\r
   //   3. DHCP request to confirm one lease.\r
   //\r
   if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) ||\r
-      ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))) {\r
+      ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))\r
+      ) {\r
 \r
     ASSERT ((Para != NULL) && (Para->ServerId != 0));\r
 \r
 \r
     ASSERT ((Para != NULL) && (Para->ServerId != 0));\r
 \r
@@ -1352,15 +1343,25 @@ DhcpSendMessage (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NetFreePool (Packet);\r
+    gBS->FreePool (Packet);\r
     return Status;\r
   }\r
 \r
   if (NewPacket != NULL) {\r
     return Status;\r
   }\r
 \r
   if (NewPacket != NULL) {\r
-    NetFreePool (Packet);\r
+    gBS->FreePool (Packet);\r
     Packet = NewPacket;\r
   }\r
 \r
     Packet = NewPacket;\r
   }\r
 \r
+  //\r
+  // Save the Client Address will be sent out\r
+  //\r
+  CopyMem (\r
+    &DhcpSb->ClientAddressSendOut[0],\r
+    &Packet->Dhcp4.Header.ClientHwAddr[0],\r
+    Packet->Dhcp4.Header.HwAddrLen\r
+    );\r
+\r
+\r
   //\r
   // Wrap it into a netbuf then send it.\r
   //\r
   //\r
   // Wrap it into a netbuf then send it.\r
   //\r
@@ -1369,7 +1370,7 @@ DhcpSendMessage (
   Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);\r
 \r
   if (Wrap == NULL) {\r
   Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);\r
 \r
   if (Wrap == NULL) {\r
-    NetFreePool (Packet);\r
+    gBS->FreePool (Packet);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -1492,33 +1493,30 @@ DhcpOnTimerTick (
   DHCP_SERVICE              *DhcpSb;\r
   DHCP_PROTOCOL             *Instance;\r
   EFI_STATUS                Status;\r
   DHCP_SERVICE              *DhcpSb;\r
   DHCP_PROTOCOL             *Instance;\r
   EFI_STATUS                Status;\r
-  \r
+\r
   DhcpSb   = (DHCP_SERVICE *) Context;\r
   Instance = DhcpSb->ActiveChild;\r
   DhcpSb   = (DHCP_SERVICE *) Context;\r
   Instance = DhcpSb->ActiveChild;\r
-\r
+  \r
   //\r
   //\r
-  // Check the time to wait offer\r
+  // Check the retransmit timer\r
   //\r
   //\r
-  if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) {\r
+  if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {\r
+\r
     //\r
     //\r
-    // OK, offer collection finished, select a offer\r
+    // Select offer at each timeout if any offer received.\r
     //\r
     //\r
-    ASSERT (DhcpSb->DhcpState == Dhcp4Selecting);\r
+    if (DhcpSb->DhcpState == Dhcp4Selecting && DhcpSb->LastOffer != NULL) {\r
 \r
 \r
-    if (DhcpSb->LastOffer == NULL) {\r
-      goto END_SESSION;\r
-    }\r
+      Status = DhcpChooseOffer (DhcpSb);\r
 \r
 \r
-    if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) {\r
-      goto END_SESSION;\r
+      if (EFI_ERROR(Status)) {\r
+        FreePool (DhcpSb->LastOffer);\r
+        DhcpSb->LastOffer = NULL;\r
+      } else {\r
+        goto ON_EXIT;\r
+      }\r
     }\r
     }\r
-  }\r
-  \r
-  //\r
-  // Check the retransmit timer\r
-  //\r
-  if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {\r
-\r
+    \r
     if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) {\r
       //\r
       // Still has another try\r
     if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) {\r
       //\r
       // Still has another try\r
@@ -1526,17 +1524,14 @@ DhcpOnTimerTick (
       DhcpRetransmit (DhcpSb);\r
       DhcpSetTransmitTimer (DhcpSb);\r
 \r
       DhcpRetransmit (DhcpSb);\r
       DhcpSetTransmitTimer (DhcpSb);\r
 \r
-    } else {\r
-      if (!DHCP_CONNECTED (DhcpSb->DhcpState)) {\r
-        goto END_SESSION;\r
-      }\r
+    } else if (DHCP_CONNECTED (DhcpSb->DhcpState)) {\r
 \r
       //\r
       // Retransmission failed, if the DHCP request is initiated by\r
       // user, adjust the current state according to the lease life.\r
       // Otherwise do nothing to wait the lease to timeout\r
       //\r
 \r
       //\r
       // Retransmission failed, if the DHCP request is initiated by\r
       // user, adjust the current state according to the lease life.\r
       // Otherwise do nothing to wait the lease to timeout\r
       //\r
-      if (DhcpSb->ExtraRefresh) {\r
+      if (DhcpSb->ExtraRefresh != 0) {\r
         Status = EFI_SUCCESS;\r
 \r
         if (DhcpSb->LeaseLife < DhcpSb->T1) {\r
         Status = EFI_SUCCESS;\r
 \r
         if (DhcpSb->LeaseLife < DhcpSb->T1) {\r
@@ -1556,6 +1551,8 @@ DhcpOnTimerTick (
         DhcpSb->IoStatus = EFI_TIMEOUT;\r
         DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);\r
       }\r
         DhcpSb->IoStatus = EFI_TIMEOUT;\r
         DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);\r
       }\r
+    } else {\r
+      goto END_SESSION;\r
     }\r
   }\r
   \r
     }\r
   }\r
   \r
@@ -1570,7 +1567,7 @@ DhcpOnTimerTick (
     // Don't timeout the lease, only count the life if user is\r
     // requesting extra renew/rebind. Adjust the state after that.\r
     //\r
     // Don't timeout the lease, only count the life if user is\r
     // requesting extra renew/rebind. Adjust the state after that.\r
     //\r
-    if (DhcpSb->ExtraRefresh) {\r
+    if (DhcpSb->ExtraRefresh != 0) {\r
       return ;\r
     }\r
 \r
       return ;\r
     }\r
 \r
@@ -1622,9 +1619,7 @@ DhcpOnTimerTick (
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  //\r
-  //\r
-  //\r
+ON_EXIT:\r
   if ((Instance != NULL) && (Instance->Token != NULL)) {\r
     Instance->Timeout--;\r
     if (Instance->Timeout == 0) {\r
   if ((Instance != NULL) && (Instance->Token != NULL)) {\r
     Instance->Timeout--;\r
     if (Instance->Timeout == 0) {\r