2 Library Routines to create IFR on-the-fly
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
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.
16 // Include common header file for this module.
18 #include "IfrSupportLibInternal.h"
23 The form package is a collection of forms that are intended to describe the pages that will be
24 displayed to the user.
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
33 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
34 @retval EFI_SUCCESS Formset successfully created
38 IN CHAR16
*FormSetTitle
,
42 IN OUT VOID
**FormBuffer
,
43 IN OUT VOID
**StringBuffer
47 EFI_HII_IFR_PACK IfrPack
;
48 FRAMEWORK_EFI_IFR_FORM_SET FormSet
;
49 FRAMEWORK_EFI_IFR_END_FORM_SET EndFormSet
;
51 CHAR16 CurrentLanguage
[4];
52 STRING_REF StringToken
;
55 // Pre-allocate a buffer sufficient for us to work from.
57 FormBuffer
= AllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE
);
58 if (FormBuffer
== NULL
) {
59 return EFI_OUT_OF_RESOURCES
;
63 // Pre-allocate a buffer sufficient for us to work from.
65 StringBuffer
= AllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE
);
66 if (StringBuffer
== NULL
) {
67 gBS
->FreePool (FormBuffer
);
68 return EFI_OUT_OF_RESOURCES
;
72 // Obtain current language value
74 GetCurrentLanguage (CurrentLanguage
);
77 // Add the FormSetTitle to the string buffer and get the StringToken
79 Status
= AddString (*StringBuffer
, CurrentLanguage
, FormSetTitle
, &StringToken
);
81 if (EFI_ERROR (Status
)) {
86 // Initialize the Ifr Package header data
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
;
92 // Initialize FormSet with the appropriate information
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
));
102 // Initialize the end formset data
104 EndFormSet
.Header
.Length
= sizeof (FRAMEWORK_EFI_IFR_END_FORM_SET
);
105 EndFormSet
.Header
.OpCode
= FRAMEWORK_EFI_IFR_END_FORM_SET_OP
;
107 Destination
= (UINT8
*) *FormBuffer
;
110 // Copy the formset/endformset data to the form buffer
112 CopyMem (Destination
, &IfrPack
, sizeof (EFI_HII_PACK_HEADER
));
114 Destination
= Destination
+ sizeof (EFI_HII_PACK_HEADER
);
116 CopyMem (Destination
, &FormSet
, sizeof (FRAMEWORK_EFI_IFR_FORM_SET
));
118 Destination
= Destination
+ sizeof (FRAMEWORK_EFI_IFR_FORM_SET
);
120 CopyMem (Destination
, &EndFormSet
, sizeof (FRAMEWORK_EFI_IFR_END_FORM_SET
));
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
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
135 @retval EFI_SUCCESS Form successfully created
139 IN CHAR16
*FormTitle
,
141 IN OUT VOID
*FormBuffer
,
142 IN OUT VOID
*StringBuffer
146 FRAMEWORK_EFI_IFR_FORM Form
;
147 FRAMEWORK_EFI_IFR_END_FORM EndForm
;
148 CHAR16 CurrentLanguage
[4];
149 STRING_REF StringToken
;
152 // Obtain current language value
154 GetCurrentLanguage (CurrentLanguage
);
156 Status
= AddString (StringBuffer
, CurrentLanguage
, FormTitle
, &StringToken
);
158 if (EFI_ERROR (Status
)) {
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
;
167 Status
= AddOpCode (FormBuffer
, &Form
);
169 if (EFI_ERROR (Status
)) {
173 EndForm
.Header
.OpCode
= FRAMEWORK_EFI_IFR_END_FORM_OP
;
174 EndForm
.Header
.Length
= sizeof (FRAMEWORK_EFI_IFR_END_FORM
);
176 Status
= AddOpCode (FormBuffer
, &EndForm
);
184 Subtitle strings are intended to be used by authors to separate sections of questions into semantic
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
191 @retval EFI_SUCCESS Subtitle successfully created
196 IN OUT VOID
*FormBuffer
,
197 IN OUT VOID
*StringBuffer
201 FRAMEWORK_EFI_IFR_SUBTITLE Subtitle
;
202 CHAR16 CurrentLanguage
[4];
203 STRING_REF StringToken
;
206 // Obtain current language value
208 GetCurrentLanguage (CurrentLanguage
);
210 Status
= AddString (StringBuffer
, CurrentLanguage
, SubTitle
, &StringToken
);
212 if (EFI_ERROR (Status
)) {
216 Subtitle
.Header
.OpCode
= FRAMEWORK_EFI_IFR_SUBTITLE_OP
;
217 Subtitle
.Header
.Length
= sizeof (FRAMEWORK_EFI_IFR_SUBTITLE
);
218 Subtitle
.SubTitle
= StringToken
;
220 Status
= AddOpCode (FormBuffer
, &Subtitle
);
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.
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
238 @retval EFI_SUCCESS - Text successfully created
247 IN OUT VOID
*FormBuffer
,
248 IN OUT VOID
*StringBuffer
252 FRAMEWORK_EFI_IFR_TEXT Text
;
253 CHAR16 CurrentLanguage
[4];
254 STRING_REF StringToken
;
257 // Obtain current language value
259 GetCurrentLanguage (CurrentLanguage
);
262 // Add first string, get first string's token
264 Status
= AddString (StringBuffer
, CurrentLanguage
, String
, &StringToken
);
266 if (EFI_ERROR (Status
)) {
270 Text
.Header
.OpCode
= FRAMEWORK_EFI_IFR_TEXT_OP
;
271 Text
.Header
.Length
= sizeof (FRAMEWORK_EFI_IFR_TEXT
);
272 Text
.Text
= StringToken
;
275 // Add second string, get first string's token
277 Status
= AddString (StringBuffer
, CurrentLanguage
, String2
, &StringToken
);
279 if (EFI_ERROR (Status
)) {
283 Text
.TextTwo
= StringToken
;
285 Text
.Flags
= (UINT8
) (Flags
| FRAMEWORK_EFI_IFR_FLAG_CREATED
);
289 // Add second string, get first string's token
291 Status
= AddString (StringBuffer
, CurrentLanguage
, String3
, &StringToken
);
293 if (EFI_ERROR (Status
)) {
297 Text
.Help
= StringToken
;
299 Status
= AddOpCode (FormBuffer
, &Text
);
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
312 @retval EFI_SUCCESS Hyperlink successfully created
318 IN OUT VOID
*FormBuffer
,
319 IN OUT VOID
*StringBuffer
323 FRAMEWORK_EFI_IFR_REF Hyperlink
;
324 CHAR16 CurrentLanguage
[4];
325 STRING_REF StringToken
;
328 // Obtain current language value
330 GetCurrentLanguage (CurrentLanguage
);
332 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
334 if (EFI_ERROR (Status
)) {
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
;
343 Status
= AddOpCode (FormBuffer
, &Hyperlink
);
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.
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
361 @retval EFI_DEVICE_ERROR - DataWidth > 2
362 @retval EFI_SUCCESS - One-Of box successfully created.
366 IN UINT16 QuestionId
,
370 IN IFR_OPTION
*OptionsList
,
371 IN UINTN OptionCount
,
372 IN OUT VOID
*FormBuffer
,
373 IN OUT VOID
*StringBuffer
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
;
385 // We do not create op-code storage widths for one-of in excess of 16 bits for now
388 return EFI_DEVICE_ERROR
;
392 // Obtain current language value
394 GetCurrentLanguage (CurrentLanguage
);
397 // Add first string, get first string's token
399 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
401 if (EFI_ERROR (Status
)) {
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
;
412 // Add second string, get first string's token
414 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
416 if (EFI_ERROR (Status
)) {
420 OneOf
.Help
= StringToken
;
422 Status
= AddOpCode (FormBuffer
, &OneOf
);
424 if (EFI_ERROR (Status
)) {
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
);
433 // Add string and get token back
435 Status
= AddString (StringBuffer
, CurrentLanguage
, OptionsList
[Index
].OptionString
, &StringToken
);
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
;
442 Status
= AddOpCode (FormBuffer
, &OneOfOption
);
444 if (EFI_ERROR (Status
)) {
449 EndOneOf
.Header
.Length
= sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF
);
450 EndOneOf
.Header
.OpCode
= FRAMEWORK_EFI_IFR_END_ONE_OF_OP
;
452 Status
= AddOpCode (FormBuffer
, &EndOneOf
);
454 if (EFI_ERROR (Status
)) {
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.
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
474 @retval EFI_SUCCESS - Ordered list successfully created.
478 IN UINT16 QuestionId
,
482 IN IFR_OPTION
*OptionsList
,
483 IN UINTN OptionCount
,
484 IN OUT VOID
*FormBuffer
,
485 IN OUT VOID
*StringBuffer
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
;
497 // Obtain current language value
499 GetCurrentLanguage (CurrentLanguage
);
502 // Add first string, get first string's token
504 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
506 if (EFI_ERROR (Status
)) {
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
;
517 // Add second string, get first string's token
519 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
521 if (EFI_ERROR (Status
)) {
525 OrderedList
.Help
= StringToken
;
527 Status
= AddOpCode (FormBuffer
, &OrderedList
);
529 if (EFI_ERROR (Status
)) {
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
);
538 // Add string and get token back
540 Status
= AddString (StringBuffer
, CurrentLanguage
, OptionsList
[Index
].OptionString
, &StringToken
);
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
;
547 Status
= AddOpCode (FormBuffer
, &OrderedListOption
);
549 if (EFI_ERROR (Status
)) {
554 EndOrderedList
.Header
.Length
= sizeof (FRAMEWORK_EFI_IFR_END_ONE_OF
);
555 EndOrderedList
.Header
.OpCode
= FRAMEWORK_EFI_IFR_END_ONE_OF_OP
;
557 Status
= AddOpCode (FormBuffer
, &EndOrderedList
);
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.
573 @retval EFI_DEVICE_ERROR DataWidth > 1
574 @retval EFI_SUCCESS Check box successfully created
578 IN UINT16 QuestionId
,
583 IN OUT VOID
*FormBuffer
,
584 IN OUT VOID
*StringBuffer
588 FRAMEWORK_EFI_IFR_CHECKBOX CheckBox
;
589 CHAR16 CurrentLanguage
[4];
590 STRING_REF StringToken
;
593 // We do not create op-code storage widths for checkbox in excess of 8 bits for now
596 return EFI_DEVICE_ERROR
;
600 // Obtain current language value
602 GetCurrentLanguage (CurrentLanguage
);
605 // Add first string, get first string's token
607 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
609 if (EFI_ERROR (Status
)) {
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
;
620 // Add second string, get first string's token
622 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
624 if (EFI_ERROR (Status
)) {
628 CheckBox
.Help
= StringToken
;
629 CheckBox
.Flags
= (UINT8
) (Flags
| FRAMEWORK_EFI_IFR_FLAG_CREATED
);
631 Status
= AddOpCode (FormBuffer
, &CheckBox
);
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.
652 @retval EFI_DEVICE_ERROR DataWidth > 2
653 @retval EFI_SUCCESS Numeric is successfully created
657 IN UINT16 QuestionId
,
667 IN OUT VOID
*FormBuffer
,
668 IN OUT VOID
*StringBuffer
672 FRAMEWORK_EFI_IFR_NUMERIC Numeric
;
673 CHAR16 CurrentLanguage
[4];
674 STRING_REF StringToken
;
677 // We do not create op-code storage widths for numerics in excess of 16 bits for now
680 return EFI_DEVICE_ERROR
;
684 // Obtain current language value
686 GetCurrentLanguage (CurrentLanguage
);
689 // Add first string, get first string's token
691 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
693 if (EFI_ERROR (Status
)) {
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
;
704 // Add second string, get first string's token
706 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
708 if (EFI_ERROR (Status
)) {
712 Numeric
.Help
= StringToken
;
713 Numeric
.Minimum
= Minimum
;
714 Numeric
.Maximum
= Maximum
;
716 Numeric
.Default
= Default
;
717 Numeric
.Flags
= (UINT8
) (Flags
| FRAMEWORK_EFI_IFR_FLAG_CREATED
);
720 Status
= AddOpCode (FormBuffer
, &Numeric
);
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.
742 IN UINT16 QuestionId
,
750 IN OUT VOID
*FormBuffer
,
751 IN OUT VOID
*StringBuffer
755 FRAMEWORK_EFI_IFR_STRING String
;
756 CHAR16 CurrentLanguage
[4];
757 STRING_REF StringToken
;
760 // Obtain current language value
762 GetCurrentLanguage (CurrentLanguage
);
765 // Add first string, get first string's token
767 Status
= AddString (StringBuffer
, CurrentLanguage
, Prompt
, &StringToken
);
769 if (EFI_ERROR (Status
)) {
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
;
780 // Add second string, get first string's token
782 Status
= AddString (StringBuffer
, CurrentLanguage
, Help
, &StringToken
);
784 if (EFI_ERROR (Status
)) {
788 String
.Help
= StringToken
;
789 String
.MinSize
= MinSize
;
790 String
.MaxSize
= MaxSize
;
791 String
.Flags
= (UINT8
) (Flags
| FRAMEWORK_EFI_IFR_FLAG_CREATED
);
794 Status
= AddOpCode (FormBuffer
, &String
);