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
)) {
85 for (InfoTypesIndex
= 0; InfoTypesIndex
< InfoTypesBufferCount
; InfoTypesIndex
++) {
86 if (CompareGuid (&InfoTypesBuffer
[InfoTypesIndex
], &gAdapterInfoPlatformSecurityGuid
)) {
91 FreePool (InfoTypesBuffer
);
93 if (AipCandidate
== NULL
) {
101 Status
= Aip
->GetInformation (
103 &gAdapterInfoPlatformSecurityGuid
,
105 &InformationBlockSize
107 if (EFI_ERROR (Status
)) {
111 Hsti
= InformationBlock
;
112 if ((Hsti
->Role
== Role
) &&
113 ((ImplementationID
== NULL
) || (StrCmp (ImplementationID
, Hsti
->ImplementationID
) == 0))) {
117 FreePool (InformationBlock
);
127 if (HstiData
!= NULL
) {
128 *HstiData
= InformationBlock
;
130 if (HstiSize
!= NULL
) {
131 *HstiSize
= InformationBlockSize
;
137 Return if input HSTI data follows HSTI specification.
139 @param HstiData HSTI data
140 @param HstiSize HSTI size
142 @retval TRUE HSTI data follows HSTI specification.
143 @retval FALSE HSTI data does not follow HSTI specification.
146 InternalHstiIsValidTable (
151 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
155 UINTN ErrorStringSize
;
156 UINTN ErrorStringLength
;
161 // basic check for header
163 if (HstiData
== NULL
) {
164 DEBUG ((EFI_D_ERROR
, "HstiData == NULL\n"));
167 if (HstiSize
< sizeof(ADAPTER_INFO_PLATFORM_SECURITY
)) {
168 DEBUG ((EFI_D_ERROR
, "HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)\n"));
171 if (((HstiSize
- sizeof(ADAPTER_INFO_PLATFORM_SECURITY
)) / 3) < Hsti
->SecurityFeaturesSize
) {
172 DEBUG ((EFI_D_ERROR
, "((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < SecurityFeaturesSize\n"));
179 if (Hsti
->Version
!= PLATFORM_SECURITY_VERSION_VNEXTCS
) {
180 DEBUG ((EFI_D_ERROR
, "Version != PLATFORM_SECURITY_VERSION_VNEXTCS\n"));
187 if ((Hsti
->Role
< PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE
) ||
188 (Hsti
->Role
> PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM
)) {
189 DEBUG ((EFI_D_ERROR
, "Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE ||\n"));
190 DEBUG ((EFI_D_ERROR
, "Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM\n"));
195 // Check ImplementationID
197 for (Index
= 0; Index
< sizeof(Hsti
->ImplementationID
)/sizeof(Hsti
->ImplementationID
[0]); Index
++) {
198 if (Hsti
->ImplementationID
[Index
] == 0) {
202 if (Index
== sizeof(Hsti
->ImplementationID
)/sizeof(Hsti
->ImplementationID
[0])) {
203 DEBUG ((EFI_D_ERROR
, "ImplementationID has no NUL CHAR\n"));
207 ErrorStringSize
= HstiSize
- sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) - Hsti
->SecurityFeaturesSize
* 3;
208 ErrorString
= (CHAR16
*)((UINTN
)Hsti
+ sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 3);
211 // basic check for ErrorString
213 if (ErrorStringSize
== 0) {
214 DEBUG ((EFI_D_ERROR
, "ErrorStringSize == 0\n"));
217 if ((ErrorStringSize
& BIT0
) != 0) {
218 DEBUG ((EFI_D_ERROR
, "(ErrorStringSize & BIT0) != 0\n"));
223 // ErrorString might not be CHAR16 aligned.
225 CopyMem (&ErrorChar
, ErrorString
, sizeof(ErrorChar
));
226 for (ErrorStringLength
= 0; (ErrorChar
!= 0) && (ErrorStringLength
< (ErrorStringSize
/2)); ErrorStringLength
++) {
228 CopyMem (&ErrorChar
, ErrorString
, sizeof(ErrorChar
));
232 // check the length of ErrorString
234 if (ErrorChar
!= 0) {
235 DEBUG ((EFI_D_ERROR
, "ErrorString has no NUL CHAR\n"));
238 if (ErrorStringLength
== (ErrorStringSize
/2)) {
239 DEBUG ((EFI_D_ERROR
, "ErrorString Length incorrect\n"));
247 Publish HSTI table in AIP protocol.
249 One system should have only one PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE.
251 If the Role is NOT PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
252 SecurityFeaturesRequired field will be ignored.
254 @param Hsti HSTI data
255 @param HstiSize HSTI size
257 @retval EFI_SUCCESS The HSTI data is published in AIP protocol.
258 @retval EFI_ALREADY_STARTED There is already HSTI table with Role and ImplementationID published in system.
259 @retval EFI_VOLUME_CORRUPTED The input HSTI data does not follow HSTI specification.
260 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish HSTI data in AIP protocol.
271 HSTI_AIP_PRIVATE_DATA
*HstiAip
;
272 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
274 CHAR16
*ImplementationID
;
275 UINT32 SecurityFeaturesSize
;
276 UINT8
*SecurityFeaturesRequired
;
278 if (!InternalHstiIsValidTable (Hsti
, HstiSize
)) {
279 return EFI_VOLUME_CORRUPTED
;
282 Role
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->Role
;
283 ImplementationID
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->ImplementationID
;
284 Aip
= InternalHstiFindAip (Role
, ImplementationID
, NULL
, NULL
);
286 return EFI_ALREADY_STARTED
;
289 HstiAip
= AllocateZeroPool (sizeof(HSTI_AIP_PRIVATE_DATA
));
290 if (HstiAip
== NULL
) {
291 return EFI_OUT_OF_RESOURCES
;
293 HstiAip
->Hsti
= AllocateCopyPool (HstiSize
, Hsti
);
294 if (HstiAip
->Hsti
== NULL
) {
296 return EFI_OUT_OF_RESOURCES
;
298 if (Role
!= PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE
) {
299 SecurityFeaturesRequired
= (UINT8
*)HstiAip
->Hsti
+ sizeof(ADAPTER_INFO_PLATFORM_SECURITY
);
300 SecurityFeaturesSize
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->SecurityFeaturesSize
;
301 ZeroMem (SecurityFeaturesRequired
, SecurityFeaturesSize
);
304 HstiAip
->Signature
= HSTI_AIP_PRIVATE_SIGNATURE
;
305 CopyMem (&HstiAip
->Aip
, &mAdapterInformationProtocol
, sizeof(EFI_ADAPTER_INFORMATION_PROTOCOL
));
306 HstiAip
->HstiSize
= HstiSize
;
307 HstiAip
->HstiMaxSize
= HstiSize
;
310 Status
= gBS
->InstallMultipleProtocolInterfaces (
312 &gEfiAdapterInformationProtocolGuid
,
316 if (EFI_ERROR (Status
)) {
317 FreePool (HstiAip
->Hsti
);
325 Search HSTI table in AIP protocol, and return the data.
326 This API will return the HSTI table with indicated Role and ImplementationID,
327 NULL ImplementationID means to find the first HSTI table with indicated Role.
329 @param Role Role of HSTI data.
330 @param ImplementationID ImplementationID of HSTI data.
331 NULL means find the first one match Role.
332 @param Hsti HSTI data. This buffer is allocated by callee, and it
333 is the responsibility of the caller to free it after
335 @param HstiSize HSTI size
337 @retval EFI_SUCCESS The HSTI data in AIP protocol is returned.
338 @retval EFI_NOT_FOUND There is not HSTI table with the Role and ImplementationID published in system.
344 IN CHAR16
*ImplementationID OPTIONAL
,
349 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
351 Aip
= InternalHstiFindAip (Role
, ImplementationID
, Hsti
, HstiSize
);
353 return EFI_NOT_FOUND
;
359 Record FeaturesVerified in published HSTI table.
360 This API will update the HSTI table with indicated Role and ImplementationID,
361 NULL ImplementationID means to find the first HSTI table with indicated Role.
363 @param Role Role of HSTI data.
364 @param ImplementationID ImplementationID of HSTI data.
365 NULL means find the first one match Role.
366 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
367 @param BitMask Bit mask of FeaturesVerified of HSTI data.
368 @param Set TRUE means to set the FeaturesVerified bit.
369 FALSE means to clear the FeaturesVerified bit.
371 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
372 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
373 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
376 InternalHstiRecordFeaturesVerified (
378 IN CHAR16
*ImplementationID
, OPTIONAL
384 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
385 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
387 UINT8
*SecurityFeaturesVerified
;
390 Aip
= InternalHstiFindAip (Role
, ImplementationID
, (VOID
**)&Hsti
, &HstiSize
);
392 return EFI_NOT_STARTED
;
395 if (ByteIndex
>= Hsti
->SecurityFeaturesSize
) {
396 return EFI_UNSUPPORTED
;
399 SecurityFeaturesVerified
= (UINT8
*)((UINTN
)Hsti
+ sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 2);
402 SecurityFeaturesVerified
[ByteIndex
] = (UINT8
)(SecurityFeaturesVerified
[ByteIndex
] | (Bit
));
404 SecurityFeaturesVerified
[ByteIndex
] = (UINT8
)(SecurityFeaturesVerified
[ByteIndex
] & (~Bit
));
407 Status
= Aip
->SetInformation (
409 &gAdapterInfoPlatformSecurityGuid
,
418 Set FeaturesVerified in published HSTI table.
419 This API will update the HSTI table with indicated Role and ImplementationID,
420 NULL ImplementationID means to find the first HSTI table with indicated Role.
422 @param Role Role of HSTI data.
423 @param ImplementationID ImplementationID of HSTI data.
424 NULL means find the first one match Role.
425 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
426 @param BitMask Bit mask of FeaturesVerified of HSTI data.
428 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
429 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
430 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
434 HstiLibSetFeaturesVerified (
436 IN CHAR16
*ImplementationID
, OPTIONAL
441 return InternalHstiRecordFeaturesVerified (
451 Clear FeaturesVerified in published HSTI table.
452 This API will update the HSTI table with indicated Role and ImplementationID,
453 NULL ImplementationID means to find the first HSTI table with indicated Role.
455 @param Role Role of HSTI data.
456 @param ImplementationID ImplementationID of HSTI data.
457 NULL means find the first one match Role.
458 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
459 @param BitMask Bit mask of FeaturesVerified of HSTI data.
461 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
462 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
463 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
467 HstiLibClearFeaturesVerified (
469 IN CHAR16
*ImplementationID
, OPTIONAL
474 return InternalHstiRecordFeaturesVerified (
484 Record ErrorString in published HSTI table.
485 This API will update the HSTI table with indicated Role and ImplementationID,
486 NULL ImplementationID means to find the first HSTI table with indicated Role.
488 @param Role Role of HSTI data.
489 @param ImplementationID ImplementationID of HSTI data.
490 NULL means find the first one match Role.
491 @param ErrorString ErrorString of HSTI data.
492 @param Append TRUE means to append the ErrorString to HSTI table.
493 FALSE means to set the ErrorString in HSTI table.
495 @retval EFI_SUCCESS The ErrorString of HSTI data is published in AIP protocol.
496 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
497 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
500 InternalHstiRecordErrorString (
502 IN CHAR16
*ImplementationID
, OPTIONAL
503 IN CHAR16
*ErrorString
,
507 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
508 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
516 Aip
= InternalHstiFindAip (Role
, ImplementationID
, (VOID
**)&Hsti
, &HstiSize
);
518 return EFI_NOT_STARTED
;
522 Offset
= HstiSize
- sizeof(CHAR16
);
524 Offset
= sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 3;
526 StringSize
= StrSize (ErrorString
);
528 NewHstiSize
= Offset
+ StringSize
;
529 NewHsti
= AllocatePool (NewHstiSize
);
530 if (NewHsti
== NULL
) {
531 return EFI_OUT_OF_RESOURCES
;
534 CopyMem (NewHsti
, Hsti
, Offset
);
535 CopyMem ((UINT8
*)NewHsti
+ Offset
, ErrorString
, StringSize
);
537 Status
= Aip
->SetInformation (
539 &gAdapterInfoPlatformSecurityGuid
,
549 Append ErrorString in published HSTI table.
550 This API will update the HSTI table with indicated Role and ImplementationID,
551 NULL ImplementationID means to find the first HSTI table with indicated Role.
553 @param Role Role of HSTI data.
554 @param ImplementationID ImplementationID of HSTI data.
555 NULL means find the first one match Role.
556 @param ErrorString ErrorString of HSTI data.
558 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.
559 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
560 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
564 HstiLibAppendErrorString (
566 IN CHAR16
*ImplementationID
, OPTIONAL
567 IN CHAR16
*ErrorString
570 return InternalHstiRecordErrorString (
579 Set a new ErrorString in published HSTI table.
580 This API will update the HSTI table with indicated Role and ImplementationID,
581 NULL ImplementationID means to find the first HSTI table with indicated Role.
583 @param Role Role of HSTI data.
584 @param ImplementationID ImplementationID of HSTI data.
585 NULL means find the first one match Role.
586 @param ErrorString ErrorString of HSTI data.
588 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.
589 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
590 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
594 HstiLibSetErrorString (
596 IN CHAR16
*ImplementationID
, OPTIONAL
597 IN CHAR16
*ErrorString
600 return InternalHstiRecordErrorString (