]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/IfrSupportLib.h
follow up the comments from code review.
[mirror_edk2.git] / MdePkg / Include / Library / IfrSupportLib.h
1 /** @file
2 The file contain all library functions and definitions for IFR opcode creation and
3 related Form Browser utility Operations.
4
5 Copyright (c) 2007 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _IFR_SUPPORT_LIBRARY_H_
17 #define _IFR_SUPPORT_LIBRARY_H_
18
19
20 #include <Protocol/HiiFont.h>
21 #include <Protocol/HiiImage.h>
22 #include <Protocol/HiiString.h>
23 #include <Protocol/HiiDatabase.h>
24 #include <Protocol/HiiConfigRouting.h>
25 #include <Protocol/HiiConfigAccess.h>
26 #include <Protocol/FormBrowser2.h>
27 #include <Protocol/SimpleTextOut.h>
28
29 #include <Guid/GlobalVariable.h>
30
31 //
32 // The architectural variable "Lang" and "LangCodes" are deprecated in UEFI
33 // specification. While, UEFI specification also states that these deprecated
34 // variables may be provided for backwards compatibility.
35
36 #define EFI_LANGUAGE_VARIABLE L"Lang"
37 #define EFI_LANGUAGE_CODES_VARIABLE L"LangCodes"
38
39 #define UEFI_LANGUAGE_VARIABLE L"PlatformLang"
40 #define UEFI_LANGUAGE_CODES_VARIABLE L"PlatformLangCodes"
41
42 ///
43 /// Limited buffer size recommended by RFC3066
44 /// (42 characters plus a NULL terminator)
45 ///
46 #define RFC_3066_ENTRY_SIZE (42 + 1)
47 #define ISO_639_2_ENTRY_SIZE 3
48
49 #define INVALID_VARSTORE_ID 0
50
51 #define QUESTION_FLAGS (EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY)
52 #define QUESTION_FLAGS_MASK (~QUESTION_FLAGS)
53
54 #pragma pack(1)
55 typedef struct {
56 EFI_STRING_ID StringToken;
57 EFI_IFR_TYPE_VALUE Value;
58 UINT8 Flags;
59 } IFR_OPTION;
60 #pragma pack()
61
62 typedef struct {
63 ///
64 /// Buffer size allocated for Data.
65 ///
66 UINT32 BufferSize;
67
68 ///
69 /// Offset in Data to append the newly created opcode binary.
70 /// It will be adjusted automatically in Create***OpCode(), and should be
71 /// initialized to 0 before invocation of a serial of Create***OpCode()
72 ///
73 UINT32 Offset;
74
75 ///
76 /// The destination buffer for created op-codes
77 ///
78 UINT8 *Data;
79 } EFI_HII_UPDATE_DATA;
80
81
82 /**
83 Create EFI_IFR_END_OP opcode.
84
85 If Data is NULL or Data->Data is NULL, then ASSERT.
86
87 @param Data Destination for the created opcode binary
88
89 @retval EFI_SUCCESS Opcode create success
90 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 CreateEndOpCode (
96 IN OUT EFI_HII_UPDATE_DATA *Data
97 )
98 ;
99
100 /**
101 Create EFI_IFR_DEFAULT_OP opcode.
102
103 @param Value Value for the default
104 @param Type Type for the default
105 @param Data Destination for the created opcode binary
106
107 @retval EFI_SUCCESS Opcode create success
108 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
109 @retval EFI_INVALID_PARAMETER The type is not valid.
110
111 **/
112 EFI_STATUS
113 EFIAPI
114 CreateDefaultOpCode (
115 IN EFI_IFR_TYPE_VALUE *Value,
116 IN UINT8 Type,
117 IN OUT EFI_HII_UPDATE_DATA *Data
118 )
119 ;
120
121 /**
122 Create EFI_IFR_ACTION_OP opcode.
123
124 @param QuestionId Question ID
125 @param Prompt String ID for Prompt
126 @param Help String ID for Help
127 @param QuestionFlags Flags in Question Header
128 @param QuestionConfig String ID for configuration
129 @param Data Destination for the created opcode binary
130
131 @retval EFI_SUCCESS Opcode create success
132 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
133 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
134
135 **/
136 EFI_STATUS
137 EFIAPI
138 CreateActionOpCode (
139 IN EFI_QUESTION_ID QuestionId,
140 IN EFI_STRING_ID Prompt,
141 IN EFI_STRING_ID Help,
142 IN UINT8 QuestionFlags,
143 IN EFI_STRING_ID QuestionConfig,
144 IN OUT EFI_HII_UPDATE_DATA *Data
145 )
146 ;
147
148 /**
149 Create EFI_IFR_SUBTITLE_OP opcode.
150
151 @param Prompt String ID for Prompt
152 @param Help String ID for Help
153 @param Flags Subtitle opcode flags
154 @param Scope Subtitle Scope bit
155 @param Data Destination for the created opcode binary
156
157 @retval EFI_SUCCESS Opcode create success
158 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
159
160 **/
161 EFI_STATUS
162 EFIAPI
163 CreateSubTitleOpCode (
164 IN EFI_STRING_ID Prompt,
165 IN EFI_STRING_ID Help,
166 IN UINT8 Flags,
167 IN UINT8 Scope,
168 IN OUT EFI_HII_UPDATE_DATA *Data
169 )
170 ;
171
172 /**
173 Create EFI_IFR_TEXT_OP opcode.
174
175 @param Prompt String ID for Prompt
176 @param Help String ID for Help
177 @param TextTwo String ID for text two
178 @param Data Destination for the created opcode binary
179
180 @retval EFI_SUCCESS Opcode create success
181 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
182
183 **/
184 EFI_STATUS
185 EFIAPI
186 CreateTextOpCode (
187 IN EFI_STRING_ID Prompt,
188 IN EFI_STRING_ID Help,
189 IN EFI_STRING_ID TextTwo,
190 IN OUT EFI_HII_UPDATE_DATA *Data
191 )
192 ;
193
194 /**
195 Create EFI_IFR_REF_OP opcode.
196
197 @param FormId Destination Form ID
198 @param Prompt String ID for Prompt
199 @param Help String ID for Help
200 @param QuestionFlags Flags in Question Header
201 @param QuestionId Question ID
202 @param Data Destination for the created opcode binary
203
204 @retval EFI_SUCCESS Opcode create success
205 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
206 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
207
208 **/
209 EFI_STATUS
210 EFIAPI
211 CreateGotoOpCode (
212 IN EFI_FORM_ID FormId,
213 IN EFI_STRING_ID Prompt,
214 IN EFI_STRING_ID Help,
215 IN UINT8 QuestionFlags,
216 IN EFI_QUESTION_ID QuestionId,
217 IN OUT EFI_HII_UPDATE_DATA *Data
218 )
219 ;
220
221 /**
222 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
223
224 @param OptionCount The number of options.
225 @param OptionsList The list of Options.
226 @param Type The data type.
227 @param Data Destination for the created opcode binary
228
229 @retval EFI_SUCCESS Opcode create success
230 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
231
232 **/
233 EFI_STATUS
234 EFIAPI
235 CreateOneOfOptionOpCode (
236 IN UINTN OptionCount,
237 IN IFR_OPTION *OptionsList,
238 IN UINT8 Type,
239 IN OUT EFI_HII_UPDATE_DATA *Data
240 )
241 ;
242
243 /**
244 Create EFI_IFR_ONE_OF_OP opcode.
245
246 @param QuestionId Question ID
247 @param VarStoreId Storage ID
248 @param VarOffset Offset in Storage
249 @param Prompt String ID for Prompt
250 @param Help String ID for Help
251 @param QuestionFlags Flags in Question Header
252 @param OneOfFlags Flags for oneof opcode
253 @param OptionsList List of options
254 @param OptionCount Number of options in option list
255 @param Data Destination for the created opcode binary
256
257 @retval EFI_SUCCESS Opcode create success
258 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
259 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
260
261 **/
262 EFI_STATUS
263 EFIAPI
264 CreateOneOfOpCode (
265 IN EFI_QUESTION_ID QuestionId,
266 IN EFI_VARSTORE_ID VarStoreId,
267 IN UINT16 VarOffset,
268 IN EFI_STRING_ID Prompt,
269 IN EFI_STRING_ID Help,
270 IN UINT8 QuestionFlags,
271 IN UINT8 OneOfFlags,
272 IN IFR_OPTION *OptionsList,
273 IN UINTN OptionCount,
274 IN OUT EFI_HII_UPDATE_DATA *Data
275 )
276 ;
277
278 /**
279 Create EFI_IFR_ORDERED_LIST_OP opcode.
280
281 @param QuestionId Question ID
282 @param VarStoreId Storage ID
283 @param VarOffset Offset in Storage
284 @param Prompt String ID for Prompt
285 @param Help String ID for Help
286 @param QuestionFlags Flags in Question Header
287 @param OrderedListFlags Flags for ordered list opcode
288 @param DataType Type for option value
289 @param MaxContainers Maximum count for options in this ordered list
290 @param OptionsList List of options
291 @param OptionCount Number of options in option list
292 @param Data Destination for the created opcode binary
293
294 @retval EFI_SUCCESS Opcode create success
295 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
296 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
297
298 **/
299 EFI_STATUS
300 EFIAPI
301 CreateOrderedListOpCode (
302 IN EFI_QUESTION_ID QuestionId,
303 IN EFI_VARSTORE_ID VarStoreId,
304 IN UINT16 VarOffset,
305 IN EFI_STRING_ID Prompt,
306 IN EFI_STRING_ID Help,
307 IN UINT8 QuestionFlags,
308 IN UINT8 OrderedListFlags,
309 IN UINT8 DataType,
310 IN UINT8 MaxContainers,
311 IN IFR_OPTION *OptionsList,
312 IN UINTN OptionCount,
313 IN OUT EFI_HII_UPDATE_DATA *Data
314 )
315 ;
316
317 /**
318 Create EFI_IFR_CHECKBOX_OP opcode.
319
320 @param QuestionId Question ID
321 @param VarStoreId Storage ID
322 @param VarOffset Offset in Storage
323 @param Prompt String ID for Prompt
324 @param Help String ID for Help
325 @param QuestionFlags Flags in Question Header
326 @param CheckBoxFlags Flags for checkbox opcode
327 @param Data Destination for the created opcode binary
328
329 @retval EFI_SUCCESS Opcode create success
330 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
331 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
332
333 **/
334 EFI_STATUS
335 EFIAPI
336 CreateCheckBoxOpCode (
337 IN EFI_QUESTION_ID QuestionId,
338 IN EFI_VARSTORE_ID VarStoreId,
339 IN UINT16 VarOffset,
340 IN EFI_STRING_ID Prompt,
341 IN EFI_STRING_ID Help,
342 IN UINT8 QuestionFlags,
343 IN UINT8 CheckBoxFlags,
344 IN OUT EFI_HII_UPDATE_DATA *Data
345 )
346 ;
347
348 /**
349 Create EFI_IFR_NUMERIC_OP opcode.
350
351 @param QuestionId Question ID
352 @param VarStoreId Storage ID
353 @param VarOffset Offset in Storage
354 @param Prompt String ID for Prompt
355 @param Help String ID for Help
356 @param QuestionFlags Flags in Question Header
357 @param NumericFlags Flags for numeric opcode
358 @param Minimum Numeric minimum value
359 @param Maximum Numeric maximum value
360 @param Step Numeric step for edit
361 @param Default Numeric default value
362 @param Data Destination for the created opcode binary
363
364 @retval EFI_SUCCESS Opcode create success
365 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
366 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
367
368 **/
369 EFI_STATUS
370 EFIAPI
371 CreateNumericOpCode (
372 IN EFI_QUESTION_ID QuestionId,
373 IN EFI_VARSTORE_ID VarStoreId,
374 IN UINT16 VarOffset,
375 IN EFI_STRING_ID Prompt,
376 IN EFI_STRING_ID Help,
377 IN UINT8 QuestionFlags,
378 IN UINT8 NumericFlags,
379 IN UINT64 Minimum,
380 IN UINT64 Maximum,
381 IN UINT64 Step,
382 IN UINT64 Default,
383 IN OUT EFI_HII_UPDATE_DATA *Data
384 )
385 ;
386
387 /**
388 Create EFI_IFR_STRING_OP opcode.
389
390 @param QuestionId Question ID
391 @param VarStoreId Storage ID
392 @param VarOffset Offset in Storage
393 @param Prompt String ID for Prompt
394 @param Help String ID for Help
395 @param QuestionFlags Flags in Question Header
396 @param StringFlags Flags for string opcode
397 @param MinSize String minimum length
398 @param MaxSize String maximum length
399 @param Data Destination for the created opcode binary
400
401 @retval EFI_SUCCESS Opcode create success
402 @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small.
403 @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid.
404
405 **/
406 EFI_STATUS
407 EFIAPI
408 CreateStringOpCode (
409 IN EFI_QUESTION_ID QuestionId,
410 IN EFI_VARSTORE_ID VarStoreId,
411 IN UINT16 VarOffset,
412 IN EFI_STRING_ID Prompt,
413 IN EFI_STRING_ID Help,
414 IN UINT8 QuestionFlags,
415 IN UINT8 StringFlags,
416 IN UINT8 MinSize,
417 IN UINT8 MaxSize,
418 IN OUT EFI_HII_UPDATE_DATA *Data
419 )
420 ;
421
422 /**
423 Converts the unicode character of the string from uppercase to lowercase.
424
425 @param Str String to be converted
426
427
428 **/
429 VOID
430 EFIAPI
431 ToLower (
432 IN OUT CHAR16 *Str
433 )
434 ;
435
436 /**
437 Converts binary buffer to Unicode string in reversed byte order to BufToHexString().
438
439 @param Str String for output
440 @param Buffer Binary buffer.
441 @param BufferSize Size of the buffer in bytes.
442
443 @retval EFI_SUCCESS The function completed successfully.
444
445 **/
446 EFI_STATUS
447 EFIAPI
448 BufferToHexString (
449 IN OUT CHAR16 *Str,
450 IN UINT8 *Buffer,
451 IN UINTN BufferSize
452 )
453 ;
454
455 /**
456 Converts Hex String to binary buffer in reversed byte order to HexStringToBuf().
457
458 @param Buffer Pointer to buffer that receives the data.
459 @param BufferSize Length in bytes of the buffer to hold converted
460 data. If routine return with EFI_SUCCESS,
461 containing length of converted data. If routine
462 return with EFI_BUFFER_TOO_SMALL, containg length
463 of buffer desired.
464 @param Str String to be converted from.
465
466 @retval EFI_SUCCESS The function completed successfully.
467
468 **/
469 EFI_STATUS
470 EFIAPI
471 HexStringToBuffer (
472 IN OUT UINT8 *Buffer,
473 IN OUT UINTN *BufferSize,
474 IN CHAR16 *Str
475 )
476 ;
477
478 /**
479 Convert binary representation Config string (e.g. "0041004200430044") to the
480 original string (e.g. "ABCD"). Config string appears in <ConfigHdr> (i.e.
481 "&NAME=<string>"), or Name/Value pair in <ConfigBody> (i.e. "label=<string>").
482
483 @param UnicodeString Original Unicode string.
484 @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string.
485 Includes tailing '\0' character.
486 On output:
487 If return EFI_SUCCESS, containing length of Unicode string buffer.
488 If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.
489 @param ConfigString Binary representation of Unicode String, <string> := (<HexCh>4)+
490
491 @retval EFI_SUCCESS Routine success.
492 @retval EFI_BUFFER_TOO_SMALL The string buffer is too small.
493
494 **/
495 EFI_STATUS
496 EFIAPI
497 ConfigStringToUnicode (
498 IN OUT CHAR16 *UnicodeString,
499 IN OUT UINTN *StrBufferLen,
500 IN CHAR16 *ConfigString
501 )
502 ;
503
504 /**
505 Convert Unicode string to binary representation Config string, e.g.
506 "ABCD" => "0041004200430044". Config string appears in <ConfigHdr> (i.e.
507 "&NAME=<string>"), or Name/Value pair in <ConfigBody> (i.e. "label=<string>").
508
509 @param ConfigString Binary representation of Unicode String, <string> := (<HexCh>4)+
510 @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string.
511 Includes tailing '\0' character.
512 On output:
513 If return EFI_SUCCESS, containing length of Unicode string buffer.
514 If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.
515 @param UnicodeString Original Unicode string.
516
517 @retval EFI_SUCCESS Routine success.
518 @retval EFI_BUFFER_TOO_SMALL The string buffer is too small.
519
520 **/
521 EFI_STATUS
522 EFIAPI
523 UnicodeToConfigString (
524 IN OUT CHAR16 *ConfigString,
525 IN OUT UINTN *StrBufferLen,
526 IN CHAR16 *UnicodeString
527 )
528 ;
529
530 /**
531 Construct <ConfigHdr> using routing information GUID/NAME/PATH.
532
533 @param ConfigHdr Pointer to the ConfigHdr string.
534 @param StrBufferLen On input: Length in bytes of buffer to hold the
535 ConfigHdr string. Includes tailing '\0' character.
536 On output: If return EFI_SUCCESS, containing
537 length of ConfigHdr string buffer. If return
538 EFI_BUFFER_TOO_SMALL, containg length of string
539 buffer desired.
540 @param Guid Routing information: GUID.
541 @param Name Routing information: NAME.
542 @param DriverHandle Driver handle which contains the routing
543 information: PATH.
544
545 @retval EFI_SUCCESS Routine success.
546 @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small.
547
548 **/
549 EFI_STATUS
550 EFIAPI
551 ConstructConfigHdr (
552 IN OUT CHAR16 *ConfigHdr,
553 IN OUT UINTN *StrBufferLen,
554 IN CONST EFI_GUID *Guid,
555 IN CHAR16 *Name, OPTIONAL
556 IN EFI_HANDLE *DriverHandle
557 )
558
559 ;
560
561 /**
562 Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string.
563
564 @param String The string to be searched in.
565 @param Offset Offset in BlockName.
566 @param Width Width in BlockName.
567
568 @retval TRUE Block name found.
569 @retval FALSE Block name not found.
570
571 **/
572 BOOLEAN
573 EFIAPI
574 FindBlockName (
575 IN OUT CHAR16 *String,
576 IN UINTN Offset,
577 IN UINTN Width
578 )
579 ;
580
581 /**
582 This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser.
583
584 @param VariableGuid An optional field to indicate the target variable
585 GUID name to use.
586 @param VariableName An optional field to indicate the target
587 human-readable variable name.
588 @param BufferSize On input: Length in bytes of buffer to hold
589 retrived data. On output: If return
590 EFI_BUFFER_TOO_SMALL, containg length of buffer
591 desired.
592 @param Buffer Buffer to hold retrived data.
593
594 @retval EFI_SUCCESS Routine success.
595 @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small.
596
597 **/
598 EFI_STATUS
599 EFIAPI
600 GetBrowserData (
601 IN CONST EFI_GUID *VariableGuid, OPTIONAL
602 IN CONST CHAR16 *VariableName, OPTIONAL
603 IN OUT UINTN *BufferSize,
604 IN OUT UINT8 *Buffer
605 )
606 ;
607
608 /**
609 This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser.
610
611 @param VariableGuid An optional field to indicate the target variable
612 GUID name to use.
613 @param VariableName An optional field to indicate the target
614 human-readable variable name.
615 @param BufferSize Length in bytes of buffer to hold retrived data.
616 @param Buffer Buffer to hold retrived data.
617 @param RequestElement An optional field to specify which part of the
618 buffer data will be send back to Browser. If NULL,
619 the whole buffer of data will be committed to
620 Browser. <RequestElement> ::=
621 &OFFSET=<Number>&WIDTH=<Number>*
622
623 @retval EFI_SUCCESS Routine success.
624 @retval Other Updating Browser uncommitted data failed.
625
626 **/
627 EFI_STATUS
628 EFIAPI
629 SetBrowserData (
630 IN CONST EFI_GUID *VariableGuid, OPTIONAL
631 IN CONST CHAR16 *VariableName, OPTIONAL
632 IN UINTN BufferSize,
633 IN CONST UINT8 *Buffer,
634 IN CONST CHAR16 *RequestElement OPTIONAL
635 )
636 ;
637
638 /**
639 Draw a dialog and return the selected key.
640
641 @param NumberOfLines The number of lines for the dialog box
642 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
643 @param String Pointer to the first string in the list
644 @param ... A series of (quantity == NumberOfLines - 1) text
645 strings which will be used to construct the dialog
646 box
647
648 @retval EFI_SUCCESS Displayed dialog and received user interaction
649 @retval EFI_INVALID_PARAMETER One of the parameters was invalid.
650
651 **/
652 EFI_STATUS
653 EFIAPI
654 IfrLibCreatePopUp (
655 IN UINTN NumberOfLines,
656 OUT EFI_INPUT_KEY *KeyValue,
657 IN CHAR16 *String,
658 ...
659 )
660 ;
661
662 /**
663 Draw a dialog and return the selected key using Variable Argument List.
664
665 @param NumberOfLines The number of lines for the dialog box
666 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
667 @param String Pointer to the first string in the list
668 @param Args VA_LIST marker for the variable argument list.
669 A series of (quantity == NumberOfLines - 1) text
670 strings which will be used to construct the dialog
671 box
672
673 @retval EFI_SUCCESS Displayed dialog and received user interaction
674 @retval EFI_INVALID_PARAMETER One of the parameters was invalid.
675
676 **/
677 EFI_STATUS
678 EFIAPI
679 IfrLibCreatePopUp2 (
680 IN UINTN NumberOfLines,
681 OUT EFI_INPUT_KEY *KeyValue,
682 IN VA_LIST Args
683 )
684 ;
685
686 #endif