Esempio n. 1
0
/**
  Send ForceClear command to TPM1.2.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12ForceClear (
  VOID
  )
{
  EFI_STATUS                        Status;
  UINT32                            TpmRecvSize;
  UINT32                            TpmSendSize;
  TPM_CMD_FORCE_CLEAR               SendBuffer;
  TPM_RSP_FORCE_CLEAR               RecvBuffer;
  UINT32                            ReturnCode;

  //
  // send Tpm command TPM_ORD_ForceClear
  //
  TpmRecvSize               = sizeof (TPM_RSP_FORCE_CLEAR);
  TpmSendSize               = sizeof (TPM_CMD_FORCE_CLEAR);
  SendBuffer.Hdr.tag        = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  SendBuffer.Hdr.paramSize  = SwapBytes32 (TpmSendSize);
  SendBuffer.Hdr.ordinal    = SwapBytes32 (TPM_ORD_ForceClear);

  Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
  switch (ReturnCode) {
  case TPM_SUCCESS:
    return EFI_SUCCESS;
  default:
    return EFI_DEVICE_ERROR;
  }
}
Esempio n. 2
0
File: Tpm12Pcr.c Progetto: jyao1/STM
/**
Read a TPM PCR.

@param[in]  PcrIndex          The PCR to be read.
@param[out] PcrValue          PCR value.

@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
Tpm12PcrRead (
  IN  TPM_PCRINDEX  PcrIndex,
  OUT TPM_DIGEST    *PcrValue
  )
{
  EFI_STATUS        Status;
  TPM_CMD_PCR_READ  Command;
  TPM_RSP_PCR_READ  Response;
  UINT32            Length;

  //
  // send Tpm command TPM_ORD_PcrRead
  //
  Command.Hdr.tag = SwapBytes16(TPM_TAG_RQU_COMMAND);
  Command.Hdr.paramSize = SwapBytes32(sizeof(Command));
  Command.Hdr.ordinal = SwapBytes32(TPM_ORD_PcrRead);
  Command.PcrIndex = SwapBytes32(PcrIndex);
  Length = sizeof(Response);
  Status = Tpm12SubmitCommand(sizeof(Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
  if (EFI_ERROR(Status)) {
    return Status;
  }

  if (Response.Hdr.returnCode != 0) {
    return EFI_DEVICE_ERROR;
  }

  if (PcrValue != NULL) {
    CopyMem(PcrValue, &Response.TpmDigest, sizeof(*PcrValue));
  }

  return Status;
}
Esempio n. 3
0
File: Tpm12Pcr.c Progetto: jyao1/STM
/**
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;
}
Esempio n. 4
0
/**
  Send ForceClear command to TPM1.2.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12ForceClear (
  VOID
  )
{
  EFI_STATUS           Status;
  TPM_RQU_COMMAND_HDR  Command;
  TPM_RSP_COMMAND_HDR  Response;
  UINT32               Length;

  //
  // send Tpm command TPM_ORD_ForceClear
  //
  Command.tag        = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  Command.paramSize  = SwapBytes32 (sizeof (Command));
  Command.ordinal    = SwapBytes32 (TPM_ORD_ForceClear);
  Length = sizeof (Response);

  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  switch (SwapBytes32 (Response.returnCode)) {
  case TPM_SUCCESS:
    return EFI_SUCCESS;
  default:
    return EFI_DEVICE_ERROR;
  }
}
Esempio n. 5
0
/**
  Send NV DefineSpace command to TPM1.2.
  
  @param PubInfo           The public parameters of the NV area.
  @param EncAuth           The encrypted AuthData, only valid if the attributes require subsequent authorization.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12NvDefineSpace (
  IN TPM12_NV_DATA_PUBLIC  *PubInfo,
  IN TPM_ENCAUTH           *EncAuth
  )
{
  EFI_STATUS                        Status;
  UINT32                            TpmRecvSize;
  UINT32                            TpmSendSize;
  TPM_CMD_NV_DEFINE_SPACE           SendBuffer;
  TPM_RSP_NV_DEFINE_SPACE           RecvBuffer;
  UINT32                            ReturnCode;

  //
  // send Tpm command TPM_ORD_NV_DefineSpace
  //
  TpmRecvSize                = sizeof (TPM_RSP_NV_DEFINE_SPACE);
  TpmSendSize                = sizeof (TPM_CMD_NV_DEFINE_SPACE);
  SendBuffer.Hdr.tag         = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  SendBuffer.Hdr.paramSize   = SwapBytes32 (sizeof(TPM_CMD_NV_DEFINE_SPACE));
  SendBuffer.Hdr.ordinal     = SwapBytes32 (TPM_ORD_NV_DefineSpace);
  SendBuffer.PubInfo.tag     = SwapBytes16 (PubInfo->tag);
  SendBuffer.PubInfo.nvIndex = SwapBytes32 (PubInfo->nvIndex);
  SendBuffer.PubInfo.pcrInfoRead.pcrSelection.sizeOfSelect  = SwapBytes16 (PubInfo->pcrInfoRead.pcrSelection.sizeOfSelect);
  SendBuffer.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[0]  = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[0];
  SendBuffer.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[1]  = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[1];
  SendBuffer.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[2]  = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[2];
  SendBuffer.PubInfo.pcrInfoRead.localityAtRelease          = PubInfo->pcrInfoRead.localityAtRelease;
  CopyMem (&SendBuffer.PubInfo.pcrInfoRead.digestAtRelease, &PubInfo->pcrInfoRead.digestAtRelease, sizeof(PubInfo->pcrInfoRead.digestAtRelease));
  SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.sizeOfSelect = SwapBytes16 (PubInfo->pcrInfoWrite.pcrSelection.sizeOfSelect);
  SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[0] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[0];
  SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[1] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[1];
  SendBuffer.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[2] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[2];
  SendBuffer.PubInfo.pcrInfoWrite.localityAtRelease         = PubInfo->pcrInfoWrite.localityAtRelease;
  CopyMem (&SendBuffer.PubInfo.pcrInfoWrite.digestAtRelease, &PubInfo->pcrInfoWrite.digestAtRelease, sizeof(PubInfo->pcrInfoWrite.digestAtRelease));
  SendBuffer.PubInfo.permission.tag        = SwapBytes16 (PubInfo->permission.tag);
  SendBuffer.PubInfo.permission.attributes = SwapBytes32 (PubInfo->permission.attributes);
  SendBuffer.PubInfo.bReadSTClear          = PubInfo->bReadSTClear;
  SendBuffer.PubInfo.bWriteSTClear         = PubInfo->bWriteSTClear;
  SendBuffer.PubInfo.bWriteDefine          = PubInfo->bWriteDefine;
  SendBuffer.PubInfo.dataSize              = SwapBytes32 (PubInfo->dataSize);
  CopyMem (&SendBuffer.EncAuth, EncAuth, sizeof(*EncAuth));

  Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
  DEBUG ((DEBUG_INFO, "Tpm12NvDefineSpace - ReturnCode = %x\n", ReturnCode));
  switch (ReturnCode) {
  case TPM_SUCCESS:
    break;
  default:
    return EFI_DEVICE_ERROR;
  }

  return EFI_SUCCESS;
}
Esempio n. 6
0
/**
  Send NV DefineSpace command to TPM1.2.
  
  @param PubInfo           The public parameters of the NV area.
  @param EncAuth           The encrypted AuthData, only valid if the attributes require subsequent authorization.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12NvDefineSpace (
  IN TPM12_NV_DATA_PUBLIC  *PubInfo,
  IN TPM_ENCAUTH           *EncAuth
  )
{
  EFI_STATUS               Status;
  TPM_CMD_NV_DEFINE_SPACE  Command;
  TPM_RSP_COMMAND_HDR      Response;
  UINT32                   Length;

  //
  // send Tpm command TPM_ORD_NV_DefineSpace
  //
  Command.Hdr.tag         = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  Command.Hdr.paramSize   = SwapBytes32 (sizeof (Command));
  Command.Hdr.ordinal     = SwapBytes32 (TPM_ORD_NV_DefineSpace);
  Command.PubInfo.tag     = SwapBytes16 (PubInfo->tag);
  Command.PubInfo.nvIndex = SwapBytes32 (PubInfo->nvIndex);
  Command.PubInfo.pcrInfoRead.pcrSelection.sizeOfSelect  = SwapBytes16 (PubInfo->pcrInfoRead.pcrSelection.sizeOfSelect);
  Command.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[0]  = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[0];
  Command.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[1]  = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[1];
  Command.PubInfo.pcrInfoRead.pcrSelection.pcrSelect[2]  = PubInfo->pcrInfoRead.pcrSelection.pcrSelect[2];
  Command.PubInfo.pcrInfoRead.localityAtRelease          = PubInfo->pcrInfoRead.localityAtRelease;
  CopyMem (&Command.PubInfo.pcrInfoRead.digestAtRelease, &PubInfo->pcrInfoRead.digestAtRelease, sizeof(PubInfo->pcrInfoRead.digestAtRelease));
  Command.PubInfo.pcrInfoWrite.pcrSelection.sizeOfSelect = SwapBytes16 (PubInfo->pcrInfoWrite.pcrSelection.sizeOfSelect);
  Command.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[0] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[0];
  Command.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[1] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[1];
  Command.PubInfo.pcrInfoWrite.pcrSelection.pcrSelect[2] = PubInfo->pcrInfoWrite.pcrSelection.pcrSelect[2];
  Command.PubInfo.pcrInfoWrite.localityAtRelease         = PubInfo->pcrInfoWrite.localityAtRelease;
  CopyMem (&Command.PubInfo.pcrInfoWrite.digestAtRelease, &PubInfo->pcrInfoWrite.digestAtRelease, sizeof(PubInfo->pcrInfoWrite.digestAtRelease));
  Command.PubInfo.permission.tag        = SwapBytes16 (PubInfo->permission.tag);
  Command.PubInfo.permission.attributes = SwapBytes32 (PubInfo->permission.attributes);
  Command.PubInfo.bReadSTClear          = PubInfo->bReadSTClear;
  Command.PubInfo.bWriteSTClear         = PubInfo->bWriteSTClear;
  Command.PubInfo.bWriteDefine          = PubInfo->bWriteDefine;
  Command.PubInfo.dataSize              = SwapBytes32 (PubInfo->dataSize);
  CopyMem (&Command.EncAuth, EncAuth, sizeof(*EncAuth));
  Length = sizeof (Response);
  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  DEBUG ((DEBUG_INFO, "Tpm12NvDefineSpace - ReturnCode = %x\n", SwapBytes32 (Response.returnCode)));
  switch (SwapBytes32 (Response.returnCode)) {
  case TPM_SUCCESS:
    return EFI_SUCCESS;
  default:
    return EFI_DEVICE_ERROR;
  }
}
Esempio n. 7
0
/**
  Send NV ReadValue command to TPM1.2.

  @param NvIndex           The index of the area to set.
  @param Offset            The offset into the area.
  @param DataSize          The size of the data area.
  @param Data              The data to set the area to.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12NvReadValue (
  IN TPM_NV_INDEX   NvIndex,
  IN UINT32         Offset,
  IN OUT UINT32     *DataSize,
  OUT UINT8         *Data
  )
{
  EFI_STATUS                        Status;
  UINT32                            TpmRecvSize;
  UINT32                            TpmSendSize;
  TPM_CMD_NV_READ_VALUE             SendBuffer;
  TPM_RSP_NV_READ_VALUE             RecvBuffer;
  UINT32                            ReturnCode;

  //
  // send Tpm command TPM_ORD_NV_ReadValue
  //
  TpmRecvSize               = sizeof (TPM_RSP_NV_READ_VALUE);
  TpmSendSize               = sizeof (TPM_CMD_NV_READ_VALUE);
  SendBuffer.Hdr.tag        = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  SendBuffer.Hdr.paramSize  = SwapBytes32 (sizeof(TPM_CMD_NV_READ_VALUE));
  SendBuffer.Hdr.ordinal    = SwapBytes32 (TPM_ORD_NV_ReadValue);
  SendBuffer.NvIndex        = SwapBytes32 (NvIndex);
  SendBuffer.Offset         = SwapBytes32 (Offset);
  SendBuffer.DataSize       = SwapBytes32 (*DataSize);

  Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
  DEBUG ((DEBUG_INFO, "Tpm12NvReadValue - ReturnCode = %x\n", ReturnCode));
  switch (ReturnCode) {
  case TPM_SUCCESS:
    break;
  default:
    return EFI_DEVICE_ERROR;
  }

  //
  // Return the response
  //
  *DataSize = SwapBytes32(RecvBuffer.DataSize);
  CopyMem (Data, &RecvBuffer.Data, *DataSize);

  return EFI_SUCCESS;
}
Esempio n. 8
0
/**
  Send NV ReadValue command to TPM1.2.

  @param NvIndex           The index of the area to set.
  @param Offset            The offset into the area.
  @param DataSize          The size of the data area.
  @param Data              The data to set the area to.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12NvReadValue (
  IN TPM_NV_INDEX  NvIndex,
  IN UINT32        Offset,
  IN OUT UINT32    *DataSize,
  OUT UINT8        *Data
  )
{
  EFI_STATUS             Status;
  TPM_CMD_NV_READ_VALUE  Command;
  TPM_RSP_NV_READ_VALUE  Response;
  UINT32                 Length;

  //
  // send Tpm command TPM_ORD_NV_ReadValue
  //
  Command.Hdr.tag       = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
  Command.Hdr.ordinal   = SwapBytes32 (TPM_ORD_NV_ReadValue);
  Command.NvIndex       = SwapBytes32 (NvIndex);
  Command.Offset        = SwapBytes32 (Offset);
  Command.DataSize      = SwapBytes32 (*DataSize);
  Length = sizeof (Response);
  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  DEBUG ((DEBUG_INFO, "Tpm12NvReadValue - ReturnCode = %x\n", SwapBytes32 (Response.Hdr.returnCode)));
  switch (SwapBytes32 (Response.Hdr.returnCode)) {
  case TPM_SUCCESS:
    break;
  default:
    return EFI_DEVICE_ERROR;
  }

  //
  // Return the response
  //
  if (SwapBytes32 (Response.DataSize) > *DataSize) {
    return EFI_BUFFER_TOO_SMALL;
  }
  *DataSize = SwapBytes32 (Response.DataSize);
  ZeroMem (Data, *DataSize);
  CopyMem (Data, &Response.Data, *DataSize);

  return EFI_SUCCESS;
}
Esempio n. 9
0
/**
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);
}
Esempio n. 10
0
/**
  Send NV WriteValue command to TPM1.2.
  
  @param NvIndex           The index of the area to set.
  @param Offset            The offset into the NV Area.
  @param DataSize          The size of the data parameter.
  @param Data              The data to set the area to.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12NvWriteValue (
  IN TPM_NV_INDEX  NvIndex,
  IN UINT32        Offset,
  IN UINT32        DataSize,
  IN UINT8         *Data
  )
{
  EFI_STATUS              Status;
  TPM_CMD_NV_WRITE_VALUE  Command;
  TPM_RSP_COMMAND_HDR     Response;
  UINT32                  Length;

  if (DataSize > sizeof (Command.Data)) {
    return EFI_UNSUPPORTED;
  }

  //
  // send Tpm command TPM_ORD_NV_WriteValue
  //
  Command.Hdr.tag       = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  Command.Hdr.paramSize = SwapBytes32 (sizeof (Command) - sizeof(Command.Data) + DataSize);
  Command.Hdr.ordinal   = SwapBytes32 (TPM_ORD_NV_WriteValue);
  Command.NvIndex       = SwapBytes32 (NvIndex);
  Command.Offset        = SwapBytes32 (Offset);
  Command.DataSize      = SwapBytes32 (DataSize);
  CopyMem (Command.Data, Data, DataSize);
  Length = sizeof (Response);
  Status = Tpm12SubmitCommand (Command.Hdr.paramSize, (UINT8 *)&Command, &Length, (UINT8 *)&Response);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  DEBUG ((DEBUG_INFO, "Tpm12NvWritedValue - ReturnCode = %x\n", SwapBytes32 (Response.returnCode)));
  switch (SwapBytes32 (Response.returnCode)) {
  case TPM_SUCCESS:
    return EFI_SUCCESS;
  default:
    return EFI_DEVICE_ERROR;
  }
}
Esempio n. 11
0
/**
  Send Startup command to TPM1.2.

  @param TpmSt           Startup Type.

  @retval EFI_SUCCESS      Operation completed successfully.
  @retval EFI_DEVICE_ERROR Unexpected device behavior.
**/
EFI_STATUS
EFIAPI
Tpm12Startup (
  IN TPM_STARTUP_TYPE          TpmSt
  )
{
  EFI_STATUS                        Status;
  UINT32                            TpmRecvSize;
  UINT32                            TpmSendSize;
  TPM_CMD_START_UP                  SendBuffer;
  TPM_RSP_START_UP                  RecvBuffer;
  UINT32                            ReturnCode;

  //
  // send Tpm command TPM_ORD_Startup
  //
  TpmRecvSize               = sizeof (TPM_RSP_START_UP);
  TpmSendSize               = sizeof (TPM_CMD_START_UP);
  SendBuffer.Hdr.tag        = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  SendBuffer.Hdr.paramSize  = SwapBytes32 (TpmSendSize);
  SendBuffer.Hdr.ordinal    = SwapBytes32 (TPM_ORD_Startup);
  SendBuffer.TpmSt          = SwapBytes16 (TpmSt);

  Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
  switch (ReturnCode) {
  case TPM_SUCCESS:
  case TPM_INVALID_POSTINIT:
    // In warm reset, TPM may response TPM_INVALID_POSTINIT
    return EFI_SUCCESS;
  default:
    return EFI_DEVICE_ERROR;
  }
}
/**
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;
  }

  if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {
    DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagPermanent: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));
    return EFI_DEVICE_ERROR;
  }

  ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));
  CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), SwapBytes32(Response.ResponseSize)));

  return Status;
}
Esempio n. 13
0
File: TcgDxe.c Progetto: OznOg/edk2
/**
  This service is a proxy for commands to the TPM.

  @param[in]  This                        Indicates the calling context
  @param[in]  TpmInputParameterBlockSize  Size of the TPM input parameter block
  @param[in]  TpmInputParameterBlock      Pointer to the TPM input parameter block
  @param[in]  TpmOutputParameterBlockSize Size of the TPM output parameter block
  @param[in]  TpmOutputParameterBlock     Pointer to the TPM output parameter block

  @retval     EFI_SUCCESS                 Operation completed successfully.
  @retval     EFI_INVALID_PARAMETER       Invalid ordinal.
  @retval     EFI_UNSUPPORTED             Current Task Priority Level  >= EFI_TPL_CALLBACK.
  @retval     EFI_TIMEOUT                 The TIS timed-out.
  
**/
EFI_STATUS
EFIAPI
TcgDxePassThroughToTpm (
  IN      EFI_TCG_PROTOCOL          *This,
  IN      UINT32                    TpmInputParameterBlockSize,
  IN      UINT8                     *TpmInputParameterBlock,
  IN      UINT32                    TpmOutputParameterBlockSize,
  IN      UINT8                     *TpmOutputParameterBlock
  )
{
  if (TpmInputParameterBlock == NULL || 
      TpmOutputParameterBlock == NULL || 
      TpmInputParameterBlockSize == 0 ||
      TpmOutputParameterBlockSize == 0) {
    return EFI_INVALID_PARAMETER;
  }

  return Tpm12SubmitCommand (
           TpmInputParameterBlockSize,
           TpmInputParameterBlock,
           &TpmOutputParameterBlockSize,
           TpmOutputParameterBlock
           );
}