From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.603.1585029554450177706 for ; Mon, 23 Mar 2020 22:59:14 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: xiao.x.chen@intel.com) IronPort-SDR: HLJ+alQVRbHVX/kopL6N6K16mgebKYqU2M7JrFscorwheXEbB9iD8rX9RAV/UY5oGsKFzdlwVG dhKXrGkkFnXg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2020 22:59:14 -0700 IronPort-SDR: 61EoXgcEMXPmpa64RPueTYqc4mVEcNH5VvER05FvoFJ1Di1sjE39e+Fhm+vWTeSCFWKN1Cug6D NAINdwkzPcCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,299,1580803200"; d="scan'208";a="265030215" Received: from chenxia1-desk.ccr.corp.intel.com ([10.239.216.22]) by orsmga002.jf.intel.com with ESMTP; 23 Mar 2020 22:59:12 -0700 From: "chenxia1" To: devel@edk2.groups.io Subject: [PATCH] SecurityPkg/TcgStorageOpalLib: add transaction interface Date: Tue, 24 Mar 2020 13:59:01 +0800 Message-Id: <20200324055901.28064-1-xiao.x.chen@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2625 Add the interface OpalStartTransaction. Add the interface OpalEndTransaction. Add the interface TcgCreateStartTransaction. Add the interface TcgCreateEndTransaction. Change-Id: I9cfa43ce005d65ba65cc6c1ffc8a6b754266189b Signed-off-by: chenxia1 --- SecurityPkg/Include/Library/TcgStorageCoreLib.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ SecurityPkg/Library/TcgStorageCoreLib/TcgStorageUtil.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SecurityPkg/Library/TcgStorageOpalLib/TcgStorageOpalCore.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) diff --git a/SecurityPkg/Include/Library/TcgStorageCoreLib.h b/SecurityPkg/Include/Library/TcgStorageCoreLib.h index 01a44c667c..451084a01d 100644 --- a/SecurityPkg/Include/Library/TcgStorageCoreLib.h +++ b/SecurityPkg/Include/Library/TcgStorageCoreLib.h @@ -1303,6 +1303,54 @@ TcgIsLocked( const TCG_LEVEL0_DISCOVERY_HEADER *Discovery ); +/** + + Creates ComPacket with StartTransaction. + + @param [in/out] CreateStruct Structure used to add Endsession + @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function. + @param [in] ComId ComID for the ComPacket + @param [in] ComIdExtension Extended ComID for the ComPacket + @param [in] HostSessionId Host Session ID for the Packet + @param [in] TpSessionId Tper Session ID for the Packet + +**/ +TCG_RESULT +EFIAPI +TcgCreateStartTransaction( + TCG_CREATE_STRUCT *CreateStruct, + UINT32 *Size, + UINT16 ComId, + UINT16 ComIdExtension, + UINT32 HostSessionId, + UINT32 TpSessionId + ); + +/** + + Creates ComPacket with EndTransaction. + + @param [in/out] CreateStruct Structure used to add Endsession + @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function. + @param [in] ComId ComID for the ComPacket + @param [in] ComIdExtension Extended ComID for the ComPacket + @param [in] HostSessionId Host Session ID for the Packet + @param [in] TpSessionId Tper Session ID for the Packet + @param [in] Status Status for the commit or abort action + +**/ +TCG_RESULT +EFIAPI +TcgCreateEndTransaction( + TCG_CREATE_STRUCT *CreateStruct, + UINT32 *Size, + UINT16 ComId, + UINT16 ComIdExtension, + UINT32 HostSessionId, + UINT32 TpSessionId, + UINT8 Status + ); + #pragma pack() diff --git a/SecurityPkg/Library/TcgStorageCoreLib/TcgStorageUtil.c b/SecurityPkg/Library/TcgStorageCoreLib/TcgStorageUtil.c index ff331bfc8a..50eeee3b47 100644 --- a/SecurityPkg/Library/TcgStorageCoreLib/TcgStorageUtil.c +++ b/SecurityPkg/Library/TcgStorageCoreLib/TcgStorageUtil.c @@ -899,3 +899,75 @@ TcgIsLocked( // return FALSE; } + +/** + + Creates ComPacket with StartTransaction. + + @param [in/out] CreateStruct Structure used to add Endsession + @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function. + @param [in] ComId ComID for the ComPacket + @param [in] ComIdExtension Extended ComID for the ComPacket + @param [in] HostSessionId Host Session ID for the Packet + @param [in] TpSessionId Tper Session ID for the Packet + +**/ +TCG_RESULT +EFIAPI +TcgCreateStartTransaction( + TCG_CREATE_STRUCT *CreateStruct, + UINT32 *Size, + UINT16 ComId, + UINT16 ComIdExtension, + UINT32 HostSessionId, + UINT32 TpSessionId + ) +{ + ERROR_CHECK(TcgStartComPacket(CreateStruct, ComId, ComIdExtension)); + ERROR_CHECK(TcgStartPacket(CreateStruct, TpSessionId, HostSessionId, 0x0, 0x0, 0x0)); + ERROR_CHECK(TcgStartSubPacket(CreateStruct, 0x0)); + ERROR_CHECK(TcgAddStartTransaction(CreateStruct)); + ERROR_CHECK(TcgAddUINT8(CreateStruct, 0x00)); // "Status" + ERROR_CHECK(TcgEndSubPacket(CreateStruct)); + ERROR_CHECK(TcgEndPacket(CreateStruct)); + ERROR_CHECK(TcgEndComPacket(CreateStruct, Size)); + + return TcgResultSuccess; +} + +/** + + Creates ComPacket with EndTransaction. + + @param [in/out] CreateStruct Structure used to add Endsession + @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function. + @param [in] ComId ComID for the ComPacket + @param [in] ComIdExtension Extended ComID for the ComPacket + @param [in] HostSessionId Host Session ID for the Packet + @param [in] TpSessionId Tper Session ID for the Packet + @param [in] Status Status for the commit or abort action + +**/ +TCG_RESULT +EFIAPI +TcgCreateEndTransaction( + TCG_CREATE_STRUCT *CreateStruct, + UINT32 *Size, + UINT16 ComId, + UINT16 ComIdExtension, + UINT32 HostSessionId, + UINT32 TpSessionId, + UINT8 Status + ) +{ + ERROR_CHECK(TcgStartComPacket(CreateStruct, ComId, ComIdExtension)); + ERROR_CHECK(TcgStartPacket(CreateStruct, TpSessionId, HostSessionId, 0x0, 0x0, 0x0)); + ERROR_CHECK(TcgStartSubPacket(CreateStruct, 0x0)); + ERROR_CHECK(TcgAddEndTransaction(CreateStruct)); + ERROR_CHECK(TcgAddUINT8(CreateStruct, Status)); // "Status" + ERROR_CHECK(TcgEndSubPacket(CreateStruct)); + ERROR_CHECK(TcgEndPacket(CreateStruct)); + ERROR_CHECK(TcgEndComPacket(CreateStruct, Size)); + + return TcgResultSuccess; +} diff --git a/SecurityPkg/Library/TcgStorageOpalLib/TcgStorageOpalCore.c b/SecurityPkg/Library/TcgStorageOpalLib/TcgStorageOpalCore.c index b58597e61f..c3e6e9d3ad 100644 --- a/SecurityPkg/Library/TcgStorageOpalLib/TcgStorageOpalCore.c +++ b/SecurityPkg/Library/TcgStorageOpalLib/TcgStorageOpalCore.c @@ -1987,3 +1987,117 @@ OpalDeviceLocked( return LockingFeature->Locked; } +/** + Start Transaction. + + @param[in/out] Session OPAL_SESSION to start transaction. + +**/ +TCG_RESULT +EFIAPI +OpalStartTransaction( + OPAL_SESSION *Session + ) +{ + UINT8 Buffer[BUFFER_SIZE]; + TCG_CREATE_STRUCT CreateStruct; + UINT32 Size; + TCG_PARSE_STRUCT ParseStruct; + + NULL_CHECK(Session); + ERROR_CHECK(TcgInitTcgCreateStruct(&CreateStruct, Buffer, sizeof(Buffer))); + ERROR_CHECK(TcgCreateStartTransaction( + &CreateStruct, + &Size, + Session->OpalBaseComId, + Session->ComIdExtension, + Session->HostSessionId, + Session->TperSessionId + )); + + ERROR_CHECK(OpalTrustedSend( + Session->Sscp, + Session->MediaId, + TCG_OPAL_SECURITY_PROTOCOL_1, + Session->OpalBaseComId, + Size, + Buffer, + sizeof(Buffer) + )); + + ERROR_CHECK(OpalTrustedRecv( + Session->Sscp, + Session->MediaId, + TCG_OPAL_SECURITY_PROTOCOL_1, + Session->OpalBaseComId, + Buffer, + sizeof(Buffer), + 0 + )); + + ERROR_CHECK(TcgInitTcgParseStruct(&ParseStruct, Buffer, sizeof(Buffer))); + ERROR_CHECK(TcgCheckComIds(&ParseStruct, Session->OpalBaseComId, Session->ComIdExtension)); + ERROR_CHECK(TcgGetNextStartTransaction(&ParseStruct)); + + return TcgResultSuccess; +} + +/** + End Transaction. + + @param[in/out] Session OPAL_SESSION to end transaction. + @param[in/out] Status 0x00 for commit and 0x01 for abort. If action succeeded, it should be TCG_METHOD_STATUS_CODE_SUCCESS. + +**/ +TCG_RESULT +EFIAPI +OpalEndTransaction( + OPAL_SESSION *Session, + UINT8 Status + ) +{ + UINT8 Buffer[BUFFER_SIZE]; + TCG_CREATE_STRUCT CreateStruct; + UINT32 Size; + TCG_PARSE_STRUCT ParseStruct; + + NULL_CHECK(Session); + ERROR_CHECK(TcgInitTcgCreateStruct(&CreateStruct, Buffer, sizeof(Buffer))); + ERROR_CHECK(TcgCreateEndTransaction( + &CreateStruct, + &Size, + Session->OpalBaseComId, + Session->ComIdExtension, + Session->HostSessionId, + Session->TperSessionId, + Status + )); + + ERROR_CHECK(OpalTrustedSend( + Session->Sscp, + Session->MediaId, + TCG_OPAL_SECURITY_PROTOCOL_1, + Session->OpalBaseComId, + Size, + Buffer, + sizeof(Buffer) + )); + + ERROR_CHECK(OpalTrustedRecv( + Session->Sscp, + Session->MediaId, + TCG_OPAL_SECURITY_PROTOCOL_1, + Session->OpalBaseComId, + Buffer, + sizeof(Buffer), + 0 + )); + + ERROR_CHECK(TcgInitTcgParseStruct(&ParseStruct, Buffer, sizeof(Buffer))); + ERROR_CHECK(TcgCheckComIds(&ParseStruct, Session->OpalBaseComId, Session->ComIdExtension)); + + ERROR_CHECK(TcgGetNextEndTransaction(&ParseStruct)); + + return TcgResultSuccess; +} + -- 2.16.2.windows.1