2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
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.
15 #include "InternalHiiLib.h"
17 #define GUID_CONFIG_STRING_TYPE 0x00
18 #define NAME_CONFIG_STRING_TYPE 0x01
19 #define PATH_CONFIG_STRING_TYPE 0x02
21 #define ACTION_SET_DEFAUTL_VALUE 0x01
22 #define ACTION_VALIDATE_SETTING 0x02
24 #define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200
27 LIST_ENTRY Entry
; // Link to Block array
35 // <ConfigHdr> Template
37 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
39 EFI_FORM_BROWSER2_PROTOCOL
*mUefiFormBrowser2
= NULL
;
42 // Template used to mark the end of a list of packages
44 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList
= {
45 sizeof (EFI_HII_PACKAGE_HEADER
),
50 Extract Hii package list GUID for given HII handle.
52 If HiiHandle could not be found in the HII database, then ASSERT.
53 If Guid is NULL, then ASSERT.
55 @param Handle Hii handle
56 @param Guid Package list GUID
58 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
63 InternalHiiExtractGuidFromHiiHandle (
64 IN EFI_HII_HANDLE Handle
,
70 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
72 ASSERT (Guid
!= NULL
);
73 ASSERT (Handle
!= NULL
);
76 // Get HII PackageList
79 HiiPackageList
= NULL
;
81 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
82 ASSERT (Status
!= EFI_NOT_FOUND
);
84 if (Status
== EFI_BUFFER_TOO_SMALL
) {
85 HiiPackageList
= AllocatePool (BufferSize
);
86 ASSERT (HiiPackageList
!= NULL
);
88 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
90 if (EFI_ERROR (Status
)) {
91 FreePool (HiiPackageList
);
98 CopyGuid (Guid
, &HiiPackageList
->PackageListGuid
);
100 FreePool (HiiPackageList
);
106 Registers a list of packages in the HII Database and returns the HII Handle
107 associated with that registration. If an HII Handle has already been registered
108 with the same PackageListGuid, then NULL is returned. If there are not enough
109 resources to perform the registration, then NULL is returned. If an empty list
110 of packages is passed in, then NULL is returned. If the size of the list of
111 package is 0, then NULL is returned.
113 The variable arguments are pointers which point to package header that defined
114 by UEFI VFR compiler and StringGather tool.
116 #pragma pack (push, 1)
119 EFI_HII_PACKAGE_HEADER PackageHeader;
120 } EDKII_AUTOGEN_PACKAGES_HEADER;
123 @param[in] PackageListGuid The GUID of the package list.
124 @param[in] DeviceHandle If not NULL, the Device Handle on which
125 an instance of DEVICE_PATH_PROTOCOL is installed.
126 This Device Handle uniquely defines the device that
127 the added packages are associated with.
128 @param[in] ... The variable argument list that contains pointers
129 to packages terminated by a NULL.
131 @retval NULL A HII Handle has already been registered in the HII Database with
132 the same PackageListGuid.
133 @retval NULL The HII Handle could not be created.
134 @retval NULL An empty list of packages was passed in.
135 @retval NULL All packages are empty.
136 @retval Other The HII Handle associated with the newly registered package list.
142 IN CONST EFI_GUID
*PackageListGuid
,
143 IN EFI_HANDLE DeviceHandle OPTIONAL
,
148 EFI_HII_HANDLE
*HiiHandleBuffer
;
151 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
152 EFI_HII_HANDLE HiiHandle
;
156 ASSERT (PackageListGuid
!= NULL
);
159 // Check to see if an HII Handle has already been registered with the same
162 HiiHandleBuffer
= HiiGetHiiHandles (PackageListGuid
);
163 if (HiiHandleBuffer
!= NULL
) {
164 FreePool (HiiHandleBuffer
);
169 // Calculate the length of all the packages in the variable argument list
171 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
172 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
177 // If there are no packages in the variable argument list or all the packages
178 // are empty, then return a NULL HII Handle
185 // Add the length of the Package List Header and the terminating Package Header
187 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
190 // Allocate the storage for the entire Package List
192 PackageListHeader
= AllocateZeroPool (Length
);
195 // If the Packahge List can not be allocated, then return a NULL HII Handle
197 if (PackageListHeader
== NULL
) {
202 // Fill in the GUID and Length of the Package List Header
204 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
205 PackageListHeader
->PackageLength
= Length
;
208 // Initialize a pointer to the beginning if the Package List data
210 Data
= (UINT8
*)(PackageListHeader
+ 1);
213 // Copy the data from each package in the variable argument list
215 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
216 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
217 CopyMem (Data
, Package
+ 1, Length
);
223 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
225 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
228 // Register the package list with the HII Database
230 Status
= gHiiDatabase
->NewPackageList (
236 if (EFI_ERROR (Status
)) {
241 // Free the allocated package list
243 FreePool (PackageListHeader
);
246 // Return the new HII Handle
252 Removes a package list from the HII database.
254 If HiiHandle is NULL, then ASSERT.
255 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
257 @param[in] HiiHandle The handle that was previously registered in the HII database
263 IN EFI_HII_HANDLE HiiHandle
268 ASSERT (HiiHandle
!= NULL
);
269 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
270 ASSERT_EFI_ERROR (Status
);
275 Retrieves the array of all the HII Handles or the HII handles of a specific
276 package list GUID in the HII Database.
277 This array is terminated with a NULL HII Handle.
278 This function allocates the returned array using AllocatePool().
279 The caller is responsible for freeing the array with FreePool().
281 @param[in] PackageListGuid An optional parameter that is used to request
282 HII Handles associated with a specific
283 Package List GUID. If this parameter is NULL,
284 then all the HII Handles in the HII Database
285 are returned. If this parameter is not NULL,
286 then zero or more HII Handles associated with
287 PackageListGuid are returned.
289 @retval NULL No HII handles were found in the HII database
290 @retval NULL The array of HII Handles could not be retrieved
291 @retval Other A pointer to the NULL terminated array of HII Handles
297 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
301 UINTN HandleBufferLength
;
302 EFI_HII_HANDLE TempHiiHandleBuffer
;
303 EFI_HII_HANDLE
*HiiHandleBuffer
;
309 // Retrieve the size required for the buffer of all HII handles.
311 HandleBufferLength
= 0;
312 Status
= gHiiDatabase
->ListPackageLists (
314 EFI_HII_PACKAGE_TYPE_ALL
,
321 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
322 // then there are no HII handles in the HII database. If ListPackageLists()
323 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
324 // handles in the HII database.
326 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
328 // Return NULL if the size can not be retrieved, or if there are no HII
329 // handles in the HII Database
335 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
337 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
338 if (HiiHandleBuffer
== NULL
) {
340 // Return NULL if allocation fails.
346 // Retrieve the array of HII Handles in the HII Database
348 Status
= gHiiDatabase
->ListPackageLists (
350 EFI_HII_PACKAGE_TYPE_ALL
,
355 if (EFI_ERROR (Status
)) {
357 // Free the buffer and return NULL if the HII handles can not be retrieved.
359 FreePool (HiiHandleBuffer
);
363 if (PackageListGuid
== NULL
) {
365 // Return the NULL terminated array of HII handles in the HII Database
367 return HiiHandleBuffer
;
369 for (Index1
= 0, Index2
= 0; HiiHandleBuffer
[Index1
] != NULL
; Index1
++) {
370 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index1
], &Guid
);
371 ASSERT_EFI_ERROR (Status
);
372 if (CompareGuid (&Guid
, PackageListGuid
)) {
373 HiiHandleBuffer
[Index2
++] = HiiHandleBuffer
[Index1
];
377 HiiHandleBuffer
[Index2
] = NULL
;
378 return HiiHandleBuffer
;
380 FreePool (HiiHandleBuffer
);
387 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
388 hex digits that appear between a '=' and a '&' in a config string.
390 If String is NULL, then ASSERT().
392 @param[in] String Pointer to a Null-terminated Unicode string.
394 @return Pointer to the Null-terminated Unicode result string.
399 InternalHiiLowerConfigString (
400 IN EFI_STRING ConfigString
406 ASSERT (ConfigString
!= NULL
);
409 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
411 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
412 if (*String
== L
'=') {
414 } else if (*String
== L
'&') {
416 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
417 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
425 Uses the BlockToConfig() service of the Config Routing Protocol to
426 convert <ConfigRequest> and a buffer to a <ConfigResp>
428 If ConfigRequest is NULL, then ASSERT().
429 If Block is NULL, then ASSERT().
431 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
432 @param[in] Block Pointer to a block of data.
433 @param[in] BlockSize The zie, in bytes, of Block.
435 @retval NULL The <ConfigResp> string could not be generated.
436 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
441 InternalHiiBlockToConfig (
442 IN CONST EFI_STRING ConfigRequest
,
443 IN CONST UINT8
*Block
,
448 EFI_STRING ConfigResp
;
451 ASSERT (ConfigRequest
!= NULL
);
452 ASSERT (Block
!= NULL
);
455 // Convert <ConfigRequest> to <ConfigResp>
457 Status
= gHiiConfigRouting
->BlockToConfig (
465 if (EFI_ERROR (Status
)) {
472 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
473 or set uncommitted data. If sata i being retrieved, then the buffer is
474 allocated using AllocatePool(). The caller is then responsible for freeing
475 the buffer using FreePool().
477 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
478 is an optional parameter that may be NULL.
479 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
480 parameter that may be NULL.
481 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
482 of uncommited data to set. If this parameter is NULL,
483 then the caller is requesting to get the uncommited data
484 from the Form Browser.
486 @retval NULL The uncommitted data could not be retrieved.
487 @retval Other A pointer to a buffer containing the uncommitted data.
492 InternalHiiBrowserCallback (
493 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
494 IN CONST CHAR16
*VariableName
, OPTIONAL
495 IN CONST EFI_STRING SetResultsData OPTIONAL
499 UINTN ResultsDataSize
;
500 EFI_STRING ResultsData
;
501 CHAR16 TempResultsData
;
506 if (mUefiFormBrowser2
== NULL
) {
507 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
508 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
515 if (SetResultsData
!= NULL
) {
517 // Request to to set data in the uncommitted browser state information
519 ResultsData
= SetResultsData
;
522 // Retrieve the length of the buffer required ResultsData from the Browser Callback
524 Status
= mUefiFormBrowser2
->BrowserCallback (
533 if (!EFI_ERROR (Status
)) {
535 // No Resluts Data, only allocate one char for '\0'
537 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
541 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
546 // Allocate the ResultsData buffer
548 ResultsData
= AllocateZeroPool (ResultsDataSize
);
549 if (ResultsData
== NULL
) {
555 // Retrieve or set the ResultsData from the Browser Callback
557 Status
= mUefiFormBrowser2
->BrowserCallback (
561 (BOOLEAN
)(SetResultsData
== NULL
),
565 if (EFI_ERROR (Status
)) {
573 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
574 information that includes a GUID, an optional Unicode string name, and a device
575 path. The string returned is allocated with AllocatePool(). The caller is
576 responsible for freeing the allocated string with FreePool().
578 The format of a <ConfigHdr> is as follows:
580 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
582 @param[in] Guid Pointer to an EFI_GUID that is the routing information
583 GUID. Each of the 16 bytes in Guid is converted to
584 a 2 Unicode character hexidecimal string. This is
585 an optional parameter that may be NULL.
586 @param[in] Name Pointer to a Null-terminated Unicode string that is
587 the routing information NAME. This is an optional
588 parameter that may be NULL. Each 16-bit Unicode
589 character in Name is converted to a 4 character Unicode
591 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
592 that is the routing information PATH. Each byte of
593 the Device Path associated with DriverHandle is converted
594 to a 2 Unicode character hexidecimal string.
596 @retval NULL DriverHandle does not support the Device Path Protocol.
597 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
602 HiiConstructConfigHdr (
603 IN CONST EFI_GUID
*Guid
, OPTIONAL
604 IN CONST CHAR16
*Name
, OPTIONAL
605 IN EFI_HANDLE DriverHandle
609 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
610 UINTN DevicePathSize
;
612 CHAR16
*ReturnString
;
617 // Compute the length of Name in Unicode characters.
618 // If Name is NULL, then the length is 0.
622 NameLength
= StrLen (Name
);
628 // Retrieve DevicePath Protocol associated with DriverHandle
630 if (DriverHandle
!= NULL
) {
631 DevicePath
= DevicePathFromHandle (DriverHandle
);
632 if (DevicePath
== NULL
) {
636 // Compute the size of the device path in bytes
638 DevicePathSize
= GetDevicePathSize (DevicePath
);
642 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
643 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
645 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
646 if (String
== NULL
) {
651 // Start with L"GUID="
653 ReturnString
= StrCpy (String
, L
"GUID=");
654 String
+= StrLen (String
);
658 // Append Guid converted to <HexCh>32
660 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
661 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
668 StrCpy (String
, L
"&NAME=");
669 String
+= StrLen (String
);
673 // Append Name converted to <Char>NameLength
675 for (; *Name
!= L
'\0'; Name
++) {
676 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
683 StrCpy (String
, L
"&PATH=");
684 String
+= StrLen (String
);
687 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
689 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
690 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
694 // Null terminate the Unicode string
699 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
701 return InternalHiiLowerConfigString (ReturnString
);
705 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
706 to binary buffer from <ConfigHdr>.
708 This is a internal function.
710 @param String UEFI configuration string.
711 @param Flag Flag specifies what type buffer will be retrieved.
712 @param Buffer Binary of Guid, Name or Device path.
714 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
715 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
716 @retval EFI_SUCCESS The buffer data is retrieved and translated to
721 InternalHiiGetBufferFromString (
722 IN EFI_STRING String
,
728 EFI_STRING ConfigHdr
;
735 if (String
== NULL
|| Buffer
== NULL
) {
736 return EFI_INVALID_PARAMETER
;
743 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
744 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
746 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
749 case GUID_CONFIG_STRING_TYPE
:
750 case PATH_CONFIG_STRING_TYPE
:
752 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
753 // as the device path and Guid resides in RAM memory.
754 // Translate the data into binary.
756 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
757 if (DataBuffer
== NULL
) {
758 return EFI_OUT_OF_RESOURCES
;
761 // Convert binary byte one by one
763 ZeroMem (TemStr
, sizeof (TemStr
));
764 for (Index
= 0; Index
< Length
; Index
++) {
765 TemStr
[0] = ConfigHdr
[Index
];
766 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
767 if ((Index
& 1) == 0) {
768 DataBuffer
[Index
/2] = DigitUint8
;
770 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
774 *Buffer
= DataBuffer
;
777 case NAME_CONFIG_STRING_TYPE
:
779 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
783 // Add the tailling char L'\0'
785 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
786 if (DataBuffer
== NULL
) {
787 return EFI_OUT_OF_RESOURCES
;
790 // Convert character one by one
792 StringPtr
= (CHAR16
*) DataBuffer
;
793 ZeroMem (TemStr
, sizeof (TemStr
));
794 for (Index
= 0; Index
< Length
; Index
+= 4) {
795 StrnCpy (TemStr
, ConfigHdr
+ Index
, 4);
796 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
799 // Add tailing L'\0' character
801 StringPtr
[Index
/4] = L
'\0';
803 *Buffer
= DataBuffer
;
807 return EFI_INVALID_PARAMETER
;
815 This function checks VarOffset and VarWidth is in the block range.
817 @param BlockArray The block array is to be checked.
818 @param VarOffset Offset of var to the structure
819 @param VarWidth Width of var.
821 @retval TRUE This Var is in the block range.
822 @retval FALSE This Var is not in the block range.
826 IN IFR_BLOCK_DATA
*BlockArray
,
832 IFR_BLOCK_DATA
*BlockData
;
835 // No Request Block array, all vars are got.
837 if (BlockArray
== NULL
) {
842 // Check the input var is in the request block range.
844 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
845 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
846 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
855 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
857 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
859 @param ValueString String in <BlockConfig> format and points to the
860 first character of <Number>.
861 @param ValueData The output value. Caller takes the responsibility
863 @param ValueLength Length of the <Number>, in characters.
865 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
867 @retval EFI_SUCCESS Value of <Number> is outputted in Number
873 InternalHiiGetValueOfNumber (
874 IN EFI_STRING ValueString
,
875 OUT UINT8
**ValueData
,
876 OUT UINTN
*ValueLength
879 EFI_STRING StringPtr
;
886 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
887 ASSERT (*ValueString
!= L
'\0');
890 // Get the length of value string
892 StringPtr
= ValueString
;
893 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
896 Length
= StringPtr
- ValueString
;
899 // Allocate buffer to store the value
901 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
903 return EFI_OUT_OF_RESOURCES
;
907 // Convert character one by one to the value buffer
909 ZeroMem (TemStr
, sizeof (TemStr
));
910 for (Index
= 0; Index
< Length
; Index
++) {
911 TemStr
[0] = ValueString
[Length
- Index
- 1];
912 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
913 if ((Index
& 1) == 0) {
914 Buf
[Index
/2] = DigitUint8
;
916 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
921 // Set the converted value and string length.
924 *ValueLength
= Length
;
929 This internal function parses IFR data to validate current setting.
931 @param ConfigResp ConfigResp string contains the current setting.
932 @param HiiPackageList Point to Hii package list.
933 @param PackageListLength The length of the pacakge.
934 @param VarGuid Guid of the buffer storage.
935 @param VarName Name of the buffer storage.
937 @retval EFI_SUCCESS The current setting is valid.
938 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
939 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
943 InternalHiiValidateCurrentSetting (
944 IN EFI_STRING ConfigResp
,
945 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
946 IN UINTN PackageListLength
,
947 IN EFI_GUID
*VarGuid
,
951 IFR_BLOCK_DATA
*CurrentBlockArray
;
952 IFR_BLOCK_DATA
*BlockData
;
953 IFR_BLOCK_DATA
*NewBlockData
;
954 IFR_BLOCK_DATA VarBlockData
;
955 EFI_STRING StringPtr
;
965 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
966 UINT32 PackageOffset
;
969 EFI_IFR_OP_HEADER
*IfrOpHdr
;
970 EFI_IFR_VARSTORE
*IfrVarStore
;
971 EFI_IFR_ONE_OF
*IfrOneOf
;
972 EFI_IFR_NUMERIC
*IfrNumeric
;
973 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
974 EFI_IFR_CHECKBOX
*IfrCheckBox
;
975 EFI_IFR_STRING
*IfrString
;
980 // 1. Get the current setting to current block data array and Convert them into VarBuffer
984 // Skip ConfigHdr string
986 StringPtr
= ConfigResp
;
987 StringPtr
= StrStr (ConfigResp
, L
"&OFFSET");
988 if (StringPtr
== NULL
) {
990 // No ConfigBlock value is requied to be validated.
991 // EFI_SUCCESS directly return.
997 // Initialize the local variables.
1000 VarStoreName
= NULL
;
1001 Status
= EFI_SUCCESS
;
1003 NewBlockData
= NULL
;
1005 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
1006 VarBuffer
= AllocateZeroPool (MaxBufferSize
);
1007 if (VarBuffer
== NULL
) {
1008 return EFI_OUT_OF_RESOURCES
;
1012 // Init CurrentBlockArray
1014 CurrentBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1015 if (CurrentBlockArray
== NULL
) {
1016 Status
= EFI_OUT_OF_RESOURCES
;
1019 InitializeListHead (&CurrentBlockArray
->Entry
);
1022 // Parse each <RequestElement> if exists
1023 // Only <BlockName> format is supported by this help function.
1024 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1026 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1028 // Skip the &OFFSET= string
1030 StringPtr
+= StrLen (L
"&OFFSET=");
1035 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1036 if (EFI_ERROR (Status
)) {
1043 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1045 FreePool (TmpBuffer
);
1048 StringPtr
+= Length
;
1049 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1050 Status
= EFI_INVALID_PARAMETER
;
1053 StringPtr
+= StrLen (L
"&WIDTH=");
1058 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1059 if (EFI_ERROR (Status
)) {
1066 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1068 FreePool (TmpBuffer
);
1071 StringPtr
+= Length
;
1072 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1073 Status
= EFI_INVALID_PARAMETER
;
1077 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1078 Status
= EFI_INVALID_PARAMETER
;
1081 StringPtr
+= StrLen (L
"&VALUE=");
1086 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1087 if (EFI_ERROR (Status
)) {
1091 StringPtr
+= Length
;
1092 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1093 Status
= EFI_INVALID_PARAMETER
;
1098 // Check whether VarBuffer is enough
1100 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1101 VarBuffer
= ReallocatePool (
1103 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1106 if (VarBuffer
== NULL
) {
1107 Status
= EFI_OUT_OF_RESOURCES
;
1110 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1114 // Update the Block with configuration info
1116 CopyMem (VarBuffer
+ Offset
, TmpBuffer
, Width
);
1117 FreePool (TmpBuffer
);
1121 // Set new Block Data
1123 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1124 if (NewBlockData
== NULL
) {
1125 Status
= EFI_OUT_OF_RESOURCES
;
1128 NewBlockData
->Offset
= Offset
;
1129 NewBlockData
->Width
= Width
;
1132 // Insert the new block data into the block data array.
1134 for (Link
= CurrentBlockArray
->Entry
.ForwardLink
; Link
!= &CurrentBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1135 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1136 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1137 if (NewBlockData
->Width
> BlockData
->Width
) {
1138 BlockData
->Width
= NewBlockData
->Width
;
1140 FreePool (NewBlockData
);
1142 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1144 // Insert new block data as the previous one of this link.
1146 InsertTailList (Link
, &NewBlockData
->Entry
);
1152 // Insert new block data into the array tail.
1154 if (Link
== &CurrentBlockArray
->Entry
) {
1155 InsertTailList (Link
, &NewBlockData
->Entry
);
1159 // If '\0', parsing is finished.
1161 if (*StringPtr
== 0) {
1165 // Go to next ConfigBlock
1170 // Merge the aligned block data into the single block data.
1172 Link
= CurrentBlockArray
->Entry
.ForwardLink
;
1173 while ((Link
!= &CurrentBlockArray
->Entry
) && (Link
->ForwardLink
!= &CurrentBlockArray
->Entry
)) {
1174 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1175 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1176 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1177 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1178 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1180 RemoveEntryList (Link
->ForwardLink
);
1181 FreePool (NewBlockData
);
1184 Link
= Link
->ForwardLink
;
1187 if (IsListEmpty (&CurrentBlockArray
->Entry
)) {
1188 Status
= EFI_SUCCESS
;
1193 // 2. Check IFR value is in block data, then Validate Vaule
1195 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1198 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1199 while (PackageOffset
< PackageListLength
) {
1200 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1203 // Parse IFR opcode from the form package.
1205 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1206 IfrOffset
= sizeof (PacakgeHeader
);
1207 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1208 while (IfrOffset
< PacakgeHeader
.Length
) {
1209 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1211 // Validate current setting to the value built in IFR opcode
1213 switch (IfrOpHdr
->OpCode
) {
1214 case EFI_IFR_VARSTORE_OP
:
1216 // VarStoreId has been found. No further found.
1218 if (IfrVarStore
!= NULL
) {
1222 // Find the matched VarStoreId to the input VarGuid and VarName
1224 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1225 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1226 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1227 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1228 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1233 // The matched VarStore is found.
1235 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1242 case EFI_IFR_FORM_OP
:
1244 // Check the matched VarStoreId is found.
1246 if (IfrVarStore
== NULL
) {
1247 Status
= EFI_SUCCESS
;
1251 case EFI_IFR_ONE_OF_OP
:
1253 // Check whether current value is the one of option.
1257 // OneOf question is not in IFR Form. This IFR form is not valid.
1259 if (IfrVarStore
== NULL
) {
1260 Status
= EFI_INVALID_PARAMETER
;
1264 // Check whether this question is for the requested varstore.
1266 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1267 if (IfrOneOf
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1272 // Get Offset by Question header and Width by DataType Flags
1274 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1275 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1277 // Check whether this question is in current block array.
1279 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1281 // This question is not in the current configuration string. Skip it.
1286 // Check this var question is in the var storage
1288 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1290 // This question exceeds the var store size.
1292 Status
= EFI_INVALID_PARAMETER
;
1297 // Get the current value for oneof opcode
1300 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1302 // Set Block Data, to be checked in the following Oneof option opcode.
1304 VarBlockData
.Offset
= Offset
;
1305 VarBlockData
.Width
= Width
;
1306 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1307 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1309 case EFI_IFR_NUMERIC_OP
:
1311 // Check the current value is in the numeric range.
1315 // Numeric question is not in IFR Form. This IFR form is not valid.
1317 if (IfrVarStore
== NULL
) {
1318 Status
= EFI_INVALID_PARAMETER
;
1322 // Check whether this question is for the requested varstore.
1324 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1325 if (IfrNumeric
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1330 // Get Offset by Question header and Width by DataType Flags
1332 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1333 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1335 // Check whether this question is in current block array.
1337 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1339 // This question is not in the current configuration string. Skip it.
1344 // Check this var question is in the var storage
1346 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1348 // This question exceeds the var store size.
1350 Status
= EFI_INVALID_PARAMETER
;
1355 // Check the current value is in the numeric range.
1358 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1359 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1360 case EFI_IFR_NUMERIC_SIZE_1
:
1361 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1363 // Not in the valid range.
1365 Status
= EFI_INVALID_PARAMETER
;
1369 case EFI_IFR_NUMERIC_SIZE_2
:
1370 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1372 // Not in the valid range.
1374 Status
= EFI_INVALID_PARAMETER
;
1378 case EFI_IFR_NUMERIC_SIZE_4
:
1379 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1381 // Not in the valid range.
1383 Status
= EFI_INVALID_PARAMETER
;
1387 case EFI_IFR_NUMERIC_SIZE_8
:
1388 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1390 // Not in the valid range.
1392 Status
= EFI_INVALID_PARAMETER
;
1399 case EFI_IFR_CHECKBOX_OP
:
1401 // Check value is BOOLEAN type, only 0 and 1 is valid.
1405 // CheckBox question is not in IFR Form. This IFR form is not valid.
1407 if (IfrVarStore
== NULL
) {
1408 Status
= EFI_INVALID_PARAMETER
;
1413 // Check whether this question is for the requested varstore.
1415 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1416 if (IfrCheckBox
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1421 // Get Offset by Question header
1423 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1424 Width
= sizeof (BOOLEAN
);
1426 // Check whether this question is in current block array.
1428 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1430 // This question is not in the current configuration string. Skip it.
1435 // Check this var question is in the var storage
1437 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1439 // This question exceeds the var store size.
1441 Status
= EFI_INVALID_PARAMETER
;
1446 // Boolean type, only 1 and 0 is valid.
1448 if (*(VarBuffer
+ Offset
) > 1) {
1449 Status
= EFI_INVALID_PARAMETER
;
1454 case EFI_IFR_STRING_OP
:
1456 // Check current string length is less than maxsize
1460 // CheckBox question is not in IFR Form. This IFR form is not valid.
1462 if (IfrVarStore
== NULL
) {
1463 Status
= EFI_INVALID_PARAMETER
;
1468 // Check whether this question is for the requested varstore.
1470 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1471 if (IfrString
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1476 // Get Offset/Width by Question header and OneOf Flags
1478 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1479 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1481 // Check whether this question is in current block array.
1483 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1485 // This question is not in the current configuration string. Skip it.
1490 // Check this var question is in the var storage
1492 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1494 // This question exceeds the var store size.
1496 Status
= EFI_INVALID_PARAMETER
;
1501 // Check current string length is less than maxsize
1503 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1504 Status
= EFI_INVALID_PARAMETER
;
1508 case EFI_IFR_ONE_OF_OPTION_OP
:
1510 // Opcode Scope is zero. This one of option is not to be checked.
1512 if (VarBlockData
.Scope
== 0) {
1517 // Only check for OneOf and OrderList opcode
1519 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1520 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1522 // Check current value is the value of one of option.
1524 if (VarValue
== IfrOneOfOption
->Value
.u64
) {
1526 // The value is one of option value.
1527 // Set OpCode to Zero, don't need check again.
1529 VarBlockData
.OpCode
= 0;
1534 case EFI_IFR_END_OP
:
1536 // Decrease opcode scope for the validated opcode
1538 if (VarBlockData
.Scope
> 0) {
1539 VarBlockData
.Scope
--;
1543 // OneOf value doesn't belong to one of option value.
1545 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1546 Status
= EFI_INVALID_PARAMETER
;
1552 // Increase Scope for the validated opcode
1554 if (VarBlockData
.Scope
> 0) {
1555 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1560 // Go to the next opcode
1562 IfrOffset
+= IfrOpHdr
->Length
;
1565 // Only one form is in a package list.
1571 // Go to next package.
1573 PackageOffset
+= PacakgeHeader
.Length
;
1577 if (VarBuffer
!= NULL
) {
1578 FreePool (VarBuffer
);
1581 if (CurrentBlockArray
!= NULL
) {
1583 // Free Link Array CurrentBlockArray
1585 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1586 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1587 RemoveEntryList (&BlockData
->Entry
);
1588 FreePool (BlockData
);
1590 FreePool (CurrentBlockArray
);
1597 This function parses the input ConfigRequest string and its matched IFR code
1598 string for setting default value and validating current setting.
1600 1. For setting default action, Reset the default value specified by DefaultId
1601 to the driver configuration got by Request string.
1602 2. For validating current setting, Validate the current configuration
1603 by parsing HII form IFR opcode.
1605 NULL request string support depends on the ExportConfig interface of
1606 HiiConfigRouting protocol in UEFI specification.
1608 @param Request A null-terminated Unicode string in
1609 <MultiConfigRequest> format. It can be NULL.
1610 If it is NULL, all current configuration for the
1611 entirety of the current HII database will be validated.
1612 If it is NULL, all configuration for the
1613 entirety of the current HII database will be reset.
1614 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1615 @param ActionType Action supports setting defaults and validate current setting.
1617 @retval TURE Action runs successfully.
1618 @retval FALSE Action is not valid or Action can't be executed successfully..
1622 InternalHiiIfrValueAction (
1623 IN CONST EFI_STRING Request
, OPTIONAL
1624 IN UINT16 DefaultId
,
1628 EFI_STRING ConfigAltResp
;
1629 EFI_STRING ConfigAltHdr
;
1630 EFI_STRING ConfigResp
;
1631 EFI_STRING Progress
;
1632 EFI_STRING StringPtr
;
1633 EFI_STRING StringHdr
;
1635 EFI_HANDLE DriverHandle
;
1636 EFI_HANDLE TempDriverHandle
;
1637 EFI_HII_HANDLE
*HiiHandleBuffer
;
1638 EFI_HII_HANDLE HiiHandle
;
1642 EFI_STRING_ID DefaultName
;
1646 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1647 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1648 UINT32 PackageOffset
;
1649 UINTN PackageListLength
;
1650 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1651 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1652 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1654 ConfigAltResp
= NULL
;
1659 ConfigAltHdr
= NULL
;
1660 HiiHandleBuffer
= NULL
;
1662 TempDriverHandle
= NULL
;
1665 HiiPackageList
= NULL
;
1668 // Only support set default and validate setting action.
1670 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
1675 // Get the full requested value and deault value string.
1677 if (Request
!= NULL
) {
1678 Status
= gHiiConfigRouting
->ExtractConfig (
1685 Status
= gHiiConfigRouting
->ExportConfig (
1691 if (EFI_ERROR (Status
)) {
1695 StringPtr
= ConfigAltResp
;
1697 while (StringPtr
!= L
'\0') {
1699 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1701 StringHdr
= StringPtr
;
1706 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1707 Status
= EFI_INVALID_PARAMETER
;
1710 StringPtr
+= StrLen (L
"GUID=");
1711 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
1712 if (EFI_ERROR (Status
)) {
1717 // Get Name value VarName
1719 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1722 if (*StringPtr
== L
'\0') {
1723 Status
= EFI_INVALID_PARAMETER
;
1726 StringPtr
+= StrLen (L
"&NAME=");
1727 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
1728 if (EFI_ERROR (Status
)) {
1733 // Get Path value DevicePath
1735 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1738 if (*StringPtr
== L
'\0') {
1739 Status
= EFI_INVALID_PARAMETER
;
1742 StringPtr
+= StrLen (L
"&PATH=");
1743 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
1744 if (EFI_ERROR (Status
)) {
1749 // Get the Driver handle by the got device path.
1751 TempDevicePath
= DevicePath
;
1752 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
1753 if (EFI_ERROR (Status
)) {
1758 // Find the matched Hii Handle for the found Driver handle
1760 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
1761 if (HiiHandleBuffer
== NULL
) {
1762 Status
= EFI_NOT_FOUND
;
1766 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
1767 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
1768 if (TempDriverHandle
== DriverHandle
) {
1773 HiiHandle
= HiiHandleBuffer
[Index
];
1774 FreePool (HiiHandleBuffer
);
1776 if (HiiHandle
== NULL
) {
1778 // This request string has no its Hii package.
1779 // Its default value and validating can't execute by parsing IFR data.
1780 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
1782 Status
= EFI_SUCCESS
;
1783 goto NextConfigAltResp
;
1787 // 2. Get DefaultName string ID by parsing the PacakgeList
1791 // Get HiiPackage by HiiHandle
1793 PackageListLength
= 0;
1794 HiiPackageList
= NULL
;
1795 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1798 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1800 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1801 Status
= EFI_INVALID_PARAMETER
;
1805 HiiPackageList
= AllocatePool (PackageListLength
);
1806 if (HiiPackageList
== NULL
) {
1807 Status
= EFI_OUT_OF_RESOURCES
;
1812 // Get PackageList on HiiHandle
1814 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1815 if (EFI_ERROR (Status
)) {
1820 // Parse the form package and get the default name string ID.
1822 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1823 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1824 Status
= EFI_NOT_FOUND
;
1825 while (PackageOffset
< PackageListLength
) {
1826 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1829 // Parse IFR opcode to get default store opcode
1831 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1832 IfrOffset
= sizeof (PacakgeHeader
);
1833 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1834 while (IfrOffset
< PacakgeHeader
.Length
) {
1835 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1837 // Match DefaultId to find its DefaultName
1839 if (IfrOpHdr
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
) {
1840 if (((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
== DefaultId
) {
1841 DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
1842 Status
= EFI_SUCCESS
;
1846 IfrOffset
+= IfrOpHdr
->Length
;
1849 // Only one form is in a package list.
1855 // Go to next package.
1857 PackageOffset
+= PacakgeHeader
.Length
;
1861 // Not found the matched default string ID
1863 if (EFI_ERROR (Status
)) {
1864 Status
= EFI_SUCCESS
;
1865 goto NextConfigAltResp
;
1870 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
1871 // Get the default configuration string according to the found defaultname string ID.
1873 Status
= gHiiConfigRouting
->GetAltConfig (
1879 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultName
:NULL
, // it can be NULL to get the current setting.
1884 // The required setting can't be found. So, it is not required to be validated and set.
1886 if (EFI_ERROR (Status
)) {
1887 Status
= EFI_SUCCESS
;
1888 goto NextConfigAltResp
;
1891 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
1893 if (StrStr (ConfigResp
, L
"&OFFSET=") == NULL
) {
1894 goto NextConfigAltResp
;
1898 // 4. Set the default configuration information or Validate current setting by parse IFR code.
1899 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1901 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1903 // Set the default configuration information.
1905 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
1908 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1910 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
);
1913 if (EFI_ERROR (Status
)) {
1919 // Free the allocated pacakge buffer and the got ConfigResp string.
1921 if (HiiPackageList
!= NULL
) {
1922 FreePool (HiiPackageList
);
1923 HiiPackageList
= NULL
;
1926 if (ConfigResp
!= NULL
) {
1927 FreePool (ConfigResp
);
1932 // Free the allocated buffer.
1940 FreePool (DevicePath
);
1944 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
1948 // Get and Skip ConfigHdr
1950 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1953 if (*StringPtr
== L
'\0') {
1958 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
1959 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
1961 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
1962 if (ConfigAltHdr
== NULL
) {
1963 Status
= EFI_OUT_OF_RESOURCES
;
1966 StrCpy (ConfigAltHdr
, L
"&");
1967 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
1968 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
1971 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
1973 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
1974 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
1975 if (*StringPtr
== L
'\0') {
1981 // Free the allocated ConfigAltHdr string
1983 FreePool (ConfigAltHdr
);
1984 if (*StringPtr
== L
'\0') {
1989 // Find &GUID as the next ConfigHdr
1991 StringPtr
= StrStr (StringPtr
, L
"&GUID");
1992 if (StringPtr
== NULL
) {
2003 if (VarGuid
!= NULL
) {
2007 if (VarName
!= NULL
) {
2011 if (DevicePath
!= NULL
) {
2012 FreePool (DevicePath
);
2015 if (ConfigResp
!= NULL
) {
2016 FreePool (ConfigResp
);
2019 if (ConfigAltResp
!= NULL
) {
2020 FreePool (ConfigAltResp
);
2023 if (HiiPackageList
!= NULL
) {
2024 FreePool (HiiPackageList
);
2027 if (EFI_ERROR (Status
)) {
2035 Validate the current configuration by parsing HII form IFR opcode.
2037 NULL request string support depends on the ExportConfig interface of
2038 HiiConfigRouting protocol in UEFI specification.
2040 @param Request A null-terminated Unicode string in
2041 <MultiConfigRequest> format. It can be NULL.
2042 If it is NULL, all current configuration for the
2043 entirety of the current HII database will be validated.
2045 @retval TURE Current configuration is valid.
2046 @retval FALSE Current configuration is invalid.
2050 HiiValidateSettings (
2051 IN CONST EFI_STRING Request OPTIONAL
2054 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2058 Reset the default value specified by DefaultId to the driver
2059 configuration got by Request string.
2061 NULL request string support depends on the ExportConfig interface of
2062 HiiConfigRouting protocol in UEFI specification.
2064 @param Request A null-terminated Unicode string in
2065 <MultiConfigRequest> format. It can be NULL.
2066 If it is NULL, all configuration for the
2067 entirety of the current HII database will be reset.
2068 @param DefaultId Specifies the type of defaults to retrieve.
2070 @retval TURE The default value is set successfully.
2071 @retval FALSE The default value can't be found and set.
2076 IN CONST EFI_STRING Request
, OPTIONAL
2080 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2084 Determines if two values in config strings match.
2086 Compares the substring between StartSearchString and StopSearchString in
2087 FirstString to the substring between StartSearchString and StopSearchString
2088 in SecondString. If the two substrings match, then TRUE is returned. If the
2089 two substrings do not match, then FALSE is returned.
2091 If FirstString is NULL, then ASSERT().
2092 If SecondString is NULL, then ASSERT().
2093 If StartSearchString is NULL, then ASSERT().
2094 If StopSearchString is NULL, then ASSERT().
2096 @param FirstString Pointer to the first Null-terminated Unicode string.
2097 @param SecondString Pointer to the second Null-terminated Unicode string.
2098 @param StartSearchString Pointer to the Null-terminated Unicode string that
2099 marks the start of the value string to compare.
2100 @param StopSearchString Pointer to the Null-terminated Unicode string that
2101 marks the end of the vakue string to compare.
2103 @retval FALSE StartSearchString is not present in FirstString.
2104 @retval FALSE StartSearchString is not present in SecondString.
2105 @retval FALSE StopSearchString is not present in FirstString.
2106 @retval FALSE StopSearchString is not present in SecondString.
2107 @retval FALSE The length of the substring in FirstString is not the
2108 same length as the substring in SecondString.
2109 @retval FALSE The value string in FirstString does not matche the
2110 value string in SecondString.
2111 @retval TRUE The value string in FirstString matches the value
2112 string in SecondString.
2117 InternalHiiCompareSubString (
2118 IN CHAR16
*FirstString
,
2119 IN CHAR16
*SecondString
,
2120 IN CHAR16
*StartSearchString
,
2121 IN CHAR16
*StopSearchString
2124 CHAR16
*EndFirstString
;
2125 CHAR16
*EndSecondString
;
2127 ASSERT (FirstString
!= NULL
);
2128 ASSERT (SecondString
!= NULL
);
2129 ASSERT (StartSearchString
!= NULL
);
2130 ASSERT (StopSearchString
!= NULL
);
2132 FirstString
= StrStr (FirstString
, StartSearchString
);
2133 if (FirstString
== NULL
) {
2137 SecondString
= StrStr (SecondString
, StartSearchString
);
2138 if (SecondString
== NULL
) {
2142 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2143 if (EndFirstString
== NULL
) {
2147 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2148 if (EndSecondString
== NULL
) {
2152 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2156 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2160 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2162 If ConfigHdr is NULL, then ASSERT().
2164 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2165 @param[in] Guid GUID of the storage.
2166 @param[in] Name NAME of the storage.
2168 @retval TRUE Routing information matches <ConfigHdr>.
2169 @retval FALSE Routing information does not match <ConfigHdr>.
2174 HiiIsConfigHdrMatch (
2175 IN CONST EFI_STRING ConfigHdr
,
2176 IN CONST EFI_GUID
*Guid
, OPTIONAL
2177 IN CONST CHAR16
*Name OPTIONAL
2180 EFI_STRING CompareConfigHdr
;
2183 ASSERT (ConfigHdr
!= NULL
);
2186 // Use Guid and Name to generate a <ConfigHdr> string
2188 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2189 if (CompareConfigHdr
== NULL
) {
2196 // Compare GUID value strings
2198 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2201 if (Result
&& Name
!= NULL
) {
2203 // Compare NAME value strings
2205 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2209 // Free the <ConfigHdr> string
2211 FreePool (CompareConfigHdr
);
2217 Retrieves uncommited data from the Form Browser and converts it to a binary
2220 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2221 is an optional parameter that may be NULL.
2222 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2223 parameter that may be NULL.
2224 @param[in] BufferSize Length in bytes of buffer to hold retrived data.
2225 @param[out] Block Buffer of data to be updated.
2227 @retval FALSE The uncommitted data could not be retrieved.
2228 @retval TRUE The uncommitted data was retrieved.
2234 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2235 IN CONST CHAR16
*VariableName
, OPTIONAL
2240 EFI_STRING ResultsData
;
2242 EFI_STRING ConfigResp
;
2247 // Retrieve the results data from the Browser Callback
2249 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2250 if (ResultsData
== NULL
) {
2255 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2257 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2258 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2259 ConfigResp
= AllocateZeroPool (Size
);
2260 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2263 // Free the allocated buffer
2265 FreePool (ResultsData
);
2266 if (ConfigResp
== NULL
) {
2271 // Convert <ConfigResp> to a buffer
2273 Status
= gHiiConfigRouting
->ConfigToBlock (
2281 // Free the allocated buffer
2283 FreePool (ConfigResp
);
2285 if (EFI_ERROR (Status
)) {
2293 Updates uncommitted data in the Form Browser.
2295 If Buffer is NULL, then ASSERT().
2297 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2298 is an optional parameter that may be NULL.
2299 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2300 parameter that may be NULL.
2301 @param[in] BufferSize Length, in bytes, of Buffer.
2302 @param[in] Buffer Buffer of data to commit.
2303 @param[in] RequestElement An optional field to specify which part of the
2304 buffer data will be send back to Browser. If NULL,
2305 the whole buffer of data will be committed to
2307 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2309 @retval FALSE The uncommitted data could not be updated.
2310 @retval TRUE The uncommitted data was updated.
2316 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2317 IN CONST CHAR16
*VariableName
, OPTIONAL
2318 IN UINTN BufferSize
,
2319 IN CONST UINT8
*Buffer
,
2320 IN CONST CHAR16
*RequestElement OPTIONAL
2324 EFI_STRING ConfigRequest
;
2325 EFI_STRING ConfigResp
;
2326 EFI_STRING ResultsData
;
2328 ASSERT (Buffer
!= NULL
);
2331 // Construct <ConfigRequest>
2333 if (RequestElement
== NULL
) {
2335 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2336 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2338 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2339 ConfigRequest
= AllocateZeroPool (Size
);
2340 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2343 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2344 // followed by <RequestElement> followed by a Null-terminator
2346 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2347 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2348 ConfigRequest
= AllocateZeroPool (Size
);
2349 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2351 if (ConfigRequest
== NULL
) {
2356 // Convert <ConfigRequest> to <ConfigResp>
2358 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2359 FreePool (ConfigRequest
);
2360 if (ConfigResp
== NULL
) {
2365 // Set data in the uncommitted browser state information
2367 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2368 FreePool (ConfigResp
);
2370 return (BOOLEAN
)(ResultsData
!= NULL
);
2373 /////////////////////////////////////////
2374 /////////////////////////////////////////
2376 /////////////////////////////////////////
2377 /////////////////////////////////////////
2379 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2385 } HII_LIB_OPCODE_BUFFER
;
2388 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2390 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2391 1, // EFI_IFR_TYPE_NUM_SIZE_8
2392 2, // EFI_IFR_TYPE_NUM_SIZE_16
2393 4, // EFI_IFR_TYPE_NUM_SIZE_32
2394 8, // EFI_IFR_TYPE_NUM_SIZE_64
2395 1, // EFI_IFR_TYPE_BOOLEAN
2396 3, // EFI_IFR_TYPE_TIME
2397 4, // EFI_IFR_TYPE_DATE
2398 2 // EFI_IFR_TYPE_STRING
2402 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2403 HiiFreeOpCodeHandle().
2405 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2406 @retval Other A new OpCode handle.
2411 HiiAllocateOpCodeHandle (
2415 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2417 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2418 if (OpCodeBuffer
== NULL
) {
2421 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2422 if (OpCodeBuffer
->Buffer
== NULL
) {
2423 FreePool (OpCodeBuffer
);
2426 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2427 OpCodeBuffer
->Position
= 0;
2428 return (VOID
*)OpCodeBuffer
;
2432 Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle().
2433 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2434 Handle are also freed.
2436 If OpCodeHandle is NULL, then ASSERT().
2441 HiiFreeOpCodeHandle (
2445 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2447 ASSERT (OpCodeHandle
!= NULL
);
2449 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2450 if (OpCodeBuffer
->Buffer
!= NULL
) {
2451 FreePool (OpCodeBuffer
->Buffer
);
2453 FreePool (OpCodeBuffer
);
2458 InternalHiiOpCodeHandlePosition (
2459 IN VOID
*OpCodeHandle
2462 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2467 InternalHiiOpCodeHandleBuffer (
2468 IN VOID
*OpCodeHandle
2471 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2476 InternalHiiGrowOpCodeHandle (
2481 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2484 ASSERT (OpCodeHandle
!= NULL
);
2486 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2487 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2488 Buffer
= ReallocatePool (
2489 OpCodeBuffer
->BufferSize
,
2490 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2491 OpCodeBuffer
->Buffer
2493 if (Buffer
== NULL
) {
2496 OpCodeBuffer
->Buffer
= Buffer
;
2497 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2499 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2500 OpCodeBuffer
->Position
+= Size
;
2506 InternalHiiCreateOpCodeExtended (
2507 IN VOID
*OpCodeHandle
,
2508 IN VOID
*OpCodeTemplate
,
2510 IN UINTN OpCodeSize
,
2511 IN UINTN ExtensionSize
,
2515 EFI_IFR_OP_HEADER
*Header
;
2518 ASSERT (OpCodeTemplate
!= NULL
);
2519 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2521 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2522 Header
->OpCode
= OpCode
;
2523 Header
->Scope
= Scope
;
2524 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2525 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2526 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2531 InternalHiiCreateOpCode (
2532 IN VOID
*OpCodeHandle
,
2533 IN VOID
*OpCodeTemplate
,
2538 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2542 Append raw opcodes to an OpCodeHandle.
2544 If OpCodeHandle is NULL, then ASSERT().
2545 If RawBuffer is NULL, then ASSERT();
2547 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2548 @param[in] RawBuffer Buffer of opcodes to append.
2549 @param[in] RawBufferSize The size, in bytes, of Buffer.
2551 @retval NULL There is not enough space left in Buffer to add the opcode.
2552 @retval Other A pointer to the appended opcodes.
2557 HiiCreateRawOpCodes (
2558 IN VOID
*OpCodeHandle
,
2559 IN UINT8
*RawBuffer
,
2560 IN UINTN RawBufferSize
2565 ASSERT (RawBuffer
!= NULL
);
2567 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2568 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2572 Append opcodes from one OpCode Handle to another OpCode handle.
2574 If OpCodeHandle is NULL, then ASSERT().
2575 If RawOpCodeHandle is NULL, then ASSERT();
2577 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2578 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2580 @retval NULL There is not enough space left in Buffer to add the opcode.
2581 @retval Other A pointer to the appended opcodes.
2586 InternalHiiAppendOpCodes (
2587 IN VOID
*OpCodeHandle
,
2588 IN VOID
*RawOpCodeHandle
2591 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2593 ASSERT (RawOpCodeHandle
!= NULL
);
2595 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2596 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2600 Create EFI_IFR_END_OP opcode.
2602 If OpCodeHandle is NULL, then ASSERT().
2604 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2606 @retval NULL There is not enough space left in Buffer to add the opcode.
2607 @retval Other A pointer to the created opcode.
2612 HiiCreateEndOpCode (
2613 IN VOID
*OpCodeHandle
2618 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2622 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2624 If OpCodeHandle is NULL, then ASSERT().
2625 If Type is invalid, then ASSERT().
2626 If Flags is invalid, then ASSERT().
2628 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2629 @param[in] StringId StringId for the option
2630 @param[in] Flags Flags for the option
2631 @param[in] Type Type for the option
2632 @param[in] Value Value for the option
2634 @retval NULL There is not enough space left in Buffer to add the opcode.
2635 @retval Other A pointer to the created opcode.
2640 HiiCreateOneOfOptionOpCode (
2641 IN VOID
*OpCodeHandle
,
2648 EFI_IFR_ONE_OF_OPTION OpCode
;
2650 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2652 ZeroMem (&OpCode
, sizeof (OpCode
));
2653 OpCode
.Option
= StringId
;
2654 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2656 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2658 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, sizeof (OpCode
));
2662 Create EFI_IFR_DEFAULT_OP opcode.
2664 If OpCodeHandle is NULL, then ASSERT().
2665 If Type is invalid, then ASSERT().
2667 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2668 @param[in] DefaultId DefaultId for the default
2669 @param[in] Type Type for the default
2670 @param[in] Value Value for the default
2672 @retval NULL There is not enough space left in Buffer to add the opcode.
2673 @retval Other A pointer to the created opcode.
2678 HiiCreateDefaultOpCode (
2679 IN VOID
*OpCodeHandle
,
2680 IN UINT16 DefaultId
,
2685 EFI_IFR_DEFAULT OpCode
;
2687 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2689 ZeroMem (&OpCode
, sizeof (OpCode
));
2691 OpCode
.DefaultId
= DefaultId
;
2692 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2694 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, sizeof (OpCode
));
2698 Create EFI_IFR_GUID opcode.
2700 If OpCodeHandle is NULL, then ASSERT().
2701 If Guid is NULL, then ASSERT().
2702 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
2704 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2705 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
2706 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
2707 optional parameter that may be NULL. If this
2708 parameter is NULL, then the GUID extension
2709 region of the created opcode is filled with zeros.
2710 If this parameter is not NULL, then the GUID
2711 extension region of GuidData will be copied to
2712 the GUID extension region of the created opcode.
2713 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
2714 must be >= sizeof(EFI_IFR_GUID).
2716 @retval NULL There is not enough space left in Buffer to add the opcode.
2717 @retval Other A pointer to the created opcode.
2722 HiiCreateGuidOpCode (
2723 IN VOID
*OpCodeHandle
,
2724 IN CONST EFI_GUID
*Guid
,
2725 IN CONST VOID
*GuidOpCode
, OPTIONAL
2729 EFI_IFR_GUID OpCode
;
2730 EFI_IFR_GUID
*OpCodePointer
;
2732 ASSERT (Guid
!= NULL
);
2733 ASSERT (OpCodeSize
>= sizeof (OpCode
));
2735 ZeroMem (&OpCode
, sizeof (OpCode
));
2736 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
2738 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
2743 OpCodeSize
- sizeof (OpCode
),
2746 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
2747 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
2749 return (UINT8
*)OpCodePointer
;
2753 Create EFI_IFR_ACTION_OP opcode.
2755 If OpCodeHandle is NULL, then ASSERT().
2756 If any reserved bits are set in QuestionFlags, then ASSERT().
2758 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2759 @param[in] QuestionId Question ID
2760 @param[in] Prompt String ID for Prompt
2761 @param[in] Help String ID for Help
2762 @param[in] QuestionFlags Flags in Question Header
2763 @param[in] QuestionConfig String ID for configuration
2765 @retval NULL There is not enough space left in Buffer to add the opcode.
2766 @retval Other A pointer to the created opcode.
2771 HiiCreateActionOpCode (
2772 IN VOID
*OpCodeHandle
,
2773 IN EFI_QUESTION_ID QuestionId
,
2774 IN EFI_STRING_ID Prompt
,
2775 IN EFI_STRING_ID Help
,
2776 IN UINT8 QuestionFlags
,
2777 IN EFI_STRING_ID QuestionConfig
2780 EFI_IFR_ACTION OpCode
;
2782 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2784 ZeroMem (&OpCode
, sizeof (OpCode
));
2785 OpCode
.Question
.QuestionId
= QuestionId
;
2786 OpCode
.Question
.Header
.Prompt
= Prompt
;
2787 OpCode
.Question
.Header
.Help
= Help
;
2788 OpCode
.Question
.Flags
= QuestionFlags
;
2789 OpCode
.QuestionConfig
= QuestionConfig
;
2791 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
2795 Create EFI_IFR_SUBTITLE_OP opcode.
2797 If OpCodeHandle is NULL, then ASSERT().
2798 If any reserved bits are set in Flags, then ASSERT().
2799 If Scope > 1, then ASSERT().
2801 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2802 @param[in] Prompt String ID for Prompt
2803 @param[in] Help String ID for Help
2804 @param[in] Flags Subtitle opcode flags
2805 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
2806 0 if this opcode is within the current scope.
2808 @retval NULL There is not enough space left in Buffer to add the opcode.
2809 @retval Other A pointer to the created opcode.
2814 HiiCreateSubTitleOpCode (
2815 IN VOID
*OpCodeHandle
,
2816 IN EFI_STRING_ID Prompt
,
2817 IN EFI_STRING_ID Help
,
2822 EFI_IFR_SUBTITLE OpCode
;
2824 ASSERT (Scope
<= 1);
2825 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
2827 ZeroMem (&OpCode
, sizeof (OpCode
));
2828 OpCode
.Statement
.Prompt
= Prompt
;
2829 OpCode
.Statement
.Help
= Help
;
2830 OpCode
.Flags
= Flags
;
2832 return InternalHiiCreateOpCodeExtended (
2835 EFI_IFR_SUBTITLE_OP
,
2843 Create EFI_IFR_REF_OP opcode.
2845 If OpCodeHandle is NULL, then ASSERT().
2846 If any reserved bits are set in QuestionFlags, then ASSERT().
2848 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2849 @param[in] FormId Destination Form ID
2850 @param[in] Prompt String ID for Prompt
2851 @param[in] Help String ID for Help
2852 @param[in] QuestionFlags Flags in Question Header
2853 @param[in] QuestionId Question ID
2855 @retval NULL There is not enough space left in Buffer to add the opcode.
2856 @retval Other A pointer to the created opcode.
2861 HiiCreateGotoOpCode (
2862 IN VOID
*OpCodeHandle
,
2863 IN EFI_FORM_ID FormId
,
2864 IN EFI_STRING_ID Prompt
,
2865 IN EFI_STRING_ID Help
,
2866 IN UINT8 QuestionFlags
,
2867 IN EFI_QUESTION_ID QuestionId
2872 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2874 ZeroMem (&OpCode
, sizeof (OpCode
));
2875 OpCode
.Question
.Header
.Prompt
= Prompt
;
2876 OpCode
.Question
.Header
.Help
= Help
;
2877 OpCode
.Question
.QuestionId
= QuestionId
;
2878 OpCode
.Question
.Flags
= QuestionFlags
;
2879 OpCode
.FormId
= FormId
;
2881 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
2885 Create EFI_IFR_CHECKBOX_OP opcode.
2887 If OpCodeHandle is NULL, then ASSERT().
2888 If any reserved bits are set in QuestionFlags, then ASSERT().
2889 If any reserved bits are set in CheckBoxFlags, then ASSERT().
2891 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2892 @param[in] QuestionId Question ID
2893 @param[in] VarStoreId Storage ID
2894 @param[in] VarOffset Offset in Storage
2895 @param[in] Prompt String ID for Prompt
2896 @param[in] Help String ID for Help
2897 @param[in] QuestionFlags Flags in Question Header
2898 @param[in] CheckBoxFlags Flags for checkbox opcode
2899 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2900 is an optional parameter that may be NULL.
2902 @retval NULL There is not enough space left in Buffer to add the opcode.
2903 @retval Other A pointer to the created opcode.
2908 HiiCreateCheckBoxOpCode (
2909 IN VOID
*OpCodeHandle
,
2910 IN EFI_QUESTION_ID QuestionId
,
2911 IN EFI_VARSTORE_ID VarStoreId
,
2912 IN UINT16 VarOffset
,
2913 IN EFI_STRING_ID Prompt
,
2914 IN EFI_STRING_ID Help
,
2915 IN UINT8 QuestionFlags
,
2916 IN UINT8 CheckBoxFlags
,
2917 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2920 EFI_IFR_CHECKBOX OpCode
;
2923 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2925 ZeroMem (&OpCode
, sizeof (OpCode
));
2926 OpCode
.Question
.QuestionId
= QuestionId
;
2927 OpCode
.Question
.VarStoreId
= VarStoreId
;
2928 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2929 OpCode
.Question
.Header
.Prompt
= Prompt
;
2930 OpCode
.Question
.Header
.Help
= Help
;
2931 OpCode
.Question
.Flags
= QuestionFlags
;
2932 OpCode
.Flags
= CheckBoxFlags
;
2934 if (DefaultsOpCodeHandle
== NULL
) {
2935 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
2938 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
2939 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
2940 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
2941 HiiCreateEndOpCode (OpCodeHandle
);
2942 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
2946 Create EFI_IFR_NUMERIC_OP opcode.
2948 If OpCodeHandle is NULL, then ASSERT().
2949 If any reserved bits are set in QuestionFlags, then ASSERT().
2950 If any reserved bits are set in NumericFlags, then ASSERT().
2952 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2953 @param[in] QuestionId Question ID
2954 @param[in] VarStoreId Storage ID
2955 @param[in] VarOffset Offset in Storage
2956 @param[in] Prompt String ID for Prompt
2957 @param[in] Help String ID for Help
2958 @param[in] QuestionFlags Flags in Question Header
2959 @param[in] NumericFlags Flags for numeric opcode
2960 @param[in] Minimum Numeric minimum value
2961 @param[in] Maximum Numeric maximum value
2962 @param[in] Step Numeric step for edit
2963 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2964 is an optional parameter that may be NULL.
2966 @retval NULL There is not enough space left in Buffer to add the opcode.
2967 @retval Other A pointer to the created opcode.
2972 HiiCreateNumericOpCode (
2973 IN VOID
*OpCodeHandle
,
2974 IN EFI_QUESTION_ID QuestionId
,
2975 IN EFI_VARSTORE_ID VarStoreId
,
2976 IN UINT16 VarOffset
,
2977 IN EFI_STRING_ID Prompt
,
2978 IN EFI_STRING_ID Help
,
2979 IN UINT8 QuestionFlags
,
2980 IN UINT8 NumericFlags
,
2984 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2987 EFI_IFR_NUMERIC OpCode
;
2990 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2992 ZeroMem (&OpCode
, sizeof (OpCode
));
2993 OpCode
.Question
.QuestionId
= QuestionId
;
2994 OpCode
.Question
.VarStoreId
= VarStoreId
;
2995 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2996 OpCode
.Question
.Header
.Prompt
= Prompt
;
2997 OpCode
.Question
.Header
.Help
= Help
;
2998 OpCode
.Question
.Flags
= QuestionFlags
;
2999 OpCode
.Flags
= NumericFlags
;
3001 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
3002 case EFI_IFR_NUMERIC_SIZE_1
:
3003 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
3004 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3005 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3008 case EFI_IFR_NUMERIC_SIZE_2
:
3009 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3010 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3011 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3014 case EFI_IFR_NUMERIC_SIZE_4
:
3015 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3016 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3017 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3020 case EFI_IFR_NUMERIC_SIZE_8
:
3021 OpCode
.data
.u64
.MinValue
= Minimum
;
3022 OpCode
.data
.u64
.MaxValue
= Maximum
;
3023 OpCode
.data
.u64
.Step
= Step
;
3027 if (DefaultsOpCodeHandle
== NULL
) {
3028 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
));
3031 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3032 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
), 0, 1);
3033 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3034 HiiCreateEndOpCode (OpCodeHandle
);
3035 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3039 Create EFI_IFR_STRING_OP opcode.
3041 If OpCodeHandle is NULL, then ASSERT().
3042 If any reserved bits are set in QuestionFlags, then ASSERT().
3043 If any reserved bits are set in StringFlags, then ASSERT().
3045 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3046 @param[in] QuestionId Question ID
3047 @param[in] VarStoreId Storage ID
3048 @param[in] VarOffset Offset in Storage
3049 @param[in] Prompt String ID for Prompt
3050 @param[in] Help String ID for Help
3051 @param[in] QuestionFlags Flags in Question Header
3052 @param[in] StringFlags Flags for string opcode
3053 @param[in] MinSize String minimum length
3054 @param[in] MaxSize String maximum length
3055 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3056 is an optional parameter that may be NULL.
3058 @retval NULL There is not enough space left in Buffer to add the opcode.
3059 @retval Other A pointer to the created opcode.
3064 HiiCreateStringOpCode (
3065 IN VOID
*OpCodeHandle
,
3066 IN EFI_QUESTION_ID QuestionId
,
3067 IN EFI_VARSTORE_ID VarStoreId
,
3068 IN UINT16 VarOffset
,
3069 IN EFI_STRING_ID Prompt
,
3070 IN EFI_STRING_ID Help
,
3071 IN UINT8 QuestionFlags
,
3072 IN UINT8 StringFlags
,
3075 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3078 EFI_IFR_STRING OpCode
;
3081 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3083 ZeroMem (&OpCode
, sizeof (OpCode
));
3084 OpCode
.Question
.Header
.Prompt
= Prompt
;
3085 OpCode
.Question
.Header
.Help
= Help
;
3086 OpCode
.Question
.QuestionId
= QuestionId
;
3087 OpCode
.Question
.VarStoreId
= VarStoreId
;
3088 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3089 OpCode
.Question
.Flags
= QuestionFlags
;
3090 OpCode
.MinSize
= MinSize
;
3091 OpCode
.MaxSize
= MaxSize
;
3092 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3094 if (DefaultsOpCodeHandle
== NULL
) {
3095 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3098 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3099 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3100 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3101 HiiCreateEndOpCode (OpCodeHandle
);
3102 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3106 Create EFI_IFR_ONE_OF_OP opcode.
3108 If OpCodeHandle is NULL, then ASSERT().
3109 If any reserved bits are set in QuestionFlags, then ASSERT().
3110 If any reserved bits are set in OneOfFlags, then ASSERT().
3112 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3113 @param[in] QuestionId Question ID
3114 @param[in] VarStoreId Storage ID
3115 @param[in] VarOffset Offset in Storage
3116 @param[in] Prompt String ID for Prompt
3117 @param[in] Help String ID for Help
3118 @param[in] QuestionFlags Flags in Question Header
3119 @param[in] OneOfFlags Flags for oneof opcode
3120 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3121 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3122 is an optional parameter that may be NULL.
3124 @retval NULL There is not enough space left in Buffer to add the opcode.
3125 @retval Other A pointer to the created opcode.
3130 HiiCreateOneOfOpCode (
3131 IN VOID
*OpCodeHandle
,
3132 IN EFI_QUESTION_ID QuestionId
,
3133 IN EFI_VARSTORE_ID VarStoreId
,
3134 IN UINT16 VarOffset
,
3135 IN EFI_STRING_ID Prompt
,
3136 IN EFI_STRING_ID Help
,
3137 IN UINT8 QuestionFlags
,
3138 IN UINT8 OneOfFlags
,
3139 IN VOID
*OptionsOpCodeHandle
,
3140 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3143 EFI_IFR_ONE_OF OpCode
;
3146 ASSERT (OptionsOpCodeHandle
!= NULL
);
3147 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3149 ZeroMem (&OpCode
, sizeof (OpCode
));
3150 OpCode
.Question
.Header
.Prompt
= Prompt
;
3151 OpCode
.Question
.Header
.Help
= Help
;
3152 OpCode
.Question
.QuestionId
= QuestionId
;
3153 OpCode
.Question
.VarStoreId
= VarStoreId
;
3154 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3155 OpCode
.Question
.Flags
= QuestionFlags
;
3156 OpCode
.Flags
= OneOfFlags
;
3158 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3159 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, sizeof (OpCode
), 0, 1);
3160 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3161 if (DefaultsOpCodeHandle
!= NULL
) {
3162 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3164 HiiCreateEndOpCode (OpCodeHandle
);
3165 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3169 Create EFI_IFR_ORDERED_LIST_OP opcode.
3171 If OpCodeHandle is NULL, then ASSERT().
3172 If any reserved bits are set in QuestionFlags, then ASSERT().
3173 If any reserved bits are set in OrderedListFlags, then ASSERT().
3175 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3176 @param[in] QuestionId Question ID
3177 @param[in] VarStoreId Storage ID
3178 @param[in] VarOffset Offset in Storage
3179 @param[in] Prompt String ID for Prompt
3180 @param[in] Help String ID for Help
3181 @param[in] QuestionFlags Flags in Question Header
3182 @param[in] OrderedListFlags Flags for ordered list opcode
3183 @param[in] DataType Type for option value
3184 @param[in] MaxContainers Maximum count for options in this ordered list
3185 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3186 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3187 is an optional parameter that may be NULL.
3189 @retval NULL There is not enough space left in Buffer to add the opcode.
3190 @retval Other A pointer to the created opcode.
3195 HiiCreateOrderedListOpCode (
3196 IN VOID
*OpCodeHandle
,
3197 IN EFI_QUESTION_ID QuestionId
,
3198 IN EFI_VARSTORE_ID VarStoreId
,
3199 IN UINT16 VarOffset
,
3200 IN EFI_STRING_ID Prompt
,
3201 IN EFI_STRING_ID Help
,
3202 IN UINT8 QuestionFlags
,
3203 IN UINT8 OrderedListFlags
,
3205 IN UINT8 MaxContainers
,
3206 IN VOID
*OptionsOpCodeHandle
,
3207 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3210 EFI_IFR_ORDERED_LIST OpCode
;
3213 ASSERT (OptionsOpCodeHandle
!= NULL
);
3214 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3216 ZeroMem (&OpCode
, sizeof (OpCode
));
3217 OpCode
.Question
.Header
.Prompt
= Prompt
;
3218 OpCode
.Question
.Header
.Help
= Help
;
3219 OpCode
.Question
.QuestionId
= QuestionId
;
3220 OpCode
.Question
.VarStoreId
= VarStoreId
;
3221 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3222 OpCode
.Question
.Flags
= QuestionFlags
;
3223 OpCode
.MaxContainers
= MaxContainers
;
3224 OpCode
.Flags
= OrderedListFlags
;
3226 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3227 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3228 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3229 if (DefaultsOpCodeHandle
!= NULL
) {
3230 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3232 HiiCreateEndOpCode (OpCodeHandle
);
3233 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3237 This is the internal worker function to update the data in
3238 a form specified by FormSetGuid, FormId and Label.
3240 @param FormSetGuid The optional Formset GUID.
3241 @param FormId The Form ID.
3242 @param Package The package header.
3244 @param TempPacakge The resultant package.
3246 @retval EFI_SUCCESS The function completes successfully.
3251 InternalHiiUpdateFormPackageData (
3252 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3253 IN EFI_FORM_ID FormId
,
3254 IN EFI_HII_PACKAGE_HEADER
*Package
,
3255 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3256 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3257 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3262 EFI_HII_PACKAGE_HEADER PackageHeader
;
3264 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3265 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3269 UINTN UpdatePackageLength
;
3271 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3272 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3273 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3275 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3276 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3277 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3278 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3282 while (Offset
< PackageHeader
.Length
) {
3283 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3284 BufferPos
+= IfrOpHdr
->Length
;
3285 UpdatePackageLength
+= IfrOpHdr
->Length
;
3288 // Find the matched FormSet and Form
3290 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3291 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3296 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
) {
3297 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3305 // The matched Form is found, and Update data in this form
3307 if (GetFormSet
&& GetForm
) {
3308 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3309 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3310 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3312 // Remove the original data when End OpCode buffer exist.
3314 if (OpCodeBufferEnd
!= NULL
) {
3315 Offset
+= IfrOpHdr
->Length
;
3316 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3317 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3318 while (Offset
< PackageHeader
.Length
) {
3320 // Search the matched end opcode
3322 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3323 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3327 // Go to the next Op-Code
3329 Offset
+= IfrOpHdr
->Length
;
3330 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3333 if (Offset
>= PackageHeader
.Length
) {
3335 // The end opcode is not found.
3337 return EFI_NOT_FOUND
;
3342 // Insert the updated data
3344 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3345 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3346 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3347 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3349 if (OpCodeBufferEnd
!= NULL
) {
3351 // Add the end opcode
3353 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3354 BufferPos
+= IfrOpHdr
->Length
;
3355 UpdatePackageLength
+= IfrOpHdr
->Length
;
3359 // Copy the left package data.
3361 Offset
+= IfrOpHdr
->Length
;
3362 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3363 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3374 // Go to the next Op-Code
3376 Offset
+= IfrOpHdr
->Length
;
3377 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3382 // The updated opcode buffer is not found.
3384 return EFI_NOT_FOUND
;
3387 // Update the package length.
3389 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3390 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3396 This function updates a form that has previously been registered with the HII
3397 Database. This function will perform at most one update operation.
3399 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3400 comparisons of IFR opcodes are performed from the beginning of the form being
3401 updated until an IFR opcode is found that exactly matches the first IFR opcode
3402 specifed by StartOpCodeHandle. The following rules are used to determine if
3403 an insert, replace, or delete operation is performed.
3405 1) If no matches are found, then NULL is returned.
3406 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3407 from StartOpcodeHandle except the first opcode are inserted immediately after
3408 the matching IFR opcode in the form beng updated.
3409 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3410 from the matching IFR opcode until an IFR opcode exatly matches the first
3411 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3412 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3413 is found, then all of the IFR opcodes between the start match and the end
3414 match are deleted from the form being updated and all of the IFR opcodes
3415 from StartOpcodeHandle except the first opcode are inserted immediately after
3416 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3417 IFR instruction, then the result of ths operation will delete all of the IFR
3418 opcodes between the start end matches.
3420 If HiiHandle is NULL, then ASSERT().
3421 If StartOpCodeHandle is NULL, then ASSERT().
3423 @param[in] HiiHandle The HII Handle of the form to update.
3424 @param[in] FormSetGuid The Formset GUID of the form to update. This
3425 is an optional parameter that may be NULL.
3426 If it is NULL, all FormSet will be updated.
3427 @param[in] FormId The ID of the form to update.
3428 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
3429 opcodes to be inserted or replaced in the form.
3430 The first IFR instruction in StartOpCodeHandle
3431 is used to find matching IFR opcode in the
3433 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
3434 that marks the end of a replace operation in
3435 the form. This is an optional parameter that
3436 may be NULL. If it is NULL, then an the IFR
3437 opcodes specified by StartOpCodeHandle are
3438 inserted into the form.
3440 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
3441 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
3442 1) The form specified by HiiHandle, FormSetGuid,
3443 and FormId could not be found in the HII Database.
3444 2) No IFR opcodes in the target form match the first
3445 IFR opcode in StartOpCodeHandle.
3446 3) EndOpCOde is not NULL, and no IFR opcodes in the
3447 target form following a matching start opcode match
3448 the first IFR opcode in EndOpCodeHandle.
3449 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
3455 IN EFI_HII_HANDLE HiiHandle
,
3456 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3457 IN EFI_FORM_ID FormId
,
3458 IN VOID
*StartOpcodeHandle
,
3459 IN VOID
*EndOpcodeHandle OPTIONAL
3463 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
3464 UINT32 PackageListLength
;
3466 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
3468 UINT8
*UpdateBufferPos
;
3469 EFI_HII_PACKAGE_HEADER
*Package
;
3470 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
3471 EFI_HII_PACKAGE_HEADER PackageHeader
;
3473 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
3474 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
3477 // Input update data can't be NULL.
3479 ASSERT (HiiHandle
!= NULL
);
3480 ASSERT (StartOpcodeHandle
!= NULL
);
3481 UpdatePackageList
= NULL
;
3483 HiiPackageList
= NULL
;
3486 // Restrive buffer data from Opcode Handle
3488 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpcodeHandle
;
3489 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpcodeHandle
;
3492 // Get the orginal package list
3495 HiiPackageList
= NULL
;
3496 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3498 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
3500 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3504 HiiPackageList
= AllocatePool (BufferSize
);
3505 if (HiiPackageList
== NULL
) {
3506 Status
= EFI_OUT_OF_RESOURCES
;
3510 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3511 if (EFI_ERROR (Status
)) {
3516 // Calculate and allocate space for retrieval of IFR data
3518 BufferSize
+= OpCodeBufferStart
->Position
;
3519 UpdatePackageList
= AllocateZeroPool (BufferSize
);
3520 if (UpdatePackageList
== NULL
) {
3521 Status
= EFI_OUT_OF_RESOURCES
;
3526 // Allocate temp buffer to store the temp updated package buffer
3528 TempPacakge
= AllocateZeroPool (BufferSize
);
3529 if (TempPacakge
== NULL
) {
3530 Status
= EFI_OUT_OF_RESOURCES
;
3534 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
3537 // Copy the package list header
3539 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
3540 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3543 // Go through each package to find the matched pacakge and update one by one
3546 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3547 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
3548 while (Offset
< PackageListLength
) {
3549 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
3550 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3551 Offset
+= Package
->Length
;
3553 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
3555 // Check this package is the matched package.
3557 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
3559 // The matched package is found. Its pacakge buffer will be updated by the input new data.
3561 if (!EFI_ERROR(Status
)) {
3567 // Add updated package buffer
3569 Package
= TempPacakge
;
3574 // Add pacakge buffer
3576 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3577 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
3578 UpdateBufferPos
+= PackageHeader
.Length
;
3583 // Update package list length
3585 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
3586 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
3589 // Update Pacakge to show form
3591 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
3594 // Not matched form is found and updated.
3596 Status
= EFI_NOT_FOUND
;
3600 if (HiiPackageList
!= NULL
) {
3601 FreePool (HiiPackageList
);
3604 if (UpdatePackageList
!= NULL
) {
3605 FreePool (UpdatePackageList
);
3608 if (TempPacakge
!= NULL
) {
3609 FreePool (TempPacakge
);