summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Network/UefiPxeBcDxe
diff options
context:
space:
mode:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2008-01-04 02:29:30 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2008-01-04 02:29:30 +0000
commitdc361cc5a04657ddc8c74bd8f044f7ad30c4118a (patch)
tree03af8f70c486a2c0eff924045afb18da768c22d8 /MdeModulePkg/Universal/Network/UefiPxeBcDxe
parent822360ee34e8b3e9274f371bc6cc020181851af6 (diff)
downloadedk2-platforms-dc361cc5a04657ddc8c74bd8f044f7ad30c4118a.tar.xz
1. Import UEFI PxeBc module in MdeModulePkg
2. Remove some SMBIOS definitions defined in PxeBc module, use those who are defined in MdePkg. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4495 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/Network/UefiPxeBcDxe')
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/ComponentName.c168
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ia32/PxeArch.h26
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ipf/PxeArch.h26
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c1746
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h542
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c451
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h103
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c1866
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h126
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c437
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h144
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c250
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h89
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf93
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.msa108
-rw-r--r--MdeModulePkg/Universal/Network/UefiPxeBcDxe/X64/PxeArch.h26
16 files changed, 6201 insertions, 0 deletions
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/ComponentName.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/ComponentName.c
new file mode 100644
index 0000000000..8deac91eab
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/ComponentName.c
@@ -0,0 +1,168 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+ ComponentName.c
+
+Abstract:
+
+
+**/
+
+
+#include "PxeBcImpl.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+PxeBcComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+PxeBcComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName = {
+ PxeBcComponentNameGetDriverName,
+ PxeBcComponentNameGetControllerName,
+ "eng"
+};
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2 = {
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PxeBcComponentNameGetDriverName,
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PxeBcComponentNameGetControllerName,
+ "en"
+};
+
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcDriverNameTable[] = {
+ {
+ "eng;en",
+ L"UEFI PXE Base Code Driver"
+ },
+ {
+ NULL,
+ NULL
+ }
+};
+
+EFI_STATUS
+EFIAPI
+PxeBcComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString2 (
+ Language,
+ This->SupportedLanguages,
+ mPxeBcDriverNameTable,
+ DriverName,
+ (BOOLEAN)(This == &gPxeBcComponentName)
+ );
+}
+
+EFI_STATUS
+EFIAPI
+PxeBcComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL * This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerNameString
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. This is an optional parameter that may be NULL. It
+ will be NULL for device drivers. It will also be NULL
+ for a bus drivers that wish to retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return EFI_UNSUPPORTED;
+}
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ia32/PxeArch.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ia32/PxeArch.h
new file mode 100644
index 0000000000..cc878d8dd7
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ia32/PxeArch.h
@@ -0,0 +1,26 @@
+/** @file
+
+Copyright (c) 2006, 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
+
+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:
+ PxeArch.h
+
+Abstract:
+ Defines PXE Arch type
+
+
+**/
+
+#ifndef _EFI_PXE_ARCH_H_
+#define _EFI_PXE_ARCH_H_
+
+#define SYS_ARCH 0x6
+
+#endif
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ipf/PxeArch.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ipf/PxeArch.h
new file mode 100644
index 0000000000..6d06045df0
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/Ipf/PxeArch.h
@@ -0,0 +1,26 @@
+/** @file
+
+Copyright (c) 2006, 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
+
+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:
+ PxeArch.h
+
+Abstract:
+ Defines PXE Arch type
+
+
+**/
+
+#ifndef _EFI_PXE_ARCH_H_
+#define _EFI_PXE_ARCH_H_
+
+#define SYS_ARCH 0x2
+
+#endif
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
new file mode 100644
index 0000000000..b76461a70d
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
@@ -0,0 +1,1746 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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
+
+
+**/
+
+
+#include "PxeBcImpl.h"
+
+//
+// This is a map from the interested DHCP4 option tags' index to the tag value.
+//
+UINT8 mInterestedDhcp4Tags[PXEBC_DHCP4_TAG_INDEX_MAX] = {
+ PXEBC_DHCP4_TAG_BOOTFILE_LEN,
+ PXEBC_DHCP4_TAG_VENDOR,
+ PXEBC_DHCP4_TAG_OVERLOAD,
+ PXEBC_DHCP4_TAG_MSG_TYPE,
+ PXEBC_DHCP4_TAG_SERVER_ID,
+ PXEBC_DHCP4_TAG_CLASS_ID,
+ PXEBC_DHCP4_TAG_BOOTFILE
+};
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Seed GC_NOTO: add argument description
+ @param Udp4 GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcInitSeedPacket (
+ IN EFI_DHCP4_PACKET *Seed,
+ IN EFI_UDP4_PROTOCOL *Udp4
+ )
+{
+ EFI_SIMPLE_NETWORK_MODE Mode;
+ EFI_DHCP4_HEADER *Header;
+
+ Udp4->GetModeData (Udp4, NULL, NULL, NULL, &Mode);
+
+ Seed->Size = sizeof (EFI_DHCP4_PACKET);
+ Seed->Length = sizeof (Seed->Dhcp4);
+
+ Header = &Seed->Dhcp4.Header;
+
+ NetZeroMem (Header, sizeof (EFI_DHCP4_HEADER));
+ Header->OpCode = PXEBC_DHCP4_OPCODE_REQUEST;
+ Header->HwType = Mode.IfType;
+ Header->HwAddrLen = (UINT8) Mode.HwAddressSize;
+ NetCopyMem (Header->ClientHwAddr, &Mode.CurrentAddress, Header->HwAddrLen);
+
+ Seed->Dhcp4.Magik = PXEBC_DHCP4_MAGIC;
+ Seed->Dhcp4.Option[0] = PXEBC_DHCP4_TAG_EOP;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Dst GC_NOTO: add argument description
+ @param Src GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcCopyEfiDhcp4Packet (
+ IN EFI_DHCP4_PACKET *Dst,
+ IN EFI_DHCP4_PACKET *Src
+ )
+{
+ ASSERT (Dst->Size >= Src->Length);
+
+ NetCopyMem (&Dst->Dhcp4, &Src->Dhcp4, Src->Length);
+ Dst->Length = Src->Length;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param OfferIndex GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcCopyProxyOffer (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN UINT32 OfferIndex
+ )
+{
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_DHCP4_PACKET *Offer;
+
+ ASSERT (OfferIndex < Private->NumOffers);
+
+ Mode = Private->PxeBc.Mode;
+ Offer = &Private->Dhcp4Offers[OfferIndex].Packet.Offer;
+
+ PxeBcCopyEfiDhcp4Packet (&Private->ProxyOffer.Packet.Offer, Offer);
+ NetCopyMem (&Mode->ProxyOffer, &Offer->Dhcp4, Offer->Length);
+ Mode->ProxyOfferReceived = TRUE;
+
+ PxeBcParseCachedDhcpPacket (&Private->ProxyOffer);
+}
+
+
+/**
+ Parse the cached dhcp packet.
+
+ @param CachedPacket Pointer to cached dhcp packet
+
+ @return TRUE : Success to parse and validation
+ @return FALSE : Fail to parse or validation
+
+**/
+BOOLEAN
+PxeBcParseCachedDhcpPacket (
+ IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket
+ )
+{
+ EFI_DHCP4_PACKET *Offer;
+ EFI_DHCP4_PACKET_OPTION **Options;
+ EFI_DHCP4_PACKET_OPTION *Option;
+ UINT8 OfferType;
+ UINTN Index;
+
+ CachedPacket->IsPxeOffer = FALSE;
+ NetZeroMem (CachedPacket->Dhcp4Option, sizeof (CachedPacket->Dhcp4Option));
+ NetZeroMem (&CachedPacket->PxeVendorOption, sizeof (CachedPacket->PxeVendorOption));
+
+ Offer = &CachedPacket->Packet.Offer;
+ Options = CachedPacket->Dhcp4Option;
+
+ //
+ // Parse interested dhcp options and store their pointers in CachedPacket->Dhcp4Option.
+ //
+ for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) {
+ Options[Index] = PxeBcParseExtendOptions (
+ Offer->Dhcp4.Option,
+ GET_OPTION_BUFFER_LEN (Offer),
+ mInterestedDhcp4Tags[Index]
+ );
+ }
+
+ //
+ // Check whether is an offer with PXEClient or not.
+ //
+ Option = Options[PXEBC_DHCP4_TAG_INDEX_CLASS_ID];
+ if ((Option != NULL) && (Option->Length >= 9) &&
+ (NetCompareMem (Option->Data, DEFAULT_CLASS_ID_DATA, 9) == 0)) {
+
+ CachedPacket->IsPxeOffer = TRUE;
+ }
+
+ //
+ // Parse pxe vendor options and store their content/pointers in CachedPacket->PxeVendorOption.
+ //
+ Option = Options[PXEBC_DHCP4_TAG_INDEX_VENDOR];
+ if (CachedPacket->IsPxeOffer && (Option != NULL)) {
+
+ if (!PxeBcParseVendorOptions (Option, &CachedPacket->PxeVendorOption)) {
+ return FALSE;
+ }
+ }
+
+ //
+ // Check whether bootfilename/serverhostname overloaded (See details in dhcp spec).
+ // If overloaded, parse this buffer as nested dhcp options, or just parse bootfilename/
+ // serverhostname option.
+ //
+ Option = Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD];
+ if ((Option != NULL) && (Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE)) {
+
+ Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = PxeBcParseExtendOptions (
+ (UINT8 *) Offer->Dhcp4.Header.BootFileName,
+ sizeof (Offer->Dhcp4.Header.BootFileName),
+ PXEBC_DHCP4_TAG_BOOTFILE
+ );
+
+ } 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.
+ //
+ Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] -
+ EFI_FIELD_OFFSET (EFI_DHCP4_PACKET_OPTION, Data[0]));
+
+ }
+
+ //
+ // Determine offer type of the dhcp packet.
+ //
+ Option = Options[PXEBC_DHCP4_TAG_INDEX_MSG_TYPE];
+ if ((Option == NULL) || (Option->Data[0] == 0)) {
+ //
+ // It's a bootp offer
+ //
+ Option = CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE];
+ if (Option == NULL) {
+ //
+ // bootp offer without bootfilename, discard it.
+ //
+ return FALSE;
+ }
+
+ OfferType = DHCP4_PACKET_TYPE_BOOTP;
+
+ } else {
+
+ if (IS_VALID_DISCOVER_VENDOR_OPTION (CachedPacket->PxeVendorOption.BitMap)) {
+ //
+ // It's a pxe10 offer with PXEClient and discover vendor option.
+ //
+ OfferType = DHCP4_PACKET_TYPE_PXE10;
+ } else if (IS_VALID_MTFTP_VENDOR_OPTION (CachedPacket->PxeVendorOption.BitMap)) {
+ //
+ // It's a wfm11a offer with PXEClient and mtftp vendor option, and
+ // return false since mtftp not supported currently.
+ //
+ return FALSE;
+#if 0
+ //
+ // WFM11A, make sure bootfile is present
+ //
+ if (CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL) {
+ //
+ // Discard this offer.
+ //
+ return ;
+ }
+
+ OfferType = DHCP4_PACKET_TYPE_WFM11A;
+#endif
+ } else {
+ //
+ // If the binl offer with only PXEClient.
+ //
+ OfferType = (UINT8) ((CachedPacket->IsPxeOffer) ? DHCP4_PACKET_TYPE_BINL : DHCP4_PACKET_TYPE_DHCP_ONLY);
+ }
+ }
+
+ CachedPacket->OfferType = OfferType;
+
+ return TRUE;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param Index GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+BOOLEAN
+PxeBcTryBinl (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN UINT32 Index
+ )
+{
+ EFI_DHCP4_PACKET *Offer;
+ EFI_IP_ADDRESS ServerIp;
+ EFI_STATUS Status;
+ PXEBC_CACHED_DHCP4_PACKET *CachedPacket;
+ EFI_DHCP4_PACKET *Reply;
+
+ 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.
+ //
+ NetCopyMem (
+ &ServerIp.Addr[0],
+ Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,
+ sizeof (EFI_IPv4_ADDRESS)
+ );
+ } else {
+ //
+ // use next server ip address.
+ //
+ NetCopyMem (&ServerIp.Addr[0], &Offer->Dhcp4.Header.ServerAddr, sizeof (EFI_IPv4_ADDRESS));
+ }
+
+ CachedPacket = &Private->ProxyOffer;
+ Reply = &CachedPacket->Packet.Offer;
+
+ Status = PxeBcDiscvBootService (
+ Private,
+ 0,
+ NULL,
+ FALSE,
+ &ServerIp,
+ 0,
+ NULL,
+ FALSE,
+ Reply
+ );
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if (!PxeBcParseCachedDhcpPacket (CachedPacket)) {
+ return FALSE;
+ }
+
+ if ((CachedPacket->OfferType != DHCP4_PACKET_TYPE_PXE10) &&
+ (CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL)) {
+ //
+ // This BINL ack doesn't have discovery options set or bootfile name
+ // specified.
+ //
+ return FALSE;
+ }
+
+ Private->PxeBc.Mode->ProxyOfferReceived = TRUE;
+ NetCopyMem (&Private->PxeBc.Mode->ProxyOffer, &Reply->Dhcp4, Reply->Length);
+
+ return TRUE;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param OfferIndex GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+BOOLEAN
+PxeBcTryBinlProxy (
+ IN PXEBC_PRIVATE_DATA *Private,
+ OUT UINT32 *OfferIndex
+ )
+{
+ UINT32 Index;
+
+ for (Index = 0; Index < Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]; Index++) {
+
+ *OfferIndex = Private->BinlIndex[Index];
+ //
+ // Try this BINL proxy offer
+ //
+ if (PxeBcTryBinl (Private, *OfferIndex)) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcCheckSelectedOffer (
+ IN PXEBC_PRIVATE_DATA *Private
+ )
+{
+ PXEBC_CACHED_DHCP4_PACKET *SelectedOffer;
+ EFI_DHCP4_PACKET_OPTION **Options;
+ UINT32 Index;
+ EFI_DHCP4_PACKET *Offer;
+ UINT32 ProxyOfferIndex;
+ EFI_STATUS Status;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_DHCP4_PACKET *Ack;
+
+ ASSERT (Private->SelectedOffer != 0);
+
+ Status = EFI_SUCCESS;
+ SelectedOffer = &Private->Dhcp4Offers[Private->SelectedOffer - 1];
+ Options = SelectedOffer->Dhcp4Option;
+
+ if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_BINL) {
+ //
+ // The addresses are acquired from a BINL dhcp offer, try BINL to get
+ // the bootfile name
+ //
+ if (!PxeBcTryBinl (Private, Private->SelectedOffer - 1)) {
+ Status = EFI_NO_RESPONSE;
+ }
+ } else if ((SelectedOffer->OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&
+ (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL)) {
+ //
+ // The selected offer to finish the D.O.R.A. is a DHCP only offer and
+ // bootfile name is not provided in this offer, we need try proxy offers
+ // to get the bootfile name or the discovery info
+ //
+ ProxyOfferIndex = Private->NumOffers;
+
+ if (Private->SortOffers) {
+ //
+ // Choose proxy offer from the type we stored during DHCP offer selection
+ //
+ ASSERT (Private->ProxyIndex[Private->ProxyOfferType] > 0);
+
+ if (Private->ProxyOfferType == DHCP4_PACKET_TYPE_BINL) {
+ //
+ // We buffer all received BINL proxy offers, try them all one by one
+ //
+ if (!PxeBcTryBinlProxy (Private, &ProxyOfferIndex)) {
+ Status = EFI_NO_RESPONSE;
+ }
+ } else {
+ //
+ // For other types, only one proxy offer is buffered.
+ //
+ ProxyOfferIndex = Private->ProxyIndex[Private->ProxyOfferType] - 1;
+ }
+ } else {
+ //
+ // Choose proxy offer in the received order.
+ //
+ Status = EFI_NO_RESPONSE;
+
+ for (Index = 0; Index < Private->NumOffers; Index++) {
+
+ Offer = &Private->Dhcp4Offers[Index].Packet.Offer;
+ if (!IS_PROXY_DHCP_OFFER (Offer)) {
+ //
+ // Skip non proxy dhcp offers.
+ //
+ continue;
+ }
+
+ if (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL) {
+ //
+ // Try BINL
+ //
+ if (!PxeBcTryBinl (Private, Index)) {
+ //
+ // Failed, skip to the next offer
+ //
+ continue;
+ }
+ }
+
+ Status = EFI_SUCCESS;
+ break;
+ }
+ }
+
+ if (!EFI_ERROR (Status) && (Private->ProxyOfferType != DHCP4_PACKET_TYPE_BINL)) {
+ //
+ // Copy the proxy offer to Mode and set the flag
+ //
+ PxeBcCopyProxyOffer (Private, ProxyOfferIndex);
+ }
+ }
+
+ if (!EFI_ERROR (Status)) {
+ //
+ // Everything is OK, set the flag and copy the DHCP packets.
+ //
+ Mode = Private->PxeBc.Mode;
+ Offer = &SelectedOffer->Packet.Offer;
+
+ //
+ // The discover packet is already copied, just set flag here.
+ //
+ Mode->DhcpDiscoverValid = TRUE;
+
+ Ack = &Private->Dhcp4Ack.Packet.Ack;
+ if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_BOOTP) {
+ //
+ // Other type of ACK is already cached. Bootp is special that we should
+ // use the bootp reply as the ACK and put it into the DHCP_ONLY buffer.
+ //
+ PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Offer);
+ }
+
+ PxeBcParseCachedDhcpPacket (&Private->Dhcp4Ack);
+
+ Mode->DhcpAckReceived = TRUE;
+
+ //
+ // Copy the dhcp ack.
+ //
+ NetCopyMem (&Mode->DhcpAck, &Ack->Dhcp4, Ack->Length);
+ }
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param RcvdOffer GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcCacheDhcpOffer (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_DHCP4_PACKET *RcvdOffer
+ )
+{
+ PXEBC_CACHED_DHCP4_PACKET *CachedOffer;
+ EFI_DHCP4_PACKET *Offer;
+ UINT8 OfferType;
+
+ CachedOffer = &Private->Dhcp4Offers[Private->NumOffers];
+ Offer = &CachedOffer->Packet.Offer;
+
+ //
+ // Cache the orignal dhcp packet
+ //
+ PxeBcCopyEfiDhcp4Packet (Offer, RcvdOffer);
+
+ //
+ // Parse and validate the options (including dhcp option and vendor option)
+ //
+ if (!PxeBcParseCachedDhcpPacket (CachedOffer)) {
+ return ;
+ }
+
+ OfferType = CachedOffer->OfferType;
+
+ if (OfferType == DHCP4_PACKET_TYPE_BOOTP) {
+
+ if (Private->BootpIndex != 0) {
+ //
+ // Only cache the first bootp offer, discard others.
+ //
+ return ;
+ } else {
+ //
+ // Take as a dhcp only offer, but record index specifically.
+ //
+ Private->BootpIndex = Private->NumOffers + 1;
+ }
+ } else {
+
+ if (IS_PROXY_DHCP_OFFER (Offer)) {
+ //
+ // It's a proxy dhcp offer with no your address, including pxe10, wfm11a or binl offer.
+ //
+ if (OfferType == DHCP4_PACKET_TYPE_BINL) {
+ //
+ // Cache all binl offers.
+ //
+ Private->BinlIndex[Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]] = Private->NumOffers;
+ Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]++;
+ } else if (Private->ProxyIndex[OfferType] != 0) {
+ //
+ // Only cache the first pxe10/wfm11a offers each, discard the others.
+ //
+ return ;
+ } else {
+ //
+ // Record index of the proxy dhcp offer with type other than binl.
+ //
+ Private->ProxyIndex[OfferType] = Private->NumOffers + 1;
+ }
+ } else {
+ //
+ // It's a dhcp offer with your address.
+ //
+ Private->OfferIndex[OfferType][Private->ServerCount[OfferType]] = Private->NumOffers;
+ Private->ServerCount[OfferType]++;
+ }
+ }
+
+ //
+ // Count the accepted offers.
+ //
+ Private->NumOffers++;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcSelectOffer (
+ IN PXEBC_PRIVATE_DATA *Private
+ )
+{
+ UINT32 Index;
+ UINT32 OfferIndex;
+ EFI_DHCP4_PACKET *Offer;
+ BOOLEAN GotProxyOffer;
+
+ Private->SelectedOffer = 0;
+
+ if (Private->SortOffers) {
+ //
+ // Select offer according to the priority
+ //
+ if (Private->ServerCount[DHCP4_PACKET_TYPE_PXE10] > 0) {
+ //
+ // DHCP with PXE10
+ //
+ Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_PXE10][0] + 1;
+
+ } else if (Private->ServerCount[DHCP4_PACKET_TYPE_WFM11A] > 0) {
+ //
+ // DHCP with WfM
+ //
+ Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_WFM11A][0] + 1;
+
+ } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_PXE10] > 0) &&
+ (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
+ ) {
+ //
+ // DHCP only and proxy DHCP with PXE10
+ //
+ Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
+ Private->ProxyOfferType = DHCP4_PACKET_TYPE_PXE10;
+
+ } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_WFM11A] > 0) &&
+ (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
+ ) {
+ //
+ // DHCP only and proxy DHCP with WfM
+ //
+ Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
+ Private->ProxyOfferType = DHCP4_PACKET_TYPE_WFM11A;
+
+ } else if (Private->ServerCount[DHCP4_PACKET_TYPE_BINL] > 0) {
+ //
+ // DHCP with BINL
+ //
+ Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_BINL][0] + 1;
+
+ } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL] > 0) &&
+ (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
+ ) {
+ //
+ // DHCP only and proxy DHCP with BINL
+ //
+ Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
+ Private->ProxyOfferType = DHCP4_PACKET_TYPE_BINL;
+
+ } else {
+ //
+ // Try offers with bootfile
+ //
+ for (Index = 0; Index < Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY]; Index++) {
+ //
+ // Select the first DHCP only offer with bootfile
+ //
+ OfferIndex = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][Index];
+ if (Private->Dhcp4Offers[OfferIndex].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {
+ Private->SelectedOffer = OfferIndex + 1;
+ break;
+ }
+ }
+
+ if (Private->SelectedOffer == 0) {
+ //
+ // Select the Bootp reply with bootfile if any
+ //
+ Private->SelectedOffer = Private->BootpIndex;
+ }
+ }
+ } else {
+ //
+ // Try the offers in the received order.
+ //
+ GotProxyOffer = FALSE;
+ for (Index = 0; Index < DHCP4_PACKET_TYPE_MAX; Index++) {
+
+ GotProxyOffer = (BOOLEAN) (Private->ProxyIndex[Index] > 0);
+ if (GotProxyOffer) {
+ break;
+ }
+ }
+
+ for (Index = 0; Index < Private->NumOffers; Index++) {
+
+ Offer = &Private->Dhcp4Offers[Index].Packet.Offer;
+
+ if (IS_PROXY_DHCP_OFFER (Offer)) {
+ //
+ // Skip proxy offers
+ //
+ continue;
+ }
+
+ if ((Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&
+ ((!GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {
+ //
+ // DHCP only offer but no proxy offer received and no bootfile option in this offer
+ //
+ continue;
+ }
+
+ Private->SelectedOffer = Index + 1;
+ break;
+ }
+ }
+}
+
+
+/**
+ 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
+
+**/
+EFI_STATUS
+PxeBcDhcpCallBack (
+ IN EFI_DHCP4_PROTOCOL * This,
+ IN VOID *Context,
+ IN EFI_DHCP4_STATE CurrentState,
+ IN EFI_DHCP4_EVENT Dhcp4Event,
+ IN EFI_DHCP4_PACKET * Packet OPTIONAL,
+ OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;
+ EFI_DHCP4_PACKET_OPTION *MaxMsgSize;
+ UINT16 Value;
+ EFI_STATUS Status;
+ BOOLEAN Received;
+
+ if ((Dhcp4Event != Dhcp4RcvdOffer) &&
+ (Dhcp4Event != Dhcp4SelectOffer) &&
+ (Dhcp4Event != Dhcp4SendDiscover) &&
+ (Dhcp4Event != Dhcp4RcvdAck)) {
+ return EFI_SUCCESS;
+ }
+
+ Private = (PXEBC_PRIVATE_DATA *) Context;
+ Mode = Private->PxeBc.Mode;
+ Callback = Private->PxeBcCallback;
+
+ //
+ // Override the Maximum DHCP Message Size.
+ //
+ MaxMsgSize = PxeBcParseExtendOptions (
+ Packet->Dhcp4.Option,
+ GET_OPTION_BUFFER_LEN (Packet),
+ PXEBC_DHCP4_TAG_MAXMSG
+ );
+ if (MaxMsgSize != NULL) {
+ Value = HTONS (PXEBC_DHCP4_MAX_PACKET_SIZE);
+ NetCopyMem (MaxMsgSize->Data, &Value, sizeof (Value));
+ }
+
+ if ((Dhcp4Event != Dhcp4SelectOffer) && (Callback != NULL)) {
+ Received = (BOOLEAN) ((Dhcp4Event == Dhcp4RcvdOffer) || (Dhcp4Event == Dhcp4RcvdAck));
+ Status = Callback->Callback (
+ Callback,
+ Private->Function,
+ Received,
+ Packet->Length,
+ (EFI_PXE_BASE_CODE_PACKET *) &Packet->Dhcp4
+ );
+ if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {
+ return EFI_ABORTED;
+ }
+ }
+
+ Status = EFI_SUCCESS;
+
+ switch (Dhcp4Event) {
+
+ case Dhcp4SendDiscover:
+ //
+ // Cache the dhcp discover packet, of which some information will be used later.
+ //
+ NetCopyMem (Mode->DhcpDiscover.Raw, &Packet->Dhcp4, Packet->Length);
+
+ break;
+
+ case Dhcp4RcvdOffer:
+ Status = EFI_NOT_READY;
+ if (Private->NumOffers < PXEBC_MAX_OFFER_NUM) {
+ //
+ // Cache the dhcp offers in Private->Dhcp4Offers[]
+ //
+ PxeBcCacheDhcpOffer (Private, Packet);
+ }
+
+ break;
+
+ case Dhcp4SelectOffer:
+ //
+ // Select an offer, if succeeded, Private->SelectedOffer points to
+ // the index of the selected one.
+ //
+ PxeBcSelectOffer (Private);
+
+ if (Private->SelectedOffer == 0) {
+ Status = EFI_ABORTED;
+ } else {
+ *NewPacket = &Private->Dhcp4Offers[Private->SelectedOffer - 1].Packet.Offer;
+ }
+
+ break;
+
+ case Dhcp4RcvdAck:
+ //
+ // Cache Ack
+ //
+ ASSERT (Private->SelectedOffer != 0);
+
+ PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Packet);
+ break;
+ }
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param OptList GC_NOTO: add argument description
+ @param IsDhcpDiscover GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+UINT32
+PxeBcBuildDhcpOptions (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_DHCP4_PACKET_OPTION **OptList,
+ IN BOOLEAN IsDhcpDiscover
+ )
+{
+ UINT32 Index;
+ PXEBC_DHCP4_OPTION_ENTRY OptEnt;
+ UINT16 Value;
+ CHAR8 *SystemSerialNumber;
+
+ Index = 0;
+ OptList[0] = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer;
+
+ if (!IsDhcpDiscover) {
+ //
+ // Append message type.
+ //
+ OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MSG_TYPE;
+ OptList[Index]->Length = 1;
+ OptEnt.Mesg = (PXEBC_DHCP4_OPTION_MESG *) OptList[Index]->Data;
+ OptEnt.Mesg->Type = PXEBC_DHCP4_MSG_TYPE_REQUEST;
+ Index++;
+ OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
+
+ //
+ // Append max message size.
+ //
+ OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MAXMSG;
+ OptList[Index]->Length = 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);
+ NetCopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16));
+ Index++;
+ OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
+ }
+ //
+ // Parameter request list option.
+ //
+ OptList[Index]->OpCode = PXEBC_DHCP4_TAG_PARA_LIST;
+ OptList[Index]->Length = 35;
+ OptEnt.Para = (PXEBC_DHCP4_OPTION_PARA *) OptList[Index]->Data;
+ OptEnt.Para->ParaList[0] = PXEBC_DHCP4_TAG_NETMASK;
+ OptEnt.Para->ParaList[1] = PXEBC_DHCP4_TAG_TIME_OFFSET;
+ OptEnt.Para->ParaList[2] = PXEBC_DHCP4_TAG_ROUTER;
+ OptEnt.Para->ParaList[3] = PXEBC_DHCP4_TAG_TIME_SERVER;
+ OptEnt.Para->ParaList[4] = PXEBC_DHCP4_TAG_NAME_SERVER;
+ OptEnt.Para->ParaList[5] = PXEBC_DHCP4_TAG_DNS_SERVER;
+ OptEnt.Para->ParaList[6] = PXEBC_DHCP4_TAG_HOSTNAME;
+ OptEnt.Para->ParaList[7] = PXEBC_DHCP4_TAG_BOOTFILE_LEN;
+ OptEnt.Para->ParaList[8] = PXEBC_DHCP4_TAG_DOMAINNAME;
+ OptEnt.Para->ParaList[9] = PXEBC_DHCP4_TAG_ROOTPATH;
+ OptEnt.Para->ParaList[10] = PXEBC_DHCP4_TAG_EXTEND_PATH;
+ OptEnt.Para->ParaList[11] = PXEBC_DHCP4_TAG_EMTU;
+ OptEnt.Para->ParaList[12] = PXEBC_DHCP4_TAG_TTL;
+ OptEnt.Para->ParaList[13] = PXEBC_DHCP4_TAG_BROADCAST;
+ OptEnt.Para->ParaList[14] = PXEBC_DHCP4_TAG_NIS_DOMAIN;
+ OptEnt.Para->ParaList[15] = PXEBC_DHCP4_TAG_NIS_SERVER;
+ OptEnt.Para->ParaList[16] = PXEBC_DHCP4_TAG_NTP_SERVER;
+ OptEnt.Para->ParaList[17] = PXEBC_DHCP4_TAG_VENDOR;
+ OptEnt.Para->ParaList[18] = PXEBC_DHCP4_TAG_REQUEST_IP;
+ OptEnt.Para->ParaList[19] = PXEBC_DHCP4_TAG_LEASE;
+ OptEnt.Para->ParaList[20] = PXEBC_DHCP4_TAG_SERVER_ID;
+ OptEnt.Para->ParaList[21] = PXEBC_DHCP4_TAG_T1;
+ OptEnt.Para->ParaList[22] = PXEBC_DHCP4_TAG_T2;
+ OptEnt.Para->ParaList[23] = PXEBC_DHCP4_TAG_CLASS_ID;
+ OptEnt.Para->ParaList[24] = PXEBC_DHCP4_TAG_TFTP;
+ OptEnt.Para->ParaList[25] = PXEBC_DHCP4_TAG_BOOTFILE;
+ OptEnt.Para->ParaList[26] = PXEBC_PXE_DHCP4_TAG_UUID;
+ OptEnt.Para->ParaList[27] = 0x80;
+ OptEnt.Para->ParaList[28] = 0x81;
+ OptEnt.Para->ParaList[29] = 0x82;
+ OptEnt.Para->ParaList[30] = 0x83;
+ OptEnt.Para->ParaList[31] = 0x84;
+ OptEnt.Para->ParaList[32] = 0x85;
+ OptEnt.Para->ParaList[33] = 0x86;
+ OptEnt.Para->ParaList[34] = 0x87;
+ Index++;
+ OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
+
+ //
+ // Append UUID/Guid-based client identifier option
+ //
+ OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UUID;
+ OptList[Index]->Length = 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))) {
+ //
+ // GUID not yet set - send all 0xff's to show programable (via SetVariable)
+ // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
+ // GUID not yet set - send all 0's to show not programable
+ //
+ ZeroMem (OptEnt.Uuid->Guid, sizeof (EFI_GUID));
+ }
+
+ //
+ // Append client network device interface option
+ //
+ 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;
+
+ Index++;
+ OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
+
+ //
+ // Append client system architecture option
+ //
+ OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_ARCH;
+ OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_ARCH);
+ OptEnt.Arch = (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->Data;
+ Value = HTONS (SYS_ARCH);
+ NetCopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));
+ Index++;
+ OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
+
+ //
+ // Append client system architecture option
+ //
+ OptList[Index]->OpCode = PXEBC_DHCP4_TAG_CLASS_ID;
+ OptList[Index]->Length = sizeof (PXEBC_DHCP4_OPTION_CLID);
+ OptEnt.Clid = (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->Data;
+ NetCopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_CLID));
+ CvtNum (SYS_ARCH, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType));
+ NetCopyMem (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;
+}
+
+
+/**
+ 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
+
+**/
+EFI_STATUS
+PxeBcDiscvBootService (
+ IN PXEBC_PRIVATE_DATA * Private,
+ IN UINT16 Type,
+ IN UINT16 *Layer,
+ IN BOOLEAN UseBis,
+ IN EFI_IP_ADDRESS * DestIp,
+ IN UINT16 IpCount,
+ IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,
+ IN BOOLEAN IsDiscv,
+ OUT EFI_DHCP4_PACKET * Reply OPTIONAL
+ )
+{
+ EFI_PXE_BASE_CODE_UDP_PORT Sport;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_DHCP4_PROTOCOL *Dhcp4;
+ EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN Token;
+ BOOLEAN IsBCast;
+ EFI_STATUS Status;
+ UINT16 RepIndex;
+ UINT16 SrvIndex;
+ UINT16 TryIndex;
+ EFI_DHCP4_LISTEN_POINT ListenPoint;
+ EFI_DHCP4_PACKET *Response;
+ EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];
+ UINT32 OptCount;
+ EFI_DHCP4_PACKET_OPTION *PxeOpt;
+ PXEBC_OPTION_BOOT_ITEM *PxeBootItem;
+ UINT8 VendorOptLen;
+
+ Mode = Private->PxeBc.Mode;
+ Dhcp4 = Private->Dhcp4;
+ Status = EFI_SUCCESS;
+
+ ZeroMem (&Token, sizeof (EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN));
+
+ if (DestIp == NULL) {
+ Sport = PXEBC_DHCP4_S_PORT;
+ IsBCast = TRUE;
+ } else {
+ Sport = PXEBC_BS_DISCOVER_PORT;
+ IsBCast = FALSE;
+ }
+
+ if (!UseBis && Layer != NULL) {
+ *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK;
+ }
+
+ OptCount = PxeBcBuildDhcpOptions (Private, OptList, FALSE);
+
+ if (IsDiscv) {
+ //
+ // Add vendor option of PXE_BOOT_ITEM
+ //
+ VendorOptLen = (sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1;
+ OptList[OptCount] = NetAllocatePool (VendorOptLen);
+ if (OptList[OptCount] == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ OptList[OptCount]->OpCode = PXEBC_DHCP4_TAG_VENDOR;
+ 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);
+ PxeBootItem = (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->Data;
+ PxeBootItem->Type = HTONS (Type);
+ PxeBootItem->Layer = HTONS (*Layer);
+ PxeOpt->Data[PxeOpt->Length] = PXEBC_DHCP4_TAG_EOP;
+
+ OptCount++;
+ }
+
+ Status = Dhcp4->Build (Dhcp4, &Private->SeedPacket, 0, NULL, OptCount, OptList, &Token.Packet);
+
+ if (IsDiscv) {
+ NetFreePool (OptList[OptCount - 1]);
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Token.Packet->Dhcp4.Header.Xid = NET_RANDOM (NetRandomInitSeed ());
+ Token.Packet->Dhcp4.Header.Reserved = (UINT16) ((IsBCast) ? 0xf000 : 0x0);
+ NetCopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
+
+ Token.RemotePort = Sport;
+
+ if (DestIp == NULL) {
+ NetSetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);
+ } else {
+ NetCopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));
+ }
+
+ NetCopyMem (&Token.GatewayAddress, &Private->GatewayIp, sizeof (EFI_IPv4_ADDRESS));
+
+ if (!IsBCast) {
+ Token.ListenPointCount = 1;
+ Token.ListenPoints = &ListenPoint;
+ Token.ListenPoints[0].ListenPort = PXEBC_BS_DISCOVER_PORT;
+ NetCopyMem (&Token.ListenPoints[0].ListenAddress, &Private->StationIp, sizeof(EFI_IPv4_ADDRESS));
+ NetCopyMem (&Token.ListenPoints[0].SubnetMask, &Private->SubnetMask, sizeof(EFI_IPv4_ADDRESS));
+ }
+ //
+ // Send Pxe Discover
+ //
+ for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) {
+
+ Token.TimeoutValue = PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex;
+
+ Status = Dhcp4->TransmitReceive (Dhcp4, &Token);
+
+ if (Token.Status != EFI_TIMEOUT) {
+ break;
+ }
+ }
+
+ if (!EFI_ERROR (Status)) {
+ //
+ // Find Pxe Reply
+ //
+ RepIndex = 0;
+ SrvIndex = 0;
+ Response = Token.ResponseList;
+
+ while (RepIndex < Token.ResponseCount) {
+
+ while (SrvIndex < IpCount) {
+
+ if (SrvList[SrvIndex].AcceptAnyResponse) {
+ break;
+ }
+
+ if ((SrvList[SrvIndex].Type == Type) && EFI_IP4_EQUAL (&(Response->Dhcp4.Header.ServerAddr), &(Private->ServerIp))) {
+ break;
+ }
+
+ SrvIndex++;
+ }
+
+ if ((IpCount != SrvIndex) || (IpCount == 0)) {
+ break;
+ }
+
+ SrvIndex = 0;
+ RepIndex++;
+
+ Response = (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->Size);
+ }
+
+ if (RepIndex < Token.ResponseCount) {
+
+ if (Reply != NULL) {
+ PxeBcCopyEfiDhcp4Packet (Reply, Response);
+ }
+
+ if (IsDiscv) {
+ NetCopyMem (&(Mode->PxeDiscover), &(Token.Packet->Dhcp4), Token.Packet->Length);
+ Mode->PxeDiscoverValid = TRUE;
+
+ NetCopyMem (Mode->PxeReply.Raw, &Response->Dhcp4, Response->Length);
+ Mode->PxeReplyReceived = TRUE;
+ }
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+
+ //
+ // free the responselist
+ //
+ NetFreePool (Token.ResponseList);
+ }
+ //
+ // Free the dhcp packet
+ //
+ NetFreePool (Token.Packet);
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Buffer GC_NOTO: add argument description
+ @param Length GC_NOTO: add argument description
+ @param OptTag GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_DHCP4_PACKET_OPTION *
+PxeBcParseExtendOptions (
+ IN UINT8 *Buffer,
+ IN UINT32 Length,
+ IN UINT8 OptTag
+ )
+{
+ EFI_DHCP4_PACKET_OPTION *Option;
+ UINT32 Offset;
+
+ Option = (EFI_DHCP4_PACKET_OPTION *) Buffer;
+ Offset = 0;
+
+ while (Offset < Length && Option->OpCode != PXEBC_DHCP4_TAG_EOP) {
+
+ if (Option->OpCode == OptTag) {
+
+ return Option;
+ }
+
+ if (Option->OpCode == PXEBC_DHCP4_TAG_PAD) {
+ Offset++;
+ } else {
+ Offset += Option->Length + 2;
+ }
+
+ Option = (EFI_DHCP4_PACKET_OPTION *) (Buffer + Offset);
+ }
+
+ return NULL;
+}
+
+
+/**
+ This function is to parse and check vendor options.
+
+ @param Dhcp4Option Pointer to dhcp options
+ @param VendorOption Pointer to vendor options
+
+ @return TRUE : Valid vendor options
+ @return FALSE : Invalid vendor options
+
+**/
+BOOLEAN
+PxeBcParseVendorOptions (
+ IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,
+ IN PXEBC_VENDOR_OPTION *VendorOption
+ )
+{
+ UINT32 *BitMap;
+ UINT8 VendorOptionLen;
+ EFI_DHCP4_PACKET_OPTION *PxeOption;
+ UINT8 Offset;
+
+ BitMap = VendorOption->BitMap;
+ VendorOptionLen = Dhcp4Option->Length;
+ PxeOption = (EFI_DHCP4_PACKET_OPTION *) &Dhcp4Option->Data[0];
+ Offset = 0;
+
+ while ((Offset < VendorOptionLen) && (PxeOption->OpCode != PXEBC_DHCP4_TAG_EOP)) {
+ //
+ // Parse every Vendor Option and set its BitMap
+ //
+ switch (PxeOption->OpCode) {
+
+ case PXEBC_VENDOR_TAG_MTFTP_IP:
+
+ NetCopyMem (&VendorOption->MtftpIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
+ break;
+
+ case PXEBC_VENDOR_TAG_MTFTP_CPORT:
+
+ NetCopyMem (&VendorOption->MtftpCPort, PxeOption->Data, sizeof (VendorOption->MtftpCPort));
+ break;
+
+ case PXEBC_VENDOR_TAG_MTFTP_SPORT:
+
+ NetCopyMem (&VendorOption->MtftpSPort, PxeOption->Data, sizeof (VendorOption->MtftpSPort));
+ break;
+
+ case PXEBC_VENDOR_TAG_MTFTP_TIMEOUT:
+
+ VendorOption->MtftpTimeout = *PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_MTFTP_DELAY:
+
+ VendorOption->MtftpDelay = *PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_DISCOVER_CTRL:
+
+ VendorOption->DiscoverCtrl = *PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_DISCOVER_MCAST:
+
+ NetCopyMem (&VendorOption->DiscoverMcastIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
+ break;
+
+ case PXEBC_VENDOR_TAG_BOOT_SERVERS:
+
+ VendorOption->BootSvrLen = PxeOption->Length;
+ VendorOption->BootSvr = (PXEBC_BOOT_SVR_ENTRY *) PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_BOOT_MENU:
+
+ VendorOption->BootMenuLen = PxeOption->Length;
+ VendorOption->BootMenu = (PXEBC_BOOT_MENU_ENTRY *) PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_MENU_PROMPT:
+
+ VendorOption->MenuPromptLen = PxeOption->Length;
+ VendorOption->MenuPrompt = (PXEBC_MENU_PROMPT *) PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_MCAST_ALLOC:
+
+ NetCopyMem (&VendorOption->McastIpBase, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&VendorOption->McastIpBlock, PxeOption->Data + 4, sizeof (VendorOption->McastIpBlock));
+ NetCopyMem (&VendorOption->McastIpRange, PxeOption->Data + 6, sizeof (VendorOption->McastIpRange));
+ break;
+
+ case PXEBC_VENDOR_TAG_CREDENTIAL_TYPES:
+
+ VendorOption->CredTypeLen = PxeOption->Length;
+ VendorOption->CredType = (UINT32 *) PxeOption->Data;
+ break;
+
+ case PXEBC_VENDOR_TAG_BOOT_ITEM:
+
+ NetCopyMem (&VendorOption->BootSrvType, PxeOption->Data, sizeof (VendorOption->BootSrvType));
+ NetCopyMem (&VendorOption->BootSrvLayer, PxeOption->Data + 2, sizeof (VendorOption->BootSrvLayer));
+ break;
+ }
+
+ SET_VENDOR_OPTION_BIT_MAP (BitMap, PxeOption->OpCode);
+
+ if (PxeOption->OpCode == PXEBC_DHCP4_TAG_PAD) {
+ Offset++;
+ } else {
+ Offset = (UINT8) (Offset + PxeOption->Length + 2);
+ }
+
+ PxeOption = (EFI_DHCP4_PACKET_OPTION *) (Dhcp4Option->Data + Offset);
+ }
+
+ //
+ // FixMe, return falas if invalid of any vendor option
+ //
+
+ return TRUE;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Str GC_NOTO: add argument description
+ @param Len GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcDisplayBootItem (
+ IN UINT8 *Str,
+ IN UINT8 Len
+ )
+{
+ UINT8 Tmp;
+
+ Len = (UINT8) MIN (70, Len);
+ Tmp = Str[Len];
+ Str[Len] = 0;
+ AsciiPrint ("%a \n", Str);
+ Str[Len] = Tmp;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+
+ @retval EFI_SUCCESS GC_NOTO: Add description for return value
+ @retval EFI_TIMEOUT GC_NOTO: Add description for return value
+
+**/
+EFI_STATUS
+PxeBcSelectBootPrompt (
+ IN PXEBC_PRIVATE_DATA *Private
+ )
+{
+ PXEBC_CACHED_DHCP4_PACKET *Packet;
+ PXEBC_VENDOR_OPTION *VendorOpt;
+ EFI_EVENT TimeoutEvent;
+ EFI_EVENT DescendEvent;
+ EFI_INPUT_KEY InputKey;
+ EFI_STATUS Status;
+ UINT8 Timeout;
+ UINT8 *Prompt;
+ UINT8 PromptLen;
+ INT32 SecCol;
+ INT32 SecRow;
+
+ TimeoutEvent = NULL;
+ DescendEvent = NULL;
+
+ if (Private->PxeBc.Mode->ProxyOfferReceived) {
+
+ Packet = &Private->ProxyOffer;
+ } else {
+
+ Packet = &Private->Dhcp4Ack;
+ }
+
+ if (Packet->OfferType != DHCP4_PACKET_TYPE_PXE10) {
+ return EFI_NOT_FOUND;
+ }
+
+ VendorOpt = &Packet->PxeVendorOption;
+
+ if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {
+ return EFI_SUCCESS;
+ }
+
+ Timeout = VendorOpt->MenuPrompt->Timeout;
+ Prompt = VendorOpt->MenuPrompt->Prompt;
+ PromptLen = (UINT8) (VendorOpt->MenuPromptLen - 1);
+
+ if (Timeout == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if (Timeout == 255) {
+ return EFI_TIMEOUT;
+ }
+
+ Status = gBS->CreateEvent (
+ EVT_TIMER,
+ TPL_CALLBACK,
+ NULL,
+ NULL,
+ &TimeoutEvent
+ );
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = gBS->SetTimer (
+ TimeoutEvent,
+ TimerRelative,
+ Timeout * TICKS_PER_SECOND
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ Status = gBS->CreateEvent (
+ EVT_TIMER,
+ TPL_CALLBACK,
+ NULL,
+ NULL,
+ &DescendEvent
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ Status = gBS->SetTimer (
+ DescendEvent,
+ TimerPeriodic,
+ TICKS_PER_SECOND
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ SecCol = gST->ConOut->Mode->CursorColumn;
+ SecRow = gST->ConOut->Mode->CursorRow;
+
+ PxeBcDisplayBootItem (Prompt, PromptLen);
+
+ gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
+ AsciiPrint ("(%d) ", Timeout--);
+
+ while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {
+
+ if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {
+ gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
+ AsciiPrint ("(%d) ", Timeout--);
+ }
+
+ if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
+
+ gBS->Stall (10 * TICKS_PER_MS);
+ continue;
+ }
+
+ if (InputKey.ScanCode == 0) {
+
+ switch (InputKey.UnicodeChar) {
+ case CTRL ('c'):
+ Status = EFI_ABORTED;
+ break;
+
+ case CTRL ('m'):
+ case 'm':
+ case 'M':
+ Status = EFI_TIMEOUT;
+ break;
+
+ default:
+ continue;
+ }
+ } else {
+
+ switch (InputKey.ScanCode) {
+ case SCAN_F8:
+ Status = EFI_TIMEOUT;
+ break;
+
+ case SCAN_ESC:
+ Status = EFI_ABORTED;
+ break;
+
+ default:
+ continue;
+ }
+ }
+
+ break;
+ }
+
+ gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1);
+
+ON_EXIT:
+
+ if (DescendEvent != NULL) {
+ gBS->CloseEvent (DescendEvent);
+ }
+
+ if (TimeoutEvent != NULL) {
+ gBS->CloseEvent (TimeoutEvent);
+ }
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param Type GC_NOTO: add argument description
+
+ @retval EFI_ABORTED GC_NOTO: Add description for return value
+ @retval EFI_SUCCESS GC_NOTO: Add description for return value
+
+**/
+EFI_STATUS
+PxeBcSelectBootMenu (
+ IN PXEBC_PRIVATE_DATA *Private,
+ OUT UINT16 *Type,
+ IN BOOLEAN UseDefaultItem
+ )
+{
+ PXEBC_CACHED_DHCP4_PACKET *Packet;
+ PXEBC_VENDOR_OPTION *VendorOpt;
+ EFI_INPUT_KEY InputKey;
+ UINT8 MenuSize;
+ UINT8 MenuNum;
+ INT32 TopRow;
+ UINT16 Select;
+ UINT16 LastSelect;
+ UINT8 Index;
+ BOOLEAN Finish;
+ CHAR8 Blank[70];
+ PXEBC_BOOT_MENU_ENTRY *MenuItem;
+ PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MAX_MENU_NUM];
+
+ Finish = FALSE;
+ Select = 1;
+ Index = 0;
+ *Type = 0;
+
+ if (Private->PxeBc.Mode->ProxyOfferReceived) {
+
+ Packet = &Private->ProxyOffer;
+ } else {
+
+ Packet = &Private->Dhcp4Ack;
+ }
+
+ ASSERT (Packet->OfferType == DHCP4_PACKET_TYPE_PXE10);
+
+ VendorOpt = &Packet->PxeVendorOption;
+
+ if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {
+ return EFI_SUCCESS;
+ }
+
+ SetMem (Blank, sizeof(Blank), ' ');
+
+ MenuSize = VendorOpt->BootMenuLen;
+ MenuItem = VendorOpt->BootMenu;
+
+ while (MenuSize > 0) {
+ MenuArray[Index] = MenuItem;
+ MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3));
+ MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);
+ Index++;
+ }
+
+ if (UseDefaultItem) {
+ *Type = NTOHS (MenuArray[0]->Type);
+ return EFI_SUCCESS;
+ }
+
+ MenuNum = Index;
+
+ for (Index = 0; Index < MenuNum; Index++) {
+ PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->DescLen);
+ }
+
+ TopRow = gST->ConOut->Mode->CursorRow - MenuNum;
+
+ do {
+ //
+ // highlight selected row
+ //
+ gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));
+ gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select);
+ Blank[MenuArray[Select]->DescLen] = 0;
+ AsciiPrint ("%a\r", Blank);
+ PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->DescLen);
+ gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
+ LastSelect = Select;
+
+ while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
+ gBS->Stall (10 * TICKS_PER_MS);
+ }
+
+ if (!InputKey.ScanCode) {
+ switch (InputKey.UnicodeChar) {
+ case CTRL ('c'):
+ InputKey.ScanCode = SCAN_ESC;
+ break;
+
+ case CTRL ('j'): /* linefeed */
+ case CTRL ('m'): /* return */
+ Finish = TRUE;
+ break;
+
+ case CTRL ('i'): /* tab */
+ case ' ':
+ case 'd':
+ case 'D':
+ InputKey.ScanCode = SCAN_DOWN;
+ break;
+
+ case CTRL ('h'): /* backspace */
+ case 'u':
+ case 'U':
+ InputKey.ScanCode = SCAN_UP;
+ break;
+
+ default:
+ InputKey.ScanCode = 0;
+ }
+ }
+
+ switch (InputKey.ScanCode) {
+ case SCAN_LEFT:
+ case SCAN_UP:
+ if (Select) {
+ --Select;
+ }
+
+ break;
+
+ case SCAN_DOWN:
+ case SCAN_RIGHT:
+ if (++Select == MenuNum) {
+ --Select;
+ }
+
+ break;
+
+ case SCAN_PAGE_UP:
+ case SCAN_HOME:
+ Select = 0;
+ break;
+
+ case SCAN_PAGE_DOWN:
+ case SCAN_END:
+ Select = (UINT16) (MenuNum - 1);
+ break;
+
+ case SCAN_ESC:
+ return EFI_ABORTED;
+ }
+
+ /* unhighlight last selected row */
+ gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
+ gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect);
+ Blank[MenuArray[LastSelect]->DescLen] = 0;
+ AsciiPrint ("%a\r", Blank);
+ PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSelect]->DescLen);
+ gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
+ } while (!Finish);
+
+ //
+ // Swap the byte order
+ //
+ *Type = NTOHS (MenuArray[Select]->Type);
+
+ return EFI_SUCCESS;
+}
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h
new file mode 100644
index 0000000000..4cb9aef46b
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h
@@ -0,0 +1,542 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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.h
+
+Abstract:
+
+ Dhcp and Discover routines for PxeBc
+
+
+**/
+
+#ifndef __EFI_PXEBC_DHCP_H__
+#define __EFI_PXEBC_DHCP_H__
+
+enum {
+ PXEBC_DHCP4_MAX_OPTION_NUM = 16,
+ PXEBC_DHCP4_MAX_OPTION_SIZE = 312,
+ PXEBC_DHCP4_MAX_PACKET_SIZE = 1472,
+
+ PXEBC_DHCP4_S_PORT = 67,
+ PXEBC_DHCP4_C_PORT = 68,
+ PXEBC_BS_DOWNLOAD_PORT = 69,
+ PXEBC_BS_DISCOVER_PORT = 4011,
+
+ PXEBC_DHCP4_OPCODE_REQUEST = 1,
+ PXEBC_DHCP4_OPCODE_REPLY = 2,
+ PXEBC_DHCP4_MSG_TYPE_REQUEST = 3,
+ PXEBC_DHCP4_MAGIC = 0x63538263, // network byte order
+ //
+ // Dhcp Options
+ //
+ PXEBC_DHCP4_TAG_PAD = 0, // Pad Option
+ PXEBC_DHCP4_TAG_EOP = 255, // End Option
+ PXEBC_DHCP4_TAG_NETMASK = 1, // Subnet Mask
+ PXEBC_DHCP4_TAG_TIME_OFFSET = 2, // Time Offset from UTC
+ PXEBC_DHCP4_TAG_ROUTER = 3, // Router option,
+ PXEBC_DHCP4_TAG_TIME_SERVER = 4, // Time Server
+ PXEBC_DHCP4_TAG_NAME_SERVER = 5, // Name Server
+ PXEBC_DHCP4_TAG_DNS_SERVER = 6, // Domain Name Server
+ PXEBC_DHCP4_TAG_HOSTNAME = 12, // Host Name
+ PXEBC_DHCP4_TAG_BOOTFILE_LEN = 13, // Boot File Size
+ PXEBC_DHCP4_TAG_DUMP = 14, // Merit Dump File
+ PXEBC_DHCP4_TAG_DOMAINNAME = 15, // Domain Name
+ PXEBC_DHCP4_TAG_ROOTPATH = 17, // Root path
+ PXEBC_DHCP4_TAG_EXTEND_PATH = 18, // Extensions Path
+ PXEBC_DHCP4_TAG_EMTU = 22, // Maximum Datagram Reassembly Size
+ PXEBC_DHCP4_TAG_TTL = 23, // Default IP Time-to-live
+ PXEBC_DHCP4_TAG_BROADCAST = 28, // Broadcast Address
+ PXEBC_DHCP4_TAG_NIS_DOMAIN = 40, // Network Information Service Domain
+ PXEBC_DHCP4_TAG_NIS_SERVER = 41, // Network Information Servers
+ PXEBC_DHCP4_TAG_NTP_SERVER = 42, // Network Time Protocol Servers
+ PXEBC_DHCP4_TAG_VENDOR = 43, // Vendor Specific Information
+ PXEBC_DHCP4_TAG_REQUEST_IP = 50, // Requested IP Address
+ PXEBC_DHCP4_TAG_LEASE = 51, // IP Address Lease Time
+ PXEBC_DHCP4_TAG_OVERLOAD = 52, // Option Overload
+ PXEBC_DHCP4_TAG_MSG_TYPE = 53, // DHCP Message Type
+ PXEBC_DHCP4_TAG_SERVER_ID = 54, // Server Identifier
+ PXEBC_DHCP4_TAG_PARA_LIST = 55, // Parameter Request List
+ PXEBC_DHCP4_TAG_MAXMSG = 57, // Maximum DHCP Message Size
+ PXEBC_DHCP4_TAG_T1 = 58, // Renewal (T1) Time Value
+ PXEBC_DHCP4_TAG_T2 = 59, // Rebinding (T2) Time Value
+ PXEBC_DHCP4_TAG_CLASS_ID = 60, // Vendor class identifier
+ PXEBC_DHCP4_TAG_CLIENT_ID = 61, // Client-identifier
+ PXEBC_DHCP4_TAG_TFTP = 66, // TFTP server name
+ PXEBC_DHCP4_TAG_BOOTFILE = 67, // Bootfile name
+ PXEBC_PXE_DHCP4_TAG_ARCH = 93,
+ PXEBC_PXE_DHCP4_TAG_UNDI = 94,
+ PXEBC_PXE_DHCP4_TAG_UUID = 97,
+ //
+ // Sub-Options in Dhcp Vendor Option
+ //
+ PXEBC_VENDOR_TAG_MTFTP_IP = 1,
+ PXEBC_VENDOR_TAG_MTFTP_CPORT = 2,
+ PXEBC_VENDOR_TAG_MTFTP_SPORT = 3,
+ PXEBC_VENDOR_TAG_MTFTP_TIMEOUT = 4,
+ PXEBC_VENDOR_TAG_MTFTP_DELAY = 5,
+ PXEBC_VENDOR_TAG_DISCOVER_CTRL = 6,
+ PXEBC_VENDOR_TAG_DISCOVER_MCAST = 7,
+ PXEBC_VENDOR_TAG_BOOT_SERVERS = 8,
+ PXEBC_VENDOR_TAG_BOOT_MENU = 9,
+ PXEBC_VENDOR_TAG_MENU_PROMPT = 10,
+ PXEBC_VENDOR_TAG_MCAST_ALLOC = 11,
+ PXEBC_VENDOR_TAG_CREDENTIAL_TYPES = 12,
+ PXEBC_VENDOR_TAG_BOOT_ITEM = 71,
+
+ PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT = 4,
+ PXEBC_DHCP4_DISCOVER_RETRIES = 4,
+
+ PXEBC_MAX_MENU_NUM = 24,
+ PXEBC_MAX_OFFER_NUM = 16,
+
+ PXEBC_BOOT_REQUEST_TIMEOUT = 1,
+ PXEBC_BOOT_REQUEST_RETRIES = 4,
+
+ PXEBC_DHCP4_OVERLOAD_FILE = 1,
+ PXEBC_DHCP4_OVERLOAD_SERVER_NAME = 2
+};
+
+//
+// The array index of the DHCP4 option tag interested
+//
+enum {
+ PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN,
+ PXEBC_DHCP4_TAG_INDEX_VENDOR,
+ PXEBC_DHCP4_TAG_INDEX_OVERLOAD,
+ PXEBC_DHCP4_TAG_INDEX_MSG_TYPE,
+ PXEBC_DHCP4_TAG_INDEX_SERVER_ID,
+ PXEBC_DHCP4_TAG_INDEX_CLASS_ID,
+ PXEBC_DHCP4_TAG_INDEX_BOOTFILE,
+ PXEBC_DHCP4_TAG_INDEX_MAX
+};
+
+//
+// The type of DHCP OFFER, arranged by priority, PXE10 has the highest priority.
+//
+enum {
+ DHCP4_PACKET_TYPE_PXE10,
+ DHCP4_PACKET_TYPE_WFM11A,
+ DHCP4_PACKET_TYPE_BINL,
+ DHCP4_PACKET_TYPE_DHCP_ONLY,
+ DHCP4_PACKET_TYPE_MAX,
+ DHCP4_PACKET_TYPE_BOOTP = DHCP4_PACKET_TYPE_MAX
+};
+
+#define BIT(x) (1 << x)
+#define CTRL(x) (0x1F & (x))
+
+//
+// WfM11a options
+//
+#define MTFTP_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_MTFTP_IP) | \
+ BIT (PXEBC_VENDOR_TAG_MTFTP_CPORT) | \
+ BIT (PXEBC_VENDOR_TAG_MTFTP_SPORT) | \
+ BIT (PXEBC_VENDOR_TAG_MTFTP_TIMEOUT) | \
+ BIT (PXEBC_VENDOR_TAG_MTFTP_DELAY))
+//
+// Discoverty options
+//
+#define DISCOVER_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_DISCOVER_CTRL) | \
+ BIT (PXEBC_VENDOR_TAG_DISCOVER_MCAST) | \
+ BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS) | \
+ BIT (PXEBC_VENDOR_TAG_BOOT_MENU) | \
+ BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))
+
+#define IS_VALID_BOOT_PROMPT(x) \
+ ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_MENU_PROMPT)) == BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))
+
+#define IS_VALID_BOOT_MENU(x) \
+ ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_MENU)) == BIT (PXEBC_VENDOR_TAG_BOOT_MENU))
+
+#define IS_VALID_MTFTP_VENDOR_OPTION(x) \
+ (((UINT32) ((x)[0]) & MTFTP_VENDOR_OPTION_BIT_MAP) == MTFTP_VENDOR_OPTION_BIT_MAP)
+
+#define IS_VALID_DISCOVER_VENDOR_OPTION(x) (((UINT32) ((x)[0]) & DISCOVER_VENDOR_OPTION_BIT_MAP) != 0)
+
+#define IS_VALID_CREDENTIAL_VENDOR_OPTION(x) \
+ (((UINT32) ((x)[0]) & BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) == BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES))
+
+#define IS_VALID_BOOTITEM_VENDOR_OPTION(x) \
+ (((UINT32) ((x)[PXEBC_VENDOR_TAG_BOOT_ITEM / 32]) & BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32)) \
+ == BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32))
+
+#define IS_DISABLE_BCAST_DISCOVER(x) (((x) & BIT (0)) == BIT (0))
+#define IS_DISABLE_MCAST_DISCOVER(x) (((x) & BIT (1)) == BIT (1))
+#define IS_ENABLE_USE_SERVER_LIST(x) (((x) & BIT (2)) == BIT (2))
+#define IS_ENABLE_BOOT_FILE_NAME(x) (((x) & BIT (3)) == BIT (3))
+
+#define SET_VENDOR_OPTION_BIT_MAP(x, y) ((UINT32) ((x)[(y) / 32]) = (UINT32) ((x)[(y) / 32]) | BIT ((y) % 32))
+
+#pragma pack(1)
+typedef struct {
+ UINT8 ParaList[135];
+} PXEBC_DHCP4_OPTION_PARA;
+
+typedef struct {
+ UINT16 Size;
+} PXEBC_DHCP4_OPTION_MAX_MESG_SIZE;
+
+typedef struct {
+ UINT8 Type;
+ UINT8 MajorVer;
+ UINT8 MinorVer;
+} PXEBC_DHCP4_OPTION_UNDI;
+
+typedef struct {
+ UINT8 Type;
+} PXEBC_DHCP4_OPTION_MESG;
+
+typedef struct {
+ UINT16 Type;
+} PXEBC_DHCP4_OPTION_ARCH;
+
+#define DEFAULT_CLASS_ID_DATA "PXEClient:Arch:?????:????:??????"
+
+typedef struct {
+ UINT8 ClassIdentifier[10];
+ UINT8 ArchitecturePrefix[5];
+ UINT8 ArchitectureType[5];
+ UINT8 Lit3[1];
+ UINT8 InterfaceName[4];
+ UINT8 Lit4[1];
+ UINT8 UndiMajor[3];
+ UINT8 UndiMinor[3];
+} PXEBC_DHCP4_OPTION_CLID;
+
+typedef struct {
+ UINT8 Type;
+ UINT8 Guid[16];
+} PXEBC_DHCP4_OPTION_UUID;
+
+typedef struct {
+ UINT16 Type;
+ UINT16 Layer;
+} PXEBC_OPTION_BOOT_ITEM;
+
+#pragma pack()
+
+typedef union {
+ PXEBC_DHCP4_OPTION_PARA *Para;
+ PXEBC_DHCP4_OPTION_UNDI *Undi;
+ PXEBC_DHCP4_OPTION_ARCH *Arch;
+ PXEBC_DHCP4_OPTION_CLID *Clid;
+ PXEBC_DHCP4_OPTION_UUID *Uuid;
+ PXEBC_DHCP4_OPTION_MESG *Mesg;
+ PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize;
+} PXEBC_DHCP4_OPTION_ENTRY;
+
+typedef struct {
+ UINT16 Type;
+ UINT8 IpCnt;
+ EFI_IPv4_ADDRESS IpAddr[1];
+} PXEBC_BOOT_SVR_ENTRY;
+
+typedef struct {
+ UINT16 Type;
+ UINT8 DescLen;
+ UINT8 DescStr[1];
+} PXEBC_BOOT_MENU_ENTRY;
+
+typedef struct {
+ UINT8 Timeout;
+ UINT8 Prompt[1];
+} PXEBC_MENU_PROMPT;
+
+typedef struct {
+ UINT32 BitMap[8];
+ EFI_IPv4_ADDRESS MtftpIp;
+ UINT16 MtftpCPort;
+ UINT16 MtftpSPort;
+ UINT8 MtftpTimeout;
+ UINT8 MtftpDelay;
+ UINT8 DiscoverCtrl;
+ EFI_IPv4_ADDRESS DiscoverMcastIp;
+ EFI_IPv4_ADDRESS McastIpBase;
+ UINT16 McastIpBlock;
+ UINT16 McastIpRange;
+ UINT16 BootSrvType;
+ UINT16 BootSrvLayer;
+ PXEBC_BOOT_SVR_ENTRY *BootSvr;
+ UINT8 BootSvrLen;
+ PXEBC_BOOT_MENU_ENTRY *BootMenu;
+ UINT8 BootMenuLen;
+ PXEBC_MENU_PROMPT *MenuPrompt;
+ UINT8 MenuPromptLen;
+ UINT32 *CredType;
+ UINT8 CredTypeLen;
+} PXEBC_VENDOR_OPTION;
+
+#define PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE (EFI_FIELD_OFFSET (EFI_DHCP4_PACKET, Dhcp4) + PXEBC_DHCP4_MAX_PACKET_SIZE)
+
+typedef struct {
+ union {
+ EFI_DHCP4_PACKET Offer;
+ EFI_DHCP4_PACKET Ack;
+ UINT8 Buffer[PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE];
+ } Packet;
+
+ BOOLEAN IsPxeOffer;
+ UINT8 OfferType;
+ EFI_DHCP4_PACKET_OPTION *Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_MAX];
+ PXEBC_VENDOR_OPTION PxeVendorOption;
+} PXEBC_CACHED_DHCP4_PACKET;
+
+#define GET_NEXT_DHCP_OPTION(Opt) \
+ (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)
+
+#define GET_OPTION_BUFFER_LEN(Pkt) ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)
+#define IS_PROXY_DHCP_OFFER(Offer) EFI_IP4_EQUAL (&((Offer)->Dhcp4.Header.YourAddr), &mZeroIp4Addr)
+
+#define GET_NEXT_BOOT_SVR_ENTRY(Ent) \
+ (PXEBC_BOOT_SVR_ENTRY *) ((UINT8 *) Ent + sizeof (*(Ent)) + ((Ent)->IpCnt - 1) * sizeof (EFI_IPv4_ADDRESS))
+
+VOID
+PxeBcInitSeedPacket (
+ IN EFI_DHCP4_PACKET *Seed,
+ IN EFI_UDP4_PROTOCOL *Udp4
+ )
+/*++
+
+Routine Description:
+
+ GC_NOTO: Add function description
+
+Arguments:
+
+ Seed - GC_NOTO: add argument description
+ Udp4 - GC_NOTO: add argument description
+
+Returns:
+
+ GC_NOTO: add return values
+
+--*/
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param CachedPacket GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+BOOLEAN
+PxeBcParseCachedDhcpPacket (
+ IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcCheckSelectedOffer (
+ IN PXEBC_PRIVATE_DATA *Private
+ )
+;
+
+
+/**
+ 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
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcDhcpCallBack (
+ IN EFI_DHCP4_PROTOCOL * This,
+ IN VOID *Context,
+ IN EFI_DHCP4_STATE CurrentState,
+ IN EFI_DHCP4_EVENT Dhcp4Event,
+ IN EFI_DHCP4_PACKET * Packet OPTIONAL,
+ OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
+ )
+;
+
+
+/**
+ 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
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcDiscvBootService (
+ IN PXEBC_PRIVATE_DATA * Private,
+ IN UINT16 Type,
+ IN UINT16 *Layer,
+ IN BOOLEAN UseBis,
+ IN EFI_IP_ADDRESS * DestIp,
+ IN UINT16 IpCount,
+ IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,
+ IN BOOLEAN IsDiscv,
+ OUT EFI_DHCP4_PACKET * Reply OPTIONAL
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param OptList GC_NOTO: add argument description
+ @param IsDhcpDiscover GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+UINT32
+PxeBcBuildDhcpOptions (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_DHCP4_PACKET_OPTION **OptList,
+ IN BOOLEAN IsDhcpDiscover
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param OptList GC_NOTO: add argument description
+ @param Type GC_NOTO: add argument description
+ @param Layer GC_NOTO: add argument description
+ @param OptLen GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcCreateBootOptions (
+ IN EFI_DHCP4_PACKET_OPTION *OptList,
+ IN UINT16 Type,
+ IN UINT16 *Layer,
+ OUT UINT32 *OptLen
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Buffer GC_NOTO: add argument description
+ @param Length GC_NOTO: add argument description
+ @param OptTag GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_DHCP4_PACKET_OPTION *
+PxeBcParseExtendOptions (
+ IN UINT8 *Buffer,
+ IN UINT32 Length,
+ IN UINT8 OptTag
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Dhcp4Option GC_NOTO: add argument description
+ @param VendorOption GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+BOOLEAN
+PxeBcParseVendorOptions (
+ IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,
+ IN PXEBC_VENDOR_OPTION *VendorOption
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param Info GC_NOTO: add argument description
+ @param Type GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcSelectBootServers (
+ IN PXEBC_PRIVATE_DATA *Private,
+ OUT EFI_PXE_BASE_CODE_DISCOVER_INFO **Info,
+ OUT UINT16 *Type
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcSelectBootPrompt (
+ IN PXEBC_PRIVATE_DATA *Private
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument description
+ @param Type GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+PxeBcSelectBootMenu (
+ IN PXEBC_PRIVATE_DATA *Private,
+ OUT UINT16 *Type,
+ IN BOOLEAN UseDefaultItem
+ )
+;
+
+#endif
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c
new file mode 100644
index 0000000000..546e6aee81
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c
@@ -0,0 +1,451 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcDriver.c
+
+Abstract:
+
+ The driver binding for IP4 CONFIG protocol.
+
+
+**/
+
+
+#include "PxeBcImpl.h"
+
+
+/**
+ The entry point for PxeBc driver which install the driver
+ binding and component name protocol on its image.
+
+ @param ImageHandle The Image handle of the driver
+ @param SystemTable The system table
+
+ @return EFI_SUCCESS
+ @return Others
+
+**/
+EFI_STATUS
+PxeBcDriverEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return EfiLibInstallDriverBindingComponentName2 (
+ ImageHandle,
+ SystemTable,
+ &gPxeBcDriverBinding,
+ ImageHandle,
+ &gPxeBcComponentName,
+ &gPxeBcComponentName2
+ );
+}
+
+
+/**
+ Test to see if this driver supports ControllerHandle.
+
+ @param This Protocol instance pointer.
+ @param ControllerHandle Handle of device to test
+ @param RemainingDevicePath Optional parameter use to pick a specific child
+ device to start.
+
+ @return EFI_SUCCES
+ @return EFI_ALREADY_STARTED
+ @return Others
+
+**/
+EFI_STATUS
+EFIAPI
+PxeBcDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL * This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
+ )
+{
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ EFI_STATUS Status;
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiPxeBaseCodeProtocolGuid,
+ (VOID **) &PxeBc,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+
+ if (!EFI_ERROR (Status)) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiDhcp4ServiceBindingProtocolGuid,
+ NULL,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL
+ );
+
+ if (!EFI_ERROR (Status)) {
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiMtftp4ServiceBindingProtocolGuid,
+ NULL,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL
+ );
+
+ }
+
+ return Status;
+}
+
+
+/**
+ Start this driver on ControllerHandle.
+
+ @param This Protocol instance pointer.
+ @param ControllerHandle Handle of device to bind driver to
+ @param RemainingDevicePath Optional parameter use to pick a specific child
+ device to start.
+
+ @return EFI_SUCCES
+ @return EFI_ALREADY_STARTED
+ @return EFI_OUT_OF_RESOURCES
+ @return Others
+
+**/
+EFI_STATUS
+EFIAPI
+PxeBcDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL * This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ UINTN Index;
+ EFI_STATUS Status;
+
+ Private = NetAllocateZeroPool (sizeof (PXEBC_PRIVATE_DATA));
+ if (Private == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Private->Signature = PXEBC_PRIVATE_DATA_SIGNATURE;
+ Private->Controller = ControllerHandle;
+ Private->Image = This->DriverBindingHandle;
+ CopyMem (&Private->PxeBc, &mPxeBcProtocolTemplate, sizeof (Private->PxeBc));
+ Private->PxeBc.Mode = &Private->Mode;
+ CopyMem (&Private->LoadFile, &mLoadFileProtocolTemplate, sizeof (Private->LoadFile));
+
+ Private->ProxyOffer.Packet.Offer.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;
+ Private->Dhcp4Ack.Packet.Ack.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;
+ Private->PxeReply.Packet.Ack.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;
+
+ for (Index = 0; Index < PXEBC_MAX_OFFER_NUM; Index++) {
+ Private->Dhcp4Offers[Index].Packet.Offer.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE;
+ }
+
+ //
+ // Get the NII interface
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
+ (VOID **) &Private->Nii,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ Status = NetLibCreateServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiDhcp4ServiceBindingProtocolGuid,
+ &Private->Dhcp4Child
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ Status = gBS->OpenProtocol (
+ Private->Dhcp4Child,
+ &gEfiDhcp4ProtocolGuid,
+ (VOID **) &Private->Dhcp4,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ Status = NetLibCreateServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiMtftp4ServiceBindingProtocolGuid,
+ &Private->Mtftp4Child
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ Status = gBS->OpenProtocol (
+ Private->Mtftp4Child,
+ &gEfiMtftp4ProtocolGuid,
+ (VOID **) &Private->Mtftp4,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ Status = NetLibCreateServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiUdp4ServiceBindingProtocolGuid,
+ &Private->Udp4Child
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ Status = gBS->OpenProtocol (
+ Private->Udp4Child,
+ &gEfiUdp4ProtocolGuid,
+ (VOID **) &Private->Udp4,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ NetZeroMem (&Private->Udp4CfgData, sizeof (EFI_UDP4_CONFIG_DATA));
+ Private->Udp4CfgData.AcceptBroadcast = TRUE;
+ Private->Udp4CfgData.AcceptPromiscuous = FALSE;
+ Private->Udp4CfgData.AcceptAnyPort = FALSE;
+ Private->Udp4CfgData.AllowDuplicatePort = TRUE;
+ Private->Udp4CfgData.TypeOfService = DEFAULT_ToS;
+ Private->Udp4CfgData.TimeToLive = DEFAULT_TTL;
+ Private->Udp4CfgData.DoNotFragment = FALSE;
+ Private->Udp4CfgData.ReceiveTimeout = 10000; // 10 milliseconds
+ Private->Udp4CfgData.UseDefaultAddress = FALSE;
+
+ PxeBcInitSeedPacket (&Private->SeedPacket, Private->Udp4);
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiPxeBaseCodeProtocolGuid,
+ &Private->PxeBc,
+ &gEfiLoadFileProtocolGuid,
+ &Private->LoadFile,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_ERROR;
+ }
+
+ return EFI_SUCCESS;
+
+ON_ERROR:
+
+ if (Private->Udp4Child != NULL) {
+ gBS->CloseProtocol (
+ Private->Udp4Child,
+ &gEfiUdp4ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ NetLibDestroyServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiUdp4ProtocolGuid,
+ Private->Udp4Child
+ );
+ }
+
+ if (Private->Mtftp4Child != NULL) {
+ gBS->CloseProtocol (
+ Private->Mtftp4Child,
+ &gEfiMtftp4ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
+ NetLibDestroyServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiMtftp4ProtocolGuid,
+ Private->Mtftp4Child
+ );
+ }
+
+ if (Private->Dhcp4Child != NULL) {
+ gBS->CloseProtocol (
+ Private->Dhcp4Child,
+ &gEfiDhcp4ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
+ NetLibDestroyServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiDhcp4ProtocolGuid,
+ Private->Dhcp4Child
+ );
+ }
+
+ NetFreePool (Private);
+
+ return Status;
+}
+
+
+/**
+ Stop this driver on ControllerHandle.
+
+ @param This Protocol instance pointer.
+ @param ControllerHandle Handle of device to stop driver on
+ @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
+ children is zero stop the entire bus driver.
+ @param ChildHandleBuffer List of Child Handles to Stop.
+
+ @return EFI_SUCCESS
+ @return EFI_DEVICE_ERROR
+ @return Others
+
+**/
+EFI_STATUS
+EFIAPI
+PxeBcDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ EFI_HANDLE NicHandle;
+ EFI_STATUS Status;
+
+ NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid);
+
+ if (NicHandle == NULL) {
+
+ NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiMtftp4ProtocolGuid);
+
+ if (NicHandle == NULL) {
+
+ return EFI_DEVICE_ERROR;
+ }
+ }
+
+ Status = gBS->OpenProtocol (
+ NicHandle,
+ &gEfiPxeBaseCodeProtocolGuid,
+ (VOID **) &PxeBc,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (PxeBc);
+
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ NicHandle,
+ &gEfiPxeBaseCodeProtocolGuid,
+ &Private->PxeBc,
+ &gEfiLoadFileProtocolGuid,
+ &Private->LoadFile,
+ NULL
+ );
+
+ if (!EFI_ERROR (Status)) {
+
+ gBS->CloseProtocol (
+ Private->Udp4Child,
+ &gEfiUdp4ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ NetLibDestroyServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiUdp4ServiceBindingProtocolGuid,
+ Private->Udp4Child
+ );
+
+ gBS->CloseProtocol (
+ Private->Dhcp4Child,
+ &gEfiDhcp4ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ NetLibDestroyServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiDhcp4ServiceBindingProtocolGuid,
+ Private->Dhcp4Child
+ );
+
+ gBS->CloseProtocol (
+ Private->Mtftp4Child,
+ &gEfiMtftp4ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ NetLibDestroyServiceChild (
+ ControllerHandle,
+ This->DriverBindingHandle,
+ &gEfiMtftp4ServiceBindingProtocolGuid,
+ Private->Mtftp4Child
+ );
+
+ NetFreePool (Private);
+ }
+
+ return Status;
+}
+
+EFI_DRIVER_BINDING_PROTOCOL gPxeBcDriverBinding = {
+ PxeBcDriverBindingSupported,
+ PxeBcDriverBindingStart,
+ PxeBcDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h
new file mode 100644
index 0000000000..4cb1e2b107
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h
@@ -0,0 +1,103 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcDriver.h
+
+Abstract:
+
+
+**/
+
+#ifndef __EFI_PXEBC_DRIVER_H__
+#define __EFI_PXEBC_DRIVER_H__
+
+EFI_STATUS
+PxeBcDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Controller,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+ Routine Description:
+ Test to see if this driver supports ControllerHandle.
+
+ Arguments:
+ This - Protocol instance pointer.
+ ControllerHandle - Handle of device to test
+ RemainingDevicePath - Optional parameter use to pick a specific child
+ device to start.
+
+ Returns:
+ EFI_SUCCES
+ EFI_ALREADY_STARTED
+ Others
+
+--*/
+// GC_NOTO: Controller - add argument and description to function comment
+;
+
+
+/**
+ Start this driver on ControllerHandle.
+
+ @param This Protocol instance pointer.
+ @param ControllerHandle Handle of device to bind driver to
+ @param RemainingDevicePath Optional parameter use to pick a specific child
+ device to start.
+
+ @return EFI_SUCCES
+ @return EFI_ALREADY_STARTED
+ @return EFI_OUT_OF_RESOURCES
+ @return Others
+
+**/
+// GC_NOTO: Controller - add argument and description to function comment
+EFI_STATUS
+PxeBcDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Controller,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+;
+
+
+/**
+ Stop this driver on ControllerHandle.
+
+ @param This Protocol instance pointer.
+ @param ControllerHandle Handle of device to stop driver on
+ @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
+ children is zero stop the entire bus driver.
+ @param ChildHandleBuffer List of Child Handles to Stop.
+
+ @return EFI_SUCCESS
+ @return EFI_DEVICE_ERROR
+ @return Others
+
+**/
+// GC_NOTO: Controller - add argument and description to function comment
+EFI_STATUS
+PxeBcDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Controller,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+;
+
+extern EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2;
+extern EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName;
+extern EFI_DRIVER_BINDING_PROTOCOL gPxeBcDriverBinding;
+#endif
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
new file mode 100644
index 0000000000..8d7b3d03ef
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
@@ -0,0 +1,1866 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcImpl.c
+
+Abstract:
+
+ Interface routines for PxeBc
+
+
+**/
+
+
+#include "PxeBcImpl.h"
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param UseIpv6 GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_ALREADY_STARTED GC_NOTO: Add description for
+ return value
+ @retval EFI_UNSUPPORTED GC_NOTO: Add description for
+ return value
+ @retval EFI_SUCCESS GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcStart (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN BOOLEAN UseIpv6
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_STATUS Status;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+
+ if (Mode->Started) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ if (UseIpv6) {
+ //
+ // IPv6 is not supported now.
+ //
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Configure the udp4 instance to let it receive data
+ //
+ Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Private->AddressIsOk = FALSE;
+
+ ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));
+
+ Mode->Started = TRUE;
+ Mode->TTL = DEFAULT_TTL;
+ Mode->ToS = DEFAULT_ToS;
+ Mode->AutoArp = TRUE;
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_NOT_STARTED GC_NOTO: Add description for
+ return value
+ @retval EFI_SUCCESS GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcStop (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+
+ if (!Mode->Started) {
+ return EFI_NOT_STARTED;
+ }
+
+ Mode->Started = FALSE;
+
+ Private->Udp4->Configure (Private->Udp4, NULL);
+
+ Private->Dhcp4->Stop (Private->Dhcp4);
+ Private->Dhcp4->Configure (Private->Dhcp4, NULL);
+
+ Private->FileSize = 0;
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param SortOffers GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_NOT_STARTED GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcDhcp (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN BOOLEAN SortOffers
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_DHCP4_PROTOCOL *Dhcp4;
+ EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;
+ EFI_DHCP4_MODE_DATA Dhcp4Mode;
+ EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];
+ UINT32 OptCount;
+ UINT32 DiscoverTimeout;
+ UINTN Index;
+ EFI_STATUS Status;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = EFI_SUCCESS;
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+ Dhcp4 = Private->Dhcp4;
+ Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DHCP;
+ Private->SortOffers = SortOffers;
+
+ if (!Mode->Started) {
+ return EFI_NOT_STARTED;
+ }
+ //
+ // Initialize the DHCP options and build the option list
+ //
+ OptCount = PxeBcBuildDhcpOptions (Private, OptList, TRUE);
+
+ //
+ // Set the DHCP4 config data.
+ //
+ NetZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));
+ Dhcp4CfgData.OptionCount = OptCount;
+ Dhcp4CfgData.OptionList = OptList;
+ Dhcp4CfgData.Dhcp4Callback = PxeBcDhcpCallBack;
+ Dhcp4CfgData.CallbackContext = Private;
+ Dhcp4CfgData.DiscoverTryCount = 1;
+ Dhcp4CfgData.DiscoverTimeout = &DiscoverTimeout;
+
+ for (Index = 0; Index < PXEBC_DHCP4_DISCOVER_RETRIES; Index++) {
+ //
+ // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.
+ //
+ DiscoverTimeout = (PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT << Index);
+
+ Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+ //
+ // Zero those arrays to record the varies numbers of DHCP OFFERS.
+ //
+ Private->NumOffers = 0;
+ Private->BootpIndex = 0;
+ NetZeroMem (Private->ServerCount, sizeof (Private->ServerCount));
+ NetZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));
+
+ Status = Dhcp4->Start (Dhcp4, NULL);
+ if (EFI_ERROR (Status)) {
+ if (Status == EFI_TIMEOUT) {
+ //
+ // If no response is received or all received offers don't match
+ // the PXE boot requirements, EFI_TIMEOUT will be returned.
+ //
+ continue;
+ }
+ //
+ // Other error status means the DHCP really fails.
+ //
+ break;
+ }
+
+ Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ ASSERT (Dhcp4Mode.State == Dhcp4Bound);
+
+ NetCopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));
+
+ //
+ // Check the selected offer to see whether BINL is required, if no or BINL is
+ // finished, set the various Mode members.
+ //
+ Status = PxeBcCheckSelectedOffer (Private);
+ if (!EFI_ERROR (Status)) {
+ break;
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ Dhcp4->Stop (Dhcp4);
+ Dhcp4->Configure (Dhcp4, NULL);
+ } else {
+ //
+ // Remove the previously configured option list and callback function
+ //
+ NetZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));
+ Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);
+
+ Private->AddressIsOk = TRUE;
+ }
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This 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 Info GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_NOT_STARTED GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcDiscover (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN UINT16 Type,
+ IN UINT16 *Layer,
+ IN BOOLEAN UseBis,
+ IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo;
+ EFI_PXE_BASE_CODE_SRVLIST *SrvList;
+ EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList;
+ PXEBC_CACHED_DHCP4_PACKET *Packet;
+ PXEBC_VENDOR_OPTION *VendorOpt;
+ UINT16 Index;
+ EFI_STATUS Status;
+ PXEBC_BOOT_SVR_ENTRY *BootSvrEntry;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+ BootSvrEntry = NULL;
+ SrvList = NULL;
+ Status = EFI_DEVICE_ERROR;
+ Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DISCOVER;
+
+ if (!Private->AddressIsOk) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (!Mode->Started) {
+ return EFI_NOT_STARTED;
+ }
+
+ //
+ // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,
+ // use the previous setting;
+ // If info isn't offered,
+ // use the cached DhcpAck and ProxyOffer packets.
+ //
+ if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {
+
+ if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {
+
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DefaultInfo.IpCnt = 1;
+ DefaultInfo.UseUCast = TRUE;
+
+ DefaultSrvList.Type = Type;
+ DefaultSrvList.AcceptAnyResponse = FALSE;
+ DefaultSrvList.IpAddr.Addr[0] = Private->ServerIp.Addr[0];
+
+ SrvList = &DefaultSrvList;
+ Info = &DefaultInfo;
+ } else if (Info == NULL) {
+ //
+ // Create info by the cached packet before
+ //
+ Packet = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer : &Private->Dhcp4Ack;
+ VendorOpt = &Packet->PxeVendorOption;
+
+ if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) {
+ //
+ // Address is not acquired or no discovery options.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DefaultInfo.UseMCast = (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);
+ DefaultInfo.UseBCast = (BOOLEAN)!IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);
+ DefaultInfo.MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);
+ DefaultInfo.UseUCast = DefaultInfo.MustUseList;
+
+ if (DefaultInfo.UseMCast) {
+ //
+ // Get the multicast discover ip address from vendor option.
+ //
+ NetCopyMem (&DefaultInfo.ServerMCastIp.Addr, &VendorOpt->DiscoverMcastIp, sizeof (EFI_IPv4_ADDRESS));
+ }
+
+ DefaultInfo.IpCnt = 0;
+
+ if (DefaultInfo.MustUseList) {
+ BootSvrEntry = VendorOpt->BootSvr;
+ Status = EFI_INVALID_PARAMETER;
+
+ while (((UINT8) (BootSvrEntry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {
+
+ if (BootSvrEntry->Type == HTONS (Type)) {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ BootSvrEntry = GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry);
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ DefaultInfo.IpCnt = BootSvrEntry->IpCnt;
+ }
+
+ Info = &DefaultInfo;
+ } else {
+
+ SrvList = Info->SrvList;
+
+ if (!SrvList[0].AcceptAnyResponse) {
+
+ for (Index = 1; Index < Info->IpCnt; Index++) {
+ if (SrvList[Index].AcceptAnyResponse) {
+ break;
+ }
+ }
+
+ if (Index != Info->IpCnt) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ }
+
+ if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) || (Info->MustUseList && Info->IpCnt == 0)) {
+
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Execute discover by UniCast/BroadCast/MultiCast
+ //
+ if (Info->UseUCast) {
+
+ for (Index = 0; Index < Info->IpCnt; Index++) {
+
+ if (BootSvrEntry == NULL) {
+ Private->ServerIp.Addr[0] = SrvList[Index].IpAddr.Addr[0];
+ } else {
+ NetCopyMem (&Private->ServerIp, &BootSvrEntry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));
+ }
+
+ Status = PxeBcDiscvBootService (
+ Private,
+ Type,
+ Layer,
+ UseBis,
+ &SrvList[Index].IpAddr,
+ 0,
+ NULL,
+ TRUE,
+ &Private->PxeReply.Packet.Ack
+ );
+ }
+
+ } else if (Info->UseMCast) {
+
+ Status = PxeBcDiscvBootService (
+ Private,
+ Type,
+ Layer,
+ UseBis,
+ &Info->ServerMCastIp,
+ 0,
+ NULL,
+ TRUE,
+ &Private->PxeReply.Packet.Ack
+ );
+
+ } else if (Info->UseBCast) {
+
+ Status = PxeBcDiscvBootService (
+ Private,
+ Type,
+ Layer,
+ UseBis,
+ NULL,
+ Info->IpCnt,
+ SrvList,
+ TRUE,
+ &Private->PxeReply.Packet.Ack
+ );
+ }
+
+ if (EFI_ERROR (Status) || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {
+
+ Status = EFI_DEVICE_ERROR;
+ } else {
+ PxeBcParseCachedDhcpPacket (&Private->PxeReply);
+ }
+
+ if (Mode->PxeBisReplyReceived) {
+ NetCopyMem (&Private->ServerIp, &Mode->PxeReply.Dhcpv4.BootpSiAddr, sizeof (EFI_IPv4_ADDRESS));
+ }
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param Operation GC_NOTO: add argument
+ description
+ @param BufferPtr GC_NOTO: add argument
+ description
+ @param Overwrite GC_NOTO: add argument
+ description
+ @param BufferSize GC_NOTO: add argument
+ description
+ @param BlockSize GC_NOTO: add argument
+ description
+ @param ServerIp GC_NOTO: add argument
+ description
+ @param Filename GC_NOTO: add argument
+ description
+ @param Info GC_NOTO: add argument
+ description
+ @param DontUseBuffer GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcMtftp (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,
+ IN OUT VOID *BufferPtr,
+ IN BOOLEAN Overwrite,
+ IN OUT UINT64 *BufferSize,
+ IN UINTN *BlockSize OPTIONAL,
+ IN EFI_IP_ADDRESS *ServerIp,
+ IN UINT8 *Filename,
+ IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL,
+ IN BOOLEAN DontUseBuffer
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_MTFTP4_CONFIG_DATA Mtftp4Config;
+ EFI_STATUS Status;
+
+ if ((This == NULL) ||
+ (Filename == NULL) ||
+ (BufferSize == NULL) ||
+ ((ServerIp == NULL) || !Ip4IsUnicast (NTOHL (ServerIp->Addr[0]), 0)) ||
+ ((BufferPtr == NULL) && DontUseBuffer) ||
+ ((BlockSize != NULL) && (*BlockSize < 512))) {
+
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = EFI_DEVICE_ERROR;
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+
+ Mtftp4Config.UseDefaultSetting = FALSE;
+ Mtftp4Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;
+ Mtftp4Config.TryCount = PXEBC_MTFTP_RETRIES;
+
+ NetCopyMem (&Mtftp4Config.StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&Mtftp4Config.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&Mtftp4Config.GatewayIp, &Private->GatewayIp, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&Mtftp4Config.ServerIp, ServerIp, sizeof (EFI_IPv4_ADDRESS));
+
+ switch (Operation) {
+
+ case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE:
+
+ Status = PxeBcTftpGetFileSize (
+ Private,
+ &Mtftp4Config,
+ Filename,
+ BlockSize,
+ BufferSize
+ );
+
+ if (!EFI_ERROR (Status)) {
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+
+ break;
+
+ case EFI_PXE_BASE_CODE_TFTP_READ_FILE:
+
+ Status = PxeBcTftpReadFile (
+ Private,
+ &Mtftp4Config,
+ Filename,
+ BlockSize,
+ BufferPtr,
+ BufferSize,
+ DontUseBuffer
+ );
+
+ break;
+
+ case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE:
+
+ Status = PxeBcTftpWriteFile (
+ Private,
+ &Mtftp4Config,
+ Filename,
+ Overwrite,
+ BlockSize,
+ BufferPtr,
+ BufferSize
+ );
+
+ break;
+
+ case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY:
+
+ Status = PxeBcTftpReadDirectory (
+ Private,
+ &Mtftp4Config,
+ Filename,
+ BlockSize,
+ BufferPtr,
+ BufferSize,
+ DontUseBuffer
+ );
+
+ break;
+
+ case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE:
+ case EFI_PXE_BASE_CODE_MTFTP_READ_FILE:
+ case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY:
+ Status = EFI_UNSUPPORTED;
+ break;
+
+ default:
+
+ Status = EFI_INVALID_PARAMETER;
+ break;
+ }
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param OpFlags GC_NOTO: add argument
+ description
+ @param DestIp GC_NOTO: add argument
+ description
+ @param DestPort GC_NOTO: add argument
+ description
+ @param GatewayIp GC_NOTO: add argument
+ description
+ @param SrcIp GC_NOTO: add argument
+ description
+ @param SrcPort GC_NOTO: add argument
+ description
+ @param HeaderSize GC_NOTO: add argument
+ description
+ @param HeaderPtr GC_NOTO: add argument
+ description
+ @param BufferSize GC_NOTO: add argument
+ description
+ @param BufferPtr GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_OUT_OF_RESOURCES GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcUdpWrite (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN UINT16 OpFlags,
+ IN EFI_IP_ADDRESS *DestIp,
+ IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,
+ IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,
+ IN EFI_IP_ADDRESS *SrcIp OPTIONAL,
+ IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,
+ IN UINTN *HeaderSize OPTIONAL,
+ IN VOID *HeaderPtr OPTIONAL,
+ IN UINTN *BufferSize,
+ IN VOID *BufferPtr
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_UDP4_PROTOCOL *Udp4;
+ EFI_UDP4_COMPLETION_TOKEN Token;
+ EFI_UDP4_TRANSMIT_DATA *Udp4TxData;
+ UINT32 FragCount;
+ UINT32 DataLength;
+ EFI_UDP4_SESSION_DATA Udp4Session;
+ EFI_STATUS Status;
+ BOOLEAN IsDone;
+ UINT16 RandomSrcPort;
+
+ IsDone = FALSE;
+
+ if ((This == NULL) || (DestIp == NULL) || (DestPort == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((GatewayIp != NULL) && !Ip4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {
+ //
+ // Gateway is provided but it's not a unicast IP address.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((HeaderSize != NULL) && ((*HeaderSize == 0) || (HeaderPtr == NULL))) {
+ //
+ // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr
+ // is NULL.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((BufferSize == NULL) || ((*BufferSize != 0) && (BufferPtr == NULL))) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Udp4 = Private->Udp4;
+
+ if (!Private->AddressIsOk && (SrcIp == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (SrcIp == NULL) {
+ SrcIp = &Private->StationIp;
+
+ if (GatewayIp == NULL) {
+ GatewayIp = &Private->GatewayIp;
+ }
+ }
+
+ if ((SrcPort == NULL) || (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT)) {
+ RandomSrcPort = (UINT16) (NET_RANDOM (NetRandomInitSeed ()) % 10000 + 1024);
+
+ if (SrcPort == NULL) {
+
+ SrcPort = &RandomSrcPort;
+ } else {
+
+ *SrcPort = RandomSrcPort;
+ }
+ }
+
+ ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));
+ ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));
+
+ NetCopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));
+ Udp4Session.DestinationPort = *DestPort;
+ NetCopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));
+ Udp4Session.SourcePort = *SrcPort;
+
+ FragCount = (HeaderSize != NULL) ? 2 : 1;
+ Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) NetAllocatePool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));
+ if (Udp4TxData == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Udp4TxData->FragmentCount = FragCount;
+ Udp4TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32) *BufferSize;
+ Udp4TxData->FragmentTable[FragCount - 1].FragmentBuffer = BufferPtr;
+ DataLength = (UINT32) *BufferSize;
+
+ if (FragCount == 2) {
+
+ Udp4TxData->FragmentTable[0].FragmentLength = (UINT32) *HeaderSize;
+ Udp4TxData->FragmentTable[0].FragmentBuffer = HeaderPtr;
+ DataLength += (UINT32) *HeaderSize;
+ }
+
+ Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;
+ Udp4TxData->UdpSessionData = &Udp4Session;
+ Udp4TxData->DataLength = DataLength;
+ Token.Packet.TxData = Udp4TxData;
+
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ NET_TPL_EVENT,
+ PxeBcCommonNotify,
+ &IsDone,
+ &Token.Event
+ );
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ Status = Udp4->Transmit (Udp4, &Token);
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ while (!IsDone) {
+
+ Udp4->Poll (Udp4);
+ }
+
+ Status = Token.Status;
+
+ON_EXIT:
+
+ if (Token.Event != NULL) {
+ gBS->CloseEvent (Token.Event);
+ }
+
+ NetFreePool (Udp4TxData);
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param OpFlags GC_NOTO: add argument
+ description
+ @param DestIp GC_NOTO: add argument
+ description
+ @param DestPort GC_NOTO: add argument
+ description
+ @param SrcIp GC_NOTO: add argument
+ description
+ @param SrcPort GC_NOTO: add argument
+ description
+ @param HeaderSize GC_NOTO: add argument
+ description
+ @param HeaderPtr GC_NOTO: add argument
+ description
+ @param BufferSize GC_NOTO: add argument
+ description
+ @param BufferPtr GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_NOT_STARTED GC_NOTO: Add description for
+ return value
+ @retval EFI_OUT_OF_RESOURCES GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcUdpRead (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN UINT16 OpFlags,
+ IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
+ IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort, OPTIONAL
+ IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
+ IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
+ IN UINTN *HeaderSize, OPTIONAL
+ IN VOID *HeaderPtr, OPTIONAL
+ IN OUT UINTN *BufferSize,
+ IN VOID *BufferPtr
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_UDP4_PROTOCOL *Udp4;
+ EFI_UDP4_COMPLETION_TOKEN Token;
+ EFI_UDP4_RECEIVE_DATA *RxData;
+ EFI_UDP4_SESSION_DATA *Session;
+ EFI_STATUS Status;
+ BOOLEAN IsDone;
+ BOOLEAN Matched;
+ UINTN CopyLen;
+
+ if (This == NULL || DestIp == NULL || DestPort == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if ((!(OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) && (DestPort == NULL)) ||
+ (!(OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) && (SrcIp == NULL)) ||
+ (!(OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) && (SrcPort == NULL))) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderPtr == NULL) && (*HeaderSize != 0))) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((BufferSize == NULL) || ((BufferPtr == NULL) && (*BufferSize != 0))) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+ Udp4 = Private->Udp4;
+
+ if (!Mode->Started) {
+ return EFI_NOT_STARTED;
+ }
+
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ NET_TPL_EVENT,
+ PxeBcCommonNotify,
+ &IsDone,
+ &Token.Event
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ IsDone = FALSE;
+ Status = Udp4->Receive (Udp4, &Token);
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ Udp4->Poll (Udp4);
+
+ if (!IsDone) {
+ Status = EFI_TIMEOUT;
+ } else {
+
+ //
+ // check whether this packet matches the filters
+ //
+ if (EFI_ERROR (Token.Status)){
+ goto ON_EXIT;
+ }
+
+ RxData = Token.Packet.RxData;
+ Session = &RxData->UdpSession;
+
+ Matched = FALSE;
+
+ //
+ // Match the destination ip of the received udp dgram
+ //
+ if (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP) {
+ Matched = TRUE;
+
+ if (DestIp != NULL) {
+ NetCopyMem (DestIp, &Session->DestinationAddress, sizeof (EFI_IPv4_ADDRESS));
+ }
+ } else {
+ if (DestIp != NULL) {
+ if (EFI_IP4_EQUAL (DestIp, &Session->DestinationAddress)) {
+ Matched = TRUE;
+ }
+ } else {
+ if (EFI_IP4_EQUAL (&Private->StationIp, &Session->DestinationAddress)) {
+ Matched = TRUE;
+ }
+ }
+ }
+
+ if (Matched) {
+ //
+ // Match the destination port of the received udp dgram
+ //
+ if (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) {
+
+ if (DestPort != NULL) {
+ *DestPort = Session->DestinationPort;
+ }
+ } else {
+
+ if (*DestPort != Session->DestinationPort) {
+ Matched = FALSE;
+ }
+ }
+ }
+
+ if (Matched) {
+ //
+ // Match the source ip of the received udp dgram
+ //
+ if (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) {
+
+ if (SrcIp != NULL) {
+ NetCopyMem (SrcIp, &Session->SourceAddress, sizeof (EFI_IPv4_ADDRESS));
+ }
+ } else {
+
+ if (!EFI_IP4_EQUAL (SrcIp, &Session->SourceAddress)) {
+ Matched = FALSE;
+ }
+ }
+ }
+
+ if (Matched) {
+ //
+ // Match the source port of the received udp dgram
+ //
+ if (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) {
+
+ if (SrcPort != NULL) {
+ *SrcPort = Session->SourcePort;
+ }
+ } else {
+
+ if (*SrcPort != Session->SourcePort) {
+ Matched = FALSE;
+ }
+ }
+ }
+
+ if (Matched) {
+
+ CopyLen = 0;
+
+ if (HeaderSize != NULL) {
+ CopyLen = MIN (*HeaderSize, RxData->DataLength);
+ NetCopyMem (HeaderPtr, RxData->FragmentTable[0].FragmentBuffer, CopyLen);
+ *HeaderSize = CopyLen;
+ }
+
+ if (RxData->DataLength - CopyLen > *BufferSize) {
+
+ Status = EFI_BUFFER_TOO_SMALL;
+ } else {
+
+ *BufferSize = RxData->DataLength - CopyLen;
+ NetCopyMem (BufferPtr, (UINT8 *) RxData->FragmentTable[0].FragmentBuffer + CopyLen, *BufferSize);
+ }
+ } else {
+
+ Status = EFI_TIMEOUT;
+ }
+
+ //
+ // Recycle the RxData
+ //
+ gBS->SignalEvent (RxData->RecycleSignal);
+ }
+
+ON_EXIT:
+
+ Udp4->Cancel (Udp4, &Token);
+
+ gBS->CloseEvent (Token.Event);
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param NewFilter GC_NOTO: add argument
+ description
+
+ @retval EFI_UNSUPPORTED GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcSetIpFilter (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param IpAddr GC_NOTO: add argument
+ description
+ @param MacAddr GC_NOTO: add argument
+ description
+
+ @retval EFI_UNSUPPORTED GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcArp (
+ IN EFI_PXE_BASE_CODE_PROTOCOL * This,
+ IN EFI_IP_ADDRESS * IpAddr,
+ IN EFI_MAC_ADDRESS * MacAddr OPTIONAL
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param NewAutoArp GC_NOTO: add argument
+ description
+ @param NewSendGUID GC_NOTO: add argument
+ description
+ @param NewTTL GC_NOTO: add argument
+ description
+ @param NewToS GC_NOTO: add argument
+ description
+ @param NewMakeCallback GC_NOTO: add argument
+ description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcSetParameters (
+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,
+ IN BOOLEAN *NewAutoArp, OPTIONAL
+ IN BOOLEAN *NewSendGUID, OPTIONAL
+ IN UINT8 *NewTTL, OPTIONAL
+ IN UINT8 *NewToS, OPTIONAL
+ IN BOOLEAN *NewMakeCallback // OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_STATUS Status;
+
+ Status = EFI_SUCCESS;
+
+ if (This == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ goto ON_EXIT;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+
+ if (NewSendGUID != NULL && *NewSendGUID == TRUE) {
+ //
+ // FixMe, cann't locate SendGuid
+ //
+ }
+
+ if (NewMakeCallback != NULL && *NewMakeCallback == TRUE) {
+
+ Status = gBS->HandleProtocol (
+ Private->Controller,
+ &gEfiPxeBaseCodeCallbackProtocolGuid,
+ (VOID **) &Private->PxeBcCallback
+ );
+ if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {
+
+ Status = EFI_INVALID_PARAMETER;
+ goto ON_EXIT;
+ }
+ }
+
+ if (!Mode->Started) {
+ Status = EFI_NOT_STARTED;
+ goto ON_EXIT;
+ }
+
+ if (NewMakeCallback != NULL) {
+
+ if (*NewMakeCallback) {
+ //
+ // Update the Callback protocol.
+ //
+ Status = gBS->HandleProtocol (
+ Private->Controller,
+ &gEfiPxeBaseCodeCallbackProtocolGuid,
+ (VOID **) &Private->PxeBcCallback
+ );
+
+ if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto ON_EXIT;
+ }
+ } else {
+ Private->PxeBcCallback = NULL;
+ }
+
+ Mode->MakeCallbacks = *NewMakeCallback;
+ }
+
+ if (NewAutoArp != NULL) {
+ Mode->AutoArp = *NewAutoArp;
+ }
+
+ if (NewSendGUID != NULL) {
+ Mode->SendGUID = *NewSendGUID;
+ }
+
+ if (NewTTL != NULL) {
+ Mode->TTL = *NewTTL;
+ }
+
+ if (NewToS != NULL) {
+ Mode->ToS = *NewToS;
+ }
+
+ON_EXIT:
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param NewStationIp GC_NOTO: add argument
+ description
+ @param NewSubnetMask GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_NOT_STARTED GC_NOTO: Add description for
+ return value
+ @retval EFI_SUCCESS GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcSetStationIP (
+ IN EFI_PXE_BASE_CODE_PROTOCOL * This,
+ IN EFI_IP_ADDRESS * NewStationIp, OPTIONAL
+ IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (NewStationIp != NULL && !Ip4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+
+ if (!Mode->Started) {
+ return EFI_NOT_STARTED;
+ }
+
+ if (NewStationIp != NULL) {
+ Mode->StationIp = *NewStationIp;
+ }
+
+ if (NewSubnetMask != NULL) {
+ Mode->SubnetMask = *NewSubnetMask;
+ }
+
+ Private->AddressIsOk = TRUE;
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param NewDhcpDiscoverValid GC_NOTO: add argument
+ description
+ @param NewDhcpAckReceived GC_NOTO: add argument
+ description
+ @param NewProxyOfferReceived GC_NOTO: add argument
+ description
+ @param NewPxeDiscoverValid GC_NOTO: add argument
+ description
+ @param NewPxeReplyReceived GC_NOTO: add argument
+ description
+ @param NewPxeBisReplyReceived GC_NOTO: add argument
+ description
+ @param NewDhcpDiscover GC_NOTO: add argument
+ description
+ @param NewDhcpAck GC_NOTO: add argument
+ description
+ @param NewProxyOffer GC_NOTO: add argument
+ description
+ @param NewPxeDiscover GC_NOTO: add argument
+ description
+ @param NewPxeReply GC_NOTO: add argument
+ description
+ @param NewPxeBisReply GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_NOT_STARTED GC_NOTO: Add description for
+ return value
+ @retval EFI_SUCCESS GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeBcSetPackets (
+ IN EFI_PXE_BASE_CODE_PROTOCOL * This,
+ IN BOOLEAN * NewDhcpDiscoverValid, OPTIONAL
+ IN BOOLEAN * NewDhcpAckReceived, OPTIONAL
+ IN BOOLEAN * NewProxyOfferReceived, OPTIONAL
+ IN BOOLEAN * NewPxeDiscoverValid, OPTIONAL
+ IN BOOLEAN * NewPxeReplyReceived, OPTIONAL
+ IN BOOLEAN * NewPxeBisReplyReceived, OPTIONAL
+ IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover, OPTIONAL
+ IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck, OPTIONAL
+ IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer, OPTIONAL
+ IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover, OPTIONAL
+ IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply, OPTIONAL
+ IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
+ Mode = Private->PxeBc.Mode;
+
+ if (!Mode->Started) {
+ return EFI_NOT_STARTED;
+ }
+
+ Private->FileSize = 0;
+
+ if (NewDhcpDiscoverValid != NULL) {
+ Mode->DhcpDiscoverValid = *NewDhcpDiscoverValid;
+ }
+
+ if (NewDhcpAckReceived != NULL) {
+ Mode->DhcpAckReceived = *NewDhcpAckReceived;
+ }
+
+ if (NewProxyOfferReceived != NULL) {
+ Mode->ProxyOfferReceived = *NewProxyOfferReceived;
+ }
+
+ if (NewPxeDiscoverValid != NULL) {
+ Mode->PxeDiscoverValid = *NewPxeDiscoverValid;
+ }
+
+ if (NewPxeReplyReceived != NULL) {
+ Mode->PxeReplyReceived = *NewPxeReplyReceived;
+ }
+
+ if (NewPxeBisReplyReceived != NULL) {
+ Mode->PxeBisReplyReceived = *NewPxeBisReplyReceived;
+ }
+
+ if (NewDhcpDiscover != NULL) {
+ NetCopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));
+ }
+
+ if (NewDhcpAck != NULL) {
+ NetCopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET));
+ }
+
+ if (NewProxyOffer != NULL) {
+ NetCopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_PACKET));
+ }
+
+ if (NewPxeDiscover != NULL) {
+ NetCopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));
+ }
+
+ if (NewPxeReply != NULL) {
+ NetCopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKET));
+ }
+
+ if (NewPxeBisReply != NULL) {
+ NetCopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE_PACKET));
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate = {
+ EFI_PXE_BASE_CODE_PROTOCOL_REVISION,
+ EfiPxeBcStart,
+ EfiPxeBcStop,
+ EfiPxeBcDhcp,
+ EfiPxeBcDiscover,
+ EfiPxeBcMtftp,
+ EfiPxeBcUdpWrite,
+ EfiPxeBcUdpRead,
+ EfiPxeBcSetIpFilter,
+ EfiPxeBcArp,
+ EfiPxeBcSetParameters,
+ EfiPxeBcSetStationIP,
+ EfiPxeBcSetPackets,
+ NULL
+};
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param Function GC_NOTO: add argument
+ description
+ @param Received GC_NOTO: add argument
+ description
+ @param PacketLength GC_NOTO: add argument
+ description
+ @param PacketPtr GC_NOTO: add argument
+ description
+
+ @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT GC_NOTO: Add description for
+ return value
+ @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE GC_NOTO: Add description for
+ return value
+ @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE GC_NOTO: Add description for
+ return value
+ @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE GC_NOTO: Add description for
+ return value
+ @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE GC_NOTO: Add description for
+ return value
+
+**/
+EFI_PXE_BASE_CODE_CALLBACK_STATUS
+EFIAPI
+EfiPxeLoadFileCallback (
+ IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL * This,
+ IN EFI_PXE_BASE_CODE_FUNCTION Function,
+ IN BOOLEAN Received,
+ IN UINT32 PacketLength,
+ IN EFI_PXE_BASE_CODE_PACKET * PacketPtr OPTIONAL
+ )
+{
+ EFI_INPUT_KEY Key;
+ EFI_STATUS Status;
+
+ //
+ // Catch Ctrl-C or ESC to abort.
+ //
+ Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
+
+ if (!EFI_ERROR (Status)) {
+
+ if (Key.ScanCode == SCAN_ESC || Key.UnicodeChar == (0x1F & 'c')) {
+
+ return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT;
+ }
+ }
+ //
+ // No print if receive packet
+ //
+ if (Received) {
+ return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
+ }
+ //
+ // Print only for three functions
+ //
+ switch (Function) {
+
+ case EFI_PXE_BASE_CODE_FUNCTION_MTFTP:
+ //
+ // Print only for open MTFTP packets, not every MTFTP packets
+ //
+ if (PacketLength != 0 && PacketPtr != NULL) {
+ if (PacketPtr->Raw[0x1C] != 0x00 || PacketPtr->Raw[0x1D] != 0x01) {
+ return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
+ }
+ }
+ break;
+
+ case EFI_PXE_BASE_CODE_FUNCTION_DHCP:
+ case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER:
+ break;
+
+ default:
+ return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
+ }
+
+ if (PacketLength != 0 && PacketPtr != NULL) {
+ //
+ // Print '.' when transmit a packet
+ //
+ AsciiPrint (".");
+
+ }
+
+ return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
+}
+
+EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate = {
+ EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION,
+ EfiPxeLoadFileCallback
+};
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Private GC_NOTO: add argument
+ description
+ @param BufferSize GC_NOTO: add argument
+ description
+ @param Buffer GC_NOTO: add argument
+ description
+
+ @return GC_NOTO: add return values
+
+**/
+EFI_STATUS
+DiscoverBootFile (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN OUT UINT64 *BufferSize,
+ IN VOID *Buffer
+ )
+{
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ EFI_PXE_BASE_CODE_MODE *Mode;
+ EFI_STATUS Status;
+ UINT16 Type;
+ UINT16 Layer;
+ BOOLEAN UseBis;
+ UINTN BlockSize;
+ PXEBC_CACHED_DHCP4_PACKET *Packet;
+ UINT16 Value;
+
+ PxeBc = &Private->PxeBc;
+ Mode = PxeBc->Mode;
+ Type = EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP;
+ Layer = EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL;
+
+ //
+ // do DHCP.
+ //
+ Status = PxeBc->Dhcp (PxeBc, TRUE);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Select a boot server
+ //
+ Status = PxeBcSelectBootPrompt (Private);
+
+ if (Status == EFI_SUCCESS) {
+ Status = PxeBcSelectBootMenu (Private, &Type, TRUE);
+ } else if (Status == EFI_TIMEOUT) {
+ Status = PxeBcSelectBootMenu (Private, &Type, FALSE);
+ }
+
+ if (!EFI_ERROR (Status)) {
+
+ if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {
+ //
+ // Local boot(PXE bootstrap server) need abort
+ //
+ return EFI_ABORTED;
+ }
+
+ UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);
+ Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ *BufferSize = 0;
+ BlockSize = 0x8000;
+
+ //
+ // Get bootfile name and (m)tftp server ip addresss
+ //
+ if (Mode->PxeReplyReceived) {
+ Packet = &Private->PxeReply;
+ } else if (Mode->ProxyOfferReceived) {
+ Packet = &Private->ProxyOffer;
+ } else {
+ Packet = &Private->Dhcp4Ack;
+ }
+
+ NetCopyMem (&Private->ServerIp, &Packet->Packet.Offer.Dhcp4.Header.ServerAddr, sizeof (EFI_IPv4_ADDRESS));
+ if (Private->ServerIp.Addr[0] == 0) {
+ //
+ // next server ip address is zero, use option 54 instead
+ //
+ NetCopyMem (
+ &Private->ServerIp,
+ Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,
+ sizeof (EFI_IPv4_ADDRESS)
+ );
+ }
+
+ ASSERT (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);
+
+ //
+ // bootlfile name
+ //
+ Private->BootFileName = (CHAR8 *) (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data);
+
+ if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] != NULL) {
+ //
+ // Already have the bootfile length option, compute the file size
+ //
+ NetCopyMem (&Value, Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));
+ Value = NTOHS (Value);
+ *BufferSize = 512 * Value;
+ Status = EFI_BUFFER_TOO_SMALL;
+ } else {
+ //
+ // Get the bootfile size from tftp
+ //
+ Status = PxeBc->Mtftp (
+ PxeBc,
+ EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
+ Buffer,
+ FALSE,
+ BufferSize,
+ &BlockSize,
+ &Private->ServerIp,
+ (UINT8 *) Private->BootFileName,
+ NULL,
+ FALSE
+ );
+ }
+
+ Private->FileSize = (UINTN) *BufferSize;
+
+ return Status;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param This GC_NOTO: add argument
+ description
+ @param FilePath GC_NOTO: add argument
+ description
+ @param BootPolicy GC_NOTO: add argument
+ description
+ @param BufferSize GC_NOTO: add argument
+ description
+ @param Buffer GC_NOTO: add argument
+ description
+
+ @retval EFI_INVALID_PARAMETER GC_NOTO: Add description for
+ return value
+ @retval EFI_UNSUPPORTED GC_NOTO: Add description for
+ return value
+
+**/
+EFI_STATUS
+EFIAPI
+EfiPxeLoadFile (
+ IN EFI_LOAD_FILE_PROTOCOL * This,
+ IN EFI_DEVICE_PATH_PROTOCOL * FilePath,
+ IN BOOLEAN BootPolicy,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer OPTIONAL
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
+ BOOLEAN NewMakeCallback;
+ UINTN BlockSize;
+ EFI_STATUS Status;
+ UINT64 TmpBufSize;
+
+ Private = PXEBC_PRIVATE_DATA_FROM_LOADFILE (This);
+ PxeBc = &Private->PxeBc;
+ NewMakeCallback = FALSE;
+ BlockSize = 0x8000;
+ Status = EFI_DEVICE_ERROR;
+
+ if (This == NULL || BufferSize == NULL) {
+
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Only support BootPolicy
+ //
+ if (!BootPolicy) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = PxeBc->Start (PxeBc, FALSE);
+ if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
+ return Status;
+ }
+
+ Status = gBS->HandleProtocol (
+ Private->Controller,
+ &gEfiPxeBaseCodeCallbackProtocolGuid,
+ (VOID **) &Private->PxeBcCallback
+ );
+ if (Status == EFI_UNSUPPORTED) {
+
+ CopyMem (&Private->LoadFileCallback, &mPxeBcCallBackTemplate, sizeof (Private->LoadFileCallback));
+
+ Status = gBS->InstallProtocolInterface (
+ &Private->Controller,
+ &gEfiPxeBaseCodeCallbackProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Private->LoadFileCallback
+ );
+
+ NewMakeCallback = (BOOLEAN) (Status == EFI_SUCCESS);
+
+ Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);
+ if (EFI_ERROR (Status)) {
+ PxeBc->Stop (PxeBc);
+ return Status;
+ }
+ }
+
+ if (Private->FileSize == 0) {
+ TmpBufSize = 0;
+ Status = DiscoverBootFile (Private, &TmpBufSize, Buffer);
+
+ if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) {
+ Status = EFI_DEVICE_ERROR;
+ } else {
+ *BufferSize = (UINTN) TmpBufSize;
+ }
+ } else if (Buffer == NULL) {
+ *BufferSize = Private->FileSize;
+ Status = EFI_BUFFER_TOO_SMALL;
+ } else {
+ //
+ // Download the file.
+ //
+ TmpBufSize = (UINT64) (*BufferSize);
+ Status = PxeBc->Mtftp (
+ PxeBc,
+ EFI_PXE_BASE_CODE_TFTP_READ_FILE,
+ Buffer,
+ FALSE,
+ &TmpBufSize,
+ &BlockSize,
+ &Private->ServerIp,
+ (UINT8 *) Private->BootFileName,
+ NULL,
+ FALSE
+ );
+ }
+ //
+ // If we added a callback protocol, now is the time to remove it.
+ //
+ if (NewMakeCallback) {
+
+ NewMakeCallback = FALSE;
+
+ PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);
+
+ gBS->UninstallProtocolInterface (
+ Private->Controller,
+ &gEfiPxeBaseCodeCallbackProtocolGuid,
+ &Private->LoadFileCallback
+ );
+ }
+ //
+ // Check download status
+ //
+ switch (Status) {
+
+ case EFI_SUCCESS:
+ break;
+
+ case EFI_BUFFER_TOO_SMALL:
+ if (Buffer != NULL) {
+ AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");
+ } else {
+ return Status;
+ }
+ break;
+
+ case EFI_DEVICE_ERROR:
+ AsciiPrint ("PXE-E07: Network device error.\n");
+ break;
+
+ case EFI_OUT_OF_RESOURCES:
+ AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");
+ break;
+
+ case EFI_NO_MEDIA:
+ AsciiPrint ("PXE-E12: Could not detect network connection.\n");
+ break;
+
+ case EFI_NO_RESPONSE:
+ AsciiPrint ("PXE-E16: No offer received.\n");
+ break;
+
+ case EFI_TIMEOUT:
+ AsciiPrint ("PXE-E18: Server response timeout.\n");
+ break;
+
+ case EFI_ABORTED:
+ AsciiPrint ("PXE-E21: Remote boot cancelled.\n");
+ break;
+
+ case EFI_ICMP_ERROR:
+ AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");
+ break;
+
+ case EFI_TFTP_ERROR:
+ AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");
+ break;
+
+ default:
+ AsciiPrint ("PXE-E99: Unexpected network error.\n");
+ break;
+ }
+
+ PxeBc->Stop (PxeBc);
+
+ return Status;
+}
+
+EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h
new file mode 100644
index 0000000000..61992521b9
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h
@@ -0,0 +1,126 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcImpl.h
+
+Abstract:
+
+
+**/
+
+#ifndef __EFI_PXEBC_IMPL_H__
+#define __EFI_PXEBC_IMPL_H__
+
+
+typedef struct _PXEBC_PRIVATE_DATA PXEBC_PRIVATE_DATA;
+
+#include <PiDxe.h>
+
+#include <Guid/SmBios.h>
+#include <IndustryStandard/Smbios.h>
+#include <Protocol/Dhcp4.h>
+#include <Protocol/PxeBaseCode.h>
+#include <Protocol/Mtftp4.h>
+#include <Protocol/Udp4.h>
+#include <Protocol/LoadFile.h>
+#include <Protocol/NetworkInterfaceIdentifier.h>
+#include <Protocol/PxeBaseCodeCallBack.h>
+
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseLib.h>
+#include <Library/NetLib.h>
+
+#include "PxeBcDriver.h"
+#include "PxeArch.h"
+#include "PxeBcDhcp.h"
+#include "PxeBcMtftp.h"
+#include "PxeBcSupport.h"
+
+#define PXEBC_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('P', 'X', 'E', 'P')
+#define PXEBC_MTFTP_TIMEOUT 4
+#define PXEBC_MTFTP_RETRIES 6
+
+struct _PXEBC_PRIVATE_DATA {
+ UINT32 Signature;
+ EFI_HANDLE Controller;
+ EFI_HANDLE Image;
+ EFI_HANDLE Dhcp4Child;
+ EFI_HANDLE Mtftp4Child;
+ EFI_HANDLE Udp4Child;
+
+ EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
+
+ EFI_PXE_BASE_CODE_PROTOCOL PxeBc;
+ EFI_LOAD_FILE_PROTOCOL LoadFile;
+ EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL LoadFileCallback;
+ EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *PxeBcCallback;
+ EFI_DHCP4_PROTOCOL *Dhcp4;
+ EFI_MTFTP4_PROTOCOL *Mtftp4;
+ EFI_UDP4_PROTOCOL *Udp4;
+ EFI_UDP4_CONFIG_DATA Udp4CfgData;
+
+ EFI_PXE_BASE_CODE_MODE Mode;
+ EFI_PXE_BASE_CODE_FUNCTION Function;
+
+ CHAR8 *BootFileName;
+
+ EFI_IP_ADDRESS StationIp;
+ EFI_IP_ADDRESS SubnetMask;
+ EFI_IP_ADDRESS GatewayIp;
+ EFI_IP_ADDRESS ServerIp;
+ BOOLEAN AddressIsOk;
+
+ UINTN FileSize;
+
+ UINT8 OptionBuffer[PXEBC_DHCP4_MAX_OPTION_SIZE];
+ EFI_DHCP4_PACKET SeedPacket;
+
+ BOOLEAN SortOffers;
+ UINT32 NumOffers;
+ UINT32 SelectedOffer;
+ UINT32 ProxyOfferType;
+
+ //
+ // Cached packets as complements of pxe mode data
+ //
+ PXEBC_CACHED_DHCP4_PACKET ProxyOffer;
+ PXEBC_CACHED_DHCP4_PACKET Dhcp4Ack;
+ PXEBC_CACHED_DHCP4_PACKET PxeReply;
+ PXEBC_CACHED_DHCP4_PACKET Dhcp4Offers[PXEBC_MAX_OFFER_NUM];
+
+ //
+ // Arrays for different types of offers:
+ // ServerCount records the count of the servers we got the offers,
+ // OfferIndex records the index of the offer sent by the server indexed by ServerCount.
+ //
+ UINT32 ServerCount[DHCP4_PACKET_TYPE_MAX];
+ UINT32 OfferIndex[DHCP4_PACKET_TYPE_MAX][PXEBC_MAX_OFFER_NUM];
+ UINT32 BootpIndex;
+ UINT32 ProxyIndex[DHCP4_PACKET_TYPE_MAX];
+ UINT32 BinlIndex[PXEBC_MAX_OFFER_NUM];
+};
+
+#define PXEBC_PRIVATE_DATA_FROM_PXEBC(a) CR (a, PXEBC_PRIVATE_DATA, PxeBc, PXEBC_PRIVATE_DATA_SIGNATURE)
+
+#define PXEBC_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, PXEBC_PRIVATE_DATA, LoadFile, PXEBC_PRIVATE_DATA_SIGNATURE)
+
+#define PXEBC_PRIVATE_DATA_FROM_PXEBCCALLBACK(a) CR (a, PXEBC_PRIVATE_DATA, PxeBcCallback, PXEBC_PRIVATE_DATA_SIGNATURE)
+
+extern EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate;
+extern EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate;
+
+#endif
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c
new file mode 100644
index 0000000000..08cdb31f84
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c
@@ -0,0 +1,437 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcMtftp.c
+
+Abstract:
+
+ PxeBc MTFTP functions
+
+
+**/
+
+#include "PxeBcImpl.h"
+
+VOID *TokenContext = NULL;
+
+UINT8 *mMtftpOptions[PXE_MTFTP_OPTION_MAXIMUM_INDEX] = {
+ "blksize",
+ "timeout",
+ "tsize",
+ "multicast"
+};
+
+
+/**
+ This is a callback function when packets received/transmitted in Mtftp driver.
+
+ @param This Pointer to Mtftp protocol instance
+ @param Token Pointer to Mtftp token
+ @param PacketLen Length of Mtftp packet
+ @param Packet Pointer to Mtftp packet
+
+ @return EFI_SUCCESS
+ @return EFI_ABORTED
+
+**/
+EFI_STATUS
+PxeBcCheckPacket (
+ IN EFI_MTFTP4_PROTOCOL *This,
+ IN EFI_MTFTP4_TOKEN *Token,
+ IN UINT16 PacketLen,
+ IN EFI_MTFTP4_PACKET *Packet
+ )
+{
+ PXEBC_PRIVATE_DATA *Private;
+ EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;
+ EFI_STATUS Status;
+
+ Private = (PXEBC_PRIVATE_DATA *) TokenContext;
+ Callback = Private->PxeBcCallback;
+ Status = EFI_SUCCESS;
+
+ if (Callback != NULL) {
+
+ Status = Callback->Callback (
+ Callback,
+ Private->Function,
+ TRUE,
+ PacketLen,
+ (EFI_PXE_BASE_CODE_PACKET *) Packet
+ );
+ if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {
+
+ Status = EFI_ABORTED;
+ } else {
+
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ return Status;
+}
+
+
+/**
+ This function is to get size of a file by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param BlockSize Pointer to block size
+ @param BufferSize Pointer to buffer size
+
+ @return EFI_SUCCESS
+ @return EFI_NOT_FOUND
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpGetFileSize (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN UINTN *BlockSize,
+ IN OUT UINT64 *BufferSize
+ )
+{
+ EFI_MTFTP4_PROTOCOL *Mtftp4;
+ EFI_MTFTP4_OPTION ReqOpt[2];
+ EFI_MTFTP4_PACKET *Packet;
+ EFI_MTFTP4_OPTION *Option;
+ UINT32 PktLen;
+ UINT8 OptBuf[128];
+ UINT32 OptCnt;
+ EFI_STATUS Status;
+
+ *BufferSize = 0;
+ Status = EFI_DEVICE_ERROR;
+ Mtftp4 = Private->Mtftp4;
+ Packet = NULL;
+ Option = NULL;
+ PktLen = 0;
+ OptCnt = 1;
+ Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;
+
+ Status = Mtftp4->Configure (Mtftp4, Config);
+ if (EFI_ERROR (Status)) {
+
+ return Status;
+ }
+
+ ReqOpt[0].OptionStr = mMtftpOptions[PXE_MTFTP_OPTION_TSIZE_INDEX];
+ UtoA10 (0, (CHAR8 *) OptBuf);
+ ReqOpt[0].ValueStr = OptBuf;
+
+ if (BlockSize != NULL) {
+ ReqOpt[1].OptionStr = mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
+ ReqOpt[1].ValueStr = ReqOpt[0].ValueStr + AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1;
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[1].ValueStr);
+ OptCnt++;
+ }
+
+ Status = Mtftp4->GetInfo (
+ Mtftp4,
+ FALSE,
+ Filename,
+ NULL,
+ (UINT8) OptCnt,
+ ReqOpt,
+ &PktLen,
+ &Packet
+ );
+
+ if (EFI_ERROR (Status)) {
+
+ goto ON_ERROR;
+ }
+
+ OptCnt = 0;
+
+ Status = Mtftp4->ParseOptions (
+ Mtftp4,
+ PktLen,
+ Packet,
+ (UINT32 *) &OptCnt,
+ &Option
+ );
+
+ if (EFI_ERROR (Status)) {
+
+ goto ON_ERROR;
+ }
+
+ Status = EFI_NOT_FOUND;
+
+ while (OptCnt != 0) {
+
+ if (AsciiStrnCmp ((CHAR8 *) Option[OptCnt - 1].OptionStr, "tsize", 5) == 0) {
+
+ *BufferSize = AtoU64 (Option[OptCnt - 1].ValueStr);
+ Status = EFI_SUCCESS;
+ }
+
+ OptCnt--;
+ }
+
+ NetFreePool (Option);
+
+ON_ERROR:
+
+ if (Packet != NULL) {
+ NetFreePool (Packet);
+ }
+
+ Mtftp4->Configure (Mtftp4, NULL);
+
+ return Status;
+}
+
+
+/**
+ This function is to get data of a file by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param BlockSize Pointer to block size
+ @param BufferPtr Pointer to buffer
+ @param BufferSize Pointer to buffer size
+ @param DontUseBuffer Indicate whether with a receive buffer
+
+ @return EFI_SUCCESS
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpReadFile (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN UINTN *BlockSize,
+ IN UINT8 *BufferPtr,
+ IN OUT UINT64 *BufferSize,
+ IN BOOLEAN DontUseBuffer
+ )
+{
+ EFI_MTFTP4_PROTOCOL *Mtftp4;
+ EFI_MTFTP4_TOKEN Token;
+ EFI_MTFTP4_OPTION ReqOpt[1];
+ UINT32 OptCnt;
+ UINT8 OptBuf[128];
+ EFI_STATUS Status;
+
+ Status = EFI_DEVICE_ERROR;
+ Mtftp4 = Private->Mtftp4;
+ OptCnt = 0;
+ Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;
+
+ Status = Mtftp4->Configure (Mtftp4, Config);
+ if (EFI_ERROR (Status)) {
+
+ return Status;
+ }
+
+ if (BlockSize != NULL) {
+
+ ReqOpt[0].OptionStr = mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
+ ReqOpt[0].ValueStr = OptBuf;
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);
+ OptCnt++;
+ }
+
+ Token.Event = NULL;
+ Token.OverrideData = NULL;
+ Token.Filename = Filename;
+ Token.ModeStr = NULL;
+ Token.OptionCount = OptCnt;
+ Token.OptionList = ReqOpt;
+ TokenContext = Private;
+
+ if (DontUseBuffer) {
+ Token.BufferSize = 0;
+ Token.Buffer = NULL;
+ } else {
+ Token.BufferSize = *BufferSize;
+ Token.Buffer = BufferPtr;
+ }
+
+ Token.CheckPacket = PxeBcCheckPacket;
+ Token.TimeoutCallback = NULL;
+ Token.PacketNeeded = NULL;
+
+ Status = Mtftp4->ReadFile (Mtftp4, &Token);
+
+ *BufferSize = Token.BufferSize;
+
+ Mtftp4->Configure (Mtftp4, NULL);
+
+ return Status;
+}
+
+
+/**
+ This function is put data of a file by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param Overwrite Indicate whether with overwrite attribute
+ @param BlockSize Pointer to block size
+ @param BufferPtr Pointer to buffer
+ @param BufferSize Pointer to buffer size
+
+ @return EFI_SUCCESS
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpWriteFile (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN BOOLEAN Overwrite,
+ IN UINTN *BlockSize,
+ IN UINT8 *BufferPtr,
+ IN OUT UINT64 *BufferSize
+ )
+{
+ EFI_MTFTP4_PROTOCOL *Mtftp4;
+ EFI_MTFTP4_TOKEN Token;
+ EFI_MTFTP4_OPTION ReqOpt[1];
+ UINT32 OptCnt;
+ UINT8 OptBuf[128];
+ EFI_STATUS Status;
+
+ Status = EFI_DEVICE_ERROR;
+ Mtftp4 = Private->Mtftp4;
+ OptCnt = 0;
+ Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;
+
+ Status = Mtftp4->Configure (Mtftp4, Config);
+ if (EFI_ERROR (Status)) {
+
+ return Status;
+ }
+
+ if (BlockSize != NULL) {
+
+ ReqOpt[0].OptionStr = mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
+ ReqOpt[0].ValueStr = OptBuf;
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);
+ OptCnt++;
+ }
+
+ Token.Event = NULL;
+ Token.OverrideData = NULL;
+ Token.Filename = Filename;
+ Token.ModeStr = NULL;
+ Token.OptionCount = OptCnt;
+ Token.OptionList = ReqOpt;
+ Token.BufferSize = *BufferSize;
+ Token.Buffer = BufferPtr;
+ Token.CheckPacket = PxeBcCheckPacket;
+ Token.TimeoutCallback = NULL;
+ Token.PacketNeeded = NULL;
+
+ Status = Mtftp4->WriteFile (Mtftp4, &Token);
+ *BufferSize = Token.BufferSize;
+
+ Mtftp4->Configure (Mtftp4, NULL);
+
+ return Status;
+}
+
+
+/**
+ This function is to get data of a directory by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param BlockSize Pointer to block size
+ @param BufferPtr Pointer to buffer
+ @param BufferSize Pointer to buffer size
+ @param DontUseBuffer Indicate whether with a receive buffer
+
+ @return EFI_SUCCES
+ @return EFI_DEVICE_ERROR
+
+**/
+// GC_NOTO: EFI_SUCCESS - add return value to function comment
+EFI_STATUS
+PxeBcTftpReadDirectory (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN UINTN *BlockSize,
+ IN UINT8 *BufferPtr,
+ IN OUT UINT64 *BufferSize,
+ IN BOOLEAN DontUseBuffer
+ )
+{
+ EFI_MTFTP4_PROTOCOL *Mtftp4;
+ EFI_MTFTP4_TOKEN Token;
+ EFI_MTFTP4_OPTION ReqOpt[1];
+ UINT32 OptCnt;
+ UINT8 OptBuf[128];
+ EFI_STATUS Status;
+
+ Status = EFI_DEVICE_ERROR;
+ Mtftp4 = Private->Mtftp4;
+ OptCnt = 0;
+ Config->InitialServerPort = PXEBC_BS_DOWNLOAD_PORT;
+
+ Status = Mtftp4->Configure (Mtftp4, Config);
+ if (EFI_ERROR (Status)) {
+
+ return Status;
+ }
+
+ if (BlockSize != NULL) {
+
+ ReqOpt[0].OptionStr = mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE_INDEX];
+ ReqOpt[0].ValueStr = OptBuf;
+ UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr);
+ OptCnt++;
+ }
+
+ Token.Event = NULL;
+ Token.OverrideData = NULL;
+ Token.Filename = Filename;
+ Token.ModeStr = NULL;
+ Token.OptionCount = OptCnt;
+ Token.OptionList = ReqOpt;
+ TokenContext = Private;
+
+ if (DontUseBuffer) {
+ Token.BufferSize = 0;
+ Token.Buffer = NULL;
+ } else {
+ Token.BufferSize = *BufferSize;
+ Token.Buffer = BufferPtr;
+ }
+
+ Token.CheckPacket = PxeBcCheckPacket;
+ Token.TimeoutCallback = NULL;
+ Token.PacketNeeded = NULL;
+
+ Status = Mtftp4->ReadDirectory (Mtftp4, &Token);
+
+ *BufferSize = Token.BufferSize;
+
+ Mtftp4->Configure (Mtftp4, NULL);
+
+ return Status;
+}
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h
new file mode 100644
index 0000000000..ac8dd2f054
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h
@@ -0,0 +1,144 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcMtftp.h
+
+Abstract:
+
+ Mtftp routines for PxeBc
+
+
+**/
+
+#ifndef __EFI_PXEBC_MTFTP_H__
+#define __EFI_PXEBC_MTFTP_H__
+
+enum {
+ PXE_MTFTP_OPTION_BLKSIZE_INDEX,
+ PXE_MTFTP_OPTION_TIMEOUT_INDEX,
+ PXE_MTFTP_OPTION_TSIZE_INDEX,
+ PXE_MTFTP_OPTION_MULTICAST_INDEX,
+ PXE_MTFTP_OPTION_MAXIMUM_INDEX
+};
+
+
+/**
+ This function is to get size of a file by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param BlockSize Pointer to block size
+ @param BufferSize Pointer to buffer size
+
+ @return EFI_SUCCESS
+ @return EFI_NOT_FOUND
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpGetFileSize (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN UINTN *BlockSize,
+ IN OUT UINT64 *BufferSize
+ )
+;
+
+
+/**
+ This function is to get data of a file by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param BlockSize Pointer to block size
+ @param BufferPtr Pointer to buffer
+ @param BufferSize Pointer to buffer size
+ @param DontUseBuffer Indicate whether with a receive buffer
+
+ @return EFI_SUCCESS
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpReadFile (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN UINTN *BlockSize,
+ IN UINT8 *BufferPtr,
+ IN OUT UINT64 *BufferSize,
+ IN BOOLEAN DontUseBuffer
+ )
+;
+
+
+/**
+ This function is put data of a file by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param Overwrite Indicate whether with overwrite attribute
+ @param BlockSize Pointer to block size
+ @param BufferPtr Pointer to buffer
+ @param BufferSize Pointer to buffer size
+
+ @return EFI_SUCCESS
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpWriteFile (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN BOOLEAN Overwrite,
+ IN UINTN *BlockSize,
+ IN UINT8 *BufferPtr,
+ IN OUT UINT64 *BufferSize
+ )
+;
+
+
+/**
+ This function is to get data of a directory by Tftp.
+
+ @param Private Pointer to PxeBc private data
+ @param Config Pointer to Mtftp configuration data
+ @param Filename Pointer to file name
+ @param BlockSize Pointer to block size
+ @param BufferPtr Pointer to buffer
+ @param BufferSize Pointer to buffer size
+ @param DontUseBuffer Indicate whether with a receive buffer
+
+ @return EFI_SUCCES
+ @return EFI_DEVICE_ERROR
+
+**/
+EFI_STATUS
+PxeBcTftpReadDirectory (
+ IN PXEBC_PRIVATE_DATA *Private,
+ IN EFI_MTFTP4_CONFIG_DATA *Config,
+ IN UINT8 *Filename,
+ IN UINTN *BlockSize,
+ IN UINT8 *BufferPtr,
+ IN OUT UINT64 *BufferSize,
+ IN BOOLEAN DontUseBuffer
+ )
+;
+
+#endif
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
new file mode 100644
index 0000000000..200d43141e
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
@@ -0,0 +1,250 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcSupport.c
+
+Abstract:
+
+ Support routines for PxeBc
+
+
+**/
+
+
+#include "PxeBcImpl.h"
+
+
+/**
+
+ @param Smbios Pointer to SMBIOS structure
+ @param StringNumber String number to return. 0 is used to skip all
+ strings and point to the next SMBIOS structure.
+
+ @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0
+
+**/
+// GC_NOTO: function comment is missing 'Routine Description:'
+CHAR8 *
+GetSmbiosString (
+ IN SMBIOS_STRUCTURE_POINTER *Smbios,
+ IN UINT16 StringNumber
+ )
+{
+ UINT16 Index;
+ CHAR8 *String;
+
+ //
+ // Skip over formatted section
+ //
+ String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);
+
+ //
+ // Look through unformated section
+ //
+ for (Index = 1; Index <= StringNumber || StringNumber == 0; Index++) {
+ if (StringNumber == Index) {
+ return String;
+ }
+ //
+ // Skip string
+ //
+ for (; *String != 0; String++)
+ ;
+ String++;
+
+ if (*String == 0) {
+ //
+ // If double NULL then we are done.
+ // Return pointer to next structure in Smbios.
+ // if you pass in a 0 you will always get here
+ //
+ Smbios->Raw = (UINT8 *)++String;
+ return NULL;
+ }
+ }
+
+ return NULL;
+}
+
+
+/**
+ This function gets system guid and serial number from the smbios table
+
+ @param SystemGuid The pointer of returned system guid
+ @param SystemSerialNumber The pointer of returned system serial number
+
+ @retval EFI_SUCCESS Successfully get the system guid and system serial
+ number
+ @retval EFI_NOT_FOUND Not find the SMBIOS table
+
+**/
+EFI_STATUS
+GetSmbiosSystemGuidAndSerialNumber (
+ IN EFI_GUID *SystemGuid,
+ OUT CHAR8 **SystemSerialNumber
+ )
+{
+ EFI_STATUS Status;
+ SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;
+ SMBIOS_STRUCTURE_POINTER Smbios;
+ SMBIOS_STRUCTURE_POINTER SmbiosEnd;
+ UINT16 Index;
+
+ Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);
+
+ if (EFI_ERROR (Status)) {
+ return EFI_NOT_FOUND;
+ }
+
+ Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;
+ SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);
+
+ for (Index = 0; Index < SmbiosTable->TableLength; Index++) {
+ if (Smbios.Hdr->Type == 1) {
+ if (Smbios.Hdr->Length < 0x19) {
+ //
+ // Older version did not support Guid and Serial number
+ //
+ continue;
+ }
+ //
+ // SMBIOS tables are byte packed so we need to do a byte copy to
+ // prevend alignment faults on Itanium-based platform.
+ //
+ CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));
+ *SystemSerialNumber = GetSmbiosString (&Smbios, Smbios.Type1->SerialNumber);
+
+ return EFI_SUCCESS;
+ }
+ //
+ // Make Smbios point to the next record
+ //
+ GetSmbiosString (&Smbios, 0);
+
+ if (Smbios.Raw >= SmbiosEnd.Raw) {
+ //
+ // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.
+ // given this we must double check against the length of the structure.
+ //
+ return EFI_SUCCESS;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Event GC_NOTO: add argument description
+ @param Context GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcCommonNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ *((BOOLEAN *) Context) = TRUE;
+}
+
+
+/**
+ Convert number to ASCII value
+
+ @param Number Numeric value to convert to decimal ASCII value.
+ @param Buffer Buffer to place ASCII version of the Number
+ @param Length Length of Buffer.
+
+ @retval none none
+
+**/
+VOID
+CvtNum (
+ IN UINTN Number,
+ IN UINT8 *Buffer,
+ IN INTN Length
+ )
+{
+ UINTN Remainder;
+
+ while (Length--) {
+ Remainder = Number % 10;
+ Number /= 10;
+ Buffer[Length] = (UINT8) ('0' + Remainder);
+ }
+}
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Number GC_NOTO: add argument description
+ @param Buffer GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+UINTN
+UtoA10 (
+ IN UINTN Number,
+ IN CHAR8 *Buffer
+ )
+{
+ UINTN Index;
+ CHAR8 TempStr[64];
+
+ Index = 63;
+ TempStr[Index] = 0;
+
+ do {
+ Index--;
+ TempStr[Index] = (CHAR8) ('0' + (Number % 10));
+ Number = Number / 10;
+ } while (Number != 0);
+
+ AsciiStrCpy (Buffer, &TempStr[Index]);
+
+ return AsciiStrLen (Buffer);
+}
+
+
+/**
+ Convert ASCII numeric string to a UINTN value
+
+ @param Number Numeric value to convert to decimal ASCII value.
+ @param Buffer Buffer to place ASCII version of the Number
+
+ @retval Value UINTN value of the ASCII string.
+
+**/
+UINT64
+AtoU64 (
+ IN UINT8 *Buffer
+ )
+{
+ UINT64 Value;
+ UINT8 Character;
+
+ Value = 0;
+ while ((Character = *Buffer++) != '\0') {
+ Value = MultU64x32 (Value, 10) + (Character - '0');
+ }
+
+ return Value;
+}
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h
new file mode 100644
index 0000000000..79210c12b3
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h
@@ -0,0 +1,89 @@
+/** @file
+
+Copyright (c) 2007, 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
+
+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:
+
+ PxeBcSupport.h
+
+Abstract:
+
+ Support routines for PxeBc
+
+
+**/
+
+#ifndef __EFI_PXEBC_SUPPORT_H__
+#define __EFI_PXEBC_SUPPORT_H__
+
+EFI_STATUS
+GetSmbiosSystemGuidAndSerialNumber (
+ IN EFI_GUID *SystemGuid,
+ OUT CHAR8 **SystemSerialNumber
+ );
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Event GC_NOTO: add argument description
+ @param Context GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+VOID
+PxeBcCommonNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+;
+
+VOID
+CvtNum (
+ IN UINTN Number,
+ IN UINT8 *Buffer,
+ IN INTN Length
+ );
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param Number GC_NOTO: add argument description
+ @param BufferPtr GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+UINTN
+UtoA10 (
+ UINTN Number,
+ CHAR8 *BufferPtr
+ )
+;
+
+
+/**
+ GC_NOTO: Add function description
+
+ @param BufferPtr GC_NOTO: add argument description
+
+ @return GC_NOTO: add return values
+
+**/
+UINT64
+AtoU64 (
+ UINT8 *BufferPtr
+ )
+;
+
+#endif
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
new file mode 100644
index 0000000000..4412d37e45
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
@@ -0,0 +1,93 @@
+#/** @file
+# Component name for module UefiPxeBc
+#
+# FIX ME!
+# Copyright (c) 2007, Intel Corporation. All rights reserved.
+#
+# 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
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+#**/
+
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UefiPxeBcDxe
+ FILE_GUID = 3B1DEAB5-C75D-442e-9238-8E2FFB62B0BB
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = PxeBcDriverEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+
+[Sources.common]
+ PxeBcMtftp.c
+ PxeBcSupport.h
+ PxeBcSupport.c
+ PxeBcDriver.c
+ PxeBcDhcp.h
+ ComponentName.c
+ PxeBcImpl.c
+ PxeBcImpl.h
+ PxeBcDhcp.c
+ PxeBcMtftp.h
+ PxeBcDriver.h
+
+[Sources.IA32]
+ Ia32\PxeArch.h
+
+[Sources.X64]
+ X64\PxeArch.h
+
+[Sources.IPF]
+ Ipf\PxeArch.h
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+
+
+[LibraryClasses]
+ BaseLib
+ UefiLib
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+ BaseMemoryLib
+ DebugLib
+ NetLib
+
+
+[Guids]
+ gEfiSmbiosTableGuid # ALWAYS_CONSUMED
+
+
+
+[Protocols]
+ gEfiMtftp4ServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiMtftp4ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiUdp4ServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiDhcp4ServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiPxeBaseCodeCallbackProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiPxeBaseCodeProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiLoadFileProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiDhcp4ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiUdp4ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiNetworkInterfaceIdentifierProtocolGuid_31 # PROTOCOL ALWAYS_CONSUMED
+
+
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.msa b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.msa
new file mode 100644
index 0000000000..cbf131a63f
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.msa
@@ -0,0 +1,108 @@
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <MsaHeader>
+ <ModuleName>UefiPxeBcDxe</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>3B1DEAB5-C75D-442e-9238-8E2FFB62B0BB</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component name for module UefiPxeBc</Abstract>
+ <Description>FIX ME!</Description>
+ <Copyright>Copyright (c) 2007, Intel Corporation. All rights reserved.</Copyright>
+ <License>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
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
+ </MsaHeader>
+ <ModuleDefinitions>
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>UefiPxeBcDxe</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>PxeBcDriver.h</Filename>
+ <Filename>PxeBcMtftp.h</Filename>
+ <Filename>PxeBcDhcp.c</Filename>
+ <Filename>PxeBcImpl.h</Filename>
+ <Filename>PxeBcImpl.c</Filename>
+ <Filename>ComponentName.c</Filename>
+ <Filename>PxeBcDhcp.h</Filename>
+ <Filename>ipf\PxeArch.h</Filename>
+ <Filename>PxeBcDriver.c</Filename>
+ <Filename SupArchList="X64">x64\PxeArch.h</Filename>
+ <Filename>PxeBcSupport.c</Filename>
+ <Filename>PxeBcSupport.h</Filename>
+ <Filename>ia32\PxeArch.h</Filename>
+ <Filename>PxeBcMtftp.c</Filename>
+ </SourceFiles>
+ <PackageDependencies>
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+ <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
+ </PackageDependencies>
+ <Protocols>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiNetworkInterfaceIdentifierProtocolGuid_31</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiUdp4ProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiDhcp4ProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiLoadFileProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiPxeBaseCodeProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiPxeBaseCodeCallbackProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiDhcp4ServiceBindingProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiUdp4ServiceBindingProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiMtftp4ProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiMtftp4ServiceBindingProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiSmbiosTableGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>PxeBcDriverEntryPoint</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea> \ No newline at end of file
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/X64/PxeArch.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/X64/PxeArch.h
new file mode 100644
index 0000000000..a8fa293a16
--- /dev/null
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/X64/PxeArch.h
@@ -0,0 +1,26 @@
+/** @file
+
+Copyright (c) 2006, 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
+
+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:
+ PxeArch.h
+
+Abstract:
+ Defines PXE Arch type
+
+
+**/
+
+#ifndef _EFI_PXE_ARCH_H_
+#define _EFI_PXE_ARCH_H_
+
+#define SYS_ARCH 0x7
+
+#endif