]>
Commit | Line | Data |
---|---|---|
c9802c45 ED |
1 | /** @file\r |
2 | \r | |
3 | This library class defines a set of interfaces to customize Ui module\r | |
4 | \r | |
5 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
c9802c45 ED |
7 | \r |
8 | **/\r | |
9 | #include <Uefi.h>\r | |
10 | \r | |
11 | #include <Guid/MdeModuleHii.h>\r | |
12 | #include <Guid/GlobalVariable.h>\r | |
13 | \r | |
14 | #include <Protocol/HiiConfigAccess.h>\r | |
15 | #include <Protocol/HiiString.h>\r | |
16 | \r | |
17 | #include <Library/HiiLib.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/UefiLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | #include <Library/MemoryAllocationLib.h>\r | |
23 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
24 | #include <Library/UefiHiiServicesLib.h>\r | |
25 | #include <Library/DevicePathLib.h>\r | |
26 | #include <Library/UefiBootServicesTableLib.h>\r | |
27 | #include "FrontPageCustomizedUiSupport.h"\r | |
28 | \r | |
29 | //\r | |
30 | // This is the VFR compiler generated header file which defines the\r | |
31 | // string identifiers.\r | |
32 | //\r | |
33 | #define PRINTABLE_LANGUAGE_NAME_STRING_ID 0x0001\r | |
34 | \r | |
35 | #define UI_HII_DRIVER_LIST_SIZE 0x8\r | |
36 | \r | |
37 | #define FRONT_PAGE_KEY_CONTINUE 0x1000\r | |
38 | #define FRONT_PAGE_KEY_RESET 0x1001\r | |
39 | #define FRONT_PAGE_KEY_LANGUAGE 0x1002\r | |
7d467158 | 40 | #define FRONT_PAGE_KEY_DRIVER 0x2000\r |
c9802c45 ED |
41 | \r |
42 | typedef struct {\r | |
43 | EFI_STRING_ID PromptId;\r | |
44 | EFI_STRING_ID HelpId;\r | |
45 | EFI_STRING_ID DevicePathId;\r | |
46 | EFI_GUID FormSetGuid;\r | |
47 | BOOLEAN EmptyLineAfter;\r | |
48 | } UI_HII_DRIVER_INSTANCE;\r | |
49 | \r | |
50 | CHAR8 *gLanguageString;\r | |
51 | EFI_STRING_ID *gLanguageToken;\r | |
52 | UI_HII_DRIVER_INSTANCE *gHiiDriverList;\r | |
7258076b | 53 | extern EFI_HII_HANDLE gStringPackHandle;\r |
e4260252 | 54 | UINT8 gCurrentLanguageIndex;\r |
c9802c45 ED |
55 | \r |
56 | \r | |
57 | /**\r | |
58 | Get next language from language code list (with separator ';').\r | |
59 | \r | |
60 | If LangCode is NULL, then ASSERT.\r | |
61 | If Lang is NULL, then ASSERT.\r | |
62 | \r | |
63 | @param LangCode On input: point to first language in the list. On\r | |
64 | output: point to next language in the list, or\r | |
65 | NULL if no more language in the list.\r | |
66 | @param Lang The first language in the list.\r | |
67 | \r | |
68 | **/\r | |
69 | VOID\r | |
70 | GetNextLanguage (\r | |
71 | IN OUT CHAR8 **LangCode,\r | |
72 | OUT CHAR8 *Lang\r | |
73 | )\r | |
74 | {\r | |
75 | UINTN Index;\r | |
76 | CHAR8 *StringPtr;\r | |
77 | \r | |
78 | ASSERT (LangCode != NULL);\r | |
79 | ASSERT (*LangCode != NULL);\r | |
80 | ASSERT (Lang != NULL);\r | |
81 | \r | |
82 | Index = 0;\r | |
83 | StringPtr = *LangCode;\r | |
84 | while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {\r | |
85 | Index++;\r | |
86 | }\r | |
87 | \r | |
88 | CopyMem (Lang, StringPtr, Index);\r | |
89 | Lang[Index] = 0;\r | |
90 | \r | |
91 | if (StringPtr[Index] == ';') {\r | |
92 | Index++;\r | |
93 | }\r | |
94 | *LangCode = StringPtr + Index;\r | |
95 | }\r | |
96 | \r | |
97 | /**\r | |
98 | This function processes the language changes in configuration.\r | |
99 | \r | |
100 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
101 | \r | |
102 | \r | |
103 | @retval TRUE The callback successfully handled the action.\r | |
104 | @retval FALSE The callback not supported in this handler.\r | |
105 | \r | |
106 | **/\r | |
107 | EFI_STATUS\r | |
108 | LanguageChangeHandler (\r | |
109 | IN EFI_IFR_TYPE_VALUE *Value\r | |
110 | )\r | |
111 | {\r | |
112 | CHAR8 *LangCode;\r | |
113 | CHAR8 *Lang;\r | |
114 | UINTN Index;\r | |
115 | EFI_STATUS Status;\r | |
116 | \r | |
117 | //\r | |
118 | // Allocate working buffer for RFC 4646 language in supported LanguageString.\r | |
119 | //\r | |
120 | Lang = AllocatePool (AsciiStrSize (gLanguageString));\r | |
121 | ASSERT (Lang != NULL);\r | |
122 | \r | |
123 | Index = 0;\r | |
124 | LangCode = gLanguageString;\r | |
125 | while (*LangCode != 0) {\r | |
126 | GetNextLanguage (&LangCode, Lang);\r | |
127 | \r | |
128 | if (Index == Value->u8) {\r | |
e4260252 | 129 | gCurrentLanguageIndex = Value->u8;\r |
c9802c45 ED |
130 | break;\r |
131 | }\r | |
132 | \r | |
133 | Index++;\r | |
134 | }\r | |
135 | \r | |
136 | if (Index == Value->u8) {\r | |
137 | Status = gRT->SetVariable (\r | |
138 | L"PlatformLang",\r | |
139 | &gEfiGlobalVariableGuid,\r | |
140 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
141 | AsciiStrSize (Lang),\r | |
142 | Lang\r | |
143 | );\r | |
144 | if (EFI_ERROR (Status)) {\r | |
145 | FreePool (Lang);\r | |
146 | return EFI_DEVICE_ERROR;\r | |
147 | }\r | |
148 | } else {\r | |
149 | ASSERT (FALSE);\r | |
150 | }\r | |
151 | FreePool (Lang);\r | |
152 | \r | |
153 | return EFI_SUCCESS;\r | |
154 | }\r | |
155 | \r | |
156 | /**\r | |
157 | This function processes the results of changes in configuration.\r | |
158 | \r | |
159 | \r | |
160 | @param HiiHandle Points to the hii handle for this formset.\r | |
161 | @param Action Specifies the type of action taken by the browser.\r | |
162 | @param QuestionId A unique value which is sent to the original exporting driver\r | |
163 | so that it can identify the type of data to expect.\r | |
164 | @param Type The type of value for the question.\r | |
165 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
166 | @param ActionRequest On return, points to the action requested by the callback function.\r | |
167 | @param Status Return the handle status.\r | |
168 | \r | |
169 | @retval TRUE The callback successfully handled the action.\r | |
170 | @retval FALSE The callback not supported in this handler.\r | |
171 | \r | |
172 | **/\r | |
173 | BOOLEAN\r | |
174 | UiSupportLibCallbackHandler (\r | |
175 | IN EFI_HII_HANDLE HiiHandle,\r | |
176 | IN EFI_BROWSER_ACTION Action,\r | |
177 | IN EFI_QUESTION_ID QuestionId,\r | |
178 | IN UINT8 Type,\r | |
179 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
180 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest,\r | |
181 | OUT EFI_STATUS *Status\r | |
182 | )\r | |
183 | {\r | |
184 | if (QuestionId != FRONT_PAGE_KEY_CONTINUE &&\r | |
185 | QuestionId != FRONT_PAGE_KEY_RESET &&\r | |
186 | QuestionId != FRONT_PAGE_KEY_LANGUAGE) {\r | |
187 | return FALSE;\r | |
188 | }\r | |
189 | \r | |
e4260252 DB |
190 | if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r |
191 | if (QuestionId == FRONT_PAGE_KEY_LANGUAGE) {\r | |
192 | Value->u8 = gCurrentLanguageIndex;\r | |
193 | *Status = EFI_SUCCESS;\r | |
194 | } else {\r | |
195 | *Status = EFI_UNSUPPORTED;\r | |
196 | }\r | |
197 | return TRUE;\r | |
198 | }\r | |
199 | \r | |
c9802c45 ED |
200 | if (Action != EFI_BROWSER_ACTION_CHANGED) {\r |
201 | //\r | |
202 | // Do nothing for other UEFI Action. Only do call back when data is changed.\r | |
203 | //\r | |
204 | *Status = EFI_UNSUPPORTED;\r | |
81c14606 | 205 | return TRUE;\r |
c9802c45 ED |
206 | }\r |
207 | \r | |
208 | if (Action == EFI_BROWSER_ACTION_CHANGED) {\r | |
209 | if ((Value == NULL) || (ActionRequest == NULL)) {\r | |
210 | *Status = EFI_INVALID_PARAMETER;\r | |
81c14606 | 211 | return TRUE;\r |
c9802c45 ED |
212 | }\r |
213 | \r | |
214 | *Status = EFI_SUCCESS;\r | |
215 | switch (QuestionId) {\r | |
216 | case FRONT_PAGE_KEY_CONTINUE:\r | |
217 | //\r | |
218 | // This is the continue - clear the screen and return an error to get out of FrontPage loop\r | |
219 | //\r | |
220 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r | |
221 | break;\r | |
222 | \r | |
223 | case FRONT_PAGE_KEY_LANGUAGE:\r | |
224 | *Status = LanguageChangeHandler(Value);\r | |
225 | break;\r | |
226 | \r | |
227 | case FRONT_PAGE_KEY_RESET:\r | |
228 | //\r | |
229 | // Reset\r | |
230 | //\r | |
231 | gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r | |
232 | *Status = EFI_UNSUPPORTED;\r | |
233 | \r | |
234 | default:\r | |
235 | break;\r | |
236 | }\r | |
237 | }\r | |
238 | \r | |
239 | return TRUE;\r | |
240 | }\r | |
241 | \r | |
242 | /**\r | |
243 | Create Select language menu in the front page with oneof opcode.\r | |
244 | \r | |
245 | @param[in] HiiHandle The hii handle for the Uiapp driver.\r | |
c9802c45 ED |
246 | @param[in] StartOpCodeHandle The opcode handle to save the new opcode.\r |
247 | \r | |
c9802c45 ED |
248 | **/\r |
249 | VOID\r | |
250 | UiCreateLanguageMenu (\r | |
251 | IN EFI_HII_HANDLE HiiHandle,\r | |
252 | IN VOID *StartOpCodeHandle\r | |
253 | )\r | |
254 | {\r | |
255 | CHAR8 *LangCode;\r | |
256 | CHAR8 *Lang;\r | |
b68ccac1 | 257 | UINTN LangSize;\r |
c9802c45 ED |
258 | CHAR8 *CurrentLang;\r |
259 | UINTN OptionCount;\r | |
260 | CHAR16 *StringBuffer;\r | |
261 | VOID *OptionsOpCodeHandle;\r | |
262 | UINTN StringSize;\r | |
263 | EFI_STATUS Status;\r | |
264 | EFI_HII_STRING_PROTOCOL *HiiString;\r | |
265 | \r | |
266 | Lang = NULL;\r | |
267 | StringBuffer = NULL;\r | |
268 | \r | |
269 | //\r | |
270 | // Init OpCode Handle and Allocate space for creation of UpdateData Buffer\r | |
271 | //\r | |
272 | OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
273 | ASSERT (OptionsOpCodeHandle != NULL);\r | |
274 | \r | |
275 | GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLang, NULL);\r | |
276 | \r | |
277 | //\r | |
278 | // Get Support language list from variable.\r | |
279 | //\r | |
280 | GetEfiGlobalVariable2 (L"PlatformLangCodes", (VOID**)&gLanguageString, NULL);\r | |
281 | if (gLanguageString == NULL) {\r | |
282 | gLanguageString = AllocateCopyPool (\r | |
283 | AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)),\r | |
284 | (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)\r | |
285 | );\r | |
286 | ASSERT (gLanguageString != NULL);\r | |
287 | }\r | |
288 | \r | |
289 | if (gLanguageToken == NULL) {\r | |
290 | //\r | |
291 | // Count the language list number.\r | |
292 | //\r | |
293 | LangCode = gLanguageString;\r | |
294 | Lang = AllocatePool (AsciiStrSize (gLanguageString));\r | |
295 | ASSERT (Lang != NULL);\r | |
296 | \r | |
297 | OptionCount = 0;\r | |
298 | while (*LangCode != 0) {\r | |
299 | GetNextLanguage (&LangCode, Lang);\r | |
300 | OptionCount ++;\r | |
301 | }\r | |
302 | \r | |
303 | //\r | |
304 | // Allocate extra 1 as the end tag.\r | |
305 | //\r | |
306 | gLanguageToken = AllocateZeroPool ((OptionCount + 1) * sizeof (EFI_STRING_ID));\r | |
307 | ASSERT (gLanguageToken != NULL);\r | |
308 | \r | |
309 | Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);\r | |
310 | ASSERT_EFI_ERROR (Status);\r | |
311 | \r | |
312 | LangCode = gLanguageString;\r | |
313 | OptionCount = 0;\r | |
314 | while (*LangCode != 0) {\r | |
315 | GetNextLanguage (&LangCode, Lang);\r | |
316 | \r | |
317 | StringSize = 0;\r | |
318 | Status = HiiString->GetString (HiiString, Lang, HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, StringBuffer, &StringSize, NULL);\r | |
319 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
320 | StringBuffer = AllocateZeroPool (StringSize);\r | |
321 | ASSERT (StringBuffer != NULL);\r | |
322 | Status = HiiString->GetString (HiiString, Lang, HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, StringBuffer, &StringSize, NULL);\r | |
323 | ASSERT_EFI_ERROR (Status);\r | |
324 | }\r | |
325 | \r | |
326 | if (EFI_ERROR (Status)) {\r | |
b68ccac1 SZ |
327 | LangSize = AsciiStrSize (Lang);\r |
328 | StringBuffer = AllocatePool (LangSize * sizeof (CHAR16));\r | |
c9802c45 | 329 | ASSERT (StringBuffer != NULL);\r |
b68ccac1 | 330 | AsciiStrToUnicodeStrS (Lang, StringBuffer, LangSize);\r |
c9802c45 ED |
331 | }\r |
332 | \r | |
333 | ASSERT (StringBuffer != NULL);\r | |
334 | gLanguageToken[OptionCount] = HiiSetString (HiiHandle, 0, StringBuffer, NULL);\r | |
335 | FreePool (StringBuffer);\r | |
336 | \r | |
337 | OptionCount++;\r | |
338 | }\r | |
339 | }\r | |
340 | \r | |
341 | ASSERT (gLanguageToken != NULL);\r | |
342 | LangCode = gLanguageString;\r | |
343 | OptionCount = 0;\r | |
344 | if (Lang == NULL) {\r | |
345 | Lang = AllocatePool (AsciiStrSize (gLanguageString));\r | |
346 | ASSERT (Lang != NULL);\r | |
347 | }\r | |
348 | while (*LangCode != 0) {\r | |
349 | GetNextLanguage (&LangCode, Lang);\r | |
350 | \r | |
351 | if (CurrentLang != NULL && AsciiStrCmp (Lang, CurrentLang) == 0) {\r | |
352 | HiiCreateOneOfOptionOpCode (\r | |
353 | OptionsOpCodeHandle,\r | |
354 | gLanguageToken[OptionCount],\r | |
355 | EFI_IFR_OPTION_DEFAULT,\r | |
356 | EFI_IFR_NUMERIC_SIZE_1,\r | |
357 | (UINT8) OptionCount\r | |
358 | );\r | |
e4260252 | 359 | gCurrentLanguageIndex = (UINT8) OptionCount;\r |
c9802c45 ED |
360 | } else {\r |
361 | HiiCreateOneOfOptionOpCode (\r | |
362 | OptionsOpCodeHandle,\r | |
363 | gLanguageToken[OptionCount],\r | |
364 | 0,\r | |
365 | EFI_IFR_NUMERIC_SIZE_1,\r | |
366 | (UINT8) OptionCount\r | |
367 | );\r | |
368 | }\r | |
369 | \r | |
370 | OptionCount++;\r | |
371 | }\r | |
372 | \r | |
373 | if (CurrentLang != NULL) {\r | |
374 | FreePool (CurrentLang);\r | |
375 | }\r | |
376 | FreePool (Lang);\r | |
377 | \r | |
378 | HiiCreateOneOfOpCode (\r | |
379 | StartOpCodeHandle,\r | |
380 | FRONT_PAGE_KEY_LANGUAGE,\r | |
381 | 0,\r | |
382 | 0,\r | |
383 | STRING_TOKEN (STR_LANGUAGE_SELECT),\r | |
384 | STRING_TOKEN (STR_LANGUAGE_SELECT_HELP),\r | |
385 | EFI_IFR_FLAG_CALLBACK,\r | |
386 | EFI_IFR_NUMERIC_SIZE_1,\r | |
387 | OptionsOpCodeHandle,\r | |
388 | NULL\r | |
389 | );\r | |
390 | }\r | |
391 | \r | |
392 | /**\r | |
393 | Create continue menu in the front page.\r | |
394 | \r | |
395 | @param[in] HiiHandle The hii handle for the Uiapp driver.\r | |
396 | @param[in] StartOpCodeHandle The opcode handle to save the new opcode.\r | |
397 | \r | |
398 | **/\r | |
399 | VOID\r | |
400 | UiCreateContinueMenu (\r | |
401 | IN EFI_HII_HANDLE HiiHandle,\r | |
402 | IN VOID *StartOpCodeHandle\r | |
403 | )\r | |
404 | {\r | |
405 | HiiCreateActionOpCode (\r | |
406 | StartOpCodeHandle,\r | |
407 | FRONT_PAGE_KEY_CONTINUE,\r | |
408 | STRING_TOKEN (STR_CONTINUE_PROMPT),\r | |
409 | STRING_TOKEN (STR_CONTINUE_PROMPT),\r | |
410 | EFI_IFR_FLAG_CALLBACK,\r | |
411 | 0\r | |
412 | );\r | |
413 | }\r | |
414 | \r | |
415 | /**\r | |
416 | Create empty line menu in the front page.\r | |
417 | \r | |
418 | @param HiiHandle The hii handle for the Uiapp driver.\r | |
419 | @param StartOpCodeHandle The opcode handle to save the new opcode.\r | |
420 | \r | |
421 | **/\r | |
422 | VOID\r | |
423 | UiCreateEmptyLine (\r | |
424 | IN EFI_HII_HANDLE HiiHandle,\r | |
425 | IN VOID *StartOpCodeHandle\r | |
426 | )\r | |
427 | {\r | |
428 | HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_NULL_STRING), 0, 0, 0);\r | |
429 | }\r | |
430 | \r | |
431 | /**\r | |
432 | Create Reset menu in the front page.\r | |
433 | \r | |
434 | @param[in] HiiHandle The hii handle for the Uiapp driver.\r | |
435 | @param[in] StartOpCodeHandle The opcode handle to save the new opcode.\r | |
436 | \r | |
437 | **/\r | |
438 | VOID\r | |
439 | UiCreateResetMenu (\r | |
440 | IN EFI_HII_HANDLE HiiHandle,\r | |
441 | IN VOID *StartOpCodeHandle\r | |
442 | )\r | |
443 | {\r | |
444 | HiiCreateActionOpCode (\r | |
445 | StartOpCodeHandle,\r | |
446 | FRONT_PAGE_KEY_RESET,\r | |
447 | STRING_TOKEN (STR_RESET_STRING),\r | |
448 | STRING_TOKEN (STR_RESET_STRING),\r | |
449 | EFI_IFR_FLAG_CALLBACK,\r | |
450 | 0\r | |
451 | );\r | |
452 | }\r | |
453 | \r | |
454 | /**\r | |
455 | Extract device path for given HII handle and class guid.\r | |
456 | \r | |
457 | @param Handle The HII handle.\r | |
458 | \r | |
459 | @retval NULL Fail to get the device path string.\r | |
460 | @return PathString Get the device path string.\r | |
461 | \r | |
462 | **/\r | |
463 | CHAR16 *\r | |
464 | ExtractDevicePathFromHiiHandle (\r | |
465 | IN EFI_HII_HANDLE Handle\r | |
466 | )\r | |
467 | {\r | |
468 | EFI_STATUS Status;\r | |
469 | EFI_HANDLE DriverHandle;\r | |
470 | \r | |
471 | ASSERT (Handle != NULL);\r | |
472 | \r | |
473 | if (Handle == NULL) {\r | |
474 | return NULL;\r | |
475 | }\r | |
476 | \r | |
477 | Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r | |
478 | if (EFI_ERROR (Status)) {\r | |
479 | return NULL;\r | |
480 | }\r | |
481 | \r | |
482 | return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);\r | |
483 | }\r | |
484 | \r | |
485 | /**\r | |
486 | Check whether this driver need to be shown in the front page.\r | |
487 | \r | |
488 | @param HiiHandle The hii handle for the driver.\r | |
489 | @param Guid The special guid for the driver which is the target.\r | |
490 | @param PromptId Return the prompt string id.\r | |
491 | @param HelpId Return the help string id.\r | |
492 | @param FormsetGuid Return the formset guid info.\r | |
493 | \r | |
494 | @retval EFI_SUCCESS Search the driver success\r | |
495 | \r | |
496 | **/\r | |
497 | BOOLEAN\r | |
498 | RequiredDriver (\r | |
499 | IN EFI_HII_HANDLE HiiHandle,\r | |
500 | IN EFI_GUID *Guid,\r | |
501 | OUT EFI_STRING_ID *PromptId,\r | |
502 | OUT EFI_STRING_ID *HelpId,\r | |
503 | OUT VOID *FormsetGuid\r | |
504 | )\r | |
505 | {\r | |
506 | EFI_STATUS Status;\r | |
507 | UINT8 ClassGuidNum;\r | |
508 | EFI_GUID *ClassGuid;\r | |
509 | EFI_IFR_FORM_SET *Buffer;\r | |
510 | UINTN BufferSize;\r | |
511 | UINT8 *Ptr;\r | |
512 | UINTN TempSize;\r | |
513 | BOOLEAN RetVal;\r | |
514 | \r | |
515 | Status = HiiGetFormSetFromHiiHandle(HiiHandle, &Buffer,&BufferSize);\r | |
516 | if (EFI_ERROR (Status)) {\r | |
517 | return FALSE;\r | |
518 | }\r | |
519 | \r | |
520 | RetVal = FALSE;\r | |
521 | TempSize = 0;\r | |
522 | Ptr = (UINT8 *) Buffer;\r | |
523 | while(TempSize < BufferSize) {\r | |
524 | TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
525 | \r | |
526 | if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){\r | |
527 | Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
528 | continue;\r | |
529 | }\r | |
530 | \r | |
531 | ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);\r | |
532 | ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));\r | |
533 | while (ClassGuidNum-- > 0) {\r | |
534 | if (!CompareGuid (Guid, ClassGuid)){\r | |
535 | ClassGuid ++;\r | |
536 | continue;\r | |
537 | }\r | |
538 | \r | |
539 | *PromptId = ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle;\r | |
540 | *HelpId = ((EFI_IFR_FORM_SET *)Ptr)->Help;\r | |
541 | CopyMem (FormsetGuid, &((EFI_IFR_FORM_SET *) Ptr)->Guid, sizeof (EFI_GUID));\r | |
542 | RetVal = TRUE;\r | |
543 | }\r | |
544 | }\r | |
545 | \r | |
546 | FreePool (Buffer);\r | |
547 | \r | |
548 | return RetVal;\r | |
549 | }\r | |
550 | \r | |
551 | /**\r | |
552 | Search the drivers in the system which need to show in the front page\r | |
553 | and insert the menu to the front page.\r | |
554 | \r | |
555 | @param HiiHandle The hii handle for the Uiapp driver.\r | |
556 | @param ClassGuid The class guid for the driver which is the target.\r | |
8caa3caa | 557 | @param SpecialHandlerFn The pointer to the specail handler function, if any.\r |
c9802c45 | 558 | @param StartOpCodeHandle The opcode handle to save the new opcode.\r |
c9802c45 ED |
559 | \r |
560 | @retval EFI_SUCCESS Search the driver success\r | |
561 | \r | |
562 | **/\r | |
563 | EFI_STATUS\r | |
564 | UiListThirdPartyDrivers (\r | |
565 | IN EFI_HII_HANDLE HiiHandle,\r | |
566 | IN EFI_GUID *ClassGuid,\r | |
567 | IN DRIVER_SPECIAL_HANDLER SpecialHandlerFn,\r | |
568 | IN VOID *StartOpCodeHandle\r | |
569 | )\r | |
570 | {\r | |
571 | UINTN Index;\r | |
572 | EFI_STRING String;\r | |
573 | EFI_STRING_ID Token;\r | |
574 | EFI_STRING_ID TokenHelp;\r | |
575 | EFI_HII_HANDLE *HiiHandles;\r | |
576 | CHAR16 *DevicePathStr;\r | |
577 | UINTN Count;\r | |
578 | UINTN CurrentSize;\r | |
579 | UI_HII_DRIVER_INSTANCE *DriverListPtr;\r | |
580 | EFI_STRING NewName;\r | |
581 | BOOLEAN EmptyLineAfter;\r | |
582 | \r | |
583 | if (gHiiDriverList != NULL) {\r | |
584 | FreePool (gHiiDriverList);\r | |
585 | }\r | |
586 | \r | |
587 | HiiHandles = HiiGetHiiHandles (NULL);\r | |
588 | ASSERT (HiiHandles != NULL);\r | |
589 | \r | |
590 | gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE));\r | |
591 | ASSERT (gHiiDriverList != NULL);\r | |
592 | DriverListPtr = gHiiDriverList;\r | |
593 | CurrentSize = UI_HII_DRIVER_LIST_SIZE;\r | |
594 | \r | |
595 | for (Index = 0, Count = 0; HiiHandles[Index] != NULL; Index++) {\r | |
596 | if (!RequiredDriver (HiiHandles[Index], ClassGuid, &Token, &TokenHelp, &gHiiDriverList[Count].FormSetGuid)) {\r | |
597 | continue;\r | |
598 | }\r | |
599 | \r | |
600 | String = HiiGetString (HiiHandles[Index], Token, NULL);\r | |
601 | if (String == NULL) {\r | |
7258076b | 602 | String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r |
c9802c45 ED |
603 | ASSERT (String != NULL);\r |
604 | } else if (SpecialHandlerFn != NULL) {\r | |
605 | //\r | |
606 | // Check whether need to rename the driver name.\r | |
607 | //\r | |
608 | EmptyLineAfter = FALSE;\r | |
609 | if (SpecialHandlerFn (String, &NewName, &EmptyLineAfter)) {\r | |
610 | FreePool (String);\r | |
611 | String = NewName;\r | |
612 | DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter;\r | |
613 | }\r | |
614 | }\r | |
615 | DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL);\r | |
616 | FreePool (String);\r | |
617 | \r | |
618 | String = HiiGetString (HiiHandles[Index], TokenHelp, NULL);\r | |
619 | if (String == NULL) {\r | |
7258076b | 620 | String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r |
c9802c45 ED |
621 | ASSERT (String != NULL);\r |
622 | }\r | |
623 | DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL);\r | |
624 | FreePool (String);\r | |
625 | \r | |
626 | DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
627 | if (DevicePathStr != NULL){\r | |
628 | DriverListPtr[Count].DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
629 | FreePool (DevicePathStr);\r | |
630 | } else {\r | |
631 | DriverListPtr[Count].DevicePathId = 0;\r | |
632 | }\r | |
633 | \r | |
634 | Count++;\r | |
635 | if (Count >= CurrentSize) {\r | |
469293f8 JW |
636 | DriverListPtr = ReallocatePool (\r |
637 | CurrentSize * sizeof (UI_HII_DRIVER_INSTANCE),\r | |
638 | (Count + UI_HII_DRIVER_LIST_SIZE)\r | |
639 | * sizeof (UI_HII_DRIVER_INSTANCE),\r | |
640 | gHiiDriverList\r | |
641 | );\r | |
c9802c45 | 642 | ASSERT (DriverListPtr != NULL);\r |
c9802c45 ED |
643 | gHiiDriverList = DriverListPtr;\r |
644 | CurrentSize += UI_HII_DRIVER_LIST_SIZE;\r | |
645 | }\r | |
646 | }\r | |
647 | \r | |
648 | FreePool (HiiHandles);\r | |
649 | \r | |
650 | Index = 0;\r | |
651 | while (gHiiDriverList[Index].PromptId != 0) {\r | |
652 | HiiCreateGotoExOpCode (\r | |
653 | StartOpCodeHandle,\r | |
654 | 0,\r | |
655 | gHiiDriverList[Index].PromptId,\r | |
656 | gHiiDriverList[Index].HelpId,\r | |
657 | 0,\r | |
7d467158 | 658 | (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_DRIVER),\r |
c9802c45 ED |
659 | 0,\r |
660 | &gHiiDriverList[Index].FormSetGuid,\r | |
661 | gHiiDriverList[Index].DevicePathId\r | |
662 | );\r | |
663 | \r | |
664 | if (gHiiDriverList[Index].EmptyLineAfter) {\r | |
665 | UiCreateEmptyLine (HiiHandle, StartOpCodeHandle);\r | |
666 | }\r | |
667 | \r | |
668 | Index ++;\r | |
669 | }\r | |
670 | \r | |
671 | return EFI_SUCCESS;\r | |
672 | }\r |