3 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
11 Find HSTI table in AIP protocol, and return the data.
12 This API will return the HSTI table with indicated Role and ImplementationID,
13 NULL ImplementationID means to find the first HSTI table with indicated Role.
15 @param Role Role of HSTI data.
16 @param ImplementationID ImplementationID of HSTI data.
17 NULL means find the first one match Role.
18 @param HstiData HSTI data. This buffer is allocated by callee, and it
19 is the responsibility of the caller to free it after
21 @param HstiSize HSTI size
23 @return Aip The AIP protocol having this HSTI.
24 @return NULL There is not HSTI table with the Role and ImplementationID published in system.
29 IN CHAR16
*ImplementationID OPTIONAL
,
30 OUT VOID
**HstiData OPTIONAL
,
31 OUT UINTN
*HstiSize OPTIONAL
35 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
39 EFI_GUID
*InfoTypesBuffer
;
40 UINTN InfoTypesBufferCount
;
42 EFI_ADAPTER_INFORMATION_PROTOCOL
*AipCandidate
;
43 VOID
*InformationBlock
;
44 UINTN InformationBlockSize
;
45 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
47 Status
= gBS
->LocateHandleBuffer (
49 &gEfiAdapterInformationProtocolGuid
,
54 if (EFI_ERROR (Status
)) {
60 InformationBlock
= NULL
;
61 InformationBlockSize
= 0;
62 for (Index
= 0; Index
< NoHandles
; Index
++) {
63 Status
= gBS
->HandleProtocol (
65 &gEfiAdapterInformationProtocolGuid
,
68 if (EFI_ERROR (Status
)) {
75 Status
= Aip
->GetSupportedTypes (
80 if (EFI_ERROR (Status
) || (InfoTypesBuffer
== NULL
) || (InfoTypesBufferCount
== 0)) {
85 for (InfoTypesIndex
= 0; InfoTypesIndex
< InfoTypesBufferCount
; InfoTypesIndex
++) {
86 if (CompareGuid (&InfoTypesBuffer
[InfoTypesIndex
], &gAdapterInfoPlatformSecurityGuid
)) {
92 FreePool (InfoTypesBuffer
);
94 if (AipCandidate
== NULL
) {
102 Status
= Aip
->GetInformation (
104 &gAdapterInfoPlatformSecurityGuid
,
106 &InformationBlockSize
108 if (EFI_ERROR (Status
)) {
112 Hsti
= InformationBlock
;
113 if ((Hsti
->Role
== Role
) &&
114 ((ImplementationID
== NULL
) || (StrCmp (ImplementationID
, Hsti
->ImplementationID
) == 0)))
119 FreePool (InformationBlock
);
130 if (HstiData
!= NULL
) {
131 *HstiData
= InformationBlock
;
134 if (HstiSize
!= NULL
) {
135 *HstiSize
= InformationBlockSize
;
142 Return if input HSTI data follows HSTI specification.
144 @param HstiData HSTI data
145 @param HstiSize HSTI size
147 @retval TRUE HSTI data follows HSTI specification.
148 @retval FALSE HSTI data does not follow HSTI specification.
151 InternalHstiIsValidTable (
156 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
160 UINTN ErrorStringSize
;
161 UINTN ErrorStringLength
;
166 // basic check for header
168 if (HstiData
== NULL
) {
169 DEBUG ((DEBUG_ERROR
, "HstiData == NULL\n"));
173 if (HstiSize
< sizeof (ADAPTER_INFO_PLATFORM_SECURITY
)) {
174 DEBUG ((DEBUG_ERROR
, "HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)\n"));
178 if (((HstiSize
- sizeof (ADAPTER_INFO_PLATFORM_SECURITY
)) / 3) < Hsti
->SecurityFeaturesSize
) {
179 DEBUG ((DEBUG_ERROR
, "((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < SecurityFeaturesSize\n"));
186 if (Hsti
->Version
!= PLATFORM_SECURITY_VERSION_VNEXTCS
) {
187 DEBUG ((DEBUG_ERROR
, "Version != PLATFORM_SECURITY_VERSION_VNEXTCS\n"));
194 if ((Hsti
->Role
< PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE
) ||
195 (Hsti
->Role
> PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM
))
197 DEBUG ((DEBUG_ERROR
, "Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE ||\n"));
198 DEBUG ((DEBUG_ERROR
, "Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM\n"));
203 // Check ImplementationID
205 for (Index
= 0; Index
< sizeof (Hsti
->ImplementationID
)/sizeof (Hsti
->ImplementationID
[0]); Index
++) {
206 if (Hsti
->ImplementationID
[Index
] == 0) {
211 if (Index
== sizeof (Hsti
->ImplementationID
)/sizeof (Hsti
->ImplementationID
[0])) {
212 DEBUG ((DEBUG_ERROR
, "ImplementationID has no NUL CHAR\n"));
216 ErrorStringSize
= HstiSize
- sizeof (ADAPTER_INFO_PLATFORM_SECURITY
) - Hsti
->SecurityFeaturesSize
* 3;
217 ErrorString
= (CHAR16
*)((UINTN
)Hsti
+ sizeof (ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 3);
220 // basic check for ErrorString
222 if (ErrorStringSize
== 0) {
223 DEBUG ((DEBUG_ERROR
, "ErrorStringSize == 0\n"));
227 if ((ErrorStringSize
& BIT0
) != 0) {
228 DEBUG ((DEBUG_ERROR
, "(ErrorStringSize & BIT0) != 0\n"));
233 // ErrorString might not be CHAR16 aligned.
235 CopyMem (&ErrorChar
, ErrorString
, sizeof (ErrorChar
));
236 for (ErrorStringLength
= 0; (ErrorChar
!= 0) && (ErrorStringLength
< (ErrorStringSize
/2)); ErrorStringLength
++) {
238 CopyMem (&ErrorChar
, ErrorString
, sizeof (ErrorChar
));
242 // check the length of ErrorString
244 if (ErrorChar
!= 0) {
245 DEBUG ((DEBUG_ERROR
, "ErrorString has no NUL CHAR\n"));
249 if (ErrorStringLength
== (ErrorStringSize
/2)) {
250 DEBUG ((DEBUG_ERROR
, "ErrorString Length incorrect\n"));
258 Publish HSTI table in AIP protocol.
260 One system should have only one PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE.
262 If the Role is NOT PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
263 SecurityFeaturesRequired field will be ignored.
265 @param Hsti HSTI data
266 @param HstiSize HSTI size
268 @retval EFI_SUCCESS The HSTI data is published in AIP protocol.
269 @retval EFI_ALREADY_STARTED There is already HSTI table with Role and ImplementationID published in system.
270 @retval EFI_VOLUME_CORRUPTED The input HSTI data does not follow HSTI specification.
271 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish HSTI data in AIP protocol.
282 HSTI_AIP_PRIVATE_DATA
*HstiAip
;
283 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
285 CHAR16
*ImplementationID
;
286 UINT32 SecurityFeaturesSize
;
287 UINT8
*SecurityFeaturesRequired
;
289 if (!InternalHstiIsValidTable (Hsti
, HstiSize
)) {
290 return EFI_VOLUME_CORRUPTED
;
293 Role
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->Role
;
294 ImplementationID
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->ImplementationID
;
295 Aip
= InternalHstiFindAip (Role
, ImplementationID
, NULL
, NULL
);
297 return EFI_ALREADY_STARTED
;
300 HstiAip
= AllocateZeroPool (sizeof (HSTI_AIP_PRIVATE_DATA
));
301 if (HstiAip
== NULL
) {
302 return EFI_OUT_OF_RESOURCES
;
305 HstiAip
->Hsti
= AllocateCopyPool (HstiSize
, Hsti
);
306 if (HstiAip
->Hsti
== NULL
) {
308 return EFI_OUT_OF_RESOURCES
;
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
);
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
;
323 Status
= gBS
->InstallMultipleProtocolInterfaces (
325 &gEfiAdapterInformationProtocolGuid
,
329 if (EFI_ERROR (Status
)) {
330 FreePool (HstiAip
->Hsti
);
338 Search HSTI table in AIP protocol, and return the data.
339 This API will return the HSTI table with indicated Role and ImplementationID,
340 NULL ImplementationID means to find the first HSTI table with indicated Role.
342 @param Role Role of HSTI data.
343 @param ImplementationID ImplementationID of HSTI data.
344 NULL means find the first one match Role.
345 @param Hsti HSTI data. This buffer is allocated by callee, and it
346 is the responsibility of the caller to free it after
348 @param HstiSize HSTI size
350 @retval EFI_SUCCESS The HSTI data in AIP protocol is returned.
351 @retval EFI_NOT_FOUND There is not HSTI table with the Role and ImplementationID published in system.
357 IN CHAR16
*ImplementationID OPTIONAL
,
362 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
364 Aip
= InternalHstiFindAip (Role
, ImplementationID
, Hsti
, HstiSize
);
366 return EFI_NOT_FOUND
;
373 Record FeaturesVerified in published HSTI table.
374 This API will update the HSTI table with indicated Role and ImplementationID,
375 NULL ImplementationID means to find the first HSTI table with indicated Role.
377 @param Role Role of HSTI data.
378 @param ImplementationID ImplementationID of HSTI data.
379 NULL means find the first one match Role.
380 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
381 @param BitMask Bit mask of FeaturesVerified of HSTI data.
382 @param Set TRUE means to set the FeaturesVerified bit.
383 FALSE means to clear the FeaturesVerified bit.
385 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
386 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
387 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
390 InternalHstiRecordFeaturesVerified (
392 IN CHAR16
*ImplementationID OPTIONAL
,
398 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
399 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
401 UINT8
*SecurityFeaturesVerified
;
404 Aip
= InternalHstiFindAip (Role
, ImplementationID
, (VOID
**)&Hsti
, &HstiSize
);
406 return EFI_NOT_STARTED
;
409 if (ByteIndex
>= Hsti
->SecurityFeaturesSize
) {
410 return EFI_UNSUPPORTED
;
413 SecurityFeaturesVerified
= (UINT8
*)((UINTN
)Hsti
+ sizeof (ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 2);
416 SecurityFeaturesVerified
[ByteIndex
] = (UINT8
)(SecurityFeaturesVerified
[ByteIndex
] | (Bit
));
418 SecurityFeaturesVerified
[ByteIndex
] = (UINT8
)(SecurityFeaturesVerified
[ByteIndex
] & (~Bit
));
421 Status
= Aip
->SetInformation (
423 &gAdapterInfoPlatformSecurityGuid
,
432 Set FeaturesVerified in published HSTI table.
433 This API will update the HSTI table with indicated Role and ImplementationID,
434 NULL ImplementationID means to find the first HSTI table with indicated Role.
436 @param Role Role of HSTI data.
437 @param ImplementationID ImplementationID of HSTI data.
438 NULL means find the first one match Role.
439 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
440 @param BitMask Bit mask of FeaturesVerified of HSTI data.
442 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
443 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
444 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
448 HstiLibSetFeaturesVerified (
450 IN CHAR16
*ImplementationID OPTIONAL
,
455 return InternalHstiRecordFeaturesVerified (
465 Clear FeaturesVerified in published HSTI table.
466 This API will update the HSTI table with indicated Role and ImplementationID,
467 NULL ImplementationID means to find the first HSTI table with indicated Role.
469 @param Role Role of HSTI data.
470 @param ImplementationID ImplementationID of HSTI data.
471 NULL means find the first one match Role.
472 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
473 @param BitMask Bit mask of FeaturesVerified of HSTI data.
475 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
476 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
477 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
481 HstiLibClearFeaturesVerified (
483 IN CHAR16
*ImplementationID OPTIONAL
,
488 return InternalHstiRecordFeaturesVerified (
498 Record ErrorString in published HSTI table.
499 This API will update the HSTI table with indicated Role and ImplementationID,
500 NULL ImplementationID means to find the first HSTI table with indicated Role.
502 @param Role Role of HSTI data.
503 @param ImplementationID ImplementationID of HSTI data.
504 NULL means find the first one match Role.
505 @param ErrorString ErrorString of HSTI data.
506 @param Append TRUE means to append the ErrorString to HSTI table.
507 FALSE means to set the ErrorString in HSTI table.
509 @retval EFI_SUCCESS The ErrorString of HSTI data is published in AIP protocol.
510 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
511 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
514 InternalHstiRecordErrorString (
516 IN CHAR16
*ImplementationID OPTIONAL
,
517 IN CHAR16
*ErrorString
,
521 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
522 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
530 Aip
= InternalHstiFindAip (Role
, ImplementationID
, (VOID
**)&Hsti
, &HstiSize
);
532 return EFI_NOT_STARTED
;
536 Offset
= HstiSize
- sizeof (CHAR16
);
538 Offset
= sizeof (ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 3;
541 StringSize
= StrSize (ErrorString
);
543 NewHstiSize
= Offset
+ StringSize
;
544 NewHsti
= AllocatePool (NewHstiSize
);
545 if (NewHsti
== NULL
) {
546 return EFI_OUT_OF_RESOURCES
;
549 CopyMem (NewHsti
, Hsti
, Offset
);
550 CopyMem ((UINT8
*)NewHsti
+ Offset
, ErrorString
, StringSize
);
552 Status
= Aip
->SetInformation (
554 &gAdapterInfoPlatformSecurityGuid
,
564 Append ErrorString in published HSTI table.
565 This API will update the HSTI table with indicated Role and ImplementationID,
566 NULL ImplementationID means to find the first HSTI table with indicated Role.
568 @param Role Role of HSTI data.
569 @param ImplementationID ImplementationID of HSTI data.
570 NULL means find the first one match Role.
571 @param ErrorString ErrorString of HSTI data.
573 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.
574 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
575 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
579 HstiLibAppendErrorString (
581 IN CHAR16
*ImplementationID OPTIONAL
,
582 IN CHAR16
*ErrorString
585 return InternalHstiRecordErrorString (
594 Set a new ErrorString in published HSTI table.
595 This API will update the HSTI table with indicated Role and ImplementationID,
596 NULL ImplementationID means to find the first HSTI table with indicated Role.
598 @param Role Role of HSTI data.
599 @param ImplementationID ImplementationID of HSTI data.
600 NULL means find the first one match Role.
601 @param ErrorString ErrorString of HSTI data.
603 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.
604 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
605 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
609 HstiLibSetErrorString (
611 IN CHAR16
*ImplementationID OPTIONAL
,
612 IN CHAR16
*ErrorString
615 return InternalHstiRecordErrorString (