X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FUefiPxeBcDxe%2FPxeBcDhcp.c;h=fa3594d36b0e17a9f71e79d1d0bea666a33a4d1d;hp=ed7ee73e91e23ca93624b08305cadf0e51488891;hb=75dce340624dba5e4a79b2e5b2dbe943bae0d0e9;hpb=1204fe8319e5e6f77df68c375ef403e9ffa9227e diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c index ed7ee73e91..fa3594d36b 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c @@ -1,8 +1,8 @@ /** @file Support for PxeBc dhcp functions. - -Copyright (c) 2007 - 2009, Intel Corporation.
-All rights reserved. This program and the accompanying materials + +Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -33,7 +33,7 @@ UINT8 mInterestedDhcp4Tags[PXEBC_DHCP4_TAG_INDEX_MAX] = { This function initialize the DHCP4 message instance. This function will pad each item of dhcp4 message packet. - + @param Seed Pointer to the message instance of the DHCP4 packet. @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance. @@ -135,6 +135,7 @@ PxeBcParseCachedDhcpPacket ( EFI_DHCP4_PACKET_OPTION *Option; UINT8 OfferType; UINTN Index; + UINT8 *Ptr8; CachedPacket->IsPxeOffer = FALSE; ZeroMem (CachedPacket->Dhcp4Option, sizeof (CachedPacket->Dhcp4Option)); @@ -181,19 +182,28 @@ PxeBcParseCachedDhcpPacket ( // serverhostname option. // Option = Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD]; - if ((Option != NULL) && (Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE)) { + if ((Option != NULL) && ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) != 0)) { Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = PxeBcParseExtendOptions ( (UINT8 *) Offer->Dhcp4.Header.BootFileName, sizeof (Offer->Dhcp4.Header.BootFileName), PXEBC_DHCP4_TAG_BOOTFILE ); + // + // RFC 2132, Section 9.5 does not strictly state Bootfile name (option 67) is null + // terminated string. So force to append null terminated character at the end of string. + // + if (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) { + Ptr8 = (UINT8*)&Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data[0]; + Ptr8 += Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Length; + *Ptr8 = '\0'; + } } else if ((Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL) && (Offer->Dhcp4.Header.BootFileName[0] != 0)) { // // If the bootfile is not present and bootfilename is present in dhcp packet, just parse it. - // And do not count dhcp option header, or else will destory the serverhostname. + // And do not count dhcp option header, or else will destroy the serverhostname. // Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] - OFFSET_OF (EFI_DHCP4_PACKET_OPTION, Data[0])); @@ -253,9 +263,9 @@ PxeBcParseCachedDhcpPacket ( the index is maximum offer number. @retval TRUE Offer the service successfully under priority BINL. - @retval FALSE Boot Service failed, parse cached dhcp packet failed or this + @retval FALSE Boot Service failed, parse cached dhcp packet failed or this BINL ack cannot find options set or bootfile name specified. - + **/ BOOLEAN PxeBcTryBinl ( @@ -287,8 +297,8 @@ PxeBcTryBinl ( ); } else { CopyMem ( - &ServerIp.Addr[0], - &Offer->Dhcp4.Header.ServerAddr, + &ServerIp.Addr[0], + &Offer->Dhcp4.Header.ServerAddr, sizeof (EFI_IPv4_ADDRESS) ); } @@ -338,7 +348,7 @@ PxeBcTryBinl ( Offer dhcp service for each proxy with a BINL dhcp offer. @param Private Pointer to PxeBc private data - @param OfferIndex Pointer to the index of cached packets as complements of + @param OfferIndex Pointer to the index of cached packets as complements of pxe mode data, the index is maximum offer number. @return If there is no service needed offer return FALSE, otherwise TRUE. @@ -408,8 +418,8 @@ PxeBcCheckSelectedOffer ( } } else if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) { // - // The selected offer to finish the D.O.R.A. is a DHCP only offer, we need - // try proxy offers if there are some, othewise the bootfile name must be + // The selected offer to finish the D.O.R.A. is a DHCP only offer, we need + // try proxy offers if there are some, othewise the bootfile name must be // set in this DHCP only offer. // if (Private->GotProxyOffer) { @@ -439,7 +449,7 @@ PxeBcCheckSelectedOffer ( } } else { // - // The proxy offer type is not determined, choose proxy offer in the + // The proxy offer type is not determined, choose proxy offer in the // received order. // Status = EFI_NO_RESPONSE; @@ -555,7 +565,9 @@ PxeBcCacheDhcpOffer ( } OfferType = CachedOffer->OfferType; - ASSERT (OfferType < DHCP4_PACKET_TYPE_MAX); + if (OfferType >= DHCP4_PACKET_TYPE_MAX) { + return ; + } if (OfferType == DHCP4_PACKET_TYPE_BOOTP) { @@ -615,7 +627,7 @@ PxeBcCacheDhcpOffer ( /** Select the specified proxy offer, such as BINL, DHCP_ONLY and so on. If the proxy does not exist, try offers with bootfile. - + @param Private Pointer to PxeBc private data. **/ @@ -733,7 +745,7 @@ PxeBcSelectOffer ( /** Callback routine. - + EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver to intercept events that occurred in the configuration process. This structure provides advanced control of each state transition of the DHCP process. The @@ -778,7 +790,6 @@ PxeBcDhcpCallBack ( UINT16 Value; EFI_STATUS Status; BOOLEAN Received; - CHAR8 *SystemSerialNumber; EFI_DHCP4_HEADER *DhcpHeader; if ((Dhcp4Event != Dhcp4RcvdOffer) && @@ -833,7 +844,7 @@ PxeBcDhcpCallBack ( // DhcpHeader = &Packet->Dhcp4.Header; - if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) DhcpHeader->ClientHwAddr, &SystemSerialNumber))) { + if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) { // // GUID not yet set - send all 0xff's to show programable (via SetVariable) // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff); @@ -842,7 +853,7 @@ PxeBcDhcpCallBack ( ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID)); } - DhcpHeader->HwAddrLen = sizeof (EFI_GUID); + DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID); } if (Dhcp4Event == Dhcp4SendDiscover) { @@ -902,8 +913,8 @@ PxeBcDhcpCallBack ( @param Private Pointer to PxeBc private data. @param OptList Pointer to a DHCP option list. - - @param IsDhcpDiscover Discover dhcp option or not. + + @param IsDhcpDiscover Discover dhcp option or not. @return The index item number of the option list. @@ -918,7 +929,6 @@ PxeBcBuildDhcpOptions ( UINT32 Index; PXEBC_DHCP4_OPTION_ENTRY OptEnt; UINT16 Value; - CHAR8 *SystemSerialNumber; Index = 0; OptList[0] = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer; @@ -938,7 +948,7 @@ PxeBcBuildDhcpOptions ( // Append max message size. // OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MAXMSG; - OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE); + OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE); OptEnt.MaxMesgSize = (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *) OptList[Index]->Data; Value = NTOHS (PXEBC_DHCP4_MAX_PACKET_SIZE); CopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16)); @@ -993,13 +1003,13 @@ PxeBcBuildDhcpOptions ( // Append UUID/Guid-based client identifier option // OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UUID; - OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_UUID); + OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UUID); OptEnt.Uuid = (PXEBC_DHCP4_OPTION_UUID *) OptList[Index]->Data; OptEnt.Uuid->Type = 0; Index++; OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) OptEnt.Uuid->Guid, &SystemSerialNumber))) { + if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) { // // GUID not yet set - send all 0xff's to show programable (via SetVariable) // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff); @@ -1012,7 +1022,7 @@ PxeBcBuildDhcpOptions ( // Append client network device interface option // OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UNDI; - OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_UNDI); + OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UNDI); OptEnt.Undi = (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->Data; if (Private->Nii != NULL) { OptEnt.Undi->Type = Private->Nii->Type; @@ -1031,9 +1041,9 @@ PxeBcBuildDhcpOptions ( // Append client system architecture option // OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_ARCH; - OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_ARCH); + OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_ARCH); OptEnt.Arch = (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->Data; - Value = HTONS (SYS_ARCH); + Value = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE); CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16)); Index++; OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]); @@ -1042,13 +1052,13 @@ PxeBcBuildDhcpOptions ( // Append client system architecture option // OptList[Index]->OpCode = PXEBC_DHCP4_TAG_CLASS_ID; - OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_CLID); + OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_CLID); OptEnt.Clid = (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->Data; CopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_CLID)); - CvtNum (SYS_ARCH, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType)); + CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType)); if (Private->Nii != NULL) { - // + // // If NII protocol exists, update DHCP option data // CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName)); @@ -1069,8 +1079,8 @@ PxeBcBuildDhcpOptions ( @param Type PxeBc option boot item type @param Layer PxeBc option boot item layer @param UseBis Use BIS or not - @param DestIp Ip address for server - @param IpCount The total count of the server ip address + @param DestIp Ip address for server + @param IpCount The total count of the server ip address @param SrvList Server list @param IsDiscv Discover the vendor or not @param Reply The dhcp4 packet of Pxe reply @@ -1078,8 +1088,8 @@ PxeBcBuildDhcpOptions ( @retval EFI_SUCCESS Operation succeeds. @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed. @retval EFI_NOT_FOUND There is no vendor option exists. - @retval EFI_TIMEOUT Send Pxe Discover time out. - + @retval EFI_TIMEOUT Send Pxe Discover time out. + **/ EFI_STATUS PxeBcDiscvBootService ( @@ -1110,7 +1120,6 @@ PxeBcDiscvBootService ( EFI_DHCP4_PACKET_OPTION *PxeOpt; PXEBC_OPTION_BOOT_ITEM *PxeBootItem; UINT8 VendorOptLen; - CHAR8 *SystemSerialNumber; EFI_DHCP4_HEADER *DhcpHeader; UINT32 Xid; @@ -1139,7 +1148,7 @@ PxeBcDiscvBootService ( // // Add vendor option of PXE_BOOT_ITEM // - VendorOptLen = (sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1; + VendorOptLen = (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1); OptList[OptCount] = AllocatePool (VendorOptLen); if (OptList[OptCount] == NULL) { return EFI_OUT_OF_RESOURCES; @@ -1149,7 +1158,7 @@ PxeBcDiscvBootService ( OptList[OptCount]->Length = (UINT8) (VendorOptLen - 2); PxeOpt = (EFI_DHCP4_PACKET_OPTION *) OptList[OptCount]->Data; PxeOpt->OpCode = PXEBC_VENDOR_TAG_BOOT_ITEM; - PxeOpt->Length = sizeof (PXEBC_OPTION_BOOT_ITEM); + PxeOpt->Length = (UINT8) sizeof (PXEBC_OPTION_BOOT_ITEM); PxeBootItem = (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->Data; PxeBootItem->Type = HTONS (Type); PxeBootItem->Layer = HTONS (*Layer); @@ -1170,16 +1179,16 @@ PxeBcDiscvBootService ( DhcpHeader = &Token.Packet->Dhcp4.Header; if (Mode->SendGUID) { - if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) DhcpHeader->ClientHwAddr, &SystemSerialNumber))) { + if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) { // // GUID not yet set - send all 0's to show not programable // ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID)); } - DhcpHeader->HwAddrLen = sizeof (EFI_GUID); + DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID); } - + Xid = NET_RANDOM (NetRandomInitSeed ()); Token.Packet->Dhcp4.Header.Xid = HTONL(Xid); Token.Packet->Dhcp4.Header.Reserved = HTONS((UINT16) ((IsBCast) ? 0x8000 : 0)); @@ -1217,6 +1226,13 @@ PxeBcDiscvBootService ( } } + if (TryIndex > PXEBC_BOOT_REQUEST_RETRIES) { + // + // No server response our PXE request + // + Status = EFI_TIMEOUT; + } + if (!EFI_ERROR (Status)) { // // Find Pxe Reply @@ -1270,7 +1286,9 @@ PxeBcDiscvBootService ( // // free the responselist // - FreePool (Token.ResponseList); + if (Token.ResponseList != NULL) { + FreePool (Token.ResponseList); + } } // // Free the dhcp packet @@ -1288,7 +1306,7 @@ PxeBcDiscvBootService ( @param Length The length of the dhcp options. @param OptTag The option OpCode. - @return NULL if the buffer length is 0 and OpCode is not + @return NULL if the buffer length is 0 and OpCode is not PXEBC_DHCP4_TAG_EOP, or the pointer to the buffer. **/ @@ -1451,8 +1469,8 @@ PxeBcParseVendorOptions ( /** This function display boot item detail. - If the length of the boot item string over 70 Char, just display 70 Char. - + If the length of the boot item string over 70 Char, just display 70 Char. + @param Str Pointer to a string (boot item string). @param Len The length of string. @@ -1479,11 +1497,11 @@ PxeBcDisplayBootItem ( @param Private Pointer to PxeBc private data. @retval EFI_SUCCESS Select boot prompt done. - @retval EFI_TIMEOUT Select boot prompt time out. + @retval EFI_TIMEOUT Select boot prompt time out. @retval EFI_NOT_FOUND The proxy offer is not Pxe10. @retval EFI_ABORTED User cancel the operation. @retval EFI_NOT_READY Read the input key from the keybroad has not finish. - + **/ EFI_STATUS PxeBcSelectBootPrompt ( @@ -1657,10 +1675,10 @@ ON_EXIT: @param Private Pointer to PxeBc private data. @param Type The type of the menu. @param UseDefaultItem Use default item or not. - + @retval EFI_ABORTED User cancel operation. @retval EFI_SUCCESS Select the boot menu success. - @retval EFI_NOT_READY Read the input key from the keybroad has not finish. + @retval EFI_NOT_READY Read the input key from the keybroad has not finish. **/ EFI_STATUS @@ -1671,7 +1689,7 @@ PxeBcSelectBootMenu ( ) { PXEBC_CACHED_DHCP4_PACKET *Packet; - PXEBC_VENDOR_OPTION *VendorOpt; + PXEBC_VENDOR_OPTION *VendorOpt; EFI_INPUT_KEY InputKey; UINT8 MenuSize; UINT8 MenuNum; @@ -1754,7 +1772,7 @@ PxeBcSelectBootMenu ( gBS->Stall (10 * TICKS_PER_MS); } - if (!InputKey.ScanCode) { + if (InputKey.ScanCode != 0) { switch (InputKey.UnicodeChar) { case CTRL ('c'): InputKey.ScanCode = SCAN_ESC; @@ -1823,6 +1841,8 @@ PxeBcSelectBootMenu ( gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum); } while (!Finish); + ASSERT (Select < PXEBC_MAX_MENU_NUM); + // // Swap the byte order //