]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
Sync the latest version from R8.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index e0fdcd382c66ef0da001dbe5e2ac7dbc4cc24400..442deeb5094317ce3766e179647f9d4c7593ec6b 100644 (file)
@@ -52,8 +52,6 @@ DhcpInitRequest (
       DhcpSb->DhcpState = Dhcp4Init;\r
       return Status;\r
     }\r
-\r
-    DhcpSb->WaitOffer = DHCP_WAIT_OFFER;\r
   } else {\r
     DhcpSetState (DhcpSb, Dhcp4Rebooting, FALSE);\r
     Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_REQUEST, NULL);\r
@@ -120,7 +118,7 @@ DhcpCallUser (
   Status = Config->Dhcp4Callback (\r
                      &DhcpSb->ActiveChild->Dhcp4Protocol,\r
                      Config->CallbackContext,\r
-                     DhcpSb->DhcpState,\r
+                     (EFI_DHCP4_STATE) DhcpSb->DhcpState,\r
                      Event,\r
                      Packet,\r
                      NewPacket\r
@@ -225,7 +223,7 @@ DhcpSetState (
   // This will clear the retry count. This is also why the rule\r
   // first transit the state, then send packets.\r
   //\r
-  if (State == Dhcp4Init) {\r
+  if (State == Dhcp4Selecting) {\r
     DhcpSb->MaxRetries = DhcpSb->ActiveConfig.DiscoverTryCount;\r
   } else {\r
     DhcpSb->MaxRetries = DhcpSb->ActiveConfig.RequestTryCount;\r
@@ -262,7 +260,7 @@ DhcpSetTransmitTimer (
 \r
   ASSERT (DhcpSb->MaxRetries > DhcpSb->CurRetry);\r
 \r
-  if (DhcpSb->DhcpState == Dhcp4Init) {\r
+  if (DhcpSb->DhcpState == Dhcp4Selecting) {\r
     Times = DhcpSb->ActiveConfig.DiscoverTimeout;\r
   } else {\r
     Times = DhcpSb->ActiveConfig.RequestTimeout;\r
@@ -273,8 +271,11 @@ DhcpSetTransmitTimer (
   }\r
 \r
   DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
-}\r
 \r
+  if (DhcpSb->DhcpState == Dhcp4Selecting) {\r
+    DhcpSb->WaitOffer = DhcpSb->PacketToLive;\r
+  }\r
+}\r
 \r
 /**\r
   Compute the lease. If the server grants a permanent lease, just\r
@@ -519,6 +520,7 @@ DhcpChooseOffer (
 {\r
   EFI_DHCP4_PACKET          *Selected;\r
   EFI_DHCP4_PACKET          *NewPacket;\r
+  EFI_DHCP4_PACKET          *TempPacket;\r
   EFI_STATUS                Status;\r
 \r
   ASSERT (DhcpSb->LastOffer != NULL);\r
@@ -542,12 +544,12 @@ DhcpChooseOffer (
 \r
   Selected = DhcpSb->LastOffer;\r
 \r
-  if (NewPacket != NULL) {\r
-    if (EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) {\r
-      NetFreePool (NewPacket);\r
-    } else {\r
+  if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) {\r
+    TempPacket = (EFI_DHCP4_PACKET *) NetAllocatePool (NewPacket->Size);\r
+    if (TempPacket != NULL) {\r
+      NetCopyMem (TempPacket, NewPacket, NewPacket->Size);\r
       NetFreePool (Selected);\r
-      Selected = NewPacket;\r
+      Selected = TempPacket;\r
     }\r
   }\r
 \r
@@ -650,10 +652,6 @@ DhcpHandleSelect (
   //\r
   Head = &Packet->Dhcp4.Header;\r
 \r
-  if (!Ip4IsUnicast (EFI_NTOHL (Head->YourAddr), (Para == NULL ? 0 : Para->NetMask))) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
   if (!DHCP_IS_BOOTP (Para) &&\r
      ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))) {\r
     goto ON_EXIT;\r
@@ -755,15 +753,15 @@ DhcpHandleRequest (
   //\r
   Message = NULL;\r
 \r
-  if (!EFI_IP4_EQUAL (Head->YourAddr, Selected->YourAddr)) {\r
-    Message = "Lease confirmed isn't the same as that in the offer";\r
+  if (!EFI_IP4_EQUAL (&Head->YourAddr, &Selected->YourAddr)) {\r
+    Message = (UINT8 *) "Lease confirmed isn't the same as that in the offer";\r
     goto REJECT;\r
   }\r
 \r
   Status = DhcpCallUser (DhcpSb, Dhcp4RcvdAck, Packet, NULL);\r
 \r
   if (EFI_ERROR (Status)) {\r
-    Message = "Lease is denied upon received ACK";\r
+    Message = (UINT8 *) "Lease is denied upon received ACK";\r
     goto REJECT;\r
   }\r
 \r
@@ -773,7 +771,7 @@ DhcpHandleRequest (
   Status = DhcpLeaseAcquired (DhcpSb);\r
 \r
   if (EFI_ERROR (Status)) {\r
-    Message = "Lease is denied upon entering bound";\r
+    Message = (UINT8 *) "Lease is denied upon entering bound";\r
     goto REJECT;\r
   }\r
 \r
@@ -846,7 +844,7 @@ DhcpHandleRenewRebind (
   // The lease is different from the selected. Don't send a DECLINE\r
   // since it isn't existed in the client's FSM.\r
   //\r
-  if (!EFI_IP4_EQUAL (Head->YourAddr, Selected->YourAddr)) {\r
+  if (!EFI_IP4_EQUAL (&Head->YourAddr, &Selected->YourAddr)) {\r
     goto ON_EXIT;\r
   }\r
 \r
@@ -948,7 +946,7 @@ DhcpHandleReboot (
   }\r
 \r
   DhcpSb->Selected  = Packet;\r
-  CopyMem (DhcpSb->Para, Para, sizeof (DHCP_PARAMETER));\r
+  CopyMem (DhcpSb->Para, Para, sizeof (*DhcpSb->Para));\r
 \r
   Status            = DhcpLeaseAcquired (DhcpSb);\r
 \r
@@ -1214,7 +1212,7 @@ DhcpSendMessage (
   Len = sizeof (EFI_DHCP4_PACKET) + 128 + DhcpSb->UserOptionLen;\r
 \r
   if (Msg != NULL) {\r
-    Len += (UINT32)AsciiStrLen (Msg);\r
+    Len += (UINT32)AsciiStrLen ((CHAR8 *) Msg);\r
   }\r
 \r
   Packet = NetAllocatePool (Len);\r
@@ -1310,7 +1308,7 @@ DhcpSendMessage (
   // Append the user's message if it isn't NULL\r
   //\r
   if (Msg != NULL) {\r
-    Len     = NET_MIN ((UINT32) AsciiStrLen (Msg), 255);\r
+    Len     = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255);\r
     Buf     = DhcpAppendOption (Buf, DHCP_TAG_MESSAGE, (UINT16) Len, Msg);\r
   }\r
 \r
@@ -1495,12 +1493,32 @@ DhcpOnTimerTick (
   )\r
 {\r
   DHCP_SERVICE              *DhcpSb;\r
+  DHCP_PROTOCOL             *Instance;\r
   EFI_STATUS                Status;\r
+  \r
+  DhcpSb   = (DHCP_SERVICE *) Context;\r
+  Instance = DhcpSb->ActiveChild;\r
 \r
-  DhcpSb = (DHCP_SERVICE *) Context;\r
+  //\r
+  // Check the time to wait offer\r
+  //\r
+  if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) {\r
+    //\r
+    // OK, offer collection finished, select a offer\r
+    //\r
+    ASSERT (DhcpSb->DhcpState == Dhcp4Selecting);\r
 \r
+    if (DhcpSb->LastOffer == NULL) {\r
+      goto END_SESSION;\r
+    }\r
+\r
+    if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) {\r
+      goto END_SESSION;\r
+    }\r
+  }\r
+  \r
   //\r
-  // Check the retransmit timer first\r
+  // Check the retransmit timer\r
   //\r
   if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {\r
 \r
@@ -1543,22 +1561,7 @@ DhcpOnTimerTick (
       }\r
     }\r
   }\r
-\r
-  if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) {\r
-    //\r
-    // OK, offer collection finished, select a offer\r
-    //\r
-    ASSERT (DhcpSb->DhcpState == Dhcp4Selecting);\r
-\r
-    if (DhcpSb->LastOffer == NULL) {\r
-      goto END_SESSION;\r
-    }\r
-\r
-    if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) {\r
-      goto END_SESSION;\r
-    }\r
-  }\r
-\r
+  \r
   //\r
   // If an address has been acquired, check whether need to\r
   // refresh or whether it has expired.\r
@@ -1622,6 +1625,16 @@ DhcpOnTimerTick (
     }\r
   }\r
 \r
+  //\r
+  //\r
+  //\r
+  if ((Instance != NULL) && (Instance->Token != NULL)) {\r
+    Instance->Timeout--;\r
+    if (Instance->Timeout == 0) {\r
+      PxeDhcpDone (Instance);\r
+    }\r
+  }\r
+\r
   return ;\r
 \r
 END_SESSION:\r