]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
1. Support inconsistent if opcode used in string/password opcode.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / ProcessOptions.c
CommitLineData
c60a0616 1/** @file\r
2Implementation for handling the User Interface option processing.\r
3\r
4\r
e5eed7d3
HT
5Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
c60a0616 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
c60a0616 16#include "Setup.h"\r
17\r
18\r
19/**\r
20 Process Question Config.\r
21\r
22 @param Selection The UI menu selection.\r
23 @param Question The Question to be peocessed.\r
24\r
25 @retval EFI_SUCCESS Question Config process success.\r
26 @retval Other Question Config process fail.\r
27\r
28**/\r
29EFI_STATUS\r
30ProcessQuestionConfig (\r
31 IN UI_MENU_SELECTION *Selection,\r
32 IN FORM_BROWSER_STATEMENT *Question\r
33 )\r
34{\r
35 EFI_STATUS Status;\r
36 CHAR16 *ConfigResp;\r
37 CHAR16 *Progress;\r
38 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
39\r
40 if (Question->QuestionConfig == 0) {\r
41 return EFI_SUCCESS;\r
42 }\r
43\r
44 //\r
45 // Get <ConfigResp>\r
46 //\r
47 ConfigResp = GetToken (Question->QuestionConfig, Selection->FormSet->HiiHandle);\r
48 if (ConfigResp == NULL) {\r
49 return EFI_NOT_FOUND;\r
50 }\r
51\r
52 //\r
53 // Send config to Configuration Driver\r
54 //\r
55 ConfigAccess = Selection->FormSet->ConfigAccess;\r
56 if (ConfigAccess == NULL) {\r
57 return EFI_UNSUPPORTED;\r
58 }\r
59 Status = ConfigAccess->RouteConfig (\r
60 ConfigAccess,\r
61 ConfigResp,\r
62 &Progress\r
63 );\r
64\r
65 return Status;\r
66}\r
67\r
68\r
69/**\r
70 Search an Option of a Question by its value.\r
71\r
72 @param Question The Question\r
73 @param OptionValue Value for Option to be searched.\r
74\r
75 @retval Pointer Pointer to the found Option.\r
76 @retval NULL Option not found.\r
77\r
78**/\r
79QUESTION_OPTION *\r
80ValueToOption (\r
81 IN FORM_BROWSER_STATEMENT *Question,\r
82 IN EFI_HII_VALUE *OptionValue\r
83 )\r
84{\r
85 LIST_ENTRY *Link;\r
86 QUESTION_OPTION *Option;\r
87\r
88 Link = GetFirstNode (&Question->OptionListHead);\r
89 while (!IsNull (&Question->OptionListHead, Link)) {\r
90 Option = QUESTION_OPTION_FROM_LINK (Link);\r
91\r
92 if (CompareHiiValue (&Option->Value, OptionValue, NULL) == 0) {\r
93 return Option;\r
94 }\r
95\r
96 Link = GetNextNode (&Question->OptionListHead, Link);\r
97 }\r
98\r
99 return NULL;\r
100}\r
101\r
102\r
d02847d3 103/**\r
104 Return data element in an Array by its Index.\r
105\r
106 @param Array The data array.\r
107 @param Type Type of the data in this array.\r
108 @param Index Zero based index for data in this array.\r
109\r
110 @retval Value The data to be returned\r
111\r
112**/\r
113UINT64\r
114GetArrayData (\r
115 IN VOID *Array,\r
116 IN UINT8 Type,\r
117 IN UINTN Index\r
118 )\r
119{\r
120 UINT64 Data;\r
121\r
122 ASSERT (Array != NULL);\r
123\r
124 Data = 0;\r
125 switch (Type) {\r
126 case EFI_IFR_TYPE_NUM_SIZE_8:\r
127 Data = (UINT64) *(((UINT8 *) Array) + Index);\r
128 break;\r
129\r
130 case EFI_IFR_TYPE_NUM_SIZE_16:\r
131 Data = (UINT64) *(((UINT16 *) Array) + Index);\r
132 break;\r
133\r
134 case EFI_IFR_TYPE_NUM_SIZE_32:\r
135 Data = (UINT64) *(((UINT32 *) Array) + Index);\r
136 break;\r
137\r
138 case EFI_IFR_TYPE_NUM_SIZE_64:\r
139 Data = (UINT64) *(((UINT64 *) Array) + Index);\r
140 break;\r
141\r
142 default:\r
143 break;\r
144 }\r
145\r
146 return Data;\r
147}\r
148\r
149\r
150/**\r
151 Set value of a data element in an Array by its Index.\r
152\r
153 @param Array The data array.\r
154 @param Type Type of the data in this array.\r
155 @param Index Zero based index for data in this array.\r
156 @param Value The value to be set.\r
157\r
158**/\r
159VOID\r
160SetArrayData (\r
161 IN VOID *Array,\r
162 IN UINT8 Type,\r
163 IN UINTN Index,\r
164 IN UINT64 Value\r
165 )\r
166{\r
167\r
168 ASSERT (Array != NULL);\r
169\r
170 switch (Type) {\r
171 case EFI_IFR_TYPE_NUM_SIZE_8:\r
172 *(((UINT8 *) Array) + Index) = (UINT8) Value;\r
173 break;\r
174\r
175 case EFI_IFR_TYPE_NUM_SIZE_16:\r
176 *(((UINT16 *) Array) + Index) = (UINT16) Value;\r
177 break;\r
178\r
179 case EFI_IFR_TYPE_NUM_SIZE_32:\r
180 *(((UINT32 *) Array) + Index) = (UINT32) Value;\r
181 break;\r
182\r
183 case EFI_IFR_TYPE_NUM_SIZE_64:\r
184 *(((UINT64 *) Array) + Index) = (UINT64) Value;\r
185 break;\r
186\r
187 default:\r
188 break;\r
189 }\r
190}\r
191\r
192\r
c60a0616 193/**\r
194 Print Question Value according to it's storage width and display attributes.\r
195\r
196 @param Question The Question to be printed.\r
197 @param FormattedNumber Buffer for output string.\r
198 @param BufferSize The FormattedNumber buffer size in bytes.\r
199\r
200 @retval EFI_SUCCESS Print success.\r
201 @retval EFI_BUFFER_TOO_SMALL Buffer size is not enough for formatted number.\r
202\r
203**/\r
204EFI_STATUS\r
205PrintFormattedNumber (\r
206 IN FORM_BROWSER_STATEMENT *Question,\r
207 IN OUT CHAR16 *FormattedNumber,\r
208 IN UINTN BufferSize\r
209 )\r
210{\r
211 INT64 Value;\r
212 CHAR16 *Format;\r
213 EFI_HII_VALUE *QuestionValue;\r
214\r
215 if (BufferSize < (21 * sizeof (CHAR16))) {\r
216 return EFI_BUFFER_TOO_SMALL;\r
217 }\r
218\r
219 QuestionValue = &Question->HiiValue;\r
220\r
221 Value = (INT64) QuestionValue->Value.u64;\r
222 switch (Question->Flags & EFI_IFR_DISPLAY) {\r
223 case EFI_IFR_DISPLAY_INT_DEC:\r
224 switch (QuestionValue->Type) {\r
225 case EFI_IFR_NUMERIC_SIZE_1:\r
226 Value = (INT64) ((INT8) QuestionValue->Value.u8);\r
227 break;\r
228\r
229 case EFI_IFR_NUMERIC_SIZE_2:\r
230 Value = (INT64) ((INT16) QuestionValue->Value.u16);\r
231 break;\r
232\r
233 case EFI_IFR_NUMERIC_SIZE_4:\r
234 Value = (INT64) ((INT32) QuestionValue->Value.u32);\r
235 break;\r
236\r
237 case EFI_IFR_NUMERIC_SIZE_8:\r
238 default:\r
239 break;\r
240 }\r
241\r
242 if (Value < 0) {\r
243 Value = -Value;\r
244 Format = L"-%ld";\r
245 } else {\r
246 Format = L"%ld";\r
247 }\r
248 break;\r
249\r
250 case EFI_IFR_DISPLAY_UINT_DEC:\r
251 Format = L"%ld";\r
252 break;\r
253\r
254 case EFI_IFR_DISPLAY_UINT_HEX:\r
255 Format = L"%lx";\r
256 break;\r
257\r
258 default:\r
259 return EFI_UNSUPPORTED;\r
260 break;\r
261 }\r
262\r
263 UnicodeSPrint (FormattedNumber, BufferSize, Format, Value);\r
264\r
265 return EFI_SUCCESS;\r
266}\r
267\r
268\r
269/**\r
270 Password may be stored as encrypted by Configuration Driver. When change a\r
271 password, user will be challenged with old password. To validate user input old\r
272 password, we will send the clear text to Configuration Driver via Callback().\r
273 Configuration driver is responsible to check the passed in password and return\r
274 the validation result. If validation pass, state machine in password Callback()\r
275 will transit from BROWSER_STATE_VALIDATE_PASSWORD to BROWSER_STATE_SET_PASSWORD.\r
276 After user type in new password twice, Callback() will be invoked to send the\r
277 new password to Configuration Driver.\r
278\r
279 @param Selection Pointer to UI_MENU_SELECTION.\r
280 @param MenuOption The MenuOption for this password Question.\r
281 @param String The clear text of password.\r
282\r
283 @retval EFI_NOT_AVAILABLE_YET Callback() request to terminate password input.\r
284 @return In state of BROWSER_STATE_VALIDATE_PASSWORD:\r
285 @retval EFI_SUCCESS Password correct, Browser will prompt for new\r
286 password.\r
287 @retval EFI_NOT_READY Password incorrect, Browser will show error\r
288 message.\r
289 @retval Other Browser will do nothing.\r
290 @return In state of BROWSER_STATE_SET_PASSWORD:\r
291 @retval EFI_SUCCESS Set password success.\r
292 @retval Other Set password failed.\r
293\r
294**/\r
295EFI_STATUS\r
296PasswordCallback (\r
297 IN UI_MENU_SELECTION *Selection,\r
298 IN UI_MENU_OPTION *MenuOption,\r
299 IN CHAR16 *String\r
300 )\r
301{\r
302 EFI_STATUS Status;\r
303 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
304 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
e2100bfa 305 EFI_IFR_TYPE_VALUE IfrTypeValue;\r
c60a0616 306\r
c60a0616 307 ConfigAccess = Selection->FormSet->ConfigAccess;\r
308 if (ConfigAccess == NULL) {\r
309 return EFI_UNSUPPORTED;\r
310 }\r
311\r
312 //\r
313 // Prepare password string in HII database\r
314 //\r
315 if (String != NULL) {\r
e2100bfa 316 IfrTypeValue.string = NewString (String, Selection->FormSet->HiiHandle);\r
c60a0616 317 } else {\r
e2100bfa 318 IfrTypeValue.string = 0;\r
c60a0616 319 }\r
320\r
321 //\r
322 // Send password to Configuration Driver for validation\r
323 //\r
324 Status = ConfigAccess->Callback (\r
325 ConfigAccess,\r
326 EFI_BROWSER_ACTION_CHANGING,\r
327 MenuOption->ThisTag->QuestionId,\r
e2100bfa
ED
328 MenuOption->ThisTag->HiiValue.Type,\r
329 &IfrTypeValue,\r
c60a0616 330 &ActionRequest\r
331 );\r
332\r
333 //\r
334 // Remove password string from HII database\r
335 //\r
336 if (String != NULL) {\r
e2100bfa 337 DeleteString (IfrTypeValue.string, Selection->FormSet->HiiHandle);\r
c60a0616 338 }\r
339\r
340 return Status;\r
341}\r
342\r
343\r
344/**\r
345 Display error message for invalid password.\r
346\r
347**/\r
348VOID\r
349PasswordInvalid (\r
350 VOID\r
351 )\r
352{\r
353 EFI_INPUT_KEY Key;\r
354\r
355 //\r
356 // Invalid password, prompt error message\r
357 //\r
358 do {\r
359 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gPassowordInvalid, gPressEnter, gEmptyString);\r
360 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
361}\r
362\r
363\r
364/**\r
365 Process a Question's Option (whether selected or un-selected).\r
366\r
367 @param Selection Pointer to UI_MENU_SELECTION.\r
368 @param MenuOption The MenuOption for this Question.\r
369 @param Selected TRUE: if Question is selected.\r
370 @param OptionString Pointer of the Option String to be displayed.\r
371\r
372 @retval EFI_SUCCESS Question Option process success.\r
373 @retval Other Question Option process fail.\r
374\r
375**/\r
376EFI_STATUS\r
377ProcessOptions (\r
378 IN UI_MENU_SELECTION *Selection,\r
379 IN UI_MENU_OPTION *MenuOption,\r
380 IN BOOLEAN Selected,\r
381 OUT CHAR16 **OptionString\r
382 )\r
383{\r
384 EFI_STATUS Status;\r
385 CHAR16 *StringPtr;\r
386 CHAR16 *TempString;\r
387 UINTN Index;\r
388 FORM_BROWSER_STATEMENT *Question;\r
389 CHAR16 FormattedNumber[21];\r
390 UINT16 Number;\r
391 CHAR16 Character[2];\r
392 EFI_INPUT_KEY Key;\r
393 UINTN BufferSize;\r
394 QUESTION_OPTION *OneOfOption;\r
395 LIST_ENTRY *Link;\r
396 EFI_HII_VALUE HiiValue;\r
397 EFI_HII_VALUE *QuestionValue;\r
398 BOOLEAN Suppress;\r
399 UINT16 Maximum;\r
8d00a0f1 400 QUESTION_OPTION *Option;\r
401 UINTN Index2;\r
d02847d3 402 UINT8 *ValueArray;\r
403 UINT8 ValueType;\r
e2100bfa 404 EFI_STRING_ID StringId;\r
c60a0616 405\r
406 Status = EFI_SUCCESS;\r
407\r
408 StringPtr = NULL;\r
409 Character[1] = L'\0';\r
410 *OptionString = NULL;\r
e2100bfa 411 StringId = 0;\r
c60a0616 412\r
413 ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));\r
414 BufferSize = (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow;\r
415\r
416 Question = MenuOption->ThisTag;\r
417 QuestionValue = &Question->HiiValue;\r
418 Maximum = (UINT16) Question->Maximum;\r
419\r
d02847d3 420 ValueArray = Question->BufferValue;\r
421 ValueType = Question->ValueType;\r
422\r
c60a0616 423 switch (Question->Operand) {\r
424 case EFI_IFR_ORDERED_LIST_OP:\r
b86b413a
LG
425 //\r
426 // Check whether there are Options of this OrderedList\r
427 //\r
428 if (IsListEmpty (&Question->OptionListHead)) {\r
429 break;\r
430 }\r
c60a0616 431 //\r
432 // Initialize Option value array\r
433 //\r
d02847d3 434 if (GetArrayData (ValueArray, ValueType, 0) == 0) {\r
c60a0616 435 GetQuestionDefault (Selection->FormSet, Selection->Form, Question, 0);\r
436 }\r
437\r
438 if (Selected) {\r
439 //\r
440 // Go ask for input\r
441 //\r
442 Status = GetSelectionInputPopUp (Selection, MenuOption);\r
443 } else {\r
444 //\r
445 // We now know how many strings we will have, so we can allocate the\r
446 // space required for the array or strings.\r
447 //\r
448 *OptionString = AllocateZeroPool (Question->MaxContainers * BufferSize);\r
449 ASSERT (*OptionString);\r
450\r
d02847d3 451 HiiValue.Type = ValueType;\r
c60a0616 452 HiiValue.Value.u64 = 0;\r
453 for (Index = 0; Index < Question->MaxContainers; Index++) {\r
d02847d3 454 HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);\r
455 if (HiiValue.Value.u64 == 0) {\r
c60a0616 456 //\r
457 // Values for the options in ordered lists should never be a 0\r
458 //\r
459 break;\r
460 }\r
461\r
462 OneOfOption = ValueToOption (Question, &HiiValue);\r
463 if (OneOfOption == NULL) {\r
8d00a0f1 464 //\r
465 // Show error message\r
466 //\r
467 do {\r
468 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r
469 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
470\r
471 //\r
472 // The initial value of the orderedlist is invalid, force to be valid value\r
473 //\r
474 Link = GetFirstNode (&Question->OptionListHead);\r
475 Index2 = 0;\r
476 while (!IsNull (&Question->OptionListHead, Link) && Index2 < Question->MaxContainers) {\r
477 Option = QUESTION_OPTION_FROM_LINK (Link);\r
d02847d3 478 SetArrayData (ValueArray, ValueType, Index2, Option->Value.Value.u64);\r
479 Index2++;\r
8d00a0f1 480 Link = GetNextNode (&Question->OptionListHead, Link);\r
481 }\r
d02847d3 482 SetArrayData (ValueArray, ValueType, Index2, 0);\r
8d00a0f1 483\r
484 Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
485 UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
486\r
f4113e1f 487 FreePool (*OptionString);\r
8d00a0f1 488 *OptionString = NULL;\r
c60a0616 489 return EFI_NOT_FOUND;\r
490 }\r
491\r
492 Suppress = FALSE;\r
493 if ((OneOfOption->SuppressExpression != NULL) &&\r
494 (OneOfOption->SuppressExpression->Result.Value.b)) {\r
495 //\r
496 // This option is suppressed\r
497 //\r
498 Suppress = TRUE;\r
499 }\r
500\r
501 if (!Suppress) {\r
502 Character[0] = LEFT_ONEOF_DELIMITER;\r
503 NewStrCat (OptionString[0], Character);\r
504 StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r
505 NewStrCat (OptionString[0], StringPtr);\r
506 Character[0] = RIGHT_ONEOF_DELIMITER;\r
507 NewStrCat (OptionString[0], Character);\r
508 Character[0] = CHAR_CARRIAGE_RETURN;\r
509 NewStrCat (OptionString[0], Character);\r
510\r
f4113e1f 511 FreePool (StringPtr);\r
c60a0616 512 }\r
513 }\r
514 }\r
515 break;\r
516\r
517 case EFI_IFR_ONE_OF_OP:\r
b86b413a
LG
518 //\r
519 // Check whether there are Options of this OneOf\r
520 //\r
521 if (IsListEmpty (&Question->OptionListHead)) {\r
522 break;\r
523 }\r
c60a0616 524 if (Selected) {\r
525 //\r
526 // Go ask for input\r
527 //\r
528 Status = GetSelectionInputPopUp (Selection, MenuOption);\r
529 } else {\r
530 *OptionString = AllocateZeroPool (BufferSize);\r
531 ASSERT (*OptionString);\r
532\r
533 OneOfOption = ValueToOption (Question, QuestionValue);\r
534 if (OneOfOption == NULL) {\r
8d00a0f1 535 //\r
536 // Show error message\r
537 //\r
538 do {\r
539 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r
540 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
541\r
542 //\r
543 // Force the Question value to be valid\r
544 //\r
545 Link = GetFirstNode (&Question->OptionListHead);\r
546 while (!IsNull (&Question->OptionListHead, Link)) {\r
547 Option = QUESTION_OPTION_FROM_LINK (Link);\r
548\r
549 if ((Option->SuppressExpression == NULL) ||\r
550 !Option->SuppressExpression->Result.Value.b) {\r
551 CopyMem (QuestionValue, &Option->Value, sizeof (EFI_HII_VALUE));\r
552 SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
553 UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
554 break;\r
555 }\r
556\r
557 Link = GetNextNode (&Question->OptionListHead, Link);\r
558 }\r
559\r
f4113e1f 560 FreePool (*OptionString);\r
8d00a0f1 561 *OptionString = NULL;\r
40a06b0c 562 return EFI_NOT_FOUND;\r
c60a0616 563 }\r
564\r
565 if ((OneOfOption->SuppressExpression != NULL) &&\r
566 (OneOfOption->SuppressExpression->Result.Value.b)) {\r
567 //\r
568 // This option is suppressed\r
569 //\r
570 Suppress = TRUE;\r
571 } else {\r
572 Suppress = FALSE;\r
573 }\r
574\r
575 if (Suppress) {\r
576 //\r
577 // Current selected option happen to be suppressed,\r
578 // enforce to select on a non-suppressed option\r
579 //\r
580 Link = GetFirstNode (&Question->OptionListHead);\r
581 while (!IsNull (&Question->OptionListHead, Link)) {\r
582 OneOfOption = QUESTION_OPTION_FROM_LINK (Link);\r
583\r
584 if ((OneOfOption->SuppressExpression == NULL) ||\r
585 !OneOfOption->SuppressExpression->Result.Value.b) {\r
586 Suppress = FALSE;\r
587 CopyMem (QuestionValue, &OneOfOption->Value, sizeof (EFI_HII_VALUE));\r
588 SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
8d00a0f1 589 UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
590 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
c60a0616 591 break;\r
592 }\r
593\r
594 Link = GetNextNode (&Question->OptionListHead, Link);\r
595 }\r
596 }\r
597\r
598 if (!Suppress) {\r
599 Character[0] = LEFT_ONEOF_DELIMITER;\r
600 NewStrCat (OptionString[0], Character);\r
601 StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r
602 NewStrCat (OptionString[0], StringPtr);\r
603 Character[0] = RIGHT_ONEOF_DELIMITER;\r
604 NewStrCat (OptionString[0], Character);\r
605\r
f4113e1f 606 FreePool (StringPtr);\r
c60a0616 607 }\r
608 }\r
609 break;\r
610\r
611 case EFI_IFR_CHECKBOX_OP:\r
612 *OptionString = AllocateZeroPool (BufferSize);\r
613 ASSERT (*OptionString);\r
614\r
615 *OptionString[0] = LEFT_CHECKBOX_DELIMITER;\r
616\r
617 if (Selected) {\r
618 //\r
619 // Since this is a BOOLEAN operation, flip it upon selection\r
620 //\r
621 QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r
622\r
623 //\r
624 // Perform inconsistent check\r
625 //\r
626 Status = ValidateQuestion (Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
627 if (EFI_ERROR (Status)) {\r
628 //\r
629 // Inconsistent check fail, restore Question Value\r
630 //\r
631 QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r
f4113e1f 632 FreePool (*OptionString);\r
8d00a0f1 633 *OptionString = NULL;\r
c60a0616 634 return Status;\r
635 }\r
636\r
637 //\r
638 // Save Question value\r
639 //\r
640 Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
641 UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
642 }\r
643\r
644 if (QuestionValue->Value.b) {\r
645 *(OptionString[0] + 1) = CHECK_ON;\r
646 } else {\r
647 *(OptionString[0] + 1) = CHECK_OFF;\r
648 }\r
649 *(OptionString[0] + 2) = RIGHT_CHECKBOX_DELIMITER;\r
650 break;\r
651\r
652 case EFI_IFR_NUMERIC_OP:\r
653 if (Selected) {\r
654 //\r
655 // Go ask for input\r
656 //\r
657 Status = GetNumericInput (Selection, MenuOption);\r
658 } else {\r
659 *OptionString = AllocateZeroPool (BufferSize);\r
660 ASSERT (*OptionString);\r
661\r
662 *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
663\r
664 //\r
665 // Formatted print\r
666 //\r
667 PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16));\r
668 Number = (UINT16) GetStringWidth (FormattedNumber);\r
669 CopyMem (OptionString[0] + 1, FormattedNumber, Number);\r
670\r
671 *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;\r
672 }\r
673 break;\r
674\r
675 case EFI_IFR_DATE_OP:\r
676 if (Selected) {\r
677 //\r
678 // This is similar to numerics\r
679 //\r
680 Status = GetNumericInput (Selection, MenuOption);\r
681 } else {\r
682 *OptionString = AllocateZeroPool (BufferSize);\r
683 ASSERT (*OptionString);\r
684\r
685 switch (MenuOption->Sequence) {\r
686 case 0:\r
687 *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
688 UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Month);\r
689 *(OptionString[0] + 3) = DATE_SEPARATOR;\r
690 break;\r
691\r
692 case 1:\r
693 SetUnicodeMem (OptionString[0], 4, L' ');\r
694 UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Day);\r
695 *(OptionString[0] + 6) = DATE_SEPARATOR;\r
696 break;\r
697\r
698 case 2:\r
699 SetUnicodeMem (OptionString[0], 7, L' ');\r
700 UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%4d", QuestionValue->Value.date.Year);\r
701 *(OptionString[0] + 11) = RIGHT_NUMERIC_DELIMITER;\r
702 break;\r
703 }\r
704 }\r
705 break;\r
706\r
707 case EFI_IFR_TIME_OP:\r
708 if (Selected) {\r
709 //\r
710 // This is similar to numerics\r
711 //\r
712 Status = GetNumericInput (Selection, MenuOption);\r
713 } else {\r
714 *OptionString = AllocateZeroPool (BufferSize);\r
715 ASSERT (*OptionString);\r
716\r
717 switch (MenuOption->Sequence) {\r
718 case 0:\r
719 *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
720 UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Hour);\r
721 *(OptionString[0] + 3) = TIME_SEPARATOR;\r
722 break;\r
723\r
724 case 1:\r
725 SetUnicodeMem (OptionString[0], 4, L' ');\r
726 UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Minute);\r
727 *(OptionString[0] + 6) = TIME_SEPARATOR;\r
728 break;\r
729\r
730 case 2:\r
731 SetUnicodeMem (OptionString[0], 7, L' ');\r
732 UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Second);\r
733 *(OptionString[0] + 9) = RIGHT_NUMERIC_DELIMITER;\r
734 break;\r
735 }\r
736 }\r
737 break;\r
738\r
739 case EFI_IFR_STRING_OP:\r
740 if (Selected) {\r
741 StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
742 ASSERT (StringPtr);\r
743\r
744 Status = ReadString (MenuOption, gPromptForData, StringPtr);\r
745 if (!EFI_ERROR (Status)) {\r
e2100bfa
ED
746 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r
747 Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
748 if (EFI_ERROR (Status)) {\r
749 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r
750 } else {\r
751 CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
752 SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
c60a0616 753\r
e2100bfa
ED
754 UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
755 }\r
c60a0616 756 }\r
757\r
f4113e1f 758 FreePool (StringPtr);\r
c60a0616 759 } else {\r
760 *OptionString = AllocateZeroPool (BufferSize);\r
761 ASSERT (*OptionString);\r
762\r
763 if (((CHAR16 *) Question->BufferValue)[0] == 0x0000) {\r
764 *(OptionString[0]) = '_';\r
765 } else {\r
766 if ((Maximum * sizeof (CHAR16)) < BufferSize) {\r
767 BufferSize = Maximum * sizeof (CHAR16);\r
768 }\r
769 CopyMem (OptionString[0], (CHAR16 *) Question->BufferValue, BufferSize);\r
770 }\r
771 }\r
772 break;\r
773\r
774 case EFI_IFR_PASSWORD_OP:\r
775 if (Selected) {\r
776 StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
777 ASSERT (StringPtr);\r
778\r
779 //\r
780 // For interactive passwords, old password is validated by callback\r
781 //\r
782 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
783 //\r
784 // Use a NULL password to test whether old password is required\r
785 //\r
786 *StringPtr = 0;\r
787 Status = PasswordCallback (Selection, MenuOption, StringPtr);\r
13ad1def 788 if (Status == EFI_NOT_AVAILABLE_YET || Status == EFI_UNSUPPORTED) {\r
c60a0616 789 //\r
13ad1def 790 // Callback is not supported, or\r
c60a0616 791 // Callback request to terminate password input\r
792 //\r
f4113e1f 793 FreePool (StringPtr);\r
c60a0616 794 return EFI_SUCCESS;\r
795 }\r
796\r
797 if (EFI_ERROR (Status)) {\r
798 //\r
799 // Old password exist, ask user for the old password\r
800 //\r
801 Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r
802 if (EFI_ERROR (Status)) {\r
f4113e1f 803 FreePool (StringPtr);\r
c60a0616 804 return Status;\r
805 }\r
806\r
807 //\r
808 // Check user input old password\r
809 //\r
810 Status = PasswordCallback (Selection, MenuOption, StringPtr);\r
811 if (EFI_ERROR (Status)) {\r
812 if (Status == EFI_NOT_READY) {\r
813 //\r
814 // Typed in old password incorrect\r
815 //\r
816 PasswordInvalid ();\r
817 } else {\r
818 Status = EFI_SUCCESS;\r
819 }\r
820\r
f4113e1f 821 FreePool (StringPtr);\r
c60a0616 822 return Status;\r
823 }\r
824 }\r
825 } else {\r
826 //\r
827 // For non-interactive password, validate old password in local\r
828 //\r
829 if (*((CHAR16 *) Question->BufferValue) != 0) {\r
830 //\r
831 // There is something there! Prompt for password\r
832 //\r
833 Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r
834 if (EFI_ERROR (Status)) {\r
f4113e1f 835 FreePool (StringPtr);\r
c60a0616 836 return Status;\r
837 }\r
838\r
839 TempString = AllocateCopyPool ((Maximum + 1) * sizeof (CHAR16), Question->BufferValue);\r
40a06b0c 840 ASSERT (TempString != NULL);\r
8b0fc5c1 841\r
c60a0616 842 TempString[Maximum] = L'\0';\r
843\r
844 if (StrCmp (StringPtr, TempString) != 0) {\r
845 //\r
846 // Typed in old password incorrect\r
847 //\r
848 PasswordInvalid ();\r
849\r
f4113e1f 850 FreePool (StringPtr);\r
851 FreePool (TempString);\r
c60a0616 852 return Status;\r
853 }\r
854\r
f4113e1f 855 FreePool (TempString);\r
c60a0616 856 }\r
857 }\r
858\r
859 //\r
860 // Ask for new password\r
861 //\r
862 ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));\r
863 Status = ReadString (MenuOption, gPromptForNewPassword, StringPtr);\r
864 if (EFI_ERROR (Status)) {\r
865 //\r
866 // Reset state machine for interactive password\r
867 //\r
868 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
869 PasswordCallback (Selection, MenuOption, NULL);\r
870 }\r
871\r
f4113e1f 872 FreePool (StringPtr);\r
c60a0616 873 return Status;\r
874 }\r
875\r
876 //\r
877 // Confirm new password\r
878 //\r
879 TempString = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
880 ASSERT (TempString);\r
881 Status = ReadString (MenuOption, gConfirmPassword, TempString);\r
882 if (EFI_ERROR (Status)) {\r
883 //\r
884 // Reset state machine for interactive password\r
885 //\r
886 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
887 PasswordCallback (Selection, MenuOption, NULL);\r
888 }\r
889\r
f4113e1f 890 FreePool (StringPtr);\r
891 FreePool (TempString);\r
c60a0616 892 return Status;\r
893 }\r
894\r
895 //\r
896 // Compare two typed-in new passwords\r
897 //\r
898 if (StrCmp (StringPtr, TempString) == 0) {\r
899 //\r
e2100bfa 900 // Prepare the Question->HiiValue.Value.string for ValidateQuestion use.\r
c60a0616 901 //\r
e2100bfa
ED
902 if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
903 StringId = Question->HiiValue.Value.string;\r
904 Question->HiiValue.Value.string = NewString (StringPtr, Selection->FormSet->HiiHandle);\r
c60a0616 905 } else {\r
e2100bfa
ED
906 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r
907 }\r
908 \r
909 Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
910\r
911 //\r
912 // Researve the Question->HiiValue.Value.string.\r
913 //\r
914 if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
915 DeleteString(Question->HiiValue.Value.string, Selection->FormSet->HiiHandle);\r
916 Question->HiiValue.Value.string = StringId;\r
917 } \r
918 \r
919 if (EFI_ERROR (Status)) {\r
920 //\r
921 // Reset state machine for interactive password\r
922 //\r
923 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
924 PasswordCallback (Selection, MenuOption, NULL);\r
925 } else {\r
926 //\r
927 // Researve the Question->HiiValue.Value.string.\r
928 //\r
929 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL); \r
930 }\r
931 } else {\r
932 //\r
933 // Two password match, send it to Configuration Driver\r
934 //\r
935 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
936 PasswordCallback (Selection, MenuOption, StringPtr);\r
937 } else {\r
938 CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
939 SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);\r
940 }\r
c60a0616 941 }\r
942 } else {\r
943 //\r
944 // Reset state machine for interactive password\r
945 //\r
946 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
947 PasswordCallback (Selection, MenuOption, NULL);\r
948 }\r
949\r
950 //\r
951 // Two password mismatch, prompt error message\r
952 //\r
953 do {\r
954 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gConfirmError, gPressEnter, gEmptyString);\r
955 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
956 }\r
957\r
f4113e1f 958 FreePool (TempString);\r
959 FreePool (StringPtr);\r
c60a0616 960 }\r
961 break;\r
962\r
963 default:\r
964 break;\r
965 }\r
966\r
967 return Status;\r
968}\r
969\r
970\r
971/**\r
972 Process the help string: Split StringPtr to several lines of strings stored in\r
973 FormattedString and the glyph width of each line cannot exceed gHelpBlockWidth.\r
974\r
975 @param StringPtr The entire help string.\r
976 @param FormattedString The oupput formatted string.\r
977 @param RowCount TRUE: if Question is selected.\r
978\r
979**/\r
980VOID\r
981ProcessHelpString (\r
982 IN CHAR16 *StringPtr,\r
983 OUT CHAR16 **FormattedString,\r
984 IN UINTN RowCount\r
985 )\r
986{\r
f4113e1f 987 UINTN BlockWidth;\r
c60a0616 988 UINTN AllocateSize;\r
989 //\r
990 // [PrevCurrIndex, CurrIndex) forms a range of a screen-line\r
991 //\r
992 UINTN CurrIndex;\r
993 UINTN PrevCurrIndex;\r
994 UINTN LineCount;\r
995 UINTN VirtualLineCount;\r
996 //\r
997 // GlyphOffset stores glyph width of current screen-line\r
998 //\r
999 UINTN GlyphOffset;\r
1000 //\r
1001 // GlyphWidth equals to 2 if we meet width directive\r
1002 //\r
1003 UINTN GlyphWidth;\r
1004 //\r
1005 // during scanning, we remember the position of last space character\r
1006 // in case that if next word cannot put in current line, we could restore back to the position\r
1007 // of last space character\r
1008 // while we should also remmeber the glyph width of the last space character for restoring\r
1009 //\r
1010 UINTN LastSpaceIndex;\r
1011 UINTN LastSpaceGlyphWidth;\r
1012 //\r
1013 // every time we begin to form a new screen-line, we should remember glyph width of single character\r
1014 // of last line\r
1015 //\r
1016 UINTN LineStartGlyphWidth;\r
1017 UINTN *IndexArray;\r
1018 UINTN *OldIndexArray;\r
1019\r
f4113e1f 1020 BlockWidth = (UINTN) gHelpBlockWidth - 1;\r
8b0fc5c1 1021\r
c60a0616 1022 //\r
1023 // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )\r
1024 // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want\r
1025 // to bring the width directive of the last line to current screen-line.\r
1026 // e.g.: "\wideabcde ... fghi", if "fghi" also has width directive but is splitted to the next screen-line\r
1027 // different from that of "\wideabcde", we should remember the width directive.\r
1028 //\r
1029 AllocateSize = 0x20;\r
1030 IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
40a06b0c 1031 ASSERT (IndexArray != NULL);\r
c60a0616 1032\r
1033 if (*FormattedString != NULL) {\r
f4113e1f 1034 FreePool (*FormattedString);\r
c60a0616 1035 *FormattedString = NULL;\r
1036 }\r
1037\r
1038 for (PrevCurrIndex = 0, CurrIndex = 0, LineCount = 0, LastSpaceIndex = 0,\r
1039 IndexArray[0] = 0, GlyphWidth = 1, GlyphOffset = 0, LastSpaceGlyphWidth = 1, LineStartGlyphWidth = 1;\r
1040 (StringPtr[CurrIndex] != CHAR_NULL);\r
1041 CurrIndex ++) {\r
1042\r
1043 if (LineCount == AllocateSize) {\r
1044 AllocateSize += 0x10;\r
1045 OldIndexArray = IndexArray;\r
1046 IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
bc166db3 1047 ASSERT (IndexArray != NULL);\r
8b0fc5c1 1048\r
c60a0616 1049 CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);\r
f4113e1f 1050 FreePool (OldIndexArray);\r
c60a0616 1051 }\r
1052 switch (StringPtr[CurrIndex]) {\r
1053\r
1054 case NARROW_CHAR:\r
1055 case WIDE_CHAR:\r
1056 GlyphWidth = ((StringPtr[CurrIndex] == WIDE_CHAR) ? 2 : 1);\r
1057 if (CurrIndex == 0) {\r
1058 LineStartGlyphWidth = GlyphWidth;\r
1059 }\r
1060 break;\r
1061\r
1062 //\r
1063 // char is '\n'\r
1064 // "\r\n" isn't handled here, handled by case CHAR_CARRIAGE_RETURN\r
1065 //\r
1066 case CHAR_LINEFEED:\r
1067 //\r
1068 // Store a range of string as a line\r
1069 //\r
1070 IndexArray[LineCount*3] = PrevCurrIndex;\r
1071 IndexArray[LineCount*3+1] = CurrIndex;\r
1072 IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
1073 LineCount ++;\r
1074 //\r
1075 // Reset offset and save begin position of line\r
1076 //\r
1077 GlyphOffset = 0;\r
1078 LineStartGlyphWidth = GlyphWidth;\r
1079 PrevCurrIndex = CurrIndex + 1;\r
1080 break;\r
1081\r
1082 //\r
1083 // char is '\r'\r
1084 // "\r\n" and "\r" both are handled here\r
1085 //\r
1086 case CHAR_CARRIAGE_RETURN:\r
1087 if (StringPtr[CurrIndex + 1] == CHAR_LINEFEED) {\r
1088 //\r
1089 // next char is '\n'\r
1090 //\r
1091 IndexArray[LineCount*3] = PrevCurrIndex;\r
1092 IndexArray[LineCount*3+1] = CurrIndex;\r
1093 IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
1094 LineCount ++;\r
1095 CurrIndex ++;\r
1096 }\r
1097 GlyphOffset = 0;\r
1098 LineStartGlyphWidth = GlyphWidth;\r
1099 PrevCurrIndex = CurrIndex + 1;\r
1100 break;\r
1101\r
1102 //\r
1103 // char is space or other char\r
1104 //\r
1105 default:\r
1106 GlyphOffset += GlyphWidth;\r
1107 if (GlyphOffset >= BlockWidth) {\r
1108 if (LastSpaceIndex > PrevCurrIndex) {\r
1109 //\r
1110 // LastSpaceIndex points to space inside current screen-line,\r
1111 // restore to LastSpaceIndex\r
1112 // (Otherwise the word is too long to fit one screen-line, just cut it)\r
1113 //\r
1114 CurrIndex = LastSpaceIndex;\r
1115 GlyphWidth = LastSpaceGlyphWidth;\r
1116 } else if (GlyphOffset > BlockWidth) {\r
1117 //\r
1118 // the word is too long to fit one screen-line and we don't get the chance\r
1119 // of GlyphOffset == BlockWidth because GlyphWidth = 2\r
1120 //\r
1121 CurrIndex --;\r
1122 }\r
1123\r
1124 IndexArray[LineCount*3] = PrevCurrIndex;\r
1125 IndexArray[LineCount*3+1] = CurrIndex + 1;\r
1126 IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
1127 LineStartGlyphWidth = GlyphWidth;\r
1128 LineCount ++;\r
1129 //\r
1130 // Reset offset and save begin position of line\r
1131 //\r
1132 GlyphOffset = 0;\r
1133 PrevCurrIndex = CurrIndex + 1;\r
1134 }\r
1135\r
1136 //\r
1137 // LastSpaceIndex: remember position of last space\r
1138 //\r
1139 if (StringPtr[CurrIndex] == CHAR_SPACE) {\r
1140 LastSpaceIndex = CurrIndex;\r
1141 LastSpaceGlyphWidth = GlyphWidth;\r
1142 }\r
1143 break;\r
1144 }\r
1145 }\r
1146\r
1147 if (GlyphOffset > 0) {\r
1148 IndexArray[LineCount*3] = PrevCurrIndex;\r
1149 IndexArray[LineCount*3+1] = CurrIndex;\r
1150 IndexArray[LineCount*3+2] = GlyphWidth;\r
1151 LineCount ++;\r
1152 }\r
1153\r
1154 if (LineCount == 0) {\r
1155 //\r
1156 // in case we meet null string\r
1157 //\r
1158 IndexArray[0] = 0;\r
1159 IndexArray[1] = 1;\r
1160 //\r
1161 // we assume null string's glyph width is 1\r
1162 //\r
1163 IndexArray[1] = 1;\r
1164 LineCount ++;\r
1165 }\r
1166\r
1167 VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));\r
1168 *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);\r
40a06b0c 1169 ASSERT (*FormattedString != NULL);\r
c60a0616 1170\r
1171 for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {\r
1172 *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16) ((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);\r
1173 StrnCpy (\r
1174 *FormattedString + CurrIndex * 2 * (BlockWidth + 1) + 1,\r
1175 StringPtr + IndexArray[CurrIndex*3],\r
1176 IndexArray[CurrIndex*3+1]-IndexArray[CurrIndex*3]\r
1177 );\r
1178 }\r
1179\r
f4113e1f 1180 FreePool (IndexArray);\r
c60a0616 1181}\r