SCAN_F12, // EFI_FUNCTION_KEY_TWELVE_MODIFIER\r
};\r
\r
-EFI_GUID mKeyboardLayoutEventGuid = EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID;\r
-\r
/**\r
Initialize Key Convertion Table by using default keyboard layout.\r
\r
KeyboardLayout\r
);\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (KeyboardLayout);\r
+ FreePool (KeyboardLayout);\r
KeyboardLayout = NULL;\r
}\r
}\r
NsKey = KeyDescriptor + 1;\r
for (Index2 = Index + 1; Index2 < KeyboardLayout->DescriptorCount; Index2++) {\r
CopyMem (&TempKey, NsKey, sizeof (EFI_KEY_DESCRIPTOR));\r
- if (TempKey.Modifier & EFI_NS_KEY_DEPENDENCY_MODIFIER) {\r
+ if (TempKey.Modifier == EFI_NS_KEY_DEPENDENCY_MODIFIER) {\r
KeyCount++;\r
} else {\r
break;\r
TPL_NOTIFY,\r
SetKeyboardLayoutEvent,\r
UsbKeyboardDevice,\r
- &mKeyboardLayoutEventGuid,\r
+ &gEfiHiiKeyBoardLayoutGuid,\r
&UsbKeyboardDevice->KeyboardLayoutEvent\r
);\r
if (EFI_ERROR (Status)) {\r
//\r
// Set boot protocol for the USB Keyboard.\r
// This driver only supports boot protocol.\r
- // The device that does not support boot protocol is not supported.\r
//\r
if (Protocol != BOOT_PROTOCOL) {\r
UsbSetProtocolRequest (\r
ZeroMem (UsbKeyboardDevice->LastKeyCodeArray, sizeof (UINT8) * 8);\r
\r
//\r
- // Set a timer for repeat keys' generation.\r
+ // Create event for repeat keys' generation.\r
//\r
if (UsbKeyboardDevice->RepeatTimer != NULL) {\r
gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
UsbKeyboardDevice->RepeatTimer = NULL;\r
}\r
\r
- Status = gBS->CreateEvent (\r
- EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- USBKeyboardRepeatHandler,\r
- UsbKeyboardDevice,\r
- &UsbKeyboardDevice->RepeatTimer\r
- );\r
+ gBS->CreateEvent (\r
+ EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+ TPL_NOTIFY,\r
+ USBKeyboardRepeatHandler,\r
+ UsbKeyboardDevice,\r
+ &UsbKeyboardDevice->RepeatTimer\r
+ );\r
\r
+ //\r
+ // Create event for delayed recovery, which deals with device error.\r
+ //\r
if (UsbKeyboardDevice->DelayedRecoveryEvent != NULL) {\r
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
UsbKeyboardDevice->DelayedRecoveryEvent = NULL;\r
}\r
\r
- Status = gBS->CreateEvent (\r
- EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- USBKeyboardRecoveryHandler,\r
- UsbKeyboardDevice,\r
- &UsbKeyboardDevice->DelayedRecoveryEvent\r
- );\r
+ gBS->CreateEvent (\r
+ EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+ TPL_NOTIFY,\r
+ USBKeyboardRecoveryHandler,\r
+ UsbKeyboardDevice,\r
+ &UsbKeyboardDevice->DelayedRecoveryEvent\r
+ );\r
\r
return EFI_SUCCESS;\r
}\r
// Handle repeat key\r
//\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]);\r
+ ASSERT (KeyDescriptor != NULL);\r
+\r
if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) {\r
//\r
// For NumLock or CapsLock pressed, there is no need to handle repeat key for them.\r
RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
+ ASSERT (KeyDescriptor != NULL);\r
\r
switch (KeyDescriptor->Modifier) {\r
\r
RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
+ ASSERT (KeyDescriptor != NULL);\r
+\r
if (!UsbKey.Down) {\r
//\r
// Key is released.\r
@retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.\r
@retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.\r
@retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER\r
+ @retval EFI_DEVICE_ERROR Keyboard layout is invalid.\r
\r
**/\r
EFI_STATUS\r
}\r
\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);\r
+ ASSERT (KeyDescriptor != NULL);\r
\r
if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) {\r
//\r
UsbKeyboardDevice->CurrentNsKey = NULL;\r
}\r
\r
+ //\r
+ // Make sure modifier of Key Descriptor is in the valid range according to UEFI spec.\r
+ //\r
+ if (KeyDescriptor->Modifier > EFI_FUNCTION_KEY_TWELVE_MODIFIER) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
Key->ScanCode = ModifierValueToEfiScanCodeConvertionTable[KeyDescriptor->Modifier];\r
Key->UnicodeChar = KeyDescriptor->Unicode;\r
\r
}\r
}\r
\r
- if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) {\r
+ if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) != 0) {\r
//\r
// For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means\r
// normal key, instead of original control key. So the ScanCode should be cleaned.\r
RemoveKeyCode (KeyboardBuffer, &UsbKey);\r
}\r
\r
+ ASSERT (KeyboardBuffer->BufferTail <= MAX_KEY_ALLOWED);\r
+\r
KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].KeyCode = Key;\r
KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].Down = Down;\r
\r
return EFI_DEVICE_ERROR;\r
}\r
\r
+ ASSERT (KeyboardBuffer->BufferHead <= MAX_KEY_ALLOWED);\r
+\r
UsbKey->KeyCode = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].KeyCode;\r
UsbKey->Down = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].Down;\r
\r