]>
Commit | Line | Data |
---|---|---|
067ed98a RN |
1 | /** @file\r |
2 | Hotkey library functions.\r | |
3 | \r | |
4 | Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "InternalBm.h"\r | |
16 | \r | |
17 | //\r | |
18 | // Lock for linked list\r | |
19 | //\r | |
20 | EFI_LOCK mBmHotkeyLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r | |
21 | LIST_ENTRY mBmHotkeyList = INITIALIZE_LIST_HEAD_VARIABLE (mBmHotkeyList);\r | |
22 | EFI_EVENT mBmHotkeyTriggered = NULL;\r | |
23 | BOOLEAN mBmHotkeyServiceStarted = FALSE;\r | |
24 | UINTN mBmHotkeySupportCount = 0;\r | |
25 | \r | |
26 | //\r | |
27 | // Set OptionNumber as unassigned value to indicate the option isn't initialized\r | |
28 | //\r | |
29 | EFI_BOOT_MANAGER_LOAD_OPTION mBmHotkeyBootOption = { LoadOptionNumberUnassigned };\r | |
30 | \r | |
31 | EFI_BOOT_MANAGER_KEY_OPTION *mBmContinueKeyOption = NULL;\r | |
32 | VOID *mBmTxtInExRegistration = NULL;\r | |
33 | \r | |
121300c4 RN |
34 | \r |
35 | /**\r | |
36 | Return the buffer size of the EFI_BOOT_MANAGER_KEY_OPTION data.\r | |
37 | \r | |
38 | @param KeyOption The input key option info.\r | |
39 | \r | |
40 | @retval The buffer size of the key option data.\r | |
41 | **/\r | |
42 | UINTN\r | |
43 | BmSizeOfKeyOption (\r | |
44 | EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r | |
45 | )\r | |
46 | {\r | |
47 | return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys)\r | |
48 | + KeyOption->KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY);\r | |
49 | }\r | |
50 | \r | |
067ed98a RN |
51 | /**\r |
52 | \r | |
53 | Check whether the input key option is valid.\r | |
54 | \r | |
121300c4 RN |
55 | @param KeyOption Key option.\r |
56 | @param KeyOptionSize Size of the key option.\r | |
067ed98a RN |
57 | \r |
58 | @retval TRUE Input key option is valid.\r | |
59 | @retval FALSE Input key option is not valid.\r | |
60 | **/\r | |
61 | BOOLEAN\r | |
62 | BmIsKeyOptionValid (\r | |
121300c4 RN |
63 | IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,\r |
64 | IN UINTN KeyOptionSize\r | |
067ed98a RN |
65 | )\r |
66 | {\r | |
f9a24380 | 67 | UINT16 OptionName[BM_OPTION_NAME_LEN];\r |
067ed98a RN |
68 | UINT8 *BootOption;\r |
69 | UINTN BootOptionSize;\r | |
70 | UINT32 Crc;\r | |
71 | \r | |
121300c4 RN |
72 | if (BmSizeOfKeyOption (KeyOption) != KeyOptionSize) {\r |
73 | return FALSE;\r | |
74 | }\r | |
75 | \r | |
067ed98a RN |
76 | //\r |
77 | // Check whether corresponding Boot Option exist\r | |
78 | //\r | |
121300c4 RN |
79 | UnicodeSPrint (\r |
80 | OptionName, sizeof (OptionName), L"%s%04x",\r | |
81 | mBmLoadOptionName[LoadOptionTypeBoot], KeyOption->BootOption\r | |
82 | );\r | |
067ed98a RN |
83 | GetEfiGlobalVariable2 (OptionName, (VOID **) &BootOption, &BootOptionSize);\r |
84 | \r | |
85 | if (BootOption == NULL) {\r | |
86 | return FALSE;\r | |
87 | }\r | |
88 | \r | |
89 | //\r | |
90 | // Check CRC for Boot Option\r | |
91 | //\r | |
92 | gBS->CalculateCrc32 (BootOption, BootOptionSize, &Crc);\r | |
93 | FreePool (BootOption);\r | |
94 | \r | |
95 | return (BOOLEAN) (KeyOption->BootOptionCrc == Crc);\r | |
96 | }\r | |
97 | \r | |
98 | /**\r | |
99 | \r | |
100 | Check whether the input variable is an key option variable.\r | |
101 | \r | |
102 | @param Name Input variable name.\r | |
103 | @param Guid Input variable guid.\r | |
104 | @param OptionNumber The option number of this key option variable.\r | |
105 | \r | |
106 | @retval TRUE Input variable is a key option variable.\r | |
107 | @retval FALSE Input variable is not a key option variable.\r | |
108 | **/\r | |
109 | BOOLEAN\r | |
110 | BmIsKeyOptionVariable (\r | |
111 | CHAR16 *Name,\r | |
112 | EFI_GUID *Guid,\r | |
113 | UINT16 *OptionNumber\r | |
114 | )\r | |
115 | {\r | |
116 | UINTN Index;\r | |
418e8cd9 | 117 | UINTN Uint;\r |
067ed98a RN |
118 | \r |
119 | if (!CompareGuid (Guid, &gEfiGlobalVariableGuid) ||\r | |
120 | (StrSize (Name) != sizeof (L"Key####")) ||\r | |
121 | (StrnCmp (Name, L"Key", 3) != 0)\r | |
122 | ) {\r | |
123 | return FALSE;\r | |
124 | }\r | |
125 | \r | |
126 | *OptionNumber = 0;\r | |
127 | for (Index = 3; Index < 7; Index++) {\r | |
418e8cd9 RN |
128 | Uint = BmCharToUint (Name[Index]);\r |
129 | if (Uint == -1) {\r | |
067ed98a | 130 | return FALSE;\r |
418e8cd9 RN |
131 | } else {\r |
132 | *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;\r | |
067ed98a RN |
133 | }\r |
134 | }\r | |
135 | \r | |
136 | return TRUE;\r | |
137 | }\r | |
138 | \r | |
121300c4 RN |
139 | typedef struct {\r |
140 | EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r | |
141 | UINTN KeyOptionCount;\r | |
142 | } BM_COLLECT_KEY_OPTIONS_PARAM;\r | |
067ed98a | 143 | \r |
121300c4 RN |
144 | /**\r |
145 | Visitor function to collect the key options from NV storage.\r | |
067ed98a | 146 | \r |
121300c4 RN |
147 | @param Name Variable name.\r |
148 | @param Guid Variable GUID.\r | |
149 | @param Context The same context passed to BmForEachVariable.\r | |
067ed98a | 150 | **/\r |
121300c4 RN |
151 | VOID\r |
152 | BmCollectKeyOptions (\r | |
153 | CHAR16 *Name,\r | |
154 | EFI_GUID *Guid,\r | |
155 | VOID *Context\r | |
067ed98a RN |
156 | )\r |
157 | {\r | |
121300c4 RN |
158 | UINTN Index;\r |
159 | BM_COLLECT_KEY_OPTIONS_PARAM *Param;\r | |
160 | EFI_BOOT_MANAGER_KEY_OPTION *KeyOption;\r | |
161 | UINT16 OptionNumber;\r | |
162 | UINTN KeyOptionSize;\r | |
163 | \r | |
164 | Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context;\r | |
165 | \r | |
166 | if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {\r | |
167 | GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize);\r | |
168 | ASSERT (KeyOption != NULL);\r | |
169 | KeyOption->OptionNumber = OptionNumber;\r | |
170 | if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {\r | |
171 | Param->KeyOptions = ReallocatePool (\r | |
172 | Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),\r | |
173 | (Param->KeyOptionCount + 1) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),\r | |
174 | Param->KeyOptions\r | |
175 | );\r | |
176 | ASSERT (Param->KeyOptions != NULL);\r | |
177 | //\r | |
178 | // Insert the key option in order\r | |
179 | //\r | |
180 | for (Index = 0; Index < Param->KeyOptionCount; Index++) {\r | |
181 | if (KeyOption->OptionNumber < Param->KeyOptions[Index].OptionNumber) {\r | |
182 | break;\r | |
183 | }\r | |
184 | }\r | |
185 | CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r | |
186 | CopyMem (&Param->KeyOptions[Index], KeyOption, BmSizeOfKeyOption (KeyOption));\r | |
187 | Param->KeyOptionCount++;\r | |
188 | }\r | |
189 | FreePool (KeyOption);\r | |
190 | }\r | |
067ed98a RN |
191 | }\r |
192 | \r | |
193 | /**\r | |
194 | Return the array of key options.\r | |
195 | \r | |
196 | @param Count Return the number of key options.\r | |
197 | \r | |
198 | @retval NULL No key option.\r | |
199 | @retval Other Pointer to the key options.\r | |
200 | **/\r | |
201 | EFI_BOOT_MANAGER_KEY_OPTION *\r | |
202 | BmGetKeyOptions (\r | |
203 | OUT UINTN *Count\r | |
204 | )\r | |
205 | {\r | |
121300c4 | 206 | BM_COLLECT_KEY_OPTIONS_PARAM Param;\r |
067ed98a RN |
207 | \r |
208 | if (Count == NULL) {\r | |
209 | return NULL;\r | |
210 | }\r | |
211 | \r | |
121300c4 RN |
212 | Param.KeyOptions = NULL;\r |
213 | Param.KeyOptionCount = 0;\r | |
067ed98a | 214 | \r |
121300c4 | 215 | BmForEachVariable (BmCollectKeyOptions, (VOID *) &Param);\r |
067ed98a | 216 | \r |
121300c4 | 217 | *Count = Param.KeyOptionCount;\r |
067ed98a | 218 | \r |
121300c4 | 219 | return Param.KeyOptions;\r |
067ed98a RN |
220 | }\r |
221 | \r | |
222 | /**\r | |
223 | Callback function for event.\r | |
224 | \r | |
225 | @param Event Event for this callback function.\r | |
226 | @param Context Context pass to this function.\r | |
227 | **/\r | |
228 | VOID\r | |
229 | EFIAPI\r | |
230 | BmEmptyFunction (\r | |
231 | IN EFI_EVENT Event,\r | |
232 | IN VOID *Context\r | |
233 | )\r | |
234 | {\r | |
235 | }\r | |
236 | \r | |
237 | /**\r | |
238 | Check whether the bit is set in the value.\r | |
239 | \r | |
240 | @param Value The value need to be check.\r | |
241 | @param Bit The bit filed need to be check.\r | |
242 | \r | |
243 | @retval TRUE The bit is set.\r | |
244 | @retval FALSE The bit is not set.\r | |
245 | **/\r | |
246 | BOOLEAN\r | |
247 | BmBitSet (\r | |
248 | IN UINT32 Value,\r | |
249 | IN UINT32 Bit\r | |
250 | )\r | |
251 | {\r | |
252 | return (BOOLEAN) ((Value & Bit) != 0);\r | |
253 | }\r | |
254 | \r | |
255 | /**\r | |
256 | Initialize the KeyData and Key[] in the EFI_BOOT_MANAGER_KEY_OPTION.\r | |
257 | \r | |
258 | @param Modifier Input key info.\r | |
259 | @param Args Va_list info.\r | |
260 | @param KeyOption Key info which need to update.\r | |
261 | \r | |
262 | @retval EFI_SUCCESS Succeed to initialize the KeyData and Key[].\r | |
263 | @return EFI_INVALID_PARAMETER Input parameter error.\r | |
264 | **/\r | |
265 | EFI_STATUS\r | |
266 | BmInitializeKeyFields (\r | |
267 | IN UINT32 Modifier,\r | |
268 | IN VA_LIST Args,\r | |
269 | OUT EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r | |
270 | )\r | |
271 | {\r | |
272 | EFI_INPUT_KEY *Key;\r | |
273 | \r | |
274 | if (KeyOption == NULL) {\r | |
275 | return EFI_INVALID_PARAMETER;\r | |
276 | }\r | |
277 | \r | |
278 | Key = NULL;\r | |
279 | while (KeyOption->KeyData.Options.InputKeyCount < sizeof (KeyOption->Keys) / sizeof (KeyOption->Keys[0])) {\r | |
280 | Key = VA_ARG (Args, EFI_INPUT_KEY *);\r | |
281 | if (Key == NULL) {\r | |
282 | break;\r | |
283 | }\r | |
284 | CopyMem (\r | |
285 | &KeyOption->Keys[KeyOption->KeyData.Options.InputKeyCount],\r | |
286 | Key,\r | |
287 | sizeof (EFI_INPUT_KEY)\r | |
288 | );\r | |
289 | KeyOption->KeyData.Options.InputKeyCount++;\r | |
290 | }\r | |
291 | \r | |
292 | if (Key != NULL) {\r | |
293 | //\r | |
294 | // Too many keys\r | |
295 | //\r | |
296 | return EFI_INVALID_PARAMETER;\r | |
297 | }\r | |
298 | \r | |
299 | if ((Modifier & ~(EFI_BOOT_MANAGER_SHIFT_PRESSED\r | |
300 | | EFI_BOOT_MANAGER_CONTROL_PRESSED\r | |
301 | | EFI_BOOT_MANAGER_ALT_PRESSED\r | |
302 | | EFI_BOOT_MANAGER_LOGO_PRESSED\r | |
303 | | EFI_BOOT_MANAGER_MENU_KEY_PRESSED\r | |
304 | | EFI_BOOT_MANAGER_SYS_REQ_PRESSED\r | |
305 | )) != 0) {\r | |
306 | return EFI_INVALID_PARAMETER;\r | |
307 | }\r | |
308 | \r | |
309 | if (BmBitSet (Modifier, EFI_BOOT_MANAGER_SHIFT_PRESSED)) {\r | |
310 | KeyOption->KeyData.Options.ShiftPressed = 1;\r | |
311 | }\r | |
312 | if (BmBitSet (Modifier, EFI_BOOT_MANAGER_CONTROL_PRESSED)) {\r | |
313 | KeyOption->KeyData.Options.ControlPressed = 1;\r | |
314 | }\r | |
315 | if (BmBitSet (Modifier, EFI_BOOT_MANAGER_ALT_PRESSED)) {\r | |
316 | KeyOption->KeyData.Options.AltPressed = 1;\r | |
317 | }\r | |
318 | if (BmBitSet (Modifier, EFI_BOOT_MANAGER_LOGO_PRESSED)) {\r | |
319 | KeyOption->KeyData.Options.LogoPressed = 1;\r | |
320 | }\r | |
321 | if (BmBitSet (Modifier, EFI_BOOT_MANAGER_MENU_KEY_PRESSED)) {\r | |
322 | KeyOption->KeyData.Options.MenuPressed = 1;\r | |
323 | }\r | |
324 | if (BmBitSet (Modifier, EFI_BOOT_MANAGER_SYS_REQ_PRESSED)) {\r | |
325 | KeyOption->KeyData.Options.SysReqPressed = 1;\r | |
326 | }\r | |
327 | \r | |
328 | return EFI_SUCCESS;\r | |
329 | }\r | |
330 | \r | |
331 | /**\r | |
332 | Try to boot the boot option triggered by hot key.\r | |
333 | **/\r | |
334 | VOID\r | |
335 | EFIAPI\r | |
336 | EfiBootManagerHotkeyBoot (\r | |
337 | VOID\r | |
338 | )\r | |
339 | {\r | |
340 | if (mBmHotkeyBootOption.OptionNumber != LoadOptionNumberUnassigned) {\r | |
341 | EfiBootManagerBoot (&mBmHotkeyBootOption);\r | |
342 | EfiBootManagerFreeLoadOption (&mBmHotkeyBootOption);\r | |
343 | mBmHotkeyBootOption.OptionNumber = LoadOptionNumberUnassigned;\r | |
344 | }\r | |
345 | }\r | |
346 | \r | |
347 | /**\r | |
348 | This is the common notification function for HotKeys, it will be registered\r | |
349 | with SimpleTextInEx protocol interface - RegisterKeyNotify() of ConIn handle.\r | |
350 | \r | |
351 | @param KeyData A pointer to a buffer that is filled in with the keystroke\r | |
352 | information for the key that was pressed.\r | |
353 | \r | |
354 | @retval EFI_SUCCESS KeyData is successfully processed.\r | |
355 | @return EFI_NOT_FOUND Fail to find boot option variable.\r | |
356 | **/\r | |
357 | EFI_STATUS\r | |
358 | EFIAPI\r | |
359 | BmHotkeyCallback (\r | |
360 | IN EFI_KEY_DATA *KeyData\r | |
361 | )\r | |
362 | {\r | |
363 | LIST_ENTRY *Link;\r | |
364 | BM_HOTKEY *Hotkey;\r | |
f9a24380 | 365 | CHAR16 OptionName[BM_OPTION_NAME_LEN];\r |
067ed98a RN |
366 | EFI_STATUS Status;\r |
367 | EFI_KEY_DATA *HotkeyData;\r | |
368 | \r | |
369 | if (mBmHotkeyBootOption.OptionNumber != LoadOptionNumberUnassigned) {\r | |
370 | //\r | |
371 | // Do not process sequential hotkey stroke until the current boot option returns\r | |
372 | //\r | |
373 | return EFI_SUCCESS;\r | |
374 | }\r | |
375 | \r | |
376 | DEBUG ((EFI_D_INFO, "[Bds]BmHotkeyCallback: %04x:%04x\n", KeyData->Key.ScanCode, KeyData->Key.UnicodeChar));\r | |
377 | \r | |
378 | EfiAcquireLock (&mBmHotkeyLock);\r | |
379 | for ( Link = GetFirstNode (&mBmHotkeyList)\r | |
380 | ; !IsNull (&mBmHotkeyList, Link)\r | |
381 | ; Link = GetNextNode (&mBmHotkeyList, Link)\r | |
382 | ) {\r | |
383 | Hotkey = BM_HOTKEY_FROM_LINK (Link);\r | |
384 | \r | |
385 | //\r | |
386 | // Is this Key Stroke we are waiting for?\r | |
387 | //\r | |
388 | ASSERT (Hotkey->WaitingKey < (sizeof (Hotkey->KeyData) / sizeof (Hotkey->KeyData[0])));\r | |
389 | HotkeyData = &Hotkey->KeyData[Hotkey->WaitingKey];\r | |
390 | if ((KeyData->Key.ScanCode == HotkeyData->Key.ScanCode) &&\r | |
391 | (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) &&\r | |
392 | (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ? \r | |
393 | (KeyData->KeyState.KeyShiftState == HotkeyData->KeyState.KeyShiftState) : TRUE\r | |
394 | )\r | |
395 | ) {\r | |
396 | \r | |
397 | //\r | |
398 | // Receive an expecting key stroke, transit to next waiting state\r | |
399 | //\r | |
400 | Hotkey->WaitingKey++;\r | |
401 | \r | |
402 | if (Hotkey->WaitingKey == Hotkey->CodeCount) {\r | |
403 | //\r | |
404 | // Reset to initial waiting state\r | |
405 | //\r | |
406 | Hotkey->WaitingKey = 0;\r | |
407 | //\r | |
408 | // Received the whole key stroke sequence\r | |
409 | //\r | |
410 | Status = gBS->SignalEvent (mBmHotkeyTriggered);\r | |
411 | ASSERT_EFI_ERROR (Status);\r | |
412 | \r | |
413 | if (!Hotkey->IsContinue) {\r | |
414 | //\r | |
415 | // Launch its BootOption\r | |
416 | //\r | |
121300c4 RN |
417 | UnicodeSPrint (\r |
418 | OptionName, sizeof (OptionName), L"%s%04x",\r | |
419 | mBmLoadOptionName[LoadOptionTypeBoot], Hotkey->BootOption\r | |
420 | );\r | |
067ed98a RN |
421 | Status = EfiBootManagerVariableToLoadOption (OptionName, &mBmHotkeyBootOption);\r |
422 | DEBUG ((EFI_D_INFO, "[Bds]Hotkey for %s pressed - %r\n", OptionName, Status));\r | |
423 | if (EFI_ERROR (Status)) {\r | |
424 | mBmHotkeyBootOption.OptionNumber = LoadOptionNumberUnassigned;\r | |
425 | }\r | |
426 | } else {\r | |
427 | DEBUG ((EFI_D_INFO, "[Bds]Continue key pressed!\n"));\r | |
428 | }\r | |
429 | }\r | |
430 | } else {\r | |
431 | //\r | |
432 | // Receive an unexpected key stroke, reset to initial waiting state\r | |
433 | //\r | |
434 | Hotkey->WaitingKey = 0;\r | |
435 | }\r | |
436 | \r | |
437 | }\r | |
438 | EfiReleaseLock (&mBmHotkeyLock);\r | |
439 | \r | |
440 | return EFI_SUCCESS;\r | |
441 | }\r | |
442 | \r | |
443 | /**\r | |
444 | Unregister hotkey notify list.\r | |
445 | \r | |
446 | @param Hotkey Hotkey list.\r | |
447 | \r | |
448 | @retval EFI_SUCCESS Unregister hotkey notify success.\r | |
449 | @retval Others Unregister hotkey notify failed.\r | |
450 | **/\r | |
451 | EFI_STATUS\r | |
452 | BmUnregisterHotkeyNotify (\r | |
453 | IN BM_HOTKEY *Hotkey\r | |
454 | )\r | |
455 | {\r | |
456 | EFI_STATUS Status;\r | |
457 | UINTN Index;\r | |
458 | UINTN KeyIndex;\r | |
459 | EFI_HANDLE *Handles;\r | |
460 | UINTN HandleCount;\r | |
461 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r | |
462 | VOID *NotifyHandle;\r | |
463 | \r | |
464 | gBS->LocateHandleBuffer (\r | |
465 | ByProtocol,\r | |
466 | &gEfiSimpleTextInputExProtocolGuid,\r | |
467 | NULL,\r | |
468 | &HandleCount,\r | |
469 | &Handles\r | |
470 | );\r | |
471 | for (Index = 0; Index < HandleCount; Index++) {\r | |
472 | Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r | |
473 | ASSERT_EFI_ERROR (Status);\r | |
474 | for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {\r | |
475 | Status = TxtInEx->RegisterKeyNotify (\r | |
476 | TxtInEx,\r | |
477 | &Hotkey->KeyData[KeyIndex],\r | |
478 | BmHotkeyCallback,\r | |
479 | &NotifyHandle\r | |
480 | );\r | |
481 | if (!EFI_ERROR (Status)) {\r | |
482 | Status = TxtInEx->UnregisterKeyNotify (TxtInEx, NotifyHandle);\r | |
483 | DEBUG ((EFI_D_INFO, "[Bds]UnregisterKeyNotify: %04x/%04x %r\n", Hotkey->KeyData[KeyIndex].Key.ScanCode, Hotkey->KeyData[KeyIndex].Key.UnicodeChar, Status));\r | |
484 | }\r | |
485 | }\r | |
486 | }\r | |
487 | \r | |
488 | return EFI_SUCCESS;\r | |
489 | }\r | |
490 | \r | |
491 | /**\r | |
492 | Register hotkey notify list.\r | |
493 | \r | |
494 | @param TxtInEx Pointer to EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL protocol.\r | |
495 | @param Hotkey Hotkey list.\r | |
496 | \r | |
497 | @retval EFI_SUCCESS Register hotkey notify success.\r | |
498 | @retval Others Register hotkey notify failed.\r | |
499 | **/\r | |
500 | EFI_STATUS\r | |
501 | BmRegisterHotkeyNotify (\r | |
502 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx,\r | |
503 | IN BM_HOTKEY *Hotkey\r | |
504 | )\r | |
505 | {\r | |
506 | EFI_STATUS Status;\r | |
507 | UINTN Index;\r | |
508 | VOID *NotifyHandle;\r | |
509 | \r | |
510 | for (Index = 0; Index < Hotkey->CodeCount; Index++) {\r | |
511 | Status = TxtInEx->RegisterKeyNotify (\r | |
512 | TxtInEx,\r | |
513 | &Hotkey->KeyData[Index],\r | |
514 | BmHotkeyCallback,\r | |
515 | &NotifyHandle\r | |
516 | );\r | |
517 | DEBUG ((\r | |
518 | EFI_D_INFO,\r | |
519 | "[Bds]RegisterKeyNotify: %04x/%04x %08x/%02x %r\n",\r | |
520 | Hotkey->KeyData[Index].Key.ScanCode,\r | |
521 | Hotkey->KeyData[Index].Key.UnicodeChar,\r | |
522 | Hotkey->KeyData[Index].KeyState.KeyShiftState,\r | |
523 | Hotkey->KeyData[Index].KeyState.KeyToggleState,\r | |
524 | Status\r | |
525 | ));\r | |
526 | if (EFI_ERROR (Status)) {\r | |
527 | //\r | |
528 | // some of the hotkey registry failed\r | |
529 | // do not unregister all in case we have both CTRL-ALT-P and CTRL-ALT-P-R\r | |
530 | //\r | |
531 | break;\r | |
532 | }\r | |
533 | }\r | |
534 | \r | |
535 | return EFI_SUCCESS;\r | |
536 | }\r | |
537 | \r | |
538 | /**\r | |
539 | Generate key shift state base on the input key option info.\r | |
540 | \r | |
541 | @param Depth Which key is checked.\r | |
542 | @param KeyOption Input key option info.\r | |
543 | @param KeyShiftState Input key shift state.\r | |
544 | @param KeyShiftStates Return possible key shift state array.\r | |
545 | @param KeyShiftStateCount Possible key shift state count.\r | |
546 | **/\r | |
547 | VOID\r | |
548 | BmGenerateKeyShiftState (\r | |
549 | IN UINTN Depth,\r | |
550 | IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,\r | |
551 | IN UINT32 KeyShiftState,\r | |
552 | IN UINT32 *KeyShiftStates,\r | |
553 | IN UINTN *KeyShiftStateCount\r | |
554 | )\r | |
555 | {\r | |
556 | switch (Depth) {\r | |
557 | case 0:\r | |
558 | if (KeyOption->KeyData.Options.ShiftPressed) {\r | |
559 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_SHIFT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
560 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_SHIFT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
561 | } else {\r | |
562 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r | |
563 | }\r | |
564 | break;\r | |
565 | \r | |
566 | case 1:\r | |
567 | if (KeyOption->KeyData.Options.ControlPressed) {\r | |
568 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_CONTROL_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
569 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_CONTROL_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
570 | } else {\r | |
571 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r | |
572 | }\r | |
573 | break;\r | |
574 | \r | |
575 | case 2:\r | |
576 | if (KeyOption->KeyData.Options.AltPressed) {\r | |
577 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_ALT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
578 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_ALT_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
579 | } else {\r | |
580 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r | |
581 | }\r | |
582 | break;\r | |
583 | case 3:\r | |
584 | if (KeyOption->KeyData.Options.LogoPressed) {\r | |
585 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_RIGHT_LOGO_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
586 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState | EFI_LEFT_LOGO_PRESSED, KeyShiftStates, KeyShiftStateCount);\r | |
587 | } else {\r | |
588 | BmGenerateKeyShiftState (Depth + 1, KeyOption, KeyShiftState, KeyShiftStates, KeyShiftStateCount);\r | |
589 | }\r | |
590 | break;\r | |
591 | case 4:\r | |
592 | if (KeyOption->KeyData.Options.MenuPressed) {\r | |
593 | KeyShiftState |= EFI_MENU_KEY_PRESSED;\r | |
594 | }\r | |
595 | if (KeyOption->KeyData.Options.SysReqPressed) {\r | |
596 | KeyShiftState |= EFI_SYS_REQ_PRESSED;\r | |
597 | }\r | |
598 | KeyShiftStates[*KeyShiftStateCount] = KeyShiftState;\r | |
599 | (*KeyShiftStateCount)++;\r | |
600 | break;\r | |
601 | }\r | |
602 | }\r | |
603 | \r | |
604 | /**\r | |
605 | Add it to hot key database, register it to existing TxtInEx.\r | |
606 | New TxtInEx will be automatically registered with all the hot key in dababase\r | |
607 | \r | |
608 | @param KeyOption Input key option info.\r | |
609 | **/\r | |
610 | EFI_STATUS\r | |
611 | BmProcessKeyOption (\r | |
612 | IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOption\r | |
613 | )\r | |
614 | {\r | |
615 | EFI_STATUS Status;\r | |
616 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r | |
617 | EFI_HANDLE *Handles;\r | |
618 | UINTN HandleCount;\r | |
619 | UINTN HandleIndex;\r | |
620 | UINTN Index;\r | |
621 | BM_HOTKEY *Hotkey;\r | |
622 | UINTN KeyIndex;\r | |
623 | //\r | |
624 | // 16 is enough to enumerate all the possible combination of LEFT_XXX and RIGHT_XXX\r | |
625 | //\r | |
626 | UINT32 KeyShiftStates[16];\r | |
627 | UINTN KeyShiftStateCount;\r | |
628 | \r | |
629 | if (KeyOption->KeyData.Options.InputKeyCount > mBmHotkeySupportCount) {\r | |
630 | return EFI_UNSUPPORTED;\r | |
631 | }\r | |
632 | \r | |
633 | KeyShiftStateCount = 0;\r | |
634 | BmGenerateKeyShiftState (0, KeyOption, EFI_SHIFT_STATE_VALID, KeyShiftStates, &KeyShiftStateCount);\r | |
635 | ASSERT (KeyShiftStateCount <= sizeof (KeyShiftStates) / sizeof (KeyShiftStates[0]));\r | |
636 | \r | |
637 | EfiAcquireLock (&mBmHotkeyLock);\r | |
638 | \r | |
639 | for (Index = 0; Index < KeyShiftStateCount; Index++) {\r | |
640 | Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));\r | |
641 | ASSERT (Hotkey != NULL);\r | |
642 | \r | |
643 | Hotkey->Signature = BM_HOTKEY_SIGNATURE;\r | |
644 | Hotkey->BootOption = KeyOption->BootOption;\r | |
645 | Hotkey->IsContinue = (BOOLEAN) (KeyOption == mBmContinueKeyOption);\r | |
646 | Hotkey->CodeCount = (UINT8) KeyOption->KeyData.Options.InputKeyCount;\r | |
647 | \r | |
648 | for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {\r | |
649 | CopyMem (&Hotkey->KeyData[KeyIndex].Key, &KeyOption->Keys[KeyIndex], sizeof (EFI_INPUT_KEY));\r | |
650 | Hotkey->KeyData[KeyIndex].KeyState.KeyShiftState = KeyShiftStates[Index];\r | |
651 | }\r | |
652 | InsertTailList (&mBmHotkeyList, &Hotkey->Link);\r | |
653 | \r | |
654 | gBS->LocateHandleBuffer (\r | |
655 | ByProtocol,\r | |
656 | &gEfiSimpleTextInputExProtocolGuid,\r | |
657 | NULL,\r | |
658 | &HandleCount,\r | |
659 | &Handles\r | |
660 | );\r | |
661 | for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r | |
662 | Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r | |
663 | ASSERT_EFI_ERROR (Status);\r | |
664 | BmRegisterHotkeyNotify (TxtInEx, Hotkey);\r | |
665 | }\r | |
666 | }\r | |
667 | \r | |
668 | EfiReleaseLock (&mBmHotkeyLock);\r | |
669 | \r | |
670 | return EFI_SUCCESS;\r | |
671 | }\r | |
672 | \r | |
673 | /**\r | |
674 | Callback function for SimpleTextInEx protocol install events\r | |
675 | \r | |
676 | @param Event the event that is signaled.\r | |
677 | @param Context not used here.\r | |
678 | \r | |
679 | **/\r | |
680 | VOID\r | |
681 | EFIAPI\r | |
682 | BmTxtInExCallback (\r | |
683 | IN EFI_EVENT Event,\r | |
684 | IN VOID *Context\r | |
685 | )\r | |
686 | {\r | |
687 | EFI_STATUS Status;\r | |
688 | UINTN BufferSize;\r | |
689 | EFI_HANDLE Handle;\r | |
690 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r | |
691 | LIST_ENTRY *Link;\r | |
692 | \r | |
693 | while (TRUE) {\r | |
694 | BufferSize = sizeof (EFI_HANDLE);\r | |
695 | Status = gBS->LocateHandle (\r | |
696 | ByRegisterNotify,\r | |
697 | NULL,\r | |
698 | mBmTxtInExRegistration,\r | |
699 | &BufferSize,\r | |
700 | &Handle\r | |
701 | );\r | |
702 | if (EFI_ERROR (Status)) {\r | |
703 | //\r | |
704 | // If no more notification events exist\r | |
705 | //\r | |
706 | return ;\r | |
707 | }\r | |
708 | \r | |
709 | Status = gBS->HandleProtocol (\r | |
710 | Handle,\r | |
711 | &gEfiSimpleTextInputExProtocolGuid,\r | |
712 | (VOID **) &TxtInEx\r | |
713 | );\r | |
714 | ASSERT_EFI_ERROR (Status);\r | |
715 | \r | |
716 | //\r | |
717 | // Register the hot key notification for the existing items in the list\r | |
718 | //\r | |
719 | EfiAcquireLock (&mBmHotkeyLock);\r | |
720 | for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); Link = GetNextNode (&mBmHotkeyList, Link)) {\r | |
721 | BmRegisterHotkeyNotify (TxtInEx, BM_HOTKEY_FROM_LINK (Link));\r | |
722 | }\r | |
723 | EfiReleaseLock (&mBmHotkeyLock);\r | |
724 | }\r | |
725 | }\r | |
726 | \r | |
727 | /**\r | |
728 | Free the key options returned from BmGetKeyOptions.\r | |
729 | \r | |
730 | @param KeyOptions Pointer to the key options.\r | |
731 | @param KeyOptionCount Number of the key options.\r | |
732 | \r | |
733 | @retval EFI_SUCCESS The key options are freed.\r | |
734 | @retval EFI_NOT_FOUND KeyOptions is NULL.\r | |
735 | **/\r | |
736 | EFI_STATUS\r | |
737 | BmFreeKeyOptions (\r | |
738 | IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions,\r | |
739 | IN UINTN KeyOptionCount\r | |
740 | )\r | |
741 | {\r | |
742 | if (KeyOptions != NULL) {\r | |
743 | FreePool (KeyOptions);\r | |
744 | return EFI_SUCCESS;\r | |
745 | } else {\r | |
746 | return EFI_NOT_FOUND;\r | |
747 | }\r | |
748 | }\r | |
749 | \r | |
750 | /**\r | |
751 | Register the key option to exit the waiting of the Boot Manager timeout.\r | |
752 | Platform should ensure that the continue key option isn't conflict with\r | |
753 | other boot key options.\r | |
754 | \r | |
755 | @param Modifier Key shift state.\r | |
756 | @param ... Parameter list of pointer of EFI_INPUT_KEY.\r | |
757 | \r | |
758 | @retval EFI_SUCCESS Successfully register the continue key option.\r | |
759 | @retval EFI_ALREADY_STARTED The continue key option is already registered.\r | |
760 | **/\r | |
761 | EFI_STATUS\r | |
762 | EFIAPI\r | |
763 | EfiBootManagerRegisterContinueKeyOption (\r | |
764 | IN UINT32 Modifier,\r | |
765 | ...\r | |
766 | )\r | |
767 | {\r | |
768 | EFI_STATUS Status;\r | |
769 | EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r | |
770 | VA_LIST Args;\r | |
771 | \r | |
772 | if (mBmContinueKeyOption != NULL) {\r | |
773 | return EFI_ALREADY_STARTED;\r | |
774 | }\r | |
775 | \r | |
776 | ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r | |
777 | VA_START (Args, Modifier);\r | |
778 | Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r | |
779 | VA_END (Args);\r | |
780 | \r | |
781 | if (!EFI_ERROR (Status)) {\r | |
782 | mBmContinueKeyOption = AllocateCopyPool (sizeof (EFI_BOOT_MANAGER_KEY_OPTION), &KeyOption);\r | |
783 | ASSERT (mBmContinueKeyOption != NULL);\r | |
784 | if (mBmHotkeyServiceStarted) {\r | |
785 | BmProcessKeyOption (mBmContinueKeyOption);\r | |
786 | }\r | |
787 | }\r | |
788 | \r | |
789 | return Status;\r | |
790 | }\r | |
791 | \r | |
792 | /**\r | |
793 | Stop the hotkey processing.\r | |
794 | \r | |
795 | @param Event Event pointer related to hotkey service.\r | |
796 | @param Context Context pass to this function.\r | |
797 | **/\r | |
798 | VOID\r | |
799 | EFIAPI\r | |
800 | BmStopHotkeyService (\r | |
801 | IN EFI_EVENT Event,\r | |
802 | IN VOID *Context\r | |
803 | )\r | |
804 | {\r | |
805 | LIST_ENTRY *Link;\r | |
806 | BM_HOTKEY *Hotkey;\r | |
807 | \r | |
808 | DEBUG ((EFI_D_INFO, "[Bds]Stop Hotkey Service!\n"));\r | |
809 | gBS->CloseEvent (Event);\r | |
810 | \r | |
811 | EfiAcquireLock (&mBmHotkeyLock);\r | |
812 | for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); ) {\r | |
813 | Hotkey = BM_HOTKEY_FROM_LINK (Link);\r | |
814 | BmUnregisterHotkeyNotify (Hotkey);\r | |
815 | Link = RemoveEntryList (Link);\r | |
816 | FreePool (Hotkey);\r | |
817 | }\r | |
818 | EfiReleaseLock (&mBmHotkeyLock);\r | |
819 | }\r | |
820 | \r | |
821 | /**\r | |
822 | Start the hot key service so that the key press can trigger the boot option.\r | |
823 | \r | |
824 | @param HotkeyTriggered Return the waitable event and it will be signaled \r | |
825 | when a valid hot key is pressed.\r | |
826 | \r | |
827 | @retval EFI_SUCCESS The hot key service is started.\r | |
828 | **/\r | |
829 | EFI_STATUS\r | |
830 | EFIAPI\r | |
831 | EfiBootManagerStartHotkeyService (\r | |
832 | IN EFI_EVENT *HotkeyTriggered\r | |
833 | )\r | |
834 | {\r | |
835 | EFI_STATUS Status;\r | |
836 | EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r | |
837 | UINTN KeyOptionCount;\r | |
838 | UINTN Index;\r | |
839 | EFI_EVENT Event;\r | |
840 | UINT32 *BootOptionSupport;\r | |
841 | \r | |
842 | Status = GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL);\r | |
843 | ASSERT (BootOptionSupport != NULL);\r | |
844 | \r | |
845 | if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY) != 0) {\r | |
846 | mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT));\r | |
847 | }\r | |
848 | FreePool (BootOptionSupport);\r | |
849 | \r | |
850 | if (mBmHotkeySupportCount == 0) {\r | |
851 | DEBUG ((EFI_D_INFO, "Bds: BootOptionSupport NV variable forbids starting the hotkey service.\n"));\r | |
852 | return EFI_UNSUPPORTED;\r | |
853 | }\r | |
854 | \r | |
855 | Status = gBS->CreateEvent (\r | |
856 | EVT_NOTIFY_WAIT,\r | |
857 | TPL_CALLBACK,\r | |
858 | BmEmptyFunction,\r | |
859 | NULL,\r | |
860 | &mBmHotkeyTriggered\r | |
861 | );\r | |
862 | ASSERT_EFI_ERROR (Status);\r | |
863 | \r | |
864 | if (HotkeyTriggered != NULL) {\r | |
865 | *HotkeyTriggered = mBmHotkeyTriggered;\r | |
866 | }\r | |
867 | \r | |
868 | KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r | |
869 | for (Index = 0; Index < KeyOptionCount; Index ++) {\r | |
870 | BmProcessKeyOption (&KeyOptions[Index]);\r | |
871 | }\r | |
872 | BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r | |
873 | \r | |
874 | if (mBmContinueKeyOption != NULL) {\r | |
875 | BmProcessKeyOption (mBmContinueKeyOption);\r | |
876 | }\r | |
877 | \r | |
878 | EfiCreateProtocolNotifyEvent (\r | |
879 | &gEfiSimpleTextInputExProtocolGuid,\r | |
880 | TPL_CALLBACK,\r | |
881 | BmTxtInExCallback,\r | |
882 | NULL,\r | |
883 | &mBmTxtInExRegistration\r | |
884 | );\r | |
885 | \r | |
886 | Status = EfiCreateEventReadyToBootEx (\r | |
887 | TPL_CALLBACK,\r | |
888 | BmStopHotkeyService,\r | |
889 | NULL,\r | |
890 | &Event\r | |
891 | );\r | |
892 | ASSERT_EFI_ERROR (Status);\r | |
893 | \r | |
894 | \r | |
895 | mBmHotkeyServiceStarted = TRUE;\r | |
896 | return Status;\r | |
897 | }\r | |
898 | \r | |
899 | /**\r | |
900 | Add the key option.\r | |
901 | It adds the key option variable and the key option takes affect immediately.\r | |
902 | \r | |
903 | @param AddedOption Return the added key option.\r | |
904 | @param BootOptionNumber The boot option number for the key option.\r | |
905 | @param Modifier Key shift state.\r | |
906 | @param ... Parameter list of pointer of EFI_INPUT_KEY.\r | |
907 | \r | |
908 | @retval EFI_SUCCESS The key option is added.\r | |
909 | @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.\r | |
910 | **/\r | |
911 | EFI_STATUS\r | |
912 | EFIAPI\r | |
913 | EfiBootManagerAddKeyOptionVariable (\r | |
914 | OUT EFI_BOOT_MANAGER_KEY_OPTION *AddedOption, OPTIONAL\r | |
915 | IN UINT16 BootOptionNumber,\r | |
916 | IN UINT32 Modifier,\r | |
917 | ...\r | |
918 | )\r | |
919 | {\r | |
920 | EFI_STATUS Status;\r | |
921 | VA_LIST Args;\r | |
922 | VOID *BootOption;\r | |
923 | UINTN BootOptionSize;\r | |
f9a24380 | 924 | CHAR16 BootOptionName[BM_OPTION_NAME_LEN];\r |
067ed98a RN |
925 | EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r |
926 | EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r | |
927 | UINTN KeyOptionCount;\r | |
928 | UINTN Index;\r | |
929 | UINTN KeyOptionNumber;\r | |
f9a24380 | 930 | CHAR16 KeyOptionName[sizeof ("Key####")];\r |
067ed98a | 931 | \r |
121300c4 RN |
932 | UnicodeSPrint (\r |
933 | BootOptionName, sizeof (BootOptionName), L"%s%04x",\r | |
934 | mBmLoadOptionName[LoadOptionTypeBoot], BootOptionNumber\r | |
935 | );\r | |
067ed98a RN |
936 | GetEfiGlobalVariable2 (BootOptionName, &BootOption, &BootOptionSize);\r |
937 | \r | |
938 | if (BootOption == NULL) {\r | |
939 | return EFI_NOT_FOUND;\r | |
940 | }\r | |
941 | \r | |
942 | ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r | |
943 | KeyOption.BootOption = BootOptionNumber;\r | |
944 | Status = gBS->CalculateCrc32 (BootOption, BootOptionSize, &KeyOption.BootOptionCrc);\r | |
945 | ASSERT_EFI_ERROR (Status);\r | |
946 | FreePool (BootOption);\r | |
947 | \r | |
948 | VA_START (Args, Modifier);\r | |
949 | Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r | |
950 | VA_END (Args);\r | |
951 | if (EFI_ERROR (Status)) {\r | |
952 | return Status;\r | |
953 | }\r | |
954 | \r | |
955 | KeyOptionNumber = LoadOptionNumberUnassigned;\r | |
956 | //\r | |
957 | // Check if the hot key sequence was defined already\r | |
958 | //\r | |
959 | KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r | |
960 | for (Index = 0; Index < KeyOptionCount; Index++) {\r | |
961 | if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) &&\r | |
962 | (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) {\r | |
963 | break;\r | |
964 | }\r | |
965 | \r | |
966 | if ((KeyOptionNumber == LoadOptionNumberUnassigned) &&\r | |
967 | (KeyOptions[Index].OptionNumber > Index)\r | |
968 | ){\r | |
969 | KeyOptionNumber = Index;\r | |
970 | }\r | |
971 | }\r | |
972 | BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r | |
973 | \r | |
974 | if (Index < KeyOptionCount) {\r | |
975 | return EFI_ALREADY_STARTED;\r | |
976 | }\r | |
977 | \r | |
978 | if (KeyOptionNumber == LoadOptionNumberUnassigned) {\r | |
979 | KeyOptionNumber = KeyOptionCount;\r | |
980 | }\r | |
981 | \r | |
982 | UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptionNumber);\r | |
983 | \r | |
984 | Status = gRT->SetVariable (\r | |
985 | KeyOptionName,\r | |
986 | &gEfiGlobalVariableGuid,\r | |
987 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r | |
988 | BmSizeOfKeyOption (&KeyOption),\r | |
989 | &KeyOption\r | |
990 | );\r | |
991 | if (!EFI_ERROR (Status)) {\r | |
992 | //\r | |
993 | // Return the Key Option in case needed by caller\r | |
994 | //\r | |
995 | if (AddedOption != NULL) {\r | |
996 | CopyMem (AddedOption, &KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r | |
997 | }\r | |
998 | \r | |
999 | //\r | |
1000 | // Register the newly added hot key\r | |
1001 | // Calling this function before EfiBootManagerStartHotkeyService doesn't\r | |
1002 | // need to call BmProcessKeyOption\r | |
1003 | //\r | |
1004 | if (mBmHotkeyServiceStarted) {\r | |
1005 | BmProcessKeyOption (&KeyOption);\r | |
1006 | }\r | |
1007 | }\r | |
1008 | \r | |
1009 | return Status;\r | |
1010 | }\r | |
1011 | \r | |
1012 | /**\r | |
1013 | Delete the Key Option variable and unregister the hot key\r | |
1014 | \r | |
1015 | @param DeletedOption Return the deleted key options.\r | |
1016 | @param Modifier Key shift state.\r | |
1017 | @param ... Parameter list of pointer of EFI_INPUT_KEY.\r | |
1018 | \r | |
1019 | @retval EFI_SUCCESS The key option is deleted.\r | |
1020 | @retval EFI_NOT_FOUND The key option cannot be found.\r | |
1021 | **/\r | |
1022 | EFI_STATUS\r | |
1023 | EFIAPI\r | |
1024 | EfiBootManagerDeleteKeyOptionVariable (\r | |
1025 | IN EFI_BOOT_MANAGER_KEY_OPTION *DeletedOption, OPTIONAL\r | |
1026 | IN UINT32 Modifier,\r | |
1027 | ...\r | |
1028 | )\r | |
1029 | {\r | |
1030 | EFI_STATUS Status;\r | |
1031 | UINTN Index;\r | |
1032 | VA_LIST Args;\r | |
1033 | EFI_BOOT_MANAGER_KEY_OPTION KeyOption;\r | |
1034 | EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions;\r | |
1035 | UINTN KeyOptionCount;\r | |
1036 | LIST_ENTRY *Link;\r | |
1037 | BM_HOTKEY *Hotkey;\r | |
1038 | UINT32 ShiftState;\r | |
1039 | BOOLEAN Match;\r | |
f9a24380 | 1040 | CHAR16 KeyOptionName[sizeof ("Key####")];\r |
067ed98a RN |
1041 | \r |
1042 | ZeroMem (&KeyOption, sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r | |
1043 | VA_START (Args, Modifier);\r | |
1044 | Status = BmInitializeKeyFields (Modifier, Args, &KeyOption);\r | |
1045 | VA_END (Args);\r | |
1046 | \r | |
1047 | if (EFI_ERROR (Status)) {\r | |
1048 | return Status;\r | |
1049 | }\r | |
1050 | \r | |
1051 | EfiAcquireLock (&mBmHotkeyLock);\r | |
1052 | //\r | |
1053 | // Delete the key option from active hot key list\r | |
1054 | // Could have multiple entries when modifier isn't 0 because we map the ShiftPressed to RIGHT_SHIFT and RIGHT_SHIFT\r | |
1055 | //\r | |
1056 | for (Link = GetFirstNode (&mBmHotkeyList); !IsNull (&mBmHotkeyList, Link); ) {\r | |
1057 | Hotkey = BM_HOTKEY_FROM_LINK (Link);\r | |
1058 | Match = (BOOLEAN) (Hotkey->CodeCount == KeyOption.KeyData.Options.InputKeyCount);\r | |
1059 | \r | |
1060 | for (Index = 0; Match && (Index < Hotkey->CodeCount); Index++) {\r | |
1061 | ShiftState = Hotkey->KeyData[Index].KeyState.KeyShiftState;\r | |
1062 | if (\r | |
1063 | (BmBitSet (ShiftState, EFI_RIGHT_SHIFT_PRESSED | EFI_LEFT_SHIFT_PRESSED) != KeyOption.KeyData.Options.ShiftPressed) ||\r | |
1064 | (BmBitSet (ShiftState, EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED) != KeyOption.KeyData.Options.ControlPressed) ||\r | |
1065 | (BmBitSet (ShiftState, EFI_RIGHT_ALT_PRESSED | EFI_LEFT_ALT_PRESSED) != KeyOption.KeyData.Options.AltPressed) ||\r | |
1066 | (BmBitSet (ShiftState, EFI_RIGHT_LOGO_PRESSED | EFI_LEFT_LOGO_PRESSED) != KeyOption.KeyData.Options.LogoPressed) ||\r | |
1067 | (BmBitSet (ShiftState, EFI_MENU_KEY_PRESSED) != KeyOption.KeyData.Options.MenuPressed) ||\r | |
1068 | (BmBitSet (ShiftState, EFI_SYS_REQ_PRESSED) != KeyOption.KeyData.Options.SysReqPressed) ||\r | |
1069 | (CompareMem (&Hotkey->KeyData[Index].Key, &KeyOption.Keys[Index], sizeof (EFI_INPUT_KEY)) != 0)\r | |
1070 | ) {\r | |
1071 | //\r | |
1072 | // Break when any field doesn't match\r | |
1073 | //\r | |
1074 | Match = FALSE;\r | |
1075 | break;\r | |
1076 | }\r | |
1077 | }\r | |
1078 | \r | |
1079 | if (Match) {\r | |
1080 | Link = RemoveEntryList (Link);\r | |
1081 | FreePool (Hotkey);\r | |
1082 | } else {\r | |
1083 | Link = GetNextNode (&mBmHotkeyList, Link);\r | |
1084 | }\r | |
1085 | }\r | |
1086 | \r | |
1087 | //\r | |
1088 | // Delete the key option from the variable\r | |
1089 | //\r | |
1090 | Status = EFI_NOT_FOUND;\r | |
1091 | KeyOptions = BmGetKeyOptions (&KeyOptionCount);\r | |
1092 | for (Index = 0; Index < KeyOptionCount; Index++) {\r | |
1093 | if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) &&\r | |
1094 | (CompareMem (\r | |
1095 | KeyOptions[Index].Keys, KeyOption.Keys,\r | |
1096 | KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)\r | |
1097 | ) {\r | |
1098 | UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptions[Index].OptionNumber);\r | |
1099 | Status = gRT->SetVariable (\r | |
1100 | KeyOptionName,\r | |
1101 | &gEfiGlobalVariableGuid,\r | |
1102 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r | |
1103 | 0,\r | |
1104 | NULL\r | |
1105 | );\r | |
1106 | //\r | |
1107 | // Return the deleted key option in case needed by caller\r | |
1108 | //\r | |
1109 | if (DeletedOption != NULL) {\r | |
1110 | CopyMem (DeletedOption, &KeyOptions[Index], sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r | |
1111 | }\r | |
1112 | break;\r | |
1113 | }\r | |
1114 | }\r | |
1115 | BmFreeKeyOptions (KeyOptions, KeyOptionCount);\r | |
1116 | \r | |
1117 | EfiReleaseLock (&mBmHotkeyLock);\r | |
1118 | \r | |
1119 | return Status;\r | |
1120 | }\r |