2008-01-21 15:39:56 +01:00
|
|
|
/** @file
|
2008-12-03 15:23:46 +01:00
|
|
|
This is an example of how a driver might export data to the HII protocol to be
|
|
|
|
later utilized by the Setup Protocol
|
|
|
|
|
2015-05-13 10:45:21 +02:00
|
|
|
Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:33:45 +02:00
|
|
|
This program and the accompanying materials
|
2008-01-21 15:39:56 +01:00
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
#include "DriverSample.h"
|
|
|
|
|
2009-04-13 08:05:15 +02:00
|
|
|
#define DISPLAY_ONLY_MY_ITEM 0x0002
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
CHAR16 VariableName[] = L"MyIfrNVData";
|
2011-08-30 14:39:53 +02:00
|
|
|
CHAR16 MyEfiVar[] = L"MyEfiVar";
|
2009-04-09 17:22:27 +02:00
|
|
|
EFI_HANDLE DriverHandle[2] = {NULL, NULL};
|
|
|
|
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData = NULL;
|
2011-06-08 10:09:47 +02:00
|
|
|
EFI_EVENT mEvent;
|
2009-04-09 17:22:27 +02:00
|
|
|
|
|
|
|
HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {
|
2009-04-02 10:48:03 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
HARDWARE_DEVICE_PATH,
|
|
|
|
HW_VENDOR_DP,
|
|
|
|
{
|
|
|
|
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
|
|
|
|
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
|
|
|
}
|
|
|
|
},
|
2011-09-18 14:21:01 +02:00
|
|
|
DRIVER_SAMPLE_FORMSET_GUID
|
2009-04-02 10:48:03 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
END_DEVICE_PATH_TYPE,
|
|
|
|
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
2009-10-26 06:27:28 +01:00
|
|
|
{
|
2009-04-02 10:48:03 +02:00
|
|
|
(UINT8) (END_DEVICE_PATH_LENGTH),
|
|
|
|
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-09 17:22:27 +02:00
|
|
|
HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
|
2009-04-02 10:48:03 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
HARDWARE_DEVICE_PATH,
|
|
|
|
HW_VENDOR_DP,
|
|
|
|
{
|
|
|
|
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
|
|
|
|
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
|
|
|
}
|
|
|
|
},
|
2011-09-18 14:21:01 +02:00
|
|
|
DRIVER_SAMPLE_INVENTORY_GUID
|
2009-04-02 10:48:03 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
END_DEVICE_PATH_TYPE,
|
|
|
|
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
2009-10-26 06:27:28 +01:00
|
|
|
{
|
2009-04-02 10:48:03 +02:00
|
|
|
(UINT8) (END_DEVICE_PATH_LENGTH),
|
|
|
|
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-08 10:09:47 +02:00
|
|
|
/**
|
|
|
|
Add empty function for event process function.
|
|
|
|
|
|
|
|
@param Event The Event need to be process
|
|
|
|
@param Context The context of the event.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
DriverSampleInternalEmptyFunction (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Notification function for keystrokes.
|
|
|
|
|
|
|
|
@param[in] KeyData The key that was pressed.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation was successful.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
NotificationFunction(
|
|
|
|
IN EFI_KEY_DATA *KeyData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
gBS->SignalEvent (mEvent);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Function to start monitoring for CTRL-C using SimpleTextInputEx.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The feature is enabled.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InternalStartMonitor(
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
|
|
|
|
EFI_KEY_DATA KeyData;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
UINTN HandleCount;
|
|
|
|
UINTN HandleIndex;
|
|
|
|
EFI_HANDLE NotifyHandle;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&HandleCount,
|
|
|
|
&Handles
|
|
|
|
);
|
|
|
|
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
|
|
|
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
KeyData.KeyState.KeyToggleState = 0;
|
|
|
|
KeyData.Key.ScanCode = 0;
|
|
|
|
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
|
|
|
|
KeyData.Key.UnicodeChar = L'c';
|
|
|
|
|
|
|
|
Status = SimpleEx->RegisterKeyNotify(
|
|
|
|
SimpleEx,
|
|
|
|
&KeyData,
|
|
|
|
NotificationFunction,
|
|
|
|
&NotifyHandle);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
|
|
|
|
Status = SimpleEx->RegisterKeyNotify(
|
|
|
|
SimpleEx,
|
|
|
|
&KeyData,
|
|
|
|
NotificationFunction,
|
|
|
|
&NotifyHandle);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Function to stop monitoring for CTRL-C using SimpleTextInputEx.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The feature is enabled.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InternalStopMonitor(
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
EFI_KEY_DATA KeyData;
|
|
|
|
UINTN HandleCount;
|
|
|
|
UINTN HandleIndex;
|
|
|
|
EFI_HANDLE NotifyHandle;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&HandleCount,
|
|
|
|
&Handles
|
|
|
|
);
|
|
|
|
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
|
|
|
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
KeyData.KeyState.KeyToggleState = 0;
|
|
|
|
KeyData.Key.ScanCode = 0;
|
|
|
|
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
|
|
|
|
KeyData.Key.UnicodeChar = L'c';
|
|
|
|
|
|
|
|
Status = SimpleEx->RegisterKeyNotify(
|
|
|
|
SimpleEx,
|
|
|
|
&KeyData,
|
|
|
|
NotificationFunction,
|
|
|
|
&NotifyHandle);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
|
|
|
|
Status = SimpleEx->RegisterKeyNotify(
|
|
|
|
SimpleEx,
|
|
|
|
&KeyData,
|
|
|
|
NotificationFunction,
|
|
|
|
&NotifyHandle);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
/**
|
|
|
|
Encode the password using a simple algorithm.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
@param Password The string to be encoded.
|
|
|
|
@param MaxSize The size of the string.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
**/
|
2008-01-21 15:39:56 +01:00
|
|
|
VOID
|
|
|
|
EncodePassword (
|
|
|
|
IN CHAR16 *Password,
|
2009-01-20 02:48:39 +01:00
|
|
|
IN UINTN MaxSize
|
2008-01-21 15:39:56 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
UINTN Loop;
|
|
|
|
CHAR16 *Buffer;
|
|
|
|
CHAR16 *Key;
|
|
|
|
|
|
|
|
Key = L"MAR10648567";
|
|
|
|
Buffer = AllocateZeroPool (MaxSize);
|
|
|
|
ASSERT (Buffer != NULL);
|
|
|
|
|
|
|
|
for (Index = 0; Key[Index] != 0; Index++) {
|
|
|
|
for (Loop = 0; Loop < (UINT8) (MaxSize / 2); Loop++) {
|
|
|
|
Buffer[Loop] = (CHAR16) (Password[Loop] ^ Key[Index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMem (Password, Buffer, MaxSize);
|
|
|
|
|
2008-12-03 15:23:46 +01:00
|
|
|
FreePool (Buffer);
|
2008-01-21 15:39:56 +01:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
/**
|
|
|
|
Validate the user's password.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
@param PrivateData This driver's private context data.
|
|
|
|
@param StringId The user's input.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
@retval EFI_SUCCESS The user's input matches the password.
|
|
|
|
@retval EFI_NOT_READY The user's input does not match the password.
|
|
|
|
**/
|
2008-01-21 15:39:56 +01:00
|
|
|
EFI_STATUS
|
|
|
|
ValidatePassword (
|
2008-11-19 14:36:34 +01:00
|
|
|
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
|
|
|
|
IN EFI_STRING_ID StringId
|
2008-01-21 15:39:56 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN BufferSize;
|
2009-05-14 09:06:06 +02:00
|
|
|
UINTN PasswordMaxSize;
|
2008-01-21 15:39:56 +01:00
|
|
|
CHAR16 *Password;
|
|
|
|
CHAR16 *EncodedPassword;
|
|
|
|
BOOLEAN OldPassword;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get encoded password first
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
|
|
|
Status = gRT->GetVariable (
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2008-01-21 15:39:56 +01:00
|
|
|
NULL,
|
|
|
|
&BufferSize,
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Old password not exist, prompt for new password
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
OldPassword = FALSE;
|
2009-05-14 09:06:06 +02:00
|
|
|
PasswordMaxSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Check whether we have any old password set
|
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
for (Index = 0; Index < PasswordMaxSize / sizeof (UINT16); Index++) {
|
2008-01-21 15:39:56 +01:00
|
|
|
if (PrivateData->Configuration.WhatIsThePassword2[Index] != 0) {
|
|
|
|
OldPassword = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!OldPassword) {
|
|
|
|
//
|
|
|
|
// Old password not exist, return EFI_SUCCESS to prompt for new password
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get user input password
|
|
|
|
//
|
2009-04-14 12:47:19 +02:00
|
|
|
Password = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);
|
|
|
|
if (Password == NULL) {
|
|
|
|
return EFI_NOT_READY;
|
|
|
|
}
|
2009-05-14 09:06:06 +02:00
|
|
|
if (StrSize (Password) > PasswordMaxSize) {
|
2008-12-03 15:23:46 +01:00
|
|
|
FreePool (Password);
|
2009-04-14 12:47:19 +02:00
|
|
|
return EFI_NOT_READY;
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Validate old password
|
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
EncodedPassword = AllocateZeroPool (PasswordMaxSize);
|
2008-01-21 15:39:56 +01:00
|
|
|
ASSERT (EncodedPassword != NULL);
|
2009-05-14 09:06:06 +02:00
|
|
|
StrnCpy (EncodedPassword, Password, StrLen (Password));
|
|
|
|
EncodePassword (EncodedPassword, StrLen (EncodedPassword) * sizeof (CHAR16));
|
2010-05-10 04:17:31 +02:00
|
|
|
if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, PasswordMaxSize) != 0) {
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Old password mismatch, return EFI_NOT_READY to prompt for error message
|
|
|
|
//
|
|
|
|
Status = EFI_NOT_READY;
|
|
|
|
} else {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-12-03 15:23:46 +01:00
|
|
|
FreePool (Password);
|
|
|
|
FreePool (EncodedPassword);
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
/**
|
|
|
|
Encode the password using a simple algorithm.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
@param PrivateData This driver's private context data.
|
|
|
|
@param StringId The password from User.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
@retval EFI_SUCESS The operation is successful.
|
|
|
|
@return Other value if gRT->SetVariable () fails.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
**/
|
2008-01-21 15:39:56 +01:00
|
|
|
EFI_STATUS
|
|
|
|
SetPassword (
|
2008-11-19 14:36:34 +01:00
|
|
|
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
|
|
|
|
IN EFI_STRING_ID StringId
|
2008-01-21 15:39:56 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
CHAR16 *Password;
|
2009-04-14 12:47:19 +02:00
|
|
|
CHAR16 *TempPassword;
|
2009-01-20 02:48:39 +01:00
|
|
|
UINTN PasswordSize;
|
2008-01-21 15:39:56 +01:00
|
|
|
DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
2009-04-13 08:05:15 +02:00
|
|
|
UINTN BufferSize;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get Buffer Storage data from EFI variable
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
|
|
|
Status = gRT->GetVariable (
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2008-01-21 15:39:56 +01:00
|
|
|
NULL,
|
|
|
|
&BufferSize,
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get user input password
|
|
|
|
//
|
2014-06-26 05:24:25 +02:00
|
|
|
Password = PrivateData->Configuration.WhatIsThePassword2;
|
2009-10-26 06:27:28 +01:00
|
|
|
PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
|
2009-01-20 02:48:39 +01:00
|
|
|
ZeroMem (Password, PasswordSize);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2009-04-14 12:47:19 +02:00
|
|
|
TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);
|
|
|
|
if (TempPassword == NULL) {
|
|
|
|
return EFI_NOT_READY;
|
|
|
|
}
|
2009-05-14 09:06:06 +02:00
|
|
|
if (StrSize (TempPassword) > PasswordSize) {
|
2009-04-14 12:47:19 +02:00
|
|
|
FreePool (TempPassword);
|
|
|
|
return EFI_NOT_READY;
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
2009-05-14 09:06:06 +02:00
|
|
|
StrnCpy (Password, TempPassword, StrLen (TempPassword));
|
2009-04-14 12:47:19 +02:00
|
|
|
FreePool (TempPassword);
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Retrive uncommitted data from Browser
|
|
|
|
//
|
2009-04-27 06:55:02 +02:00
|
|
|
Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
|
|
|
|
ASSERT (Configuration != NULL);
|
2011-09-18 14:21:01 +02:00
|
|
|
if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Update password's clear text in the screen
|
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
CopyMem (Configuration->PasswordClearText, Password, StrSize (Password));
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Update uncommitted data of Browser
|
|
|
|
//
|
2009-04-13 08:05:15 +02:00
|
|
|
HiiSetBrowserData (
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2009-04-13 08:05:15 +02:00
|
|
|
VariableName,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
(UINT8 *) Configuration,
|
|
|
|
NULL
|
|
|
|
);
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2009-04-27 06:55:02 +02:00
|
|
|
//
|
|
|
|
// Free Configuration Buffer
|
|
|
|
//
|
|
|
|
FreePool (Configuration);
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set password
|
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
EncodePassword (Password, StrLen (Password) * 2);
|
2008-01-21 15:39:56 +01:00
|
|
|
Status = gRT->SetVariable(
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2008-01-21 15:39:56 +01:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2010-02-11 02:59:35 +01:00
|
|
|
/**
|
|
|
|
Update names of Name/Value storage to current language.
|
|
|
|
|
|
|
|
@param PrivateData Points to the driver private data.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS All names are successfully updated.
|
|
|
|
@retval EFI_NOT_FOUND Failed to get Name from HII database.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
LoadNameValueNames (
|
|
|
|
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get Name/Value name string of current language
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
|
|
|
|
PrivateData->NameValueName[Index] = HiiGetString (
|
|
|
|
PrivateData->HiiHandle[0],
|
|
|
|
PrivateData->NameStringId[Index],
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (PrivateData->NameValueName[Index] == NULL) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2011-05-20 04:58:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
|
|
|
|
or WIDTH or VALUE.
|
|
|
|
<BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
|
|
|
|
|
|
|
|
This is a internal function.
|
|
|
|
|
|
|
|
@param StringPtr String in <BlockConfig> format and points to the
|
|
|
|
first character of <Number>.
|
|
|
|
@param Number The output value. Caller takes the responsibility
|
|
|
|
to free memory.
|
|
|
|
@param Len Length of the <Number>, in characters.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
|
|
|
|
structures.
|
|
|
|
@retval EFI_SUCCESS Value of <Number> is outputted in Number
|
|
|
|
successfully.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
GetValueOfNumber (
|
|
|
|
IN EFI_STRING StringPtr,
|
|
|
|
OUT UINT8 **Number,
|
|
|
|
OUT UINTN *Len
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STRING TmpPtr;
|
|
|
|
UINTN Length;
|
|
|
|
EFI_STRING Str;
|
|
|
|
UINT8 *Buf;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT8 DigitUint8;
|
|
|
|
UINTN Index;
|
|
|
|
CHAR16 TemStr[2];
|
|
|
|
|
|
|
|
if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buf = NULL;
|
|
|
|
|
|
|
|
TmpPtr = StringPtr;
|
|
|
|
while (*StringPtr != L'\0' && *StringPtr != L'&') {
|
|
|
|
StringPtr++;
|
|
|
|
}
|
|
|
|
*Len = StringPtr - TmpPtr;
|
|
|
|
Length = *Len + 1;
|
|
|
|
|
|
|
|
Str = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));
|
|
|
|
if (Str == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));
|
|
|
|
*(Str + *Len) = L'\0';
|
|
|
|
|
|
|
|
Length = (Length + 1) / 2;
|
|
|
|
Buf = (UINT8 *) AllocateZeroPool (Length);
|
|
|
|
if (Buf == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Length = *Len;
|
|
|
|
ZeroMem (TemStr, sizeof (TemStr));
|
|
|
|
for (Index = 0; Index < Length; Index ++) {
|
|
|
|
TemStr[0] = Str[Length - Index - 1];
|
|
|
|
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
|
|
|
|
if ((Index & 1) == 0) {
|
|
|
|
Buf [Index/2] = DigitUint8;
|
|
|
|
} else {
|
|
|
|
Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*Number = Buf;
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
if (Str != NULL) {
|
|
|
|
FreePool (Str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create altcfg string.
|
|
|
|
|
|
|
|
@param Result The request result string.
|
|
|
|
@param ConfigHdr The request head info. <ConfigHdr> format.
|
|
|
|
@param Offset The offset of the parameter int he structure.
|
|
|
|
@param Width The width of the parameter.
|
|
|
|
|
|
|
|
|
|
|
|
@retval The string with altcfg info append at the end.
|
|
|
|
**/
|
|
|
|
EFI_STRING
|
|
|
|
CreateAltCfgString (
|
|
|
|
IN EFI_STRING Result,
|
|
|
|
IN EFI_STRING ConfigHdr,
|
|
|
|
IN UINTN Offset,
|
|
|
|
IN UINTN Width
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STRING StringPtr;
|
|
|
|
EFI_STRING TmpStr;
|
|
|
|
UINTN NewLen;
|
|
|
|
|
2011-05-25 10:15:05 +02:00
|
|
|
NewLen = StrLen (Result);
|
2011-05-23 16:13:08 +02:00
|
|
|
//
|
|
|
|
// String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
|
|
|
|
//
|
2011-05-25 10:15:05 +02:00
|
|
|
NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);
|
2011-05-20 04:58:35 +02:00
|
|
|
StringPtr = AllocateZeroPool (NewLen);
|
|
|
|
if (StringPtr == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TmpStr = StringPtr;
|
|
|
|
if (Result != NULL) {
|
|
|
|
StrCpy (StringPtr, Result);
|
|
|
|
StringPtr += StrLen (Result);
|
|
|
|
FreePool (Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeSPrint (
|
|
|
|
StringPtr,
|
|
|
|
(1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
|
|
|
|
L"&%s&ALTCFG=%04x",
|
|
|
|
ConfigHdr,
|
|
|
|
EFI_HII_DEFAULT_CLASS_STANDARD
|
|
|
|
);
|
|
|
|
StringPtr += StrLen (StringPtr);
|
|
|
|
|
|
|
|
UnicodeSPrint (
|
|
|
|
StringPtr,
|
|
|
|
(8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
|
|
|
|
L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
|
|
|
|
Offset,
|
|
|
|
Width,
|
|
|
|
DEFAULT_CLASS_STANDARD_VALUE
|
|
|
|
);
|
|
|
|
StringPtr += StrLen (StringPtr);
|
|
|
|
|
|
|
|
UnicodeSPrint (
|
|
|
|
StringPtr,
|
|
|
|
(1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
|
|
|
|
L"&%s&ALTCFG=%04x",
|
|
|
|
ConfigHdr,
|
|
|
|
EFI_HII_DEFAULT_CLASS_MANUFACTURING
|
|
|
|
);
|
|
|
|
StringPtr += StrLen (StringPtr);
|
|
|
|
|
|
|
|
UnicodeSPrint (
|
|
|
|
StringPtr,
|
|
|
|
(8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
|
|
|
|
L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
|
|
|
|
Offset,
|
|
|
|
Width,
|
|
|
|
DEFAULT_CLASS_MANUFACTURING_VALUE
|
|
|
|
);
|
|
|
|
StringPtr += StrLen (StringPtr);
|
|
|
|
|
|
|
|
return TmpStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check whether need to add the altcfg string. if need to add, add the altcfg
|
|
|
|
string.
|
|
|
|
|
|
|
|
@param RequestResult The request result string.
|
|
|
|
@param ConfigRequestHdr The request head info. <ConfigHdr> format.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
AppendAltCfgString (
|
|
|
|
IN OUT EFI_STRING *RequestResult,
|
|
|
|
IN EFI_STRING ConfigRequestHdr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STRING StringPtr;
|
|
|
|
UINTN Length;
|
|
|
|
UINT8 *TmpBuffer;
|
|
|
|
UINTN Offset;
|
|
|
|
UINTN Width;
|
|
|
|
UINTN BlockSize;
|
|
|
|
UINTN ValueOffset;
|
|
|
|
UINTN ValueWidth;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2014-07-28 09:52:57 +02:00
|
|
|
TmpBuffer = NULL;
|
2011-05-20 04:58:35 +02:00
|
|
|
StringPtr = *RequestResult;
|
|
|
|
StringPtr = StrStr (StringPtr, L"OFFSET");
|
|
|
|
BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
|
|
|
ValueOffset = OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, GetDefaultValueFromAccess);
|
|
|
|
ValueWidth = sizeof (((DRIVER_SAMPLE_CONFIGURATION *)0)->GetDefaultValueFromAccess);
|
|
|
|
|
|
|
|
if (StringPtr == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {
|
|
|
|
StringPtr += StrLen (L"OFFSET=");
|
|
|
|
//
|
|
|
|
// Get Offset
|
|
|
|
//
|
|
|
|
Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Offset = 0;
|
|
|
|
CopyMem (
|
|
|
|
&Offset,
|
|
|
|
TmpBuffer,
|
|
|
|
(((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
|
|
|
|
);
|
|
|
|
FreePool (TmpBuffer);
|
|
|
|
|
|
|
|
StringPtr += Length;
|
|
|
|
if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StringPtr += StrLen (L"&WIDTH=");
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get Width
|
|
|
|
//
|
|
|
|
Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Width = 0;
|
|
|
|
CopyMem (
|
|
|
|
&Width,
|
|
|
|
TmpBuffer,
|
|
|
|
(((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
|
|
|
|
);
|
|
|
|
FreePool (TmpBuffer);
|
|
|
|
|
|
|
|
StringPtr += Length;
|
|
|
|
if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StringPtr += StrLen (L"&VALUE=");
|
|
|
|
|
|
|
|
//
|
2011-05-31 02:59:15 +02:00
|
|
|
// Get Value
|
2011-05-20 04:58:35 +02:00
|
|
|
//
|
|
|
|
Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StringPtr += Length;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Calculate Value and convert it to hex string.
|
|
|
|
//
|
|
|
|
if (Offset + Width > BlockSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Offset <= ValueOffset && Offset + Width >= ValueOffset + ValueWidth) {
|
2011-05-23 16:13:08 +02:00
|
|
|
*RequestResult = CreateAltCfgString(*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth);
|
|
|
|
return;
|
2011-05-20 04:58:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
/**
|
|
|
|
This function allows a caller to extract the current configuration for one
|
|
|
|
or more named elements from the target driver.
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
@param Request A null-terminated Unicode string in
|
|
|
|
<ConfigRequest> format.
|
|
|
|
@param Progress On return, points to a character in the Request
|
|
|
|
string. Points to the string's null terminator if
|
|
|
|
request was successful. Points to the most recent
|
|
|
|
'&' before the first failing name/value pair (or
|
|
|
|
the beginning of the string if the failure is in
|
|
|
|
the first name/value pair) if the request was not
|
|
|
|
successful.
|
|
|
|
@param Results A null-terminated Unicode string in
|
|
|
|
<ConfigAltResp> format which has all values filled
|
|
|
|
in for the names in the Request string. String to
|
|
|
|
be allocated by the called function.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The Results is filled with the requested values.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
|
2010-05-10 04:17:31 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
|
2008-01-21 15:39:56 +01:00
|
|
|
@retval EFI_NOT_FOUND Routing data doesn't match any storage in this
|
|
|
|
driver.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ExtractConfig (
|
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN CONST EFI_STRING Request,
|
|
|
|
OUT EFI_STRING *Progress,
|
|
|
|
OUT EFI_STRING *Results
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BufferSize;
|
|
|
|
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
|
|
|
|
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
|
2009-05-14 09:06:06 +02:00
|
|
|
EFI_STRING ConfigRequest;
|
2009-06-25 11:08:30 +02:00
|
|
|
EFI_STRING ConfigRequestHdr;
|
2009-05-14 09:06:06 +02:00
|
|
|
UINTN Size;
|
2010-02-11 02:59:35 +01:00
|
|
|
EFI_STRING Value;
|
|
|
|
UINTN ValueStrLen;
|
|
|
|
CHAR16 BackupChar;
|
|
|
|
CHAR16 *StrPointer;
|
2010-03-04 07:48:52 +01:00
|
|
|
BOOLEAN AllocatedRequest;
|
2010-02-11 02:59:35 +01:00
|
|
|
|
2010-03-04 07:48:52 +01:00
|
|
|
if (Progress == NULL || Results == NULL) {
|
2009-05-20 14:05:45 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2009-05-14 09:06:06 +02:00
|
|
|
//
|
|
|
|
// Initialize the local variables.
|
|
|
|
//
|
2009-06-25 11:08:30 +02:00
|
|
|
ConfigRequestHdr = NULL;
|
|
|
|
ConfigRequest = NULL;
|
|
|
|
Size = 0;
|
|
|
|
*Progress = Request;
|
2010-03-04 07:48:52 +01:00
|
|
|
AllocatedRequest = FALSE;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
|
|
|
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
|
|
|
HiiConfigRouting = PrivateData->HiiConfigRouting;
|
|
|
|
|
2008-11-04 15:28:08 +01:00
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
// Get Buffer Storage data from EFI variable.
|
|
|
|
// Try to get the current setting from variable.
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
2009-05-18 07:03:45 +02:00
|
|
|
Status = gRT->GetVariable (
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2009-05-18 07:03:45 +02:00
|
|
|
NULL,
|
|
|
|
&BufferSize,
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2009-05-21 07:05:59 +02:00
|
|
|
return EFI_NOT_FOUND;
|
2009-05-18 07:03:45 +02:00
|
|
|
}
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-04 15:28:08 +01:00
|
|
|
if (Request == NULL) {
|
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
// Request is set to NULL, construct full request string.
|
2009-04-13 08:05:15 +02:00
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
|
|
|
|
//
|
2009-10-26 06:27:28 +01:00
|
|
|
// Allocate and fill a buffer large enough to hold the <ConfigHdr> template
|
2009-05-14 09:06:06 +02:00
|
|
|
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
|
2010-03-04 07:48:52 +01:00
|
|
|
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
|
2009-05-14 09:06:06 +02:00
|
|
|
ConfigRequest = AllocateZeroPool (Size);
|
2010-03-05 08:55:16 +01:00
|
|
|
ASSERT (ConfigRequest != NULL);
|
2010-03-04 07:48:52 +01:00
|
|
|
AllocatedRequest = TRUE;
|
2009-06-25 11:08:30 +02:00
|
|
|
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
|
|
|
|
FreePool (ConfigRequestHdr);
|
2011-05-20 04:58:35 +02:00
|
|
|
ConfigRequestHdr = NULL;
|
2009-05-14 09:06:06 +02:00
|
|
|
} else {
|
2009-05-21 07:05:59 +02:00
|
|
|
//
|
|
|
|
// Check routing data in <ConfigHdr>.
|
|
|
|
// Note: if only one Storage is used, then this checking could be skipped.
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {
|
2009-05-21 07:05:59 +02:00
|
|
|
return EFI_NOT_FOUND;
|
2009-05-14 09:06:06 +02:00
|
|
|
}
|
2010-03-04 07:48:52 +01:00
|
|
|
//
|
2011-08-30 14:39:53 +02:00
|
|
|
// Check whether request for EFI Varstore. EFI varstore get data
|
|
|
|
// through hii database, not support in this path.
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) {
|
2011-08-30 14:39:53 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
// Set Request to the unified request string.
|
|
|
|
//
|
2009-05-21 07:05:59 +02:00
|
|
|
ConfigRequest = Request;
|
2010-02-11 02:59:35 +01:00
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
// Check whether Request includes Request Element.
|
2010-02-11 02:59:35 +01:00
|
|
|
//
|
|
|
|
if (StrStr (Request, L"OFFSET") == NULL) {
|
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
// Check Request Element does exist in Reques String
|
2010-02-11 02:59:35 +01:00
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
StrPointer = StrStr (Request, L"PATH");
|
|
|
|
if (StrPointer == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
if (StrStr (StrPointer, L"&") == NULL) {
|
|
|
|
Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16);
|
|
|
|
ConfigRequest = AllocateZeroPool (Size);
|
2010-03-05 08:55:16 +01:00
|
|
|
ASSERT (ConfigRequest != NULL);
|
2010-03-04 07:48:52 +01:00
|
|
|
AllocatedRequest = TRUE;
|
|
|
|
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", Request, (UINT64)BufferSize);
|
2010-02-11 02:59:35 +01:00
|
|
|
}
|
2010-03-04 07:48:52 +01:00
|
|
|
}
|
|
|
|
}
|
2010-02-11 02:59:35 +01:00
|
|
|
|
2010-03-04 07:48:52 +01:00
|
|
|
//
|
|
|
|
// Check if requesting Name/Value storage
|
|
|
|
//
|
|
|
|
if (StrStr (ConfigRequest, L"OFFSET") == NULL) {
|
|
|
|
//
|
|
|
|
// Update Name/Value storage Names
|
|
|
|
//
|
|
|
|
Status = LoadNameValueNames (PrivateData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
2010-02-11 02:59:35 +01:00
|
|
|
|
2010-03-04 07:48:52 +01:00
|
|
|
//
|
|
|
|
// Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
|
|
|
|
// <Request> ::=<ConfigHdr>&Name0&Name1&Name2
|
|
|
|
// <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
|
|
|
|
//
|
|
|
|
BufferSize = (StrLen (ConfigRequest) +
|
|
|
|
1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 +
|
|
|
|
1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 +
|
|
|
|
1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16);
|
|
|
|
*Results = AllocateZeroPool (BufferSize);
|
|
|
|
ASSERT (*Results != NULL);
|
|
|
|
StrCpy (*Results, ConfigRequest);
|
|
|
|
Value = *Results;
|
2010-02-11 02:59:35 +01:00
|
|
|
|
2010-03-04 07:48:52 +01:00
|
|
|
//
|
|
|
|
// Append value of NameValueVar0, type is UINT8
|
|
|
|
//
|
|
|
|
if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) {
|
|
|
|
Value += StrLen (PrivateData->NameValueName[0]);
|
|
|
|
ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1);
|
|
|
|
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
|
|
|
|
|
|
|
|
BackupChar = Value[ValueStrLen];
|
|
|
|
*Value++ = L'=';
|
|
|
|
Value += UnicodeValueToString (
|
|
|
|
Value,
|
|
|
|
PREFIX_ZERO | RADIX_HEX,
|
|
|
|
PrivateData->Configuration.NameValueVar0,
|
|
|
|
sizeof (PrivateData->Configuration.NameValueVar0) * 2
|
|
|
|
);
|
|
|
|
*Value = BackupChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Append value of NameValueVar1, type is UINT16
|
|
|
|
//
|
|
|
|
if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) {
|
|
|
|
Value += StrLen (PrivateData->NameValueName[1]);
|
|
|
|
ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1);
|
|
|
|
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
|
|
|
|
|
|
|
|
BackupChar = Value[ValueStrLen];
|
|
|
|
*Value++ = L'=';
|
|
|
|
Value += UnicodeValueToString (
|
|
|
|
Value,
|
|
|
|
PREFIX_ZERO | RADIX_HEX,
|
|
|
|
PrivateData->Configuration.NameValueVar1,
|
|
|
|
sizeof (PrivateData->Configuration.NameValueVar1) * 2
|
|
|
|
);
|
|
|
|
*Value = BackupChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Append value of NameValueVar2, type is CHAR16 *
|
|
|
|
//
|
|
|
|
if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) {
|
|
|
|
Value += StrLen (PrivateData->NameValueName[2]);
|
|
|
|
ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1;
|
|
|
|
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
|
2010-02-11 02:59:35 +01:00
|
|
|
|
2010-03-04 07:48:52 +01:00
|
|
|
*Value++ = L'=';
|
2010-02-11 02:59:35 +01:00
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
// Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
|
2010-02-11 02:59:35 +01:00
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
StrPointer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;
|
|
|
|
for (; *StrPointer != L'\0'; StrPointer++) {
|
|
|
|
Value += UnicodeValueToString (Value, PREFIX_ZERO | RADIX_HEX, *StrPointer, 4);
|
2010-02-11 02:59:35 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-04 07:48:52 +01:00
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
|
|
|
|
//
|
|
|
|
Status = HiiConfigRouting->BlockToConfig (
|
|
|
|
HiiConfigRouting,
|
|
|
|
ConfigRequest,
|
|
|
|
(UINT8 *) &PrivateData->Configuration,
|
|
|
|
BufferSize,
|
|
|
|
Results,
|
|
|
|
Progress
|
|
|
|
);
|
2011-05-23 16:13:08 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
2011-09-18 14:21:01 +02:00
|
|
|
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
|
2011-05-23 16:13:08 +02:00
|
|
|
AppendAltCfgString(Results, ConfigRequestHdr);
|
|
|
|
}
|
2008-11-04 15:28:08 +01:00
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
// Free the allocated config request string.
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
2010-03-04 07:48:52 +01:00
|
|
|
if (AllocatedRequest) {
|
2009-05-14 09:06:06 +02:00
|
|
|
FreePool (ConfigRequest);
|
2010-03-04 07:48:52 +01:00
|
|
|
}
|
2011-05-20 04:58:35 +02:00
|
|
|
|
|
|
|
if (ConfigRequestHdr != NULL) {
|
|
|
|
FreePool (ConfigRequestHdr);
|
|
|
|
}
|
2010-03-04 07:48:52 +01:00
|
|
|
//
|
|
|
|
// Set Progress string to the original request string.
|
|
|
|
//
|
|
|
|
if (Request == NULL) {
|
2009-05-18 05:26:54 +02:00
|
|
|
*Progress = NULL;
|
2010-03-04 07:48:52 +01:00
|
|
|
} else if (StrStr (Request, L"OFFSET") == NULL) {
|
|
|
|
*Progress = Request + StrLen (Request);
|
2009-05-14 09:06:06 +02:00
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function processes the results of changes in configuration.
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
@param Configuration A null-terminated Unicode string in <ConfigResp>
|
|
|
|
format.
|
|
|
|
@param Progress A pointer to a string filled in with the offset of
|
|
|
|
the most recent '&' before the first failing
|
|
|
|
name/value pair (or the beginning of the string if
|
|
|
|
the failure is in the first name/value pair) or
|
|
|
|
the terminating NULL if all was successful.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The Results is processed successfully.
|
|
|
|
@retval EFI_INVALID_PARAMETER Configuration is NULL.
|
|
|
|
@retval EFI_NOT_FOUND Routing data doesn't match any storage in this
|
|
|
|
driver.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
RouteConfig (
|
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN CONST EFI_STRING Configuration,
|
|
|
|
OUT EFI_STRING *Progress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BufferSize;
|
|
|
|
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
|
|
|
|
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
|
2010-02-11 02:59:35 +01:00
|
|
|
CHAR16 *Value;
|
|
|
|
CHAR16 *StrPtr;
|
|
|
|
CHAR16 TemStr[5];
|
|
|
|
UINT8 *DataBuffer;
|
|
|
|
UINT8 DigitUint8;
|
|
|
|
UINTN Index;
|
|
|
|
CHAR16 *StrBuffer;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2009-07-08 04:31:10 +02:00
|
|
|
if (Configuration == NULL || Progress == NULL) {
|
2008-11-04 15:28:08 +01:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
|
|
|
HiiConfigRouting = PrivateData->HiiConfigRouting;
|
2009-07-08 04:31:10 +02:00
|
|
|
*Progress = Configuration;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2009-05-14 09:06:06 +02:00
|
|
|
//
|
2008-11-04 15:28:08 +01:00
|
|
|
// Check routing data in <ConfigHdr>.
|
|
|
|
// Note: if only one Storage is used, then this checking could be skipped.
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {
|
2008-11-04 15:28:08 +01:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:39:53 +02:00
|
|
|
//
|
|
|
|
// Check whether request for EFI Varstore. EFI varstore get data
|
|
|
|
// through hii database, not support in this path.
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {
|
2011-08-30 14:39:53 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Get Buffer Storage data from EFI variable
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
2009-05-18 07:03:45 +02:00
|
|
|
Status = gRT->GetVariable (
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2009-05-18 07:03:45 +02:00
|
|
|
NULL,
|
|
|
|
&BufferSize,
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2010-02-11 02:59:35 +01:00
|
|
|
//
|
|
|
|
// Check if configuring Name/Value storage
|
|
|
|
//
|
|
|
|
if (StrStr (Configuration, L"OFFSET") == NULL) {
|
|
|
|
//
|
|
|
|
// Update Name/Value storage Names
|
|
|
|
//
|
|
|
|
Status = LoadNameValueNames (PrivateData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Convert value for NameValueVar0
|
|
|
|
//
|
|
|
|
if ((Value = StrStr (Configuration, PrivateData->NameValueName[0])) != NULL) {
|
|
|
|
//
|
|
|
|
// Skip "Name="
|
|
|
|
//
|
|
|
|
Value += StrLen (PrivateData->NameValueName[0]);
|
|
|
|
Value++;
|
|
|
|
//
|
|
|
|
// Get Value String
|
|
|
|
//
|
|
|
|
StrPtr = StrStr (Value, L"&");
|
|
|
|
if (StrPtr == NULL) {
|
|
|
|
StrPtr = Value + StrLen (Value);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Convert Value to Buffer data
|
|
|
|
//
|
|
|
|
DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar0;
|
|
|
|
ZeroMem (TemStr, sizeof (TemStr));
|
|
|
|
for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {
|
|
|
|
TemStr[0] = *StrPtr;
|
|
|
|
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
|
|
|
|
if ((Index & 1) == 0) {
|
|
|
|
DataBuffer [Index/2] = DigitUint8;
|
|
|
|
} else {
|
|
|
|
DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Convert value for NameValueVar1
|
|
|
|
//
|
|
|
|
if ((Value = StrStr (Configuration, PrivateData->NameValueName[1])) != NULL) {
|
|
|
|
//
|
|
|
|
// Skip "Name="
|
|
|
|
//
|
|
|
|
Value += StrLen (PrivateData->NameValueName[1]);
|
|
|
|
Value++;
|
|
|
|
//
|
|
|
|
// Get Value String
|
|
|
|
//
|
|
|
|
StrPtr = StrStr (Value, L"&");
|
|
|
|
if (StrPtr == NULL) {
|
|
|
|
StrPtr = Value + StrLen (Value);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Convert Value to Buffer data
|
|
|
|
//
|
|
|
|
DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar1;
|
|
|
|
ZeroMem (TemStr, sizeof (TemStr));
|
|
|
|
for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {
|
|
|
|
TemStr[0] = *StrPtr;
|
|
|
|
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
|
|
|
|
if ((Index & 1) == 0) {
|
|
|
|
DataBuffer [Index/2] = DigitUint8;
|
|
|
|
} else {
|
|
|
|
DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Convert value for NameValueVar2
|
|
|
|
//
|
|
|
|
if ((Value = StrStr (Configuration, PrivateData->NameValueName[2])) != NULL) {
|
|
|
|
//
|
|
|
|
// Skip "Name="
|
|
|
|
//
|
|
|
|
Value += StrLen (PrivateData->NameValueName[2]);
|
|
|
|
Value++;
|
|
|
|
//
|
|
|
|
// Get Value String
|
|
|
|
//
|
|
|
|
StrPtr = StrStr (Value, L"&");
|
|
|
|
if (StrPtr == NULL) {
|
|
|
|
StrPtr = Value + StrLen (Value);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
|
|
|
|
//
|
|
|
|
StrBuffer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;
|
|
|
|
ZeroMem (TemStr, sizeof (TemStr));
|
|
|
|
while (Value < StrPtr) {
|
|
|
|
StrnCpy (TemStr, Value, 4);
|
|
|
|
*(StrBuffer++) = (CHAR16) StrHexToUint64 (TemStr);
|
|
|
|
Value += 4;
|
|
|
|
}
|
|
|
|
*StrBuffer = L'\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Store Buffer Storage back to EFI variable
|
|
|
|
//
|
|
|
|
Status = gRT->SetVariable(
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2010-02-11 02:59:35 +01:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
|
|
|
|
//
|
|
|
|
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
|
|
|
Status = HiiConfigRouting->ConfigToBlock (
|
|
|
|
HiiConfigRouting,
|
|
|
|
Configuration,
|
|
|
|
(UINT8 *) &PrivateData->Configuration,
|
|
|
|
&BufferSize,
|
|
|
|
Progress
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Store Buffer Storage back to EFI variable
|
|
|
|
//
|
|
|
|
Status = gRT->SetVariable(
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2008-01-21 15:39:56 +01:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function processes the results of changes in configuration.
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
@param Action Specifies the type of action taken by the browser.
|
|
|
|
@param QuestionId A unique value which is sent to the original
|
|
|
|
exporting driver so that it can identify the type
|
|
|
|
of data to expect.
|
|
|
|
@param Type The type of value for the question.
|
|
|
|
@param Value A pointer to the data being sent to the original
|
|
|
|
exporting driver.
|
|
|
|
@param ActionRequest On return, points to the action requested by the
|
|
|
|
callback function.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The callback successfully handled the action.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
|
|
|
|
variable and its data.
|
|
|
|
@retval EFI_DEVICE_ERROR The variable could not be saved.
|
|
|
|
@retval EFI_UNSUPPORTED The specified Action is not supported by the
|
|
|
|
callback.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DriverCallback (
|
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN EFI_BROWSER_ACTION Action,
|
|
|
|
IN EFI_QUESTION_ID QuestionId,
|
|
|
|
IN UINT8 Type,
|
|
|
|
IN EFI_IFR_TYPE_VALUE *Value,
|
|
|
|
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
|
|
|
|
EFI_STATUS Status;
|
2009-04-13 08:05:15 +02:00
|
|
|
VOID *StartOpCodeHandle;
|
|
|
|
VOID *OptionsOpCodeHandle;
|
|
|
|
EFI_IFR_GUID_LABEL *StartLabel;
|
|
|
|
VOID *EndOpCodeHandle;
|
|
|
|
EFI_IFR_GUID_LABEL *EndLabel;
|
2009-10-26 06:27:28 +01:00
|
|
|
EFI_INPUT_KEY Key;
|
|
|
|
DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
2011-08-30 14:39:53 +02:00
|
|
|
MY_EFI_VARSTORE_DATA *EfiData;
|
2011-06-08 10:09:47 +02:00
|
|
|
EFI_FORM_ID FormId;
|
2015-05-13 10:45:21 +02:00
|
|
|
EFI_STRING Progress;
|
|
|
|
EFI_STRING Results;
|
|
|
|
UINT32 ProgressErr;
|
|
|
|
CHAR16 *TmpStr;
|
2011-04-12 03:15:28 +02:00
|
|
|
|
|
|
|
if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||
|
|
|
|
(ActionRequest == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2009-10-26 06:27:28 +01:00
|
|
|
|
|
|
|
|
2011-06-08 10:09:47 +02:00
|
|
|
FormId = 0;
|
2015-05-13 10:45:21 +02:00
|
|
|
ProgressErr = 0;
|
2011-04-12 03:15:28 +02:00
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
|
|
|
|
|
|
|
switch (Action) {
|
|
|
|
case EFI_BROWSER_ACTION_FORM_OPEN:
|
|
|
|
{
|
|
|
|
if (QuestionId == 0x1234) {
|
|
|
|
//
|
|
|
|
// Sample CallBack for UEFI FORM_OPEN action:
|
|
|
|
// Add Save action into Form 3 when Form 1 is opened.
|
|
|
|
// This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
|
|
|
|
//
|
|
|
|
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the container for dynamic opcodes
|
|
|
|
//
|
|
|
|
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (StartOpCodeHandle != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the start opcode
|
|
|
|
//
|
|
|
|
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
|
|
|
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
StartLabel->Number = LABEL_UPDATE2;
|
|
|
|
|
|
|
|
HiiCreateActionOpCode (
|
|
|
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
|
|
|
0x1238, // Question ID
|
|
|
|
STRING_TOKEN(STR_SAVE_TEXT), // Prompt text
|
|
|
|
STRING_TOKEN(STR_SAVE_TEXT), // Help text
|
|
|
|
EFI_IFR_FLAG_CALLBACK, // Question flag
|
|
|
|
0 // Action String ID
|
|
|
|
);
|
|
|
|
|
|
|
|
HiiUpdateForm (
|
|
|
|
PrivateData->HiiHandle[0], // HII handle
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid, // Formset GUID
|
2011-04-12 03:15:28 +02:00
|
|
|
0x3, // Form ID
|
|
|
|
StartOpCodeHandle, // Label for where to insert opcodes
|
|
|
|
NULL // Insert data
|
|
|
|
);
|
|
|
|
|
|
|
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
|
|
|
}
|
2011-06-08 10:09:47 +02:00
|
|
|
|
|
|
|
if (QuestionId == 0x1247) {
|
|
|
|
Status = InternalStartMonitor ();
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
2011-04-12 03:15:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_BROWSER_ACTION_FORM_CLOSE:
|
|
|
|
{
|
|
|
|
if (QuestionId == 0x5678) {
|
|
|
|
//
|
|
|
|
// Sample CallBack for UEFI FORM_CLOSE action:
|
|
|
|
// Show up a pop-up to specify Form 3 will be closed when exit Form 3.
|
|
|
|
//
|
|
|
|
do {
|
|
|
|
CreatePopUp (
|
|
|
|
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
|
|
|
&Key,
|
|
|
|
L"",
|
|
|
|
L"You are going to leave third Form!",
|
|
|
|
L"Press ESC or ENTER to continue ...",
|
|
|
|
L"",
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
|
|
|
|
}
|
2011-06-08 10:09:47 +02:00
|
|
|
|
|
|
|
if (QuestionId == 0x1247) {
|
|
|
|
Status = InternalStopMonitor ();
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
2011-04-12 03:15:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_BROWSER_ACTION_RETRIEVE:
|
|
|
|
{
|
2011-08-30 14:39:53 +02:00
|
|
|
if (QuestionId == 0x1248) {
|
|
|
|
{
|
|
|
|
if (Type != EFI_IFR_TYPE_REF) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value->ref.FormId = 0x3;
|
|
|
|
}
|
2011-04-12 03:15:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-05-20 04:58:35 +02:00
|
|
|
case EFI_BROWSER_ACTION_DEFAULT_STANDARD:
|
|
|
|
{
|
|
|
|
switch (QuestionId) {
|
|
|
|
case 0x1240:
|
|
|
|
Value->u8 = DEFAULT_CLASS_STANDARD_VALUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING:
|
|
|
|
{
|
|
|
|
switch (QuestionId) {
|
|
|
|
case 0x1240:
|
|
|
|
Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
case EFI_BROWSER_ACTION_CHANGING:
|
|
|
|
{
|
|
|
|
switch (QuestionId) {
|
2011-08-30 14:39:53 +02:00
|
|
|
case 0x1249:
|
|
|
|
{
|
|
|
|
if (Type != EFI_IFR_TYPE_REF) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value->ref.FormId = 0x1234;
|
|
|
|
}
|
|
|
|
break;
|
2011-04-12 03:15:28 +02:00
|
|
|
case 0x1234:
|
2010-06-02 04:05:47 +02:00
|
|
|
//
|
|
|
|
// Initialize the container for dynamic opcodes
|
|
|
|
//
|
|
|
|
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (StartOpCodeHandle != NULL);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
EndOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (EndOpCodeHandle != NULL);
|
|
|
|
|
2010-06-02 04:05:47 +02:00
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the start opcode
|
|
|
|
//
|
|
|
|
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
|
|
|
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
2011-04-12 03:15:28 +02:00
|
|
|
StartLabel->Number = LABEL_UPDATE1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the end opcode
|
|
|
|
//
|
|
|
|
EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
|
|
|
EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
EndLabel->Number = LABEL_END;
|
2010-06-02 04:05:47 +02:00
|
|
|
|
|
|
|
HiiCreateActionOpCode (
|
|
|
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
2011-04-12 03:15:28 +02:00
|
|
|
0x1237, // Question ID
|
|
|
|
STRING_TOKEN(STR_EXIT_TEXT), // Prompt text
|
|
|
|
STRING_TOKEN(STR_EXIT_TEXT), // Help text
|
2010-06-02 04:05:47 +02:00
|
|
|
EFI_IFR_FLAG_CALLBACK, // Question flag
|
|
|
|
0 // Action String ID
|
2009-10-26 06:27:28 +01:00
|
|
|
);
|
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
//
|
|
|
|
// Create Option OpCode
|
|
|
|
//
|
|
|
|
OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (OptionsOpCodeHandle != NULL);
|
|
|
|
|
|
|
|
HiiCreateOneOfOptionOpCode (
|
|
|
|
OptionsOpCodeHandle,
|
|
|
|
STRING_TOKEN (STR_BOOT_OPTION1),
|
|
|
|
0,
|
|
|
|
EFI_IFR_NUMERIC_SIZE_1,
|
|
|
|
1
|
2010-06-02 04:05:47 +02:00
|
|
|
);
|
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateOneOfOptionOpCode (
|
|
|
|
OptionsOpCodeHandle,
|
|
|
|
STRING_TOKEN (STR_BOOT_OPTION2),
|
|
|
|
0,
|
|
|
|
EFI_IFR_NUMERIC_SIZE_1,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Prepare initial value for the dynamic created oneof Question
|
|
|
|
//
|
|
|
|
PrivateData->Configuration.DynamicOneof = 2;
|
|
|
|
Status = gRT->SetVariable(
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2011-04-12 03:15:28 +02:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2010-06-02 04:05:47 +02:00
|
|
|
//
|
2011-04-12 03:15:28 +02:00
|
|
|
// Set initial vlaue of dynamic created oneof Question in Form Browser
|
2010-06-02 04:05:47 +02:00
|
|
|
//
|
2011-04-12 03:15:28 +02:00
|
|
|
Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
|
|
|
|
ASSERT (Configuration != NULL);
|
2011-09-18 14:21:01 +02:00
|
|
|
if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {
|
2011-04-12 03:15:28 +02:00
|
|
|
Configuration->DynamicOneof = 2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Update uncommitted data of Browser
|
|
|
|
//
|
|
|
|
HiiSetBrowserData (
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2011-04-12 03:15:28 +02:00
|
|
|
VariableName,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
(UINT8 *) Configuration,
|
2010-06-02 04:05:47 +02:00
|
|
|
NULL
|
|
|
|
);
|
2011-04-12 03:15:28 +02:00
|
|
|
}
|
|
|
|
FreePool (Configuration);
|
|
|
|
|
|
|
|
HiiCreateOneOfOpCode (
|
|
|
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
|
|
|
0x8001, // Question ID (or call it "key")
|
|
|
|
CONFIGURATION_VARSTORE_ID, // VarStore ID
|
|
|
|
(UINT16) DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage
|
|
|
|
STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text
|
|
|
|
STRING_TOKEN (STR_ONE_OF_HELP), // Question help text
|
|
|
|
EFI_IFR_FLAG_CALLBACK, // Question flag
|
|
|
|
EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value
|
|
|
|
OptionsOpCodeHandle, // Option Opcode list
|
|
|
|
NULL // Default Opcode is NULl
|
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateOrderedListOpCode (
|
|
|
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
|
|
|
0x8002, // Question ID
|
|
|
|
CONFIGURATION_VARSTORE_ID, // VarStore ID
|
|
|
|
(UINT16) DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage
|
|
|
|
STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text
|
|
|
|
STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text
|
|
|
|
EFI_IFR_FLAG_RESET_REQUIRED, // Question flag
|
|
|
|
0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
|
|
|
|
EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value
|
|
|
|
5, // Maximum container
|
|
|
|
OptionsOpCodeHandle, // Option Opcode list
|
|
|
|
NULL // Default Opcode is NULl
|
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateTextOpCode (
|
|
|
|
StartOpCodeHandle,
|
|
|
|
STRING_TOKEN(STR_TEXT_SAMPLE_HELP),
|
|
|
|
STRING_TOKEN(STR_TEXT_SAMPLE_HELP),
|
|
|
|
STRING_TOKEN(STR_TEXT_SAMPLE_STRING)
|
2009-04-13 08:05:15 +02:00
|
|
|
);
|
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateDateOpCode (
|
|
|
|
StartOpCodeHandle,
|
|
|
|
0x8004,
|
|
|
|
0x0,
|
|
|
|
0x0,
|
|
|
|
STRING_TOKEN(STR_DATE_SAMPLE_HELP),
|
|
|
|
STRING_TOKEN(STR_DATE_SAMPLE_HELP),
|
|
|
|
0,
|
|
|
|
QF_DATE_STORAGE_TIME,
|
|
|
|
NULL
|
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateTimeOpCode (
|
|
|
|
StartOpCodeHandle,
|
|
|
|
0x8005,
|
|
|
|
0x0,
|
|
|
|
0x0,
|
|
|
|
STRING_TOKEN(STR_TIME_SAMPLE_HELP),
|
|
|
|
STRING_TOKEN(STR_TIME_SAMPLE_HELP),
|
|
|
|
0,
|
|
|
|
QF_TIME_STORAGE_TIME,
|
|
|
|
NULL
|
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateGotoOpCode (
|
|
|
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
|
|
|
1, // Target Form ID
|
|
|
|
STRING_TOKEN (STR_GOTO_FORM1), // Prompt text
|
|
|
|
STRING_TOKEN (STR_GOTO_HELP), // Help text
|
|
|
|
0, // Question flag
|
|
|
|
0x8003 // Question ID
|
|
|
|
);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiUpdateForm (
|
|
|
|
PrivateData->HiiHandle[0], // HII handle
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid, // Formset GUID
|
2011-04-12 03:15:28 +02:00
|
|
|
0x1234, // Form ID
|
|
|
|
StartOpCodeHandle, // Label for where to insert opcodes
|
|
|
|
EndOpCodeHandle // Replace data
|
2009-10-26 06:27:28 +01:00
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
|
|
|
HiiFreeOpCodeHandle (OptionsOpCodeHandle);
|
|
|
|
HiiFreeOpCodeHandle (EndOpCodeHandle);
|
|
|
|
break;
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
case 0x5678:
|
2011-06-08 10:09:47 +02:00
|
|
|
case 0x1247:
|
2011-04-12 03:15:28 +02:00
|
|
|
//
|
|
|
|
// We will reach here once the Question is refreshed
|
|
|
|
//
|
2010-06-02 04:05:47 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
//
|
|
|
|
// Initialize the container for dynamic opcodes
|
|
|
|
//
|
|
|
|
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (StartOpCodeHandle != NULL);
|
2010-06-02 04:05:47 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the start opcode
|
|
|
|
//
|
|
|
|
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
|
|
|
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
2011-06-08 10:09:47 +02:00
|
|
|
if (QuestionId == 0x5678) {
|
|
|
|
StartLabel->Number = LABEL_UPDATE2;
|
|
|
|
FormId = 0x03;
|
|
|
|
PrivateData->Configuration.DynamicRefresh++;
|
|
|
|
} else if (QuestionId == 0x1247 ) {
|
|
|
|
StartLabel->Number = LABEL_UPDATE3;
|
2011-08-30 14:39:53 +02:00
|
|
|
FormId = 0x06;
|
2011-06-08 10:09:47 +02:00
|
|
|
PrivateData->Configuration.RefreshGuidCount++;
|
|
|
|
}
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiCreateActionOpCode (
|
|
|
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
|
|
|
0x1237, // Question ID
|
|
|
|
STRING_TOKEN(STR_EXIT_TEXT), // Prompt text
|
|
|
|
STRING_TOKEN(STR_EXIT_TEXT), // Help text
|
|
|
|
EFI_IFR_FLAG_CALLBACK, // Question flag
|
|
|
|
0 // Action String ID
|
2009-04-13 08:05:15 +02:00
|
|
|
);
|
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiUpdateForm (
|
|
|
|
PrivateData->HiiHandle[0], // HII handle
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid, // Formset GUID
|
2011-06-08 10:09:47 +02:00
|
|
|
FormId, // Form ID
|
2011-04-12 03:15:28 +02:00
|
|
|
StartOpCodeHandle, // Label for where to insert opcodes
|
|
|
|
NULL // Insert data
|
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
//
|
|
|
|
// Refresh the Question value
|
|
|
|
//
|
|
|
|
Status = gRT->SetVariable(
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2011-04-12 03:15:28 +02:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
&PrivateData->Configuration
|
|
|
|
);
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2011-06-08 10:09:47 +02:00
|
|
|
if (QuestionId == 0x5678) {
|
|
|
|
//
|
2011-08-30 14:39:53 +02:00
|
|
|
// Update uncommitted data of Browser
|
2011-06-08 10:09:47 +02:00
|
|
|
//
|
2011-08-30 14:39:53 +02:00
|
|
|
EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));
|
|
|
|
ASSERT (EfiData != NULL);
|
2011-09-18 14:21:01 +02:00
|
|
|
if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *) EfiData)) {
|
2011-08-30 14:39:53 +02:00
|
|
|
EfiData->Field8 = 111;
|
|
|
|
HiiSetBrowserData (
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2011-08-30 14:39:53 +02:00
|
|
|
MyEfiVar,
|
|
|
|
sizeof (MY_EFI_VARSTORE_DATA),
|
|
|
|
(UINT8 *) EfiData,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
FreePool (EfiData);
|
2011-06-08 10:09:47 +02:00
|
|
|
}
|
2011-04-12 03:15:28 +02:00
|
|
|
break;
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
case 0x2000:
|
|
|
|
//
|
|
|
|
// Only used to update the state.
|
|
|
|
//
|
|
|
|
if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0) &&
|
|
|
|
(PrivateData->PasswordState == BROWSER_STATE_SET_PASSWORD)) {
|
|
|
|
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
//
|
|
|
|
// When try to set a new password, user will be chanlleged with old password.
|
|
|
|
// The Callback is responsible for validating old password input by user,
|
|
|
|
// If Callback return EFI_SUCCESS, it indicates validation pass.
|
|
|
|
//
|
|
|
|
switch (PrivateData->PasswordState) {
|
|
|
|
case BROWSER_STATE_VALIDATE_PASSWORD:
|
|
|
|
Status = ValidatePassword (PrivateData, Value->string);
|
|
|
|
if (Status == EFI_SUCCESS) {
|
|
|
|
PrivateData->PasswordState = BROWSER_STATE_SET_PASSWORD;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
case BROWSER_STATE_SET_PASSWORD:
|
|
|
|
Status = SetPassword (PrivateData, Value->string);
|
|
|
|
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
|
|
|
|
break;
|
2010-12-23 07:47:50 +01:00
|
|
|
|
2011-04-12 03:15:28 +02:00
|
|
|
default:
|
|
|
|
break;
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-04-12 03:15:28 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2011-12-15 03:54:49 +01:00
|
|
|
case EFI_BROWSER_ACTION_CHANGED:
|
|
|
|
switch (QuestionId) {
|
|
|
|
case 0x1237:
|
|
|
|
//
|
|
|
|
// User press "Exit now", request Browser to exit
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1238:
|
|
|
|
//
|
|
|
|
// User press "Save now", request Browser to save the uncommitted data.
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1241:
|
|
|
|
case 0x1246:
|
|
|
|
//
|
|
|
|
// User press "Submit current form and Exit now", request Browser to submit current form and exit
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1242:
|
|
|
|
//
|
|
|
|
// User press "Discard current form now", request Browser to discard the uncommitted data.
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1243:
|
|
|
|
//
|
|
|
|
// User press "Submit current form now", request Browser to save the uncommitted data.
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1244:
|
|
|
|
case 0x1245:
|
|
|
|
//
|
|
|
|
// User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
|
|
|
|
break;
|
2015-05-13 10:45:21 +02:00
|
|
|
|
|
|
|
case 0x1231:
|
|
|
|
//
|
|
|
|
// 1. Check to see whether system support keyword.
|
|
|
|
//
|
|
|
|
Status = PrivateData->HiiKeywordHandler->GetData (PrivateData->HiiKeywordHandler,
|
|
|
|
L"NAMESPACE=x-UEFI-ns",
|
|
|
|
L"KEYWORD=iSCSIBootEnable",
|
|
|
|
&Progress,
|
|
|
|
&ProgressErr,
|
|
|
|
&Results
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
do {
|
|
|
|
CreatePopUp (
|
|
|
|
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
|
|
|
&Key,
|
|
|
|
L"",
|
|
|
|
L"This system not support this keyword!",
|
|
|
|
L"Press ENTER to continue ...",
|
|
|
|
L"",
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
} while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 2. If system support this keyword, just try to change value.
|
|
|
|
//
|
2011-12-15 03:54:49 +01:00
|
|
|
|
2015-05-13 10:45:21 +02:00
|
|
|
//
|
|
|
|
// Change value from '0' to '1' or from '1' to '0'
|
|
|
|
//
|
|
|
|
TmpStr = StrStr (Results, L"&VALUE=");
|
|
|
|
ASSERT (TmpStr != NULL);
|
|
|
|
TmpStr += StrLen (L"&VALUE=");
|
|
|
|
TmpStr++;
|
|
|
|
if (*TmpStr == L'0') {
|
|
|
|
*TmpStr = L'1';
|
|
|
|
} else {
|
|
|
|
*TmpStr = L'0';
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 3. Call the keyword handler protocol to change the value.
|
|
|
|
//
|
|
|
|
Status = PrivateData->HiiKeywordHandler->SetData (PrivateData->HiiKeywordHandler,
|
|
|
|
Results,
|
|
|
|
&Progress,
|
|
|
|
&ProgressErr
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
do {
|
|
|
|
CreatePopUp (
|
|
|
|
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
|
|
|
&Key,
|
|
|
|
L"",
|
|
|
|
L"Set keyword to the system failed!",
|
|
|
|
L"Press ENTER to continue ...",
|
|
|
|
L"",
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
} while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-15 03:54:49 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
default:
|
2011-04-12 03:15:28 +02:00
|
|
|
Status = EFI_UNSUPPORTED;
|
2008-01-21 15:39:56 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
/**
|
|
|
|
Main entry for this driver.
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-11-19 14:36:34 +01:00
|
|
|
@param ImageHandle Image handle this driver.
|
|
|
|
@param SystemTable Pointer to SystemTable.
|
|
|
|
|
|
|
|
@retval EFI_SUCESS This function always complete successfully.
|
|
|
|
|
|
|
|
**/
|
2008-01-21 15:39:56 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DriverSampleInit (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HII_HANDLE HiiHandle[2];
|
|
|
|
EFI_SCREEN_DESCRIPTOR Screen;
|
|
|
|
EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
|
|
|
|
EFI_HII_STRING_PROTOCOL *HiiString;
|
|
|
|
EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
|
|
|
|
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
|
2015-05-13 10:45:21 +02:00
|
|
|
EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;
|
2008-01-21 15:39:56 +01:00
|
|
|
CHAR16 *NewString;
|
|
|
|
UINTN BufferSize;
|
|
|
|
DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
2009-05-14 09:06:06 +02:00
|
|
|
BOOLEAN ActionFlag;
|
2009-10-26 06:27:28 +01:00
|
|
|
EFI_STRING ConfigRequestHdr;
|
2013-07-02 09:53:35 +02:00
|
|
|
EFI_STRING NameRequestHdr;
|
2011-08-30 14:39:53 +02:00
|
|
|
MY_EFI_VARSTORE_DATA *VarStoreConfig;
|
2012-02-29 05:56:26 +01:00
|
|
|
EFI_INPUT_KEY HotKey;
|
|
|
|
EFI_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
// Initialize the local variables.
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
2009-05-14 09:06:06 +02:00
|
|
|
ConfigRequestHdr = NULL;
|
2012-08-14 11:52:25 +02:00
|
|
|
NewString = NULL;
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Initialize screen dimensions for SendForm().
|
|
|
|
// Remove 3 characters from top and bottom
|
|
|
|
//
|
|
|
|
ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
|
|
|
|
gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
|
|
|
|
|
|
|
|
Screen.TopRow = 3;
|
|
|
|
Screen.BottomRow = Screen.BottomRow - 3;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize driver private data
|
|
|
|
//
|
2009-10-19 03:30:24 +02:00
|
|
|
PrivateData = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
|
2008-01-21 15:39:56 +01:00
|
|
|
if (PrivateData == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
|
|
|
|
|
|
|
|
PrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
|
|
|
|
PrivateData->ConfigAccess.RouteConfig = RouteConfig;
|
|
|
|
PrivateData->ConfigAccess.Callback = DriverCallback;
|
|
|
|
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate Hii Database protocol
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
PrivateData->HiiDatabase = HiiDatabase;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate HiiString protocol
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
PrivateData->HiiString = HiiString;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate Formbrowser2 protocol
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
PrivateData->FormBrowser2 = FormBrowser2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate ConfigRouting protocol
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
PrivateData->HiiConfigRouting = HiiConfigRouting;
|
|
|
|
|
2015-05-13 10:45:21 +02:00
|
|
|
//
|
|
|
|
// Locate keyword handler protocol
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **) &HiiKeywordHandler);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
PrivateData->HiiKeywordHandler = HiiKeywordHandler;
|
|
|
|
|
2009-04-02 10:48:03 +02:00
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
2008-01-21 15:39:56 +01:00
|
|
|
&DriverHandle[0],
|
2009-04-02 10:48:03 +02:00
|
|
|
&gEfiDevicePathProtocolGuid,
|
2009-04-09 17:22:27 +02:00
|
|
|
&mHiiVendorDevicePath0,
|
2008-01-21 15:39:56 +01:00
|
|
|
&gEfiHiiConfigAccessProtocolGuid,
|
2009-04-02 10:48:03 +02:00
|
|
|
&PrivateData->ConfigAccess,
|
|
|
|
NULL
|
2008-01-21 15:39:56 +01:00
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2009-04-02 10:48:03 +02:00
|
|
|
PrivateData->DriverHandle[0] = DriverHandle[0];
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Publish our HII data
|
|
|
|
//
|
2009-04-14 12:47:19 +02:00
|
|
|
HiiHandle[0] = HiiAddPackages (
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2009-04-14 12:47:19 +02:00
|
|
|
DriverHandle[0],
|
|
|
|
DriverSampleStrings,
|
|
|
|
VfrBin,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (HiiHandle[0] == NULL) {
|
2008-01-21 15:39:56 +01:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivateData->HiiHandle[0] = HiiHandle[0];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Publish another Fromset
|
|
|
|
//
|
2009-04-02 10:48:03 +02:00
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&DriverHandle[1],
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
2009-04-09 17:22:27 +02:00
|
|
|
&mHiiVendorDevicePath1,
|
2015-05-13 10:45:21 +02:00
|
|
|
&gEfiHiiConfigAccessProtocolGuid,
|
|
|
|
&PrivateData->ConfigAccess,
|
2009-04-02 10:48:03 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
PrivateData->DriverHandle[1] = DriverHandle[1];
|
|
|
|
|
2009-04-14 12:47:19 +02:00
|
|
|
HiiHandle[1] = HiiAddPackages (
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleInventoryGuid,
|
2009-04-14 12:47:19 +02:00
|
|
|
DriverHandle[1],
|
|
|
|
DriverSampleStrings,
|
|
|
|
InventoryBin,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (HiiHandle[1] == NULL) {
|
2010-02-11 02:59:35 +01:00
|
|
|
DriverSampleUnload (ImageHandle);
|
2008-01-21 15:39:56 +01:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivateData->HiiHandle[1] = HiiHandle[1];
|
|
|
|
|
2011-11-25 08:00:05 +01:00
|
|
|
//
|
|
|
|
// Update the device path string.
|
|
|
|
//
|
2013-07-26 05:14:08 +02:00
|
|
|
NewString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0, FALSE, FALSE);
|
2012-08-14 11:52:25 +02:00
|
|
|
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {
|
2011-11-25 08:00:05 +01:00
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2012-08-14 11:52:25 +02:00
|
|
|
if (NewString != NULL) {
|
|
|
|
FreePool (NewString);
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Very simple example of how one would update a string that is already
|
|
|
|
// in the HII database
|
|
|
|
//
|
|
|
|
NewString = L"700 Mhz";
|
|
|
|
|
2009-04-14 12:47:19 +02:00
|
|
|
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {
|
2010-02-11 02:59:35 +01:00
|
|
|
DriverSampleUnload (ImageHandle);
|
2009-04-14 12:47:19 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
|
|
|
|
2010-02-11 02:59:35 +01:00
|
|
|
HiiSetString (HiiHandle[0], 0, NewString, NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize Name/Value name String ID
|
|
|
|
//
|
|
|
|
PrivateData->NameStringId[0] = STR_NAME_VALUE_VAR_NAME0;
|
|
|
|
PrivateData->NameStringId[1] = STR_NAME_VALUE_VAR_NAME1;
|
|
|
|
PrivateData->NameStringId[2] = STR_NAME_VALUE_VAR_NAME2;
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// Initialize configuration data
|
|
|
|
//
|
|
|
|
Configuration = &PrivateData->Configuration;
|
|
|
|
ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Try to read NV config EFI variable first
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);
|
2009-05-14 09:06:06 +02:00
|
|
|
ASSERT (ConfigRequestHdr != NULL);
|
|
|
|
|
2013-07-02 09:53:35 +02:00
|
|
|
NameRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, NULL, DriverHandle[0]);
|
|
|
|
ASSERT (NameRequestHdr != NULL);
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
2011-09-18 14:21:01 +02:00
|
|
|
Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);
|
2009-05-14 09:06:06 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2009-05-18 07:03:45 +02:00
|
|
|
//
|
|
|
|
// Store zero data Buffer Storage to EFI variable
|
|
|
|
//
|
|
|
|
Status = gRT->SetVariable(
|
|
|
|
VariableName,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2009-05-18 07:03:45 +02:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
|
|
|
Configuration
|
|
|
|
);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
|
|
|
// EFI variable for NV config doesn't exit, we should build this variable
|
|
|
|
// based on default values stored in IFR
|
|
|
|
//
|
2013-07-02 09:53:35 +02:00
|
|
|
ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (!ActionFlag) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2013-07-02 09:53:35 +02:00
|
|
|
|
2009-05-14 09:06:06 +02:00
|
|
|
ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (!ActionFlag) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2009-05-14 09:06:06 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// EFI variable does exist and Validate Current Setting
|
|
|
|
//
|
2013-07-02 09:53:35 +02:00
|
|
|
ActionFlag = HiiValidateSettings (NameRequestHdr);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (!ActionFlag) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2013-07-02 09:53:35 +02:00
|
|
|
|
2009-05-14 09:06:06 +02:00
|
|
|
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (!ActionFlag) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
2011-08-30 14:39:53 +02:00
|
|
|
FreePool (ConfigRequestHdr);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2011-08-30 14:39:53 +02:00
|
|
|
//
|
|
|
|
// Initialize efi varstore configuration data
|
|
|
|
//
|
|
|
|
VarStoreConfig = &PrivateData->VarStoreConfig;
|
|
|
|
ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));
|
|
|
|
|
2011-09-18 14:21:01 +02:00
|
|
|
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);
|
2011-08-30 14:39:53 +02:00
|
|
|
ASSERT (ConfigRequestHdr != NULL);
|
|
|
|
|
|
|
|
BufferSize = sizeof (MY_EFI_VARSTORE_DATA);
|
2011-09-18 14:21:01 +02:00
|
|
|
Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);
|
2011-08-30 14:39:53 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Store zero data to EFI variable Storage.
|
|
|
|
//
|
|
|
|
Status = gRT->SetVariable(
|
|
|
|
MyEfiVar,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gDriverSampleFormSetGuid,
|
2011-08-30 14:39:53 +02:00
|
|
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
sizeof (MY_EFI_VARSTORE_DATA),
|
|
|
|
VarStoreConfig
|
|
|
|
);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
2011-08-30 14:39:53 +02:00
|
|
|
//
|
|
|
|
// EFI variable for NV config doesn't exit, we should build this variable
|
|
|
|
// based on default values stored in IFR
|
|
|
|
//
|
|
|
|
ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (!ActionFlag) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2011-08-30 14:39:53 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// EFI variable does exist and Validate Current Setting
|
|
|
|
//
|
|
|
|
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
2014-03-27 08:08:15 +01:00
|
|
|
if (!ActionFlag) {
|
|
|
|
DriverSampleUnload (ImageHandle);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2011-08-30 14:39:53 +02:00
|
|
|
}
|
2009-05-14 09:06:06 +02:00
|
|
|
FreePool (ConfigRequestHdr);
|
|
|
|
|
2011-06-08 10:09:47 +02:00
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
DriverSampleInternalEmptyFunction,
|
|
|
|
NULL,
|
2011-09-18 14:21:01 +02:00
|
|
|
&gEfiIfrRefreshIdOpGuid,
|
2011-06-08 10:09:47 +02:00
|
|
|
&mEvent
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2012-02-29 05:56:26 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Example of how to use BrowserEx protocol to register HotKey.
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (&gEfiFormBrowserExProtocolGuid, NULL, (VOID **) &FormBrowserEx);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// First unregister the default hot key F9 and F10.
|
|
|
|
//
|
|
|
|
HotKey.UnicodeChar = CHAR_NULL;
|
|
|
|
HotKey.ScanCode = SCAN_F9;
|
|
|
|
FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
|
|
|
|
HotKey.ScanCode = SCAN_F10;
|
|
|
|
FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Register the default HotKey F9 and F10 again.
|
|
|
|
//
|
|
|
|
HotKey.ScanCode = SCAN_F10;
|
|
|
|
NewString = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL);
|
|
|
|
ASSERT (NewString != NULL);
|
|
|
|
FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);
|
|
|
|
HotKey.ScanCode = SCAN_F9;
|
|
|
|
NewString = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL);
|
|
|
|
ASSERT (NewString != NULL);
|
|
|
|
FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
2009-10-26 06:27:28 +01:00
|
|
|
// In default, this driver is built into Flash device image,
|
2009-04-13 08:05:15 +02:00
|
|
|
// the following code doesn't run.
|
2008-01-21 15:39:56 +01:00
|
|
|
//
|
2009-04-13 08:05:15 +02:00
|
|
|
|
2009-04-09 17:22:27 +02:00
|
|
|
//
|
2009-04-13 08:05:15 +02:00
|
|
|
// Example of how to display only the item we sent to HII
|
2009-10-26 06:27:28 +01:00
|
|
|
// When this driver is not built into Flash device image,
|
2009-04-13 08:05:15 +02:00
|
|
|
// it need to call SendForm to show front page by itself.
|
2009-04-09 17:22:27 +02:00
|
|
|
//
|
2009-04-13 08:05:15 +02:00
|
|
|
if (DISPLAY_ONLY_MY_ITEM <= 1) {
|
|
|
|
//
|
|
|
|
// Have the browser pull out our copy of the data, and only display our data
|
|
|
|
//
|
|
|
|
Status = FormBrowser2->SendForm (
|
|
|
|
FormBrowser2,
|
|
|
|
&(HiiHandle[DISPLAY_ONLY_MY_ITEM]),
|
|
|
|
1,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2009-04-24 09:25:36 +02:00
|
|
|
HiiRemovePackages (HiiHandle[0]);
|
2009-10-26 06:27:28 +01:00
|
|
|
|
2009-04-24 09:25:36 +02:00
|
|
|
HiiRemovePackages (HiiHandle[1]);
|
2009-04-09 17:22:27 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:06:06 +02:00
|
|
|
return EFI_SUCCESS;
|
2009-04-09 17:22:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Unloads the application and its installed protocol.
|
|
|
|
|
|
|
|
@param[in] ImageHandle Handle that identifies the image to be unloaded.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The image has been unloaded.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DriverSampleUnload (
|
|
|
|
IN EFI_HANDLE ImageHandle
|
|
|
|
)
|
|
|
|
{
|
2010-02-11 02:59:35 +01:00
|
|
|
UINTN Index;
|
2010-05-17 10:32:05 +02:00
|
|
|
|
|
|
|
ASSERT (PrivateData != NULL);
|
|
|
|
|
2009-04-09 17:22:27 +02:00
|
|
|
if (DriverHandle[0] != NULL) {
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
DriverHandle[0],
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
&mHiiVendorDevicePath0,
|
|
|
|
&gEfiHiiConfigAccessProtocolGuid,
|
|
|
|
&PrivateData->ConfigAccess,
|
|
|
|
NULL
|
|
|
|
);
|
2009-10-19 03:30:24 +02:00
|
|
|
DriverHandle[0] = NULL;
|
2009-04-09 17:22:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DriverHandle[1] != NULL) {
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
DriverHandle[1],
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
&mHiiVendorDevicePath1,
|
|
|
|
NULL
|
|
|
|
);
|
2009-10-19 03:30:24 +02:00
|
|
|
DriverHandle[1] = NULL;
|
2009-04-09 17:22:27 +02:00
|
|
|
}
|
|
|
|
|
2009-04-24 09:25:36 +02:00
|
|
|
if (PrivateData->HiiHandle[0] != NULL) {
|
|
|
|
HiiRemovePackages (PrivateData->HiiHandle[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PrivateData->HiiHandle[1] != NULL) {
|
|
|
|
HiiRemovePackages (PrivateData->HiiHandle[1]);
|
|
|
|
}
|
|
|
|
|
2010-05-17 10:32:05 +02:00
|
|
|
for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
|
|
|
|
if (PrivateData->NameValueName[Index] != NULL) {
|
|
|
|
FreePool (PrivateData->NameValueName[Index]);
|
2010-02-11 02:59:35 +01:00
|
|
|
}
|
2008-01-21 15:39:56 +01:00
|
|
|
}
|
2010-05-17 10:32:05 +02:00
|
|
|
FreePool (PrivateData);
|
|
|
|
PrivateData = NULL;
|
2008-01-21 15:39:56 +01:00
|
|
|
|
2011-06-08 10:09:47 +02:00
|
|
|
gBS->CloseEvent (mEvent);
|
|
|
|
|
2008-01-21 15:39:56 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|