]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkIfrSupportLib/IfrOnTheFly.c
Fix coding style issue.
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkIfrSupportLib / IfrOnTheFly.c
1 /** @file
2 Library Routines to create IFR on-the-fly
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 //
16 // Include common header file for this module.
17 //
18 #include "IfrSupportLibInternal.h"
19
20 /**
21 Create a formset
22
23 The form package is a collection of forms that are intended to describe the pages that will be
24 displayed to the user.
25
26 @param FormSetTitle Title of formset
27 @param Guid Guid of formset
28 @param Class Class of formset
29 @param SubClass Sub class of formset
30 @param FormBuffer Pointer of the formset created
31 @param StringBuffer Pointer of FormSetTitile string created
32
33 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
34 @retval EFI_SUCCESS Formset successfully created
35 **/
36 EFI_STATUS
37 CreateFormSet (
38 IN CHAR16 *FormSetTitle,
39 IN EFI_GUID *Guid,
40 IN UINT8 Class,
41 IN UINT8 SubClass,
42 IN OUT VOID **FormBuffer,
43 IN OUT VOID **StringBuffer
44 )
45 {
46 EFI_STATUS Status;
47 EFI_HII_IFR_PACK IfrPack;
48 FRAMEWORK_EFI_IFR_FORM_SET FormSet;
49 FRAMEWORK_EFI_IFR_END_FORM_SET EndFormSet;
50 UINT8 *Destination;
51 CHAR16 CurrentLanguage[4];
52 STRING_REF StringToken;
53
54 //
55 // Pre-allocate a buffer sufficient for us to work from.
56 //
57 FormBuffer = AllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE);
58 if (FormBuffer == NULL) {
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 //
63 // Pre-allocate a buffer sufficient for us to work from.
64 //
65 StringBuffer = AllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE);
66 if (StringBuffer == NULL) {
67 gBS->FreePool (FormBuffer);
68 return EFI_OUT_OF_RESOURCES;
69 }
70
71 //
72 // Obtain current language value
73 //
74 GetCurrentLanguage (CurrentLanguage);
75
76 //
77 // Add the FormSetTitle to the string buffer and get the StringToken
78 //
79 Status = AddString (*StringBuffer, CurrentLanguage, FormSetTitle, &StringToken);
80
81 if (EFI_ERROR (Status)) {
82 return Status;
83 }
84
85 //
86 // Initialize the Ifr Package header data
87 //
88 IfrPack.Header.Length = sizeof (EFI_HII_PACK_HEADER) + sizeof (FRAMEWORK_EFI_IFR_FORM_SET) + sizeof (FRAMEWORK_EFI_IFR_END_FORM_SET);
89 IfrPack.Header.Type = EFI_HII_IFR;
90
91 //
92 // Initialize FormSet with the appropriate information
93 //
94 FormSet.Header.OpCode = FRAMEWORK_EFI_IFR_FORM_SET_OP;
95 FormSet.Header.Length = sizeof (FRAMEWORK_EFI_IFR_FORM_SET);
96 FormSet.FormSetTitle = StringToken;
97 FormSet.Class = Class;
98 FormSet.SubClass = SubClass;
99 CopyMem (&FormSet.Guid, Guid, sizeof (EFI_GUID));
100
101 //
102 // Initialize the end formset data
103 //
104 EndFormSet.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_FORM_SET);
105 EndFormSet.Header.OpCode = FRAMEWORK_EFI_IFR_END_FORM_SET_OP;
106
107 Destination = (UINT8 *) *FormBuffer;
108
109 //
110 // Copy the formset/endformset data to the form buffer
111 //
112 CopyMem (Destination, &IfrPack, sizeof (EFI_HII_PACK_HEADER));
113
114 Destination = Destination + sizeof (EFI_HII_PACK_HEADER);
115
116 CopyMem (Destination, &FormSet, sizeof (FRAMEWORK_EFI_IFR_FORM_SET));
117
118 Destination = Destination + sizeof (FRAMEWORK_EFI_IFR_FORM_SET);
119
120 CopyMem (Destination, &EndFormSet, sizeof (FRAMEWORK_EFI_IFR_END_FORM_SET));
121 return EFI_SUCCESS;
122 }
123
124 /**
125 Create a form
126 A form is the encapsulation of what amounts to a browser page. The header defines a FormId,
127 which is referenced by the form package, among others. It also defines a FormTitle, which is a
128 string to be used as the title for the form
129
130 @param FormTitle Title of the form
131 @param FormId Id of the form
132 @param FormBuffer Pointer of the form created
133 @param StringBuffer Pointer of FormTitil string created
134
135 @retval EFI_SUCCESS Form successfully created
136 **/
137 EFI_STATUS
138 CreateForm (
139 IN CHAR16 *FormTitle,
140 IN UINT16 FormId,
141 IN OUT VOID *FormBuffer,
142 IN OUT VOID *StringBuffer
143 )
144 {
145 EFI_STATUS Status;
146 FRAMEWORK_EFI_IFR_FORM Form;
147 FRAMEWORK_EFI_IFR_END_FORM EndForm;
148 CHAR16 CurrentLanguage[4];
149 STRING_REF StringToken;
150
151 //
152 // Obtain current language value
153 //
154 GetCurrentLanguage (CurrentLanguage);
155
156 Status = AddString (StringBuffer, CurrentLanguage, FormTitle, &StringToken);
157
158 if (EFI_ERROR (Status)) {
159 return Status;
160 }
161
162 Form.Header.OpCode = FRAMEWORK_EFI_IFR_FORM_OP;
163 Form.Header.Length = sizeof (FRAMEWORK_EFI_IFR_FORM);
164 Form.FormId = FormId;
165 Form.FormTitle = StringToken;
166
167 Status = AddOpCode (FormBuffer, &Form);
168
169 if (EFI_ERROR (Status)) {
170 return Status;
171 }
172
173 EndForm.Header.OpCode = FRAMEWORK_EFI_IFR_END_FORM_OP;
174 EndForm.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_FORM);
175
176 Status = AddOpCode (FormBuffer, &EndForm);
177
178 return Status;
179 }
180
181 /**
182 Create a SubTitle
183
184 Subtitle strings are intended to be used by authors to separate sections of questions into semantic
185 groups.
186
187 @param SubTitle Sub title to be created
188 @param FormBuffer Where this subtitle to add to
189 @param StringBuffer String buffer created for subtitle
190
191 @retval EFI_SUCCESS Subtitle successfully created
192 **/
193 EFI_STATUS
194 CreateSubTitle (
195 IN CHAR16 *SubTitle,
196 IN OUT VOID *FormBuffer,
197 IN OUT VOID *StringBuffer
198 )
199 {
200 EFI_STATUS Status;
201 FRAMEWORK_EFI_IFR_SUBTITLE Subtitle;
202 CHAR16 CurrentLanguage[4];
203 STRING_REF StringToken;
204
205 //
206 // Obtain current language value
207 //
208 GetCurrentLanguage (CurrentLanguage);
209
210 Status = AddString (StringBuffer, CurrentLanguage, SubTitle, &StringToken);
211
212 if (EFI_ERROR (Status)) {
213 return Status;
214 }
215
216 Subtitle.Header.OpCode = FRAMEWORK_EFI_IFR_SUBTITLE_OP;
217 Subtitle.Header.Length = sizeof (FRAMEWORK_EFI_IFR_SUBTITLE);
218 Subtitle.SubTitle = StringToken;
219
220 Status = AddOpCode (FormBuffer, &Subtitle);
221
222 return Status;
223 }
224
225 /**
226 Create a line of text
227 Unlike HTML, text is simply another tag.
228 This tag type enables IFR to be more easily localized.
229
230 @param String - First string of the text
231 @param String2 - Second string of the text
232 @param String3 - Help string of the text
233 @param Flags - Flag of the text
234 @param Key - Key of the text
235 @param FormBuffer - The form where this text adds to
236 @param StringBuffer - String buffer created for String, String2 and String3
237
238 @retval EFI_SUCCESS - Text successfully created
239 **/
240 EFI_STATUS
241 CreateText (
242 IN CHAR16 *String,
243 IN CHAR16 *String2,
244 IN CHAR16 *String3,
245 IN UINT8 Flags,
246 IN UINT16 Key,
247 IN OUT VOID *FormBuffer,
248 IN OUT VOID *StringBuffer
249 )
250 {
251 EFI_STATUS Status;
252 FRAMEWORK_EFI_IFR_TEXT Text;
253 CHAR16 CurrentLanguage[4];
254 STRING_REF StringToken;
255
256 //
257 // Obtain current language value
258 //
259 GetCurrentLanguage (CurrentLanguage);
260
261 //
262 // Add first string, get first string's token
263 //
264 Status = AddString (StringBuffer, CurrentLanguage, String, &StringToken);
265
266 if (EFI_ERROR (Status)) {
267 return Status;
268 }
269
270 Text.Header.OpCode = FRAMEWORK_EFI_IFR_TEXT_OP;
271 Text.Header.Length = sizeof (FRAMEWORK_EFI_IFR_TEXT);
272 Text.Text = StringToken;
273
274 //
275 // Add second string, get first string's token
276 //
277 Status = AddString (StringBuffer, CurrentLanguage, String2, &StringToken);
278
279 if (EFI_ERROR (Status)) {
280 return Status;
281 }
282
283 Text.TextTwo = StringToken;
284
285 Text.Flags = (UINT8) (Flags | FRAMEWORK_EFI_IFR_FLAG_CREATED);
286 Text.Key = Key;
287
288 //
289 // Add second string, get first string's token
290 //
291 Status = AddString (StringBuffer, CurrentLanguage, String3, &StringToken);
292
293 if (EFI_ERROR (Status)) {
294 return Status;
295 }
296
297 Text.Help = StringToken;
298
299 Status = AddOpCode (FormBuffer, &Text);
300
301 return Status;
302 }
303
304 /**
305 Create a hyperlink
306
307 @param FormId Form ID of the hyperlink
308 @param Prompt Prompt of the hyperlink
309 @param FormBuffer The form where this hyperlink adds to
310 @param StringBuffer String buffer created for Prompt
311
312 @retval EFI_SUCCESS Hyperlink successfully created
313 **/
314 EFI_STATUS
315 CreateGoto (
316 IN UINT16 FormId,
317 IN CHAR16 *Prompt,
318 IN OUT VOID *FormBuffer,
319 IN OUT VOID *StringBuffer
320 )
321 {
322 EFI_STATUS Status;
323 FRAMEWORK_EFI_IFR_REF Hyperlink;
324 CHAR16 CurrentLanguage[4];
325 STRING_REF StringToken;
326
327 //
328 // Obtain current language value
329 //
330 GetCurrentLanguage (CurrentLanguage);
331
332 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
333
334 if (EFI_ERROR (Status)) {
335 return Status;
336 }
337
338 Hyperlink.Header.OpCode = FRAMEWORK_EFI_IFR_REF_OP;
339 Hyperlink.Header.Length = sizeof (FRAMEWORK_EFI_IFR_REF);
340 Hyperlink.FormId = FormId;
341 Hyperlink.Prompt = StringToken;
342
343 Status = AddOpCode (FormBuffer, &Hyperlink);
344
345 return Status;
346 }
347
348 /**
349 Create a one-of question with a set of options to choose from. The
350 OptionsList is a pointer to a null-terminated list of option descriptions.
351
352 @param QuestionId - Question ID of the one-of box
353 @param DataWidth - DataWidth of the one-of box
354 @param Prompt - Prompt of the one-of box
355 @param Help - Help of the one-of box
356 @param OptionsList - Each string in it is an option of the one-of box
357 @param OptionCount - Option string count
358 @param FormBuffer - The form where this one-of box adds to
359 @param StringBuffer - String buffer created for Prompt, Help and Option strings
360
361 @retval EFI_DEVICE_ERROR - DataWidth > 2
362 @retval EFI_SUCCESS - One-Of box successfully created.
363 **/
364 EFI_STATUS
365 CreateOneOf (
366 IN UINT16 QuestionId,
367 IN UINT8 DataWidth,
368 IN CHAR16 *Prompt,
369 IN CHAR16 *Help,
370 IN IFR_OPTION *OptionsList,
371 IN UINTN OptionCount,
372 IN OUT VOID *FormBuffer,
373 IN OUT VOID *StringBuffer
374 )
375 {
376 EFI_STATUS Status;
377 UINTN Index;
378 FRAMEWORK_EFI_IFR_ONE_OF OneOf;
379 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OneOfOption;
380 FRAMEWORK_EFI_IFR_END_ONE_OF EndOneOf;
381 CHAR16 CurrentLanguage[4];
382 STRING_REF StringToken;
383
384 //
385 // We do not create op-code storage widths for one-of in excess of 16 bits for now
386 //
387 if (DataWidth > 2) {
388 return EFI_DEVICE_ERROR;
389 }
390
391 //
392 // Obtain current language value
393 //
394 GetCurrentLanguage (CurrentLanguage);
395
396 //
397 // Add first string, get first string's token
398 //
399 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
400
401 if (EFI_ERROR (Status)) {
402 return Status;
403 }
404
405 OneOf.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OP;
406 OneOf.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF);
407 OneOf.QuestionId = QuestionId;
408 OneOf.Width = DataWidth;
409 OneOf.Prompt = StringToken;
410
411 //
412 // Add second string, get first string's token
413 //
414 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
415
416 if (EFI_ERROR (Status)) {
417 return Status;
418 }
419
420 OneOf.Help = StringToken;
421
422 Status = AddOpCode (FormBuffer, &OneOf);
423
424 if (EFI_ERROR (Status)) {
425 return Status;
426 }
427
428 for (Index = 0; Index < OptionCount; Index++) {
429 OneOfOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
430 OneOfOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
431
432 //
433 // Add string and get token back
434 //
435 Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
436
437 OneOfOption.Option = StringToken;
438 OneOfOption.Value = OptionsList[Index].Value;
439 OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags | FRAMEWORK_EFI_IFR_FLAG_CREATED);
440 OneOfOption.Key = OptionsList[Index].Key;
441
442 Status = AddOpCode (FormBuffer, &OneOfOption);
443
444 if (EFI_ERROR (Status)) {
445 return Status;
446 }
447 }
448
449 EndOneOf.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
450 EndOneOf.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
451
452 Status = AddOpCode (FormBuffer, &EndOneOf);
453
454 if (EFI_ERROR (Status)) {
455 return Status;
456 }
457
458 return EFI_SUCCESS;
459 }
460
461 /**
462 Create a one-of question with a set of options to choose from. The
463 OptionsList is a pointer to a null-terminated list of option descriptions.
464
465 @param QuestionId - Question ID of the ordered list
466 @param MaxEntries - MaxEntries of the ordered list
467 @param Prompt - Prompt of the ordered list
468 @param Help - Help of the ordered list
469 @param OptionsList - Each string in it is an option of the ordered list
470 @param OptionCount - Option string count
471 @param FormBuffer - The form where this ordered list adds to
472 @param StringBuffer - String buffer created for Prompt, Help and Option strings
473
474 @retval EFI_SUCCESS - Ordered list successfully created.
475 **/
476 EFI_STATUS
477 CreateOrderedList (
478 IN UINT16 QuestionId,
479 IN UINT8 MaxEntries,
480 IN CHAR16 *Prompt,
481 IN CHAR16 *Help,
482 IN IFR_OPTION *OptionsList,
483 IN UINTN OptionCount,
484 IN OUT VOID *FormBuffer,
485 IN OUT VOID *StringBuffer
486 )
487 {
488 EFI_STATUS Status;
489 UINTN Index;
490 FRAMEWORK_EFI_IFR_ORDERED_LIST OrderedList;
491 FRAMEWORK_EFI_IFR_ONE_OF_OPTION OrderedListOption;
492 FRAMEWORK_EFI_IFR_END_ONE_OF EndOrderedList;
493 CHAR16 CurrentLanguage[4];
494 STRING_REF StringToken;
495
496 //
497 // Obtain current language value
498 //
499 GetCurrentLanguage (CurrentLanguage);
500
501 //
502 // Add first string, get first string's token
503 //
504 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
505
506 if (EFI_ERROR (Status)) {
507 return Status;
508 }
509
510 OrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_ORDERED_LIST_OP;
511 OrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ORDERED_LIST);
512 OrderedList.QuestionId = QuestionId;
513 OrderedList.MaxEntries = MaxEntries;
514 OrderedList.Prompt = StringToken;
515
516 //
517 // Add second string, get first string's token
518 //
519 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
520
521 if (EFI_ERROR (Status)) {
522 return Status;
523 }
524
525 OrderedList.Help = StringToken;
526
527 Status = AddOpCode (FormBuffer, &OrderedList);
528
529 if (EFI_ERROR (Status)) {
530 return Status;
531 }
532
533 for (Index = 0; Index < OptionCount; Index++) {
534 OrderedListOption.Header.OpCode = FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP;
535 OrderedListOption.Header.Length = sizeof (FRAMEWORK_EFI_IFR_ONE_OF_OPTION);
536
537 //
538 // Add string and get token back
539 //
540 Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
541
542 OrderedListOption.Option = StringToken;
543 OrderedListOption.Value = OptionsList[Index].Value;
544 OrderedListOption.Flags = (UINT8) (OptionsList[Index].Flags | FRAMEWORK_EFI_IFR_FLAG_CREATED);
545 OrderedListOption.Key = OptionsList[Index].Key;
546
547 Status = AddOpCode (FormBuffer, &OrderedListOption);
548
549 if (EFI_ERROR (Status)) {
550 return Status;
551 }
552 }
553
554 EndOrderedList.Header.Length = sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF);
555 EndOrderedList.Header.OpCode = FRAMEWORK_EFI_IFR_END_ONE_OF_OP;
556
557 Status = AddOpCode (FormBuffer, &EndOrderedList);
558
559 return Status;
560 }
561
562 /**
563 Create a checkbox
564
565 @param QuestionId Question ID of the check box
566 @param DataWidth DataWidth of the check box
567 @param Prompt Prompt of the check box
568 @param Help Help of the check box
569 @param Flags Flags of the check box
570 @param FormBuffer The form where this check box adds to
571 @param StringBuffer String buffer created for Prompt and Help.
572
573 @retval EFI_DEVICE_ERROR DataWidth > 1
574 @retval EFI_SUCCESS Check box successfully created
575 **/
576 EFI_STATUS
577 CreateCheckBox (
578 IN UINT16 QuestionId,
579 IN UINT8 DataWidth,
580 IN CHAR16 *Prompt,
581 IN CHAR16 *Help,
582 IN UINT8 Flags,
583 IN OUT VOID *FormBuffer,
584 IN OUT VOID *StringBuffer
585 )
586 {
587 EFI_STATUS Status;
588 FRAMEWORK_EFI_IFR_CHECKBOX CheckBox;
589 CHAR16 CurrentLanguage[4];
590 STRING_REF StringToken;
591
592 //
593 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
594 //
595 if (DataWidth > 1) {
596 return EFI_DEVICE_ERROR;
597 }
598
599 //
600 // Obtain current language value
601 //
602 GetCurrentLanguage (CurrentLanguage);
603
604 //
605 // Add first string, get first string's token
606 //
607 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
608
609 if (EFI_ERROR (Status)) {
610 return Status;
611 }
612
613 CheckBox.Header.OpCode = FRAMEWORK_EFI_IFR_CHECKBOX_OP;
614 CheckBox.Header.Length = sizeof (FRAMEWORK_EFI_IFR_CHECKBOX);
615 CheckBox.QuestionId = QuestionId;
616 CheckBox.Width = DataWidth;
617 CheckBox.Prompt = StringToken;
618
619 //
620 // Add second string, get first string's token
621 //
622 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
623
624 if (EFI_ERROR (Status)) {
625 return Status;
626 }
627
628 CheckBox.Help = StringToken;
629 CheckBox.Flags = (UINT8) (Flags | FRAMEWORK_EFI_IFR_FLAG_CREATED);
630
631 Status = AddOpCode (FormBuffer, &CheckBox);
632
633 return Status;
634 }
635
636 /**
637 Create a numeric
638
639 @param QuestionId Question ID of the numeric
640 @param DataWidth DataWidth of the numeric
641 @param Prompt Prompt of the numeric
642 @param Help Help of the numeric
643 @param Minimum Minumun boundary of the numeric
644 @param Maximum Maximum boundary of the numeric
645 @param Step Step of the numeric
646 @param Default Default value
647 @param Flags Flags of the numeric
648 @param Key Key of the numeric
649 @param FormBuffer The form where this numeric adds to
650 @param StringBuffer String buffer created for Prompt and Help.
651
652 @retval EFI_DEVICE_ERROR DataWidth > 2
653 @retval EFI_SUCCESS Numeric is successfully created
654 **/
655 EFI_STATUS
656 CreateNumeric (
657 IN UINT16 QuestionId,
658 IN UINT8 DataWidth,
659 IN CHAR16 *Prompt,
660 IN CHAR16 *Help,
661 IN UINT16 Minimum,
662 IN UINT16 Maximum,
663 IN UINT16 Step,
664 IN UINT16 Default,
665 IN UINT8 Flags,
666 IN UINT16 Key,
667 IN OUT VOID *FormBuffer,
668 IN OUT VOID *StringBuffer
669 )
670 {
671 EFI_STATUS Status;
672 FRAMEWORK_EFI_IFR_NUMERIC Numeric;
673 CHAR16 CurrentLanguage[4];
674 STRING_REF StringToken;
675
676 //
677 // We do not create op-code storage widths for numerics in excess of 16 bits for now
678 //
679 if (DataWidth > 2) {
680 return EFI_DEVICE_ERROR;
681 }
682
683 //
684 // Obtain current language value
685 //
686 GetCurrentLanguage (CurrentLanguage);
687
688 //
689 // Add first string, get first string's token
690 //
691 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
692
693 if (EFI_ERROR (Status)) {
694 return Status;
695 }
696
697 Numeric.Header.OpCode = FRAMEWORK_EFI_IFR_NUMERIC_OP;
698 Numeric.Header.Length = sizeof (FRAMEWORK_EFI_IFR_NUMERIC);
699 Numeric.QuestionId = QuestionId;
700 Numeric.Width = DataWidth;
701 Numeric.Prompt = StringToken;
702
703 //
704 // Add second string, get first string's token
705 //
706 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
707
708 if (EFI_ERROR (Status)) {
709 return Status;
710 }
711
712 Numeric.Help = StringToken;
713 Numeric.Minimum = Minimum;
714 Numeric.Maximum = Maximum;
715 Numeric.Step = Step;
716 Numeric.Default = Default;
717 Numeric.Flags = (UINT8) (Flags | FRAMEWORK_EFI_IFR_FLAG_CREATED);
718 Numeric.Key = Key;
719
720 Status = AddOpCode (FormBuffer, &Numeric);
721
722 return Status;
723 }
724
725 /**
726 Create a string
727
728 @param QuestionId - Question ID of the string
729 @param DataWidth - DataWidth of the string
730 @param Prompt - Prompt of the string
731 @param Help - Help of the string
732 @param MinSize - Min size boundary of the string
733 @param MaxSize - Max size boundary of the string
734 @param Flags - Flags of the string
735 @param Key - Key of the string
736 @param FormBuffer - The form where this string adds to
737 @param StringBuffer - String buffer created for Prompt and Help.
738 @retval EFI_SUCCESS - String successfully created.
739 **/
740 EFI_STATUS
741 CreateString (
742 IN UINT16 QuestionId,
743 IN UINT8 DataWidth,
744 IN CHAR16 *Prompt,
745 IN CHAR16 *Help,
746 IN UINT8 MinSize,
747 IN UINT8 MaxSize,
748 IN UINT8 Flags,
749 IN UINT16 Key,
750 IN OUT VOID *FormBuffer,
751 IN OUT VOID *StringBuffer
752 )
753 {
754 EFI_STATUS Status;
755 FRAMEWORK_EFI_IFR_STRING String;
756 CHAR16 CurrentLanguage[4];
757 STRING_REF StringToken;
758
759 //
760 // Obtain current language value
761 //
762 GetCurrentLanguage (CurrentLanguage);
763
764 //
765 // Add first string, get first string's token
766 //
767 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
768
769 if (EFI_ERROR (Status)) {
770 return Status;
771 }
772
773 String.Header.OpCode = FRAMEWORK_EFI_IFR_STRING_OP;
774 String.Header.Length = sizeof (FRAMEWORK_EFI_IFR_STRING);
775 String.QuestionId = QuestionId;
776 String.Width = DataWidth;
777 String.Prompt = StringToken;
778
779 //
780 // Add second string, get first string's token
781 //
782 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
783
784 if (EFI_ERROR (Status)) {
785 return Status;
786 }
787
788 String.Help = StringToken;
789 String.MinSize = MinSize;
790 String.MaxSize = MaxSize;
791 String.Flags = (UINT8) (Flags | FRAMEWORK_EFI_IFR_FLAG_CREATED);
792 String.Key = Key;
793
794 Status = AddOpCode (FormBuffer, &String);
795
796 return Status;
797 }
798