]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / SmbiosMeasurementDxe / SmbiosMeasurementDxe.c
1 /** @file
2 This driver measures SMBIOS table to TPM.
3
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10
11 #include <Protocol/Smbios.h>
12 #include <IndustryStandard/SmBios.h>
13 #include <IndustryStandard/UefiTcgPlatform.h>
14 #include <Guid/EventGroup.h>
15 #include <Guid/SmBios.h>
16 #include <Library/DebugLib.h>
17 #include <Library/UefiDriverEntryPoint.h>
18 #include <Library/UefiLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/TpmMeasurementLib.h>
24
25 #define FIELD_SIZE_OF(TYPE, Field) ((UINTN)sizeof(((TYPE *)0)->Field))
26
27 typedef struct {
28 UINT8 Type;
29 UINTN Offset;
30 UINTN Size;
31 UINT32 Flags;
32 } SMBIOS_FILTER_TABLE;
33 #define SMBIOS_FILTER_TABLE_FLAG_IS_STRING BIT0
34
35 typedef struct {
36 UINT8 Type;
37 SMBIOS_FILTER_TABLE *Filter; // NULL means all fields
38 UINTN FilterCount;
39 } SMBIOS_FILTER_STRUCT;
40
41 //
42 // Platform Specific Policy
43 //
44 SMBIOS_FILTER_TABLE mSmbiosFilterType1BlackList[] = {
45 {0x01, OFFSET_OF(SMBIOS_TABLE_TYPE1, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE1, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
46 {0x01, OFFSET_OF(SMBIOS_TABLE_TYPE1, Uuid), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE1, Uuid), 0},
47 {0x01, OFFSET_OF(SMBIOS_TABLE_TYPE1, WakeUpType), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE1, WakeUpType), 0},
48 };
49 SMBIOS_FILTER_TABLE mSmbiosFilterType2BlackList[] = {
50 {0x02, OFFSET_OF(SMBIOS_TABLE_TYPE2, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE2, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
51 {0x02, OFFSET_OF(SMBIOS_TABLE_TYPE2, LocationInChassis), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE2, LocationInChassis), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
52 };
53 SMBIOS_FILTER_TABLE mSmbiosFilterType3BlackList[] = {
54 {0x03, OFFSET_OF(SMBIOS_TABLE_TYPE3, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE3, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
55 {0x03, OFFSET_OF(SMBIOS_TABLE_TYPE3, AssetTag), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE3, AssetTag), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
56 };
57 SMBIOS_FILTER_TABLE mSmbiosFilterType4BlackList[] = {
58 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
59 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, AssetTag), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, AssetTag), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
60 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, PartNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, PartNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
61 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, CoreCount), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, CoreCount), 0},
62 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, EnabledCoreCount), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, EnabledCoreCount), 0},
63 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, ThreadCount), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, ThreadCount), 0},
64 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, CoreCount2), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, CoreCount2), 0},
65 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, EnabledCoreCount2), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, EnabledCoreCount2), 0},
66 {0x04, OFFSET_OF(SMBIOS_TABLE_TYPE4, ThreadCount2), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE4, ThreadCount2), 0},
67 };
68 SMBIOS_FILTER_TABLE mSmbiosFilterType17BlackList[] = {
69 {0x11, OFFSET_OF(SMBIOS_TABLE_TYPE17, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE17, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
70 {0x11, OFFSET_OF(SMBIOS_TABLE_TYPE17, AssetTag), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE17, AssetTag), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
71 {0x11, OFFSET_OF(SMBIOS_TABLE_TYPE17, PartNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE17, PartNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
72 };
73 SMBIOS_FILTER_TABLE mSmbiosFilterType22BlackList[] = {
74 {0x16, OFFSET_OF(SMBIOS_TABLE_TYPE22, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE22, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
75 {0x16, OFFSET_OF(SMBIOS_TABLE_TYPE22, SBDSSerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE22, SBDSSerialNumber), 0},
76 {0x16, OFFSET_OF(SMBIOS_TABLE_TYPE22, SBDSManufactureDate), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE22, SBDSManufactureDate), 0},
77 };
78 SMBIOS_FILTER_TABLE mSmbiosFilterType23BlackList[] = {
79 {0x17, OFFSET_OF(SMBIOS_TABLE_TYPE23, ResetCount), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE23, ResetCount), 0},
80 };
81 SMBIOS_FILTER_TABLE mSmbiosFilterType27BlackList[] = {
82 {0x1B, OFFSET_OF(SMBIOS_TABLE_TYPE27, NominalSpeed), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE27, NominalSpeed), 0},
83 };
84 SMBIOS_FILTER_TABLE mSmbiosFilterType39BlackList[] = {
85 {0x27, OFFSET_OF(SMBIOS_TABLE_TYPE39, SerialNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE39, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
86 {0x27, OFFSET_OF(SMBIOS_TABLE_TYPE39, AssetTagNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE39, AssetTagNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
87 {0x27, OFFSET_OF(SMBIOS_TABLE_TYPE39, ModelPartNumber), FIELD_SIZE_OF(SMBIOS_TABLE_TYPE39, ModelPartNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING},
88 };
89
90 SMBIOS_FILTER_STRUCT mSmbiosFilterStandardTableBlackList[] = {
91 {0x01, mSmbiosFilterType1BlackList, sizeof(mSmbiosFilterType1BlackList)/sizeof(mSmbiosFilterType1BlackList[0])},
92 {0x02, mSmbiosFilterType2BlackList, sizeof(mSmbiosFilterType2BlackList)/sizeof(mSmbiosFilterType2BlackList[0])},
93 {0x03, mSmbiosFilterType3BlackList, sizeof(mSmbiosFilterType3BlackList)/sizeof(mSmbiosFilterType3BlackList[0])},
94 {0x04, mSmbiosFilterType4BlackList, sizeof(mSmbiosFilterType4BlackList)/sizeof(mSmbiosFilterType4BlackList[0])},
95 {0x0B, NULL, 0},
96 {0x0F, NULL, 0},
97 {0x11, mSmbiosFilterType17BlackList, sizeof(mSmbiosFilterType17BlackList)/sizeof(mSmbiosFilterType17BlackList[0])},
98 {0x12, NULL, 0},
99 {0x16, mSmbiosFilterType22BlackList, sizeof(mSmbiosFilterType22BlackList)/sizeof(mSmbiosFilterType22BlackList[0])},
100 {0x17, mSmbiosFilterType23BlackList, sizeof(mSmbiosFilterType23BlackList)/sizeof(mSmbiosFilterType23BlackList[0])},
101 {0x1B, mSmbiosFilterType27BlackList, sizeof(mSmbiosFilterType27BlackList)/sizeof(mSmbiosFilterType27BlackList[0])},
102 {0x1F, NULL, 0},
103 {0x21, NULL, 0},
104 {0x27, mSmbiosFilterType39BlackList, sizeof(mSmbiosFilterType39BlackList)/sizeof(mSmbiosFilterType39BlackList[0])},
105 };
106
107 EFI_SMBIOS_PROTOCOL *mSmbios;
108 UINTN mMaxLen;
109
110 /**
111
112 This function dump raw data.
113
114 @param Data raw data
115 @param Size raw data size
116
117 **/
118 VOID
119 InternalDumpData (
120 IN UINT8 *Data,
121 IN UINTN Size
122 )
123 {
124 UINTN Index;
125 for (Index = 0; Index < Size; Index++) {
126 DEBUG ((EFI_D_VERBOSE, "%02x", (UINTN)Data[Index]));
127 }
128 }
129
130 /**
131
132 This function dump raw data with colume format.
133
134 @param Data raw data
135 @param Size raw data size
136
137 **/
138 VOID
139 InternalDumpHex (
140 IN UINT8 *Data,
141 IN UINTN Size
142 )
143 {
144 UINTN Index;
145 UINTN Count;
146 UINTN Left;
147
148 #define COLUME_SIZE (16 * 2)
149
150 Count = Size / COLUME_SIZE;
151 Left = Size % COLUME_SIZE;
152 for (Index = 0; Index < Count; Index++) {
153 DEBUG ((EFI_D_VERBOSE, "%04x: ", Index * COLUME_SIZE));
154 InternalDumpData (Data + Index * COLUME_SIZE, COLUME_SIZE);
155 DEBUG ((EFI_D_VERBOSE, "\n"));
156 }
157
158 if (Left != 0) {
159 DEBUG ((EFI_D_VERBOSE, "%04x: ", Index * COLUME_SIZE));
160 InternalDumpData (Data + Index * COLUME_SIZE, Left);
161 DEBUG ((EFI_D_VERBOSE, "\n"));
162 }
163 }
164
165
166 /**
167
168 This function get filter structure by SMBIOS type.
169
170 @param Type SMBIOS type
171
172 **/
173 SMBIOS_FILTER_STRUCT *
174 GetFilterStructByType (
175 IN UINT8 Type
176 )
177 {
178 UINTN Index;
179 for (Index = 0; Index < sizeof(mSmbiosFilterStandardTableBlackList)/sizeof(mSmbiosFilterStandardTableBlackList[0]); Index++) {
180 if (mSmbiosFilterStandardTableBlackList[Index].Type == Type) {
181 return &mSmbiosFilterStandardTableBlackList[Index];
182 }
183 }
184 return NULL;
185 }
186
187 /**
188
189 This function get SMBIOS string in SMBIOS table.
190
191 @param Head SMBIOS table head
192 @param StringId SMBIOS string ID
193 @param StringLen length of SMBIOS string
194
195 @return SMBIOS string data
196 **/
197 CHAR8 *
198 GetSmbiosStringById (
199 IN EFI_SMBIOS_TABLE_HEADER *Head,
200 IN SMBIOS_TABLE_STRING StringId,
201 OUT UINTN *StringLen
202 )
203 {
204 UINTN Size;
205 UINTN StrLen;
206 CHAR8 *CharInStr;
207 UINTN StringsNumber;
208 CHAR8 *String;
209
210 CharInStr = (CHAR8 *)Head + Head->Length;
211 Size = Head->Length;
212 StringsNumber = 0;
213 StrLen = 0;
214 //
215 // look for the two consecutive zeros, check the string limit by the way.
216 //
217 String = NULL;
218 while (*CharInStr != 0 || *(CharInStr+1) != 0) {
219 if (*CharInStr == 0) {
220 Size += 1;
221 CharInStr++;
222 }
223 String = CharInStr;
224
225 for (StrLen = 0 ; StrLen < mMaxLen; StrLen++) {
226 if (*(CharInStr+StrLen) == 0) {
227 break;
228 }
229 }
230 *StringLen = StrLen;
231
232 if (StrLen == mMaxLen) {
233 return NULL;
234 }
235
236 //
237 // forward the pointer
238 //
239 CharInStr += StrLen;
240 Size += StrLen;
241 StringsNumber += 1;
242 if (StringsNumber == StringId) {
243 break;
244 }
245 }
246
247 return String;
248 }
249
250 /**
251
252 This function update SMBIOS table based on policy.
253
254 @param TableEntry SMBIOS table
255 @param TableEntrySize SMBIOS table size
256
257 **/
258 VOID
259 FilterSmbiosEntry (
260 IN OUT VOID *TableEntry,
261 IN UINTN TableEntrySize
262 )
263 {
264 SMBIOS_FILTER_STRUCT *FilterStruct;
265 SMBIOS_FILTER_TABLE *Filter;
266 UINTN Index;
267 SMBIOS_TABLE_STRING StringId;
268 CHAR8 *String;
269 UINTN StringLen;
270
271 DEBUG ((EFI_D_INFO, "Smbios Table (Type - %d):\n", ((SMBIOS_STRUCTURE *)TableEntry)->Type));
272 DEBUG_CODE (InternalDumpHex (TableEntry, TableEntrySize););
273
274 //
275 // Skip measurement for OEM types.
276 //
277 if (((SMBIOS_STRUCTURE *)TableEntry)->Type >= SMBIOS_OEM_BEGIN) {
278 // zero all table fields, except header
279 ZeroMem ((UINT8 *)TableEntry + sizeof(SMBIOS_STRUCTURE), TableEntrySize - sizeof(SMBIOS_STRUCTURE));
280 } else {
281 FilterStruct = GetFilterStructByType (((SMBIOS_STRUCTURE *)TableEntry)->Type);
282 if (FilterStruct != NULL) {
283 if (FilterStruct->Filter == NULL || FilterStruct->FilterCount == 0) {
284 // zero all table fields, except header
285 ZeroMem ((UINT8 *)TableEntry + sizeof(SMBIOS_STRUCTURE), TableEntrySize - sizeof(SMBIOS_STRUCTURE));
286 } else {
287 Filter = FilterStruct->Filter;
288 for (Index = 0; Index < FilterStruct->FilterCount; Index++) {
289 if (((SMBIOS_STRUCTURE *) TableEntry)->Length >= (Filter[Index].Offset + Filter[Index].Size)) {
290 //
291 // The field is present in the SMBIOS entry.
292 //
293 if ((Filter[Index].Flags & SMBIOS_FILTER_TABLE_FLAG_IS_STRING) != 0) {
294 CopyMem (&StringId, (UINT8 *)TableEntry + Filter[Index].Offset, sizeof(StringId));
295 if (StringId != 0) {
296 // set ' ' for string field
297 String = GetSmbiosStringById (TableEntry, StringId, &StringLen);
298 ASSERT (String != NULL);
299 //DEBUG ((EFI_D_INFO,"StrId(0x%x)-%a(%d)\n", StringId, String, StringLen));
300 SetMem (String, StringLen, ' ');
301 }
302 }
303 // zero non-string field
304 ZeroMem ((UINT8 *)TableEntry + Filter[Index].Offset, Filter[Index].Size);
305 }
306 }
307 }
308 }
309 }
310
311 DEBUG ((EFI_D_INFO, "Filter Smbios Table (Type - %d):\n", ((SMBIOS_STRUCTURE *)TableEntry)->Type));
312 DEBUG_CODE (InternalDumpHex (TableEntry, TableEntrySize););
313 }
314
315 /**
316
317 Get the full size of SMBIOS structure including optional strings that follow the formatted structure.
318
319 @param Head Pointer to the beginning of SMBIOS structure.
320 @param NumberOfStrings The returned number of optional strings that follow the formatted structure.
321
322 @return Size The returned size.
323 **/
324 UINTN
325 GetSmbiosStructureSize (
326 IN EFI_SMBIOS_TABLE_HEADER *Head,
327 OUT UINTN *NumberOfStrings
328 )
329 {
330 UINTN Size;
331 UINTN StrLen;
332 CHAR8 *CharInStr;
333 UINTN StringsNumber;
334
335 CharInStr = (CHAR8 *)Head + Head->Length;
336 Size = Head->Length;
337 StringsNumber = 0;
338 StrLen = 0;
339 //
340 // look for the two consecutive zeros, check the string limit by the way.
341 //
342 while (*CharInStr != 0 || *(CharInStr+1) != 0) {
343 if (*CharInStr == 0) {
344 Size += 1;
345 CharInStr++;
346 }
347
348 for (StrLen = 0 ; StrLen < mMaxLen; StrLen++) {
349 if (*(CharInStr+StrLen) == 0) {
350 break;
351 }
352 }
353
354 if (StrLen == mMaxLen) {
355 return 0;
356 }
357
358 //
359 // forward the pointer
360 //
361 CharInStr += StrLen;
362 Size += StrLen;
363 StringsNumber += 1;
364 }
365
366 //
367 // count ending two zeros.
368 //
369 Size += 2;
370
371 if (NumberOfStrings != NULL) {
372 *NumberOfStrings = StringsNumber;
373 }
374 return Size;
375 }
376
377 /**
378
379 This function returns full SMBIOS table length.
380
381 @param TableAddress SMBIOS table based address
382 @param TableMaximumSize Maximum size of SMBIOS table
383
384 @return SMBIOS table length
385
386 **/
387 UINTN
388 GetSmbiosTableLength (
389 IN VOID *TableAddress,
390 IN UINTN TableMaximumSize
391 )
392 {
393 VOID *TableEntry;
394 VOID *TableAddressEnd;
395 UINTN TableEntryLength;
396
397 TableAddressEnd = (VOID *)((UINTN)TableAddress + TableMaximumSize);
398 TableEntry = TableAddress;
399 while (TableEntry < TableAddressEnd) {
400 TableEntryLength = GetSmbiosStructureSize (TableEntry, NULL);
401 if (TableEntryLength == 0) {
402 break;
403 }
404 if (((SMBIOS_STRUCTURE *)TableEntry)->Type == 127) {
405 TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
406 break;
407 }
408 TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
409 }
410
411 return ((UINTN)TableEntry - (UINTN)TableAddress);
412 }
413
414 /**
415
416 This function updatess full SMBIOS table length.
417
418 @param TableAddress SMBIOS table based address
419 @param TableLength SMBIOS table length
420
421 **/
422 VOID
423 FilterSmbiosTable (
424 IN OUT VOID *TableAddress,
425 IN UINTN TableLength
426 )
427 {
428 VOID *TableAddressEnd;
429 VOID *TableEntry;
430 UINTN TableEntryLength;
431
432 TableEntry = TableAddress;
433 TableAddressEnd = (VOID *)((UINTN)TableAddress + TableLength);
434 while ((UINTN)TableEntry < (UINTN)TableAddressEnd) {
435 TableEntryLength = GetSmbiosStructureSize (TableEntry, NULL);
436 if (TableEntryLength == 0) {
437 break;
438 }
439
440 FilterSmbiosEntry (TableEntry, TableEntryLength);
441
442 TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
443 }
444 }
445
446 /**
447 Measure SMBIOS with EV_EFI_HANDOFF_TABLES to PCR[1].
448
449 @param[in] Event Event whose notification function is being invoked.
450 @param[in] Context Pointer to the notification function's context.
451
452 **/
453 VOID
454 EFIAPI
455 MeasureSmbiosTable (
456 IN EFI_EVENT Event,
457 IN VOID *Context
458 )
459 {
460 EFI_STATUS Status;
461 EFI_HANDOFF_TABLE_POINTERS HandoffTables;
462 SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;
463 SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios3Table;
464 VOID *SmbiosTableAddress;
465 VOID *TableAddress;
466 UINTN TableLength;
467
468 SmbiosTable = NULL;
469 Smbios3Table = NULL;
470 SmbiosTableAddress = NULL;
471 TableLength = 0;
472
473 if (mSmbios->MajorVersion >= 3) {
474 Status = EfiGetSystemConfigurationTable (
475 &gEfiSmbios3TableGuid,
476 (VOID **) &Smbios3Table
477 );
478 if (!EFI_ERROR (Status)) {
479 DEBUG ((EFI_D_INFO, "Smbios3Table:\n"));
480 DEBUG ((EFI_D_INFO, " AnchorString - '%c%c%c%c%c'\n",
481 Smbios3Table->AnchorString[0],
482 Smbios3Table->AnchorString[1],
483 Smbios3Table->AnchorString[2],
484 Smbios3Table->AnchorString[3],
485 Smbios3Table->AnchorString[4]
486 ));
487 DEBUG ((EFI_D_INFO, " EntryPointStructureChecksum - 0x%02x\n", Smbios3Table->EntryPointStructureChecksum));
488 DEBUG ((EFI_D_INFO, " EntryPointLength - 0x%02x\n", Smbios3Table->EntryPointLength));
489 DEBUG ((EFI_D_INFO, " MajorVersion - 0x%02x\n", Smbios3Table->MajorVersion));
490 DEBUG ((EFI_D_INFO, " MinorVersion - 0x%02x\n", Smbios3Table->MinorVersion));
491 DEBUG ((EFI_D_INFO, " DocRev - 0x%02x\n", Smbios3Table->DocRev));
492 DEBUG ((EFI_D_INFO, " EntryPointRevision - 0x%02x\n", Smbios3Table->EntryPointRevision));
493 DEBUG ((EFI_D_INFO, " TableMaximumSize - 0x%08x\n", Smbios3Table->TableMaximumSize));
494 DEBUG ((EFI_D_INFO, " TableAddress - 0x%016lx\n", Smbios3Table->TableAddress));
495 }
496 }
497
498 if (Smbios3Table == NULL) {
499 Status = EfiGetSystemConfigurationTable (
500 &gEfiSmbiosTableGuid,
501 (VOID **) &SmbiosTable
502 );
503 if (!EFI_ERROR (Status)) {
504 DEBUG ((EFI_D_INFO, "SmbiosTable:\n"));
505 DEBUG ((EFI_D_INFO, " AnchorString - '%c%c%c%c'\n",
506 SmbiosTable->AnchorString[0],
507 SmbiosTable->AnchorString[1],
508 SmbiosTable->AnchorString[2],
509 SmbiosTable->AnchorString[3]
510 ));
511 DEBUG ((EFI_D_INFO, " EntryPointStructureChecksum - 0x%02x\n", SmbiosTable->EntryPointStructureChecksum));
512 DEBUG ((EFI_D_INFO, " EntryPointLength - 0x%02x\n", SmbiosTable->EntryPointLength));
513 DEBUG ((EFI_D_INFO, " MajorVersion - 0x%02x\n", SmbiosTable->MajorVersion));
514 DEBUG ((EFI_D_INFO, " MinorVersion - 0x%02x\n", SmbiosTable->MinorVersion));
515 DEBUG ((EFI_D_INFO, " MaxStructureSize - 0x%08x\n", SmbiosTable->MaxStructureSize));
516 DEBUG ((EFI_D_INFO, " EntryPointRevision - 0x%02x\n", SmbiosTable->EntryPointRevision));
517 DEBUG ((EFI_D_INFO, " FormattedArea - '%c%c%c%c%c'\n",
518 SmbiosTable->FormattedArea[0],
519 SmbiosTable->FormattedArea[1],
520 SmbiosTable->FormattedArea[2],
521 SmbiosTable->FormattedArea[3],
522 SmbiosTable->FormattedArea[4]
523 ));
524 DEBUG ((EFI_D_INFO, " IntermediateAnchorString - '%c%c%c%c%c'\n",
525 SmbiosTable->IntermediateAnchorString[0],
526 SmbiosTable->IntermediateAnchorString[1],
527 SmbiosTable->IntermediateAnchorString[2],
528 SmbiosTable->IntermediateAnchorString[3],
529 SmbiosTable->IntermediateAnchorString[4]
530 ));
531 DEBUG ((EFI_D_INFO, " IntermediateChecksum - 0x%02x\n", SmbiosTable->IntermediateChecksum));
532 DEBUG ((EFI_D_INFO, " TableLength - 0x%04x\n", SmbiosTable->TableLength));
533 DEBUG ((EFI_D_INFO, " TableAddress - 0x%08x\n", SmbiosTable->TableAddress));
534 DEBUG ((EFI_D_INFO, " NumberOfSmbiosStructures - 0x%04x\n", SmbiosTable->NumberOfSmbiosStructures));
535 DEBUG ((EFI_D_INFO, " SmbiosBcdRevision - 0x%02x\n", SmbiosTable->SmbiosBcdRevision));
536 }
537 }
538
539 if (Smbios3Table != NULL) {
540 SmbiosTableAddress = (VOID *)(UINTN)Smbios3Table->TableAddress;
541 TableLength = GetSmbiosTableLength (SmbiosTableAddress, Smbios3Table->TableMaximumSize);
542 } else if (SmbiosTable != NULL) {
543 SmbiosTableAddress = (VOID *)(UINTN)SmbiosTable->TableAddress;
544 TableLength = SmbiosTable->TableLength;
545 }
546
547 if (SmbiosTableAddress != NULL) {
548 DEBUG ((DEBUG_INFO, "The Smbios Table starts at: 0x%x\n", SmbiosTableAddress));
549 DEBUG ((DEBUG_INFO, "The Smbios Table size: 0x%x\n", TableLength));
550 DEBUG_CODE (InternalDumpHex ((UINT8 *)(UINTN)SmbiosTableAddress, TableLength););
551
552 TableAddress = AllocateCopyPool ((UINTN)TableLength, (VOID *)(UINTN)SmbiosTableAddress);
553 if (TableAddress == NULL) {
554 return ;
555 }
556
557 FilterSmbiosTable (TableAddress, TableLength);
558
559 DEBUG ((DEBUG_INFO, "The final Smbios Table starts at: 0x%x\n", TableAddress));
560 DEBUG ((DEBUG_INFO, "The final Smbios Table size: 0x%x\n", TableLength));
561 DEBUG_CODE (InternalDumpHex (TableAddress, TableLength););
562
563 HandoffTables.NumberOfTables = 1;
564 if (Smbios3Table != NULL) {
565 CopyGuid (&(HandoffTables.TableEntry[0].VendorGuid), &gEfiSmbios3TableGuid);
566 HandoffTables.TableEntry[0].VendorTable = Smbios3Table;
567 } else {
568 CopyGuid (&(HandoffTables.TableEntry[0].VendorGuid), &gEfiSmbiosTableGuid);
569 HandoffTables.TableEntry[0].VendorTable = SmbiosTable;
570 }
571 Status = TpmMeasureAndLogData (
572 1, // PCRIndex
573 EV_EFI_HANDOFF_TABLES, // EventType
574 &HandoffTables, // EventLog
575 sizeof (HandoffTables), // LogLen
576 TableAddress, // HashData
577 TableLength // HashDataLen
578 );
579 if (EFI_ERROR (Status)) {
580 return ;
581 }
582 }
583
584 return ;
585 }
586
587 /**
588
589 Driver to produce Smbios measurement.
590
591 @param ImageHandle Module's image handle
592 @param SystemTable Pointer of EFI_SYSTEM_TABLE
593
594 @return Status returned from EfiCreateEventReadyToBootEx().
595
596 **/
597 EFI_STATUS
598 EFIAPI
599 SmbiosMeasurementDriverEntryPoint (
600 IN EFI_HANDLE ImageHandle,
601 IN EFI_SYSTEM_TABLE *SystemTable
602 )
603 {
604 EFI_STATUS Status;
605 EFI_EVENT Event;
606
607 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &mSmbios);
608 ASSERT_EFI_ERROR (Status);
609 DEBUG ((DEBUG_INFO, "The Smbios Table Version: %x.%x\n", mSmbios->MajorVersion, mSmbios->MinorVersion));
610
611 if (mSmbios->MajorVersion < 2 || (mSmbios->MajorVersion == 2 && mSmbios->MinorVersion < 7)){
612 mMaxLen = SMBIOS_STRING_MAX_LENGTH;
613 } else if (mSmbios->MajorVersion < 3) {
614 //
615 // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string.
616 // However, the length of the entire structure table (including all strings) must be reported
617 // in the Structure Table Length field of the SMBIOS Structure Table Entry Point,
618 // which is a WORD field limited to 65,535 bytes.
619 //
620 mMaxLen = SMBIOS_TABLE_MAX_LENGTH;
621 } else {
622 //
623 // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes.
624 // Locate the end of string as long as possible.
625 //
626 mMaxLen = SMBIOS_3_0_TABLE_MAX_LENGTH;
627 }
628
629 //
630 // Measure Smbios tables
631 //
632 Status = EfiCreateEventReadyToBootEx (
633 TPL_CALLBACK,
634 MeasureSmbiosTable,
635 NULL,
636 &Event
637 );
638
639 return Status;
640 }