From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com []) by mx.groups.io with SMTP id smtpd.web10.7977.1595924447539035211 for ; Tue, 28 Jul 2020 01:20:48 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: qi1.zhang@intel.com) IronPort-SDR: zzyhS+BSL2xQLE+YxqYPm5uEKgYpro8OSyM+MwvbkvlZylhMMuACwVbnfjSvLBb7SA5DjzJzKN SGSbp5kjuwqA== X-IronPort-AV: E=McAfee;i="6000,8403,9695"; a="138686515" X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="138686515" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2020 01:20:48 -0700 IronPort-SDR: ONxyOdpaRqA8tYn+4IO/QgmvQVphrc6E1gZrdn2CFIfwCyN7iRHy5A8r3c7YY2BuLuf7smulFS S5DN9AyjJ5Xw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="272245526" Received: from shwdesssddpdqi.ccr.corp.intel.com ([10.239.9.10]) by fmsmga007.fm.intel.com with ESMTP; 28 Jul 2020 01:20:46 -0700 From: "Qi Zhang" To: devel@edk2.groups.io Cc: "Zhang, Qi" , Jiewen Yao , Jian J Wang , Chao Zhang , Rahul Kumar Subject: [PATCH v4 1/2] SecurityPkg/Tpm2CommandLib: add a new function Date: Tue, 28 Jul 2020 16:20:39 +0800 Message-Id: <20200728082040.13955-2-qi1.zhang@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20200728082040.13955-1-qi1.zhang@intel.com> References: <20200728082040.13955-1-qi1.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: "Zhang, Qi" Tpm2GetCapabilityIsCommandImplemented REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2793 check if the commad is supported by comparing the command code with command index. Cc: Jiewen Yao Cc: Jian J Wang Cc: Chao Zhang Cc: Rahul Kumar Signed-off-by: Qi Zhang --- SecurityPkg/Include/Library/Tpm2CommandLib.h | 16 ++++++++ .../Library/Tpm2CommandLib/Tpm2Capability.c | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b/SecurityPkg/Inc= lude/Library/Tpm2CommandLib.h index ce381e786b..ee8eb62295 100644 --- a/SecurityPkg/Include/Library/Tpm2CommandLib.h +++ b/SecurityPkg/Include/Library/Tpm2CommandLib.h @@ -790,6 +790,22 @@ Tpm2GetCapabilityAlgorithmSet ( OUT UINT32 *AlgorithmSet=0D );=0D =0D +/**=0D + This function will query if the command is supported.=0D +=0D + @param[In] Command TPM_CC command starts from TPM_CC_FIRST.=0D + @param[out] IsCmdImpl The command is supported or not.=0D +=0D + @retval EFI_SUCCESS Operation completed successfully.=0D + @retval EFI_DEVICE_ERROR The command was unsuccessful.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +Tpm2GetCapabilityIsCommandImplemented (=0D + IN TPM_CC Command,=0D + OUT BOOLEAN *IsCmdImpl=0D + );=0D +=0D /**=0D This command is used to check to see if specific combinations of algorit= hm parameters are supported.=0D =0D diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c b/Security= Pkg/Library/Tpm2CommandLib/Tpm2Capability.c index 85b11c7715..17c0c3a151 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c @@ -39,6 +39,8 @@ typedef struct { =0D #pragma pack()=0D =0D +#define TPMA_CC_COMMANDINDEX_MASK 0x2000FFFF=0D +=0D /**=0D This command returns various information regarding the TPM and its curre= nt state.=0D =0D @@ -628,6 +630,44 @@ Tpm2GetCapabilityAlgorithmSet ( return EFI_SUCCESS;=0D }=0D =0D +/**=0D + This function will query if the command is supported.=0D +=0D + @param[In] Command TPM_CC command starts from TPM_CC_FIRST.=0D + @param[out] IsCmdImpl The command is supported or not.=0D +=0D + @retval EFI_SUCCESS Operation completed successfully.=0D + @retval EFI_DEVICE_ERROR The command was unsuccessful.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +Tpm2GetCapabilityIsCommandImplemented (=0D + IN TPM_CC Command,=0D + OUT BOOLEAN *IsCmdImpl=0D + )=0D +{=0D + TPMS_CAPABILITY_DATA TpmCap;=0D + TPMI_YES_NO MoreData;=0D + EFI_STATUS Status;=0D + UINT32 Attribute;=0D +=0D + Status =3D Tpm2GetCapability (=0D + TPM_CAP_COMMANDS,=0D + Command,=0D + 1,=0D + &MoreData,=0D + &TpmCap=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + CopyMem (&Attribute, &TpmCap.data.command.commandAttributes[0], sizeof (= UINT32));=0D + *IsCmdImpl =3D (Command =3D=3D (SwapBytes32(Attribute) & TPMA_CC_COMMAND= INDEX_MASK));=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D /**=0D This command is used to check to see if specific combinations of algorit= hm parameters are supported.=0D =0D --=20 2.26.2.windows.1