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