]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg/Tpm2CommandLib: add a new function
authorZhang, Qi <qi1.zhang@intel.com>
Tue, 28 Jul 2020 08:20:39 +0000 (16:20 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 28 Jul 2020 09:56:25 +0000 (09:56 +0000)
 Tpm2GetCapabilityIsCommandImplemented

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2793

check if the commad is supported by comparing the command code with
command index.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Qi Zhang <qi1.zhang@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
SecurityPkg/Include/Library/Tpm2CommandLib.h
SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c

index ce381e786b2c275fd500112ef94d7521bdf5009e..ee8eb622951c54921c228155a01298015cf9506d 100644 (file)
@@ -790,6 +790,22 @@ Tpm2GetCapabilityAlgorithmSet (
   OUT     UINT32      *AlgorithmSet\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
 /**\r
   This command is used to check to see if specific combinations of algorithm parameters are supported.\r
 \r
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