TianoCore EDK2 master
Loading...
Searching...
No Matches
HstiDxe.c
Go to the documentation of this file.
1
8#include "HstiDxe.h"
9
26VOID *
28 IN UINT32 Role,
29 IN CHAR16 *ImplementationID OPTIONAL,
30 OUT VOID **HstiData OPTIONAL,
31 OUT UINTN *HstiSize OPTIONAL
32 )
33{
34 EFI_STATUS Status;
36 UINTN NoHandles;
37 EFI_HANDLE *Handles;
38 UINTN Index;
39 EFI_GUID *InfoTypesBuffer;
40 UINTN InfoTypesBufferCount;
41 UINTN InfoTypesIndex;
43 VOID *InformationBlock;
44 UINTN InformationBlockSize;
46
47 Status = gBS->LocateHandleBuffer (
49 &gEfiAdapterInformationProtocolGuid,
50 NULL,
51 &NoHandles,
52 &Handles
53 );
54 if (EFI_ERROR (Status)) {
55 return NULL;
56 }
57
58 Hsti = NULL;
59 Aip = NULL;
60 InformationBlock = NULL;
61 InformationBlockSize = 0;
62 for (Index = 0; Index < NoHandles; Index++) {
63 Status = gBS->HandleProtocol (
64 Handles[Index],
65 &gEfiAdapterInformationProtocolGuid,
66 (VOID **)&Aip
67 );
68 if (EFI_ERROR (Status)) {
69 continue;
70 }
71
72 //
73 // Check AIP
74 //
75 Status = Aip->GetSupportedTypes (
76 Aip,
77 &InfoTypesBuffer,
78 &InfoTypesBufferCount
79 );
80 if (EFI_ERROR (Status) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == 0)) {
81 continue;
82 }
83
84 AipCandidate = NULL;
85 for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) {
86 if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformSecurityGuid)) {
87 AipCandidate = Aip;
88 break;
89 }
90 }
91
92 FreePool (InfoTypesBuffer);
93
94 if (AipCandidate == NULL) {
95 continue;
96 }
97
98 //
99 // Check HSTI Role
100 //
101 Aip = AipCandidate;
102 Status = Aip->GetInformation (
103 Aip,
104 &gAdapterInfoPlatformSecurityGuid,
105 &InformationBlock,
106 &InformationBlockSize
107 );
108 if (EFI_ERROR (Status)) {
109 continue;
110 }
111
112 Hsti = InformationBlock;
113 if ((Hsti->Role == Role) &&
114 ((ImplementationID == NULL) || (StrCmp (ImplementationID, Hsti->ImplementationID) == 0)))
115 {
116 break;
117 } else {
118 Hsti = NULL;
119 FreePool (InformationBlock);
120 continue;
121 }
122 }
123
124 FreePool (Handles);
125
126 if (Hsti == NULL) {
127 return NULL;
128 }
129
130 if (HstiData != NULL) {
131 *HstiData = InformationBlock;
132 }
133
134 if (HstiSize != NULL) {
135 *HstiSize = InformationBlockSize;
136 }
137
138 return Aip;
139}
140
150BOOLEAN
152 IN VOID *HstiData,
153 IN UINTN HstiSize
154 )
155{
157 UINTN Index;
158 CHAR16 *ErrorString;
159 CHAR16 ErrorChar;
160 UINTN ErrorStringSize;
161 UINTN ErrorStringLength;
162
163 Hsti = HstiData;
164
165 //
166 // basic check for header
167 //
168 if (HstiData == NULL) {
169 DEBUG ((DEBUG_ERROR, "HstiData == NULL\n"));
170 return FALSE;
171 }
172
173 if (HstiSize < sizeof (ADAPTER_INFO_PLATFORM_SECURITY)) {
174 DEBUG ((DEBUG_ERROR, "HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)\n"));
175 return FALSE;
176 }
177
178 if (((HstiSize - sizeof (ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < Hsti->SecurityFeaturesSize) {
179 DEBUG ((DEBUG_ERROR, "((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < SecurityFeaturesSize\n"));
180 return FALSE;
181 }
182
183 //
184 // Check Version
185 //
186 if (Hsti->Version != PLATFORM_SECURITY_VERSION_VNEXTCS) {
187 DEBUG ((DEBUG_ERROR, "Version != PLATFORM_SECURITY_VERSION_VNEXTCS\n"));
188 return FALSE;
189 }
190
191 //
192 // Check Role
193 //
194 if ((Hsti->Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE) ||
195 (Hsti->Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM))
196 {
197 DEBUG ((DEBUG_ERROR, "Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE ||\n"));
198 DEBUG ((DEBUG_ERROR, "Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM\n"));
199 return FALSE;
200 }
201
202 //
203 // Check ImplementationID
204 //
205 for (Index = 0; Index < sizeof (Hsti->ImplementationID)/sizeof (Hsti->ImplementationID[0]); Index++) {
206 if (Hsti->ImplementationID[Index] == 0) {
207 break;
208 }
209 }
210
211 if (Index == sizeof (Hsti->ImplementationID)/sizeof (Hsti->ImplementationID[0])) {
212 DEBUG ((DEBUG_ERROR, "ImplementationID has no NUL CHAR\n"));
213 return FALSE;
214 }
215
216 ErrorStringSize = HstiSize - sizeof (ADAPTER_INFO_PLATFORM_SECURITY) - Hsti->SecurityFeaturesSize * 3;
217 ErrorString = (CHAR16 *)((UINTN)Hsti + sizeof (ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 3);
218
219 //
220 // basic check for ErrorString
221 //
222 if (ErrorStringSize == 0) {
223 DEBUG ((DEBUG_ERROR, "ErrorStringSize == 0\n"));
224 return FALSE;
225 }
226
227 if ((ErrorStringSize & BIT0) != 0) {
228 DEBUG ((DEBUG_ERROR, "(ErrorStringSize & BIT0) != 0\n"));
229 return FALSE;
230 }
231
232 //
233 // ErrorString might not be CHAR16 aligned.
234 //
235 CopyMem (&ErrorChar, ErrorString, sizeof (ErrorChar));
236 for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringSize/2)); ErrorStringLength++) {
237 ErrorString++;
238 CopyMem (&ErrorChar, ErrorString, sizeof (ErrorChar));
239 }
240
241 //
242 // check the length of ErrorString
243 //
244 if (ErrorChar != 0) {
245 DEBUG ((DEBUG_ERROR, "ErrorString has no NUL CHAR\n"));
246 return FALSE;
247 }
248
249 if (ErrorStringLength == (ErrorStringSize/2)) {
250 DEBUG ((DEBUG_ERROR, "ErrorString Length incorrect\n"));
251 return FALSE;
252 }
253
254 return TRUE;
255}
256
274EFIAPI
276 IN VOID *Hsti,
277 IN UINTN HstiSize
278 )
279{
280 EFI_STATUS Status;
281 EFI_HANDLE Handle;
282 HSTI_AIP_PRIVATE_DATA *HstiAip;
284 UINT32 Role;
285 CHAR16 *ImplementationID;
286 UINT32 SecurityFeaturesSize;
287 UINT8 *SecurityFeaturesRequired;
288
289 if (!InternalHstiIsValidTable (Hsti, HstiSize)) {
290 return EFI_VOLUME_CORRUPTED;
291 }
292
293 Role = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->Role;
294 ImplementationID = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->ImplementationID;
295 Aip = InternalHstiFindAip (Role, ImplementationID, NULL, NULL);
296 if (Aip != NULL) {
297 return EFI_ALREADY_STARTED;
298 }
299
300 HstiAip = AllocateZeroPool (sizeof (HSTI_AIP_PRIVATE_DATA));
301 if (HstiAip == NULL) {
302 return EFI_OUT_OF_RESOURCES;
303 }
304
305 HstiAip->Hsti = AllocateCopyPool (HstiSize, Hsti);
306 if (HstiAip->Hsti == NULL) {
307 FreePool (HstiAip);
308 return EFI_OUT_OF_RESOURCES;
309 }
310
311 if (Role != PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE) {
312 SecurityFeaturesRequired = (UINT8 *)HstiAip->Hsti + sizeof (ADAPTER_INFO_PLATFORM_SECURITY);
313 SecurityFeaturesSize = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->SecurityFeaturesSize;
314 ZeroMem (SecurityFeaturesRequired, SecurityFeaturesSize);
315 }
316
317 HstiAip->Signature = HSTI_AIP_PRIVATE_SIGNATURE;
318 CopyMem (&HstiAip->Aip, &mAdapterInformationProtocol, sizeof (EFI_ADAPTER_INFORMATION_PROTOCOL));
319 HstiAip->HstiSize = HstiSize;
320 HstiAip->HstiMaxSize = HstiSize;
321
322 Handle = NULL;
323 Status = gBS->InstallMultipleProtocolInterfaces (
324 &Handle,
325 &gEfiAdapterInformationProtocolGuid,
326 &HstiAip->Aip,
327 NULL
328 );
329 if (EFI_ERROR (Status)) {
330 FreePool (HstiAip->Hsti);
331 FreePool (HstiAip);
332 }
333
334 return Status;
335}
336
354EFIAPI
356 IN UINT32 Role,
357 IN CHAR16 *ImplementationID OPTIONAL,
358 OUT VOID **Hsti,
359 OUT UINTN *HstiSize
360 )
361{
363
364 Aip = InternalHstiFindAip (Role, ImplementationID, Hsti, HstiSize);
365 if (Aip == NULL) {
366 return EFI_NOT_FOUND;
367 }
368
369 return EFI_SUCCESS;
370}
371
391 IN UINT32 Role,
392 IN CHAR16 *ImplementationID OPTIONAL,
393 IN UINT32 ByteIndex,
394 IN UINT8 Bit,
395 IN BOOLEAN Set
396 )
397{
400 UINTN HstiSize;
401 UINT8 *SecurityFeaturesVerified;
402 EFI_STATUS Status;
403
404 Aip = InternalHstiFindAip (Role, ImplementationID, (VOID **)&Hsti, &HstiSize);
405 if (Aip == NULL) {
406 return EFI_NOT_STARTED;
407 }
408
409 if (ByteIndex >= Hsti->SecurityFeaturesSize) {
410 return EFI_UNSUPPORTED;
411 }
412
413 SecurityFeaturesVerified = (UINT8 *)((UINTN)Hsti + sizeof (ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 2);
414
415 if (Set) {
416 SecurityFeaturesVerified[ByteIndex] = (UINT8)(SecurityFeaturesVerified[ByteIndex] | (Bit));
417 } else {
418 SecurityFeaturesVerified[ByteIndex] = (UINT8)(SecurityFeaturesVerified[ByteIndex] & (~Bit));
419 }
420
421 Status = Aip->SetInformation (
422 Aip,
423 &gAdapterInfoPlatformSecurityGuid,
424 Hsti,
425 HstiSize
426 );
427 FreePool (Hsti);
428 return Status;
429}
430
447EFIAPI
449 IN UINT32 Role,
450 IN CHAR16 *ImplementationID OPTIONAL,
451 IN UINT32 ByteIndex,
452 IN UINT8 BitMask
453 )
454{
456 Role,
457 ImplementationID,
458 ByteIndex,
459 BitMask,
460 TRUE
461 );
462}
463
480EFIAPI
482 IN UINT32 Role,
483 IN CHAR16 *ImplementationID OPTIONAL,
484 IN UINT32 ByteIndex,
485 IN UINT8 BitMask
486 )
487{
489 Role,
490 ImplementationID,
491 ByteIndex,
492 BitMask,
493 FALSE
494 );
495}
496
515 IN UINT32 Role,
516 IN CHAR16 *ImplementationID OPTIONAL,
517 IN CHAR16 *ErrorString,
518 IN BOOLEAN Append
519 )
520{
523 UINTN HstiSize;
524 UINTN StringSize;
525 VOID *NewHsti;
526 UINTN NewHstiSize;
527 UINTN Offset;
528 EFI_STATUS Status;
529
530 Aip = InternalHstiFindAip (Role, ImplementationID, (VOID **)&Hsti, &HstiSize);
531 if (Aip == NULL) {
532 return EFI_NOT_STARTED;
533 }
534
535 if (Append) {
536 Offset = HstiSize - sizeof (CHAR16);
537 } else {
538 Offset = sizeof (ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 3;
539 }
540
541 StringSize = StrSize (ErrorString);
542
543 NewHstiSize = Offset + StringSize;
544 NewHsti = AllocatePool (NewHstiSize);
545 if (NewHsti == NULL) {
546 return EFI_OUT_OF_RESOURCES;
547 }
548
549 CopyMem (NewHsti, Hsti, Offset);
550 CopyMem ((UINT8 *)NewHsti + Offset, ErrorString, StringSize);
551
552 Status = Aip->SetInformation (
553 Aip,
554 &gAdapterInfoPlatformSecurityGuid,
555 NewHsti,
556 NewHstiSize
557 );
558 FreePool (Hsti);
559 FreePool (NewHsti);
560 return Status;
561}
562
578EFIAPI
580 IN UINT32 Role,
581 IN CHAR16 *ImplementationID OPTIONAL,
582 IN CHAR16 *ErrorString
583 )
584{
586 Role,
587 ImplementationID,
588 ErrorString,
589 TRUE
590 );
591}
592
608EFIAPI
610 IN UINT32 Role,
611 IN CHAR16 *ImplementationID OPTIONAL,
612 IN CHAR16 *ErrorString
613 )
614{
616 Role,
617 ImplementationID,
618 ErrorString,
619 FALSE
620 );
621}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI HstiLibGetTable(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, OUT VOID **Hsti, OUT UINTN *HstiSize)
Definition: HstiDxe.c:355
EFI_STATUS EFIAPI HstiLibSetErrorString(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN CHAR16 *ErrorString)
Definition: HstiDxe.c:609
EFI_STATUS EFIAPI HstiLibClearFeaturesVerified(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN UINT32 ByteIndex, IN UINT8 BitMask)
Definition: HstiDxe.c:481
EFI_STATUS EFIAPI HstiLibAppendErrorString(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN CHAR16 *ErrorString)
Definition: HstiDxe.c:579
BOOLEAN InternalHstiIsValidTable(IN VOID *HstiData, IN UINTN HstiSize)
Definition: HstiDxe.c:151
EFI_STATUS InternalHstiRecordErrorString(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN CHAR16 *ErrorString, IN BOOLEAN Append)
Definition: HstiDxe.c:514
EFI_STATUS InternalHstiRecordFeaturesVerified(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN UINT32 ByteIndex, IN UINT8 Bit, IN BOOLEAN Set)
Definition: HstiDxe.c:390
EFI_STATUS EFIAPI HstiLibSetFeaturesVerified(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, IN UINT32 ByteIndex, IN UINT8 BitMask)
Definition: HstiDxe.c:448
VOID * InternalHstiFindAip(IN UINT32 Role, IN CHAR16 *ImplementationID OPTIONAL, OUT VOID **HstiData OPTIONAL, OUT UINTN *HstiSize OPTIONAL)
Definition: HstiDxe.c:27
EFI_STATUS EFIAPI HstiLibSetTable(IN VOID *Hsti, IN UINTN HstiSize)
Definition: HstiDxe.c:275
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI Set(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_MODE Mode)
Definition: PL061Gpio.c:219
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ ByProtocol
Definition: UefiSpec.h:1518
Definition: Base.h:213