]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2CommandLib/Tpm2Startup.c
SecurityPkg: Add DEBUG messages for TPM2Startup
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Startup.c
index e8af4033ce81509d035e4b677ba7939a4bab79ff..dc2c5628f9201caac3259a3a286b7beb8c912a1d 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Implement TPM2 Startup related command.\r
 \r
-Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -59,6 +60,7 @@ Tpm2Startup (
   TPM2_STARTUP_COMMAND              Cmd;\r
   TPM2_STARTUP_RESPONSE             Res;\r
   UINT32                            ResultBufSize;\r
+  TPM_RC                            ResponseCode;\r
 \r
   Cmd.Header.tag         = SwapBytes16(TPM_ST_NO_SESSIONS);\r
   Cmd.Header.paramSize   = SwapBytes32(sizeof(Cmd));\r
@@ -67,8 +69,23 @@ Tpm2Startup (
 \r
   ResultBufSize = sizeof(Res);\r
   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
-\r
-  return Status;\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ResponseCode = SwapBytes32(Res.Header.responseCode);\r
+  switch (ResponseCode)  {\r
+  case TPM_RC_SUCCESS:\r
+    DEBUG ((DEBUG_INFO, "TPM2Startup: TPM_RC_SUCCESS\n"));\r
+    return EFI_SUCCESS;\r
+  case TPM_RC_INITIALIZE:\r
+    // TPM_RC_INITIALIZE can be returned if Tpm2Startup is not required.\r
+    DEBUG ((DEBUG_INFO, "TPM2Startup: TPM_RC_INITIALIZE\n"));\r
+    return EFI_SUCCESS;\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "Tpm2Startup: Response Code error! 0x%08x\r\n", ResponseCode));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
 }\r
 \r
 /**\r
@@ -97,6 +114,14 @@ Tpm2Shutdown (
 \r
   ResultBufSize = sizeof(Res);\r
   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (SwapBytes32(Res.Header.responseCode) != TPM_RC_SUCCESS) {\r
+    DEBUG ((EFI_D_ERROR, "Tpm2Shutdown: Response Code error! 0x%08x\r\n", SwapBytes32(Res.Header.responseCode)));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r