X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FUefiPxeBcDxe%2FPxeBcDhcp.c;h=5e86cf5779e6cc10e2789bc221dcaaad79820c5e;hp=eb91307944c7e6f9d7cb041db9368e7585325943;hb=2ce5c88a7adaea3eeeccc932b18da5f02440f8cd;hpb=05c0e3cb8ad921c94ef51fc972e117baa32ce82f diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c index eb91307944..5e86cf5779 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c @@ -1,6 +1,7 @@ /** @file - -Copyright (c) 2007 - 2008, Intel Corporation + Support for PxeBc dhcp functions. + +Copyright (c) 2007 - 2009, 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 @@ -9,15 +10,6 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - PxeBcDhcp.c - -Abstract: - - Support for PxeBc dhcp functions - - **/ @@ -38,12 +30,12 @@ UINT8 mInterestedDhcp4Tags[PXEBC_DHCP4_TAG_INDEX_MAX] = { /** - GC_NOTO: Add function description + This function initialize the DHCP4 message instance. - @param Seed GC_NOTO: add argument description - @param Udp4 GC_NOTO: add argument description - - @return GC_NOTO: add return values + 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. **/ VOID @@ -74,12 +66,10 @@ PxeBcInitSeedPacket ( /** - GC_NOTO: Add function description - - @param Dst GC_NOTO: add argument description - @param Src GC_NOTO: add argument description + Copy the DCHP4 packet from srouce to destination. - @return GC_NOTO: add return values + @param Dst Pointer to the EFI_DHCP4_PROTOCOL instance. + @param Src Pointer to the EFI_DHCP4_PROTOCOL instance. **/ VOID @@ -96,12 +86,11 @@ PxeBcCopyEfiDhcp4Packet ( /** - GC_NOTO: Add function description - - @param Private GC_NOTO: add argument description - @param OfferIndex GC_NOTO: add argument description + Copy the dhcp4 packet to the PxeBc private data and parse the dhcp4 packet. - @return GC_NOTO: add return values + @param Private Pointer to PxeBc private data. + @param OfferIndex Index of cached packets as complements of pxe mode data, + the index is maximum offer number. **/ VOID @@ -114,6 +103,7 @@ PxeBcCopyProxyOffer ( EFI_DHCP4_PACKET *Offer; ASSERT (OfferIndex < Private->NumOffers); + ASSERT (OfferIndex < PXEBC_MAX_OFFER_NUM); Mode = Private->PxeBc.Mode; Offer = &Private->Dhcp4Offers[OfferIndex].Packet.Offer; @@ -129,10 +119,10 @@ PxeBcCopyProxyOffer ( /** Parse the cached dhcp packet. - @param CachedPacket Pointer to cached dhcp packet + @param CachedPacket Pointer to cached dhcp packet. - @return TRUE : Success to parse and validation - @return FALSE : Fail to parse or validation + @retval TRUE Succeed to parse and validation. + @retval FALSE Fail to parse or validation. **/ BOOLEAN @@ -206,7 +196,7 @@ PxeBcParseCachedDhcpPacket ( // And do not count dhcp option header, or else will destory the serverhostname. // Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] - - EFI_FIELD_OFFSET (EFI_DHCP4_PACKET_OPTION, Data[0])); + OFFSET_OF (EFI_DHCP4_PACKET_OPTION, Data[0])); } @@ -256,13 +246,16 @@ PxeBcParseCachedDhcpPacket ( /** - GC_NOTO: Add function description + Offer dhcp service with a BINL dhcp offer. - @param Private GC_NOTO: add argument description - @param Index GC_NOTO: add argument description - - @return GC_NOTO: add return values + @param Private Pointer to PxeBc private data. + @param Index Index of cached packets as complements of pxe mode data, + 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 + BINL ack cannot find options set or bootfile name specified. + **/ BOOLEAN PxeBcTryBinl ( @@ -276,23 +269,31 @@ PxeBcTryBinl ( PXEBC_CACHED_DHCP4_PACKET *CachedPacket; EFI_DHCP4_PACKET *Reply; + ASSERT (Index < PXEBC_MAX_OFFER_NUM); ASSERT (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL); Offer = &Private->Dhcp4Offers[Index].Packet.Offer; - if (Offer->Dhcp4.Header.ServerAddr.Addr[0] == 0) { - // - // next server ip address is zero, use server id option instead. - // + + // + // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier) + // in DHCPOFFER packet. + // (It does not comply with PXE Spec, Ver2.1) + // + if (EFI_IP4_EQUAL (&Offer->Dhcp4.Header.ServerAddr.Addr, &mZeroIp4Addr)) { CopyMem ( &ServerIp.Addr[0], Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data, sizeof (EFI_IPv4_ADDRESS) ); } else { - // - // use next server ip address. - // - CopyMem (&ServerIp.Addr[0], &Offer->Dhcp4.Header.ServerAddr, sizeof (EFI_IPv4_ADDRESS)); + CopyMem ( + &ServerIp.Addr[0], + &Offer->Dhcp4.Header.ServerAddr, + sizeof (EFI_IPv4_ADDRESS) + ); + } + if (ServerIp.Addr[0] == 0) { + return FALSE; } CachedPacket = &Private->ProxyOffer; @@ -334,12 +335,13 @@ PxeBcTryBinl ( /** - GC_NOTO: Add function description + Offer dhcp service for each proxy with a BINL dhcp offer. - @param Private GC_NOTO: add argument description - @param OfferIndex GC_NOTO: add argument description + @param Private Pointer to PxeBc private data + @param OfferIndex Pointer to the index of cached packets as complements of + pxe mode data, the index is maximum offer number. - @return GC_NOTO: add return values + @return If there is no service needed offer return FALSE, otherwise TRUE. **/ BOOLEAN @@ -366,11 +368,14 @@ PxeBcTryBinlProxy ( /** - GC_NOTO: Add function description + This function is to check the selected proxy offer (include BINL dhcp offer and + DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe base code + mode structure. - @param Private GC_NOTO: add argument description + @param Private Pointer to PxeBc private data. - @return GC_NOTO: add return values + @retval EFI_SUCCESS Operational successful. + @retval EFI_NO_RESPONSE Offer dhcp service failed. **/ EFI_STATUS @@ -518,12 +523,10 @@ PxeBcCheckSelectedOffer ( /** - GC_NOTO: Add function description - - @param Private GC_NOTO: add argument description - @param RcvdOffer GC_NOTO: add argument description + Cache the Dhcp4 packet offer, Parse and validate each option of the packet. - @return GC_NOTO: add return values + @param Private Pointer to PxeBc private data. + @param RcvdOffer Pointer to the received Dhcp proxy offer packet. **/ VOID @@ -552,6 +555,7 @@ PxeBcCacheDhcpOffer ( } OfferType = CachedOffer->OfferType; + ASSERT (OfferType < DHCP4_PACKET_TYPE_MAX); if (OfferType == DHCP4_PACKET_TYPE_BOOTP) { @@ -595,6 +599,7 @@ PxeBcCacheDhcpOffer ( // // It's a dhcp offer with your address. // + ASSERT (Private->ServerCount[OfferType] < PXEBC_MAX_OFFER_NUM); Private->OfferIndex[OfferType][Private->ServerCount[OfferType]] = Private->NumOffers; Private->ServerCount[OfferType]++; } @@ -608,11 +613,10 @@ PxeBcCacheDhcpOffer ( /** - GC_NOTO: Add function description - - @param Private GC_NOTO: add argument description - - @return GC_NOTO: add return values + 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. **/ VOID @@ -728,20 +732,36 @@ PxeBcSelectOffer ( /** - GC_NOTO: Add function description - - @param This GC_NOTO: add argument description - @param Context GC_NOTO: add argument description - @param CurrentState GC_NOTO: add argument description - @param Dhcp4Event GC_NOTO: add argument description - @param Packet GC_NOTO: add argument description - @param NewPacket GC_NOTO: add argument description - - @retval EFI_SUCCESS GC_NOTO: Add description for return value - @retval EFI_ABORTED GC_NOTO: Add description for return value + 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 + returned status code determines the behavior of the EFI DHCPv4 Protocol driver. + There are three possible returned values, which are described in the following + table. + + @param This Pointer to the EFI DHCPv4 Protocol instance that is used to + configure this callback function. + @param Context Pointer to the context that is initialized by + EFI_DHCP4_PROTOCOL.Configure(). + @param CurrentState The current operational state of the EFI DHCPv4 Protocol + driver. + @param Dhcp4Event The event that occurs in the current state, which usually means a + state transition. + @param Packet The DHCP packet that is going to be sent or already received. + @param NewPacket The packet that is used to replace the above Packet. + + @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process. + @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol + driver will continue to wait for more DHCPOFFER packets until the retry + timeout expires. + @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and + return to the Dhcp4Init or Dhcp4InitReboot state. **/ EFI_STATUS +EFIAPI PxeBcDhcpCallBack ( IN EFI_DHCP4_PROTOCOL * This, IN VOID *Context, @@ -878,13 +898,14 @@ PxeBcDhcpCallBack ( /** - GC_NOTO: Add function description + Initialize the DHCP options and build the option list. - @param Private GC_NOTO: add argument description - @param OptList GC_NOTO: add argument description - @param IsDhcpDiscover GC_NOTO: add argument description + @param Private Pointer to PxeBc private data. + @param OptList Pointer to a DHCP option list. + + @param IsDhcpDiscover Discover dhcp option or not. - @return GC_NOTO: add return values + @return The index item number of the option list. **/ UINT32 @@ -993,9 +1014,15 @@ PxeBcBuildDhcpOptions ( OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UNDI; OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_UNDI); OptEnt.Undi = (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->Data; - OptEnt.Undi->Type = Private->Nii->Type; - OptEnt.Undi->MajorVer = Private->Nii->MajorVer; - OptEnt.Undi->MinorVer = Private->Nii->MinorVer; + if (Private->Nii != NULL) { + OptEnt.Undi->Type = Private->Nii->Type; + OptEnt.Undi->MajorVer = Private->Nii->MajorVer; + OptEnt.Undi->MinorVer = Private->Nii->MinorVer; + } else { + OptEnt.Undi->Type = DEFAULT_UNDI_TYPE; + OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR; + OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR; + } Index++; OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]); @@ -1019,9 +1046,16 @@ PxeBcBuildDhcpOptions ( 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)); - CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName)); - CvtNum (Private->Nii->MajorVer, OptEnt.Clid->UndiMajor, sizeof (OptEnt.Clid->UndiMajor)); - CvtNum (Private->Nii->MinorVer, OptEnt.Clid->UndiMinor, sizeof (OptEnt.Clid->UndiMinor)); + + if (Private->Nii != NULL) { + // + // If NII protocol exists, update DHCP option data + // + CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName)); + CvtNum (Private->Nii->MajorVer, OptEnt.Clid->UndiMajor, sizeof (OptEnt.Clid->UndiMajor)); + CvtNum (Private->Nii->MinorVer, OptEnt.Clid->UndiMinor, sizeof (OptEnt.Clid->UndiMinor)); + } + Index++; return Index; @@ -1029,20 +1063,23 @@ PxeBcBuildDhcpOptions ( /** - GC_NOTO: Add function description - - @param Private GC_NOTO: add argument description - @param Type GC_NOTO: add argument description - @param Layer GC_NOTO: add argument description - @param UseBis GC_NOTO: add argument description - @param DestIp GC_NOTO: add argument description - @param IpCount GC_NOTO: add argument description - @param SrvList GC_NOTO: add argument description - @param IsDiscv GC_NOTO: add argument description - @param Reply GC_NOTO: add argument description - - @retval EFI_OUT_OF_RESOURCES GC_NOTO: Add description for return value - + Discover the boot of service and initialize the vendor option if exists. + + @param Private Pointer to PxeBc private data. + @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 SrvList Server list + @param IsDiscv Discover the vendor or not + @param Reply The dhcp4 packet of Pxe reply + + @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. + **/ EFI_STATUS PxeBcDiscvBootService ( @@ -1075,7 +1112,7 @@ PxeBcDiscvBootService ( UINT8 VendorOptLen; CHAR8 *SystemSerialNumber; EFI_DHCP4_HEADER *DhcpHeader; - + UINT32 Xid; Mode = Private->PxeBc.Mode; Dhcp4 = Private->Dhcp4; @@ -1098,6 +1135,7 @@ PxeBcDiscvBootService ( OptCount = PxeBcBuildDhcpOptions (Private, OptList, FALSE); if (IsDiscv) { + ASSERT (Layer != NULL); // // Add vendor option of PXE_BOOT_ITEM // @@ -1141,14 +1179,15 @@ PxeBcDiscvBootService ( DhcpHeader->HwAddrLen = sizeof (EFI_GUID); } - - Token.Packet->Dhcp4.Header.Xid = NET_RANDOM (NetRandomInitSeed ()); - Token.Packet->Dhcp4.Header.Reserved = (UINT16) ((IsBCast) ? 0xf000 : 0x0); + + Xid = NET_RANDOM (NetRandomInitSeed ()); + Token.Packet->Dhcp4.Header.Xid = HTONL(Xid); + Token.Packet->Dhcp4.Header.Reserved = HTONS((IsBCast) ? 0x8000 : 0); CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS)); Token.RemotePort = Sport; - if (DestIp == NULL) { + if (IsBCast) { SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff); } else { CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS)); @@ -1168,7 +1207,8 @@ PxeBcDiscvBootService ( // for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) { - Token.TimeoutValue = PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex; + Token.TimeoutValue = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex); + Token.Packet->Dhcp4.Header.Seconds = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * (TryIndex - 1)); Status = Dhcp4->TransmitReceive (Dhcp4, &Token); @@ -1242,13 +1282,14 @@ PxeBcDiscvBootService ( /** - GC_NOTO: Add function description + Parse interested dhcp options. - @param Buffer GC_NOTO: add argument description - @param Length GC_NOTO: add argument description - @param OptTag GC_NOTO: add argument description + @param Buffer Pointer to the dhcp options packet. + @param Length The length of the dhcp options. + @param OptTag The option OpCode. - @return GC_NOTO: add return values + @return NULL if the buffer length is 0 and OpCode is not + PXEBC_DHCP4_TAG_EOP, or the pointer to the buffer. **/ EFI_DHCP4_PACKET_OPTION * @@ -1290,8 +1331,7 @@ PxeBcParseExtendOptions ( @param Dhcp4Option Pointer to dhcp options @param VendorOption Pointer to vendor options - @return TRUE : Valid vendor options - @return FALSE : Invalid vendor options + @return TRUE if valid for vendor options, or FALSE. **/ BOOLEAN @@ -1409,12 +1449,12 @@ PxeBcParseVendorOptions ( /** - GC_NOTO: Add function description + This function display boot item detail. - @param Str GC_NOTO: add argument description - @param Len GC_NOTO: add argument description - - @return GC_NOTO: add return values + 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. **/ VOID @@ -1434,13 +1474,16 @@ PxeBcDisplayBootItem ( /** - GC_NOTO: Add function description - - @param Private GC_NOTO: add argument description + Choose the boot prompt. - @retval EFI_SUCCESS GC_NOTO: Add description for return value - @retval EFI_TIMEOUT GC_NOTO: Add description for return value + @param Private Pointer to PxeBc private data. + @retval EFI_SUCCESS Select boot prompt done. + @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 ( @@ -1609,13 +1652,15 @@ ON_EXIT: /** - GC_NOTO: Add function description - - @param Private GC_NOTO: add argument description - @param Type GC_NOTO: add argument description + Select the boot menu. - @retval EFI_ABORTED GC_NOTO: Add description for return value - @retval EFI_SUCCESS GC_NOTO: Add description for return value + @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. **/ EFI_STATUS @@ -1665,15 +1710,21 @@ PxeBcSelectBootMenu ( MenuSize = VendorOpt->BootMenuLen; MenuItem = VendorOpt->BootMenu; + if (MenuSize == 0) { + return EFI_NOT_READY; + } + while (MenuSize > 0) { - MenuArray[Index] = MenuItem; + MenuArray[Index++] = MenuItem; MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3)); MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3); - Index++; + if (Index >= PXEBC_MAX_MENU_NUM) { + break; + } } if (UseDefaultItem) { - CopyMem (Type, &MenuArray[0]->Type, sizeof (UINT16)); + *Type = MenuArray[0]->Type; *Type = NTOHS (*Type); return EFI_SUCCESS; } @@ -1687,6 +1738,7 @@ PxeBcSelectBootMenu ( TopRow = gST->ConOut->Mode->CursorRow - MenuNum; do { + ASSERT (Select < PXEBC_MAX_MENU_NUM); // // highlight selected row // @@ -1734,7 +1786,7 @@ PxeBcSelectBootMenu ( switch (InputKey.ScanCode) { case SCAN_LEFT: case SCAN_UP: - if (Select) { + if (Select > 0) { --Select; }