42#define TPMA_CC_COMMANDINDEX_MASK 0x2000FFFF
72 IN TPM_CAP Capability,
74 IN UINT32 PropertyCount,
75 OUT TPMI_YES_NO *MoreData,
82 UINT32 SendBufferSize;
83 UINT32 RecvBufferSize;
88 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_NO_SESSIONS);
89 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_GetCapability);
93 SendBuffer.PropertyCount =
SwapBytes32 (PropertyCount);
95 SendBufferSize = (UINT32)
sizeof (SendBuffer);
96 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
101 RecvBufferSize =
sizeof (RecvBuffer);
102 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
103 if (EFI_ERROR (Status)) {
108 return EFI_DEVICE_ERROR;
114 if (
SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
115 DEBUG ((DEBUG_ERROR,
"Tpm2GetCapability: Response Code error! 0x%08x\r\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
116 return EFI_DEVICE_ERROR;
122 *MoreData = RecvBuffer.MoreData;
148 TPMI_YES_NO MoreData;
152 TPM_CAP_TPM_PROPERTIES,
153 TPM_PT_FAMILY_INDICATOR,
158 if (EFI_ERROR (Status)) {
162 CopyMem (Family, &TpmCap.data.tpmProperties.tpmProperty->value, 4);
180 OUT UINT32 *ManufactureId
184 TPMI_YES_NO MoreData;
188 TPM_CAP_TPM_PROPERTIES,
194 if (EFI_ERROR (Status)) {
198 *ManufactureId = TpmCap.data.tpmProperties.tpmProperty->value;
217 OUT UINT32 *FirmwareVersion1,
218 OUT UINT32 *FirmwareVersion2
222 TPMI_YES_NO MoreData;
226 TPM_CAP_TPM_PROPERTIES,
227 TPM_PT_FIRMWARE_VERSION_1,
232 if (EFI_ERROR (Status)) {
236 *FirmwareVersion1 =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
239 TPM_CAP_TPM_PROPERTIES,
240 TPM_PT_FIRMWARE_VERSION_2,
245 if (EFI_ERROR (Status)) {
249 *FirmwareVersion2 =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
268 OUT UINT32 *MaxCommandSize,
269 OUT UINT32 *MaxResponseSize
273 TPMI_YES_NO MoreData;
277 TPM_CAP_TPM_PROPERTIES,
278 TPM_PT_MAX_COMMAND_SIZE,
283 if (EFI_ERROR (Status)) {
287 *MaxCommandSize =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
290 TPM_CAP_TPM_PROPERTIES,
291 TPM_PT_MAX_RESPONSE_SIZE,
296 if (EFI_ERROR (Status)) {
300 *MaxResponseSize =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
322 TPMI_YES_NO MoreData;
333 if (EFI_ERROR (Status)) {
340 if (AlgList->count > MAX_CAP_ALGS) {
341 DEBUG ((DEBUG_ERROR,
"Tpm2GetCapabilitySupportedAlg - AlgList->count error %x\n", AlgList->count));
342 return EFI_DEVICE_ERROR;
345 for (Index = 0; Index < AlgList->count; Index++) {
346 AlgList->algProperties[Index].alg =
SwapBytes16 (AlgList->algProperties[Index].alg);
366 OUT UINT32 *LockoutCounter
370 TPMI_YES_NO MoreData;
374 TPM_CAP_TPM_PROPERTIES,
375 TPM_PT_LOCKOUT_COUNTER,
380 if (EFI_ERROR (Status)) {
384 *LockoutCounter =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
402 OUT UINT32 *LockoutInterval
406 TPMI_YES_NO MoreData;
410 TPM_CAP_TPM_PROPERTIES,
411 TPM_PT_LOCKOUT_INTERVAL,
416 if (EFI_ERROR (Status)) {
420 *LockoutInterval =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
439 OUT UINT32 *InputBufferSize
443 TPMI_YES_NO MoreData;
447 TPM_CAP_TPM_PROPERTIES,
453 if (EFI_ERROR (Status)) {
457 *InputBufferSize =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
479 TPMI_YES_NO MoreData;
490 if (EFI_ERROR (Status)) {
494 Pcrs->count =
SwapBytes32 (TpmCap.data.assignedPCR.count);
495 if (Pcrs->count > HASH_COUNT) {
496 DEBUG ((DEBUG_ERROR,
"Tpm2GetCapabilityPcrs - Pcrs->count error %x\n", Pcrs->count));
497 return EFI_DEVICE_ERROR;
500 for (Index = 0; Index < Pcrs->count; Index++) {
501 Pcrs->pcrSelections[Index].hash =
SwapBytes16 (TpmCap.data.assignedPCR.pcrSelections[Index].hash);
502 Pcrs->pcrSelections[Index].sizeofSelect = TpmCap.data.assignedPCR.pcrSelections[Index].sizeofSelect;
503 if (Pcrs->pcrSelections[Index].sizeofSelect > PCR_SELECT_MAX) {
504 DEBUG ((DEBUG_ERROR,
"Tpm2GetCapabilityPcrs - sizeofSelect error %x\n", Pcrs->pcrSelections[Index].sizeofSelect));
505 return EFI_DEVICE_ERROR;
508 CopyMem (Pcrs->pcrSelections[Index].pcrSelect, TpmCap.data.assignedPCR.pcrSelections[Index].pcrSelect, Pcrs->pcrSelections[Index].sizeofSelect);
528 OUT UINT32 *TpmHashAlgorithmBitmap,
529 OUT UINT32 *ActivePcrBanks
535 UINT8 ActivePcrBankCount;
541 DEBUG ((DEBUG_INFO,
"Supported PCRs - Count = %08x\n", Pcrs.count));
542 ActivePcrBankCount = 0;
546 if (EFI_ERROR (Status)) {
547 DEBUG ((DEBUG_ERROR,
"GetSupportedAndActivePcrs - Tpm2GetCapabilityPcrs fail!\n"));
548 *TpmHashAlgorithmBitmap = HASH_ALG_SHA1;
549 *ActivePcrBanks = HASH_ALG_SHA1;
550 ActivePcrBankCount = 1;
557 *TpmHashAlgorithmBitmap = 0;
559 for (Index = 0; Index < Pcrs.count; Index++) {
560 switch (Pcrs.pcrSelections[Index].hash) {
562 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA1 present.\n"));
563 *TpmHashAlgorithmBitmap |= HASH_ALG_SHA1;
564 if (!
IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
565 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA1 active.\n"));
566 *ActivePcrBanks |= HASH_ALG_SHA1;
567 ActivePcrBankCount++;
572 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA256 present.\n"));
573 *TpmHashAlgorithmBitmap |= HASH_ALG_SHA256;
574 if (!
IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
575 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA256 active.\n"));
576 *ActivePcrBanks |= HASH_ALG_SHA256;
577 ActivePcrBankCount++;
582 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA384 present.\n"));
583 *TpmHashAlgorithmBitmap |= HASH_ALG_SHA384;
584 if (!
IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
585 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA384 active.\n"));
586 *ActivePcrBanks |= HASH_ALG_SHA384;
587 ActivePcrBankCount++;
592 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA512 present.\n"));
593 *TpmHashAlgorithmBitmap |= HASH_ALG_SHA512;
594 if (!
IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
595 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SHA512 active.\n"));
596 *ActivePcrBanks |= HASH_ALG_SHA512;
597 ActivePcrBankCount++;
601 case TPM_ALG_SM3_256:
602 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SM3_256 present.\n"));
603 *TpmHashAlgorithmBitmap |= HASH_ALG_SM3_256;
604 if (!
IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
605 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - HASH_ALG_SM3_256 active.\n"));
606 *ActivePcrBanks |= HASH_ALG_SM3_256;
607 ActivePcrBankCount++;
612 DEBUG ((DEBUG_VERBOSE,
"GetSupportedAndActivePcrs - Unsupported bank 0x%04x.\n", Pcrs.pcrSelections[Index].hash));
619 DEBUG ((DEBUG_INFO,
"GetSupportedAndActivePcrs - Count = %08x\n", ActivePcrBankCount));
636 OUT UINT32 *AlgorithmSet
640 TPMI_YES_NO MoreData;
644 TPM_CAP_TPM_PROPERTIES,
645 TPM_PT_ALGORITHM_SET,
650 if (EFI_ERROR (Status)) {
654 *AlgorithmSet =
SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);
672 OUT BOOLEAN *IsCmdImpl
676 TPMI_YES_NO MoreData;
687 if (EFI_ERROR (Status)) {
691 CopyMem (&Attribute, &TpmCap.data.command.commandAttributes[0], sizeof (UINT32));
692 *IsCmdImpl = (Command == (
SwapBytes32 (Attribute) & TPMA_CC_COMMANDINDEX_MASK));
714 UINT32 SendBufferSize;
715 UINT32 RecvBufferSize;
721 SendBuffer.Header.tag =
SwapBytes16 (TPM_ST_NO_SESSIONS);
722 SendBuffer.Header.commandCode =
SwapBytes32 (TPM_CC_TestParms);
724 Buffer = (UINT8 *)&SendBuffer.Parameters;
726 Buffer +=
sizeof (UINT16);
727 switch (Parameters->type) {
728 case TPM_ALG_KEYEDHASH:
730 Buffer +=
sizeof (UINT16);
731 switch (Parameters->parameters.keyedHashDetail.scheme.scheme) {
734 Buffer +=
sizeof (UINT16);
738 Buffer +=
sizeof (UINT16);
740 Buffer +=
sizeof (UINT16);
743 return EFI_INVALID_PARAMETER;
747 case TPM_ALG_SYMCIPHER:
749 Buffer +=
sizeof (UINT16);
750 switch (Parameters->parameters.symDetail.algorithm) {
753 Buffer +=
sizeof (UINT16);
755 Buffer +=
sizeof (UINT16);
759 Buffer +=
sizeof (UINT16);
761 Buffer +=
sizeof (UINT16);
765 Buffer +=
sizeof (UINT16);
770 return EFI_INVALID_PARAMETER;
776 Buffer +=
sizeof (UINT16);
777 switch (Parameters->parameters.rsaDetail.symmetric.algorithm) {
780 Buffer +=
sizeof (UINT16);
782 Buffer +=
sizeof (UINT16);
786 Buffer +=
sizeof (UINT16);
788 Buffer +=
sizeof (UINT16);
793 return EFI_INVALID_PARAMETER;
797 Buffer +=
sizeof (UINT16);
798 switch (Parameters->parameters.rsaDetail.scheme.scheme) {
801 Buffer +=
sizeof (UINT16);
805 Buffer +=
sizeof (UINT16);
811 Buffer +=
sizeof (UINT16);
816 return EFI_INVALID_PARAMETER;
820 Buffer +=
sizeof (UINT16);
822 Buffer +=
sizeof (UINT32);
826 Buffer +=
sizeof (UINT16);
827 switch (Parameters->parameters.eccDetail.symmetric.algorithm) {
830 Buffer +=
sizeof (UINT16);
832 Buffer +=
sizeof (UINT16);
836 Buffer +=
sizeof (UINT16);
838 Buffer +=
sizeof (UINT16);
843 return EFI_INVALID_PARAMETER;
847 Buffer +=
sizeof (UINT16);
848 switch (Parameters->parameters.eccDetail.scheme.scheme) {
851 Buffer +=
sizeof (UINT16);
855 Buffer +=
sizeof (UINT16);
857 case TPM_ALG_ECSCHNORR:
859 Buffer +=
sizeof (UINT16);
866 return EFI_INVALID_PARAMETER;
870 Buffer +=
sizeof (UINT16);
872 Buffer +=
sizeof (UINT16);
873 switch (Parameters->parameters.eccDetail.kdf.scheme) {
876 Buffer +=
sizeof (UINT16);
878 case TPM_ALG_KDF1_SP800_108:
880 Buffer +=
sizeof (UINT16);
882 case TPM_ALG_KDF1_SP800_56a:
884 Buffer +=
sizeof (UINT16);
888 Buffer +=
sizeof (UINT16);
893 return EFI_INVALID_PARAMETER;
898 return EFI_INVALID_PARAMETER;
901 SendBufferSize = (UINT32)((
UINTN)Buffer - (
UINTN)&SendBuffer);
902 SendBuffer.Header.paramSize =
SwapBytes32 (SendBufferSize);
907 RecvBufferSize =
sizeof (RecvBuffer);
908 Status =
Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
909 if (EFI_ERROR (Status)) {
914 DEBUG ((DEBUG_ERROR,
"Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize));
915 return EFI_DEVICE_ERROR;
918 if (
SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
919 DEBUG ((DEBUG_ERROR,
"Tpm2TestParms - responseCode - %x\n",
SwapBytes32 (RecvBuffer.Header.responseCode)));
920 return EFI_UNSUPPORTED;
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI IsZeroBuffer(IN CONST VOID *Buffer, IN UINTN Length)
#define DEBUG(Expression)
#define TPM_ALG_RSA
The RSA algorithm.
#define TPM_ALG_XOR
XOR using the rolling nonces.
#define TPM_ALG_MGF1
The XOR algorithm using MGF1 to create a string the size of the encrypted block.
#define TPM_ALG_HMAC
The RFC 2104 HMAC algorithm.
EFI_STATUS EFIAPI Tpm2GetCapabilitySupportedAndActivePcrs(OUT UINT32 *TpmHashAlgorithmBitmap, OUT UINT32 *ActivePcrBanks)
EFI_STATUS EFIAPI Tpm2GetCapabilitySupportedAlg(OUT TPML_ALG_PROPERTY *AlgList)
EFI_STATUS EFIAPI Tpm2GetCapabilityAlgorithmSet(OUT UINT32 *AlgorithmSet)
EFI_STATUS EFIAPI Tpm2GetCapabilityIsCommandImplemented(IN TPM_CC Command, OUT BOOLEAN *IsCmdImpl)
EFI_STATUS EFIAPI Tpm2GetCapability(IN TPM_CAP Capability, IN UINT32 Property, IN UINT32 PropertyCount, OUT TPMI_YES_NO *MoreData, OUT TPMS_CAPABILITY_DATA *CapabilityData)
EFI_STATUS EFIAPI Tpm2GetCapabilityLockoutInterval(OUT UINT32 *LockoutInterval)
EFI_STATUS EFIAPI Tpm2GetCapabilityFamily(OUT CHAR8 *Family)
EFI_STATUS EFIAPI Tpm2GetCapabilityFirmwareVersion(OUT UINT32 *FirmwareVersion1, OUT UINT32 *FirmwareVersion2)
EFI_STATUS EFIAPI Tpm2GetCapabilityMaxCommandResponseSize(OUT UINT32 *MaxCommandSize, OUT UINT32 *MaxResponseSize)
EFI_STATUS EFIAPI Tpm2GetCapabilityManufactureID(OUT UINT32 *ManufactureId)
EFI_STATUS EFIAPI Tpm2TestParms(IN TPMT_PUBLIC_PARMS *Parameters)
EFI_STATUS EFIAPI Tpm2GetCapabilityInputBufferSize(OUT UINT32 *InputBufferSize)
EFI_STATUS EFIAPI Tpm2GetCapabilityPcrs(OUT TPML_PCR_SELECTION *Pcrs)
EFI_STATUS EFIAPI Tpm2GetCapabilityLockoutCounter(OUT UINT32 *LockoutCounter)
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)