]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
SecurityPkg/Tpm2CommandLib: add a new function
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Capability.c
index 85b11c77158f012fbec9e4cdd25484e2b54742b4..17c0c3a15158d26fb51abf57a39a3840ba1ee63f 100644 (file)
@@ -39,6 +39,8 @@ typedef struct {
 \r
 #pragma pack()\r
 \r
+#define TPMA_CC_COMMANDINDEX_MASK  0x2000FFFF\r
+\r
 /**\r
   This command returns various information regarding the TPM and its current state.\r
 \r
@@ -628,6 +630,44 @@ Tpm2GetCapabilityAlgorithmSet (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  This function will query if the command is supported.\r
+\r
+  @param[In]  Command         TPM_CC command starts from TPM_CC_FIRST.\r
+  @param[out] IsCmdImpl       The command is supported or not.\r
+\r
+  @retval EFI_SUCCESS            Operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR       The command was unsuccessful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm2GetCapabilityIsCommandImplemented (\r
+  IN      TPM_CC      Command,\r
+  OUT     BOOLEAN     *IsCmdImpl\r
+  )\r
+{\r
+  TPMS_CAPABILITY_DATA    TpmCap;\r
+  TPMI_YES_NO             MoreData;\r
+  EFI_STATUS              Status;\r
+  UINT32                  Attribute;\r
+\r
+  Status = Tpm2GetCapability (\r
+             TPM_CAP_COMMANDS,\r
+             Command,\r
+             1,\r
+             &MoreData,\r
+             &TpmCap\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  CopyMem (&Attribute, &TpmCap.data.command.commandAttributes[0], sizeof (UINT32));\r
+  *IsCmdImpl = (Command == (SwapBytes32(Attribute) & TPMA_CC_COMMANDINDEX_MASK));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   This command is used to check to see if specific combinations of algorithm parameters are supported.\r
 \r