mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-27 15:44:04 +02:00
SecurityPkg/Tpm12CommandLib: Add TPM 1.2 commands used by TCG modules
Add the following APIs that are required by TcgPei and/or TcgDxe to the Tpm12CommandLib instance: Tpm12Extend() Tpm12PhysicalPresence() Tpm12ContinueSelfTest() Tpm12GetCapabilityFlagPermanent() Tpm12GetCapabilityFlagVolatile() Cc: Chao Zhang <chao.b.zhang@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney <michael.d.kinney@intel.com> Reviewed-by: Chao Zhang <chao.b.zhang@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19727 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
e7c83012fd
commit
83b9662fb0
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# This library is used by other modules to send TPM 1.2 command.
|
# This library is used by other modules to send TPM 1.2 command.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
|
# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
# This program and the accompanying materials
|
# This program and the accompanying materials
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
# which accompanies this distribution. The full text of the license may be found at
|
# which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -32,6 +32,10 @@
|
|||||||
Tpm12Startup.c
|
Tpm12Startup.c
|
||||||
Tpm12Ownership.c
|
Tpm12Ownership.c
|
||||||
Tpm12NvStorage.c
|
Tpm12NvStorage.c
|
||||||
|
Tpm12GetCapability.c
|
||||||
|
Tpm12Pcr.c
|
||||||
|
Tpm12PhysicalPresence.c
|
||||||
|
Tpm12SelfTest.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
@ -44,4 +48,3 @@
|
|||||||
TimerLib
|
TimerLib
|
||||||
DebugLib
|
DebugLib
|
||||||
Tpm12DeviceLib
|
Tpm12DeviceLib
|
||||||
|
|
||||||
|
127
SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
Normal file
127
SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/** @file
|
||||||
|
Implement TPM1.2 Get Capabilities related commands.
|
||||||
|
|
||||||
|
Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
|
This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <PiPei.h>
|
||||||
|
#include <Library/Tpm12CommandLib.h>
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TPM_RQU_COMMAND_HDR Hdr;
|
||||||
|
UINT32 Capability;
|
||||||
|
UINT32 CapabilityFlagSize;
|
||||||
|
UINT32 CapabilityFlag;
|
||||||
|
} TPM_CMD_GET_CAPABILITY;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TPM_RSP_COMMAND_HDR Hdr;
|
||||||
|
UINT32 ResponseSize;
|
||||||
|
TPM_PERMANENT_FLAGS Flags;
|
||||||
|
} TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TPM_RSP_COMMAND_HDR Hdr;
|
||||||
|
UINT32 ResponseSize;
|
||||||
|
TPM_STCLEAR_FLAGS Flags;
|
||||||
|
} TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS;
|
||||||
|
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get TPM capability permanent flags.
|
||||||
|
|
||||||
|
@param[out] TpmPermanentFlags Pointer to the buffer for returned flag structure.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Operation completed successfully.
|
||||||
|
@retval EFI_TIMEOUT The register can't run into the expected status in time.
|
||||||
|
@retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
|
||||||
|
@retval EFI_DEVICE_ERROR Unexpected device behavior.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
Tpm12GetCapabilityFlagPermanent (
|
||||||
|
OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
TPM_CMD_GET_CAPABILITY Command;
|
||||||
|
TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS Response;
|
||||||
|
UINT32 Length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// send Tpm command TPM_ORD_GetCapability
|
||||||
|
//
|
||||||
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);
|
||||||
|
Command.Capability = SwapBytes32 (TPM_CAP_FLAG);
|
||||||
|
Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT));
|
||||||
|
Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_PERMANENT);
|
||||||
|
Length = sizeof (Response);
|
||||||
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));
|
||||||
|
CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), Response.ResponseSize));
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get TPM capability volatile flags.
|
||||||
|
|
||||||
|
@param[out] VolatileFlags Pointer to the buffer for returned flag structure.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Operation completed successfully.
|
||||||
|
@retval EFI_DEVICE_ERROR The command was unsuccessful.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
Tpm12GetCapabilityFlagVolatile (
|
||||||
|
OUT TPM_STCLEAR_FLAGS *VolatileFlags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
TPM_CMD_GET_CAPABILITY Command;
|
||||||
|
TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS Response;
|
||||||
|
UINT32 Length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// send Tpm command TPM_ORD_GetCapability
|
||||||
|
//
|
||||||
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);
|
||||||
|
Command.Capability = SwapBytes32 (TPM_CAP_FLAG);
|
||||||
|
Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_VOLATILE));
|
||||||
|
Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_VOLATILE);
|
||||||
|
Length = sizeof (Response);
|
||||||
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZeroMem (VolatileFlags, sizeof (*VolatileFlags));
|
||||||
|
CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), Response.ResponseSize));
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Implement TPM1.2 NV storage related command.
|
Implement TPM1.2 NV storage related command.
|
||||||
|
|
||||||
Copyright (c) 2015, Intel Corporation. All rights reserved. <BR>
|
Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -12,18 +12,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <Uefi.h>
|
#include <PiPei.h>
|
||||||
#include <IndustryStandard/Tpm12.h>
|
|
||||||
#include <Library/BaseMemoryLib.h>
|
|
||||||
#include <Library/BaseLib.h>
|
|
||||||
#include <Library/Tpm12DeviceLib.h>
|
|
||||||
#include <Library/Tpm12CommandLib.h>
|
#include <Library/Tpm12CommandLib.h>
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Max TPM command/reponse length
|
// Max TPM NV value length
|
||||||
//
|
//
|
||||||
#define TPMCMDBUFLENGTH 1024
|
#define TPMNVVALUELENGTH 1024
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
@ -33,10 +32,6 @@ typedef struct {
|
|||||||
TPM_ENCAUTH EncAuth;
|
TPM_ENCAUTH EncAuth;
|
||||||
} TPM_CMD_NV_DEFINE_SPACE;
|
} TPM_CMD_NV_DEFINE_SPACE;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RSP_COMMAND_HDR Hdr;
|
|
||||||
} TPM_RSP_NV_DEFINE_SPACE;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TPM_RQU_COMMAND_HDR Hdr;
|
TPM_RQU_COMMAND_HDR Hdr;
|
||||||
TPM_NV_INDEX NvIndex;
|
TPM_NV_INDEX NvIndex;
|
||||||
@ -47,7 +42,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
TPM_RSP_COMMAND_HDR Hdr;
|
TPM_RSP_COMMAND_HDR Hdr;
|
||||||
UINT32 DataSize;
|
UINT32 DataSize;
|
||||||
UINT8 Data[TPMCMDBUFLENGTH];
|
UINT8 Data[TPMNVVALUELENGTH];
|
||||||
} TPM_RSP_NV_READ_VALUE;
|
} TPM_RSP_NV_READ_VALUE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -55,13 +50,9 @@ typedef struct {
|
|||||||
TPM_NV_INDEX NvIndex;
|
TPM_NV_INDEX NvIndex;
|
||||||
UINT32 Offset;
|
UINT32 Offset;
|
||||||
UINT32 DataSize;
|
UINT32 DataSize;
|
||||||
UINT8 Data[TPMCMDBUFLENGTH];
|
UINT8 Data[TPMNVVALUELENGTH];
|
||||||
} TPM_CMD_NV_WRITE_VALUE;
|
} TPM_CMD_NV_WRITE_VALUE;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RSP_COMMAND_HDR Hdr;
|
|
||||||
} TPM_RSP_NV_WRITE_VALUE;
|
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,57 +71,50 @@ Tpm12NvDefineSpace (
|
|||||||
IN TPM_ENCAUTH *EncAuth
|
IN TPM_ENCAUTH *EncAuth
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 TpmRecvSize;
|
TPM_CMD_NV_DEFINE_SPACE Command;
|
||||||
UINT32 TpmSendSize;
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
TPM_CMD_NV_DEFINE_SPACE SendBuffer;
|
UINT32 Length;
|
||||||
TPM_RSP_NV_DEFINE_SPACE RecvBuffer;
|
|
||||||
UINT32 ReturnCode;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// send Tpm command TPM_ORD_NV_DefineSpace
|
// send Tpm command TPM_ORD_NV_DefineSpace
|
||||||
//
|
//
|
||||||
TpmRecvSize = sizeof (TPM_RSP_NV_DEFINE_SPACE);
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
TpmSendSize = sizeof (TPM_CMD_NV_DEFINE_SPACE);
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_DefineSpace);
|
||||||
SendBuffer.Hdr.paramSize = SwapBytes32 (sizeof(TPM_CMD_NV_DEFINE_SPACE));
|
Command.PubInfo.tag = SwapBytes16 (PubInfo->tag);
|
||||||
SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_DefineSpace);
|
Command.PubInfo.nvIndex = SwapBytes32 (PubInfo->nvIndex);
|
||||||
SendBuffer.PubInfo.tag = SwapBytes16 (PubInfo->tag);
|
Command.PubInfo.pcrInfoRead.pcrSelection.sizeOfSelect = SwapBytes16 (PubInfo->pcrInfoRead.pcrSelection.sizeOfSelect);
|
||||||
SendBuffer.PubInfo.nvIndex = SwapBytes32 (PubInfo->nvIndex);
|
Command.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[0] = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[0];
|
||||||
SendBuffer.PubInfo.pcrInfoRead.pcrSelection.sizeOfSelect = SwapBytes16 (PubInfo->pcrInfoRead.pcrSelection.sizeOfSelect);
|
Command.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[1] = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[1];
|
||||||
SendBuffer.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[0] = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[0];
|
Command.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[2] = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[2];
|
||||||
SendBuffer.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[1] = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[1];
|
Command.PubInfo.pcrInfoRead.localityAtRelease = PubInfo->pcrInfoRead.localityAtRelease;
|
||||||
SendBuffer.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[2] = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[2];
|
CopyMem (&Command.PubInfo.pcrInfoRead.digestAtRelease, &PubInfo->pcrInfoRead.digestAtRelease, sizeof(PubInfo->pcrInfoRead.digestAtRelease));
|
||||||
SendBuffer.PubInfo.pcrInfoRead.localityAtRelease = PubInfo->pcrInfoRead.localityAtRelease;
|
Command.PubInfo.pcrInfoWrite.pcrSelection.sizeOfSelect = SwapBytes16 (PubInfo->pcrInfoWrite.pcrSelection.sizeOfSelect);
|
||||||
CopyMem (&SendBuffer.PubInfo.pcrInfoRead.digestAtRelease, &PubInfo->pcrInfoRead.digestAtRelease, sizeof(PubInfo->pcrInfoRead.digestAtRelease));
|
Command.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[0] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[0];
|
||||||
SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.sizeOfSelect = SwapBytes16 (PubInfo->pcrInfoWrite.pcrSelection.sizeOfSelect);
|
Command.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[1] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[1];
|
||||||
SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[0] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[0];
|
Command.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[2] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[2];
|
||||||
SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[1] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[1];
|
Command.PubInfo.pcrInfoWrite.localityAtRelease = PubInfo->pcrInfoWrite.localityAtRelease;
|
||||||
SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[2] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[2];
|
CopyMem (&Command.PubInfo.pcrInfoWrite.digestAtRelease, &PubInfo->pcrInfoWrite.digestAtRelease, sizeof(PubInfo->pcrInfoWrite.digestAtRelease));
|
||||||
SendBuffer.PubInfo.pcrInfoWrite.localityAtRelease = PubInfo->pcrInfoWrite.localityAtRelease;
|
Command.PubInfo.permission.tag = SwapBytes16 (PubInfo->permission.tag);
|
||||||
CopyMem (&SendBuffer.PubInfo.pcrInfoWrite.digestAtRelease, &PubInfo->pcrInfoWrite.digestAtRelease, sizeof(PubInfo->pcrInfoWrite.digestAtRelease));
|
Command.PubInfo.permission.attributes = SwapBytes32 (PubInfo->permission.attributes);
|
||||||
SendBuffer.PubInfo.permission.tag = SwapBytes16 (PubInfo->permission.tag);
|
Command.PubInfo.bReadSTClear = PubInfo->bReadSTClear;
|
||||||
SendBuffer.PubInfo.permission.attributes = SwapBytes32 (PubInfo->permission.attributes);
|
Command.PubInfo.bWriteSTClear = PubInfo->bWriteSTClear;
|
||||||
SendBuffer.PubInfo.bReadSTClear = PubInfo->bReadSTClear;
|
Command.PubInfo.bWriteDefine = PubInfo->bWriteDefine;
|
||||||
SendBuffer.PubInfo.bWriteSTClear = PubInfo->bWriteSTClear;
|
Command.PubInfo.dataSize = SwapBytes32 (PubInfo->dataSize);
|
||||||
SendBuffer.PubInfo.bWriteDefine = PubInfo->bWriteDefine;
|
CopyMem (&Command.EncAuth, EncAuth, sizeof(*EncAuth));
|
||||||
SendBuffer.PubInfo.dataSize = SwapBytes32 (PubInfo->dataSize);
|
Length = sizeof (Response);
|
||||||
CopyMem (&SendBuffer.EncAuth, EncAuth, sizeof(*EncAuth));
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
|
||||||
Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
|
DEBUG ((DEBUG_INFO, "Tpm12NvDefineSpace - ReturnCode = %x\n", SwapBytes32 (Response.returnCode)));
|
||||||
DEBUG ((DEBUG_INFO, "Tpm12NvDefineSpace - ReturnCode = %x\n", ReturnCode));
|
switch (SwapBytes32 (Response.returnCode)) {
|
||||||
switch (ReturnCode) {
|
|
||||||
case TPM_SUCCESS:
|
case TPM_SUCCESS:
|
||||||
break;
|
return EFI_SUCCESS;
|
||||||
default:
|
default:
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,38 +131,33 @@ Tpm12NvDefineSpace (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
Tpm12NvReadValue (
|
Tpm12NvReadValue (
|
||||||
IN TPM_NV_INDEX NvIndex,
|
IN TPM_NV_INDEX NvIndex,
|
||||||
IN UINT32 Offset,
|
IN UINT32 Offset,
|
||||||
IN OUT UINT32 *DataSize,
|
IN OUT UINT32 *DataSize,
|
||||||
OUT UINT8 *Data
|
OUT UINT8 *Data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 TpmRecvSize;
|
TPM_CMD_NV_READ_VALUE Command;
|
||||||
UINT32 TpmSendSize;
|
TPM_RSP_NV_READ_VALUE Response;
|
||||||
TPM_CMD_NV_READ_VALUE SendBuffer;
|
UINT32 Length;
|
||||||
TPM_RSP_NV_READ_VALUE RecvBuffer;
|
|
||||||
UINT32 ReturnCode;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// send Tpm command TPM_ORD_NV_ReadValue
|
// send Tpm command TPM_ORD_NV_ReadValue
|
||||||
//
|
//
|
||||||
TpmRecvSize = sizeof (TPM_RSP_NV_READ_VALUE);
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
TpmSendSize = sizeof (TPM_CMD_NV_READ_VALUE);
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_ReadValue);
|
||||||
SendBuffer.Hdr.paramSize = SwapBytes32 (sizeof(TPM_CMD_NV_READ_VALUE));
|
Command.NvIndex = SwapBytes32 (NvIndex);
|
||||||
SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_ReadValue);
|
Command.Offset = SwapBytes32 (Offset);
|
||||||
SendBuffer.NvIndex = SwapBytes32 (NvIndex);
|
Command.DataSize = SwapBytes32 (*DataSize);
|
||||||
SendBuffer.Offset = SwapBytes32 (Offset);
|
Length = sizeof (Response);
|
||||||
SendBuffer.DataSize = SwapBytes32 (*DataSize);
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
|
||||||
Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
|
DEBUG ((DEBUG_INFO, "Tpm12NvReadValue - ReturnCode = %x\n", SwapBytes32 (Response.Hdr.returnCode)));
|
||||||
DEBUG ((DEBUG_INFO, "Tpm12NvReadValue - ReturnCode = %x\n", ReturnCode));
|
switch (SwapBytes32 (Response.Hdr.returnCode)) {
|
||||||
switch (ReturnCode) {
|
|
||||||
case TPM_SUCCESS:
|
case TPM_SUCCESS:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -188,8 +167,12 @@ Tpm12NvReadValue (
|
|||||||
//
|
//
|
||||||
// Return the response
|
// Return the response
|
||||||
//
|
//
|
||||||
*DataSize = SwapBytes32(RecvBuffer.DataSize);
|
if (SwapBytes32 (Response.DataSize) > *DataSize) {
|
||||||
CopyMem (Data, &RecvBuffer.Data, *DataSize);
|
return EFI_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
*DataSize = SwapBytes32 (Response.DataSize);
|
||||||
|
ZeroMem (Data, *DataSize);
|
||||||
|
CopyMem (Data, &Response.Data, *DataSize);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -208,48 +191,41 @@ Tpm12NvReadValue (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
Tpm12NvWriteValue (
|
Tpm12NvWriteValue (
|
||||||
IN TPM_NV_INDEX NvIndex,
|
IN TPM_NV_INDEX NvIndex,
|
||||||
IN UINT32 Offset,
|
IN UINT32 Offset,
|
||||||
IN UINT32 DataSize,
|
IN UINT32 DataSize,
|
||||||
IN UINT8 *Data
|
IN UINT8 *Data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 TpmRecvSize;
|
TPM_CMD_NV_WRITE_VALUE Command;
|
||||||
UINT32 TpmSendSize;
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
TPM_CMD_NV_WRITE_VALUE SendBuffer;
|
UINT32 Length;
|
||||||
TPM_RSP_NV_WRITE_VALUE RecvBuffer;
|
|
||||||
UINT32 ReturnCode;
|
|
||||||
|
|
||||||
if (DataSize > sizeof(SendBuffer.Data)) {
|
if (DataSize > sizeof (Command.Data)) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// send Tpm command TPM_ORD_NV_WriteValue
|
// send Tpm command TPM_ORD_NV_WriteValue
|
||||||
//
|
//
|
||||||
TpmRecvSize = sizeof (TPM_RSP_NV_WRITE_VALUE);
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
TpmSendSize = sizeof (TPM_CMD_NV_WRITE_VALUE) - sizeof(SendBuffer.Data) + DataSize;
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command) - sizeof(Command.Data) + DataSize);
|
||||||
SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_WriteValue);
|
||||||
SendBuffer.Hdr.paramSize = SwapBytes32 (sizeof(TPM_CMD_NV_WRITE_VALUE) - sizeof(SendBuffer.Data) + DataSize);
|
Command.NvIndex = SwapBytes32 (NvIndex);
|
||||||
SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_NV_WriteValue);
|
Command.Offset = SwapBytes32 (Offset);
|
||||||
SendBuffer.NvIndex = SwapBytes32 (NvIndex);
|
Command.DataSize = SwapBytes32 (DataSize);
|
||||||
SendBuffer.Offset = SwapBytes32 (Offset);
|
CopyMem (Command.Data, Data, DataSize);
|
||||||
SendBuffer.DataSize = SwapBytes32 (DataSize);
|
Length = sizeof (Response);
|
||||||
CopyMem (SendBuffer.Data, Data, DataSize);
|
Status = Tpm12SubmitCommand (Command.Hdr.paramSize, (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
|
||||||
Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
|
DEBUG ((DEBUG_INFO, "Tpm12NvWritedValue - ReturnCode = %x\n", SwapBytes32 (Response.returnCode)));
|
||||||
DEBUG ((DEBUG_INFO, "Tpm12NvWritedValue - ReturnCode = %x\n", ReturnCode));
|
switch (SwapBytes32 (Response.returnCode)) {
|
||||||
switch (ReturnCode) {
|
|
||||||
case TPM_SUCCESS:
|
case TPM_SUCCESS:
|
||||||
break;
|
return EFI_SUCCESS;
|
||||||
default:
|
default:
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
@ -12,24 +12,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <Uefi.h>
|
#include <PiPei.h>
|
||||||
#include <IndustryStandard/Tpm12.h>
|
|
||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/Tpm12DeviceLib.h>
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
|
|
||||||
#pragma pack(1)
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RQU_COMMAND_HDR Hdr;
|
|
||||||
} TPM_CMD_FORCE_CLEAR;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RSP_COMMAND_HDR Hdr;
|
|
||||||
} TPM_RSP_FORCE_CLEAR;
|
|
||||||
|
|
||||||
#pragma pack()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Send ForceClear command to TPM1.2.
|
Send ForceClear command to TPM1.2.
|
||||||
|
|
||||||
@ -42,28 +29,24 @@ Tpm12ForceClear (
|
|||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 TpmRecvSize;
|
TPM_RQU_COMMAND_HDR Command;
|
||||||
UINT32 TpmSendSize;
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
TPM_CMD_FORCE_CLEAR SendBuffer;
|
UINT32 Length;
|
||||||
TPM_RSP_FORCE_CLEAR RecvBuffer;
|
|
||||||
UINT32 ReturnCode;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// send Tpm command TPM_ORD_ForceClear
|
// send Tpm command TPM_ORD_ForceClear
|
||||||
//
|
//
|
||||||
TpmRecvSize = sizeof (TPM_RSP_FORCE_CLEAR);
|
Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
TpmSendSize = sizeof (TPM_CMD_FORCE_CLEAR);
|
Command.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
Command.ordinal = SwapBytes32 (TPM_ORD_ForceClear);
|
||||||
SendBuffer.Hdr.paramSize = SwapBytes32 (TpmSendSize);
|
Length = sizeof (Response);
|
||||||
SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_ForceClear);
|
|
||||||
|
|
||||||
Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
|
switch (SwapBytes32 (Response.returnCode)) {
|
||||||
switch (ReturnCode) {
|
|
||||||
case TPM_SUCCESS:
|
case TPM_SUCCESS:
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
default:
|
default:
|
||||||
|
82
SecurityPkg/Library/Tpm12CommandLib/Tpm12Pcr.c
Normal file
82
SecurityPkg/Library/Tpm12CommandLib/Tpm12Pcr.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/** @file
|
||||||
|
Implement TPM1.2 PCR related commands.
|
||||||
|
|
||||||
|
Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
|
This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <PiPei.h>
|
||||||
|
#include <Library/Tpm12CommandLib.h>
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TPM_RQU_COMMAND_HDR Hdr;
|
||||||
|
TPM_PCRINDEX PcrIndex;
|
||||||
|
TPM_DIGEST TpmDigest;
|
||||||
|
} TPM_CMD_EXTEND;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TPM_RSP_COMMAND_HDR Hdr;
|
||||||
|
TPM_DIGEST TpmDigest;
|
||||||
|
} TPM_RSP_EXTEND;
|
||||||
|
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
/**
|
||||||
|
Extend a TPM PCR.
|
||||||
|
|
||||||
|
@param[in] DigestToExtend The 160 bit value representing the event to be recorded.
|
||||||
|
@param[in] PcrIndex The PCR to be updated.
|
||||||
|
@param[out] NewPcrValue New PCR value after extend.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Operation completed successfully.
|
||||||
|
@retval EFI_TIMEOUT The register can't run into the expected status in time.
|
||||||
|
@retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
|
||||||
|
@retval EFI_DEVICE_ERROR Unexpected device behavior.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
Tpm12Extend (
|
||||||
|
IN TPM_DIGEST *DigestToExtend,
|
||||||
|
IN TPM_PCRINDEX PcrIndex,
|
||||||
|
OUT TPM_DIGEST *NewPcrValue
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
TPM_CMD_EXTEND Command;
|
||||||
|
TPM_RSP_EXTEND Response;
|
||||||
|
UINT32 Length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// send Tpm command TPM_ORD_Extend
|
||||||
|
//
|
||||||
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_Extend);
|
||||||
|
Command.PcrIndex = SwapBytes32 (PcrIndex);
|
||||||
|
CopyMem (&Command.TpmDigest, DigestToExtend, sizeof (Command.TpmDigest));
|
||||||
|
Length = sizeof (Response);
|
||||||
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NewPcrValue != NULL) {
|
||||||
|
CopyMem (NewPcrValue, &Response.TpmDigest, sizeof (*NewPcrValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
60
SecurityPkg/Library/Tpm12CommandLib/Tpm12PhysicalPresence.c
Normal file
60
SecurityPkg/Library/Tpm12CommandLib/Tpm12PhysicalPresence.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/** @file
|
||||||
|
Implement TPM1.2 Physical Presence related command.
|
||||||
|
|
||||||
|
Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
|
This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <PiPei.h>
|
||||||
|
#include <Library/Tpm12CommandLib.h>
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TPM_RQU_COMMAND_HDR Hdr;
|
||||||
|
TPM_PHYSICAL_PRESENCE PhysicalPresence;
|
||||||
|
} TPM_CMD_PHYSICAL_PRESENCE;
|
||||||
|
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send TSC_PhysicalPresence command to TPM.
|
||||||
|
|
||||||
|
@param[in] PhysicalPresence The state to set the TPMs Physical Presence flags.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Operation completed successfully.
|
||||||
|
@retval EFI_TIMEOUT The register can't run into the expected status in time.
|
||||||
|
@retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
|
||||||
|
@retval EFI_DEVICE_ERROR Unexpected device behavior.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
Tpm12PhysicalPresence (
|
||||||
|
IN TPM_PHYSICAL_PRESENCE PhysicalPresence
|
||||||
|
)
|
||||||
|
{
|
||||||
|
TPM_CMD_PHYSICAL_PRESENCE Command;
|
||||||
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
|
UINT32 Length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// send Tpm command TSC_ORD_PhysicalPresence
|
||||||
|
//
|
||||||
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
|
Command.Hdr.ordinal = SwapBytes32 (TSC_ORD_PhysicalPresence);
|
||||||
|
Command.PhysicalPresence = SwapBytes16 (PhysicalPresence);
|
||||||
|
Length = sizeof (Response);
|
||||||
|
return Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
}
|
46
SecurityPkg/Library/Tpm12CommandLib/Tpm12SelfTest.c
Normal file
46
SecurityPkg/Library/Tpm12CommandLib/Tpm12SelfTest.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/** @file
|
||||||
|
Implement TPM1.2 NV Self Test related commands.
|
||||||
|
|
||||||
|
Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
|
This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <PiPei.h>
|
||||||
|
#include <Library/Tpm12CommandLib.h>
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send TPM_ContinueSelfTest command to TPM.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Operation completed successfully.
|
||||||
|
@retval EFI_TIMEOUT The register can't run into the expected status in time.
|
||||||
|
@retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
|
||||||
|
@retval EFI_DEVICE_ERROR Unexpected device behavior.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
Tpm12ContinueSelfTest (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
TPM_RQU_COMMAND_HDR Command;
|
||||||
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
|
UINT32 Length;
|
||||||
|
|
||||||
|
//
|
||||||
|
// send Tpm command TPM_ORD_ContinueSelfTest
|
||||||
|
//
|
||||||
|
Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
|
Command.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
|
Command.ordinal = SwapBytes32 (TPM_ORD_ContinueSelfTest);
|
||||||
|
return Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
}
|
@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <Uefi.h>
|
#include <PiPei.h>
|
||||||
#include <IndustryStandard/Tpm12.h>
|
|
||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/Tpm12DeviceLib.h>
|
#include <Library/Tpm12DeviceLib.h>
|
||||||
@ -25,18 +24,6 @@ typedef struct {
|
|||||||
TPM_STARTUP_TYPE TpmSt;
|
TPM_STARTUP_TYPE TpmSt;
|
||||||
} TPM_CMD_START_UP;
|
} TPM_CMD_START_UP;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RSP_COMMAND_HDR Hdr;
|
|
||||||
} TPM_RSP_START_UP;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RQU_COMMAND_HDR Hdr;
|
|
||||||
} TPM_CMD_SAVE_STATE;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TPM_RSP_COMMAND_HDR Hdr;
|
|
||||||
} TPM_RSP_SAVE_STATE;
|
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,32 +37,27 @@ typedef struct {
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
Tpm12Startup (
|
Tpm12Startup (
|
||||||
IN TPM_STARTUP_TYPE TpmSt
|
IN TPM_STARTUP_TYPE TpmSt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 TpmRecvSize;
|
TPM_CMD_START_UP Command;
|
||||||
UINT32 TpmSendSize;
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
TPM_CMD_START_UP SendBuffer;
|
UINT32 Length;
|
||||||
TPM_RSP_START_UP RecvBuffer;
|
|
||||||
UINT32 ReturnCode;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// send Tpm command TPM_ORD_Startup
|
// send Tpm command TPM_ORD_Startup
|
||||||
//
|
//
|
||||||
TpmRecvSize = sizeof (TPM_RSP_START_UP);
|
Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
TpmSendSize = sizeof (TPM_CMD_START_UP);
|
Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_Startup);
|
||||||
SendBuffer.Hdr.paramSize = SwapBytes32 (TpmSendSize);
|
Command.TpmSt = SwapBytes16 (TpmSt);
|
||||||
SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_Startup);
|
Length = sizeof (Response);
|
||||||
SendBuffer.TpmSt = SwapBytes16 (TpmSt);
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
|
||||||
Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
|
switch (SwapBytes32(Response.returnCode)) {
|
||||||
switch (ReturnCode) {
|
|
||||||
case TPM_SUCCESS:
|
case TPM_SUCCESS:
|
||||||
case TPM_INVALID_POSTINIT:
|
case TPM_INVALID_POSTINIT:
|
||||||
// In warm reset, TPM may response TPM_INVALID_POSTINIT
|
// In warm reset, TPM may response TPM_INVALID_POSTINIT
|
||||||
@ -97,28 +79,23 @@ Tpm12SaveState (
|
|||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 TpmRecvSize;
|
TPM_RQU_COMMAND_HDR Command;
|
||||||
UINT32 TpmSendSize;
|
TPM_RSP_COMMAND_HDR Response;
|
||||||
TPM_CMD_SAVE_STATE SendBuffer;
|
UINT32 Length;
|
||||||
TPM_RSP_SAVE_STATE RecvBuffer;
|
|
||||||
UINT32 ReturnCode;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// send Tpm command TPM_ORD_SaveState
|
// send Tpm command TPM_ORD_SaveState
|
||||||
//
|
//
|
||||||
TpmRecvSize = sizeof (TPM_RSP_SAVE_STATE);
|
Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
||||||
TpmSendSize = sizeof (TPM_CMD_SAVE_STATE);
|
Command.paramSize = SwapBytes32 (sizeof (Command));
|
||||||
SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
|
Command.ordinal = SwapBytes32 (TPM_ORD_SaveState);
|
||||||
SendBuffer.Hdr.paramSize = SwapBytes32 (TpmSendSize);
|
Length = sizeof (Response);
|
||||||
SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_SaveState);
|
Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
|
||||||
|
|
||||||
Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
|
switch (SwapBytes32 (Response.returnCode)) {
|
||||||
switch (ReturnCode) {
|
|
||||||
case TPM_SUCCESS:
|
case TPM_SUCCESS:
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user