/** @file
Provides a way for 3rd party applications to register themselves for launch by the
Boot Manager based on hot key
Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
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 "Hotkey.h"
/**
Check if the Key Option is valid or not.
@param KeyOption The Hot Key Option to be checked.
@retval TRUE The Hot Key Option is valid.
@retval FALSE The Hot Key Option is invalid.
**/
)
{
//
// Check whether corresponding Boot Option exist
//
);
return FALSE;
}
//
// Check CRC for Boot Option
//
}
/**
Create Key#### for the given hotkey.
@param KeyOption The Hot Key Option to be added.
@param KeyOptionNumber The key option number for Key#### (optional).
@retval EFI_SUCCESS Register hotkey successfully.
@retval EFI_INVALID_PARAMETER The hotkey option is invalid.
@retval EFI_OUT_OF_RESOURCES Fail to allocate memory resource.
**/
)
{
//
// Validate the given key option
//
if (!IsKeyOptionValid (KeyOption)) {
return EFI_INVALID_PARAMETER;
}
KeyOptionSize = sizeof (EFI_KEY_OPTION) + KeyOption->KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY);
//
// Check whether HotKey conflict with keys used by Setup Browser
//
);
KeyOrderSize = 0;
}
//
// Find free key option number
//
MaxOptionNumber = 0;
TempOption = NULL;
}
);
//
// Got the option, so just return
//
return EFI_SUCCESS;
}
KeyOptionSize - sizeof (EFI_KEY_OPTION)
) == 0) {
//
// Hotkey is the same but BootOption changed, need update
//
break;
}
}
}
if (UpdateBootOption) {
} else {
}
if (KeyOptionNumber != NULL) {
}
//
// Create variable Key####
//
);
return Status;
}
//
// Update the key order variable - "KeyOrder"
//
if (!UpdateBootOption) {
KeyOrderSize += sizeof (UINT16);
}
if (NewKeyOrder == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
);
return Status;
}
/**
Delete Key#### for the given Key Option number.
@param KeyOptionNumber Key option number for Key####
@retval EFI_SUCCESS Unregister hotkey successfully.
@retval EFI_NOT_FOUND No Key#### is found for the given Key Option number.
**/
)
{
//
// Delete variable Key####
//
gRT->SetVariable (
0,
);
//
// Adjust key order array
//
);
return EFI_SUCCESS;
}
Index2Del = 0;
break;
}
}
//
// KeyOptionNumber found in "KeyOrder", delete it
//
}
KeyOrderSize -= sizeof (UINT16);
}
);
return Status;
}
/**
Try to boot the boot option triggered by hotkey.
@retval EFI_SUCCESS There is HotkeyBootOption & it is processed
@retval EFI_NOT_FOUND There is no HotkeyBootOption
**/
)
{
if (mHotkeyBootOption == NULL) {
return EFI_NOT_FOUND;
}
//
// Clear the screen before launch this BootOption
//
Status = BdsLibBootViaBootOption (mHotkeyBootOption, mHotkeyBootOption->DevicePath, &ExitDataSize, &ExitData);
//
// Call platform action to indicate the boot fail
//
} else {
//
// Call platform action to indicate the boot success
//
}
return EFI_SUCCESS;
}
/**
This is the common notification function for HotKeys, it will be registered
with SimpleTextInEx protocol interface - RegisterKeyNotify() of ConIn handle.
@param KeyData A pointer to a buffer that is filled in with the keystroke
information for the key that was pressed.
@retval EFI_SUCCESS KeyData is successfully processed.
@return EFI_NOT_FOUND Fail to find boot option variable.
**/
)
{
if (mHotkeyBootOption != NULL) {
//
// Do not process sequential hotkey stroke until the current boot option returns
//
return EFI_SUCCESS;
}
) {
//
// Is this Key Stroke we are waiting for?
//
)
) {
//
// For hotkey of key combination, transit to next waiting state
//
Hotkey->WaitingKey++;
//
// Received the whole key stroke sequence
//
}
} else {
//
// Receive an unexpected key stroke, reset to initial waiting state
//
Hotkey->WaitingKey = 0;
}
if (HotkeyCatched) {
//
// Reset to initial waiting state
//
Hotkey->WaitingKey = 0;
//
// Launch its BootOption
//
}
}
return Status;
}
/**
Register the common HotKey notify function to given SimpleTextInEx protocol instance.
@param SimpleTextInEx Simple Text Input Ex protocol instance
@retval EFI_SUCCESS Register hotkey notification function successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary data structures.
**/
)
{
//
// Register notification function for each hotkey
//
Index = 0;
do {
);
//
// some of the hotkey registry failed
//
return Status;
}
Index ++;
} while ((Index < Hotkey->CodeCount) && (Index < (sizeof (Hotkey->KeyData) / sizeof (EFI_KEY_DATA))));
}
return EFI_SUCCESS;
}
/**
Callback function for SimpleTextInEx protocol install events
@param Event the event that is signaled.
@param Context not used here.
**/
)
{
while (TRUE) {
BufferSize = sizeof (EFI_HANDLE);
NULL,
);
//
// If no more notification events exist
//
return ;
}
(VOID **) &SimpleTextInEx
);
}
}
/**
Insert Key Option to hotkey list.
@param KeyOption The Hot Key Option to be added to hotkey list.
@retval EFI_SUCCESS Add to hotkey list success.
@retval EFI_OUT_OF_RESOURCES Fail to allocate memory resource.
**/
)
{
if (HotkeyLeft == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Map key shift state from KeyOptions to EFI_KEY_DATA.KeyState
//
}
}
}
}
}
}
Index = 0;
do {
//
// If Key CodeCount is 0, then only KeyData[0] is used;
// if Key CodeCount is n, then KeyData[0]~KeyData[n-1] are used
//
Index++;
KeyData++;
if (KeyShiftStateLeft != KeyShiftStateRight) {
//
// Need an extra hotkey for shift key on right
//
if (HotkeyRight == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Index = 0;
do {
//
// Key.ScanCode and Key.UnicodeChar have already been initialized,
// only need to update KeyState.KeyShiftState
//
Index++;
KeyData++;
}
return EFI_SUCCESS;
}
/**
Process all the "Key####" variables, associate Hotkeys with corresponding Boot Options.
@retval EFI_SUCCESS Hotkey services successfully initialized.
@retval EFI_NOT_FOUND Can not find the "KeyOrder" variable
**/
)
{
//
// Export our capability - EFI_BOOT_OPTION_SUPPORT_KEY and EFI_BOOT_OPTION_SUPPORT_APP
// with maximum number of key presses of 3
//
L"BootOptionSupport",
sizeof (UINT32),
);
//
// Get valid Key Option List from private EFI variable "KeyOrder"
//
);
return EFI_NOT_FOUND;
}
);
} else {
}
}
//
// Register Protocol notify for Hotkey service
//
NULL,
);
//
// Register for protocol notifications on this event
//
);
return Status;
}