SecurityPkg: TcgConfigDxe: Move TPM state string update to CallBack function
authorZhang, Chao B <chao.b.zhang@intel.com>
Mon, 22 Feb 2016 05:51:53 +0000 (13:51 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Mon, 22 Feb 2016 06:19:04 +0000 (14:19 +0800)
TPM state string update requires HiiHandle which may not be initialized when calling ExtractConfig.
Move this logic to CallBack function.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Dandan Bi <dandan.bi@intel.com>
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h

index 29ec7b06213ffdda59a2206979bfa5f10690f908..a9d310545630a1b8f941fb59bb8578fb0e16979a 100644 (file)
@@ -73,9 +73,15 @@ TcgConfigDriverEntryPoint (
   if (PrivateData == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
+  PrivateData->Configuration = AllocatePool (sizeof (TCG_CONFIGURATION));\r
+  if (PrivateData->Configuration == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
   PrivateData->TcgProtocol = TcgProtocol;\r
-  \r
+\r
   //\r
   // Install TCG configuration form\r
   //\r
index c2e3b34a25e3cad2a65c3060cb8b8b984cfc2cd2..7fa5611cfd9476f3d0010df977216f9e6ca6fab0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HII Config Access protocol implementation of TCG configuration module.\r
 \r
-Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 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
@@ -149,8 +149,6 @@ TcgExtractConfig (
   )\r
 {\r
   EFI_STATUS                 Status;\r
-  UINTN                      BufferSize;\r
-  TCG_CONFIGURATION          Configuration;\r
   TCG_CONFIG_PRIVATE_DATA    *PrivateData;\r
   EFI_STRING                 ConfigRequestHdr;\r
   EFI_STRING                 ConfigRequest;\r
@@ -158,7 +156,6 @@ TcgExtractConfig (
   UINTN                      Size;\r
   BOOLEAN                    TpmEnable;\r
   BOOLEAN                    TpmActivate;\r
-  CHAR16                     State[32];\r
 \r
   if (Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -179,12 +176,10 @@ TcgExtractConfig (
   //\r
   // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
   //  \r
-  ZeroMem (&Configuration, sizeof (TCG_CONFIGURATION));\r
-\r
-  Configuration.TpmOperation    = PHYSICAL_PRESENCE_ENABLE;\r
+  PrivateData->Configuration->TpmOperation = PHYSICAL_PRESENCE_ENABLE;\r
 \r
   //\r
-  // Display current TPM state.\r
+  // Get current TPM state.\r
   //\r
   if (PrivateData->TcgProtocol != NULL) {\r
     Status = GetTpmState (PrivateData->TcgProtocol, &TpmEnable, &TpmActivate);\r
@@ -192,20 +187,10 @@ TcgExtractConfig (
       return Status;\r
     }\r
 \r
-    UnicodeSPrint (\r
-      State,\r
-      sizeof (State),\r
-      L"%s, and %s",\r
-      TpmEnable   ? L"Enabled"   : L"Disabled",\r
-      TpmActivate ? L"Activated" : L"Deactivated"\r
-      );\r
-    Configuration.TpmEnable   = TpmEnable;\r
-    Configuration.TpmActivate = TpmActivate;\r
-\r
-    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM_STATE_CONTENT), State, NULL);\r
+    PrivateData->Configuration->TpmEnable   = TpmEnable;\r
+    PrivateData->Configuration->TpmActivate = TpmActivate;\r
   }\r
 \r
-  BufferSize = sizeof (Configuration);\r
   ConfigRequest = Request;\r
   if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
     //\r
@@ -218,15 +203,15 @@ TcgExtractConfig (
     ConfigRequest = AllocateZeroPool (Size);\r
     ASSERT (ConfigRequest != NULL);\r
     AllocatedRequest = TRUE;\r
-    UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64) BufferSize);\r
+    UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, sizeof (TCG_CONFIGURATION));\r
     FreePool (ConfigRequestHdr);\r
   }\r
 \r
   Status = gHiiConfigRouting->BlockToConfig (\r
                                 gHiiConfigRouting,\r
                                 ConfigRequest,\r
-                                (UINT8 *) &Configuration,\r
-                                BufferSize,\r
+                                (UINT8 *) PrivateData->Configuration,\r
+                                sizeof (TCG_CONFIGURATION),\r
                                 Results,\r
                                 Progress\r
                                 );\r
@@ -386,10 +371,29 @@ TcgCallback (
      OUT EFI_BROWSER_ACTION_REQUEST            *ActionRequest\r
   )\r
 {\r
+  TCG_CONFIG_PRIVATE_DATA    *PrivateData;\r
+  CHAR16                     State[32];\r
+\r
   if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
+    if (QuestionId == KEY_TPM_ACTION) {\r
+\r
+      PrivateData = TCG_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
+      UnicodeSPrint (\r
+        State,\r
+        sizeof (State),\r
+        L"%s, and %s",\r
+        PrivateData->Configuration->TpmEnable   ? L"Enabled"   : L"Disabled",\r
+        PrivateData->Configuration->TpmActivate ? L"Activated" : L"Deactivated"\r
+        );\r
+      HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM_STATE_CONTENT), State, NULL);\r
+    }\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if ((Action != EFI_BROWSER_ACTION_CHANGED) || (QuestionId != KEY_TPM_ACTION)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -497,6 +501,9 @@ UninstallTcgConfigForm (
            );\r
     PrivateData->DriverHandle = NULL;\r
   }\r
-  \r
+\r
+  if (PrivateData->Configuration != NULL) {\r
+    FreePool(PrivateData->Configuration);\r
+  }\r
   FreePool (PrivateData);\r
 }\r
index acc6062a9b3501b0cb5d99b6711f05c6a414b0dc..a03abaa1ddef429c77d3c5c68ace8adfd4c9ccdd 100644 (file)
@@ -61,6 +61,7 @@ typedef struct {
   EFI_HII_HANDLE                    HiiHandle;\r
   EFI_HANDLE                        DriverHandle;  \r
 \r
+  TCG_CONFIGURATION                 *Configuration;\r
   EFI_TCG_PROTOCOL                  *TcgProtocol;\r
 } TCG_CONFIG_PRIVATE_DATA;\r
 \r