smbios.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*++
  2. Copyright (c) 2000 Intel Corporation
  3. Module Name:
  4. Smbios.c
  5. Abstract:
  6. Lib fucntions for SMBIOS. Used to get system serial number and GUID
  7. Revision History
  8. --*/
  9. #include "lib.h"
  10. EFI_STATUS
  11. LibGetSmbiosSystemGuidAndSerialNumber (
  12. IN EFI_GUID *SystemGuid,
  13. OUT CHAR8 **SystemSerialNumber
  14. )
  15. {
  16. EFI_STATUS Status;
  17. SMBIOS_STRUCTURE_TABLE *SmbiosTable;
  18. SMBIOS_STRUCTURE_POINTER Smbios;
  19. SMBIOS_STRUCTURE_POINTER SmbiosEnd;
  20. UINT16 Index;
  21. Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&SmbiosTable);
  22. if (EFI_ERROR(Status)) {
  23. return EFI_NOT_FOUND;
  24. }
  25. Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress;
  26. SmbiosEnd.Raw = (UINT8 *)(SmbiosTable->TableAddress + SmbiosTable->TableLength);
  27. for (Index = 0; Index < SmbiosTable->TableLength ; Index++) {
  28. if (Smbios.Hdr->Type == 1) {
  29. if (Smbios.Hdr->Length < 0x19) {
  30. //
  31. // Older version did not support Guid and Serial number
  32. //
  33. continue;
  34. }
  35. //
  36. // SMBIOS tables are byte packed so we need to do a byte copy to
  37. // prevend alignment faults on IA-64.
  38. CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof(EFI_GUID));
  39. *SystemSerialNumber = LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber);
  40. return EFI_SUCCESS;
  41. }
  42. //
  43. // Make Smbios point to the next record
  44. //
  45. LibGetSmbiosString (&Smbios, -1);
  46. if (Smbios.Raw >= SmbiosEnd.Raw) {
  47. //
  48. // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.
  49. // given this we must double check against the lenght of
  50. /// the structure. My home PC has this bug.ruthard
  51. //
  52. return EFI_SUCCESS;
  53. }
  54. }
  55. return EFI_SUCCESS;
  56. }
  57. CHAR8*
  58. LibGetSmbiosString (
  59. IN SMBIOS_STRUCTURE_POINTER *Smbios,
  60. IN UINT16 StringNumber
  61. )
  62. /*++
  63. Return SMBIOS string given the string number.
  64. Arguments:
  65. Smbios - Pointer to SMBIOS structure
  66. StringNumber - String number to return. -1 is used to skip all strings and
  67. point to the next SMBIOS structure.
  68. Returns:
  69. Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
  70. --*/
  71. {
  72. UINT16 Index;
  73. CHAR8 *String;
  74. //
  75. // Skip over formatted section
  76. //
  77. String = (CHAR8 *)(Smbios->Raw + Smbios->Hdr->Length);
  78. //
  79. // Look through unformated section
  80. //
  81. for (Index = 1; Index <= StringNumber; Index++) {
  82. if (StringNumber == Index) {
  83. return String;
  84. }
  85. //
  86. // Skip string
  87. //
  88. for (; *String != 0; String++);
  89. String++;
  90. if (*String == 0) {
  91. //
  92. // If double NULL then we are done.
  93. // Retrun pointer to next structure in Smbios.
  94. // if you pass in a -1 you will always get here
  95. //
  96. Smbios->Raw = (UINT8 *)++String;
  97. return NULL;
  98. }
  99. }
  100. return NULL;
  101. }