Reviewed-by: Dandan Bi <dandan...@intel.com>

-----Original Message-----
From: Zhang, Chao B 
Sent: Friday, January 29, 2016 4:47 PM
To: edk2-de...@ml01.01.org
Cc: Yao, Jiewen; Bi, Dandan; Zhang, Chao B
Subject: [PATCH] SecurityPkg: TcgConfigDxe: Move TPM state string update to 
CallBack function

TPM state string update requires HiiHandle which may not be ready when calling 
ExtractConfig.
Move this logic to CallBack function.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chao Zhang <chao.b.zh...@intel.com>
---
 SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c | 10 ++++-
 SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c   | 55 +++++++++++++++-----------
 SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h   |  1 +
 3 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c 
b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
index 29ec7b0..a9d3105 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
@@ -73,9 +73,15 @@ TcgConfigDriverEntryPoint (
   if (PrivateData == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
-  
+
+  PrivateData->Configuration = AllocatePool (sizeof 
+ (TCG_CONFIGURATION));  if (PrivateData->Configuration == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrorExit;
+  }
+
   PrivateData->TcgProtocol = TcgProtocol;
-  
+
   //
   // Install TCG configuration form
   //
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c 
b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
index c2e3b34..7fa5611 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
@@ -1,7 +1,7 @@
 /** @file
   HII Config Access protocol implementation of TCG configuration module.
 
-Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available 
under the terms and conditions of the BSD License  which accompanies this 
distribution.  The full text of the license may be found at @@ -149,8 +149,6 @@ 
TcgExtractConfig (
   )
 {
   EFI_STATUS                 Status;
-  UINTN                      BufferSize;
-  TCG_CONFIGURATION          Configuration;
   TCG_CONFIG_PRIVATE_DATA    *PrivateData;
   EFI_STRING                 ConfigRequestHdr;
   EFI_STRING                 ConfigRequest;
@@ -158,7 +156,6 @@ TcgExtractConfig (
   UINTN                      Size;
   BOOLEAN                    TpmEnable;
   BOOLEAN                    TpmActivate;
-  CHAR16                     State[32];
 
   if (Progress == NULL || Results == NULL) {
     return EFI_INVALID_PARAMETER;
@@ -179,12 +176,10 @@ TcgExtractConfig (
   //
   // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
   //
-  ZeroMem (&Configuration, sizeof (TCG_CONFIGURATION));
-
-  Configuration.TpmOperation    = PHYSICAL_PRESENCE_ENABLE;
+  PrivateData->Configuration->TpmOperation = PHYSICAL_PRESENCE_ENABLE;
 
   //
-  // Display current TPM state.
+  // Get current TPM state.
   //
   if (PrivateData->TcgProtocol != NULL) {
     Status = GetTpmState (PrivateData->TcgProtocol, &TpmEnable, &TpmActivate);
@@ -192,20 +187,10 @@ TcgExtractConfig (
       return Status;
     }
 
-    UnicodeSPrint (
-      State,
-      sizeof (State),
-      L"%s, and %s",
-      TpmEnable   ? L"Enabled"   : L"Disabled",
-      TpmActivate ? L"Activated" : L"Deactivated"
-      );
-    Configuration.TpmEnable   = TpmEnable;
-    Configuration.TpmActivate = TpmActivate;
-
-    HiiSetString (PrivateData->HiiHandle, STRING_TOKEN 
(STR_TPM_STATE_CONTENT), State, NULL);
+    PrivateData->Configuration->TpmEnable   = TpmEnable;
+    PrivateData->Configuration->TpmActivate = TpmActivate;
   }
 
-  BufferSize = sizeof (Configuration);
   ConfigRequest = Request;
   if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
     //
@@ -218,15 +203,15 @@ TcgExtractConfig (
     ConfigRequest = AllocateZeroPool (Size);
     ASSERT (ConfigRequest != NULL);
     AllocatedRequest = TRUE;
-    UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", 
ConfigRequestHdr, (UINT64) BufferSize);
+    UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", 
ConfigRequestHdr, sizeof (TCG_CONFIGURATION));
     FreePool (ConfigRequestHdr);
   }
 
   Status = gHiiConfigRouting->BlockToConfig (
                                 gHiiConfigRouting,
                                 ConfigRequest,
-                                (UINT8 *) &Configuration,
-                                BufferSize,
+                                (UINT8 *) PrivateData->Configuration,
+                                sizeof (TCG_CONFIGURATION),
                                 Results,
                                 Progress
                                 );
@@ -386,10 +371,29 @@ TcgCallback (
      OUT EFI_BROWSER_ACTION_REQUEST            *ActionRequest
   )
 {
+  TCG_CONFIG_PRIVATE_DATA    *PrivateData;
+  CHAR16                     State[32];
+
   if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
 
+  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
+    if (QuestionId == KEY_TPM_ACTION) {
+
+      PrivateData = TCG_CONFIG_PRIVATE_DATA_FROM_THIS (This);
+      UnicodeSPrint (
+        State,
+        sizeof (State),
+        L"%s, and %s",
+        PrivateData->Configuration->TpmEnable   ? L"Enabled"   : L"Disabled",
+        PrivateData->Configuration->TpmActivate ? L"Activated" : L"Deactivated"
+        );
+      HiiSetString (PrivateData->HiiHandle, STRING_TOKEN 
(STR_TPM_STATE_CONTENT), State, NULL);
+    }
+    return EFI_SUCCESS;
+  }
+
   if ((Action != EFI_BROWSER_ACTION_CHANGED) || (QuestionId != 
KEY_TPM_ACTION)) {
     return EFI_UNSUPPORTED;
   }
@@ -497,6 +501,9 @@ UninstallTcgConfigForm (
            );
     PrivateData->DriverHandle = NULL;
   }
-  
+
+  if (PrivateData->Configuration != NULL) {
+    FreePool(PrivateData->Configuration);
+  }
   FreePool (PrivateData);
 }
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h 
b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h
index acc6062..a03abaa 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h
@@ -61,6 +61,7 @@ typedef struct {
   EFI_HII_HANDLE                    HiiHandle;
   EFI_HANDLE                        DriverHandle;  
 
+  TCG_CONFIGURATION                 *Configuration;
   EFI_TCG_PROTOCOL                  *TcgProtocol;
 } TCG_CONFIG_PRIVATE_DATA;
 
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to