]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
Add Copyright notices and comments for Red Hat contributor.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcDhcp.c
index ce58321eb06ec2e423924657a20b694db9247244..8be753151ccbd578ed1022e54a495130ea80f3dd 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Support for PxeBc dhcp functions.\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013, Red Hat, Inc.\r
+Copyright (c) 2007 - 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
@@ -203,7 +204,7 @@ PxeBcParseCachedDhcpPacket (
             (Offer->Dhcp4.Header.BootFileName[0] != 0)) {\r
     //\r
     // If the bootfile is not present and bootfilename is present in dhcp packet, just parse it.\r
-    // And do not count dhcp option header, or else will destory the serverhostname.\r
+    // And do not count dhcp option header, or else will destroy the serverhostname.\r
     //\r
     Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] -\r
                                             OFFSET_OF (EFI_DHCP4_PACKET_OPTION, Data[0]));\r
@@ -565,7 +566,9 @@ PxeBcCacheDhcpOffer (
   }\r
 \r
   OfferType = CachedOffer->OfferType;\r
-  ASSERT (OfferType < DHCP4_PACKET_TYPE_MAX);\r
+  if (OfferType >= DHCP4_PACKET_TYPE_MAX) {\r
+    return ;\r
+  }\r
 \r
   if (OfferType == DHCP4_PACKET_TYPE_BOOTP) {\r
 \r
@@ -788,7 +791,6 @@ PxeBcDhcpCallBack (
   UINT16                              Value;\r
   EFI_STATUS                          Status;\r
   BOOLEAN                             Received;\r
-  CHAR8                               *SystemSerialNumber;\r
   EFI_DHCP4_HEADER                    *DhcpHeader;\r
 \r
   if ((Dhcp4Event != Dhcp4RcvdOffer) &&\r
@@ -843,7 +845,7 @@ PxeBcDhcpCallBack (
       //\r
       DhcpHeader = &Packet->Dhcp4.Header;\r
 \r
-      if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) DhcpHeader->ClientHwAddr, &SystemSerialNumber))) {\r
+      if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {\r
         //\r
         // GUID not yet set - send all 0xff's to show programable (via SetVariable)\r
         // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);\r
@@ -852,7 +854,7 @@ PxeBcDhcpCallBack (
         ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));\r
       }\r
 \r
-      DhcpHeader->HwAddrLen = sizeof (EFI_GUID);\r
+      DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);\r
     }\r
 \r
     if (Dhcp4Event == Dhcp4SendDiscover) {\r
@@ -928,7 +930,6 @@ PxeBcBuildDhcpOptions (
   UINT32                    Index;\r
   PXEBC_DHCP4_OPTION_ENTRY  OptEnt;\r
   UINT16                    Value;\r
-  CHAR8                     *SystemSerialNumber;\r
 \r
   Index       = 0;\r
   OptList[0]  = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer;\r
@@ -948,7 +949,7 @@ PxeBcBuildDhcpOptions (
     // Append max message size.\r
     //\r
     OptList[Index]->OpCode  = PXEBC_DHCP4_TAG_MAXMSG;\r
-    OptList[Index]->Length  = sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE);\r
+    OptList[Index]->Length  = (UINT8) sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE);\r
     OptEnt.MaxMesgSize      = (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *) OptList[Index]->Data;\r
     Value                   = NTOHS (PXEBC_DHCP4_MAX_PACKET_SIZE);\r
     CopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16));\r
@@ -1003,13 +1004,13 @@ PxeBcBuildDhcpOptions (
   // Append UUID/Guid-based client identifier option\r
   //\r
   OptList[Index]->OpCode  = PXEBC_PXE_DHCP4_TAG_UUID;\r
-  OptList[Index]->Length  = sizeof (PXEBC_DHCP4_OPTION_UUID);\r
+  OptList[Index]->Length  = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UUID);\r
   OptEnt.Uuid             = (PXEBC_DHCP4_OPTION_UUID *) OptList[Index]->Data;\r
   OptEnt.Uuid->Type       = 0;\r
   Index++;\r
   OptList[Index]          = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);\r
 \r
-  if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) OptEnt.Uuid->Guid, &SystemSerialNumber))) {\r
+  if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) {\r
     //\r
     // GUID not yet set - send all 0xff's to show programable (via SetVariable)\r
     // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);\r
@@ -1022,7 +1023,7 @@ PxeBcBuildDhcpOptions (
   // Append client network device interface option\r
   //\r
   OptList[Index]->OpCode  = PXEBC_PXE_DHCP4_TAG_UNDI;\r
-  OptList[Index]->Length  = sizeof (PXEBC_DHCP4_OPTION_UNDI);\r
+  OptList[Index]->Length  = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UNDI);\r
   OptEnt.Undi             = (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->Data;\r
   if (Private->Nii != NULL) {\r
     OptEnt.Undi->Type       = Private->Nii->Type;\r
@@ -1041,7 +1042,7 @@ PxeBcBuildDhcpOptions (
   // Append client system architecture option\r
   //\r
   OptList[Index]->OpCode  = PXEBC_PXE_DHCP4_TAG_ARCH;\r
-  OptList[Index]->Length  = sizeof (PXEBC_DHCP4_OPTION_ARCH);\r
+  OptList[Index]->Length  = (UINT8) sizeof (PXEBC_DHCP4_OPTION_ARCH);\r
   OptEnt.Arch             = (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->Data;\r
   Value                   = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE);\r
   CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));\r
@@ -1052,7 +1053,7 @@ PxeBcBuildDhcpOptions (
   // Append client system architecture option\r
   //\r
   OptList[Index]->OpCode  = PXEBC_DHCP4_TAG_CLASS_ID;\r
-  OptList[Index]->Length  = sizeof (PXEBC_DHCP4_OPTION_CLID);\r
+  OptList[Index]->Length  = (UINT8) sizeof (PXEBC_DHCP4_OPTION_CLID);\r
   OptEnt.Clid             = (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->Data;\r
   CopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_CLID));\r
   CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType));\r
@@ -1120,7 +1121,6 @@ PxeBcDiscvBootService (
   EFI_DHCP4_PACKET_OPTION             *PxeOpt;\r
   PXEBC_OPTION_BOOT_ITEM              *PxeBootItem;\r
   UINT8                               VendorOptLen;\r
-  CHAR8                               *SystemSerialNumber;\r
   EFI_DHCP4_HEADER                    *DhcpHeader;\r
   UINT32                              Xid;\r
 \r
@@ -1149,7 +1149,7 @@ PxeBcDiscvBootService (
     //\r
     // Add vendor option of PXE_BOOT_ITEM\r
     //\r
-    VendorOptLen      = (sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1;\r
+    VendorOptLen = (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1);\r
     OptList[OptCount] = AllocatePool (VendorOptLen);\r
     if (OptList[OptCount] == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -1159,7 +1159,7 @@ PxeBcDiscvBootService (
     OptList[OptCount]->Length     = (UINT8) (VendorOptLen - 2);\r
     PxeOpt                        = (EFI_DHCP4_PACKET_OPTION *) OptList[OptCount]->Data;\r
     PxeOpt->OpCode                = PXEBC_VENDOR_TAG_BOOT_ITEM;\r
-    PxeOpt->Length                = sizeof (PXEBC_OPTION_BOOT_ITEM);\r
+    PxeOpt->Length                = (UINT8) sizeof (PXEBC_OPTION_BOOT_ITEM);\r
     PxeBootItem                   = (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->Data;\r
     PxeBootItem->Type             = HTONS (Type);\r
     PxeBootItem->Layer            = HTONS (*Layer);\r
@@ -1180,14 +1180,14 @@ PxeBcDiscvBootService (
 \r
   DhcpHeader = &Token.Packet->Dhcp4.Header;\r
   if (Mode->SendGUID) {\r
-    if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) DhcpHeader->ClientHwAddr, &SystemSerialNumber))) {\r
+    if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {\r
       //\r
       // GUID not yet set - send all 0's to show not programable\r
       //\r
       ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));\r
     }\r
 \r
-    DhcpHeader->HwAddrLen = sizeof (EFI_GUID);\r
+    DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);\r
   }\r
 \r
   Xid                                 = NET_RANDOM (NetRandomInitSeed ());\r
@@ -1537,6 +1537,19 @@ PxeBcSelectBootPrompt (
   }\r
 \r
   VendorOpt = &Packet->PxeVendorOption;\r
+  //\r
+  // According to the PXE specification 2.1, Table 2-1 PXE DHCP Options  (Full  \r
+  // List), we must not consider a boot prompt or boot menu if all of the  \r
+  // following hold:\r
+  // - the PXE_DISCOVERY_CONTROL PXE tag is present inside the Vendor Options\r
+  //   (=43) DHCP tag, and\r
+  // - the PXE_DISCOVERY_CONTROL PXE tag has bit 3 set, and  \r
+  // - a boot file name has been presented with DHCP option 67.\r
+  //\r
+  if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) &&\r
+      Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {\r
+    return EFI_ABORTED;\r
+  }\r
 \r
   if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {\r
     return EFI_SUCCESS;\r