3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The file contain all library function for Ifr Operations.
26 #include <Protocol/HiiFont.h>
27 #include <Protocol/HiiImage.h>
28 #include <Protocol/HiiString.h>
29 #include <Protocol/HiiDatabase.h>
30 #include <Protocol/HiiConfigRouting.h>
31 #include <Protocol/HiiConfigAccess.h>
32 #include <Protocol/FormBrowser2.h>
33 #include <Protocol/SimpleTextOut.h>
35 #include <Guid/GlobalVariable.h>
37 #define IFR_LIB_DEFAULT_STRING_SIZE 0x200
40 // The architectural variable "Lang" and "LangCodes" are deprecated in UEFI
41 // specification. While, UEFI specification also states that these deprecated
42 // variables may be provided for backwards compatibility.
43 // If "LANG_SUPPORT" is defined, "Lang" and "LangCodes" will be produced;
44 // If "LANG_SUPPORT" is undefined, "Lang" and "LangCodes" will not be produced.
48 #define EFI_LANGUAGE_VARIABLE L"Lang"
49 #define EFI_LANGUAGE_CODES_VARIABLE L"LangCodes"
51 #define UEFI_LANGUAGE_VARIABLE L"PlatformLang"
52 #define UEFI_LANGUAGE_CODES_VARIABLE L"PlatformLangCodes"
55 // Limited buffer size recommended by RFC4646 (4.3. Length Considerations)
56 // (42 characters plus a NULL terminator)
58 #define RFC_3066_ENTRY_SIZE (42 + 1)
59 #define ISO_639_2_ENTRY_SIZE 3
61 #define INVALID_VARSTORE_ID 0
63 #define QUESTION_FLAGS (EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY)
64 #define QUESTION_FLAGS_MASK (~QUESTION_FLAGS)
66 extern EFI_HII_DATABASE_PROTOCOL
*gIfrLibHiiDatabase
;
67 extern EFI_HII_STRING_PROTOCOL
*gIfrLibHiiString
;
71 EFI_STRING_ID StringToken
;
72 EFI_IFR_TYPE_VALUE Value
;
79 // Buffer size allocated for Data.
84 // Offset in Data to append the newly created opcode binary.
85 // It will be adjusted automatically in Create***OpCode(), and should be
86 // initialized to 0 before invocation of a serial of Create***OpCode()
91 // The destination buffer for created op-codes
94 } EFI_HII_UPDATE_DATA
;
98 // Exported Library functions
102 IN OUT EFI_HII_UPDATE_DATA
*Data
107 Create EFI_IFR_END_OP opcode.
110 Data - Destination for the created opcode binary
113 EFI_SUCCESS - Opcode create success
119 CreateDefaultOpCode (
120 IN EFI_IFR_TYPE_VALUE
*Value
,
122 IN OUT EFI_HII_UPDATE_DATA
*Data
127 Create EFI_IFR_DEFAULT_OP opcode.
130 Value - Value for the default
131 Type - Type for the default
132 Data - Destination for the created opcode binary
135 EFI_SUCCESS - Opcode create success
142 IN EFI_QUESTION_ID QuestionId
,
143 IN EFI_STRING_ID Prompt
,
144 IN EFI_STRING_ID Help
,
145 IN UINT8 QuestionFlags
,
146 IN EFI_STRING_ID QuestionConfig
,
147 IN OUT EFI_HII_UPDATE_DATA
*Data
152 Create EFI_IFR_ACTION_OP opcode.
155 QuestionId - Question ID
156 Prompt - String ID for Prompt
157 Help - String ID for Help
158 QuestionFlags - Flags in Question Header
159 QuestionConfig - String ID for configuration
160 Data - Destination for the created opcode binary
163 EFI_SUCCESS - Opcode create success
169 CreateSubTitleOpCode (
170 IN EFI_STRING_ID Prompt
,
171 IN EFI_STRING_ID Help
,
174 IN OUT EFI_HII_UPDATE_DATA
*Data
179 Create EFI_IFR_SUBTITLE_OP opcode.
182 Prompt - String ID for Prompt
183 Help - String ID for Help
184 Flags - Subtitle opcode flags
185 Scope - Subtitle Scope bit
186 Data - Destination for the created opcode binary
189 EFI_SUCCESS - Opcode create success
196 IN EFI_STRING_ID Prompt
,
197 IN EFI_STRING_ID Help
,
198 IN EFI_STRING_ID TextTwo
,
199 IN OUT EFI_HII_UPDATE_DATA
*Data
204 Create EFI_IFR_TEXT_OP opcode.
207 Prompt - String ID for Prompt
208 Help - String ID for Help
209 TextTwo - String ID for text two
210 Data - Destination for the created opcode binary
213 EFI_SUCCESS - Opcode create success
220 IN EFI_FORM_ID FormId
,
221 IN EFI_STRING_ID Prompt
,
222 IN EFI_STRING_ID Help
,
223 IN UINT8 QuestionFlags
,
224 IN EFI_QUESTION_ID QuestionId
,
225 IN OUT EFI_HII_UPDATE_DATA
*Data
230 Create EFI_IFR_REF_OP opcode.
233 FormId - Destination Form ID
234 Prompt - String ID for Prompt
235 Help - String ID for Help
236 QuestionFlags - Flags in Question Header
237 QuestionId - Question ID
238 Data - Destination for the created opcode binary
241 EFI_SUCCESS - Opcode create success
247 CreateOneOfOptionOpCode (
248 IN UINTN OptionCount
,
249 IN IFR_OPTION
*OptionsList
,
251 IN OUT EFI_HII_UPDATE_DATA
*Data
257 IN EFI_QUESTION_ID QuestionId
,
258 IN EFI_VARSTORE_ID VarStoreId
,
260 IN EFI_STRING_ID Prompt
,
261 IN EFI_STRING_ID Help
,
262 IN UINT8 QuestionFlags
,
264 IN IFR_OPTION
*OptionsList
,
265 IN UINTN OptionCount
,
266 IN OUT EFI_HII_UPDATE_DATA
*Data
271 Create EFI_IFR_ONE_OF_OP opcode.
274 QuestionId - Question ID
275 VarStoreId - Storage ID
276 VarOffset - Offset in Storage
277 Prompt - String ID for Prompt
278 Help - String ID for Help
279 QuestionFlags - Flags in Question Header
280 OneOfFlags - Flags for oneof opcode
281 OptionsList - List of options
282 OptionCount - Number of options in option list
283 Data - Destination for the created opcode binary
286 EFI_SUCCESS - Opcode create success
292 CreateOrderedListOpCode (
293 IN EFI_QUESTION_ID QuestionId
,
294 IN EFI_VARSTORE_ID VarStoreId
,
296 IN EFI_STRING_ID Prompt
,
297 IN EFI_STRING_ID Help
,
298 IN UINT8 QuestionFlags
,
301 IN UINT8 MaxContainers
,
302 IN IFR_OPTION
*OptionsList
,
303 IN UINTN OptionCount
,
304 IN OUT EFI_HII_UPDATE_DATA
*Data
309 Create EFI_IFR_ORDERED_LIST_OP opcode.
312 QuestionId - Question ID
313 VarStoreId - Storage ID
314 VarOffset - Offset in Storage
315 Prompt - String ID for Prompt
316 Help - String ID for Help
317 QuestionFlags - Flags in Question Header
318 Flags - Flags for ordered list opcode
319 DataType - Type for option value
320 MaxContainers - Maximum count for options in this ordered list
321 OptionsList - List of options
322 OptionCount - Number of options in option list
323 Data - Destination for the created opcode binary
326 EFI_SUCCESS - Opcode create success
332 CreateCheckBoxOpCode (
333 IN EFI_QUESTION_ID QuestionId
,
334 IN EFI_VARSTORE_ID VarStoreId
,
336 IN EFI_STRING_ID Prompt
,
337 IN EFI_STRING_ID Help
,
338 IN UINT8 QuestionFlags
,
339 IN UINT8 CheckBoxFlags
,
340 IN OUT EFI_HII_UPDATE_DATA
*Data
345 Create EFI_IFR_CHECKBOX_OP opcode.
348 QuestionId - Question ID
349 VarStoreId - Storage ID
350 VarOffset - Offset in Storage
351 Prompt - String ID for Prompt
352 Help - String ID for Help
353 QuestionFlags - Flags in Question Header
354 CheckBoxFlags - Flags for checkbox opcode
355 Data - Destination for the created opcode binary
358 EFI_SUCCESS - Opcode create success
364 CreateNumericOpCode (
365 IN EFI_QUESTION_ID QuestionId
,
366 IN EFI_VARSTORE_ID VarStoreId
,
368 IN EFI_STRING_ID Prompt
,
369 IN EFI_STRING_ID Help
,
370 IN UINT8 QuestionFlags
,
371 IN UINT8 NumericFlags
,
376 IN OUT EFI_HII_UPDATE_DATA
*Data
381 Create EFI_IFR_NUMERIC_OP opcode.
384 QuestionId - Question ID
385 VarStoreId - Storage ID
386 VarOffset - Offset in Storage
387 Prompt - String ID for Prompt
388 Help - String ID for Help
389 QuestionFlags - Flags in Question Header
390 NumericFlags - Flags for numeric opcode
391 Minimum - Numeric minimum value
392 Maximum - Numeric maximum value
393 Step - Numeric step for edit
394 Default - Numeric default value
395 Data - Destination for the created opcode binary
398 EFI_SUCCESS - Opcode create success
405 IN EFI_QUESTION_ID QuestionId
,
406 IN EFI_VARSTORE_ID VarStoreId
,
408 IN EFI_STRING_ID Prompt
,
409 IN EFI_STRING_ID Help
,
410 IN UINT8 QuestionFlags
,
411 IN UINT8 StringFlags
,
414 IN OUT EFI_HII_UPDATE_DATA
*Data
419 Create EFI_IFR_STRING_OP opcode.
422 QuestionId - Question ID
423 VarStoreId - Storage ID
424 VarOffset - Offset in Storage
425 Prompt - String ID for Prompt
426 Help - String ID for Help
427 QuestionFlags - Flags in Question Header
428 StringFlags - Flags for string opcode
429 MinSize - String minimum length
430 MaxSize - String maximum length
431 Data - Destination for the created opcode binary
434 EFI_SUCCESS - Opcode create success
441 IN EFI_STRING_ID Title
,
442 IN UINT16 LineNumber
,
444 IN OUT EFI_HII_UPDATE_DATA
*Data
449 Create GUIDed opcode for banner.
452 Title - String ID for title
453 LineNumber - Line number for this banner
454 Alignment - Alignment for this banner, left, center or right
455 Data - Destination for the created opcode binary
458 EFI_SUCCESS - Opcode create success
463 EFI_HII_PACKAGE_LIST_HEADER
*
465 IN UINTN NumberOfPackages
,
472 Assemble EFI_HII_PACKAGE_LIST according to the passed in packages.
475 NumberOfPackages - Number of packages.
476 GuidId - Package GUID.
479 Pointer of EFI_HII_PACKAGE_LIST_HEADER.
485 DevicePathToHiiHandle (
486 IN EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
,
487 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
492 Find HII Handle associated with given Device Path.
495 HiiDatabase - Point to EFI_HII_DATABASE_PROTOCOL instance.
496 DevicePath - Device Path associated with the HII package list handle.
499 Handle - HII package list Handle associated with the Device Path.
500 NULL - Hii Package list handle is not found.
508 IN UINTN
*BufferSize
,
515 Configure the buffer accrording to ConfigBody strings.
518 DefaultId - the ID of default.
519 Buffer - the start address of buffer.
520 BufferSize - the size of buffer.
521 Number - the number of the strings.
524 EFI_BUFFER_TOO_SMALL - the BufferSize is too small to operate.
525 EFI_INVALID_PARAMETER - Buffer is NULL or BufferSize is 0.
526 EFI_SUCCESS - Operation successful.
532 ExtractGuidFromHiiHandle (
533 IN EFI_HII_HANDLE Handle
,
539 Extract Hii package list GUID for given HII handle.
542 HiiHandle - Hii handle
543 Guid - Package list GUID
546 EFI_SUCCESS - Successfully extract GUID from Hii database.
560 Converts binary buffer to Unicode string in reversed byte order to BufToHexString().
563 Str - String for output
564 Buffer - Binary buffer.
565 BufferSize - Size of the buffer in bytes.
568 EFI_SUCCESS - The function completed successfully.
575 IN OUT UINT8
*Buffer
,
576 IN OUT UINTN
*BufferSize
,
582 Converts Hex String to binary buffer in reversed byte order to HexStringToBuf().
585 Buffer - Pointer to buffer that receives the data.
586 BufferSize - Length in bytes of the buffer to hold converted data.
587 If routine return with EFI_SUCCESS, containing length of converted data.
588 If routine return with EFI_BUFFER_TOO_SMALL, containg length of buffer desired.
589 Str - String to be converted from.
592 EFI_SUCCESS - The function completed successfully.
599 IN OUT CHAR16
*ConfigHdr
,
600 IN OUT UINTN
*StrBufferLen
,
602 IN CHAR16
*Name
, OPTIONAL
603 IN EFI_HANDLE
*DriverHandle
608 Construct <ConfigHdr> using routing information GUID/NAME/PATH.
611 ConfigHdr - Pointer to the ConfigHdr string.
612 StrBufferLen - On input: Length in bytes of buffer to hold the ConfigHdr string. Includes tailing '\0' character.
614 If return EFI_SUCCESS, containing length of ConfigHdr string buffer.
615 If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.
616 Guid - Routing information: GUID.
617 Name - Routing information: NAME.
618 DriverHandle - Driver handle which contains the routing information: PATH.
621 EFI_SUCCESS - Routine success.
622 EFI_BUFFER_TOO_SMALL - The ConfigHdr string buffer is too small.
629 IN OUT CHAR16
*String
,
636 Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string.
639 String - The string to be searched in.
640 Offset - Offset in BlockName.
641 Width - Width in BlockName.
644 TRUE - Block name found.
645 FALSE - Block name not found.
652 EFI_GUID
*VariableGuid
, OPTIONAL
653 CHAR16
*VariableName
, OPTIONAL
660 This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser.
663 VariableGuid - An optional field to indicate the target variable GUID name to use.
664 VariableName - An optional field to indicate the target human-readable variable name.
665 BufferSize - On input: Length in bytes of buffer to hold retrived data.
667 If return EFI_BUFFER_TOO_SMALL, containg length of buffer desired.
668 Buffer - Buffer to hold retrived data.
671 EFI_SUCCESS - Routine success.
672 EFI_BUFFER_TOO_SMALL - The intput buffer is too small.
679 IN OUT UINTN
*HandleBufferLength
,
680 OUT EFI_HII_HANDLE
**HiiHandleBuffer
685 Determines the handles that are currently active in the database.
686 It's the caller's responsibility to free handle buffer.
689 HiiDatabase - A pointer to the EFI_HII_DATABASE_PROTOCOL instance.
690 HandleBufferLength - On input, a pointer to the length of the handle buffer. On output,
691 the length of the handle buffer that is required for the handles found.
692 HiiHandleBuffer - Pointer to an array of Hii Handles returned.
695 EFI_SUCCESS - Get an array of Hii Handles successfully.
696 EFI_INVALID_PARAMETER - Hii is NULL.
697 EFI_NOT_FOUND - Database not found.
704 EFI_GUID
*VariableGuid
, OPTIONAL
705 CHAR16
*VariableName
, OPTIONAL
708 CHAR16
*RequestElement OPTIONAL
713 This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser.
716 VariableGuid - An optional field to indicate the target variable GUID name to use.
717 VariableName - An optional field to indicate the target human-readable variable name.
718 BufferSize - Length in bytes of buffer to hold retrived data.
719 Buffer - Buffer to hold retrived data.
720 RequestElement - An optional field to specify which part of the buffer data
721 will be send back to Browser. If NULL, the whole buffer of
722 data will be committed to Browser.
723 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
726 EFI_SUCCESS - Routine success.
727 Other - Updating Browser uncommitted data failed.
733 ConvertRfc3066LanguageToIso639Language (
734 CHAR8
*LanguageRfc3066
,
735 CHAR8
*LanguageIso639
740 Convert language code from RFC3066 to ISO639-2.
743 LanguageRfc3066 - RFC3066 language code.
744 LanguageIso639 - ISO639-2 language code.
747 EFI_SUCCESS - Language code converted.
748 EFI_NOT_FOUND - Language code not found.
755 CHAR8
*SupportedLanguages
760 Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will
761 be converted to "engfra".
764 SupportedLanguages - The RFC3066 language list.
767 The ISO639-2 language list.
779 Determine what is the current language setting
782 Lang - Pointer of system language
792 IN OUT CHAR8
**LangCode
,
798 Get next language from language code list.
801 LangCode - The language code.
802 Lang - Returned language.
811 GetSupportedLanguages (
812 IN EFI_HII_HANDLE HiiHandle
817 This function returns the list of supported languages, in the format specified
818 in UEFI specification Appendix M.
821 HiiHandle - The HII package list handle.
824 The supported languages.
830 GetSupportedLanguageNumber (
831 IN EFI_HII_HANDLE HiiHandle
836 This function returns the number of supported languages
839 HiiHandle - The HII package list handle.
842 The number of supported languages.
848 GetStringFromHandle (
849 IN EFI_HII_HANDLE HiiHandle
,
850 IN EFI_STRING_ID StringId
,
851 OUT EFI_STRING
*String
856 Get string specified by StringId form the HiiHandle.
859 HiiHandle - The HII handle of package list.
860 StringId - The String ID.
861 String - The output string.
864 EFI_NOT_FOUND - String is not found.
865 EFI_SUCCESS - Operation is successful.
866 EFI_OUT_OF_RESOURCES - There is not enought memory in the system.
867 EFI_INVALID_PARAMETER - The String is NULL.
874 IN EFI_GUID
*ProducerGuid
,
875 IN EFI_STRING_ID StringId
,
876 OUT EFI_STRING
*String
881 Get the string given the StringId and String package Producer's Guid.
884 ProducerGuid - The Guid of String package list.
885 StringId - The String ID.
886 String - The output string.
889 EFI_NOT_FOUND - String is not found.
890 EFI_SUCCESS - Operation is successful.
891 EFI_OUT_OF_RESOURCES - There is not enought memory in the system.
898 IN EFI_HII_HANDLE PackageList
,
899 OUT EFI_STRING_ID
*StringId
,
900 IN CONST EFI_STRING String
905 This function adds the string into String Package of each language.
908 PackageList - Handle of the package list where this string will be added.
909 StringId - On return, contains the new strings id, which is unique within PackageList.
910 String - Points to the new null-terminated string.
913 EFI_SUCCESS - The new string was added successfully.
914 EFI_NOT_FOUND - The specified PackageList could not be found in database.
915 EFI_OUT_OF_RESOURCES - Could not add the string due to lack of resources.
916 EFI_INVALID_PARAMETER - String is NULL or StringId is NULL is NULL.
923 IN EFI_HII_HANDLE PackageList
,
924 IN EFI_STRING_ID StringId
,
925 OUT EFI_STRING String
,
926 IN OUT UINTN
*StringSize
931 This function try to retrieve string from String package of current language.
932 If fail, it try to retrieve string from String package of first language it support.
935 PackageList - The package list in the HII database to search for the specified string.
936 StringId - The string's id, which is unique within PackageList.
937 String - Points to the new null-terminated string.
938 StringSize - On entry, points to the size of the buffer pointed to by String, in bytes. On return,
939 points to the length of the string, in bytes.
942 EFI_SUCCESS - The string was returned successfully.
943 EFI_NOT_FOUND - The string specified by StringId is not available.
944 EFI_BUFFER_TOO_SMALL - The buffer specified by StringLength is too small to hold the string.
945 EFI_INVALID_PARAMETER - The String or StringSize was NULL.
952 IN EFI_HII_HANDLE PackageList
,
953 IN EFI_STRING_ID StringId
,
954 IN CONST EFI_STRING String
959 This function updates the string in String package of current language.
962 PackageList - The package list containing the strings.
963 StringId - The string's id, which is unique within PackageList.
964 String - Points to the new null-terminated string.
967 EFI_SUCCESS - The string was updated successfully.
968 EFI_NOT_FOUND - The string specified by StringId is not in the database.
969 EFI_INVALID_PARAMETER - The String was NULL.
970 EFI_OUT_OF_RESOURCES - The system is out of resources to accomplish the task.
977 IN UINTN NumberOfLines
,
978 OUT EFI_INPUT_KEY
*KeyValue
,
985 Draw a dialog and return the selected key.
988 NumberOfLines - The number of lines for the dialog box
989 KeyValue - The EFI_KEY value returned if HotKey is TRUE..
990 String - Pointer to the first string in the list
991 ... - A series of (quantity == NumberOfLines) text strings which
992 will be used to construct the dialog box
995 EFI_SUCCESS - Displayed dialog and received user interaction
996 EFI_INVALID_PARAMETER - One of the parameters was invalid.
1003 IN EFI_HII_HANDLE Handle
,
1004 IN EFI_GUID
*FormSetGuid
, OPTIONAL
1005 IN EFI_FORM_ID FormId
,
1008 IN EFI_HII_UPDATE_DATA
*Data
1012 Routine Description:
1013 This function allows the caller to update a form that has
1014 previously been registered with the EFI HII database.
1018 FormSetGuid - The formset should be updated.
1019 FormId - The form should be updated.
1020 Label - Update information starting immediately after this label in the IFR
1021 Insert - If TRUE and Data is not NULL, insert data after Label.
1022 If FALSE, replace opcodes between two labels with Data.
1023 Data - The adding data; If NULL, remove opcodes between two Label.
1026 EFI_SUCCESS - Update success.
1027 Other - Update fail.