]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
1. Fix a bug in PXE driver that the PXE boot do not restart if a new boot option...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index 56b03a8a596cebd96ad16be354e78ba6fa3f3243..19ad101d5404d812998568727fdbb7175f43e72c 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
   \r
-Copyright (c) 2006 - 2010, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, 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
@@ -37,6 +37,11 @@ DhcpInitRequest (
 \r
   ASSERT ((DhcpSb->DhcpState == Dhcp4Init) || (DhcpSb->DhcpState == Dhcp4InitReboot));\r
 \r
+  //\r
+  // Clear initial time to make sure that elapsed-time is set to 0 for first Discover or REQUEST message.\r
+  //\r
+  DhcpSb->ActiveChild->ElaspedTime= 0;\r
+  \r
   if (DhcpSb->DhcpState == Dhcp4Init) {\r
     DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE);\r
     Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_DISCOVER, NULL);\r
@@ -967,11 +972,11 @@ DhcpInput (
   DhcpSb  = (DHCP_SERVICE *) Context;\r
 \r
   //\r
-  // Don't restart receive if error occurs or DHCP is destoried.\r
+  // Don't restart receive if error occurs or DHCP is destroyed.\r
   //\r
   if (EFI_ERROR (IoStatus)) {\r
     return ;\r
-  } else if (DhcpSb->ServiceState == DHCP_DESTORY) {\r
+  } else if (DhcpSb->ServiceState == DHCP_DESTROY) {\r
     NetbufFree (UdpPacket);\r
     return ;\r
   }\r
@@ -1218,6 +1223,17 @@ DhcpSendMessage (
   EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);\r
   CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);\r
 \r
+  if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) {\r
+    Head->Seconds = 0;\r
+  } else if ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting)) {\r
+    //\r
+    // Use the same value as the original DHCPDISCOVER message.\r
+    //\r
+    Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds;\r
+  } else {\r
+    SetElapsedTime(&Head->Seconds, DhcpSb->ActiveChild);\r
+  }\r
+\r
   //\r
   // Append the DHCP message type\r
   //\r
@@ -1429,7 +1445,12 @@ DhcpRetransmit (
 \r
   ASSERT (DhcpSb->LastPacket != NULL);\r
 \r
-  DhcpSb->LastPacket->Dhcp4.Header.Seconds = HTONS (*(UINT16 *)(&DhcpSb->LastTimeout));\r
+  //\r
+  // For REQUEST message in Dhcp4Requesting state, do not change the secs fields.\r
+  //\r
+  if (DhcpSb->DhcpState != Dhcp4Requesting) {\r
+    SetElapsedTime(&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);\r
+  }\r
 \r
   //\r
   // Wrap it into a netbuf then send it.\r
@@ -1502,6 +1523,13 @@ DhcpOnTimerTick (
 \r
   DhcpSb   = (DHCP_SERVICE *) Context;\r
   Instance = DhcpSb->ActiveChild;\r
+\r
+  //\r
+  // 0xffff is the maximum supported value for elapsed time according to RFC.\r
+  //\r
+  if (Instance != NULL && Instance->ElaspedTime < 0xffff) {\r
+    Instance->ElaspedTime++;\r
+  }\r
   \r
   //\r
   // Check the retransmit timer\r
@@ -1516,8 +1544,10 @@ DhcpOnTimerTick (
       Status = DhcpChooseOffer (DhcpSb);\r
 \r
       if (EFI_ERROR(Status)) {\r
-        FreePool (DhcpSb->LastOffer);\r
-        DhcpSb->LastOffer = NULL;\r
+        if (DhcpSb->LastOffer != NULL) {\r
+          FreePool (DhcpSb->LastOffer);\r
+          DhcpSb->LastOffer = NULL;\r
+        }\r
       } else {\r
         goto ON_EXIT;\r
       }\r
@@ -1591,6 +1621,10 @@ DhcpOnTimerTick (
         goto END_SESSION;\r
       }\r
 \r
+      if (Instance != NULL) {\r
+        Instance->ElaspedTime= 0;\r
+      }      \r
+      \r
       Status = DhcpSendMessage (\r
                  DhcpSb,\r
                  DhcpSb->Selected,\r
@@ -1611,6 +1645,10 @@ DhcpOnTimerTick (
         goto END_SESSION;\r
       }\r
 \r
+      if (Instance != NULL) {\r
+        Instance->ElaspedTime= 0;\r
+      }    \r
+\r
       Status = DhcpSendMessage (\r
                  DhcpSb,\r
                  DhcpSb->Selected,\r