From nobody Wed Apr 24 12:04:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+56144+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56144+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1585048692; cv=none; d=zohomail.com; s=zohoarc; b=e5TmZdf5KmWXDAfNd0B3zaEa9gEfLtX35gcN5xwjqUSVD/QvEVL4yNBAE3EhGNlQXRqHZa1fajGBIYF0PhrCaBYTDUPev7/SvDTo2jW3HpnpjSJn/vL/IZHe5pAmw/tK6IZbATTia2mUFkBde6+d2J1vUbvplDRWYqPHIi+nFug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585048692; h=Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=1Os4oRp9u0HefdtUj4VnnOj445y83IXunT+NtNN0Oc8=; b=iU9dtETvMvW3GUQuA7ceof+RtFY/mt/mU6MW2GN/nJHKCO/m+RcIrT+NEU9vI6b7rDQaoiHir6BPF5xL1q8tw2Xyjb9KemzJDj/U5gzymU9yji26A6v1Dq4xg8J057s1xr6qYgmkiK6ZURPUos8Tla9t2t7UQiyJPXpe5OjmOxU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56144+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1585048692028345.7027904212164; Tue, 24 Mar 2020 04:18:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id W3ZGYY1788612xLZv5jGVxen; Tue, 24 Mar 2020 04:18:11 -0700 X-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 IronPort-SDR: xFHWsUGpM69HiYYHTcb1w6zq7S0NQ5Jbie+jNIonMUXS2HZP/wOT1GTX72rS3+FPn9XAV+kgo1 EZr/zVDomxyw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-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" X-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: [edk2-devel] [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> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,xiao.x.chen@intel.com X-Gm-Message-State: 30C5OLRRjPcWWobxTOFdXBkHx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1585048691; bh=hHZxo0eKM2geG2nNP4P6rii1hGY0cOO/DcGJqFkfwys=; h=Date:From:Reply-To:Subject:To; b=eqb0UxP+EJl91lufACSJoeWNTb2EmutmP/lL3uc0O2+TTcitlYIpXqwHd2ogW1OTgne TH6syIrnKNdlsGzRfK4a+DfqPwUQzWPrK3XVrS5N+7yIE6pReuLV82LgBrwwH1nD181gi 8rpCDTLuXDmkbOIUrOjRTJi3/ow0OAKW9O4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2625 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 ); =20 +/** + + 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 a= ction + +**/ +TCG_RESULT +EFIAPI +TcgCreateEndTransaction( + TCG_CREATE_STRUCT *CreateStruct, + UINT32 *Size, + UINT16 ComId, + UINT16 ComIdExtension, + UINT32 HostSessionId, + UINT32 TpSessionId, + UINT8 Status + ); + #pragma pack() =20 =20 diff --git a/SecurityPkg/Library/TcgStorageCoreLib/TcgStorageUtil.c b/Secur= ityPkg/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 a= ction + +**/ +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/S= ecurityPkg/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; } =20 +/** + 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 acti= on 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; +} + --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56144): https://edk2.groups.io/g/devel/message/56144 Mute This Topic: https://groups.io/mt/72514659/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-