public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "chenxia1" <xiao.x.chen@intel.com>
To: devel@edk2.groups.io
Subject: [PATCH] SecurityPkg/TcgStorageOpalLib: add transaction interface
Date: Tue, 24 Mar 2020 13:59:01 +0800	[thread overview]
Message-ID: <20200324055901.28064-1-xiao.x.chen@intel.com> (raw)

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 <xiao.x.chen@intel.com>
---
 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


             reply	other threads:[~2020-03-24  5:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24  5:59 chenxia1 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-03-24  5:37 [PATCH] SecurityPkg/TcgStorageOpalLib: add transaction interface chenxia1

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=20200324055901.28064-1-xiao.x.chen@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