From 57b301b569ec392b7bcad5f19a44fe93e0502a7f Mon Sep 17 00:00:00 2001 From: hhuan13 Date: Thu, 14 Jul 2011 11:27:05 +0000 Subject: [PATCH] 1. Define a netlib library function NetLibGetSystemGuid() 2. Update PXE driver to use NetLibGetSystemGuid() git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12017 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Include/Library/NetLib.h | 18 ++- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 88 ++++++++++++- MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf | 3 +- .../Network/UefiPxeBcDxe/PxeBcDhcp.c | 11 +- .../Network/UefiPxeBcDxe/PxeBcSupport.c | 123 +----------------- .../Network/UefiPxeBcDxe/PxeBcSupport.h | 19 +-- 6 files changed, 112 insertions(+), 150 deletions(-) diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h index 102d7f1413..4bb1f766a1 100644 --- a/MdeModulePkg/Include/Library/NetLib.h +++ b/MdeModulePkg/Include/Library/NetLib.h @@ -2,7 +2,7 @@ This library is only intended to be used by UEFI network stack modules. It provides basic functions for the UEFI network stack. -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2011, 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
@@ -2020,4 +2020,20 @@ VOID NetIpSecNetbufFree ( NET_BUF *Nbuf ); + +/** + This function obtains the system guid from the smbios table. + + @param[out] SystemGuid The pointer of the returned system guid. + + @retval EFI_SUCCESS Successfully obtained the system guid. + @retval EFI_NOT_FOUND Did not find the SMBIOS table. + +**/ +EFI_STATUS +EFIAPI +NetLibGetSystemGuid ( + OUT EFI_GUID *SystemGuid + ); + #endif diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c index 55c72027fc..dbd77e5bda 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -1,7 +1,7 @@ /** @file Network library. -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2011, 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 @@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include +#include + #include #include #include @@ -23,6 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include @@ -3155,3 +3158,86 @@ Exit: return Status; } + + +/** + This function obtains the system guid from the smbios table. + + @param[out] SystemGuid The pointer of the returned system guid. + + @retval EFI_SUCCESS Successfully obtained the system guid. + @retval EFI_NOT_FOUND Did not find the SMBIOS table. + +**/ +EFI_STATUS +EFIAPI +NetLibGetSystemGuid ( + OUT EFI_GUID *SystemGuid + ) +{ + EFI_STATUS Status; + SMBIOS_TABLE_ENTRY_POINT *SmbiosTable; + SMBIOS_STRUCTURE_POINTER Smbios; + SMBIOS_STRUCTURE_POINTER SmbiosEnd; + CHAR8 *String; + + SmbiosTable = NULL; + Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable); + + if (EFI_ERROR (Status) || SmbiosTable == NULL) { + return EFI_NOT_FOUND; + } + + Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress; + SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength); + + do { + if (Smbios.Hdr->Type == 1) { + if (Smbios.Hdr->Length < 0x19) { + // + // Older version did not support UUID. + // + return EFI_NOT_FOUND; + } + + // + // 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)); + return EFI_SUCCESS; + } + + // + // Go to the next SMBIOS structure. Each SMBIOS structure may include 2 parts: + // 1. Formatted section; 2. Unformatted string section. So, 2 steps are needed + // to skip one SMBIOS structure. + // + + // + // Step 1: Skip over formatted section. + // + String = (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length); + + // + // Step 2: Skip over unformated string section. + // + do { + // + // Each string is terminated with a NULL(00h) BYTE and the sets of strings + // is terminated with an additional NULL(00h) BYTE. + // + for ( ; *String != 0; String++) { + } + + if (*(UINT8*)++String == 0) { + // + // Pointer to the next SMBIOS structure. + // + Smbios.Raw = (UINT8 *)++String; + break; + } + } while (TRUE); + } while (Smbios.Raw < SmbiosEnd.Raw); + return EFI_NOT_FOUND; +} diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf index 9b11c8211d..190d82b39d 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf @@ -1,7 +1,7 @@ ## @file # Instance of DxeNetLib. # -# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+# Copyright (c) 2006 - 2011, 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 @@ -51,6 +51,7 @@ [Guids] gEfiNicIp4ConfigVariableGuid + gEfiSmbiosTableGuid [Protocols] gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c index 6b25cab33d..a9c86dc042 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c @@ -1,7 +1,7 @@ /** @file Support for PxeBc dhcp functions. -Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2011, 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 @@ -788,7 +788,6 @@ PxeBcDhcpCallBack ( UINT16 Value; EFI_STATUS Status; BOOLEAN Received; - CHAR8 *SystemSerialNumber; EFI_DHCP4_HEADER *DhcpHeader; if ((Dhcp4Event != Dhcp4RcvdOffer) && @@ -843,7 +842,7 @@ PxeBcDhcpCallBack ( // DhcpHeader = &Packet->Dhcp4.Header; - if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) DhcpHeader->ClientHwAddr, &SystemSerialNumber))) { + if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) { // // GUID not yet set - send all 0xff's to show programable (via SetVariable) // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff); @@ -928,7 +927,6 @@ PxeBcBuildDhcpOptions ( UINT32 Index; PXEBC_DHCP4_OPTION_ENTRY OptEnt; UINT16 Value; - CHAR8 *SystemSerialNumber; Index = 0; OptList[0] = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer; @@ -1009,7 +1007,7 @@ PxeBcBuildDhcpOptions ( Index++; OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) OptEnt.Uuid->Guid, &SystemSerialNumber))) { + if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) { // // GUID not yet set - send all 0xff's to show programable (via SetVariable) // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff); @@ -1120,7 +1118,6 @@ PxeBcDiscvBootService ( EFI_DHCP4_PACKET_OPTION *PxeOpt; PXEBC_OPTION_BOOT_ITEM *PxeBootItem; UINT8 VendorOptLen; - CHAR8 *SystemSerialNumber; EFI_DHCP4_HEADER *DhcpHeader; UINT32 Xid; @@ -1180,7 +1177,7 @@ PxeBcDiscvBootService ( DhcpHeader = &Token.Packet->Dhcp4.Header; if (Mode->SendGUID) { - if (EFI_ERROR (GetSmbiosSystemGuidAndSerialNumber ((EFI_GUID *) DhcpHeader->ClientHwAddr, &SystemSerialNumber))) { + if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) { // // GUID not yet set - send all 0's to show not programable // diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c index 60cace885d..327e4a26d8 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c @@ -1,7 +1,7 @@ /** @file Support routines for PxeBc. -Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2011, 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 @@ -16,127 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PxeBcImpl.h" -/** - This function returns SMBIOS string given the string number. - - @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 - -**/ -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; - } - ASSERT (SmbiosTable != NULL); - - 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; -} - - /** The common notify function associated with various PxeBc events. diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h index 8eb9574e80..96f48f56de 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h @@ -1,6 +1,6 @@ /** @file Support routines for PxeBc. -Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2011, 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 @@ -14,23 +14,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef __EFI_PXEBC_SUPPORT_H__ #define __EFI_PXEBC_SUPPORT_H__ -/** - 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 - ); - /** The common notify function associated with various PxeBc events. -- 2.39.2