]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
SecurityPkg/Tpm12CommandLib: Add TPM 1.2 commands used by TCG modules
[mirror_edk2.git] / SecurityPkg / Library / Tpm12CommandLib / Tpm12GetCapability.c
diff --git a/SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c b/SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
new file mode 100644 (file)
index 0000000..c33746a
--- /dev/null
@@ -0,0 +1,127 @@
+/** @file\r
+  Implement TPM1.2 Get Capabilities related commands.\r
+\r
+Copyright (c) 2016, Intel Corporation. All rights reserved. <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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Library/Tpm12CommandLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/Tpm12DeviceLib.h>\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  TPM_RQU_COMMAND_HDR  Hdr;\r
+  UINT32               Capability;\r
+  UINT32               CapabilityFlagSize;\r
+  UINT32               CapabilityFlag;\r
+} TPM_CMD_GET_CAPABILITY;\r
+\r
+typedef struct {\r
+  TPM_RSP_COMMAND_HDR  Hdr;\r
+  UINT32               ResponseSize;\r
+  TPM_PERMANENT_FLAGS  Flags;\r
+} TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS;\r
+\r
+typedef struct {\r
+  TPM_RSP_COMMAND_HDR  Hdr;\r
+  UINT32               ResponseSize;\r
+  TPM_STCLEAR_FLAGS    Flags;\r
+} TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS;\r
+\r
+#pragma pack()\r
+\r
+/**\r
+Get TPM capability permanent flags.\r
+\r
+@param[out] TpmPermanentFlags   Pointer to the buffer for returned flag structure.\r
+\r
+@retval EFI_SUCCESS           Operation completed successfully.\r
+@retval EFI_TIMEOUT           The register can't run into the expected status in time.\r
+@retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.\r
+@retval EFI_DEVICE_ERROR      Unexpected device behavior.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm12GetCapabilityFlagPermanent (\r
+  OUT TPM_PERMANENT_FLAGS  *TpmPermanentFlags\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  TPM_CMD_GET_CAPABILITY                  Command;\r
+  TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS  Response;\r
+  UINT32                                  Length;\r
+\r
+  //\r
+  // send Tpm command TPM_ORD_GetCapability\r
+  //\r
+  Command.Hdr.tag            = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
+  Command.Hdr.paramSize      = SwapBytes32 (sizeof (Command));\r
+  Command.Hdr.ordinal        = SwapBytes32 (TPM_ORD_GetCapability);\r
+  Command.Capability         = SwapBytes32 (TPM_CAP_FLAG);\r
+  Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT));\r
+  Command.CapabilityFlag     = SwapBytes32 (TPM_CAP_FLAG_PERMANENT);\r
+  Length = sizeof (Response);\r
+  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));\r
+  CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), Response.ResponseSize));\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+Get TPM capability volatile flags.\r
+\r
+@param[out] VolatileFlags   Pointer to the buffer for returned flag structure.\r
+\r
+@retval EFI_SUCCESS      Operation completed successfully.\r
+@retval EFI_DEVICE_ERROR The command was unsuccessful.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm12GetCapabilityFlagVolatile (\r
+  OUT TPM_STCLEAR_FLAGS  *VolatileFlags\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  TPM_CMD_GET_CAPABILITY                Command;\r
+  TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS  Response;\r
+  UINT32                                Length;\r
+\r
+  //\r
+  // send Tpm command TPM_ORD_GetCapability\r
+  //\r
+  Command.Hdr.tag            = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
+  Command.Hdr.paramSize      = SwapBytes32 (sizeof (Command));\r
+  Command.Hdr.ordinal        = SwapBytes32 (TPM_ORD_GetCapability);\r
+  Command.Capability         = SwapBytes32 (TPM_CAP_FLAG);\r
+  Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_VOLATILE));\r
+  Command.CapabilityFlag     = SwapBytes32 (TPM_CAP_FLAG_VOLATILE);\r
+  Length = sizeof (Response);\r
+  Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ZeroMem (VolatileFlags, sizeof (*VolatileFlags));\r
+  CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), Response.ResponseSize));\r
+\r
+  return Status;\r
+}\r