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