]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
MdeModulePkg: Remove DHCP4.TransmitReceive()and DORA process dependency.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index 2af4888d5c42db11ff4f9afc6d1b11b834b4588a..995bbcf840bfdd5201e7b798c543c57117853567 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 - 2014, 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
@@ -313,6 +318,7 @@ DhcpComputeLease (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 DhcpConfigLeaseIoPort (\r
   IN UDP_IO                 *UdpIo,\r
   IN VOID                   *Context\r
@@ -398,6 +404,7 @@ DhcpLeaseAcquired (
 \r
   if (DhcpSb->Netmask == 0) {\r
     Class           = NetGetIpClass (DhcpSb->ClientAddr);\r
+    ASSERT (Class < IP4_ADDR_CLASSE);\r
     DhcpSb->Netmask = gIp4AllMasks[Class << 3];\r
   }\r
 \r
@@ -947,6 +954,7 @@ ON_EXIT:
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpInput (\r
   NET_BUF                   *UdpPacket,\r
   UDP_END_POINT             *EndPoint,\r
@@ -965,11 +973,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
@@ -1100,6 +1108,7 @@ RESTART:
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpReleasePacket (\r
   IN VOID                   *Arg\r
   )\r
@@ -1118,6 +1127,7 @@ DhcpReleasePacket (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpOnPacketSent (\r
   NET_BUF                   *Packet,\r
   UDP_END_POINT             *EndPoint,\r
@@ -1214,6 +1224,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
@@ -1425,7 +1446,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
@@ -1498,6 +1524,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
@@ -1512,8 +1545,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
@@ -1587,6 +1622,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
@@ -1607,6 +1646,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