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