mirror of https://github.com/acidanthera/audk.git
Add example usage of EFI_BROWSER_ACTION_FORM_OPEN and EFI_BROWSER_ACTION_FORM_CLOSE to DriverSample.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9365 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
ce6d12cce0
commit
a6973cff62
|
@ -2,7 +2,7 @@
|
||||||
This is an example of how a driver might export data to the HII protocol to be
|
This is an example of how a driver might export data to the HII protocol to be
|
||||||
later utilized by the Setup Protocol
|
later utilized by the Setup Protocol
|
||||||
|
|
||||||
Copyright (c) 2004 - 2008, Intel Corporation
|
Copyright (c) 2004 - 2009, Intel Corporation
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -43,7 +43,7 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {
|
||||||
{
|
{
|
||||||
END_DEVICE_PATH_TYPE,
|
END_DEVICE_PATH_TYPE,
|
||||||
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
||||||
{
|
{
|
||||||
(UINT8) (END_DEVICE_PATH_LENGTH),
|
(UINT8) (END_DEVICE_PATH_LENGTH),
|
||||||
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
|
||||||
{
|
{
|
||||||
END_DEVICE_PATH_TYPE,
|
END_DEVICE_PATH_TYPE,
|
||||||
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
||||||
{
|
{
|
||||||
(UINT8) (END_DEVICE_PATH_LENGTH),
|
(UINT8) (END_DEVICE_PATH_LENGTH),
|
||||||
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
||||||
}
|
}
|
||||||
|
@ -77,10 +77,10 @@ HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encode the password using a simple algorithm.
|
Encode the password using a simple algorithm.
|
||||||
|
|
||||||
@param Password The string to be encoded.
|
@param Password The string to be encoded.
|
||||||
@param MaxSize The size of the string.
|
@param MaxSize The size of the string.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
EncodePassword (
|
EncodePassword (
|
||||||
|
@ -111,10 +111,10 @@ EncodePassword (
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Validate the user's password.
|
Validate the user's password.
|
||||||
|
|
||||||
@param PrivateData This driver's private context data.
|
@param PrivateData This driver's private context data.
|
||||||
@param StringId The user's input.
|
@param StringId The user's input.
|
||||||
|
|
||||||
@retval EFI_SUCCESS The user's input matches the password.
|
@retval EFI_SUCCESS The user's input matches the password.
|
||||||
@retval EFI_NOT_READY The user's input does not match the password.
|
@retval EFI_NOT_READY The user's input does not match the password.
|
||||||
**/
|
**/
|
||||||
|
@ -204,13 +204,13 @@ ValidatePassword (
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encode the password using a simple algorithm.
|
Encode the password using a simple algorithm.
|
||||||
|
|
||||||
@param PrivateData This driver's private context data.
|
@param PrivateData This driver's private context data.
|
||||||
@param StringId The password from User.
|
@param StringId The password from User.
|
||||||
|
|
||||||
@retval EFI_SUCESS The operation is successful.
|
@retval EFI_SUCESS The operation is successful.
|
||||||
@return Other value if gRT->SetVariable () fails.
|
@return Other value if gRT->SetVariable () fails.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
SetPassword (
|
SetPassword (
|
||||||
|
@ -244,9 +244,9 @@ SetPassword (
|
||||||
// Get user input password
|
// Get user input password
|
||||||
//
|
//
|
||||||
Password = &PrivateData->Configuration.WhatIsThePassword2[0];
|
Password = &PrivateData->Configuration.WhatIsThePassword2[0];
|
||||||
PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
|
PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
|
||||||
ZeroMem (Password, PasswordSize);
|
ZeroMem (Password, PasswordSize);
|
||||||
|
|
||||||
TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);
|
TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);
|
||||||
if (TempPassword == NULL) {
|
if (TempPassword == NULL) {
|
||||||
return EFI_NOT_READY;
|
return EFI_NOT_READY;
|
||||||
|
@ -344,7 +344,7 @@ ExtractConfig (
|
||||||
EFI_STRING ConfigRequest;
|
EFI_STRING ConfigRequest;
|
||||||
EFI_STRING ConfigRequestHdr;
|
EFI_STRING ConfigRequestHdr;
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
|
|
||||||
if (Progress == NULL || Results == NULL || Request == NULL) {
|
if (Progress == NULL || Results == NULL || Request == NULL) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
@ -374,14 +374,14 @@ ExtractConfig (
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Request == NULL) {
|
if (Request == NULL) {
|
||||||
//
|
//
|
||||||
// Request is set to NULL, construct full request string.
|
// Request is set to NULL, construct full request string.
|
||||||
//
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate and fill a buffer large enough to hold the <ConfigHdr> template
|
// Allocate and fill a buffer large enough to hold the <ConfigHdr> template
|
||||||
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
|
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
|
||||||
//
|
//
|
||||||
ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
|
ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
|
||||||
|
@ -411,7 +411,7 @@ ExtractConfig (
|
||||||
Results,
|
Results,
|
||||||
Progress
|
Progress
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Request == NULL) {
|
if (Request == NULL) {
|
||||||
FreePool (ConfigRequest);
|
FreePool (ConfigRequest);
|
||||||
*Progress = NULL;
|
*Progress = NULL;
|
||||||
|
@ -554,15 +554,76 @@ DriverCallback (
|
||||||
EFI_IFR_GUID_LABEL *StartLabel;
|
EFI_IFR_GUID_LABEL *StartLabel;
|
||||||
VOID *EndOpCodeHandle;
|
VOID *EndOpCodeHandle;
|
||||||
EFI_IFR_GUID_LABEL *EndLabel;
|
EFI_IFR_GUID_LABEL *EndLabel;
|
||||||
|
EFI_INPUT_KEY Key;
|
||||||
|
DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
||||||
|
|
||||||
|
if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
|
||||||
|
//
|
||||||
|
// On FORM_OPEN event, update the form on-the-fly
|
||||||
|
//
|
||||||
|
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
|
||||||
|
&mFormSetGuid, // Formset GUID
|
||||||
|
0x3, // Form ID
|
||||||
|
StartOpCodeHandle, // Label for where to insert opcodes
|
||||||
|
NULL // Insert data
|
||||||
|
);
|
||||||
|
|
||||||
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
|
||||||
|
//
|
||||||
|
// On FORM_CLOSE event, show up a pop-up
|
||||||
|
//
|
||||||
|
do {
|
||||||
|
CreatePopUp (
|
||||||
|
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
||||||
|
&Key,
|
||||||
|
L"",
|
||||||
|
L"You are going to leave the Form!",
|
||||||
|
L"Press ESC or ENTER to continue ...",
|
||||||
|
L"",
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if ((Value == NULL) || (ActionRequest == NULL)) {
|
if ((Value == NULL) || (ActionRequest == NULL)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0)) {
|
if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
||||||
|
@ -635,6 +696,28 @@ DriverCallback (
|
||||||
&PrivateData->Configuration
|
&PrivateData->Configuration
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set initial vlaue of dynamic created oneof Question in Form Browser
|
||||||
|
//
|
||||||
|
Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
|
||||||
|
ASSERT (Configuration != NULL);
|
||||||
|
Status = HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
Configuration->DynamicOneof = 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update uncommitted data of Browser
|
||||||
|
//
|
||||||
|
HiiSetBrowserData (
|
||||||
|
&mFormSetGuid,
|
||||||
|
VariableName,
|
||||||
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
||||||
|
(UINT8 *) Configuration,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
FreePool (Configuration);
|
||||||
|
|
||||||
HiiCreateOneOfOpCode (
|
HiiCreateOneOfOpCode (
|
||||||
StartOpCodeHandle, // Container for dynamic created opcodes
|
StartOpCodeHandle, // Container for dynamic created opcodes
|
||||||
0x8001, // Question ID (or call it "key")
|
0x8001, // Question ID (or call it "key")
|
||||||
|
@ -682,8 +765,9 @@ DriverCallback (
|
||||||
|
|
||||||
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
||||||
HiiFreeOpCodeHandle (OptionsOpCodeHandle);
|
HiiFreeOpCodeHandle (OptionsOpCodeHandle);
|
||||||
|
HiiFreeOpCodeHandle (EndOpCodeHandle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x5678:
|
case 0x5678:
|
||||||
//
|
//
|
||||||
// We will reach here once the Question is refreshed
|
// We will reach here once the Question is refreshed
|
||||||
|
@ -710,7 +794,7 @@ DriverCallback (
|
||||||
EFI_IFR_FLAG_CALLBACK, // Question flag
|
EFI_IFR_FLAG_CALLBACK, // Question flag
|
||||||
0 // Action String ID
|
0 // Action String ID
|
||||||
);
|
);
|
||||||
|
|
||||||
HiiUpdateForm (
|
HiiUpdateForm (
|
||||||
PrivateData->HiiHandle[0], // HII handle
|
PrivateData->HiiHandle[0], // HII handle
|
||||||
&mFormSetGuid, // Formset GUID
|
&mFormSetGuid, // Formset GUID
|
||||||
|
@ -719,8 +803,8 @@ DriverCallback (
|
||||||
NULL // Insert data
|
NULL // Insert data
|
||||||
);
|
);
|
||||||
|
|
||||||
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Refresh the Question value
|
// Refresh the Question value
|
||||||
//
|
//
|
||||||
|
@ -732,7 +816,7 @@ DriverCallback (
|
||||||
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
||||||
&PrivateData->Configuration
|
&PrivateData->Configuration
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
|
// Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
|
||||||
// the first statement in Form 3 be suppressed
|
// the first statement in Form 3 be suppressed
|
||||||
|
@ -795,7 +879,7 @@ DriverCallback (
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Main entry for this driver.
|
Main entry for this driver.
|
||||||
|
|
||||||
@param ImageHandle Image handle this driver.
|
@param ImageHandle Image handle this driver.
|
||||||
@param SystemTable Pointer to SystemTable.
|
@param SystemTable Pointer to SystemTable.
|
||||||
|
|
||||||
|
@ -820,8 +904,8 @@ DriverSampleInit (
|
||||||
UINTN BufferSize;
|
UINTN BufferSize;
|
||||||
DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
||||||
BOOLEAN ActionFlag;
|
BOOLEAN ActionFlag;
|
||||||
EFI_STRING ConfigRequestHdr;
|
EFI_STRING ConfigRequestHdr;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize the local variables.
|
// Initialize the local variables.
|
||||||
//
|
//
|
||||||
|
@ -990,18 +1074,18 @@ DriverSampleInit (
|
||||||
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
||||||
ASSERT (ActionFlag);
|
ASSERT (ActionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
FreePool (ConfigRequestHdr);
|
FreePool (ConfigRequestHdr);
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// In default, this driver is built into Flash device image,
|
// In default, this driver is built into Flash device image,
|
||||||
// the following code doesn't run.
|
// the following code doesn't run.
|
||||||
//
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
// Example of how to display only the item we sent to HII
|
// Example of how to display only the item we sent to HII
|
||||||
// When this driver is not built into Flash device image,
|
// When this driver is not built into Flash device image,
|
||||||
// it need to call SendForm to show front page by itself.
|
// it need to call SendForm to show front page by itself.
|
||||||
//
|
//
|
||||||
if (DISPLAY_ONLY_MY_ITEM <= 1) {
|
if (DISPLAY_ONLY_MY_ITEM <= 1) {
|
||||||
|
@ -1017,9 +1101,9 @@ DriverSampleInit (
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
HiiRemovePackages (HiiHandle[0]);
|
HiiRemovePackages (HiiHandle[0]);
|
||||||
|
|
||||||
HiiRemovePackages (HiiHandle[1]);
|
HiiRemovePackages (HiiHandle[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Copyright (c) 2007, Intel Corporation
|
Copyright (c) 2007 - 2009, Intel Corporation
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -43,6 +43,7 @@ Revision History
|
||||||
#include <Library/HiiLib.h>
|
#include <Library/HiiLib.h>
|
||||||
#include <Library/DevicePathLib.h>
|
#include <Library/DevicePathLib.h>
|
||||||
#include <Library/PrintLib.h>
|
#include <Library/PrintLib.h>
|
||||||
|
#include <Library/UefiLib.h>
|
||||||
|
|
||||||
#include "NVDataStruc.h"
|
#include "NVDataStruc.h"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# This is a sample driver which show how HII protocol, VFR and UNI files are used to
|
# This is a sample driver which show how HII protocol, VFR and UNI files are used to
|
||||||
# create a driver which can be dipslayed and configured by a UEFI HII Form Browser.
|
# create a driver which can be dipslayed and configured by a UEFI HII Form Browser.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.
|
# Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.
|
||||||
#
|
#
|
||||||
# All rights reserved. This program and the accompanying materials
|
# All rights reserved. This program and the accompanying materials
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
@ -55,6 +55,7 @@
|
||||||
DebugLib
|
DebugLib
|
||||||
HiiLib
|
HiiLib
|
||||||
PrintLib
|
PrintLib
|
||||||
|
UefiLib
|
||||||
|
|
||||||
[Guids]
|
[Guids]
|
||||||
gEfiIfrTianoGuid ## CONSUMES ## Guid
|
gEfiIfrTianoGuid ## CONSUMES ## Guid
|
||||||
|
|
Loading…
Reference in New Issue