]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
sync comments, fix function header, rename variable name to follow coding style.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcDhcp.c
index c70390ab2e72c9375c78c5b829e84df0e7c7bbd4..eb91307944c7e6f9d7cb041db9368e7585325943 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 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
@@ -401,72 +401,84 @@ PxeBcCheckSelectedOffer (
     if (!PxeBcTryBinl (Private, Private->SelectedOffer - 1)) {\r
       Status = EFI_NO_RESPONSE;\r
     }\r
-  } else if ((SelectedOffer->OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&\r
-           (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL)) {\r
+  } else if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) {\r
     //\r
-    // The selected offer to finish the D.O.R.A. is a DHCP only offer and\r
-    // bootfile name is not provided in this offer, we need try proxy offers\r
-    // to get the bootfile name or the discovery info\r
+    // The selected offer to finish the D.O.R.A. is a DHCP only offer, we need \r
+    // try proxy offers if there are some, othewise the bootfile name must be \r
+    // set in this DHCP only offer.\r
     //\r
-    ProxyOfferIndex = Private->NumOffers;\r
-\r
-    if (Private->SortOffers) {\r
+    if (Private->GotProxyOffer) {\r
       //\r
-      // Choose proxy offer from the type we stored during DHCP offer selection\r
+      // Get rid of the compiler warning.\r
       //\r
-      ASSERT (Private->ProxyIndex[Private->ProxyOfferType] > 0);\r
-\r
-      if (Private->ProxyOfferType == DHCP4_PACKET_TYPE_BINL) {\r
+      ProxyOfferIndex = 0;\r
+      if (Private->SortOffers) {\r
         //\r
-        // We buffer all received BINL proxy offers, try them all one by one\r
+        // The offers are sorted before selecting, the proxy offer type must be\r
+        // already determined.\r
         //\r
-        if (!PxeBcTryBinlProxy (Private, &ProxyOfferIndex)) {\r
-          Status = EFI_NO_RESPONSE;\r
+        ASSERT (Private->ProxyIndex[Private->ProxyOfferType] > 0);\r
+\r
+        if (Private->ProxyOfferType == DHCP4_PACKET_TYPE_BINL) {\r
+          //\r
+          // We buffer all received BINL proxy offers, try them all one by one\r
+          //\r
+          if (!PxeBcTryBinlProxy (Private, &ProxyOfferIndex)) {\r
+            Status = EFI_NO_RESPONSE;\r
+          }\r
+        } else {\r
+          //\r
+          // For other types, only one proxy offer is buffered.\r
+          //\r
+          ProxyOfferIndex = Private->ProxyIndex[Private->ProxyOfferType] - 1;\r
         }\r
       } else {\r
         //\r
-        // For other types, only one proxy offer is buffered.\r
+        // The proxy offer type is not determined, choose proxy offer in the \r
+        // received order.\r
         //\r
-        ProxyOfferIndex = Private->ProxyIndex[Private->ProxyOfferType] - 1;\r
-      }\r
-    } else {\r
-      //\r
-      // Choose proxy offer in the received order.\r
-      //\r
-      Status = EFI_NO_RESPONSE;\r
+        Status = EFI_NO_RESPONSE;\r
 \r
-      for (Index = 0; Index < Private->NumOffers; Index++) {\r
+        for (Index = 0; Index < Private->NumOffers; Index++) {\r
 \r
-        Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\r
-        if (!IS_PROXY_DHCP_OFFER (Offer)) {\r
-          //\r
-          // Skip non proxy dhcp offers.\r
-          //\r
-          continue;\r
-        }\r
-\r
-        if (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL) {\r
-          //\r
-          // Try BINL\r
-          //\r
-          if (!PxeBcTryBinl (Private, Index)) {\r
+          Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\r
+          if (!IS_PROXY_DHCP_OFFER (Offer)) {\r
             //\r
-            // Failed, skip to the next offer\r
+            // Skip non proxy dhcp offers.\r
             //\r
             continue;\r
           }\r
-        }\r
 \r
-        Status = EFI_SUCCESS;\r
-        break;\r
+          if (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL) {\r
+            //\r
+            // Try BINL\r
+            //\r
+            if (!PxeBcTryBinl (Private, Index)) {\r
+              //\r
+              // Failed, skip to the next offer\r
+              //\r
+              continue;\r
+            }\r
+          }\r
+\r
+          Private->ProxyOfferType = Private->Dhcp4Offers[Index].OfferType;\r
+          ProxyOfferIndex         = Index;\r
+          Status                  = EFI_SUCCESS;\r
+          break;\r
+        }\r
       }\r
-    }\r
 \r
-    if (!EFI_ERROR (Status) && (Private->ProxyOfferType != DHCP4_PACKET_TYPE_BINL)) {\r
+      if (!EFI_ERROR (Status) && (Private->ProxyOfferType != DHCP4_PACKET_TYPE_BINL)) {\r
+        //\r
+        // Copy the proxy offer to Mode and set the flag\r
+        //\r
+        PxeBcCopyProxyOffer (Private, ProxyOfferIndex);\r
+      }\r
+    } else {\r
       //\r
-      // Copy the proxy offer to Mode and set the flag\r
+      // No proxy offer is received, the bootfile name MUST be set.\r
       //\r
-      PxeBcCopyProxyOffer (Private, ProxyOfferIndex);\r
+      ASSERT (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r
     }\r
   }\r
 \r
@@ -560,6 +572,8 @@ PxeBcCacheDhcpOffer (
       //\r
       // It's a proxy dhcp offer with no your address, including pxe10, wfm11a or binl offer.\r
       //\r
+      Private->GotProxyOffer = TRUE;\r
+\r
       if (OfferType == DHCP4_PACKET_TYPE_BINL) {\r
         //\r
         // Cache all binl offers.\r
@@ -609,7 +623,6 @@ PxeBcSelectOffer (
   UINT32            Index;\r
   UINT32            OfferIndex;\r
   EFI_DHCP4_PACKET  *Offer;\r
-  BOOLEAN           GotProxyOffer;\r
 \r
   Private->SelectedOffer = 0;\r
 \r
@@ -688,15 +701,6 @@ PxeBcSelectOffer (
     //\r
     // Try the offers in the received order.\r
     //\r
-    GotProxyOffer = FALSE;\r
-    for (Index = 0; Index < DHCP4_PACKET_TYPE_MAX; Index++) {\r
-\r
-      GotProxyOffer = (BOOLEAN) (Private->ProxyIndex[Index] > 0);\r
-      if (GotProxyOffer) {\r
-        break;\r
-      }\r
-    }\r
-\r
     for (Index = 0; Index < Private->NumOffers; Index++) {\r
 \r
       Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\r
@@ -709,7 +713,7 @@ PxeBcSelectOffer (
       }\r
 \r
       if ((Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&\r
-          ((!GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {\r
+          ((!Private->GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {\r
         //\r
         // DHCP only offer but no proxy offer received and no bootfile option in this offer\r
         //\r