2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2009, 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 and DeviceHandle, then NULL is returned. If there
109 are not enough resources to perform the registration, then NULL is returned.
110 If an empty list of packages is passed in, then NULL is returned. If the size of
111 the list of 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
,
150 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
151 EFI_HII_HANDLE HiiHandle
;
155 ASSERT (PackageListGuid
!= NULL
);
158 // Calculate the length of all the packages in the variable argument list
160 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
161 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
166 // If there are no packages in the variable argument list or all the packages
167 // are empty, then return a NULL HII Handle
174 // Add the length of the Package List Header and the terminating Package Header
176 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
179 // Allocate the storage for the entire Package List
181 PackageListHeader
= AllocateZeroPool (Length
);
184 // If the Package List can not be allocated, then return a NULL HII Handle
186 if (PackageListHeader
== NULL
) {
191 // Fill in the GUID and Length of the Package List Header
193 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
194 PackageListHeader
->PackageLength
= Length
;
197 // Initialize a pointer to the beginning if the Package List data
199 Data
= (UINT8
*)(PackageListHeader
+ 1);
202 // Copy the data from each package in the variable argument list
204 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
205 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
206 CopyMem (Data
, Package
+ 1, Length
);
212 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
214 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
217 // Register the package list with the HII Database
219 Status
= gHiiDatabase
->NewPackageList (
225 if (EFI_ERROR (Status
)) {
230 // Free the allocated package list
232 FreePool (PackageListHeader
);
235 // Return the new HII Handle
241 Removes a package list from the HII database.
243 If HiiHandle is NULL, then ASSERT.
244 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
246 @param[in] HiiHandle The handle that was previously registered in the HII database
252 IN EFI_HII_HANDLE HiiHandle
257 ASSERT (HiiHandle
!= NULL
);
258 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
259 ASSERT_EFI_ERROR (Status
);
264 Retrieves the array of all the HII Handles or the HII handles of a specific
265 package list GUID in the HII Database.
266 This array is terminated with a NULL HII Handle.
267 This function allocates the returned array using AllocatePool().
268 The caller is responsible for freeing the array with FreePool().
270 @param[in] PackageListGuid An optional parameter that is used to request
271 HII Handles associated with a specific
272 Package List GUID. If this parameter is NULL,
273 then all the HII Handles in the HII Database
274 are returned. If this parameter is not NULL,
275 then zero or more HII Handles associated with
276 PackageListGuid are returned.
278 @retval NULL No HII handles were found in the HII database
279 @retval NULL The array of HII Handles could not be retrieved
280 @retval Other A pointer to the NULL terminated array of HII Handles
286 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
290 UINTN HandleBufferLength
;
291 EFI_HII_HANDLE TempHiiHandleBuffer
;
292 EFI_HII_HANDLE
*HiiHandleBuffer
;
298 // Retrieve the size required for the buffer of all HII handles.
300 HandleBufferLength
= 0;
301 Status
= gHiiDatabase
->ListPackageLists (
303 EFI_HII_PACKAGE_TYPE_ALL
,
310 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
311 // then there are no HII handles in the HII database. If ListPackageLists()
312 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
313 // handles in the HII database.
315 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
317 // Return NULL if the size can not be retrieved, or if there are no HII
318 // handles in the HII Database
324 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
326 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
327 if (HiiHandleBuffer
== NULL
) {
329 // Return NULL if allocation fails.
335 // Retrieve the array of HII Handles in the HII Database
337 Status
= gHiiDatabase
->ListPackageLists (
339 EFI_HII_PACKAGE_TYPE_ALL
,
344 if (EFI_ERROR (Status
)) {
346 // Free the buffer and return NULL if the HII handles can not be retrieved.
348 FreePool (HiiHandleBuffer
);
352 if (PackageListGuid
== NULL
) {
354 // Return the NULL terminated array of HII handles in the HII Database
356 return HiiHandleBuffer
;
358 for (Index1
= 0, Index2
= 0; HiiHandleBuffer
[Index1
] != NULL
; Index1
++) {
359 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index1
], &Guid
);
360 ASSERT_EFI_ERROR (Status
);
361 if (CompareGuid (&Guid
, PackageListGuid
)) {
362 HiiHandleBuffer
[Index2
++] = HiiHandleBuffer
[Index1
];
366 HiiHandleBuffer
[Index2
] = NULL
;
367 return HiiHandleBuffer
;
369 FreePool (HiiHandleBuffer
);
376 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
377 hex digits that appear between a '=' and a '&' in a config string.
379 If String is NULL, then ASSERT().
381 @param[in] String Pointer to a Null-terminated Unicode string.
383 @return Pointer to the Null-terminated Unicode result string.
388 InternalHiiLowerConfigString (
389 IN EFI_STRING ConfigString
395 ASSERT (ConfigString
!= NULL
);
398 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
400 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
401 if (*String
== L
'=') {
403 } else if (*String
== L
'&') {
405 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
406 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
414 Uses the BlockToConfig() service of the Config Routing Protocol to
415 convert <ConfigRequest> and a buffer to a <ConfigResp>
417 If ConfigRequest is NULL, then ASSERT().
418 If Block is NULL, then ASSERT().
420 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
421 @param[in] Block Pointer to a block of data.
422 @param[in] BlockSize The zie, in bytes, of Block.
424 @retval NULL The <ConfigResp> string could not be generated.
425 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
430 InternalHiiBlockToConfig (
431 IN CONST EFI_STRING ConfigRequest
,
432 IN CONST UINT8
*Block
,
437 EFI_STRING ConfigResp
;
440 ASSERT (ConfigRequest
!= NULL
);
441 ASSERT (Block
!= NULL
);
444 // Convert <ConfigRequest> to <ConfigResp>
446 Status
= gHiiConfigRouting
->BlockToConfig (
454 if (EFI_ERROR (Status
)) {
461 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
462 or set uncommitted data. If sata i being retrieved, then the buffer is
463 allocated using AllocatePool(). The caller is then responsible for freeing
464 the buffer using FreePool().
466 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
467 is an optional parameter that may be NULL.
468 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
469 parameter that may be NULL.
470 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
471 of uncommited data to set. If this parameter is NULL,
472 then the caller is requesting to get the uncommited data
473 from the Form Browser.
475 @retval NULL The uncommitted data could not be retrieved.
476 @retval Other A pointer to a buffer containing the uncommitted data.
481 InternalHiiBrowserCallback (
482 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
483 IN CONST CHAR16
*VariableName
, OPTIONAL
484 IN CONST EFI_STRING SetResultsData OPTIONAL
488 UINTN ResultsDataSize
;
489 EFI_STRING ResultsData
;
490 CHAR16 TempResultsData
;
495 if (mUefiFormBrowser2
== NULL
) {
496 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
497 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
504 if (SetResultsData
!= NULL
) {
506 // Request to to set data in the uncommitted browser state information
508 ResultsData
= SetResultsData
;
511 // Retrieve the length of the buffer required ResultsData from the Browser Callback
513 Status
= mUefiFormBrowser2
->BrowserCallback (
522 if (!EFI_ERROR (Status
)) {
524 // No Resluts Data, only allocate one char for '\0'
526 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
530 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
535 // Allocate the ResultsData buffer
537 ResultsData
= AllocateZeroPool (ResultsDataSize
);
538 if (ResultsData
== NULL
) {
544 // Retrieve or set the ResultsData from the Browser Callback
546 Status
= mUefiFormBrowser2
->BrowserCallback (
550 (BOOLEAN
)(SetResultsData
== NULL
),
554 if (EFI_ERROR (Status
)) {
562 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
563 information that includes a GUID, an optional Unicode string name, and a device
564 path. The string returned is allocated with AllocatePool(). The caller is
565 responsible for freeing the allocated string with FreePool().
567 The format of a <ConfigHdr> is as follows:
569 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
571 @param[in] Guid Pointer to an EFI_GUID that is the routing information
572 GUID. Each of the 16 bytes in Guid is converted to
573 a 2 Unicode character hexidecimal string. This is
574 an optional parameter that may be NULL.
575 @param[in] Name Pointer to a Null-terminated Unicode string that is
576 the routing information NAME. This is an optional
577 parameter that may be NULL. Each 16-bit Unicode
578 character in Name is converted to a 4 character Unicode
580 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
581 that is the routing information PATH. Each byte of
582 the Device Path associated with DriverHandle is converted
583 to a 2 Unicode character hexidecimal string.
585 @retval NULL DriverHandle does not support the Device Path Protocol.
586 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
591 HiiConstructConfigHdr (
592 IN CONST EFI_GUID
*Guid
, OPTIONAL
593 IN CONST CHAR16
*Name
, OPTIONAL
594 IN EFI_HANDLE DriverHandle
598 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
599 UINTN DevicePathSize
;
601 CHAR16
*ReturnString
;
606 // Compute the length of Name in Unicode characters.
607 // If Name is NULL, then the length is 0.
611 NameLength
= StrLen (Name
);
617 // Retrieve DevicePath Protocol associated with DriverHandle
619 if (DriverHandle
!= NULL
) {
620 DevicePath
= DevicePathFromHandle (DriverHandle
);
621 if (DevicePath
== NULL
) {
625 // Compute the size of the device path in bytes
627 DevicePathSize
= GetDevicePathSize (DevicePath
);
631 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
632 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
634 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
635 if (String
== NULL
) {
640 // Start with L"GUID="
642 ReturnString
= StrCpy (String
, L
"GUID=");
643 String
+= StrLen (String
);
647 // Append Guid converted to <HexCh>32
649 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
650 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
657 StrCpy (String
, L
"&NAME=");
658 String
+= StrLen (String
);
662 // Append Name converted to <Char>NameLength
664 for (; *Name
!= L
'\0'; Name
++) {
665 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
672 StrCpy (String
, L
"&PATH=");
673 String
+= StrLen (String
);
676 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
678 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
679 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
683 // Null terminate the Unicode string
688 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
690 return InternalHiiLowerConfigString (ReturnString
);
694 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
695 to binary buffer from <ConfigHdr>.
697 This is a internal function.
699 @param String UEFI configuration string.
700 @param Flag Flag specifies what type buffer will be retrieved.
701 @param Buffer Binary of Guid, Name or Device path.
703 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
704 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
705 @retval EFI_SUCCESS The buffer data is retrieved and translated to
710 InternalHiiGetBufferFromString (
711 IN EFI_STRING String
,
717 EFI_STRING ConfigHdr
;
724 if (String
== NULL
|| Buffer
== NULL
) {
725 return EFI_INVALID_PARAMETER
;
732 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
733 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
735 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
738 case GUID_CONFIG_STRING_TYPE
:
739 case PATH_CONFIG_STRING_TYPE
:
741 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
742 // as the device path and Guid resides in RAM memory.
743 // Translate the data into binary.
745 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
746 if (DataBuffer
== NULL
) {
747 return EFI_OUT_OF_RESOURCES
;
750 // Convert binary byte one by one
752 ZeroMem (TemStr
, sizeof (TemStr
));
753 for (Index
= 0; Index
< Length
; Index
++) {
754 TemStr
[0] = ConfigHdr
[Index
];
755 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
756 if ((Index
& 1) == 0) {
757 DataBuffer
[Index
/2] = DigitUint8
;
759 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
763 *Buffer
= DataBuffer
;
766 case NAME_CONFIG_STRING_TYPE
:
768 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
772 // Add the tailling char L'\0'
774 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
775 if (DataBuffer
== NULL
) {
776 return EFI_OUT_OF_RESOURCES
;
779 // Convert character one by one
781 StringPtr
= (CHAR16
*) DataBuffer
;
782 ZeroMem (TemStr
, sizeof (TemStr
));
783 for (Index
= 0; Index
< Length
; Index
+= 4) {
784 StrnCpy (TemStr
, ConfigHdr
+ Index
, 4);
785 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
788 // Add tailing L'\0' character
790 StringPtr
[Index
/4] = L
'\0';
792 *Buffer
= DataBuffer
;
796 return EFI_INVALID_PARAMETER
;
804 This function checks VarOffset and VarWidth is in the block range.
806 @param BlockArray The block array is to be checked.
807 @param VarOffset Offset of var to the structure
808 @param VarWidth Width of var.
810 @retval TRUE This Var is in the block range.
811 @retval FALSE This Var is not in the block range.
815 IN IFR_BLOCK_DATA
*BlockArray
,
821 IFR_BLOCK_DATA
*BlockData
;
824 // No Request Block array, all vars are got.
826 if (BlockArray
== NULL
) {
831 // Check the input var is in the request block range.
833 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
834 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
835 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
844 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
846 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
848 @param ValueString String in <BlockConfig> format and points to the
849 first character of <Number>.
850 @param ValueData The output value. Caller takes the responsibility
852 @param ValueLength Length of the <Number>, in characters.
854 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
856 @retval EFI_SUCCESS Value of <Number> is outputted in Number
862 InternalHiiGetValueOfNumber (
863 IN EFI_STRING ValueString
,
864 OUT UINT8
**ValueData
,
865 OUT UINTN
*ValueLength
868 EFI_STRING StringPtr
;
875 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
876 ASSERT (*ValueString
!= L
'\0');
879 // Get the length of value string
881 StringPtr
= ValueString
;
882 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
885 Length
= StringPtr
- ValueString
;
888 // Allocate buffer to store the value
890 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
892 return EFI_OUT_OF_RESOURCES
;
896 // Convert character one by one to the value buffer
898 ZeroMem (TemStr
, sizeof (TemStr
));
899 for (Index
= 0; Index
< Length
; Index
++) {
900 TemStr
[0] = ValueString
[Length
- Index
- 1];
901 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
902 if ((Index
& 1) == 0) {
903 Buf
[Index
/2] = DigitUint8
;
905 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
910 // Set the converted value and string length.
913 *ValueLength
= Length
;
918 This internal function parses IFR data to validate current setting.
920 @param ConfigResp ConfigResp string contains the current setting.
921 @param HiiPackageList Point to Hii package list.
922 @param PackageListLength The length of the pacakge.
923 @param VarGuid Guid of the buffer storage.
924 @param VarName Name of the buffer storage.
926 @retval EFI_SUCCESS The current setting is valid.
927 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
928 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
932 InternalHiiValidateCurrentSetting (
933 IN EFI_STRING ConfigResp
,
934 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
935 IN UINTN PackageListLength
,
936 IN EFI_GUID
*VarGuid
,
940 IFR_BLOCK_DATA
*CurrentBlockArray
;
941 IFR_BLOCK_DATA
*BlockData
;
942 IFR_BLOCK_DATA
*NewBlockData
;
943 IFR_BLOCK_DATA VarBlockData
;
944 EFI_STRING StringPtr
;
954 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
955 UINT32 PackageOffset
;
958 EFI_IFR_OP_HEADER
*IfrOpHdr
;
959 EFI_IFR_VARSTORE
*IfrVarStore
;
960 EFI_IFR_ONE_OF
*IfrOneOf
;
961 EFI_IFR_NUMERIC
*IfrNumeric
;
962 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
963 EFI_IFR_CHECKBOX
*IfrCheckBox
;
964 EFI_IFR_STRING
*IfrString
;
969 // 1. Get the current setting to current block data array and Convert them into VarBuffer
973 // Skip ConfigHdr string
975 StringPtr
= ConfigResp
;
976 StringPtr
= StrStr (ConfigResp
, L
"&OFFSET");
977 if (StringPtr
== NULL
) {
979 // No ConfigBlock value is requied to be validated.
980 // EFI_SUCCESS directly return.
986 // Initialize the local variables.
990 Status
= EFI_SUCCESS
;
994 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
995 VarBuffer
= AllocateZeroPool (MaxBufferSize
);
996 if (VarBuffer
== NULL
) {
997 return EFI_OUT_OF_RESOURCES
;
1001 // Init CurrentBlockArray
1003 CurrentBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1004 if (CurrentBlockArray
== NULL
) {
1005 Status
= EFI_OUT_OF_RESOURCES
;
1008 InitializeListHead (&CurrentBlockArray
->Entry
);
1011 // Parse each <RequestElement> if exists
1012 // Only <BlockName> format is supported by this help function.
1013 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1015 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1017 // Skip the &OFFSET= string
1019 StringPtr
+= StrLen (L
"&OFFSET=");
1024 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1025 if (EFI_ERROR (Status
)) {
1032 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1034 FreePool (TmpBuffer
);
1037 StringPtr
+= Length
;
1038 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1039 Status
= EFI_INVALID_PARAMETER
;
1042 StringPtr
+= StrLen (L
"&WIDTH=");
1047 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1048 if (EFI_ERROR (Status
)) {
1055 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1057 FreePool (TmpBuffer
);
1060 StringPtr
+= Length
;
1061 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1062 Status
= EFI_INVALID_PARAMETER
;
1066 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1067 Status
= EFI_INVALID_PARAMETER
;
1070 StringPtr
+= StrLen (L
"&VALUE=");
1075 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1076 if (EFI_ERROR (Status
)) {
1080 StringPtr
+= Length
;
1081 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1082 Status
= EFI_INVALID_PARAMETER
;
1087 // Check whether VarBuffer is enough
1089 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1090 VarBuffer
= ReallocatePool (
1092 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1095 if (VarBuffer
== NULL
) {
1096 Status
= EFI_OUT_OF_RESOURCES
;
1099 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1103 // Update the Block with configuration info
1105 CopyMem (VarBuffer
+ Offset
, TmpBuffer
, Width
);
1106 FreePool (TmpBuffer
);
1110 // Set new Block Data
1112 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1113 if (NewBlockData
== NULL
) {
1114 Status
= EFI_OUT_OF_RESOURCES
;
1117 NewBlockData
->Offset
= Offset
;
1118 NewBlockData
->Width
= Width
;
1121 // Insert the new block data into the block data array.
1123 for (Link
= CurrentBlockArray
->Entry
.ForwardLink
; Link
!= &CurrentBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1124 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1125 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1126 if (NewBlockData
->Width
> BlockData
->Width
) {
1127 BlockData
->Width
= NewBlockData
->Width
;
1129 FreePool (NewBlockData
);
1131 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1133 // Insert new block data as the previous one of this link.
1135 InsertTailList (Link
, &NewBlockData
->Entry
);
1141 // Insert new block data into the array tail.
1143 if (Link
== &CurrentBlockArray
->Entry
) {
1144 InsertTailList (Link
, &NewBlockData
->Entry
);
1148 // If '\0', parsing is finished.
1150 if (*StringPtr
== 0) {
1154 // Go to next ConfigBlock
1159 // Merge the aligned block data into the single block data.
1161 Link
= CurrentBlockArray
->Entry
.ForwardLink
;
1162 while ((Link
!= &CurrentBlockArray
->Entry
) && (Link
->ForwardLink
!= &CurrentBlockArray
->Entry
)) {
1163 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1164 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1165 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1166 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1167 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1169 RemoveEntryList (Link
->ForwardLink
);
1170 FreePool (NewBlockData
);
1173 Link
= Link
->ForwardLink
;
1176 if (IsListEmpty (&CurrentBlockArray
->Entry
)) {
1177 Status
= EFI_SUCCESS
;
1182 // 2. Check IFR value is in block data, then Validate Vaule
1184 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1187 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1188 while (PackageOffset
< PackageListLength
) {
1189 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1192 // Parse IFR opcode from the form package.
1194 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1195 IfrOffset
= sizeof (PacakgeHeader
);
1196 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1197 while (IfrOffset
< PacakgeHeader
.Length
) {
1198 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1200 // Validate current setting to the value built in IFR opcode
1202 switch (IfrOpHdr
->OpCode
) {
1203 case EFI_IFR_VARSTORE_OP
:
1205 // VarStoreId has been found. No further found.
1207 if (IfrVarStore
!= NULL
) {
1211 // Find the matched VarStoreId to the input VarGuid and VarName
1213 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1214 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1215 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1216 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1217 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1222 // The matched VarStore is found.
1224 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1231 case EFI_IFR_FORM_OP
:
1233 // Check the matched VarStoreId is found.
1235 if (IfrVarStore
== NULL
) {
1236 Status
= EFI_SUCCESS
;
1240 case EFI_IFR_ONE_OF_OP
:
1242 // Check whether current value is the one of option.
1246 // OneOf question is not in IFR Form. This IFR form is not valid.
1248 if (IfrVarStore
== NULL
) {
1249 Status
= EFI_INVALID_PARAMETER
;
1253 // Check whether this question is for the requested varstore.
1255 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1256 if (IfrOneOf
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1261 // Get Offset by Question header and Width by DataType Flags
1263 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1264 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1266 // Check whether this question is in current block array.
1268 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1270 // This question is not in the current configuration string. Skip it.
1275 // Check this var question is in the var storage
1277 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1279 // This question exceeds the var store size.
1281 Status
= EFI_INVALID_PARAMETER
;
1286 // Get the current value for oneof opcode
1289 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1291 // Set Block Data, to be checked in the following Oneof option opcode.
1293 VarBlockData
.Offset
= Offset
;
1294 VarBlockData
.Width
= Width
;
1295 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1296 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1298 case EFI_IFR_NUMERIC_OP
:
1300 // Check the current value is in the numeric range.
1304 // Numeric question is not in IFR Form. This IFR form is not valid.
1306 if (IfrVarStore
== NULL
) {
1307 Status
= EFI_INVALID_PARAMETER
;
1311 // Check whether this question is for the requested varstore.
1313 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1314 if (IfrNumeric
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1319 // Get Offset by Question header and Width by DataType Flags
1321 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1322 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1324 // Check whether this question is in current block array.
1326 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1328 // This question is not in the current configuration string. Skip it.
1333 // Check this var question is in the var storage
1335 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1337 // This question exceeds the var store size.
1339 Status
= EFI_INVALID_PARAMETER
;
1344 // Check the current value is in the numeric range.
1347 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1348 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1349 case EFI_IFR_NUMERIC_SIZE_1
:
1350 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1352 // Not in the valid range.
1354 Status
= EFI_INVALID_PARAMETER
;
1358 case EFI_IFR_NUMERIC_SIZE_2
:
1359 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1361 // Not in the valid range.
1363 Status
= EFI_INVALID_PARAMETER
;
1367 case EFI_IFR_NUMERIC_SIZE_4
:
1368 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1370 // Not in the valid range.
1372 Status
= EFI_INVALID_PARAMETER
;
1376 case EFI_IFR_NUMERIC_SIZE_8
:
1377 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1379 // Not in the valid range.
1381 Status
= EFI_INVALID_PARAMETER
;
1388 case EFI_IFR_CHECKBOX_OP
:
1390 // Check value is BOOLEAN type, only 0 and 1 is valid.
1394 // CheckBox question is not in IFR Form. This IFR form is not valid.
1396 if (IfrVarStore
== NULL
) {
1397 Status
= EFI_INVALID_PARAMETER
;
1402 // Check whether this question is for the requested varstore.
1404 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1405 if (IfrCheckBox
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1410 // Get Offset by Question header
1412 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1413 Width
= sizeof (BOOLEAN
);
1415 // Check whether this question is in current block array.
1417 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1419 // This question is not in the current configuration string. Skip it.
1424 // Check this var question is in the var storage
1426 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1428 // This question exceeds the var store size.
1430 Status
= EFI_INVALID_PARAMETER
;
1435 // Boolean type, only 1 and 0 is valid.
1437 if (*(VarBuffer
+ Offset
) > 1) {
1438 Status
= EFI_INVALID_PARAMETER
;
1443 case EFI_IFR_STRING_OP
:
1445 // Check current string length is less than maxsize
1449 // CheckBox question is not in IFR Form. This IFR form is not valid.
1451 if (IfrVarStore
== NULL
) {
1452 Status
= EFI_INVALID_PARAMETER
;
1457 // Check whether this question is for the requested varstore.
1459 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1460 if (IfrString
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1465 // Get Offset/Width by Question header and OneOf Flags
1467 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1468 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1470 // Check whether this question is in current block array.
1472 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1474 // This question is not in the current configuration string. Skip it.
1479 // Check this var question is in the var storage
1481 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1483 // This question exceeds the var store size.
1485 Status
= EFI_INVALID_PARAMETER
;
1490 // Check current string length is less than maxsize
1492 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1493 Status
= EFI_INVALID_PARAMETER
;
1497 case EFI_IFR_ONE_OF_OPTION_OP
:
1499 // Opcode Scope is zero. This one of option is not to be checked.
1501 if (VarBlockData
.Scope
== 0) {
1506 // Only check for OneOf and OrderList opcode
1508 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1509 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1511 // Check current value is the value of one of option.
1513 if (VarValue
== IfrOneOfOption
->Value
.u64
) {
1515 // The value is one of option value.
1516 // Set OpCode to Zero, don't need check again.
1518 VarBlockData
.OpCode
= 0;
1523 case EFI_IFR_END_OP
:
1525 // Decrease opcode scope for the validated opcode
1527 if (VarBlockData
.Scope
> 0) {
1528 VarBlockData
.Scope
--;
1532 // OneOf value doesn't belong to one of option value.
1534 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1535 Status
= EFI_INVALID_PARAMETER
;
1541 // Increase Scope for the validated opcode
1543 if (VarBlockData
.Scope
> 0) {
1544 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1549 // Go to the next opcode
1551 IfrOffset
+= IfrOpHdr
->Length
;
1554 // Only one form is in a package list.
1560 // Go to next package.
1562 PackageOffset
+= PacakgeHeader
.Length
;
1566 if (VarBuffer
!= NULL
) {
1567 FreePool (VarBuffer
);
1570 if (CurrentBlockArray
!= NULL
) {
1572 // Free Link Array CurrentBlockArray
1574 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1575 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1576 RemoveEntryList (&BlockData
->Entry
);
1577 FreePool (BlockData
);
1579 FreePool (CurrentBlockArray
);
1586 This function parses the input ConfigRequest string and its matched IFR code
1587 string for setting default value and validating current setting.
1589 1. For setting default action, Reset the default value specified by DefaultId
1590 to the driver configuration got by Request string.
1591 2. For validating current setting, Validate the current configuration
1592 by parsing HII form IFR opcode.
1594 NULL request string support depends on the ExportConfig interface of
1595 HiiConfigRouting protocol in UEFI specification.
1597 @param Request A null-terminated Unicode string in
1598 <MultiConfigRequest> format. It can be NULL.
1599 If it is NULL, all current configuration for the
1600 entirety of the current HII database will be validated.
1601 If it is NULL, all configuration for the
1602 entirety of the current HII database will be reset.
1603 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1604 @param ActionType Action supports setting defaults and validate current setting.
1606 @retval TURE Action runs successfully.
1607 @retval FALSE Action is not valid or Action can't be executed successfully..
1611 InternalHiiIfrValueAction (
1612 IN CONST EFI_STRING Request
, OPTIONAL
1613 IN UINT16 DefaultId
,
1617 EFI_STRING ConfigAltResp
;
1618 EFI_STRING ConfigAltHdr
;
1619 EFI_STRING ConfigResp
;
1620 EFI_STRING Progress
;
1621 EFI_STRING StringPtr
;
1622 EFI_STRING StringHdr
;
1624 EFI_HANDLE DriverHandle
;
1625 EFI_HANDLE TempDriverHandle
;
1626 EFI_HII_HANDLE
*HiiHandleBuffer
;
1627 EFI_HII_HANDLE HiiHandle
;
1631 EFI_STRING_ID DefaultName
;
1635 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1636 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1637 UINT32 PackageOffset
;
1638 UINTN PackageListLength
;
1639 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1640 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1641 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1643 ConfigAltResp
= NULL
;
1648 ConfigAltHdr
= NULL
;
1649 HiiHandleBuffer
= NULL
;
1651 TempDriverHandle
= NULL
;
1654 HiiPackageList
= NULL
;
1657 // Only support set default and validate setting action.
1659 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
1664 // Get the full requested value and deault value string.
1666 if (Request
!= NULL
) {
1667 Status
= gHiiConfigRouting
->ExtractConfig (
1674 Status
= gHiiConfigRouting
->ExportConfig (
1680 if (EFI_ERROR (Status
)) {
1684 StringPtr
= ConfigAltResp
;
1686 while (StringPtr
!= L
'\0') {
1688 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1690 StringHdr
= StringPtr
;
1695 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1696 Status
= EFI_INVALID_PARAMETER
;
1699 StringPtr
+= StrLen (L
"GUID=");
1700 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
1701 if (EFI_ERROR (Status
)) {
1706 // Get Name value VarName
1708 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1711 if (*StringPtr
== L
'\0') {
1712 Status
= EFI_INVALID_PARAMETER
;
1715 StringPtr
+= StrLen (L
"&NAME=");
1716 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
1717 if (EFI_ERROR (Status
)) {
1722 // Get Path value DevicePath
1724 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1727 if (*StringPtr
== L
'\0') {
1728 Status
= EFI_INVALID_PARAMETER
;
1731 StringPtr
+= StrLen (L
"&PATH=");
1732 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
1733 if (EFI_ERROR (Status
)) {
1738 // Get the Driver handle by the got device path.
1740 TempDevicePath
= DevicePath
;
1741 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
1742 if (EFI_ERROR (Status
)) {
1747 // Find the matched Hii Handle for the found Driver handle
1749 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
1750 if (HiiHandleBuffer
== NULL
) {
1751 Status
= EFI_NOT_FOUND
;
1755 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
1756 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
1757 if (TempDriverHandle
== DriverHandle
) {
1762 HiiHandle
= HiiHandleBuffer
[Index
];
1763 FreePool (HiiHandleBuffer
);
1765 if (HiiHandle
== NULL
) {
1767 // This request string has no its Hii package.
1768 // Its default value and validating can't execute by parsing IFR data.
1769 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
1771 Status
= EFI_SUCCESS
;
1772 goto NextConfigAltResp
;
1776 // 2. Get DefaultName string ID by parsing the PacakgeList
1780 // Get HiiPackage by HiiHandle
1782 PackageListLength
= 0;
1783 HiiPackageList
= NULL
;
1784 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1787 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1789 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1790 Status
= EFI_INVALID_PARAMETER
;
1794 HiiPackageList
= AllocatePool (PackageListLength
);
1795 if (HiiPackageList
== NULL
) {
1796 Status
= EFI_OUT_OF_RESOURCES
;
1801 // Get PackageList on HiiHandle
1803 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1804 if (EFI_ERROR (Status
)) {
1809 // Parse the form package and get the default name string ID.
1811 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1812 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1813 Status
= EFI_NOT_FOUND
;
1814 while (PackageOffset
< PackageListLength
) {
1815 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1818 // Parse IFR opcode to get default store opcode
1820 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1821 IfrOffset
= sizeof (PacakgeHeader
);
1822 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1823 while (IfrOffset
< PacakgeHeader
.Length
) {
1824 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1826 // Match DefaultId to find its DefaultName
1828 if (IfrOpHdr
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
) {
1829 if (((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
== DefaultId
) {
1830 DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
1831 Status
= EFI_SUCCESS
;
1835 IfrOffset
+= IfrOpHdr
->Length
;
1838 // Only one form is in a package list.
1844 // Go to next package.
1846 PackageOffset
+= PacakgeHeader
.Length
;
1850 // Not found the matched default string ID
1852 if (EFI_ERROR (Status
)) {
1853 Status
= EFI_SUCCESS
;
1854 goto NextConfigAltResp
;
1859 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
1860 // Get the default configuration string according to the found defaultname string ID.
1862 Status
= gHiiConfigRouting
->GetAltConfig (
1868 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultName
:NULL
, // it can be NULL to get the current setting.
1873 // The required setting can't be found. So, it is not required to be validated and set.
1875 if (EFI_ERROR (Status
)) {
1876 Status
= EFI_SUCCESS
;
1877 goto NextConfigAltResp
;
1880 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
1882 if (StrStr (ConfigResp
, L
"&OFFSET=") == NULL
) {
1883 goto NextConfigAltResp
;
1887 // 4. Set the default configuration information or Validate current setting by parse IFR code.
1888 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1890 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1892 // Set the default configuration information.
1894 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
1897 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1899 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
);
1902 if (EFI_ERROR (Status
)) {
1908 // Free the allocated pacakge buffer and the got ConfigResp string.
1910 if (HiiPackageList
!= NULL
) {
1911 FreePool (HiiPackageList
);
1912 HiiPackageList
= NULL
;
1915 if (ConfigResp
!= NULL
) {
1916 FreePool (ConfigResp
);
1921 // Free the allocated buffer.
1929 FreePool (DevicePath
);
1933 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
1937 // Get and Skip ConfigHdr
1939 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1942 if (*StringPtr
== L
'\0') {
1947 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
1948 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
1950 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
1951 if (ConfigAltHdr
== NULL
) {
1952 Status
= EFI_OUT_OF_RESOURCES
;
1955 StrCpy (ConfigAltHdr
, L
"&");
1956 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
1957 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
1960 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
1962 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
1963 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
1964 if (*StringPtr
== L
'\0') {
1970 // Free the allocated ConfigAltHdr string
1972 FreePool (ConfigAltHdr
);
1973 if (*StringPtr
== L
'\0') {
1978 // Find &GUID as the next ConfigHdr
1980 StringPtr
= StrStr (StringPtr
, L
"&GUID");
1981 if (StringPtr
== NULL
) {
1992 if (VarGuid
!= NULL
) {
1996 if (VarName
!= NULL
) {
2000 if (DevicePath
!= NULL
) {
2001 FreePool (DevicePath
);
2004 if (ConfigResp
!= NULL
) {
2005 FreePool (ConfigResp
);
2008 if (ConfigAltResp
!= NULL
) {
2009 FreePool (ConfigAltResp
);
2012 if (HiiPackageList
!= NULL
) {
2013 FreePool (HiiPackageList
);
2016 if (EFI_ERROR (Status
)) {
2024 Validate the current configuration by parsing HII form IFR opcode.
2026 NULL request string support depends on the ExportConfig interface of
2027 HiiConfigRouting protocol in UEFI specification.
2029 @param Request A null-terminated Unicode string in
2030 <MultiConfigRequest> format. It can be NULL.
2031 If it is NULL, all current configuration for the
2032 entirety of the current HII database will be validated.
2034 @retval TURE Current configuration is valid.
2035 @retval FALSE Current configuration is invalid.
2039 HiiValidateSettings (
2040 IN CONST EFI_STRING Request OPTIONAL
2043 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2047 Reset the default value specified by DefaultId to the driver
2048 configuration got by Request string.
2050 NULL request string support depends on the ExportConfig interface of
2051 HiiConfigRouting protocol in UEFI specification.
2053 @param Request A null-terminated Unicode string in
2054 <MultiConfigRequest> format. It can be NULL.
2055 If it is NULL, all configuration for the
2056 entirety of the current HII database will be reset.
2057 @param DefaultId Specifies the type of defaults to retrieve.
2059 @retval TURE The default value is set successfully.
2060 @retval FALSE The default value can't be found and set.
2065 IN CONST EFI_STRING Request
, OPTIONAL
2069 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2073 Determines if two values in config strings match.
2075 Compares the substring between StartSearchString and StopSearchString in
2076 FirstString to the substring between StartSearchString and StopSearchString
2077 in SecondString. If the two substrings match, then TRUE is returned. If the
2078 two substrings do not match, then FALSE is returned.
2080 If FirstString is NULL, then ASSERT().
2081 If SecondString is NULL, then ASSERT().
2082 If StartSearchString is NULL, then ASSERT().
2083 If StopSearchString is NULL, then ASSERT().
2085 @param FirstString Pointer to the first Null-terminated Unicode string.
2086 @param SecondString Pointer to the second Null-terminated Unicode string.
2087 @param StartSearchString Pointer to the Null-terminated Unicode string that
2088 marks the start of the value string to compare.
2089 @param StopSearchString Pointer to the Null-terminated Unicode string that
2090 marks the end of the vakue string to compare.
2092 @retval FALSE StartSearchString is not present in FirstString.
2093 @retval FALSE StartSearchString is not present in SecondString.
2094 @retval FALSE StopSearchString is not present in FirstString.
2095 @retval FALSE StopSearchString is not present in SecondString.
2096 @retval FALSE The length of the substring in FirstString is not the
2097 same length as the substring in SecondString.
2098 @retval FALSE The value string in FirstString does not matche the
2099 value string in SecondString.
2100 @retval TRUE The value string in FirstString matches the value
2101 string in SecondString.
2106 InternalHiiCompareSubString (
2107 IN CHAR16
*FirstString
,
2108 IN CHAR16
*SecondString
,
2109 IN CHAR16
*StartSearchString
,
2110 IN CHAR16
*StopSearchString
2113 CHAR16
*EndFirstString
;
2114 CHAR16
*EndSecondString
;
2116 ASSERT (FirstString
!= NULL
);
2117 ASSERT (SecondString
!= NULL
);
2118 ASSERT (StartSearchString
!= NULL
);
2119 ASSERT (StopSearchString
!= NULL
);
2121 FirstString
= StrStr (FirstString
, StartSearchString
);
2122 if (FirstString
== NULL
) {
2126 SecondString
= StrStr (SecondString
, StartSearchString
);
2127 if (SecondString
== NULL
) {
2131 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2132 if (EndFirstString
== NULL
) {
2136 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2137 if (EndSecondString
== NULL
) {
2141 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2145 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2149 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2151 If ConfigHdr is NULL, then ASSERT().
2153 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2154 @param[in] Guid GUID of the storage.
2155 @param[in] Name NAME of the storage.
2157 @retval TRUE Routing information matches <ConfigHdr>.
2158 @retval FALSE Routing information does not match <ConfigHdr>.
2163 HiiIsConfigHdrMatch (
2164 IN CONST EFI_STRING ConfigHdr
,
2165 IN CONST EFI_GUID
*Guid
, OPTIONAL
2166 IN CONST CHAR16
*Name OPTIONAL
2169 EFI_STRING CompareConfigHdr
;
2172 ASSERT (ConfigHdr
!= NULL
);
2175 // Use Guid and Name to generate a <ConfigHdr> string
2177 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2178 if (CompareConfigHdr
== NULL
) {
2185 // Compare GUID value strings
2187 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2190 if (Result
&& Name
!= NULL
) {
2192 // Compare NAME value strings
2194 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2198 // Free the <ConfigHdr> string
2200 FreePool (CompareConfigHdr
);
2206 Retrieves uncommited data from the Form Browser and converts it to a binary
2209 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2210 is an optional parameter that may be NULL.
2211 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2212 parameter that may be NULL.
2213 @param[in] BufferSize Length in bytes of buffer to hold retrived data.
2214 @param[out] Block Buffer of data to be updated.
2216 @retval FALSE The uncommitted data could not be retrieved.
2217 @retval TRUE The uncommitted data was retrieved.
2223 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2224 IN CONST CHAR16
*VariableName
, OPTIONAL
2229 EFI_STRING ResultsData
;
2231 EFI_STRING ConfigResp
;
2236 // Retrieve the results data from the Browser Callback
2238 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2239 if (ResultsData
== NULL
) {
2244 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2246 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2247 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2248 ConfigResp
= AllocateZeroPool (Size
);
2249 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2252 // Free the allocated buffer
2254 FreePool (ResultsData
);
2255 if (ConfigResp
== NULL
) {
2260 // Convert <ConfigResp> to a buffer
2262 Status
= gHiiConfigRouting
->ConfigToBlock (
2270 // Free the allocated buffer
2272 FreePool (ConfigResp
);
2274 if (EFI_ERROR (Status
)) {
2282 Updates uncommitted data in the Form Browser.
2284 If Buffer is NULL, then ASSERT().
2286 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2287 is an optional parameter that may be NULL.
2288 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2289 parameter that may be NULL.
2290 @param[in] BufferSize Length, in bytes, of Buffer.
2291 @param[in] Buffer Buffer of data to commit.
2292 @param[in] RequestElement An optional field to specify which part of the
2293 buffer data will be send back to Browser. If NULL,
2294 the whole buffer of data will be committed to
2296 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2298 @retval FALSE The uncommitted data could not be updated.
2299 @retval TRUE The uncommitted data was updated.
2305 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2306 IN CONST CHAR16
*VariableName
, OPTIONAL
2307 IN UINTN BufferSize
,
2308 IN CONST UINT8
*Buffer
,
2309 IN CONST CHAR16
*RequestElement OPTIONAL
2313 EFI_STRING ConfigRequest
;
2314 EFI_STRING ConfigResp
;
2315 EFI_STRING ResultsData
;
2317 ASSERT (Buffer
!= NULL
);
2320 // Construct <ConfigRequest>
2322 if (RequestElement
== NULL
) {
2324 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2325 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2327 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2328 ConfigRequest
= AllocateZeroPool (Size
);
2329 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2332 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2333 // followed by <RequestElement> followed by a Null-terminator
2335 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2336 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2337 ConfigRequest
= AllocateZeroPool (Size
);
2338 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2340 if (ConfigRequest
== NULL
) {
2345 // Convert <ConfigRequest> to <ConfigResp>
2347 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2348 FreePool (ConfigRequest
);
2349 if (ConfigResp
== NULL
) {
2354 // Set data in the uncommitted browser state information
2356 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2357 FreePool (ConfigResp
);
2359 return (BOOLEAN
)(ResultsData
!= NULL
);
2362 /////////////////////////////////////////
2363 /////////////////////////////////////////
2365 /////////////////////////////////////////
2366 /////////////////////////////////////////
2368 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2374 } HII_LIB_OPCODE_BUFFER
;
2377 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2379 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2380 1, // EFI_IFR_TYPE_NUM_SIZE_8
2381 2, // EFI_IFR_TYPE_NUM_SIZE_16
2382 4, // EFI_IFR_TYPE_NUM_SIZE_32
2383 8, // EFI_IFR_TYPE_NUM_SIZE_64
2384 1, // EFI_IFR_TYPE_BOOLEAN
2385 3, // EFI_IFR_TYPE_TIME
2386 4, // EFI_IFR_TYPE_DATE
2387 2 // EFI_IFR_TYPE_STRING
2391 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2392 HiiFreeOpCodeHandle().
2394 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2395 @retval Other A new OpCode handle.
2400 HiiAllocateOpCodeHandle (
2404 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2406 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2407 if (OpCodeBuffer
== NULL
) {
2410 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2411 if (OpCodeBuffer
->Buffer
== NULL
) {
2412 FreePool (OpCodeBuffer
);
2415 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2416 OpCodeBuffer
->Position
= 0;
2417 return (VOID
*)OpCodeBuffer
;
2421 Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle().
2422 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2423 Handle are also freed.
2425 If OpCodeHandle is NULL, then ASSERT().
2430 HiiFreeOpCodeHandle (
2434 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2436 ASSERT (OpCodeHandle
!= NULL
);
2438 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2439 if (OpCodeBuffer
->Buffer
!= NULL
) {
2440 FreePool (OpCodeBuffer
->Buffer
);
2442 FreePool (OpCodeBuffer
);
2447 InternalHiiOpCodeHandlePosition (
2448 IN VOID
*OpCodeHandle
2451 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2456 InternalHiiOpCodeHandleBuffer (
2457 IN VOID
*OpCodeHandle
2460 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2465 InternalHiiGrowOpCodeHandle (
2470 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2473 ASSERT (OpCodeHandle
!= NULL
);
2475 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2476 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2477 Buffer
= ReallocatePool (
2478 OpCodeBuffer
->BufferSize
,
2479 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2480 OpCodeBuffer
->Buffer
2482 if (Buffer
== NULL
) {
2485 OpCodeBuffer
->Buffer
= Buffer
;
2486 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2488 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2489 OpCodeBuffer
->Position
+= Size
;
2495 InternalHiiCreateOpCodeExtended (
2496 IN VOID
*OpCodeHandle
,
2497 IN VOID
*OpCodeTemplate
,
2499 IN UINTN OpCodeSize
,
2500 IN UINTN ExtensionSize
,
2504 EFI_IFR_OP_HEADER
*Header
;
2507 ASSERT (OpCodeTemplate
!= NULL
);
2508 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2510 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2511 Header
->OpCode
= OpCode
;
2512 Header
->Scope
= Scope
;
2513 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2514 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2515 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2520 InternalHiiCreateOpCode (
2521 IN VOID
*OpCodeHandle
,
2522 IN VOID
*OpCodeTemplate
,
2527 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2531 Append raw opcodes to an OpCodeHandle.
2533 If OpCodeHandle is NULL, then ASSERT().
2534 If RawBuffer is NULL, then ASSERT();
2536 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2537 @param[in] RawBuffer Buffer of opcodes to append.
2538 @param[in] RawBufferSize The size, in bytes, of Buffer.
2540 @retval NULL There is not enough space left in Buffer to add the opcode.
2541 @retval Other A pointer to the appended opcodes.
2546 HiiCreateRawOpCodes (
2547 IN VOID
*OpCodeHandle
,
2548 IN UINT8
*RawBuffer
,
2549 IN UINTN RawBufferSize
2554 ASSERT (RawBuffer
!= NULL
);
2556 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2557 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2561 Append opcodes from one OpCode Handle to another OpCode handle.
2563 If OpCodeHandle is NULL, then ASSERT().
2564 If RawOpCodeHandle is NULL, then ASSERT();
2566 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2567 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2569 @retval NULL There is not enough space left in Buffer to add the opcode.
2570 @retval Other A pointer to the appended opcodes.
2575 InternalHiiAppendOpCodes (
2576 IN VOID
*OpCodeHandle
,
2577 IN VOID
*RawOpCodeHandle
2580 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2582 ASSERT (RawOpCodeHandle
!= NULL
);
2584 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2585 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2589 Create EFI_IFR_END_OP opcode.
2591 If OpCodeHandle is NULL, then ASSERT().
2593 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2595 @retval NULL There is not enough space left in Buffer to add the opcode.
2596 @retval Other A pointer to the created opcode.
2601 HiiCreateEndOpCode (
2602 IN VOID
*OpCodeHandle
2607 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2611 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2613 If OpCodeHandle is NULL, then ASSERT().
2614 If Type is invalid, then ASSERT().
2615 If Flags is invalid, then ASSERT().
2617 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2618 @param[in] StringId StringId for the option
2619 @param[in] Flags Flags for the option
2620 @param[in] Type Type for the option
2621 @param[in] Value Value for the option
2623 @retval NULL There is not enough space left in Buffer to add the opcode.
2624 @retval Other A pointer to the created opcode.
2629 HiiCreateOneOfOptionOpCode (
2630 IN VOID
*OpCodeHandle
,
2637 EFI_IFR_ONE_OF_OPTION OpCode
;
2639 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2641 ZeroMem (&OpCode
, sizeof (OpCode
));
2642 OpCode
.Option
= StringId
;
2643 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2645 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2647 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, sizeof (OpCode
));
2651 Create EFI_IFR_DEFAULT_OP opcode.
2653 If OpCodeHandle is NULL, then ASSERT().
2654 If Type is invalid, then ASSERT().
2656 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2657 @param[in] DefaultId DefaultId for the default
2658 @param[in] Type Type for the default
2659 @param[in] Value Value for the default
2661 @retval NULL There is not enough space left in Buffer to add the opcode.
2662 @retval Other A pointer to the created opcode.
2667 HiiCreateDefaultOpCode (
2668 IN VOID
*OpCodeHandle
,
2669 IN UINT16 DefaultId
,
2674 EFI_IFR_DEFAULT OpCode
;
2676 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2678 ZeroMem (&OpCode
, sizeof (OpCode
));
2680 OpCode
.DefaultId
= DefaultId
;
2681 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2683 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, sizeof (OpCode
));
2687 Create EFI_IFR_GUID opcode.
2689 If OpCodeHandle is NULL, then ASSERT().
2690 If Guid is NULL, then ASSERT().
2691 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
2693 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2694 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
2695 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
2696 optional parameter that may be NULL. If this
2697 parameter is NULL, then the GUID extension
2698 region of the created opcode is filled with zeros.
2699 If this parameter is not NULL, then the GUID
2700 extension region of GuidData will be copied to
2701 the GUID extension region of the created opcode.
2702 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
2703 must be >= sizeof(EFI_IFR_GUID).
2705 @retval NULL There is not enough space left in Buffer to add the opcode.
2706 @retval Other A pointer to the created opcode.
2711 HiiCreateGuidOpCode (
2712 IN VOID
*OpCodeHandle
,
2713 IN CONST EFI_GUID
*Guid
,
2714 IN CONST VOID
*GuidOpCode
, OPTIONAL
2718 EFI_IFR_GUID OpCode
;
2719 EFI_IFR_GUID
*OpCodePointer
;
2721 ASSERT (Guid
!= NULL
);
2722 ASSERT (OpCodeSize
>= sizeof (OpCode
));
2724 ZeroMem (&OpCode
, sizeof (OpCode
));
2725 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
2727 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
2732 OpCodeSize
- sizeof (OpCode
),
2735 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
2736 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
2738 return (UINT8
*)OpCodePointer
;
2742 Create EFI_IFR_ACTION_OP opcode.
2744 If OpCodeHandle is NULL, then ASSERT().
2745 If any reserved bits are set in QuestionFlags, then ASSERT().
2747 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2748 @param[in] QuestionId Question ID
2749 @param[in] Prompt String ID for Prompt
2750 @param[in] Help String ID for Help
2751 @param[in] QuestionFlags Flags in Question Header
2752 @param[in] QuestionConfig String ID for configuration
2754 @retval NULL There is not enough space left in Buffer to add the opcode.
2755 @retval Other A pointer to the created opcode.
2760 HiiCreateActionOpCode (
2761 IN VOID
*OpCodeHandle
,
2762 IN EFI_QUESTION_ID QuestionId
,
2763 IN EFI_STRING_ID Prompt
,
2764 IN EFI_STRING_ID Help
,
2765 IN UINT8 QuestionFlags
,
2766 IN EFI_STRING_ID QuestionConfig
2769 EFI_IFR_ACTION OpCode
;
2771 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2773 ZeroMem (&OpCode
, sizeof (OpCode
));
2774 OpCode
.Question
.QuestionId
= QuestionId
;
2775 OpCode
.Question
.Header
.Prompt
= Prompt
;
2776 OpCode
.Question
.Header
.Help
= Help
;
2777 OpCode
.Question
.Flags
= QuestionFlags
;
2778 OpCode
.QuestionConfig
= QuestionConfig
;
2780 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
2784 Create EFI_IFR_SUBTITLE_OP opcode.
2786 If OpCodeHandle is NULL, then ASSERT().
2787 If any reserved bits are set in Flags, then ASSERT().
2788 If Scope > 1, then ASSERT().
2790 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2791 @param[in] Prompt String ID for Prompt
2792 @param[in] Help String ID for Help
2793 @param[in] Flags Subtitle opcode flags
2794 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
2795 0 if this opcode is within the current scope.
2797 @retval NULL There is not enough space left in Buffer to add the opcode.
2798 @retval Other A pointer to the created opcode.
2803 HiiCreateSubTitleOpCode (
2804 IN VOID
*OpCodeHandle
,
2805 IN EFI_STRING_ID Prompt
,
2806 IN EFI_STRING_ID Help
,
2811 EFI_IFR_SUBTITLE OpCode
;
2813 ASSERT (Scope
<= 1);
2814 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
2816 ZeroMem (&OpCode
, sizeof (OpCode
));
2817 OpCode
.Statement
.Prompt
= Prompt
;
2818 OpCode
.Statement
.Help
= Help
;
2819 OpCode
.Flags
= Flags
;
2821 return InternalHiiCreateOpCodeExtended (
2824 EFI_IFR_SUBTITLE_OP
,
2832 Create EFI_IFR_REF_OP opcode.
2834 If OpCodeHandle is NULL, then ASSERT().
2835 If any reserved bits are set in QuestionFlags, then ASSERT().
2837 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2838 @param[in] FormId Destination Form ID
2839 @param[in] Prompt String ID for Prompt
2840 @param[in] Help String ID for Help
2841 @param[in] QuestionFlags Flags in Question Header
2842 @param[in] QuestionId Question ID
2844 @retval NULL There is not enough space left in Buffer to add the opcode.
2845 @retval Other A pointer to the created opcode.
2850 HiiCreateGotoOpCode (
2851 IN VOID
*OpCodeHandle
,
2852 IN EFI_FORM_ID FormId
,
2853 IN EFI_STRING_ID Prompt
,
2854 IN EFI_STRING_ID Help
,
2855 IN UINT8 QuestionFlags
,
2856 IN EFI_QUESTION_ID QuestionId
2861 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2863 ZeroMem (&OpCode
, sizeof (OpCode
));
2864 OpCode
.Question
.Header
.Prompt
= Prompt
;
2865 OpCode
.Question
.Header
.Help
= Help
;
2866 OpCode
.Question
.QuestionId
= QuestionId
;
2867 OpCode
.Question
.Flags
= QuestionFlags
;
2868 OpCode
.FormId
= FormId
;
2870 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
2874 Create EFI_IFR_CHECKBOX_OP opcode.
2876 If OpCodeHandle is NULL, then ASSERT().
2877 If any reserved bits are set in QuestionFlags, then ASSERT().
2878 If any reserved bits are set in CheckBoxFlags, then ASSERT().
2880 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2881 @param[in] QuestionId Question ID
2882 @param[in] VarStoreId Storage ID
2883 @param[in] VarOffset Offset in Storage
2884 @param[in] Prompt String ID for Prompt
2885 @param[in] Help String ID for Help
2886 @param[in] QuestionFlags Flags in Question Header
2887 @param[in] CheckBoxFlags Flags for checkbox opcode
2888 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2889 is an optional parameter that may be NULL.
2891 @retval NULL There is not enough space left in Buffer to add the opcode.
2892 @retval Other A pointer to the created opcode.
2897 HiiCreateCheckBoxOpCode (
2898 IN VOID
*OpCodeHandle
,
2899 IN EFI_QUESTION_ID QuestionId
,
2900 IN EFI_VARSTORE_ID VarStoreId
,
2901 IN UINT16 VarOffset
,
2902 IN EFI_STRING_ID Prompt
,
2903 IN EFI_STRING_ID Help
,
2904 IN UINT8 QuestionFlags
,
2905 IN UINT8 CheckBoxFlags
,
2906 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2909 EFI_IFR_CHECKBOX OpCode
;
2912 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2914 ZeroMem (&OpCode
, sizeof (OpCode
));
2915 OpCode
.Question
.QuestionId
= QuestionId
;
2916 OpCode
.Question
.VarStoreId
= VarStoreId
;
2917 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2918 OpCode
.Question
.Header
.Prompt
= Prompt
;
2919 OpCode
.Question
.Header
.Help
= Help
;
2920 OpCode
.Question
.Flags
= QuestionFlags
;
2921 OpCode
.Flags
= CheckBoxFlags
;
2923 if (DefaultsOpCodeHandle
== NULL
) {
2924 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
2927 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
2928 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
2929 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
2930 HiiCreateEndOpCode (OpCodeHandle
);
2931 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
2935 Create EFI_IFR_NUMERIC_OP opcode.
2937 If OpCodeHandle is NULL, then ASSERT().
2938 If any reserved bits are set in QuestionFlags, then ASSERT().
2939 If any reserved bits are set in NumericFlags, then ASSERT().
2941 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2942 @param[in] QuestionId Question ID
2943 @param[in] VarStoreId Storage ID
2944 @param[in] VarOffset Offset in Storage
2945 @param[in] Prompt String ID for Prompt
2946 @param[in] Help String ID for Help
2947 @param[in] QuestionFlags Flags in Question Header
2948 @param[in] NumericFlags Flags for numeric opcode
2949 @param[in] Minimum Numeric minimum value
2950 @param[in] Maximum Numeric maximum value
2951 @param[in] Step Numeric step for edit
2952 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2953 is an optional parameter that may be NULL.
2955 @retval NULL There is not enough space left in Buffer to add the opcode.
2956 @retval Other A pointer to the created opcode.
2961 HiiCreateNumericOpCode (
2962 IN VOID
*OpCodeHandle
,
2963 IN EFI_QUESTION_ID QuestionId
,
2964 IN EFI_VARSTORE_ID VarStoreId
,
2965 IN UINT16 VarOffset
,
2966 IN EFI_STRING_ID Prompt
,
2967 IN EFI_STRING_ID Help
,
2968 IN UINT8 QuestionFlags
,
2969 IN UINT8 NumericFlags
,
2973 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2976 EFI_IFR_NUMERIC OpCode
;
2979 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2981 ZeroMem (&OpCode
, sizeof (OpCode
));
2982 OpCode
.Question
.QuestionId
= QuestionId
;
2983 OpCode
.Question
.VarStoreId
= VarStoreId
;
2984 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2985 OpCode
.Question
.Header
.Prompt
= Prompt
;
2986 OpCode
.Question
.Header
.Help
= Help
;
2987 OpCode
.Question
.Flags
= QuestionFlags
;
2988 OpCode
.Flags
= NumericFlags
;
2990 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
2991 case EFI_IFR_NUMERIC_SIZE_1
:
2992 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
2993 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
2994 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
2997 case EFI_IFR_NUMERIC_SIZE_2
:
2998 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
2999 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3000 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3003 case EFI_IFR_NUMERIC_SIZE_4
:
3004 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3005 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3006 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3009 case EFI_IFR_NUMERIC_SIZE_8
:
3010 OpCode
.data
.u64
.MinValue
= Minimum
;
3011 OpCode
.data
.u64
.MaxValue
= Maximum
;
3012 OpCode
.data
.u64
.Step
= Step
;
3016 if (DefaultsOpCodeHandle
== NULL
) {
3017 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
));
3020 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3021 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
), 0, 1);
3022 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3023 HiiCreateEndOpCode (OpCodeHandle
);
3024 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3028 Create EFI_IFR_STRING_OP opcode.
3030 If OpCodeHandle is NULL, then ASSERT().
3031 If any reserved bits are set in QuestionFlags, then ASSERT().
3032 If any reserved bits are set in StringFlags, then ASSERT().
3034 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3035 @param[in] QuestionId Question ID
3036 @param[in] VarStoreId Storage ID
3037 @param[in] VarOffset Offset in Storage
3038 @param[in] Prompt String ID for Prompt
3039 @param[in] Help String ID for Help
3040 @param[in] QuestionFlags Flags in Question Header
3041 @param[in] StringFlags Flags for string opcode
3042 @param[in] MinSize String minimum length
3043 @param[in] MaxSize String maximum length
3044 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3045 is an optional parameter that may be NULL.
3047 @retval NULL There is not enough space left in Buffer to add the opcode.
3048 @retval Other A pointer to the created opcode.
3053 HiiCreateStringOpCode (
3054 IN VOID
*OpCodeHandle
,
3055 IN EFI_QUESTION_ID QuestionId
,
3056 IN EFI_VARSTORE_ID VarStoreId
,
3057 IN UINT16 VarOffset
,
3058 IN EFI_STRING_ID Prompt
,
3059 IN EFI_STRING_ID Help
,
3060 IN UINT8 QuestionFlags
,
3061 IN UINT8 StringFlags
,
3064 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3067 EFI_IFR_STRING OpCode
;
3070 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3072 ZeroMem (&OpCode
, sizeof (OpCode
));
3073 OpCode
.Question
.Header
.Prompt
= Prompt
;
3074 OpCode
.Question
.Header
.Help
= Help
;
3075 OpCode
.Question
.QuestionId
= QuestionId
;
3076 OpCode
.Question
.VarStoreId
= VarStoreId
;
3077 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3078 OpCode
.Question
.Flags
= QuestionFlags
;
3079 OpCode
.MinSize
= MinSize
;
3080 OpCode
.MaxSize
= MaxSize
;
3081 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3083 if (DefaultsOpCodeHandle
== NULL
) {
3084 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3087 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3088 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3089 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3090 HiiCreateEndOpCode (OpCodeHandle
);
3091 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3095 Create EFI_IFR_ONE_OF_OP opcode.
3097 If OpCodeHandle is NULL, then ASSERT().
3098 If any reserved bits are set in QuestionFlags, then ASSERT().
3099 If any reserved bits are set in OneOfFlags, then ASSERT().
3101 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3102 @param[in] QuestionId Question ID
3103 @param[in] VarStoreId Storage ID
3104 @param[in] VarOffset Offset in Storage
3105 @param[in] Prompt String ID for Prompt
3106 @param[in] Help String ID for Help
3107 @param[in] QuestionFlags Flags in Question Header
3108 @param[in] OneOfFlags Flags for oneof opcode
3109 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3110 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3111 is an optional parameter that may be NULL.
3113 @retval NULL There is not enough space left in Buffer to add the opcode.
3114 @retval Other A pointer to the created opcode.
3119 HiiCreateOneOfOpCode (
3120 IN VOID
*OpCodeHandle
,
3121 IN EFI_QUESTION_ID QuestionId
,
3122 IN EFI_VARSTORE_ID VarStoreId
,
3123 IN UINT16 VarOffset
,
3124 IN EFI_STRING_ID Prompt
,
3125 IN EFI_STRING_ID Help
,
3126 IN UINT8 QuestionFlags
,
3127 IN UINT8 OneOfFlags
,
3128 IN VOID
*OptionsOpCodeHandle
,
3129 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3132 EFI_IFR_ONE_OF OpCode
;
3135 ASSERT (OptionsOpCodeHandle
!= NULL
);
3136 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3138 ZeroMem (&OpCode
, sizeof (OpCode
));
3139 OpCode
.Question
.Header
.Prompt
= Prompt
;
3140 OpCode
.Question
.Header
.Help
= Help
;
3141 OpCode
.Question
.QuestionId
= QuestionId
;
3142 OpCode
.Question
.VarStoreId
= VarStoreId
;
3143 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3144 OpCode
.Question
.Flags
= QuestionFlags
;
3145 OpCode
.Flags
= OneOfFlags
;
3147 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3148 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, sizeof (OpCode
), 0, 1);
3149 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3150 if (DefaultsOpCodeHandle
!= NULL
) {
3151 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3153 HiiCreateEndOpCode (OpCodeHandle
);
3154 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3158 Create EFI_IFR_ORDERED_LIST_OP opcode.
3160 If OpCodeHandle is NULL, then ASSERT().
3161 If any reserved bits are set in QuestionFlags, then ASSERT().
3162 If any reserved bits are set in OrderedListFlags, then ASSERT().
3164 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3165 @param[in] QuestionId Question ID
3166 @param[in] VarStoreId Storage ID
3167 @param[in] VarOffset Offset in Storage
3168 @param[in] Prompt String ID for Prompt
3169 @param[in] Help String ID for Help
3170 @param[in] QuestionFlags Flags in Question Header
3171 @param[in] OrderedListFlags Flags for ordered list opcode
3172 @param[in] DataType Type for option value
3173 @param[in] MaxContainers Maximum count for options in this ordered list
3174 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3175 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3176 is an optional parameter that may be NULL.
3178 @retval NULL There is not enough space left in Buffer to add the opcode.
3179 @retval Other A pointer to the created opcode.
3184 HiiCreateOrderedListOpCode (
3185 IN VOID
*OpCodeHandle
,
3186 IN EFI_QUESTION_ID QuestionId
,
3187 IN EFI_VARSTORE_ID VarStoreId
,
3188 IN UINT16 VarOffset
,
3189 IN EFI_STRING_ID Prompt
,
3190 IN EFI_STRING_ID Help
,
3191 IN UINT8 QuestionFlags
,
3192 IN UINT8 OrderedListFlags
,
3194 IN UINT8 MaxContainers
,
3195 IN VOID
*OptionsOpCodeHandle
,
3196 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3199 EFI_IFR_ORDERED_LIST OpCode
;
3202 ASSERT (OptionsOpCodeHandle
!= NULL
);
3203 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3205 ZeroMem (&OpCode
, sizeof (OpCode
));
3206 OpCode
.Question
.Header
.Prompt
= Prompt
;
3207 OpCode
.Question
.Header
.Help
= Help
;
3208 OpCode
.Question
.QuestionId
= QuestionId
;
3209 OpCode
.Question
.VarStoreId
= VarStoreId
;
3210 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3211 OpCode
.Question
.Flags
= QuestionFlags
;
3212 OpCode
.MaxContainers
= MaxContainers
;
3213 OpCode
.Flags
= OrderedListFlags
;
3215 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3216 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3217 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3218 if (DefaultsOpCodeHandle
!= NULL
) {
3219 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3221 HiiCreateEndOpCode (OpCodeHandle
);
3222 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3226 This is the internal worker function to update the data in
3227 a form specified by FormSetGuid, FormId and Label.
3229 @param FormSetGuid The optional Formset GUID.
3230 @param FormId The Form ID.
3231 @param Package The package header.
3233 @param TempPacakge The resultant package.
3235 @retval EFI_SUCCESS The function completes successfully.
3240 InternalHiiUpdateFormPackageData (
3241 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3242 IN EFI_FORM_ID FormId
,
3243 IN EFI_HII_PACKAGE_HEADER
*Package
,
3244 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3245 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3246 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3251 EFI_HII_PACKAGE_HEADER PackageHeader
;
3253 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3254 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3258 UINTN UpdatePackageLength
;
3260 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3261 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3262 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3264 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3265 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3266 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3267 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3271 while (Offset
< PackageHeader
.Length
) {
3272 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3273 BufferPos
+= IfrOpHdr
->Length
;
3274 UpdatePackageLength
+= IfrOpHdr
->Length
;
3277 // Find the matched FormSet and Form
3279 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3280 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3285 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
) {
3286 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3294 // The matched Form is found, and Update data in this form
3296 if (GetFormSet
&& GetForm
) {
3297 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3298 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3299 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3301 // Remove the original data when End OpCode buffer exist.
3303 if (OpCodeBufferEnd
!= NULL
) {
3304 Offset
+= IfrOpHdr
->Length
;
3305 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3306 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3307 while (Offset
< PackageHeader
.Length
) {
3309 // Search the matched end opcode
3311 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3312 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3316 // Go to the next Op-Code
3318 Offset
+= IfrOpHdr
->Length
;
3319 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3322 if (Offset
>= PackageHeader
.Length
) {
3324 // The end opcode is not found.
3326 return EFI_NOT_FOUND
;
3331 // Insert the updated data
3333 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3334 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3335 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3336 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3338 if (OpCodeBufferEnd
!= NULL
) {
3340 // Add the end opcode
3342 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3343 BufferPos
+= IfrOpHdr
->Length
;
3344 UpdatePackageLength
+= IfrOpHdr
->Length
;
3348 // Copy the left package data.
3350 Offset
+= IfrOpHdr
->Length
;
3351 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3352 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3363 // Go to the next Op-Code
3365 Offset
+= IfrOpHdr
->Length
;
3366 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3371 // The updated opcode buffer is not found.
3373 return EFI_NOT_FOUND
;
3376 // Update the package length.
3378 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3379 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3385 This function updates a form that has previously been registered with the HII
3386 Database. This function will perform at most one update operation.
3388 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3389 comparisons of IFR opcodes are performed from the beginning of the form being
3390 updated until an IFR opcode is found that exactly matches the first IFR opcode
3391 specifed by StartOpCodeHandle. The following rules are used to determine if
3392 an insert, replace, or delete operation is performed.
3394 1) If no matches are found, then NULL is returned.
3395 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3396 from StartOpcodeHandle except the first opcode are inserted immediately after
3397 the matching IFR opcode in the form beng updated.
3398 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3399 from the matching IFR opcode until an IFR opcode exatly matches the first
3400 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3401 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3402 is found, then all of the IFR opcodes between the start match and the end
3403 match are deleted from the form being updated and all of the IFR opcodes
3404 from StartOpcodeHandle except the first opcode are inserted immediately after
3405 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3406 IFR instruction, then the result of ths operation will delete all of the IFR
3407 opcodes between the start end matches.
3409 If HiiHandle is NULL, then ASSERT().
3410 If StartOpCodeHandle is NULL, then ASSERT().
3412 @param[in] HiiHandle The HII Handle of the form to update.
3413 @param[in] FormSetGuid The Formset GUID of the form to update. This
3414 is an optional parameter that may be NULL.
3415 If it is NULL, all FormSet will be updated.
3416 @param[in] FormId The ID of the form to update.
3417 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
3418 opcodes to be inserted or replaced in the form.
3419 The first IFR instruction in StartOpCodeHandle
3420 is used to find matching IFR opcode in the
3422 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
3423 that marks the end of a replace operation in
3424 the form. This is an optional parameter that
3425 may be NULL. If it is NULL, then an the IFR
3426 opcodes specified by StartOpCodeHandle are
3427 inserted into the form.
3429 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
3430 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
3431 1) The form specified by HiiHandle, FormSetGuid,
3432 and FormId could not be found in the HII Database.
3433 2) No IFR opcodes in the target form match the first
3434 IFR opcode in StartOpCodeHandle.
3435 3) EndOpCOde is not NULL, and no IFR opcodes in the
3436 target form following a matching start opcode match
3437 the first IFR opcode in EndOpCodeHandle.
3438 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
3444 IN EFI_HII_HANDLE HiiHandle
,
3445 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3446 IN EFI_FORM_ID FormId
,
3447 IN VOID
*StartOpcodeHandle
,
3448 IN VOID
*EndOpcodeHandle OPTIONAL
3452 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
3453 UINT32 PackageListLength
;
3455 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
3457 UINT8
*UpdateBufferPos
;
3458 EFI_HII_PACKAGE_HEADER
*Package
;
3459 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
3460 EFI_HII_PACKAGE_HEADER PackageHeader
;
3462 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
3463 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
3466 // Input update data can't be NULL.
3468 ASSERT (HiiHandle
!= NULL
);
3469 ASSERT (StartOpcodeHandle
!= NULL
);
3470 UpdatePackageList
= NULL
;
3472 HiiPackageList
= NULL
;
3475 // Restrive buffer data from Opcode Handle
3477 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpcodeHandle
;
3478 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpcodeHandle
;
3481 // Get the orginal package list
3484 HiiPackageList
= NULL
;
3485 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3487 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
3489 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3493 HiiPackageList
= AllocatePool (BufferSize
);
3494 if (HiiPackageList
== NULL
) {
3495 Status
= EFI_OUT_OF_RESOURCES
;
3499 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3500 if (EFI_ERROR (Status
)) {
3505 // Calculate and allocate space for retrieval of IFR data
3507 BufferSize
+= OpCodeBufferStart
->Position
;
3508 UpdatePackageList
= AllocateZeroPool (BufferSize
);
3509 if (UpdatePackageList
== NULL
) {
3510 Status
= EFI_OUT_OF_RESOURCES
;
3515 // Allocate temp buffer to store the temp updated package buffer
3517 TempPacakge
= AllocateZeroPool (BufferSize
);
3518 if (TempPacakge
== NULL
) {
3519 Status
= EFI_OUT_OF_RESOURCES
;
3523 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
3526 // Copy the package list header
3528 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
3529 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3532 // Go through each package to find the matched pacakge and update one by one
3535 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3536 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
3537 while (Offset
< PackageListLength
) {
3538 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
3539 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3540 Offset
+= Package
->Length
;
3542 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
3544 // Check this package is the matched package.
3546 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
3548 // The matched package is found. Its pacakge buffer will be updated by the input new data.
3550 if (!EFI_ERROR(Status
)) {
3556 // Add updated package buffer
3558 Package
= TempPacakge
;
3563 // Add pacakge buffer
3565 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3566 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
3567 UpdateBufferPos
+= PackageHeader
.Length
;
3572 // Update package list length
3574 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
3575 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
3578 // Update Pacakge to show form
3580 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
3583 // Not matched form is found and updated.
3585 Status
= EFI_NOT_FOUND
;
3589 if (HiiPackageList
!= NULL
) {
3590 FreePool (HiiPackageList
);
3593 if (UpdatePackageList
!= NULL
) {
3594 FreePool (UpdatePackageList
);
3597 if (TempPacakge
!= NULL
) {
3598 FreePool (TempPacakge
);