public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Qi Zhang <qi1.zhang@intel.com>
To: devel@edk2.groups.io
Cc: "Zhang, Qi" <qi1.zhang@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Chao Zhang <chao.b.zhang@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>
Subject: [PATCH 1/2] SecurityPkg/Tpm2CommandLib: add new function Tpm2GetCapabilityIsCmdImpl.
Date: Tue, 16 Jun 2020 15:30:49 +0800	[thread overview]
Message-ID: <20200616073048.2019-2-qi1.zhang@intel.com> (raw)
In-Reply-To: <20200616073048.2019-1-qi1.zhang@intel.com>

From: "Zhang, Qi" <qi1.zhang@intel.com>

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>
---
 SecurityPkg/Include/Library/Tpm2CommandLib.h        | 16 ++++++++++++++++
 SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b/SecurityPkg/Include/Library/Tpm2CommandLib.h
index ce381e786b..ce7290c0f5 100644
--- a/SecurityPkg/Include/Library/Tpm2CommandLib.h
+++ b/SecurityPkg/Include/Library/Tpm2CommandLib.h
@@ -790,6 +790,22 @@ Tpm2GetCapabilityAlgorithmSet (
   OUT     UINT32      *AlgorithmSet
   );
 
+/**
+  This function will query if the command is supported.
+
+  @param[In]  Command         TPM_CC command starts from TPM_CC_FIRST.
+  @param[out] IsCmdImpl       The command is supported or not.
+
+  @retval EFI_SUCCESS            Operation completed successfully.
+  @retval EFI_DEVICE_ERROR       The command was unsuccessful.
+**/
+EFI_STATUS
+EFIAPI
+Tpm2GetCapabilityIsCmdImpl (
+  IN      TPM_CC      Command,
+  OUT     BOOLEAN     *IsCmdImpl
+  );
+
 /**
   This command is used to check to see if specific combinations of algorithm parameters are supported.
 
diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
index 85b11c7715..0c8f980e69 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
@@ -39,6 +39,8 @@ typedef struct {
 
 #pragma pack()
 
+#define TPMA_CC_COMMANDINDEX_MASK  0x2000FFFF
+
 /**
   This command returns various information regarding the TPM and its current state.
 
@@ -628,6 +630,44 @@ Tpm2GetCapabilityAlgorithmSet (
   return EFI_SUCCESS;
 }
 
+/**
+  This function will query if the command is supported.
+
+  @param[In]  Command         TPM_CC command starts from TPM_CC_FIRST.
+  @param[out] IsCmdImpl       The command is supported or not.
+
+  @retval EFI_SUCCESS            Operation completed successfully.
+  @retval EFI_DEVICE_ERROR       The command was unsuccessful.
+**/
+EFI_STATUS
+EFIAPI
+Tpm2GetCapabilityIsCmdImpl (
+  IN      TPM_CC      Command,
+  OUT     BOOLEAN     *IsCmdImpl
+  )
+{
+  TPMS_CAPABILITY_DATA    TpmCap;
+  TPMI_YES_NO             MoreData;
+  EFI_STATUS              Status;
+  UINT32                  Attribute;
+
+  Status = Tpm2GetCapability (
+             TPM_CAP_COMMANDS,
+             Command,
+             1,
+             &MoreData,
+             &TpmCap
+             );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  CopyMem (&Attribute, &TpmCap.data.command.commandAttributes[0], sizeof (UINT32));
+  *IsCmdImpl = (Command == (SwapBytes32(Attribute) & TPMA_CC_COMMANDINDEX_MASK));
+
+  return EFI_SUCCESS;
+}
+
 /**
   This command is used to check to see if specific combinations of algorithm parameters are supported.
 
-- 
2.26.2.windows.1


  reply	other threads:[~2020-06-16  7:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16  7:30 [PATCH v2 0/2] refine TPM2 operation pull down list Qi Zhang
2020-06-16  7:30 ` Qi Zhang [this message]
2020-06-16  7:30 ` [PATCH 2/2] SecurityPkg/Tcg2Config: remove TPM2_ChangEPS if it is not supported Qi Zhang
2020-07-05 12:37 ` [PATCH v2 0/2] refine TPM2 operation pull down list Zhang, Qi1
2020-07-05 23:59 ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200616073048.2019-2-qi1.zhang@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox