3 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Find HSTI table in AIP protocol, and return the data.
18 This API will return the HSTI table with indicated Role and ImplementationID,
19 NULL ImplementationID means to find the first HSTI table with indicated Role.
21 @param Role Role of HSTI data.
22 @param ImplementationID ImplementationID of HSTI data.
23 NULL means find the first one match Role.
24 @param HstiData HSTI data. This buffer is allocated by callee, and it
25 is the responsibility of the caller to free it after
27 @param HstiSize HSTI size
29 @return Aip The AIP protocol having this HSTI.
30 @return NULL There is not HSTI table with the Role and ImplementationID published in system.
35 IN CHAR16
*ImplementationID OPTIONAL
,
36 OUT VOID
**HstiData OPTIONAL
,
37 OUT UINTN
*HstiSize OPTIONAL
41 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
45 EFI_GUID
*InfoTypesBuffer
;
46 UINTN InfoTypesBufferCount
;
48 EFI_ADAPTER_INFORMATION_PROTOCOL
*AipCandidate
;
49 VOID
*InformationBlock
;
50 UINTN InformationBlockSize
;
51 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
53 Status
= gBS
->LocateHandleBuffer (
55 &gEfiAdapterInformationProtocolGuid
,
60 if (EFI_ERROR (Status
)) {
66 InformationBlock
= NULL
;
67 InformationBlockSize
= 0;
68 for (Index
= 0; Index
< NoHandles
; Index
++) {
69 Status
= gBS
->HandleProtocol (
71 &gEfiAdapterInformationProtocolGuid
,
74 if (EFI_ERROR (Status
)) {
81 Status
= Aip
->GetSupportedTypes (
86 if (EFI_ERROR (Status
)) {
91 for (InfoTypesIndex
= 0; InfoTypesIndex
< InfoTypesBufferCount
; InfoTypesIndex
++) {
92 if (CompareGuid (&InfoTypesBuffer
[InfoTypesIndex
], &gAdapterInfoPlatformSecurityGuid
)) {
97 FreePool (InfoTypesBuffer
);
99 if (AipCandidate
== NULL
) {
107 Status
= Aip
->GetInformation (
109 &gAdapterInfoPlatformSecurityGuid
,
111 &InformationBlockSize
113 if (EFI_ERROR (Status
)) {
117 Hsti
= InformationBlock
;
118 if ((Hsti
->Role
== Role
) &&
119 ((ImplementationID
== NULL
) || (StrCmp (ImplementationID
, Hsti
->ImplementationID
) == 0))) {
123 FreePool (InformationBlock
);
133 if (HstiData
!= NULL
) {
134 *HstiData
= InformationBlock
;
136 if (HstiSize
!= NULL
) {
137 *HstiSize
= InformationBlockSize
;
143 Return if input HSTI data follows HSTI specification.
145 @param HstiData HSTI data
146 @param HstiSize HSTI size
148 @retval TRUE HSTI data follows HSTI specification.
149 @retval FALSE HSTI data does not follow HSTI specification.
152 InternalHstiIsValidTable (
157 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
161 UINTN ErrorStringSize
;
162 UINTN ErrorStringLength
;
167 // basic check for header
169 if (HstiData
== NULL
) {
170 DEBUG ((EFI_D_ERROR
, "HstiData == NULL\n"));
173 if (HstiSize
< sizeof(ADAPTER_INFO_PLATFORM_SECURITY
)) {
174 DEBUG ((EFI_D_ERROR
, "HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)\n"));
177 if (((HstiSize
- sizeof(ADAPTER_INFO_PLATFORM_SECURITY
)) / 3) < Hsti
->SecurityFeaturesSize
) {
178 DEBUG ((EFI_D_ERROR
, "((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < SecurityFeaturesSize\n"));
185 if (Hsti
->Version
!= PLATFORM_SECURITY_VERSION_VNEXTCS
) {
186 DEBUG ((EFI_D_ERROR
, "Version != PLATFORM_SECURITY_VERSION_VNEXTCS\n"));
193 if ((Hsti
->Role
< PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE
) ||
194 (Hsti
->Role
> PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM
)) {
195 DEBUG ((EFI_D_ERROR
, "Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE ||\n"));
196 DEBUG ((EFI_D_ERROR
, "Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM\n"));
201 // Check ImplementationID
203 for (Index
= 0; Index
< sizeof(Hsti
->ImplementationID
)/sizeof(Hsti
->ImplementationID
[0]); Index
++) {
204 if (Hsti
->ImplementationID
[Index
] == 0) {
208 if (Index
== sizeof(Hsti
->ImplementationID
)/sizeof(Hsti
->ImplementationID
[0])) {
209 DEBUG ((EFI_D_ERROR
, "ImplementationID is no NUL CHAR\n"));
213 ErrorStringSize
= HstiSize
- sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) - Hsti
->SecurityFeaturesSize
* 3;
214 ErrorString
= (CHAR16
*)((UINTN
)Hsti
+ sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) - Hsti
->SecurityFeaturesSize
* 3);
217 // basic check for ErrorString
219 if (ErrorStringSize
== 0) {
220 DEBUG ((EFI_D_ERROR
, "ErrorStringSize == 0\n"));
223 if ((ErrorStringSize
& BIT0
) != 0) {
224 DEBUG ((EFI_D_ERROR
, "(ErrorStringSize & BIT0) != 0\n"));
229 // ErrorString might not be CHAR16 aligned.
231 CopyMem (&ErrorChar
, ErrorString
, sizeof(ErrorChar
));
232 for (ErrorStringLength
= 0; (ErrorChar
!= 0) && (ErrorStringLength
< (ErrorStringSize
/2)); ErrorStringLength
++) {
234 CopyMem (&ErrorChar
, ErrorString
, sizeof(ErrorChar
));
238 // check the length of ErrorString
240 if (ErrorChar
!= 0) {
241 DEBUG ((EFI_D_ERROR
, "ErrorString has no NUL CHAR\n"));
244 if (ErrorStringLength
== (ErrorStringSize
/2)) {
245 DEBUG ((EFI_D_ERROR
, "ErrorString Length incorrect\n"));
253 Publish HSTI table in AIP protocol.
255 One system should have only one PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE.
257 If the Role is NOT PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
258 SecurityFeaturesRequired field will be ignored.
260 @param Hsti HSTI data
261 @param HstiSize HSTI size
263 @retval EFI_SUCCESS The HSTI data is published in AIP protocol.
264 @retval EFI_ALREADY_STARTED There is already HSTI table with Role and ImplementationID published in system.
265 @retval EFI_VOLUME_CORRUPTED The input HSTI data does not follow HSTI specification.
266 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish HSTI data in AIP protocol.
277 HSTI_AIP_PRIVATE_DATA
*HstiAip
;
278 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
280 CHAR16
*ImplementationID
;
281 UINT32 SecurityFeaturesSize
;
282 UINT8
*SecurityFeaturesRequired
;
284 if (!InternalHstiIsValidTable (Hsti
, HstiSize
)) {
285 return EFI_VOLUME_CORRUPTED
;
288 Role
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->Role
;
289 ImplementationID
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->ImplementationID
;
290 Aip
= InternalHstiFindAip (Role
, ImplementationID
, NULL
, NULL
);
292 return EFI_ALREADY_STARTED
;
295 HstiAip
= AllocateZeroPool (sizeof(HSTI_AIP_PRIVATE_DATA
));
296 if (HstiAip
== NULL
) {
297 return EFI_OUT_OF_RESOURCES
;
299 HstiAip
->Hsti
= AllocateCopyPool (HstiSize
, Hsti
);
300 if (HstiAip
== NULL
) {
302 return EFI_OUT_OF_RESOURCES
;
304 if (Role
!= PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE
) {
305 SecurityFeaturesRequired
= (UINT8
*)HstiAip
->Hsti
+ sizeof(ADAPTER_INFO_PLATFORM_SECURITY
);
306 SecurityFeaturesSize
= ((ADAPTER_INFO_PLATFORM_SECURITY
*)Hsti
)->SecurityFeaturesSize
;
307 ZeroMem (SecurityFeaturesRequired
, SecurityFeaturesSize
);
310 HstiAip
->Signature
= HSTI_AIP_PRIVATE_SIGNATURE
;
311 CopyMem (&HstiAip
->Aip
, &mAdapterInformationProtocol
, sizeof(EFI_ADAPTER_INFORMATION_PROTOCOL
));
312 HstiAip
->HstiSize
= HstiSize
;
313 HstiAip
->HstiMaxSize
= HstiSize
;
316 Status
= gBS
->InstallMultipleProtocolInterfaces (
318 &gEfiAdapterInformationProtocolGuid
,
322 if (EFI_ERROR (Status
)) {
323 FreePool (HstiAip
->Hsti
);
331 Search HSTI table in AIP protocol, and return the data.
332 This API will return the HSTI table with indicated Role and ImplementationID,
333 NULL ImplementationID means to find the first HSTI table with indicated Role.
335 @param Role Role of HSTI data.
336 @param ImplementationID ImplementationID of HSTI data.
337 NULL means find the first one match Role.
338 @param Hsti HSTI data. This buffer is allocated by callee, and it
339 is the responsibility of the caller to free it after
341 @param HstiSize HSTI size
343 @retval EFI_SUCCESS The HSTI data in AIP protocol is returned.
344 @retval EFI_NOT_FOUND There is not HSTI table with the Role and ImplementationID published in system.
350 IN CHAR16
*ImplementationID OPTIONAL
,
355 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
357 Aip
= InternalHstiFindAip (Role
, ImplementationID
, Hsti
, HstiSize
);
359 return EFI_NOT_FOUND
;
365 Record FeaturesVerified in published HSTI table.
366 This API will update the HSTI table with indicated Role and ImplementationID,
367 NULL ImplementationID means to find the first HSTI table with indicated Role.
369 @param Role Role of HSTI data.
370 @param ImplementationID ImplementationID of HSTI data.
371 NULL means find the first one match Role.
372 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
373 @param BitMask Bit mask of FeaturesVerified of HSTI data.
374 @param Set TRUE means to set the FeaturesVerified bit.
375 FALSE means to clear the FeaturesVerified bit.
377 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
378 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
379 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
382 InternalHstiRecordFeaturesVerified (
384 IN CHAR16
*ImplementationID
, OPTIONAL
390 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
391 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
393 UINT8
*SecurityFeaturesVerified
;
396 Aip
= InternalHstiFindAip (Role
, ImplementationID
, (VOID
**)&Hsti
, &HstiSize
);
398 return EFI_NOT_STARTED
;
401 if (ByteIndex
>= Hsti
->SecurityFeaturesSize
) {
402 return EFI_UNSUPPORTED
;
405 SecurityFeaturesVerified
= (UINT8
*)((UINTN
)Hsti
+ sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 2);
408 SecurityFeaturesVerified
[ByteIndex
] = (UINT8
)(SecurityFeaturesVerified
[ByteIndex
] | (Bit
));
410 SecurityFeaturesVerified
[ByteIndex
] = (UINT8
)(SecurityFeaturesVerified
[ByteIndex
] & (~Bit
));
413 Status
= Aip
->SetInformation (
415 &gAdapterInfoPlatformSecurityGuid
,
423 Set FeaturesVerified in published HSTI table.
424 This API will update the HSTI table with indicated Role and ImplementationID,
425 NULL ImplementationID means to find the first HSTI table with indicated Role.
427 @param Role Role of HSTI data.
428 @param ImplementationID ImplementationID of HSTI data.
429 NULL means find the first one match Role.
430 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
431 @param BitMask Bit mask of FeaturesVerified of HSTI data.
433 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
434 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
435 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
439 HstiLibSetFeaturesVerified (
441 IN CHAR16
*ImplementationID
, OPTIONAL
446 return InternalHstiRecordFeaturesVerified (
456 Clear FeaturesVerified in published HSTI table.
457 This API will update the HSTI table with indicated Role and ImplementationID,
458 NULL ImplementationID means to find the first HSTI table with indicated Role.
460 @param Role Role of HSTI data.
461 @param ImplementationID ImplementationID of HSTI data.
462 NULL means find the first one match Role.
463 @param ByteIndex Byte index of FeaturesVerified of HSTI data.
464 @param BitMask Bit mask of FeaturesVerified of HSTI data.
466 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.
467 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
468 @retval EFI_UNSUPPORTED The ByteIndex is invalid.
472 HstiLibClearFeaturesVerified (
474 IN CHAR16
*ImplementationID
, OPTIONAL
479 return InternalHstiRecordFeaturesVerified (
489 Record ErrorString in published HSTI table.
490 This API will update the HSTI table with indicated Role and ImplementationID,
491 NULL ImplementationID means to find the first HSTI table with indicated Role.
493 @param Role Role of HSTI data.
494 @param ImplementationID ImplementationID of HSTI data.
495 NULL means find the first one match Role.
496 @param ErrorString ErrorString of HSTI data.
497 @param Append TRUE means to append the ErrorString to HSTI table.
498 FALSE means to set the ErrorString in HSTI table.
500 @retval EFI_SUCCESS The ErrorString of HSTI data is published in AIP protocol.
501 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
502 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
505 InternalHstiRecordErrorString (
507 IN CHAR16
*ImplementationID
, OPTIONAL
508 IN CHAR16
*ErrorString
,
512 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
513 ADAPTER_INFO_PLATFORM_SECURITY
*Hsti
;
521 Aip
= InternalHstiFindAip (Role
, ImplementationID
, (VOID
**)&Hsti
, &HstiSize
);
523 return EFI_NOT_STARTED
;
527 Offset
= HstiSize
- sizeof(CHAR16
);
529 Offset
= sizeof(ADAPTER_INFO_PLATFORM_SECURITY
) + Hsti
->SecurityFeaturesSize
* 3;
531 StringSize
= StrSize (ErrorString
);
533 NewHstiSize
= Offset
+ StringSize
;
534 NewHsti
= AllocatePool (NewHstiSize
);
535 if (NewHsti
== NULL
) {
536 return EFI_OUT_OF_RESOURCES
;
539 CopyMem (NewHsti
, Hsti
, Offset
);
540 CopyMem ((UINT8
*)NewHsti
+ Offset
, ErrorString
, StringSize
);
542 Status
= Aip
->SetInformation (
544 &gAdapterInfoPlatformSecurityGuid
,
552 Append ErrorString in published HSTI table.
553 This API will update the HSTI table with indicated Role and ImplementationID,
554 NULL ImplementationID means to find the first HSTI table with indicated Role.
556 @param Role Role of HSTI data.
557 @param ImplementationID ImplementationID of HSTI data.
558 NULL means find the first one match Role.
559 @param ErrorString ErrorString of HSTI data.
561 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.
562 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
563 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
567 HstiLibAppendErrorString (
569 IN CHAR16
*ImplementationID
, OPTIONAL
570 IN CHAR16
*ErrorString
573 return InternalHstiRecordErrorString (
582 Set a new ErrorString in published HSTI table.
583 This API will update the HSTI table with indicated Role and ImplementationID,
584 NULL ImplementationID means to find the first HSTI table with indicated Role.
586 @param Role Role of HSTI data.
587 @param ImplementationID ImplementationID of HSTI data.
588 NULL means find the first one match Role.
589 @param ErrorString ErrorString of HSTI data.
591 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.
592 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.
593 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.
597 HstiLibSetErrorString (
599 IN CHAR16
*ImplementationID
, OPTIONAL
600 IN CHAR16
*ErrorString
603 return InternalHstiRecordErrorString (