]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
MdeModulePkg: Update Api from NetLibDetectMedia to NetLibDetectMediaWaitTimeout.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index ba7082e9851c2151e9c3694954312b6f959aa954..3898223af5db37d910862e360bcdff9fbd245a14 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
   \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, 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
@@ -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
@@ -388,8 +393,6 @@ DhcpLeaseAcquired (
   IN OUT DHCP_SERVICE           *DhcpSb\r
   )\r
 {\r
-  INTN                      Class;\r
-\r
   DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr);\r
 \r
   if (DhcpSb->Para != NULL) {\r
@@ -398,8 +401,7 @@ DhcpLeaseAcquired (
   }\r
 \r
   if (DhcpSb->Netmask == 0) {\r
-    Class           = NetGetIpClass (DhcpSb->ClientAddr);\r
-    DhcpSb->Netmask = gIp4AllMasks[Class << 3];\r
+    return EFI_ABORTED;\r
   }\r
 \r
   if (DhcpSb->LeaseIoPort != NULL) {\r
@@ -967,11 +969,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,12 +1220,23 @@ 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
   Packet->Dhcp4.Magik = DHCP_OPTION_MAGIC;\r
   Buf                 = Packet->Dhcp4.Option;\r
-  Buf                 = DhcpAppendOption (Buf, DHCP_TAG_TYPE, 1, &Type);\r
+  Buf                 = DhcpAppendOption (Buf, DHCP4_TAG_MSG_TYPE, 1, &Type);\r
 \r
   //\r
   // Append the serverid option if necessary:\r
@@ -1238,7 +1251,7 @@ DhcpSendMessage (
     ASSERT ((Para != NULL) && (Para->ServerId != 0));\r
 \r
     IpAddr  = HTONL (Para->ServerId);\r
-    Buf     = DhcpAppendOption (Buf, DHCP_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr);\r
+    Buf     = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr);\r
   }\r
 \r
   //\r
@@ -1264,7 +1277,7 @@ DhcpSendMessage (
   }\r
 \r
   if (IpAddr != 0) {\r
-    Buf = DhcpAppendOption (Buf, DHCP_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr);\r
+    Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr);\r
   }\r
 \r
   //\r
@@ -1274,7 +1287,7 @@ DhcpSendMessage (
   //\r
   if ((Type != DHCP_MSG_DECLINE) && (Type != DHCP_MSG_RELEASE)) {\r
     MaxMsg  = HTONS (0xFF00);\r
-    Buf     = DhcpAppendOption (Buf, DHCP_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg);\r
+    Buf     = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg);\r
   }\r
 \r
   //\r
@@ -1282,7 +1295,7 @@ DhcpSendMessage (
   //\r
   if (Msg != NULL) {\r
     Len     = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255);\r
-    Buf     = DhcpAppendOption (Buf, DHCP_TAG_MESSAGE, (UINT16) Len, Msg);\r
+    Buf     = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16) Len, Msg);\r
   }\r
 \r
   //\r
@@ -1295,7 +1308,7 @@ DhcpSendMessage (
       // if it is a DHCP decline or DHCP release .\r
       //\r
       if (((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) &&\r
-          (Config->OptionList[Index]->OpCode != DHCP_TAG_CLIENT_ID)) {\r
+          (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID)) {\r
         continue;\r
       }\r
 \r
@@ -1308,7 +1321,7 @@ DhcpSendMessage (
     }\r
   }\r
 \r
-  *(Buf++) = DHCP_TAG_EOP;\r
+  *(Buf++) = DHCP4_TAG_EOP;\r
   Packet->Length += (UINT32) (Buf - Packet->Dhcp4.Option);\r
 \r
   //\r
@@ -1429,7 +1442,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
@@ -1496,12 +1514,21 @@ DhcpOnTimerTick (
   IN VOID                   *Context\r
   )\r
 {\r
+  LIST_ENTRY                *Entry;\r
+  LIST_ENTRY                *Next;\r
   DHCP_SERVICE              *DhcpSb;\r
   DHCP_PROTOCOL             *Instance;\r
   EFI_STATUS                Status;\r
 \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
@@ -1593,6 +1620,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
@@ -1613,6 +1644,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
@@ -1628,10 +1663,17 @@ DhcpOnTimerTick (
   }\r
 \r
 ON_EXIT:\r
-  if ((Instance != NULL) && (Instance->Token != NULL)) {\r
-    Instance->Timeout--;\r
-    if (Instance->Timeout == 0) {\r
-      PxeDhcpDone (Instance);\r
+  //\r
+  // Iterate through all the DhcpSb Children.\r
+  //\r
+  NET_LIST_FOR_EACH_SAFE (Entry, Next, &DhcpSb->Children) {\r
+    Instance = NET_LIST_USER_STRUCT (Entry, DHCP_PROTOCOL, Link);\r
+    \r
+    if ((Instance != NULL) && (Instance->Token != NULL)) {\r
+      Instance->Timeout--;\r
+      if (Instance->Timeout == 0) {\r
+        PxeDhcpDone (Instance);\r
+      }\r
     }\r
   }\r
 \r