]> 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 854a5a729156812e6f311c0546fa8a879009e1ea..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 - 2012, 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
@@ -388,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
@@ -671,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
@@ -1766,44 +1767,6 @@ DriverCallback (
   return Status;\r
 }\r
 \r
-\r
-/**\r
-  Transfer the binary device path to string.\r
-\r
-  @param   DevicePath     The device path info.\r
-\r
-  @retval  Device path string info.\r
-\r
-**/\r
-CHAR16  *\r
-GenerateDevicePathString (\r
-  EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
-  )\r
-{\r
-  CHAR16                    *String;\r
-  CHAR16                    *TmpBuf;\r
-  UINTN                     Index;\r
-  UINT8                     *Buffer;\r
-  UINTN                     DevicePathSize;\r
-\r
-  //\r
-  // Compute the size of the device path in bytes\r
-  //\r
-  DevicePathSize = GetDevicePathSize (DevicePath);\r
-  \r
-  String = AllocateZeroPool ((DevicePathSize * 2 + 1) * sizeof (CHAR16));\r
-  if (String == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  TmpBuf = String;\r
-  for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {\r
-    TmpBuf += UnicodeValueToString (TmpBuf, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);\r
-  }\r
-\r
-  return String;\r
-}\r
-\r
 /**\r
   Main entry for this driver.\r
 \r
@@ -1832,6 +1795,7 @@ 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
@@ -1961,7 +1925,7 @@ DriverSampleInit (
   //\r
   // Update the device path string.\r
   //\r
-  NewString = GenerateDevicePathString((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0);\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
@@ -2002,6 +1966,9 @@ DriverSampleInit (
   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, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);\r
   if (EFI_ERROR (Status)) {\r
@@ -2015,19 +1982,40 @@ DriverSampleInit (
                     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
@@ -2053,19 +2041,28 @@ DriverSampleInit (
                     sizeof (MY_EFI_VARSTORE_DATA),\r
                     VarStoreConfig\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 (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 (ConfigRequestHdr);\r
-    ASSERT (ActionFlag);\r
+    if (!ActionFlag) {\r
+      DriverSampleUnload (ImageHandle);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   }\r
   FreePool (ConfigRequestHdr);\r
 \r