]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
SecurityPkg/SmmTcg2PhysicalPresenceLib: Fix coding style issue
[mirror_edk2.git] / SecurityPkg / Library / SmmTcg2PhysicalPresenceLib / SmmTcg2PhysicalPresenceLib.c
index e3f7150ee0fcda915a1194243035f19ec6ecc315..6a4dce919845c47f6f53c1b497c7b2ca691899b2 100644 (file)
@@ -10,7 +10,7 @@
   Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()\r
   will receive untrusted input and do validation.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, 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
@@ -27,13 +27,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Protocol/SmmVariable.h>\r
 \r
+#include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/Tcg2PpVendorLib.h>\r
 #include <Library/SmmServicesTableLib.h>\r
-#include <Library/TcgPhysicalPresenceStorageLib.h>\r
+\r
+#define     PP_INF_VERSION_1_2    "1.2"\r
 \r
 EFI_SMM_VARIABLE_PROTOCOL  *mTcg2PpSmmVariable;\r
+BOOLEAN                    mIsTcg2PPVerLowerThan_1_3 = FALSE;\r
 \r
 /**\r
   The handler for TPM physical presence function:\r
@@ -130,13 +133,8 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
     goto EXIT;\r
   }\r
 \r
-  if (((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) &&\r
-       (*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN))||\r
-      ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE) &&\r
-       (*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN))) {\r
-    //\r
-    // This command requires UI to prompt user for Auth data.\r
-    //\r
+  if ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) &&\r
+      (*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN) ) {\r
     ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED;\r
     goto EXIT;\r
   }\r
@@ -153,12 +151,11 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
                                    DataSize,\r
                                    &PpData\r
                                    );\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) { \r
-    DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));\r
-    ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;\r
-    goto EXIT;\r
+    if (EFI_ERROR (Status)) { \r
+      DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));\r
+      ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;\r
+      goto EXIT;\r
+    }\r
   }\r
 \r
   if (*OperationRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {\r
@@ -171,7 +168,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
                                    &Flags\r
                                    );\r
     if (EFI_ERROR (Status)) {\r
-      Flags.PPFlags = TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT;\r
+      Flags.PPFlags = TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT | TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_DEFAULT;\r
     }\r
     ReturnCode = Tcg2PpVendorLibSubmitRequestToPreOSFunction (*OperationRequest, Flags.PPFlags, *RequestParameter);\r
   }\r
@@ -247,13 +244,12 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
   IN UINT32                 OperationRequest\r
   )\r
 {\r
-  EFI_STATUS                               Status;\r
-  UINTN                                    DataSize;\r
-  EFI_TCG2_PHYSICAL_PRESENCE               PpData;\r
-  EFI_TCG2_PHYSICAL_PRESENCE_FLAGS         Flags;\r
-  UINT32                                   StorageFlags;\r
-  BOOLEAN                                  RequestConfirmed;\r
-\r
+  EFI_STATUS                        Status;\r
+  UINTN                             DataSize;\r
+  EFI_TCG2_PHYSICAL_PRESENCE        PpData;\r
+  EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;\r
+  BOOLEAN                           RequestConfirmed;\r
+  \r
   DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));\r
 \r
   //\r
@@ -287,11 +283,6 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
     return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;\r
   }\r
 \r
-  //\r
-  // Get the Physical Presence storage flags\r
-  //\r
-  StorageFlags = TcgPhysicalPresenceStorageLibReturnStorageFlags();\r
-\r
   RequestConfirmed = FALSE;\r
 \r
   switch (OperationRequest) {\r
@@ -304,6 +295,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
       }\r
       break;\r
 \r
+    case TCG2_PHYSICAL_PRESENCE_NO_ACTION:\r
     case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_TRUE:\r
       RequestConfirmed = TRUE;\r
       break;\r
@@ -328,28 +320,43 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
       break;\r
 \r
     case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID:\r
-      if ((StorageFlags & TCG_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) {\r
+      if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) {\r
         RequestConfirmed = TRUE;\r
       }\r
       break;\r
 \r
     case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID:\r
-      if ((StorageFlags & TCG_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) {\r
+      if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) {\r
         RequestConfirmed = TRUE;\r
       }\r
       break;\r
 \r
     case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE:\r
     case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE:\r
+      RequestConfirmed = TRUE;\r
+      break;\r
+\r
+    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE:\r
+    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE:\r
       break;\r
 \r
     default:\r
-      if (OperationRequest <= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) {\r
-        RequestConfirmed = TRUE;\r
-      } else {\r
+      if (!mIsTcg2PPVerLowerThan_1_3) {\r
         if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {\r
+          //\r
+          // TCG2 PP1.3 spec defined operations that are reserved or un-implemented\r
+          //\r
           return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;\r
         }\r
+      } else {\r
+       //\r
+       // TCG PP lower than 1.3. (1.0, 1.1, 1.2)\r
+       //\r
+       if (OperationRequest <= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) {\r
+         RequestConfirmed = TRUE;\r
+       } else if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {\r
+         return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;\r
+       }\r
       }\r
       break;\r
   }\r
@@ -366,7 +373,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
 }\r
 \r
 /**\r
-  The constructor function register UNI strings into imageHandle.\r
+  The constructor function locates SmmVariable protocol.\r
   \r
   It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
 \r
@@ -385,6 +392,10 @@ Tcg2PhysicalPresenceLibConstructor (
 {\r
   EFI_STATUS  Status;\r
 \r
+  if (AsciiStrnCmp(PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer), sizeof(PP_INF_VERSION_1_2) - 1) <= 0) {\r
+    mIsTcg2PPVerLowerThan_1_3 = TRUE;\r
+  }\r
+\r
   //\r
   // Locate SmmVariableProtocol.\r
   //\r