]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
MdeModulePkg: Add match2 opcode support in SetupBrowserDxe and sample code in DriverS...
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
index 9751242fd2a29c68b52a542fc748c4bf671fd706..204c043ff45e9617935f68aadb8ef9f9e1f72079 100644 (file)
@@ -2,7 +2,7 @@
 This is an example of how a driver might export data to the HII protocol to be\r
 later utilized by the Setup Protocol\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, 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
@@ -18,12 +18,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define DISPLAY_ONLY_MY_ITEM  0x0002\r
 \r
-EFI_GUID   mFormSetGuid = FORMSET_GUID;\r
-EFI_GUID   mInventoryGuid = INVENTORY_GUID;\r
-\r
 CHAR16     VariableName[] = L"MyIfrNVData";\r
+CHAR16     MyEfiVar[] = L"MyEfiVar";\r
 EFI_HANDLE                      DriverHandle[2] = {NULL, NULL};\r
 DRIVER_SAMPLE_PRIVATE_DATA      *PrivateData = NULL;\r
+EFI_EVENT                       mEvent;\r
 \r
 HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath0 = {\r
   {\r
@@ -35,10 +34,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath0 = {
         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
       }\r
     },\r
-    //\r
-    // {C153B68D-EBFC-488e-B110-662867745B87}\r
-    //\r
-    { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } }\r
+    DRIVER_SAMPLE_FORMSET_GUID\r
   },\r
   {\r
     END_DEVICE_PATH_TYPE,\r
@@ -60,10 +56,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath1 = {
         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
       }\r
     },\r
-    //\r
-    // {06F37F07-0C48-40e9-8436-0A08A0BB76B0}\r
-    //\r
-    { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } }\r
+    DRIVER_SAMPLE_INVENTORY_GUID\r
   },\r
   {\r
     END_DEVICE_PATH_TYPE,\r
@@ -75,6 +68,158 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath1 = {
   }\r
 };\r
 \r
+/**\r
+  Add empty function for event process function.\r
+\r
+  @param Event    The Event need to be process\r
+  @param Context  The context of the event.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DriverSampleInternalEmptyFunction (\r
+  IN  EFI_EVENT Event,\r
+  IN  VOID      *Context\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Notification function for keystrokes.\r
+\r
+  @param[in] KeyData    The key that was pressed.\r
+\r
+  @retval EFI_SUCCESS   The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+NotificationFunction(\r
+  IN EFI_KEY_DATA *KeyData\r
+  )\r
+{\r
+  gBS->SignalEvent (mEvent);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to start monitoring for CTRL-C using SimpleTextInputEx. \r
+\r
+  @retval EFI_SUCCESS           The feature is enabled.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough mnemory available.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalStartMonitor(\r
+  VOID\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
+  EFI_KEY_DATA                      KeyData;\r
+  EFI_STATUS                        Status;\r
+  EFI_HANDLE                        *Handles;\r
+  UINTN                             HandleCount;\r
+  UINTN                             HandleIndex;\r
+  EFI_HANDLE                        NotifyHandle;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+              ByProtocol,\r
+              &gEfiSimpleTextInputExProtocolGuid,\r
+              NULL,\r
+              &HandleCount,\r
+              &Handles\r
+              );\r
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+    Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    KeyData.KeyState.KeyToggleState = 0;\r
+    KeyData.Key.ScanCode            = 0;\r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
+    KeyData.Key.UnicodeChar         = L'c';\r
+\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+    \r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to stop monitoring for CTRL-C using SimpleTextInputEx.  \r
+\r
+  @retval EFI_SUCCESS           The feature is enabled.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough mnemory available.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalStopMonitor(\r
+  VOID\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
+  EFI_STATUS                        Status;\r
+  EFI_HANDLE                        *Handles;\r
+  EFI_KEY_DATA                      KeyData;  \r
+  UINTN                             HandleCount;\r
+  UINTN                             HandleIndex;\r
+  EFI_HANDLE                        NotifyHandle;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                ByProtocol,\r
+                &gEfiSimpleTextInputExProtocolGuid,\r
+                NULL,\r
+                &HandleCount,\r
+                &Handles\r
+                );\r
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+    Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    KeyData.KeyState.KeyToggleState = 0;\r
+    KeyData.Key.ScanCode            = 0;\r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
+    KeyData.Key.UnicodeChar         = L'c';\r
+\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);\r
+    }\r
+\r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);\r
+    }\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   Encode the password using a simple algorithm.\r
 \r
@@ -138,7 +283,7 @@ ValidatePassword (
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   NULL,\r
                   &BufferSize,\r
                   &PrivateData->Configuration\r
@@ -231,7 +376,7 @@ SetPassword (
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   NULL,\r
                   &BufferSize,\r
                   &PrivateData->Configuration\r
@@ -243,7 +388,7 @@ SetPassword (
   //\r
   // Get user input password\r
   //\r
-  Password = &PrivateData->Configuration.WhatIsThePassword2[0];\r
+  Password = PrivateData->Configuration.WhatIsThePassword2;\r
   PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);\r
   ZeroMem (Password, PasswordSize);\r
 \r
@@ -263,7 +408,7 @@ SetPassword (
   //\r
   Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
   ASSERT (Configuration != NULL);\r
-  if (HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
+  if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
     //\r
     // Update password's clear text in the screen\r
     //\r
@@ -273,7 +418,7 @@ SetPassword (
     // Update uncommitted data of Browser\r
     //\r
     HiiSetBrowserData (\r
-       &mFormSetGuid,\r
+       &gDriverSampleFormSetGuid,\r
        VariableName,\r
        sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
        (UINT8 *) Configuration,\r
@@ -293,7 +438,7 @@ SetPassword (
   EncodePassword (Password, StrLen (Password) * 2);\r
   Status = gRT->SetVariable(\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                   sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                   &PrivateData->Configuration\r
@@ -517,7 +662,6 @@ AppendAltCfgString (
   )\r
 {\r
   EFI_STRING                          StringPtr;\r
-  EFI_STRING                          TmpPtr;\r
   UINTN                               Length;\r
   UINT8                               *TmpBuffer;\r
   UINTN                               Offset;\r
@@ -527,6 +671,7 @@ AppendAltCfgString (
   UINTN                               ValueWidth;\r
   EFI_STATUS                          Status;\r
 \r
+  TmpBuffer = NULL;\r
   StringPtr = *RequestResult;\r
   StringPtr = StrStr (StringPtr, L"OFFSET");\r
   BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
@@ -538,11 +683,6 @@ AppendAltCfgString (
   }\r
 \r
   while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {\r
-    //\r
-    // Back up the header of one <BlockName>\r
-    //\r
-    TmpPtr = StringPtr;\r
-\r
     StringPtr += StrLen (L"OFFSET=");\r
     //\r
     // Get Offset\r
@@ -587,7 +727,7 @@ AppendAltCfgString (
     StringPtr += StrLen (L"&VALUE=");\r
 \r
     //\r
-    // Get Width\r
+    // Get Value\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
     if (EFI_ERROR (Status)) {\r
@@ -679,7 +819,7 @@ ExtractConfig (
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
             VariableName,\r
-            &mFormSetGuid,\r
+            &gDriverSampleFormSetGuid,\r
             NULL,\r
             &BufferSize,\r
             &PrivateData->Configuration\r
@@ -697,7 +837,7 @@ ExtractConfig (
     // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
     //\r
-    ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
+    ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
     ASSERT (ConfigRequest != NULL);\r
@@ -710,10 +850,17 @@ ExtractConfig (
     // Check routing data in <ConfigHdr>.\r
     // Note: if only one Storage is used, then this checking could be skipped.\r
     //\r
-    if (!HiiIsConfigHdrMatch (Request, &mFormSetGuid, NULL)) {\r
+    if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {\r
       return EFI_NOT_FOUND;\r
     }\r
     //\r
+    // Check whether request for EFI Varstore. EFI varstore get data\r
+    // through hii database, not support in this path.\r
+    //\r
+    if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    //\r
     // Set Request to the unified request string.\r
     //\r
     ConfigRequest = Request;\r
@@ -834,7 +981,7 @@ ExtractConfig (
                                   Progress\r
                                   );\r
     if (!EFI_ERROR (Status)) {\r
-      ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
+      ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
       AppendAltCfgString(Results, ConfigRequestHdr);\r
     }\r
   }\r
@@ -912,17 +1059,25 @@ RouteConfig (
   // Check routing data in <ConfigHdr>.\r
   // Note: if only one Storage is used, then this checking could be skipped.\r
   //\r
-  if (!HiiIsConfigHdrMatch (Configuration, &mFormSetGuid, NULL)) {\r
+  if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
+  //\r
+  // Check whether request for EFI Varstore. EFI varstore get data\r
+  // through hii database, not support in this path.\r
+  //\r
+  if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Get Buffer Storage data from EFI variable\r
   //\r
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
             VariableName,\r
-            &mFormSetGuid,\r
+            &gDriverSampleFormSetGuid,\r
             NULL,\r
             &BufferSize,\r
             &PrivateData->Configuration\r
@@ -1041,7 +1196,7 @@ RouteConfig (
     //\r
     Status = gRT->SetVariable(\r
       VariableName,\r
-      &mFormSetGuid,\r
+      &gDriverSampleFormSetGuid,\r
       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
       sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
       &PrivateData->Configuration\r
@@ -1070,7 +1225,7 @@ RouteConfig (
   //\r
   Status = gRT->SetVariable(\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                   sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                   &PrivateData->Configuration\r
@@ -1115,7 +1270,6 @@ DriverCallback (
 {\r
   DRIVER_SAMPLE_PRIVATE_DATA      *PrivateData;\r
   EFI_STATUS                      Status;\r
-  UINT8                           MyVar;\r
   VOID                            *StartOpCodeHandle;\r
   VOID                            *OptionsOpCodeHandle;\r
   EFI_IFR_GUID_LABEL              *StartLabel;\r
@@ -1123,7 +1277,8 @@ DriverCallback (
   EFI_IFR_GUID_LABEL              *EndLabel;\r
   EFI_INPUT_KEY                   Key;\r
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
-  UINTN                           MyVarSize;\r
+  MY_EFI_VARSTORE_DATA            *EfiData;\r
+  EFI_FORM_ID                     FormId;\r
   \r
   if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||\r
     (ActionRequest == NULL)) {\r
@@ -1131,6 +1286,7 @@ DriverCallback (
   }\r
 \r
 \r
+  FormId = 0;\r
   Status = EFI_SUCCESS;\r
   PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
 \r
@@ -1169,7 +1325,7 @@ DriverCallback (
 \r
         HiiUpdateForm (\r
           PrivateData->HiiHandle[0],  // HII handle\r
-          &mFormSetGuid,              // Formset GUID\r
+          &gDriverSampleFormSetGuid,  // Formset GUID\r
           0x3,                        // Form ID\r
           StartOpCodeHandle,          // Label for where to insert opcodes\r
           NULL                        // Insert data\r
@@ -1177,6 +1333,11 @@ DriverCallback (
 \r
         HiiFreeOpCodeHandle (StartOpCodeHandle);\r
       }\r
+\r
+      if (QuestionId == 0x1247) {\r
+        Status = InternalStartMonitor ();\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
     }\r
     break;\r
 \r
@@ -1199,26 +1360,24 @@ DriverCallback (
             );\r
         } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
       }\r
+\r
+      if (QuestionId == 0x1247) {\r
+        Status = InternalStopMonitor ();\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
     }\r
     break;\r
     \r
   case EFI_BROWSER_ACTION_RETRIEVE:\r
     {\r
-      if (QuestionId == 0x1111) {\r
-        //\r
-        // EfiVarstore question takes sample action (print value as debug information) \r
-        // after read/write question.\r
-        //\r
-        MyVarSize = 1;\r
-        Status = gRT->GetVariable(\r
-                        L"MyVar",\r
-                        &mFormSetGuid,\r
-                        NULL,\r
-                        &MyVarSize,\r
-                        &MyVar\r
-                        );\r
-        ASSERT_EFI_ERROR (Status);\r
-        DEBUG ((DEBUG_INFO, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar, MyVarSize));\r
+      if (QuestionId == 0x1248) {\r
+        {\r
+          if (Type != EFI_IFR_TYPE_REF) {\r
+            return EFI_INVALID_PARAMETER;\r
+          }\r
+        \r
+          Value->ref.FormId = 0x3;\r
+        }\r
       }\r
     }\r
     break;\r
@@ -1254,6 +1413,15 @@ DriverCallback (
   case EFI_BROWSER_ACTION_CHANGING:\r
   {\r
     switch (QuestionId) {\r
+    case 0x1249:\r
+      {\r
+        if (Type != EFI_IFR_TYPE_REF) {\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
+\r
+        Value->ref.FormId = 0x1234;\r
+      }\r
+    break;\r
     case 0x1234:\r
       //\r
       // Initialize the container for dynamic opcodes\r
@@ -1315,7 +1483,7 @@ DriverCallback (
       PrivateData->Configuration.DynamicOneof = 2;\r
       Status = gRT->SetVariable(\r
                       VariableName,\r
-                      &mFormSetGuid,\r
+                      &gDriverSampleFormSetGuid,\r
                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                       sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                       &PrivateData->Configuration\r
@@ -1326,14 +1494,14 @@ DriverCallback (
       //\r
       Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
       ASSERT (Configuration != NULL);\r
-      if (HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
+      if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
         Configuration->DynamicOneof = 2;\r
 \r
         //\r
         // Update uncommitted data of Browser\r
         //\r
         HiiSetBrowserData (\r
-          &mFormSetGuid,\r
+          &gDriverSampleFormSetGuid,\r
           VariableName,\r
           sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
           (UINT8 *) Configuration,\r
@@ -1412,7 +1580,7 @@ DriverCallback (
 \r
       HiiUpdateForm (\r
         PrivateData->HiiHandle[0],  // HII handle\r
-        &mFormSetGuid,              // Formset GUID\r
+        &gDriverSampleFormSetGuid,  // Formset GUID\r
         0x1234,                     // Form ID\r
         StartOpCodeHandle,          // Label for where to insert opcodes\r
         EndOpCodeHandle             // Replace data\r
@@ -1424,6 +1592,7 @@ DriverCallback (
       break;\r
 \r
     case 0x5678:\r
+    case 0x1247:\r
       //\r
       // We will reach here once the Question is refreshed\r
       //\r
@@ -1439,7 +1608,15 @@ DriverCallback (
       //\r
       StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
       StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
-      StartLabel->Number       = LABEL_UPDATE2;\r
+      if (QuestionId == 0x5678) {\r
+        StartLabel->Number       = LABEL_UPDATE2;\r
+        FormId                   = 0x03;\r
+        PrivateData->Configuration.DynamicRefresh++;\r
+      } else if (QuestionId == 0x1247 ) {\r
+        StartLabel->Number       = LABEL_UPDATE3;\r
+        FormId                   = 0x06;\r
+        PrivateData->Configuration.RefreshGuidCount++;\r
+      }\r
 \r
       HiiCreateActionOpCode (\r
         StartOpCodeHandle,                // Container for dynamic created opcodes\r
@@ -1452,8 +1629,8 @@ DriverCallback (
 \r
       HiiUpdateForm (\r
         PrivateData->HiiHandle[0],  // HII handle\r
-        &mFormSetGuid,              // Formset GUID\r
-        0x3,                        // Form ID\r
+        &gDriverSampleFormSetGuid,              // Formset GUID\r
+        FormId,                        // Form ID\r
         StartOpCodeHandle,          // Label for where to insert opcodes\r
         NULL                        // Insert data\r
         );\r
@@ -1463,42 +1640,32 @@ DriverCallback (
       //\r
       // Refresh the Question value\r
       //\r
-      PrivateData->Configuration.DynamicRefresh++;\r
       Status = gRT->SetVariable(\r
                       VariableName,\r
-                      &mFormSetGuid,\r
+                      &gDriverSampleFormSetGuid,\r
                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                       sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                       &PrivateData->Configuration\r
                       );\r
 \r
-      //\r
-      // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause\r
-      // the first statement in Form 3 be suppressed\r
-      //\r
-      MyVarSize = 1;\r
-      MyVar = 111;\r
-      Status = gRT->SetVariable(\r
-                      L"MyVar",\r
-                      &mFormSetGuid,\r
-                      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                      MyVarSize,\r
-                      &MyVar\r
-                      );\r
-      break;\r
-\r
-    case 0x1237:\r
-      //\r
-      // User press "Exit now", request Browser to exit\r
-      //\r
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
-      break;\r
-\r
-    case 0x1238:\r
-      //\r
-      // User press "Save now", request Browser to save the uncommitted data.\r
-      //\r
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
+      if (QuestionId == 0x5678) {\r
+        //\r
+        // Update uncommitted data of Browser\r
+        //\r
+        EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));\r
+        ASSERT (EfiData != NULL);\r
+        if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *) EfiData)) {\r
+          EfiData->Field8 = 111;\r
+          HiiSetBrowserData (\r
+            &gDriverSampleFormSetGuid,\r
+            MyEfiVar,\r
+            sizeof (MY_EFI_VARSTORE_DATA),\r
+            (UINT8 *) EfiData,\r
+            NULL\r
+            );\r
+        }\r
+        FreePool (EfiData);\r
+      }\r
       break;\r
 \r
     case 0x2000:\r
@@ -1535,27 +1702,63 @@ DriverCallback (
 \r
       break;\r
 \r
-    case 0x1111:\r
-      //\r
-      // EfiVarstore question takes sample action (print value as debug information) \r
-      // after read/write question.\r
-      //\r
-      MyVarSize = 1;\r
-      Status = gRT->GetVariable(\r
-                      L"MyVar",\r
-                      &mFormSetGuid,\r
-                      NULL,\r
-                      &MyVarSize,\r
-                      &MyVar\r
-                      );\r
-      ASSERT_EFI_ERROR (Status);\r
-      DEBUG ((DEBUG_INFO, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar, MyVarSize));\r
     default:\r
       break;\r
     }\r
   }\r
   break;\r
 \r
+  case EFI_BROWSER_ACTION_CHANGED:\r
+    switch (QuestionId) {\r
+      case 0x1237:\r
+        //\r
+        // User press "Exit now", request Browser to exit\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
+        break;\r
+      \r
+      case 0x1238:\r
+        //\r
+        // User press "Save now", request Browser to save the uncommitted data.\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
+        break;\r
+      \r
+      case 0x1241:\r
+      case 0x1246:\r
+        //\r
+        // User press "Submit current form and Exit now", request Browser to submit current form and exit\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
+        break;\r
+      \r
+      case 0x1242:\r
+        //\r
+        // User press "Discard current form now", request Browser to discard the uncommitted data.\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;\r
+        break;\r
+      \r
+      case 0x1243:\r
+        //\r
+        // User press "Submit current form now", request Browser to save the uncommitted data.\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+        break;\r
+      \r
+      case 0x1244:\r
+      case 0x1245:\r
+        //\r
+        // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
+        break;\r
+        \r
+      default:\r
+      break;\r
+    }\r
+  break;\r
+\r
   default:\r
     Status = EFI_UNSUPPORTED;\r
     break;\r
@@ -1592,11 +1795,17 @@ DriverSampleInit (
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
   BOOLEAN                         ActionFlag;\r
   EFI_STRING                      ConfigRequestHdr;\r
+  EFI_STRING                      NameRequestHdr;\r
+  MY_EFI_VARSTORE_DATA            *VarStoreConfig;\r
+  EFI_INPUT_KEY                   HotKey;\r
+  EFI_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;\r
 \r
   //\r
   // Initialize the local variables.\r
   //\r
   ConfigRequestHdr = NULL;\r
+  NewString        = NULL;\r
+\r
   //\r
   // Initialize screen dimensions for SendForm().\r
   // Remove 3 characters from top and bottom\r
@@ -1674,7 +1883,7 @@ DriverSampleInit (
   // Publish our HII data\r
   //\r
   HiiHandle[0] = HiiAddPackages (\r
-                   &mFormSetGuid,\r
+                   &gDriverSampleFormSetGuid,\r
                    DriverHandle[0],\r
                    DriverSampleStrings,\r
                    VfrBin,\r
@@ -1700,7 +1909,7 @@ DriverSampleInit (
   PrivateData->DriverHandle[1] = DriverHandle[1];\r
 \r
   HiiHandle[1] = HiiAddPackages (\r
-                   &mInventoryGuid,\r
+                   &gDriverSampleInventoryGuid,\r
                    DriverHandle[1],\r
                    DriverSampleStrings,\r
                    InventoryBin,\r
@@ -1713,6 +1922,18 @@ DriverSampleInit (
 \r
   PrivateData->HiiHandle[1] = HiiHandle[1];\r
 \r
+  //\r
+  // Update the device path string.\r
+  //\r
+  NewString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0, FALSE, FALSE);\r
+  if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {\r
+    DriverSampleUnload (ImageHandle);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  if (NewString != NULL) {\r
+    FreePool (NewString);\r
+  }\r
+\r
   //\r
   // Very simple example of how one would update a string that is already\r
   // in the HII database\r
@@ -1742,39 +1963,145 @@ DriverSampleInit (
   //\r
   // Try to read NV config EFI variable first\r
   //\r
-  ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, DriverHandle[0]);\r
+  ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);\r
   ASSERT (ConfigRequestHdr != NULL);\r
 \r
+  NameRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, NULL, DriverHandle[0]);\r
+  ASSERT (NameRequestHdr != NULL);\r
+\r
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
-  Status = gRT->GetVariable (VariableName, &mFormSetGuid, NULL, &BufferSize, Configuration);\r
+  Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Store zero data Buffer Storage to EFI variable\r
     //\r
     Status = gRT->SetVariable(\r
                     VariableName,\r
-                    &mFormSetGuid,\r
+                    &gDriverSampleFormSetGuid,\r
                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                     sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                     Configuration\r
                     );\r
-    ASSERT (Status == EFI_SUCCESS);\r
+    if (EFI_ERROR (Status)) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return Status;\r
+    }\r
     //\r
     // EFI variable for NV config doesn't exit, we should build this variable\r
     // based on default values stored in IFR\r
     //\r
+    ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   } else {\r
     //\r
     // EFI variable does exist and Validate Current Setting\r
     //\r
+    ActionFlag = HiiValidateSettings (NameRequestHdr);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   }\r
+  FreePool (ConfigRequestHdr);\r
 \r
+  //\r
+  // Initialize efi varstore configuration data\r
+  //\r
+  VarStoreConfig = &PrivateData->VarStoreConfig;\r
+  ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));\r
+\r
+  ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);\r
+  ASSERT (ConfigRequestHdr != NULL);\r
+\r
+  BufferSize = sizeof (MY_EFI_VARSTORE_DATA);\r
+  Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Store zero data to EFI variable Storage.\r
+    //\r
+    Status = gRT->SetVariable(\r
+                    MyEfiVar,\r
+                    &gDriverSampleFormSetGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (MY_EFI_VARSTORE_DATA),\r
+                    VarStoreConfig\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return Status;\r
+    }\r
+    //\r
+    // EFI variable for NV config doesn't exit, we should build this variable\r
+    // based on default values stored in IFR\r
+    //\r
+    ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } else {\r
+    //\r
+    // EFI variable does exist and Validate Current Setting\r
+    //\r
+    ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
   FreePool (ConfigRequestHdr);\r
 \r
+  Status = gBS->CreateEventEx (\r
+        EVT_NOTIFY_SIGNAL, \r
+        TPL_NOTIFY,\r
+        DriverSampleInternalEmptyFunction,\r
+        NULL,\r
+        &gEfiIfrRefreshIdOpGuid,\r
+        &mEvent\r
+        );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Example of how to use BrowserEx protocol to register HotKey.\r
+  // \r
+  Status = gBS->LocateProtocol (&gEfiFormBrowserExProtocolGuid, NULL, (VOID **) &FormBrowserEx);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // First unregister the default hot key F9 and F10.\r
+    //\r
+    HotKey.UnicodeChar = CHAR_NULL;\r
+    HotKey.ScanCode    = SCAN_F9;\r
+    FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);\r
+    HotKey.ScanCode    = SCAN_F10;\r
+    FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);\r
+    \r
+    //\r
+    // Register the default HotKey F9 and F10 again.\r
+    //\r
+    HotKey.ScanCode   = SCAN_F10;\r
+    NewString         = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL);\r
+    ASSERT (NewString != NULL);\r
+    FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);\r
+    HotKey.ScanCode   = SCAN_F9;\r
+    NewString         = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL);\r
+    ASSERT (NewString != NULL);\r
+    FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);\r
+  }\r
 \r
   //\r
   // In default, this driver is built into Flash device image,\r
@@ -1863,5 +2190,7 @@ DriverSampleUnload (
   FreePool (PrivateData);\r
   PrivateData = NULL;\r
 \r
+  gBS->CloseEvent (mEvent);\r
+\r
   return EFI_SUCCESS;\r
 }\r