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.485.1585028269205581150 for ; Mon, 23 Mar 2020 22:37:49 -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: xFHWsUGpM69HiYYHTcb1w6zq7S0NQ5Jbie+jNIonMUXS2HZP/wOT1GTX72rS3+FPn9XAV+kgo1 EZr/zVDomxyw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2020 22:37:48 -0700 IronPort-SDR: wxKToNSgI4AduGGtR3MMxyY5vRZJxAIaxc0cCyXnQPke0YLLeXnv8KsMyq2Y4fKPnmYLk0Jizd L49O4ltKfoVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,299,1580803200"; d="scan'208";a="446093671" Received: from chenxia1-desk.ccr.corp.intel.com ([10.239.216.22]) by fmsmga005.fm.intel.com with ESMTP; 23 Mar 2020 22:37:47 -0700 From: "chenxia1" To: devel@edk2.groups.io Subject: [PATCH] SecurityPkg/TcgStorageOpalLib: add transaction interface Date: Tue, 24 Mar 2020 13:37:39 +0800 Message-Id: <20200324053739.32160-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