ee99bfafe4e90f8dd67872bd1e5e54c727e46945
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkIfrSupportLib / IfrOnTheFly.c
1 /*++
2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module Name:
12 IfrOnTheFly.c
13
14 Abstract:
15
16 Library Routines to create IFR on-the-fly
17
18 Revision History:
19
20 --*/
21
22 //
23 // Include common header file for this module.
24 //
25 #include "CommonHeader.h"
26
27 EFI_STATUS
28 CreateFormSet (
29 IN CHAR16 *FormSetTitle,
30 IN EFI_GUID *Guid,
31 IN UINT8 Class,
32 IN UINT8 SubClass,
33 IN OUT VOID **FormBuffer,
34 IN OUT VOID **StringBuffer
35 )
36 /*++
37
38 Routine Description:
39
40 Create a formset
41
42 Arguments:
43
44 FormSetTitle - Title of formset
45
46 Guid - Guid of formset
47
48 Class - Class of formset
49
50 SubClass - Sub class of formset
51
52 FormBuffer - Pointer of the formset created
53
54 StringBuffer - Pointer of FormSetTitile string created
55
56 Returns:
57
58 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
59
60 EFI_SUCCESS - Formset successfully created
61
62 --*/
63 {
64 EFI_STATUS Status;
65 EFI_HII_IFR_PACK IfrPack;
66 EFI_IFR_FORM_SET FormSet;
67 EFI_IFR_END_FORM_SET EndFormSet;
68 UINT8 *Destination;
69 CHAR16 CurrentLanguage[4];
70 STRING_REF StringToken;
71
72 //
73 // Pre-allocate a buffer sufficient for us to work from.
74 //
75 FormBuffer = AllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE);
76 if (FormBuffer == NULL) {
77 return EFI_OUT_OF_RESOURCES;
78 }
79
80 //
81 // Pre-allocate a buffer sufficient for us to work from.
82 //
83 StringBuffer = AllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE);
84 if (StringBuffer == NULL) {
85 gBS->FreePool (FormBuffer);
86 return EFI_OUT_OF_RESOURCES;
87 }
88
89 //
90 // Obtain current language value
91 //
92 GetCurrentLanguage (CurrentLanguage);
93
94 //
95 // Add the FormSetTitle to the string buffer and get the StringToken
96 //
97 Status = AddString (*StringBuffer, CurrentLanguage, FormSetTitle, &StringToken);
98
99 if (EFI_ERROR (Status)) {
100 return Status;
101 }
102
103 //
104 // Initialize the Ifr Package header data
105 //
106 IfrPack.Header.Length = sizeof (EFI_HII_PACK_HEADER) + sizeof (EFI_IFR_FORM_SET) + sizeof (EFI_IFR_END_FORM_SET);
107 IfrPack.Header.Type = EFI_HII_IFR;
108
109 //
110 // Initialize FormSet with the appropriate information
111 //
112 FormSet.Header.OpCode = EFI_IFR_FORM_SET_OP;
113 FormSet.Header.Length = sizeof (EFI_IFR_FORM_SET);
114 FormSet.FormSetTitle = StringToken;
115 FormSet.Class = Class;
116 FormSet.SubClass = SubClass;
117 CopyMem (&FormSet.Guid, Guid, sizeof (EFI_GUID));
118
119 //
120 // Initialize the end formset data
121 //
122 EndFormSet.Header.Length = sizeof (EFI_IFR_END_FORM_SET);
123 EndFormSet.Header.OpCode = EFI_IFR_END_FORM_SET_OP;
124
125 Destination = (UINT8 *) *FormBuffer;
126
127 //
128 // Copy the formset/endformset data to the form buffer
129 //
130 CopyMem (Destination, &IfrPack, sizeof (EFI_HII_PACK_HEADER));
131
132 Destination = Destination + sizeof (EFI_HII_PACK_HEADER);
133
134 CopyMem (Destination, &FormSet, sizeof (EFI_IFR_FORM_SET));
135
136 Destination = Destination + sizeof (EFI_IFR_FORM_SET);
137
138 CopyMem (Destination, &EndFormSet, sizeof (EFI_IFR_END_FORM_SET));
139 return EFI_SUCCESS;
140 }
141
142
143 EFI_STATUS
144 CreateForm (
145 IN CHAR16 *FormTitle,
146 IN UINT16 FormId,
147 IN OUT VOID *FormBuffer,
148 IN OUT VOID *StringBuffer
149 )
150 /*++
151
152 Routine Description:
153
154 Create a form
155
156 Arguments:
157
158 FormTitle - Title of the form
159
160 FormId - Id of the form
161
162 FormBuffer - Pointer of the form created
163
164 StringBuffer - Pointer of FormTitil string created
165
166 Returns:
167
168 EFI_SUCCESS - Form successfully created
169
170 --*/
171 {
172 EFI_STATUS Status;
173 EFI_IFR_FORM Form;
174 EFI_IFR_END_FORM EndForm;
175 CHAR16 CurrentLanguage[4];
176 STRING_REF StringToken;
177
178 //
179 // Obtain current language value
180 //
181 GetCurrentLanguage (CurrentLanguage);
182
183 Status = AddString (StringBuffer, CurrentLanguage, FormTitle, &StringToken);
184
185 if (EFI_ERROR (Status)) {
186 return Status;
187 }
188
189 Form.Header.OpCode = EFI_IFR_FORM_OP;
190 Form.Header.Length = sizeof (EFI_IFR_FORM);
191 Form.FormId = FormId;
192 Form.FormTitle = StringToken;
193
194 Status = AddOpCode (FormBuffer, &Form);
195
196 if (EFI_ERROR (Status)) {
197 return Status;
198 }
199
200 EndForm.Header.OpCode = EFI_IFR_END_FORM_OP;
201 EndForm.Header.Length = sizeof (EFI_IFR_END_FORM);
202
203 Status = AddOpCode (FormBuffer, &EndForm);
204
205 if (EFI_ERROR (Status)) {
206 return Status;
207 }
208
209 return EFI_SUCCESS;
210 }
211
212
213 EFI_STATUS
214 CreateSubTitle (
215 IN CHAR16 *SubTitle,
216 IN OUT VOID *FormBuffer,
217 IN OUT VOID *StringBuffer
218 )
219 /*++
220
221 Routine Description:
222
223 Create a SubTitle
224
225 Arguments:
226
227 SubTitle - Sub title to be created
228
229 FormBuffer - Where this subtitle to add to
230
231 StringBuffer - String buffer created for subtitle
232
233 Returns:
234
235 EFI_SUCCESS - Subtitle successfully created
236
237 --*/
238 {
239 EFI_STATUS Status;
240 EFI_IFR_SUBTITLE Subtitle;
241 CHAR16 CurrentLanguage[4];
242 STRING_REF StringToken;
243
244 //
245 // Obtain current language value
246 //
247 GetCurrentLanguage (CurrentLanguage);
248
249 Status = AddString (StringBuffer, CurrentLanguage, SubTitle, &StringToken);
250
251 if (EFI_ERROR (Status)) {
252 return Status;
253 }
254
255 Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
256 Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
257 Subtitle.SubTitle = StringToken;
258
259 Status = AddOpCode (FormBuffer, &Subtitle);
260
261 if (EFI_ERROR (Status)) {
262 return Status;
263 }
264
265 return EFI_SUCCESS;
266 }
267
268
269 EFI_STATUS
270 CreateText (
271 IN CHAR16 *String,
272 IN CHAR16 *String2,
273 IN CHAR16 *String3,
274 IN UINT8 Flags,
275 IN UINT16 Key,
276 IN OUT VOID *FormBuffer,
277 IN OUT VOID *StringBuffer
278 )
279 /*++
280
281 Routine Description:
282
283 Create a line of text
284
285 Arguments:
286
287 String - First string of the text
288
289 String2 - Second string of the text
290
291 String3 - Help string of the text
292
293 Flags - Flag of the text
294
295 Key - Key of the text
296
297 FormBuffer - The form where this text adds to
298
299 StringBuffer - String buffer created for String, String2 and String3
300
301 Returns:
302
303 EFI_SUCCESS - Text successfully created
304
305 --*/
306 {
307 EFI_STATUS Status;
308 EFI_IFR_TEXT Text;
309 CHAR16 CurrentLanguage[4];
310 STRING_REF StringToken;
311
312 //
313 // Obtain current language value
314 //
315 GetCurrentLanguage (CurrentLanguage);
316
317 //
318 // Add first string, get first string's token
319 //
320 Status = AddString (StringBuffer, CurrentLanguage, String, &StringToken);
321
322 if (EFI_ERROR (Status)) {
323 return Status;
324 }
325
326 Text.Header.OpCode = EFI_IFR_TEXT_OP;
327 Text.Header.Length = sizeof (EFI_IFR_TEXT);
328 Text.Text = StringToken;
329
330 //
331 // Add second string, get first string's token
332 //
333 Status = AddString (StringBuffer, CurrentLanguage, String2, &StringToken);
334
335 if (EFI_ERROR (Status)) {
336 return Status;
337 }
338
339 Text.TextTwo = StringToken;
340
341 Text.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
342 Text.Key = Key;
343
344 //
345 // Add second string, get first string's token
346 //
347 Status = AddString (StringBuffer, CurrentLanguage, String3, &StringToken);
348
349 if (EFI_ERROR (Status)) {
350 return Status;
351 }
352
353 Text.Help = StringToken;
354
355 Status = AddOpCode (FormBuffer, &Text);
356
357 if (EFI_ERROR (Status)) {
358 return Status;
359 }
360
361 return EFI_SUCCESS;
362 }
363
364
365 EFI_STATUS
366 CreateGoto (
367 IN UINT16 FormId,
368 IN CHAR16 *Prompt,
369 IN OUT VOID *FormBuffer,
370 IN OUT VOID *StringBuffer
371 )
372 /*++
373
374 Routine Description:
375
376 Create a hyperlink
377
378 Arguments:
379
380 FormId - Form ID of the hyperlink
381
382 Prompt - Prompt of the hyperlink
383
384 FormBuffer - The form where this hyperlink adds to
385
386 StringBuffer - String buffer created for Prompt
387
388 Returns:
389
390 EFI_SUCCESS - Hyperlink successfully created
391
392 --*/
393 {
394 EFI_STATUS Status;
395 EFI_IFR_REF Hyperlink;
396 CHAR16 CurrentLanguage[4];
397 STRING_REF StringToken;
398
399 //
400 // Obtain current language value
401 //
402 GetCurrentLanguage (CurrentLanguage);
403
404 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
405
406 if (EFI_ERROR (Status)) {
407 return Status;
408 }
409
410 Hyperlink.Header.OpCode = EFI_IFR_REF_OP;
411 Hyperlink.Header.Length = sizeof (EFI_IFR_REF);
412 Hyperlink.FormId = FormId;
413 Hyperlink.Prompt = StringToken;
414
415 Status = AddOpCode (FormBuffer, &Hyperlink);
416
417 if (EFI_ERROR (Status)) {
418 return Status;
419 }
420
421 return EFI_SUCCESS;
422 }
423
424
425 EFI_STATUS
426 CreateOneOf (
427 IN UINT16 QuestionId,
428 IN UINT8 DataWidth,
429 IN CHAR16 *Prompt,
430 IN CHAR16 *Help,
431 IN IFR_OPTION *OptionsList,
432 IN UINTN OptionCount,
433 IN OUT VOID *FormBuffer,
434 IN OUT VOID *StringBuffer
435 )
436 /*++
437
438 Routine Description:
439
440 Create a one-of question with a set of options to choose from. The
441 OptionsList is a pointer to a null-terminated list of option descriptions.
442
443 Arguments:
444
445 QuestionId - Question ID of the one-of box
446
447 DataWidth - DataWidth of the one-of box
448
449 Prompt - Prompt of the one-of box
450
451 Help - Help of the one-of box
452
453 OptionsList - Each string in it is an option of the one-of box
454
455 OptionCount - Option string count
456
457 FormBuffer - The form where this one-of box adds to
458
459 StringBuffer - String buffer created for Prompt, Help and Option strings
460
461 Returns:
462
463 EFI_DEVICE_ERROR - DataWidth > 2
464
465 EFI_SUCCESS - One-Of box successfully created.
466
467 --*/
468 {
469 EFI_STATUS Status;
470 UINTN Index;
471 EFI_IFR_ONE_OF OneOf;
472 EFI_IFR_ONE_OF_OPTION OneOfOption;
473 EFI_IFR_END_ONE_OF EndOneOf;
474 CHAR16 CurrentLanguage[4];
475 STRING_REF StringToken;
476
477 //
478 // We do not create op-code storage widths for one-of in excess of 16 bits for now
479 //
480 if (DataWidth > 2) {
481 return EFI_DEVICE_ERROR;
482 }
483
484 //
485 // Obtain current language value
486 //
487 GetCurrentLanguage (CurrentLanguage);
488
489 //
490 // Add first string, get first string's token
491 //
492 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
493
494 if (EFI_ERROR (Status)) {
495 return Status;
496 }
497
498 OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;
499 OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);
500 OneOf.QuestionId = QuestionId;
501 OneOf.Width = DataWidth;
502 OneOf.Prompt = StringToken;
503
504 //
505 // Add second string, get first string's token
506 //
507 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
508
509 if (EFI_ERROR (Status)) {
510 return Status;
511 }
512
513 OneOf.Help = StringToken;
514
515 Status = AddOpCode (FormBuffer, &OneOf);
516
517 if (EFI_ERROR (Status)) {
518 return Status;
519 }
520
521 for (Index = 0; Index < OptionCount; Index++) {
522 OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
523 OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
524
525 //
526 // Add string and get token back
527 //
528 Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
529
530 OneOfOption.Option = StringToken;
531 OneOfOption.Value = OptionsList[Index].Value;
532 OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);
533 OneOfOption.Key = OptionsList[Index].Key;
534
535 Status = AddOpCode (FormBuffer, &OneOfOption);
536
537 if (EFI_ERROR (Status)) {
538 return Status;
539 }
540 }
541
542 EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
543 EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
544
545 Status = AddOpCode (FormBuffer, &EndOneOf);
546
547 if (EFI_ERROR (Status)) {
548 return Status;
549 }
550
551 return EFI_SUCCESS;
552 }
553
554 EFI_STATUS
555 CreateOrderedList (
556 IN UINT16 QuestionId,
557 IN UINT8 MaxEntries,
558 IN CHAR16 *Prompt,
559 IN CHAR16 *Help,
560 IN IFR_OPTION *OptionsList,
561 IN UINTN OptionCount,
562 IN OUT VOID *FormBuffer,
563 IN OUT VOID *StringBuffer
564 )
565 /*++
566
567 Routine Description:
568
569 Create a one-of question with a set of options to choose from. The
570 OptionsList is a pointer to a null-terminated list of option descriptions.
571
572 Arguments:
573
574 QuestionId - Question ID of the ordered list
575
576 MaxEntries - MaxEntries of the ordered list
577
578 Prompt - Prompt of the ordered list
579
580 Help - Help of the ordered list
581
582 OptionsList - Each string in it is an option of the ordered list
583
584 OptionCount - Option string count
585
586 FormBuffer - The form where this ordered list adds to
587
588 StringBuffer - String buffer created for Prompt, Help and Option strings
589
590 Returns:
591
592 EFI_SUCCESS - Ordered list successfully created.
593
594 --*/
595 {
596 EFI_STATUS Status;
597 UINTN Index;
598 EFI_IFR_ORDERED_LIST OrderedList;
599 EFI_IFR_ONE_OF_OPTION OrderedListOption;
600 EFI_IFR_END_ONE_OF EndOrderedList;
601 CHAR16 CurrentLanguage[4];
602 STRING_REF StringToken;
603
604 //
605 // Obtain current language value
606 //
607 GetCurrentLanguage (CurrentLanguage);
608
609 //
610 // Add first string, get first string's token
611 //
612 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
613
614 if (EFI_ERROR (Status)) {
615 return Status;
616 }
617
618 OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;
619 OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);
620 OrderedList.QuestionId = QuestionId;
621 OrderedList.MaxEntries = MaxEntries;
622 OrderedList.Prompt = StringToken;
623
624 //
625 // Add second string, get first string's token
626 //
627 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
628
629 if (EFI_ERROR (Status)) {
630 return Status;
631 }
632
633 OrderedList.Help = StringToken;
634
635 Status = AddOpCode (FormBuffer, &OrderedList);
636
637 if (EFI_ERROR (Status)) {
638 return Status;
639 }
640
641 for (Index = 0; Index < OptionCount; Index++) {
642 OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
643 OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
644
645 //
646 // Add string and get token back
647 //
648 Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
649
650 OrderedListOption.Option = StringToken;
651 OrderedListOption.Value = OptionsList[Index].Value;
652 OrderedListOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);
653 OrderedListOption.Key = OptionsList[Index].Key;
654
655 Status = AddOpCode (FormBuffer, &OrderedListOption);
656
657 if (EFI_ERROR (Status)) {
658 return Status;
659 }
660 }
661
662 EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
663 EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
664
665 Status = AddOpCode (FormBuffer, &EndOrderedList);
666
667 if (EFI_ERROR (Status)) {
668 return Status;
669 }
670
671 return EFI_SUCCESS;
672 }
673
674
675 EFI_STATUS
676 CreateCheckBox (
677 IN UINT16 QuestionId,
678 IN UINT8 DataWidth,
679 IN CHAR16 *Prompt,
680 IN CHAR16 *Help,
681 IN UINT8 Flags,
682 IN OUT VOID *FormBuffer,
683 IN OUT VOID *StringBuffer
684 )
685 /*++
686
687 Routine Description:
688
689 Create a checkbox
690
691 Arguments:
692
693 QuestionId - Question ID of the check box
694
695 DataWidth - DataWidth of the check box
696
697 Prompt - Prompt of the check box
698
699 Help - Help of the check box
700
701 Flags - Flags of the check box
702
703 FormBuffer - The form where this check box adds to
704
705 StringBuffer - String buffer created for Prompt and Help.
706
707 Returns:
708
709 EFI_DEVICE_ERROR - DataWidth > 1
710
711 EFI_SUCCESS - Check box successfully created
712
713 --*/
714 {
715 EFI_STATUS Status;
716 EFI_IFR_CHECKBOX CheckBox;
717 CHAR16 CurrentLanguage[4];
718 STRING_REF StringToken;
719
720 //
721 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
722 //
723 if (DataWidth > 1) {
724 return EFI_DEVICE_ERROR;
725 }
726
727 //
728 // Obtain current language value
729 //
730 GetCurrentLanguage (CurrentLanguage);
731
732 //
733 // Add first string, get first string's token
734 //
735 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
736
737 if (EFI_ERROR (Status)) {
738 return Status;
739 }
740
741 CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;
742 CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX);
743 CheckBox.QuestionId = QuestionId;
744 CheckBox.Width = DataWidth;
745 CheckBox.Prompt = StringToken;
746
747 //
748 // Add second string, get first string's token
749 //
750 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
751
752 if (EFI_ERROR (Status)) {
753 return Status;
754 }
755
756 CheckBox.Help = StringToken;
757 CheckBox.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
758
759 Status = AddOpCode (FormBuffer, &CheckBox);
760
761 if (EFI_ERROR (Status)) {
762 return Status;
763 }
764
765 return EFI_SUCCESS;
766 }
767
768
769 EFI_STATUS
770 CreateNumeric (
771 IN UINT16 QuestionId,
772 IN UINT8 DataWidth,
773 IN CHAR16 *Prompt,
774 IN CHAR16 *Help,
775 IN UINT16 Minimum,
776 IN UINT16 Maximum,
777 IN UINT16 Step,
778 IN UINT16 Default,
779 IN UINT8 Flags,
780 IN UINT16 Key,
781 IN OUT VOID *FormBuffer,
782 IN OUT VOID *StringBuffer
783 )
784 /*++
785
786 Routine Description:
787
788 Create a numeric
789
790 Arguments:
791
792 QuestionId - Question ID of the numeric
793
794 DataWidth - DataWidth of the numeric
795
796 Prompt - Prompt of the numeric
797
798 Help - Help of the numeric
799
800 Minimum - Minumun boundary of the numeric
801
802 Maximum - Maximum boundary of the numeric
803
804 Step - Step of the numeric
805
806 Default - Default value
807
808 Flags - Flags of the numeric
809
810 Key - Key of the numeric
811
812 FormBuffer - The form where this numeric adds to
813
814 StringBuffer - String buffer created for Prompt and Help.
815
816 Returns:
817
818 EFI_DEVICE_ERROR - DataWidth > 2
819
820 EFI_SUCCESS - Numeric is successfully created
821
822 --*/
823 {
824 EFI_STATUS Status;
825 EFI_IFR_NUMERIC Numeric;
826 CHAR16 CurrentLanguage[4];
827 STRING_REF StringToken;
828
829 //
830 // We do not create op-code storage widths for numerics in excess of 16 bits for now
831 //
832 if (DataWidth > 2) {
833 return EFI_DEVICE_ERROR;
834 }
835
836 //
837 // Obtain current language value
838 //
839 GetCurrentLanguage (CurrentLanguage);
840
841 //
842 // Add first string, get first string's token
843 //
844 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
845
846 if (EFI_ERROR (Status)) {
847 return Status;
848 }
849
850 Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;
851 Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);
852 Numeric.QuestionId = QuestionId;
853 Numeric.Width = DataWidth;
854 Numeric.Prompt = StringToken;
855
856 //
857 // Add second string, get first string's token
858 //
859 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
860
861 if (EFI_ERROR (Status)) {
862 return Status;
863 }
864
865 Numeric.Help = StringToken;
866 Numeric.Minimum = Minimum;
867 Numeric.Maximum = Maximum;
868 Numeric.Step = Step;
869 Numeric.Default = Default;
870 Numeric.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
871 Numeric.Key = Key;
872
873 Status = AddOpCode (FormBuffer, &Numeric);
874
875 if (EFI_ERROR (Status)) {
876 return Status;
877 }
878
879 return EFI_SUCCESS;
880 }
881
882
883 EFI_STATUS
884 CreateString (
885 IN UINT16 QuestionId,
886 IN UINT8 DataWidth,
887 IN CHAR16 *Prompt,
888 IN CHAR16 *Help,
889 IN UINT8 MinSize,
890 IN UINT8 MaxSize,
891 IN UINT8 Flags,
892 IN UINT16 Key,
893 IN OUT VOID *FormBuffer,
894 IN OUT VOID *StringBuffer
895 )
896 /*++
897
898 Routine Description:
899
900 Create a string
901
902 Arguments:
903
904 QuestionId - Question ID of the string
905
906 DataWidth - DataWidth of the string
907
908 Prompt - Prompt of the string
909
910 Help - Help of the string
911
912 MinSize - Min size boundary of the string
913
914 MaxSize - Max size boundary of the string
915
916 Flags - Flags of the string
917
918 Key - Key of the string
919
920 FormBuffer - The form where this string adds to
921
922 StringBuffer - String buffer created for Prompt and Help.
923
924 Returns:
925
926 EFI_SUCCESS - String successfully created.
927
928 --*/
929 {
930 EFI_STATUS Status;
931 EFI_IFR_STRING String;
932 CHAR16 CurrentLanguage[4];
933 STRING_REF StringToken;
934
935 //
936 // Obtain current language value
937 //
938 GetCurrentLanguage (CurrentLanguage);
939
940 //
941 // Add first string, get first string's token
942 //
943 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
944
945 if (EFI_ERROR (Status)) {
946 return Status;
947 }
948
949 String.Header.OpCode = EFI_IFR_STRING_OP;
950 String.Header.Length = sizeof (EFI_IFR_STRING);
951 String.QuestionId = QuestionId;
952 String.Width = DataWidth;
953 String.Prompt = StringToken;
954
955 //
956 // Add second string, get first string's token
957 //
958 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
959
960 if (EFI_ERROR (Status)) {
961 return Status;
962 }
963
964 String.Help = StringToken;
965 String.MinSize = MinSize;
966 String.MaxSize = MaxSize;
967 String.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
968 String.Key = Key;
969
970 Status = AddOpCode (FormBuffer, &String);
971
972 if (EFI_ERROR (Status)) {
973 return Status;
974 }
975
976 return EFI_SUCCESS;
977 }