2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 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 EFI_VARSTORE_ID VarStoreId
;
37 } IFR_VARSTORAGE_DATA
;
40 // <ConfigHdr> Template
42 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
44 EFI_FORM_BROWSER2_PROTOCOL
*mUefiFormBrowser2
= NULL
;
47 // Template used to mark the end of a list of packages
49 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList
= {
50 sizeof (EFI_HII_PACKAGE_HEADER
),
55 Extract Hii package list GUID for given HII handle.
57 If HiiHandle could not be found in the HII database, then ASSERT.
58 If Guid is NULL, then ASSERT.
60 @param Handle Hii handle
61 @param Guid Package list GUID
63 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
68 InternalHiiExtractGuidFromHiiHandle (
69 IN EFI_HII_HANDLE Handle
,
75 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
77 ASSERT (Guid
!= NULL
);
78 ASSERT (Handle
!= NULL
);
81 // Get HII PackageList
84 HiiPackageList
= NULL
;
86 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
87 ASSERT (Status
!= EFI_NOT_FOUND
);
89 if (Status
== EFI_BUFFER_TOO_SMALL
) {
90 HiiPackageList
= AllocatePool (BufferSize
);
91 ASSERT (HiiPackageList
!= NULL
);
93 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
95 if (EFI_ERROR (Status
)) {
96 FreePool (HiiPackageList
);
103 CopyGuid (Guid
, &HiiPackageList
->PackageListGuid
);
105 FreePool (HiiPackageList
);
111 Registers a list of packages in the HII Database and returns the HII Handle
112 associated with that registration. If an HII Handle has already been registered
113 with the same PackageListGuid and DeviceHandle, then NULL is returned. If there
114 are not enough resources to perform the registration, then NULL is returned.
115 If an empty list of packages is passed in, then NULL is returned. If the size of
116 the list of package is 0, then NULL is returned.
118 The variable arguments are pointers which point to package header that defined
119 by UEFI VFR compiler and StringGather tool.
121 #pragma pack (push, 1)
124 EFI_HII_PACKAGE_HEADER PackageHeader;
125 } EDKII_AUTOGEN_PACKAGES_HEADER;
128 @param[in] PackageListGuid The GUID of the package list.
129 @param[in] DeviceHandle If not NULL, the Device Handle on which
130 an instance of DEVICE_PATH_PROTOCOL is installed.
131 This Device Handle uniquely defines the device that
132 the added packages are associated with.
133 @param[in] ... The variable argument list that contains pointers
134 to packages terminated by a NULL.
136 @retval NULL A HII Handle has already been registered in the HII Database with
137 the same PackageListGuid and DeviceHandle.
138 @retval NULL The HII Handle could not be created.
139 @retval NULL An empty list of packages was passed in.
140 @retval NULL All packages are empty.
141 @retval Other The HII Handle associated with the newly registered package list.
147 IN CONST EFI_GUID
*PackageListGuid
,
148 IN EFI_HANDLE DeviceHandle OPTIONAL
,
155 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
156 EFI_HII_HANDLE HiiHandle
;
160 ASSERT (PackageListGuid
!= NULL
);
163 // Calculate the length of all the packages in the variable argument list
165 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
166 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
171 // If there are no packages in the variable argument list or all the packages
172 // are empty, then return a NULL HII Handle
179 // Add the length of the Package List Header and the terminating Package Header
181 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
184 // Allocate the storage for the entire Package List
186 PackageListHeader
= AllocateZeroPool (Length
);
189 // If the Package List can not be allocated, then return a NULL HII Handle
191 if (PackageListHeader
== NULL
) {
196 // Fill in the GUID and Length of the Package List Header
198 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
199 PackageListHeader
->PackageLength
= Length
;
202 // Initialize a pointer to the beginning if the Package List data
204 Data
= (UINT8
*)(PackageListHeader
+ 1);
207 // Copy the data from each package in the variable argument list
209 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
210 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
211 CopyMem (Data
, Package
+ 1, Length
);
217 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
219 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
222 // Register the package list with the HII Database
224 Status
= gHiiDatabase
->NewPackageList (
230 if (EFI_ERROR (Status
)) {
235 // Free the allocated package list
237 FreePool (PackageListHeader
);
240 // Return the new HII Handle
246 Removes a package list from the HII database.
248 If HiiHandle is NULL, then ASSERT.
249 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
251 @param[in] HiiHandle The handle that was previously registered in the HII database
257 IN EFI_HII_HANDLE HiiHandle
262 ASSERT (HiiHandle
!= NULL
);
263 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
264 ASSERT_EFI_ERROR (Status
);
269 Retrieves the array of all the HII Handles or the HII handles of a specific
270 package list GUID in the HII Database.
271 This array is terminated with a NULL HII Handle.
272 This function allocates the returned array using AllocatePool().
273 The caller is responsible for freeing the array with FreePool().
275 @param[in] PackageListGuid An optional parameter that is used to request
276 HII Handles associated with a specific
277 Package List GUID. If this parameter is NULL,
278 then all the HII Handles in the HII Database
279 are returned. If this parameter is not NULL,
280 then zero or more HII Handles associated with
281 PackageListGuid are returned.
283 @retval NULL No HII handles were found in the HII database
284 @retval NULL The array of HII Handles could not be retrieved
285 @retval Other A pointer to the NULL terminated array of HII Handles
291 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
295 UINTN HandleBufferLength
;
296 EFI_HII_HANDLE TempHiiHandleBuffer
;
297 EFI_HII_HANDLE
*HiiHandleBuffer
;
303 // Retrieve the size required for the buffer of all HII handles.
305 HandleBufferLength
= 0;
306 Status
= gHiiDatabase
->ListPackageLists (
308 EFI_HII_PACKAGE_TYPE_ALL
,
315 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
316 // then there are no HII handles in the HII database. If ListPackageLists()
317 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
318 // handles in the HII database.
320 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
322 // Return NULL if the size can not be retrieved, or if there are no HII
323 // handles in the HII Database
329 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
331 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
332 if (HiiHandleBuffer
== NULL
) {
334 // Return NULL if allocation fails.
340 // Retrieve the array of HII Handles in the HII Database
342 Status
= gHiiDatabase
->ListPackageLists (
344 EFI_HII_PACKAGE_TYPE_ALL
,
349 if (EFI_ERROR (Status
)) {
351 // Free the buffer and return NULL if the HII handles can not be retrieved.
353 FreePool (HiiHandleBuffer
);
357 if (PackageListGuid
== NULL
) {
359 // Return the NULL terminated array of HII handles in the HII Database
361 return HiiHandleBuffer
;
363 for (Index1
= 0, Index2
= 0; HiiHandleBuffer
[Index1
] != NULL
; Index1
++) {
364 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index1
], &Guid
);
365 ASSERT_EFI_ERROR (Status
);
366 if (CompareGuid (&Guid
, PackageListGuid
)) {
367 HiiHandleBuffer
[Index2
++] = HiiHandleBuffer
[Index1
];
371 HiiHandleBuffer
[Index2
] = NULL
;
372 return HiiHandleBuffer
;
374 FreePool (HiiHandleBuffer
);
381 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
382 hex digits that appear between a '=' and a '&' in a config string.
384 If ConfigString is NULL, then ASSERT().
386 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
388 @return Pointer to the Null-terminated Unicode result string.
393 InternalHiiLowerConfigString (
394 IN EFI_STRING ConfigString
400 ASSERT (ConfigString
!= NULL
);
403 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
405 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
406 if (*String
== L
'=') {
408 } else if (*String
== L
'&') {
410 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
411 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
419 Uses the BlockToConfig() service of the Config Routing Protocol to
420 convert <ConfigRequest> and a buffer to a <ConfigResp>
422 If ConfigRequest is NULL, then ASSERT().
423 If Block is NULL, then ASSERT().
425 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
426 @param[in] Block Pointer to a block of data.
427 @param[in] BlockSize The zie, in bytes, of Block.
429 @retval NULL The <ConfigResp> string could not be generated.
430 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
435 InternalHiiBlockToConfig (
436 IN CONST EFI_STRING ConfigRequest
,
437 IN CONST UINT8
*Block
,
442 EFI_STRING ConfigResp
;
445 ASSERT (ConfigRequest
!= NULL
);
446 ASSERT (Block
!= NULL
);
449 // Convert <ConfigRequest> to <ConfigResp>
451 Status
= gHiiConfigRouting
->BlockToConfig (
459 if (EFI_ERROR (Status
)) {
466 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
467 or set uncommitted data. If sata i being retrieved, then the buffer is
468 allocated using AllocatePool(). The caller is then responsible for freeing
469 the buffer using FreePool().
471 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
472 parameter that may be NULL.
473 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
474 is an optional parameter that may be NULL.
475 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
476 of uncommited data to set. If this parameter is NULL,
477 then the caller is requesting to get the uncommited data
478 from the Form Browser.
480 @retval NULL The uncommitted data could not be retrieved.
481 @retval Other A pointer to a buffer containing the uncommitted data.
486 InternalHiiBrowserCallback (
487 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
488 IN CONST CHAR16
*VariableName
, OPTIONAL
489 IN CONST EFI_STRING SetResultsData OPTIONAL
493 UINTN ResultsDataSize
;
494 EFI_STRING ResultsData
;
495 CHAR16 TempResultsData
;
500 if (mUefiFormBrowser2
== NULL
) {
501 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
502 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
509 if (SetResultsData
!= NULL
) {
511 // Request to to set data in the uncommitted browser state information
513 ResultsData
= SetResultsData
;
516 // Retrieve the length of the buffer required ResultsData from the Browser Callback
518 Status
= mUefiFormBrowser2
->BrowserCallback (
527 if (!EFI_ERROR (Status
)) {
529 // No Resluts Data, only allocate one char for '\0'
531 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
535 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
540 // Allocate the ResultsData buffer
542 ResultsData
= AllocateZeroPool (ResultsDataSize
);
543 if (ResultsData
== NULL
) {
549 // Retrieve or set the ResultsData from the Browser Callback
551 Status
= mUefiFormBrowser2
->BrowserCallback (
555 (BOOLEAN
)(SetResultsData
== NULL
),
559 if (EFI_ERROR (Status
)) {
567 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
568 information that includes a GUID, an optional Unicode string name, and a device
569 path. The string returned is allocated with AllocatePool(). The caller is
570 responsible for freeing the allocated string with FreePool().
572 The format of a <ConfigHdr> is as follows:
574 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
576 @param[in] Guid Pointer to an EFI_GUID that is the routing information
577 GUID. Each of the 16 bytes in Guid is converted to
578 a 2 Unicode character hexidecimal string. This is
579 an optional parameter that may be NULL.
580 @param[in] Name Pointer to a Null-terminated Unicode string that is
581 the routing information NAME. This is an optional
582 parameter that may be NULL. Each 16-bit Unicode
583 character in Name is converted to a 4 character Unicode
585 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
586 that is the routing information PATH. Each byte of
587 the Device Path associated with DriverHandle is converted
588 to a 2 Unicode character hexidecimal string.
590 @retval NULL DriverHandle does not support the Device Path Protocol.
591 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
596 HiiConstructConfigHdr (
597 IN CONST EFI_GUID
*Guid
, OPTIONAL
598 IN CONST CHAR16
*Name
, OPTIONAL
599 IN EFI_HANDLE DriverHandle
603 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
604 UINTN DevicePathSize
;
606 CHAR16
*ReturnString
;
611 // Compute the length of Name in Unicode characters.
612 // If Name is NULL, then the length is 0.
616 NameLength
= StrLen (Name
);
622 // Retrieve DevicePath Protocol associated with DriverHandle
624 if (DriverHandle
!= NULL
) {
625 DevicePath
= DevicePathFromHandle (DriverHandle
);
626 if (DevicePath
== NULL
) {
630 // Compute the size of the device path in bytes
632 DevicePathSize
= GetDevicePathSize (DevicePath
);
636 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
637 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
639 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
640 if (String
== NULL
) {
645 // Start with L"GUID="
647 ReturnString
= StrCpy (String
, L
"GUID=");
648 String
+= StrLen (String
);
652 // Append Guid converted to <HexCh>32
654 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
655 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
662 StrCpy (String
, L
"&NAME=");
663 String
+= StrLen (String
);
667 // Append Name converted to <Char>NameLength
669 for (; *Name
!= L
'\0'; Name
++) {
670 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
677 StrCpy (String
, L
"&PATH=");
678 String
+= StrLen (String
);
681 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
683 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
684 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
688 // Null terminate the Unicode string
693 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
695 return InternalHiiLowerConfigString (ReturnString
);
699 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
700 to binary buffer from <ConfigHdr>.
702 This is a internal function.
704 @param String UEFI configuration string.
705 @param Flag Flag specifies what type buffer will be retrieved.
706 @param Buffer Binary of Guid, Name or Device path.
708 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
709 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
710 @retval EFI_SUCCESS The buffer data is retrieved and translated to
715 InternalHiiGetBufferFromString (
716 IN EFI_STRING String
,
722 EFI_STRING ConfigHdr
;
729 if (String
== NULL
|| Buffer
== NULL
) {
730 return EFI_INVALID_PARAMETER
;
737 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
738 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
740 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
743 case GUID_CONFIG_STRING_TYPE
:
744 case PATH_CONFIG_STRING_TYPE
:
746 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
747 // as the device path and Guid resides in RAM memory.
748 // Translate the data into binary.
750 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
751 if (DataBuffer
== NULL
) {
752 return EFI_OUT_OF_RESOURCES
;
755 // Convert binary byte one by one
757 ZeroMem (TemStr
, sizeof (TemStr
));
758 for (Index
= 0; Index
< Length
; Index
++) {
759 TemStr
[0] = ConfigHdr
[Index
];
760 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
761 if ((Index
& 1) == 0) {
762 DataBuffer
[Index
/2] = DigitUint8
;
764 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
768 *Buffer
= DataBuffer
;
771 case NAME_CONFIG_STRING_TYPE
:
773 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
777 // Add the tailling char L'\0'
779 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
780 if (DataBuffer
== NULL
) {
781 return EFI_OUT_OF_RESOURCES
;
784 // Convert character one by one
786 StringPtr
= (CHAR16
*) DataBuffer
;
787 ZeroMem (TemStr
, sizeof (TemStr
));
788 for (Index
= 0; Index
< Length
; Index
+= 4) {
789 StrnCpy (TemStr
, ConfigHdr
+ Index
, 4);
790 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
793 // Add tailing L'\0' character
795 StringPtr
[Index
/4] = L
'\0';
797 *Buffer
= DataBuffer
;
801 return EFI_INVALID_PARAMETER
;
808 This function checks VarOffset and VarWidth is in the block range.
810 @param BlockArray The block array is to be checked.
811 @param VarOffset Offset of var to the structure
812 @param VarWidth Width of var.
814 @retval TRUE This Var is in the block range.
815 @retval FALSE This Var is not in the block range.
819 IN IFR_BLOCK_DATA
*BlockArray
,
825 IFR_BLOCK_DATA
*BlockData
;
828 // No Request Block array, all vars are got.
830 if (BlockArray
== NULL
) {
835 // Check the input var is in the request block range.
837 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
838 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
839 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
848 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
850 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
852 @param ValueString String in <BlockConfig> format and points to the
853 first character of <Number>.
854 @param ValueData The output value. Caller takes the responsibility
856 @param ValueLength Length of the <Number>, in characters.
858 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
860 @retval EFI_SUCCESS Value of <Number> is outputted in Number
866 InternalHiiGetValueOfNumber (
867 IN EFI_STRING ValueString
,
868 OUT UINT8
**ValueData
,
869 OUT UINTN
*ValueLength
872 EFI_STRING StringPtr
;
879 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
880 ASSERT (*ValueString
!= L
'\0');
883 // Get the length of value string
885 StringPtr
= ValueString
;
886 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
889 Length
= StringPtr
- ValueString
;
892 // Allocate buffer to store the value
894 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
896 return EFI_OUT_OF_RESOURCES
;
900 // Convert character one by one to the value buffer
902 ZeroMem (TemStr
, sizeof (TemStr
));
903 for (Index
= 0; Index
< Length
; Index
++) {
904 TemStr
[0] = ValueString
[Length
- Index
- 1];
905 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
906 if ((Index
& 1) == 0) {
907 Buf
[Index
/2] = DigitUint8
;
909 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
914 // Set the converted value and string length.
917 *ValueLength
= Length
;
922 Get value from config request resp string.
924 @param ConfigElement ConfigResp string contains the current setting.
925 @param VarName The variable name which need to get value.
926 @param VarValue The return value.
928 @retval EFI_SUCCESS Get the value for the VarName
929 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
932 GetValueFromRequest (
933 IN CHAR16
*ConfigElement
,
944 // Find VarName related string.
946 StringPtr
= StrStr (ConfigElement
, VarName
);
947 ASSERT (StringPtr
!= NULL
);
950 // Skip the "VarName=" string
952 StringPtr
+= StrLen (VarName
) + 1;
957 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
958 if (EFI_ERROR (Status
)) {
963 CopyMem (VarValue
, TmpBuffer
, (((Length
+ 1) / 2) < sizeof (UINT64
)) ? ((Length
+ 1) / 2) : sizeof (UINT64
));
965 FreePool (TmpBuffer
);
971 This internal function parses IFR data to validate current setting.
973 Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid;
974 else the VarBuffer and CurrentBlockArray is valid.
976 @param HiiPackageList Point to Hii package list.
977 @param PackageListLength The length of the pacakge.
978 @param VarGuid Guid of the buffer storage.
979 @param VarName Name of the buffer storage.
980 @param VarBuffer The data buffer for the storage.
981 @param CurrentBlockArray The block array from the config Requst string.
982 @param RequestElement The config string for this storage.
983 @param HiiHandle The HiiHandle for this formset.
984 @param NameValueType Whether current storage is name/value varstore or not.
986 @retval EFI_SUCCESS The current setting is valid.
987 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
988 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
991 ValidateQuestionFromVfr (
992 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
993 IN UINTN PackageListLength
,
994 IN EFI_GUID
*VarGuid
,
997 IN IFR_BLOCK_DATA
*CurrentBlockArray
,
998 IN CHAR16
*RequestElement
,
999 IN EFI_HII_HANDLE HiiHandle
,
1000 IN BOOLEAN NameValueType
1003 IFR_BLOCK_DATA VarBlockData
;
1008 EFI_IFR_TYPE_VALUE TmpValue
;
1010 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1011 UINT32 PackageOffset
;
1014 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1015 EFI_IFR_VARSTORE
*IfrVarStore
;
1016 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueStore
;
1017 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1018 IFR_VARSTORAGE_DATA VarStoreData
;
1019 EFI_IFR_ONE_OF
*IfrOneOf
;
1020 EFI_IFR_NUMERIC
*IfrNumeric
;
1021 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
1022 EFI_IFR_CHECKBOX
*IfrCheckBox
;
1023 EFI_IFR_STRING
*IfrString
;
1024 CHAR8
*VarStoreName
;
1026 CHAR16
*QuestionName
;
1030 // Initialize the local variables.
1033 VarStoreName
= NULL
;
1034 Status
= EFI_SUCCESS
;
1038 IfrNameValueStore
= NULL
;
1039 IfrEfiVarStore
= NULL
;
1040 ZeroMem (&VarStoreData
, sizeof (IFR_VARSTORAGE_DATA
));
1041 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1044 // Check IFR value is in block data, then Validate Value
1046 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1047 while (PackageOffset
< PackageListLength
) {
1048 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1051 // Parse IFR opcode from the form package.
1053 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1054 IfrOffset
= sizeof (PacakgeHeader
);
1055 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1056 while (IfrOffset
< PacakgeHeader
.Length
) {
1057 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1059 // Validate current setting to the value built in IFR opcode
1061 switch (IfrOpHdr
->OpCode
) {
1062 case EFI_IFR_VARSTORE_OP
:
1064 // VarStoreId has been found. No further found.
1066 if (VarStoreData
.VarStoreId
!= 0) {
1070 // Find the matched VarStoreId to the input VarGuid and VarName
1072 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1073 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1074 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1075 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1076 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1081 // The matched VarStore is found.
1083 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1090 if (IfrVarStore
!= NULL
) {
1091 VarStoreData
.VarStoreId
= IfrVarStore
->VarStoreId
;
1092 VarStoreData
.Size
= IfrVarStore
->Size
;
1095 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1097 // VarStoreId has been found. No further found.
1099 if (VarStoreData
.VarStoreId
!= 0) {
1103 // Find the matched VarStoreId to the input VarGuid
1105 IfrNameValueStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1106 if (!CompareGuid ((EFI_GUID
*) (VOID
*) &IfrNameValueStore
->Guid
, VarGuid
)) {
1107 IfrNameValueStore
= NULL
;
1110 if (IfrNameValueStore
!= NULL
) {
1111 VarStoreData
.VarStoreId
= IfrNameValueStore
->VarStoreId
;
1114 case EFI_IFR_VARSTORE_EFI_OP
:
1116 // VarStore is found. Don't need to search any more.
1118 if (VarStoreData
.VarStoreId
!= 0) {
1122 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1125 // If the length is small than the structure, this is from old efi
1126 // varstore definition. Old efi varstore get config directly from
1127 // GetVariable function.
1129 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1133 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrEfiVarStore
->Guid
, VarGuid
)) {
1134 VarStoreName
= (CHAR8
*) IfrEfiVarStore
->Name
;
1135 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1136 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1141 // The matched VarStore is found.
1143 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1144 IfrEfiVarStore
= NULL
;
1147 IfrEfiVarStore
= NULL
;
1150 if (IfrEfiVarStore
!= NULL
) {
1152 // Find the matched VarStore
1154 VarStoreData
.VarStoreId
= IfrEfiVarStore
->VarStoreId
;
1155 VarStoreData
.Size
= IfrEfiVarStore
->Size
;
1158 case EFI_IFR_FORM_OP
:
1159 case EFI_IFR_FORM_MAP_OP
:
1161 // Check the matched VarStoreId is found.
1163 if (VarStoreData
.VarStoreId
== 0) {
1167 case EFI_IFR_ONE_OF_OP
:
1169 // Check whether current value is the one of option.
1173 // OneOf question is not in IFR Form. This IFR form is not valid.
1175 if (VarStoreData
.VarStoreId
== 0) {
1176 return EFI_INVALID_PARAMETER
;
1179 // Check whether this question is for the requested varstore.
1181 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1182 if (IfrOneOf
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1186 if (NameValueType
) {
1187 QuestionName
= HiiGetString (HiiHandle
, IfrOneOf
->Question
.VarStoreInfo
.VarName
, NULL
);
1188 ASSERT (QuestionName
!= NULL
);
1190 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1192 // This question is not in the current configuration string. Skip it.
1197 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1198 if (EFI_ERROR (Status
)) {
1203 // Get Offset by Question header and Width by DataType Flags
1205 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1206 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1208 // Check whether this question is in current block array.
1210 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1212 // This question is not in the current configuration string. Skip it.
1217 // Check this var question is in the var storage
1219 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1221 // This question exceeds the var store size.
1223 return EFI_INVALID_PARAMETER
;
1227 // Get the current value for oneof opcode
1230 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1233 // Set Block Data, to be checked in the following Oneof option opcode.
1235 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1236 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1238 case EFI_IFR_NUMERIC_OP
:
1240 // Check the current value is in the numeric range.
1244 // Numeric question is not in IFR Form. This IFR form is not valid.
1246 if (VarStoreData
.VarStoreId
== 0) {
1247 return EFI_INVALID_PARAMETER
;
1250 // Check whether this question is for the requested varstore.
1252 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1253 if (IfrNumeric
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1257 if (NameValueType
) {
1258 QuestionName
= HiiGetString (HiiHandle
, IfrNumeric
->Question
.VarStoreInfo
.VarName
, NULL
);
1259 ASSERT (QuestionName
!= NULL
);
1261 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1263 // This question is not in the current configuration string. Skip it.
1268 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1269 if (EFI_ERROR (Status
)) {
1274 // Get Offset by Question header and Width by DataType Flags
1276 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1277 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1279 // Check whether this question is in current block array.
1281 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1283 // This question is not in the current configuration string. Skip it.
1288 // Check this var question is in the var storage
1290 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1292 // This question exceeds the var store size.
1294 return EFI_INVALID_PARAMETER
;
1298 // Check the current value is in the numeric range.
1301 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1303 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1304 case EFI_IFR_NUMERIC_SIZE_1
:
1305 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1307 // Not in the valid range.
1309 return EFI_INVALID_PARAMETER
;
1312 case EFI_IFR_NUMERIC_SIZE_2
:
1313 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1315 // Not in the valid range.
1317 return EFI_INVALID_PARAMETER
;
1320 case EFI_IFR_NUMERIC_SIZE_4
:
1321 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1323 // Not in the valid range.
1325 return EFI_INVALID_PARAMETER
;
1328 case EFI_IFR_NUMERIC_SIZE_8
:
1329 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1331 // Not in the valid range.
1333 return EFI_INVALID_PARAMETER
;
1339 case EFI_IFR_CHECKBOX_OP
:
1341 // Check value is BOOLEAN type, only 0 and 1 is valid.
1345 // CheckBox question is not in IFR Form. This IFR form is not valid.
1347 if (VarStoreData
.VarStoreId
== 0) {
1348 return EFI_INVALID_PARAMETER
;
1352 // Check whether this question is for the requested varstore.
1354 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1355 if (IfrCheckBox
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1359 if (NameValueType
) {
1360 QuestionName
= HiiGetString (HiiHandle
, IfrCheckBox
->Question
.VarStoreInfo
.VarName
, NULL
);
1361 ASSERT (QuestionName
!= NULL
);
1363 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1365 // This question is not in the current configuration string. Skip it.
1370 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1371 if (EFI_ERROR (Status
)) {
1376 // Get Offset by Question header
1378 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1379 Width
= (UINT16
) sizeof (BOOLEAN
);
1381 // Check whether this question is in current block array.
1383 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1385 // This question is not in the current configuration string. Skip it.
1390 // Check this var question is in the var storage
1392 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1394 // This question exceeds the var store size.
1396 return EFI_INVALID_PARAMETER
;
1399 // Check the current value is in the numeric range.
1402 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1405 // Boolean type, only 1 and 0 is valid.
1408 return EFI_INVALID_PARAMETER
;
1411 case EFI_IFR_STRING_OP
:
1413 // Check current string length is less than maxsize
1417 // CheckBox question is not in IFR Form. This IFR form is not valid.
1419 if (VarStoreData
.VarStoreId
== 0) {
1420 return EFI_INVALID_PARAMETER
;
1424 // Check whether this question is for the requested varstore.
1426 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1427 if (IfrString
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1431 // Get Width by OneOf Flags
1433 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1434 if (NameValueType
) {
1435 QuestionName
= HiiGetString (HiiHandle
, IfrString
->Question
.VarStoreInfo
.VarName
, NULL
);
1436 ASSERT (QuestionName
!= NULL
);
1438 StringPtr
= StrStr (RequestElement
, QuestionName
);
1439 if (StringPtr
== NULL
) {
1441 // This question is not in the current configuration string. Skip it.
1452 // Check current string length is less than maxsize
1454 if (StrSize (StringPtr
) > Width
) {
1455 return EFI_INVALID_PARAMETER
;
1459 // Get Offset/Width by Question header and OneOf Flags
1461 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1463 // Check whether this question is in current block array.
1465 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1467 // This question is not in the current configuration string. Skip it.
1472 // Check this var question is in the var storage
1474 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1476 // This question exceeds the var store size.
1478 return EFI_INVALID_PARAMETER
;
1482 // Check current string length is less than maxsize
1484 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1485 return EFI_INVALID_PARAMETER
;
1489 case EFI_IFR_ONE_OF_OPTION_OP
:
1491 // Opcode Scope is zero. This one of option is not to be checked.
1493 if (VarBlockData
.Scope
== 0) {
1498 // Only check for OneOf and OrderList opcode
1500 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1501 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1503 // Check current value is the value of one of option.
1505 ASSERT (IfrOneOfOption
->Type
<= EFI_IFR_TYPE_NUM_SIZE_64
);
1506 ZeroMem (&TmpValue
, sizeof (EFI_IFR_TYPE_VALUE
));
1507 CopyMem (&TmpValue
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
1508 if (VarValue
== TmpValue
.u64
) {
1510 // The value is one of option value.
1511 // Set OpCode to Zero, don't need check again.
1513 VarBlockData
.OpCode
= 0;
1517 case EFI_IFR_END_OP
:
1519 // Decrease opcode scope for the validated opcode
1521 if (VarBlockData
.Scope
> 0) {
1522 VarBlockData
.Scope
--;
1526 // OneOf value doesn't belong to one of option value.
1528 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1529 return EFI_INVALID_PARAMETER
;
1534 // Increase Scope for the validated opcode
1536 if (VarBlockData
.Scope
> 0) {
1537 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1542 // Go to the next opcode
1544 IfrOffset
+= IfrOpHdr
->Length
;
1547 // Only one form is in a package list.
1553 // Go to next package.
1555 PackageOffset
+= PacakgeHeader
.Length
;
1562 This internal function parses IFR data to validate current setting.
1564 @param ConfigElement ConfigResp element string contains the current setting.
1565 @param CurrentBlockArray Current block array.
1566 @param VarBuffer Data buffer for this varstore.
1568 @retval EFI_SUCCESS The current setting is valid.
1569 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1570 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1574 IN CHAR16
*ConfigElement
,
1575 OUT IFR_BLOCK_DATA
**CurrentBlockArray
,
1576 OUT UINT8
**VarBuffer
1579 IFR_BLOCK_DATA
*BlockData
;
1580 IFR_BLOCK_DATA
*NewBlockData
;
1581 EFI_STRING StringPtr
;
1587 UINTN MaxBufferSize
;
1589 CHAR8
*VarStoreName
;
1591 IFR_BLOCK_DATA
*BlockArray
;
1595 // Initialize the local variables.
1598 VarStoreName
= NULL
;
1599 Status
= EFI_SUCCESS
;
1601 NewBlockData
= NULL
;
1604 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
1605 DataBuffer
= AllocateZeroPool (MaxBufferSize
);
1606 if (DataBuffer
== NULL
) {
1607 return EFI_OUT_OF_RESOURCES
;
1613 BlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1614 if (BlockArray
== NULL
) {
1615 Status
= EFI_OUT_OF_RESOURCES
;
1618 InitializeListHead (&BlockArray
->Entry
);
1620 StringPtr
= StrStr (ConfigElement
, L
"&OFFSET=");
1621 ASSERT (StringPtr
!= NULL
);
1624 // Parse each <RequestElement> if exists
1625 // Only <BlockName> format is supported by this help function.
1626 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1628 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1630 // Skip the &OFFSET= string
1632 StringPtr
+= StrLen (L
"&OFFSET=");
1637 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1638 if (EFI_ERROR (Status
)) {
1645 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1647 FreePool (TmpBuffer
);
1650 StringPtr
+= Length
;
1651 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1652 Status
= EFI_INVALID_PARAMETER
;
1655 StringPtr
+= StrLen (L
"&WIDTH=");
1660 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1661 if (EFI_ERROR (Status
)) {
1668 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1670 FreePool (TmpBuffer
);
1673 StringPtr
+= Length
;
1674 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1675 Status
= EFI_INVALID_PARAMETER
;
1679 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1680 Status
= EFI_INVALID_PARAMETER
;
1683 StringPtr
+= StrLen (L
"&VALUE=");
1688 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1689 if (EFI_ERROR (Status
)) {
1693 StringPtr
+= Length
;
1694 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1695 Status
= EFI_INVALID_PARAMETER
;
1700 // Check whether VarBuffer is enough
1702 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1703 DataBuffer
= ReallocatePool (
1705 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1708 if (DataBuffer
== NULL
) {
1709 Status
= EFI_OUT_OF_RESOURCES
;
1712 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1716 // Update the Block with configuration info
1718 CopyMem (DataBuffer
+ Offset
, TmpBuffer
, Width
);
1719 FreePool (TmpBuffer
);
1723 // Set new Block Data
1725 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1726 if (NewBlockData
== NULL
) {
1727 Status
= EFI_OUT_OF_RESOURCES
;
1730 NewBlockData
->Offset
= Offset
;
1731 NewBlockData
->Width
= Width
;
1734 // Insert the new block data into the block data array.
1736 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1737 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1738 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1739 if (NewBlockData
->Width
> BlockData
->Width
) {
1740 BlockData
->Width
= NewBlockData
->Width
;
1742 FreePool (NewBlockData
);
1744 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1746 // Insert new block data as the previous one of this link.
1748 InsertTailList (Link
, &NewBlockData
->Entry
);
1754 // Insert new block data into the array tail.
1756 if (Link
== &BlockArray
->Entry
) {
1757 InsertTailList (Link
, &NewBlockData
->Entry
);
1761 // If '\0', parsing is finished.
1763 if (*StringPtr
== 0) {
1767 // Go to next ConfigBlock
1772 // Merge the aligned block data into the single block data.
1774 Link
= BlockArray
->Entry
.ForwardLink
;
1775 while ((Link
!= &BlockArray
->Entry
) && (Link
->ForwardLink
!= &BlockArray
->Entry
)) {
1776 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1777 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1778 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1779 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1780 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1782 RemoveEntryList (Link
->ForwardLink
);
1783 FreePool (NewBlockData
);
1786 Link
= Link
->ForwardLink
;
1789 *VarBuffer
= DataBuffer
;
1790 *CurrentBlockArray
= BlockArray
;
1794 if (DataBuffer
!= NULL
) {
1795 FreePool (DataBuffer
);
1798 if (BlockArray
!= NULL
) {
1800 // Free Link Array CurrentBlockArray
1802 while (!IsListEmpty (&BlockArray
->Entry
)) {
1803 BlockData
= BASE_CR (BlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1804 RemoveEntryList (&BlockData
->Entry
);
1805 FreePool (BlockData
);
1807 FreePool (BlockArray
);
1814 This internal function parses IFR data to validate current setting.
1816 @param ConfigResp ConfigResp string contains the current setting.
1817 @param HiiPackageList Point to Hii package list.
1818 @param PackageListLength The length of the pacakge.
1819 @param VarGuid Guid of the buffer storage.
1820 @param VarName Name of the buffer storage.
1821 @param HiiHandle The HiiHandle for this package.
1823 @retval EFI_SUCCESS The current setting is valid.
1824 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1825 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1829 InternalHiiValidateCurrentSetting (
1830 IN EFI_STRING ConfigResp
,
1831 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
1832 IN UINTN PackageListLength
,
1833 IN EFI_GUID
*VarGuid
,
1835 IN EFI_HII_HANDLE HiiHandle
1840 IFR_BLOCK_DATA
*CurrentBlockArray
;
1841 IFR_BLOCK_DATA
*BlockData
;
1843 BOOLEAN NameValueType
;
1845 CurrentBlockArray
= NULL
;
1848 Status
= EFI_SUCCESS
;
1851 // If StringPtr != NULL, get the request elements.
1853 if (StrStr (ConfigResp
, L
"&OFFSET=") != NULL
) {
1854 Status
= GetBlockDataInfo(ConfigResp
, &CurrentBlockArray
, &VarBuffer
);
1855 if (EFI_ERROR (Status
)) {
1858 NameValueType
= FALSE
;
1861 // Skip header part.
1863 StringPtr
= StrStr (ConfigResp
, L
"PATH=");
1864 ASSERT (StringPtr
!= NULL
);
1866 if (StrStr (StringPtr
, L
"&") != NULL
) {
1867 NameValueType
= TRUE
;
1870 // Not found Request element, return success.
1876 Status
= ValidateQuestionFromVfr(
1888 if (VarBuffer
!= NULL
) {
1889 FreePool (VarBuffer
);
1892 if (CurrentBlockArray
!= NULL
) {
1894 // Free Link Array CurrentBlockArray
1896 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1897 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1898 RemoveEntryList (&BlockData
->Entry
);
1899 FreePool (BlockData
);
1901 FreePool (CurrentBlockArray
);
1908 Check whether the ConfigRequest string has the request elements.
1909 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
1910 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
1912 @param ConfigRequest The input config request string.
1914 @retval TRUE The input include config request elements.
1915 @retval FALSE The input string not includes.
1919 GetElementsFromRequest (
1920 IN EFI_STRING ConfigRequest
1923 EFI_STRING TmpRequest
;
1925 TmpRequest
= StrStr (ConfigRequest
, L
"PATH=");
1926 ASSERT (TmpRequest
!= NULL
);
1928 if ((StrStr (TmpRequest
, L
"&OFFSET=") != NULL
) || (StrStr (TmpRequest
, L
"&") != NULL
)) {
1936 This function parses the input ConfigRequest string and its matched IFR code
1937 string for setting default value and validating current setting.
1939 1. For setting default action, Reset the default value specified by DefaultId
1940 to the driver configuration got by Request string.
1941 2. For validating current setting, Validate the current configuration
1942 by parsing HII form IFR opcode.
1944 NULL request string support depends on the ExportConfig interface of
1945 HiiConfigRouting protocol in UEFI specification.
1947 @param Request A null-terminated Unicode string in
1948 <MultiConfigRequest> format. It can be NULL.
1949 If it is NULL, all current configuration for the
1950 entirety of the current HII database will be validated.
1951 If it is NULL, all configuration for the
1952 entirety of the current HII database will be reset.
1953 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1954 @param ActionType Action supports setting defaults and validate current setting.
1956 @retval TURE Action runs successfully.
1957 @retval FALSE Action is not valid or Action can't be executed successfully..
1961 InternalHiiIfrValueAction (
1962 IN CONST EFI_STRING Request
, OPTIONAL
1963 IN UINT16 DefaultId
,
1967 EFI_STRING ConfigAltResp
;
1968 EFI_STRING ConfigAltHdr
;
1969 EFI_STRING ConfigResp
;
1970 EFI_STRING Progress
;
1971 EFI_STRING StringPtr
;
1972 EFI_STRING StringHdr
;
1974 EFI_HANDLE DriverHandle
;
1975 EFI_HANDLE TempDriverHandle
;
1976 EFI_HII_HANDLE
*HiiHandleBuffer
;
1977 EFI_HII_HANDLE HiiHandle
;
1982 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1983 UINTN PackageListLength
;
1984 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1985 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1987 ConfigAltResp
= NULL
;
1992 ConfigAltHdr
= NULL
;
1993 HiiHandleBuffer
= NULL
;
1995 TempDriverHandle
= NULL
;
1997 HiiPackageList
= NULL
;
2000 // Only support set default and validate setting action.
2002 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
2007 // Get the full requested value and deault value string.
2009 if (Request
!= NULL
) {
2010 Status
= gHiiConfigRouting
->ExtractConfig (
2017 Status
= gHiiConfigRouting
->ExportConfig (
2023 if (EFI_ERROR (Status
)) {
2027 StringPtr
= ConfigAltResp
;
2029 while (StringPtr
!= L
'\0') {
2031 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
2033 StringHdr
= StringPtr
;
2038 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2039 Status
= EFI_INVALID_PARAMETER
;
2042 StringPtr
+= StrLen (L
"GUID=");
2043 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
2044 if (EFI_ERROR (Status
)) {
2049 // Get Name value VarName
2051 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
2054 if (*StringPtr
== L
'\0') {
2055 Status
= EFI_INVALID_PARAMETER
;
2058 StringPtr
+= StrLen (L
"&NAME=");
2059 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
2060 if (EFI_ERROR (Status
)) {
2065 // Get Path value DevicePath
2067 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
2070 if (*StringPtr
== L
'\0') {
2071 Status
= EFI_INVALID_PARAMETER
;
2074 StringPtr
+= StrLen (L
"&PATH=");
2075 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
2076 if (EFI_ERROR (Status
)) {
2081 // Get the Driver handle by the got device path.
2083 TempDevicePath
= DevicePath
;
2084 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
2085 if (EFI_ERROR (Status
)) {
2090 // Find the matched Hii Handle for the found Driver handle
2092 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
2093 if (HiiHandleBuffer
== NULL
) {
2094 Status
= EFI_NOT_FOUND
;
2098 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
2099 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
2100 if (TempDriverHandle
== DriverHandle
) {
2105 HiiHandle
= HiiHandleBuffer
[Index
];
2106 FreePool (HiiHandleBuffer
);
2108 if (HiiHandle
== NULL
) {
2110 // This request string has no its Hii package.
2111 // Its default value and validating can't execute by parsing IFR data.
2112 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
2114 Status
= EFI_SUCCESS
;
2115 goto NextConfigAltResp
;
2119 // 2. Get HiiPackage by HiiHandle
2121 PackageListLength
= 0;
2122 HiiPackageList
= NULL
;
2123 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
2126 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
2128 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
2129 Status
= EFI_INVALID_PARAMETER
;
2133 HiiPackageList
= AllocatePool (PackageListLength
);
2134 if (HiiPackageList
== NULL
) {
2135 Status
= EFI_OUT_OF_RESOURCES
;
2140 // Get PackageList on HiiHandle
2142 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
2143 if (EFI_ERROR (Status
)) {
2148 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
2149 // Get the default configuration string according to the default ID.
2151 Status
= gHiiConfigRouting
->GetAltConfig (
2157 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultId
:NULL
, // it can be NULL to get the current setting.
2162 // The required setting can't be found. So, it is not required to be validated and set.
2164 if (EFI_ERROR (Status
)) {
2165 Status
= EFI_SUCCESS
;
2166 goto NextConfigAltResp
;
2169 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
2171 if (!GetElementsFromRequest (ConfigResp
)) {
2172 goto NextConfigAltResp
;
2176 // 4. Set the default configuration information or Validate current setting by parse IFR code.
2177 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2179 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
2181 // Set the default configuration information.
2183 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
2186 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2188 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
, HiiHandle
);
2191 if (EFI_ERROR (Status
)) {
2197 // Free the allocated pacakge buffer and the got ConfigResp string.
2199 if (HiiPackageList
!= NULL
) {
2200 FreePool (HiiPackageList
);
2201 HiiPackageList
= NULL
;
2204 if (ConfigResp
!= NULL
) {
2205 FreePool (ConfigResp
);
2210 // Free the allocated buffer.
2218 FreePool (DevicePath
);
2222 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
2226 // Get and Skip ConfigHdr
2228 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
2231 if (*StringPtr
== L
'\0') {
2236 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
2237 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
2239 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
2240 if (ConfigAltHdr
== NULL
) {
2241 Status
= EFI_OUT_OF_RESOURCES
;
2244 StrCpy (ConfigAltHdr
, L
"&");
2245 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
2246 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
2249 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
2251 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
2252 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
2253 if (*StringPtr
== L
'\0') {
2259 // Free the allocated ConfigAltHdr string
2261 FreePool (ConfigAltHdr
);
2262 if (*StringPtr
== L
'\0') {
2267 // Find &GUID as the next ConfigHdr
2269 StringPtr
= StrStr (StringPtr
, L
"&GUID");
2270 if (StringPtr
== NULL
) {
2281 if (VarGuid
!= NULL
) {
2285 if (VarName
!= NULL
) {
2289 if (DevicePath
!= NULL
) {
2290 FreePool (DevicePath
);
2293 if (ConfigResp
!= NULL
) {
2294 FreePool (ConfigResp
);
2297 if (ConfigAltResp
!= NULL
) {
2298 FreePool (ConfigAltResp
);
2301 if (HiiPackageList
!= NULL
) {
2302 FreePool (HiiPackageList
);
2305 if (EFI_ERROR (Status
)) {
2313 Validate the current configuration by parsing HII form IFR opcode.
2315 NULL request string support depends on the ExportConfig interface of
2316 HiiConfigRouting protocol in UEFI specification.
2318 @param Request A null-terminated Unicode string in
2319 <MultiConfigRequest> format. It can be NULL.
2320 If it is NULL, all current configuration for the
2321 entirety of the current HII database will be validated.
2323 @retval TRUE Current configuration is valid.
2324 @retval FALSE Current configuration is invalid.
2328 HiiValidateSettings (
2329 IN CONST EFI_STRING Request OPTIONAL
2332 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2336 Reset the default value specified by DefaultId to the driver
2337 configuration got by Request string.
2339 NULL request string support depends on the ExportConfig interface of
2340 HiiConfigRouting protocol in UEFI specification.
2342 @param Request A null-terminated Unicode string in
2343 <MultiConfigRequest> format. It can be NULL.
2344 If it is NULL, all configuration for the
2345 entirety of the current HII database will be reset.
2346 @param DefaultId Specifies the type of defaults to retrieve.
2348 @retval TURE The default value is set successfully.
2349 @retval FALSE The default value can't be found and set.
2354 IN CONST EFI_STRING Request
, OPTIONAL
2358 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2362 Determines if two values in config strings match.
2364 Compares the substring between StartSearchString and StopSearchString in
2365 FirstString to the substring between StartSearchString and StopSearchString
2366 in SecondString. If the two substrings match, then TRUE is returned. If the
2367 two substrings do not match, then FALSE is returned.
2369 If FirstString is NULL, then ASSERT().
2370 If SecondString is NULL, then ASSERT().
2371 If StartSearchString is NULL, then ASSERT().
2372 If StopSearchString is NULL, then ASSERT().
2374 @param FirstString Pointer to the first Null-terminated Unicode string.
2375 @param SecondString Pointer to the second Null-terminated Unicode string.
2376 @param StartSearchString Pointer to the Null-terminated Unicode string that
2377 marks the start of the value string to compare.
2378 @param StopSearchString Pointer to the Null-terminated Unicode string that
2379 marks the end of the value string to compare.
2381 @retval FALSE StartSearchString is not present in FirstString.
2382 @retval FALSE StartSearchString is not present in SecondString.
2383 @retval FALSE StopSearchString is not present in FirstString.
2384 @retval FALSE StopSearchString is not present in SecondString.
2385 @retval FALSE The length of the substring in FirstString is not the
2386 same length as the substring in SecondString.
2387 @retval FALSE The value string in FirstString does not matche the
2388 value string in SecondString.
2389 @retval TRUE The value string in FirstString matches the value
2390 string in SecondString.
2395 InternalHiiCompareSubString (
2396 IN CHAR16
*FirstString
,
2397 IN CHAR16
*SecondString
,
2398 IN CHAR16
*StartSearchString
,
2399 IN CHAR16
*StopSearchString
2402 CHAR16
*EndFirstString
;
2403 CHAR16
*EndSecondString
;
2405 ASSERT (FirstString
!= NULL
);
2406 ASSERT (SecondString
!= NULL
);
2407 ASSERT (StartSearchString
!= NULL
);
2408 ASSERT (StopSearchString
!= NULL
);
2410 FirstString
= StrStr (FirstString
, StartSearchString
);
2411 if (FirstString
== NULL
) {
2415 SecondString
= StrStr (SecondString
, StartSearchString
);
2416 if (SecondString
== NULL
) {
2420 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2421 if (EndFirstString
== NULL
) {
2425 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2426 if (EndSecondString
== NULL
) {
2430 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2434 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2438 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2440 If ConfigHdr is NULL, then ASSERT().
2442 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2443 @param[in] Guid GUID of the storage.
2444 @param[in] Name NAME of the storage.
2446 @retval TRUE Routing information matches <ConfigHdr>.
2447 @retval FALSE Routing information does not match <ConfigHdr>.
2452 HiiIsConfigHdrMatch (
2453 IN CONST EFI_STRING ConfigHdr
,
2454 IN CONST EFI_GUID
*Guid
, OPTIONAL
2455 IN CONST CHAR16
*Name OPTIONAL
2458 EFI_STRING CompareConfigHdr
;
2461 ASSERT (ConfigHdr
!= NULL
);
2464 // Use Guid and Name to generate a <ConfigHdr> string
2466 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2467 if (CompareConfigHdr
== NULL
) {
2474 // Compare GUID value strings
2476 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2479 if (Result
&& Name
!= NULL
) {
2481 // Compare NAME value strings
2483 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2487 // Free the <ConfigHdr> string
2489 FreePool (CompareConfigHdr
);
2495 Retrieves uncommitted data from the Form Browser and converts it to a binary
2498 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2499 parameter that may be NULL.
2500 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2501 is an optional parameter that may be NULL.
2502 @param[in] BufferSize Length in bytes of buffer to hold retrieved data.
2503 @param[out] Buffer Buffer of data to be updated.
2505 @retval FALSE The uncommitted data could not be retrieved.
2506 @retval TRUE The uncommitted data was retrieved.
2512 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2513 IN CONST CHAR16
*VariableName
, OPTIONAL
2514 IN UINTN BufferSize
,
2518 EFI_STRING ResultsData
;
2520 EFI_STRING ConfigResp
;
2525 // Retrieve the results data from the Browser Callback
2527 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2528 if (ResultsData
== NULL
) {
2533 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2535 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2536 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2537 ConfigResp
= AllocateZeroPool (Size
);
2538 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2541 // Free the allocated buffer
2543 FreePool (ResultsData
);
2544 if (ConfigResp
== NULL
) {
2549 // Convert <ConfigResp> to a buffer
2551 Status
= gHiiConfigRouting
->ConfigToBlock (
2559 // Free the allocated buffer
2561 FreePool (ConfigResp
);
2563 if (EFI_ERROR (Status
)) {
2571 Updates uncommitted data in the Form Browser.
2573 If Buffer is NULL, then ASSERT().
2575 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2576 parameter that may be NULL.
2577 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2578 is an optional parameter that may be NULL.
2579 @param[in] BufferSize Length, in bytes, of Buffer.
2580 @param[in] Buffer Buffer of data to commit.
2581 @param[in] RequestElement An optional field to specify which part of the
2582 buffer data will be send back to Browser. If NULL,
2583 the whole buffer of data will be committed to
2585 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2587 @retval FALSE The uncommitted data could not be updated.
2588 @retval TRUE The uncommitted data was updated.
2594 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2595 IN CONST CHAR16
*VariableName
, OPTIONAL
2596 IN UINTN BufferSize
,
2597 IN CONST UINT8
*Buffer
,
2598 IN CONST CHAR16
*RequestElement OPTIONAL
2602 EFI_STRING ConfigRequest
;
2603 EFI_STRING ConfigResp
;
2604 EFI_STRING ResultsData
;
2606 ASSERT (Buffer
!= NULL
);
2609 // Construct <ConfigRequest>
2611 if (RequestElement
== NULL
) {
2613 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2614 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2616 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2617 ConfigRequest
= AllocateZeroPool (Size
);
2618 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2621 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2622 // followed by <RequestElement> followed by a Null-terminator
2624 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2625 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2626 ConfigRequest
= AllocateZeroPool (Size
);
2627 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2629 if (ConfigRequest
== NULL
) {
2634 // Convert <ConfigRequest> to <ConfigResp>
2636 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2637 FreePool (ConfigRequest
);
2638 if (ConfigResp
== NULL
) {
2643 // Set data in the uncommitted browser state information
2645 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2646 FreePool (ConfigResp
);
2648 return (BOOLEAN
)(ResultsData
!= NULL
);
2651 /////////////////////////////////////////
2652 /////////////////////////////////////////
2654 /////////////////////////////////////////
2655 /////////////////////////////////////////
2657 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2663 } HII_LIB_OPCODE_BUFFER
;
2666 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2668 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2669 1, // EFI_IFR_TYPE_NUM_SIZE_8
2670 2, // EFI_IFR_TYPE_NUM_SIZE_16
2671 4, // EFI_IFR_TYPE_NUM_SIZE_32
2672 8, // EFI_IFR_TYPE_NUM_SIZE_64
2673 1, // EFI_IFR_TYPE_BOOLEAN
2674 3, // EFI_IFR_TYPE_TIME
2675 4, // EFI_IFR_TYPE_DATE
2676 2 // EFI_IFR_TYPE_STRING
2680 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2681 HiiFreeOpCodeHandle().
2683 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2684 @retval Other A new OpCode handle.
2689 HiiAllocateOpCodeHandle (
2693 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2695 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2696 if (OpCodeBuffer
== NULL
) {
2699 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2700 if (OpCodeBuffer
->Buffer
== NULL
) {
2701 FreePool (OpCodeBuffer
);
2704 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2705 OpCodeBuffer
->Position
= 0;
2706 return (VOID
*)OpCodeBuffer
;
2710 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().
2711 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2712 Handle are also freed.
2714 If OpCodeHandle is NULL, then ASSERT().
2716 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2721 HiiFreeOpCodeHandle (
2725 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2727 ASSERT (OpCodeHandle
!= NULL
);
2729 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2730 if (OpCodeBuffer
->Buffer
!= NULL
) {
2731 FreePool (OpCodeBuffer
->Buffer
);
2733 FreePool (OpCodeBuffer
);
2737 Internal function gets the current position of opcode buffer.
2739 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2741 @return Current position of opcode buffer.
2745 InternalHiiOpCodeHandlePosition (
2746 IN VOID
*OpCodeHandle
2749 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2753 Internal function gets the start pointer of opcode buffer.
2755 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2757 @return Pointer to the opcode buffer base.
2761 InternalHiiOpCodeHandleBuffer (
2762 IN VOID
*OpCodeHandle
2765 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2769 Internal function reserves the enough buffer for current opcode.
2770 When the buffer is not enough, Opcode buffer will be extended.
2772 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2773 @param[in] Size Size of current opcode.
2775 @return Pointer to the current opcode.
2779 InternalHiiGrowOpCodeHandle (
2780 IN VOID
*OpCodeHandle
,
2784 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2787 ASSERT (OpCodeHandle
!= NULL
);
2789 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2790 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2791 Buffer
= ReallocatePool (
2792 OpCodeBuffer
->BufferSize
,
2793 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2794 OpCodeBuffer
->Buffer
2796 ASSERT (Buffer
!= NULL
);
2797 OpCodeBuffer
->Buffer
= Buffer
;
2798 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2800 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2801 OpCodeBuffer
->Position
+= Size
;
2806 Internal function creates opcode based on the template opcode.
2808 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2809 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2810 @param[in] OpCode OpCode IFR value.
2811 @param[in] OpCodeSize Size of opcode.
2812 @param[in] ExtensionSize Size of extended opcode.
2813 @param[in] Scope Scope bit of opcode.
2815 @return Pointer to the current opcode with opcode data.
2819 InternalHiiCreateOpCodeExtended (
2820 IN VOID
*OpCodeHandle
,
2821 IN VOID
*OpCodeTemplate
,
2823 IN UINTN OpCodeSize
,
2824 IN UINTN ExtensionSize
,
2828 EFI_IFR_OP_HEADER
*Header
;
2831 ASSERT (OpCodeTemplate
!= NULL
);
2832 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2834 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2835 Header
->OpCode
= OpCode
;
2836 Header
->Scope
= Scope
;
2837 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2838 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2839 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2843 Internal function creates opcode based on the template opcode for the normal opcode.
2845 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2846 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2847 @param[in] OpCode OpCode IFR value.
2848 @param[in] OpCodeSize Size of opcode.
2850 @return Pointer to the current opcode with opcode data.
2854 InternalHiiCreateOpCode (
2855 IN VOID
*OpCodeHandle
,
2856 IN VOID
*OpCodeTemplate
,
2861 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2865 Append raw opcodes to an OpCodeHandle.
2867 If OpCodeHandle is NULL, then ASSERT().
2868 If RawBuffer is NULL, then ASSERT();
2870 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2871 @param[in] RawBuffer Buffer of opcodes to append.
2872 @param[in] RawBufferSize The size, in bytes, of Buffer.
2874 @retval NULL There is not enough space left in Buffer to add the opcode.
2875 @retval Other A pointer to the appended opcodes.
2880 HiiCreateRawOpCodes (
2881 IN VOID
*OpCodeHandle
,
2882 IN UINT8
*RawBuffer
,
2883 IN UINTN RawBufferSize
2888 ASSERT (RawBuffer
!= NULL
);
2890 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2891 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2895 Append opcodes from one OpCode Handle to another OpCode handle.
2897 If OpCodeHandle is NULL, then ASSERT().
2898 If RawOpCodeHandle is NULL, then ASSERT();
2900 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2901 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2903 @retval NULL There is not enough space left in Buffer to add the opcode.
2904 @retval Other A pointer to the appended opcodes.
2909 InternalHiiAppendOpCodes (
2910 IN VOID
*OpCodeHandle
,
2911 IN VOID
*RawOpCodeHandle
2914 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2916 ASSERT (RawOpCodeHandle
!= NULL
);
2918 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2919 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2923 Create EFI_IFR_END_OP opcode.
2925 If OpCodeHandle is NULL, then ASSERT().
2927 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2929 @retval NULL There is not enough space left in Buffer to add the opcode.
2930 @retval Other A pointer to the created opcode.
2935 HiiCreateEndOpCode (
2936 IN VOID
*OpCodeHandle
2941 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2945 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2947 If OpCodeHandle is NULL, then ASSERT().
2948 If Type is invalid, then ASSERT().
2949 If Flags is invalid, then ASSERT().
2951 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2952 @param[in] StringId StringId for the option
2953 @param[in] Flags Flags for the option
2954 @param[in] Type Type for the option
2955 @param[in] Value Value for the option
2957 @retval NULL There is not enough space left in Buffer to add the opcode.
2958 @retval Other A pointer to the created opcode.
2963 HiiCreateOneOfOptionOpCode (
2964 IN VOID
*OpCodeHandle
,
2971 EFI_IFR_ONE_OF_OPTION OpCode
;
2973 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2975 ZeroMem (&OpCode
, sizeof (OpCode
));
2976 OpCode
.Option
= StringId
;
2977 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2979 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2981 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, OFFSET_OF(EFI_IFR_ONE_OF_OPTION
, Value
) + mHiiDefaultTypeToWidth
[Type
]);
2985 Create EFI_IFR_DEFAULT_OP opcode.
2987 If OpCodeHandle is NULL, then ASSERT().
2988 If Type is invalid, then ASSERT().
2990 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2991 @param[in] DefaultId DefaultId for the default
2992 @param[in] Type Type for the default
2993 @param[in] Value Value for the default
2995 @retval NULL There is not enough space left in Buffer to add the opcode.
2996 @retval Other A pointer to the created opcode.
3001 HiiCreateDefaultOpCode (
3002 IN VOID
*OpCodeHandle
,
3003 IN UINT16 DefaultId
,
3008 EFI_IFR_DEFAULT OpCode
;
3010 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
3012 ZeroMem (&OpCode
, sizeof (OpCode
));
3014 OpCode
.DefaultId
= DefaultId
;
3015 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
3017 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, OFFSET_OF(EFI_IFR_DEFAULT
, Value
) + mHiiDefaultTypeToWidth
[Type
]);
3021 Create EFI_IFR_GUID opcode.
3023 If OpCodeHandle is NULL, then ASSERT().
3024 If Guid is NULL, then ASSERT().
3025 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
3027 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3028 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
3029 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
3030 optional parameter that may be NULL. If this
3031 parameter is NULL, then the GUID extension
3032 region of the created opcode is filled with zeros.
3033 If this parameter is not NULL, then the GUID
3034 extension region of GuidData will be copied to
3035 the GUID extension region of the created opcode.
3036 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
3037 must be >= sizeof(EFI_IFR_GUID).
3039 @retval NULL There is not enough space left in Buffer to add the opcode.
3040 @retval Other A pointer to the created opcode.
3045 HiiCreateGuidOpCode (
3046 IN VOID
*OpCodeHandle
,
3047 IN CONST EFI_GUID
*Guid
,
3048 IN CONST VOID
*GuidOpCode
, OPTIONAL
3052 EFI_IFR_GUID OpCode
;
3053 EFI_IFR_GUID
*OpCodePointer
;
3055 ASSERT (Guid
!= NULL
);
3056 ASSERT (OpCodeSize
>= sizeof (OpCode
));
3058 ZeroMem (&OpCode
, sizeof (OpCode
));
3059 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
3061 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
3066 OpCodeSize
- sizeof (OpCode
),
3069 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
3070 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
3072 return (UINT8
*)OpCodePointer
;
3076 Create EFI_IFR_ACTION_OP opcode.
3078 If OpCodeHandle is NULL, then ASSERT().
3079 If any reserved bits are set in QuestionFlags, then ASSERT().
3081 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3082 @param[in] QuestionId Question ID
3083 @param[in] Prompt String ID for Prompt
3084 @param[in] Help String ID for Help
3085 @param[in] QuestionFlags Flags in Question Header
3086 @param[in] QuestionConfig String ID for configuration
3088 @retval NULL There is not enough space left in Buffer to add the opcode.
3089 @retval Other A pointer to the created opcode.
3094 HiiCreateActionOpCode (
3095 IN VOID
*OpCodeHandle
,
3096 IN EFI_QUESTION_ID QuestionId
,
3097 IN EFI_STRING_ID Prompt
,
3098 IN EFI_STRING_ID Help
,
3099 IN UINT8 QuestionFlags
,
3100 IN EFI_STRING_ID QuestionConfig
3103 EFI_IFR_ACTION OpCode
;
3105 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3107 ZeroMem (&OpCode
, sizeof (OpCode
));
3108 OpCode
.Question
.QuestionId
= QuestionId
;
3109 OpCode
.Question
.Header
.Prompt
= Prompt
;
3110 OpCode
.Question
.Header
.Help
= Help
;
3111 OpCode
.Question
.Flags
= QuestionFlags
;
3112 OpCode
.QuestionConfig
= QuestionConfig
;
3114 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
3118 Create EFI_IFR_SUBTITLE_OP opcode.
3120 If OpCodeHandle is NULL, then ASSERT().
3121 If any reserved bits are set in Flags, then ASSERT().
3122 If Scope > 1, then ASSERT().
3124 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3125 @param[in] Prompt String ID for Prompt
3126 @param[in] Help String ID for Help
3127 @param[in] Flags Subtitle opcode flags
3128 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
3129 0 if this opcode is within the current scope.
3131 @retval NULL There is not enough space left in Buffer to add the opcode.
3132 @retval Other A pointer to the created opcode.
3137 HiiCreateSubTitleOpCode (
3138 IN VOID
*OpCodeHandle
,
3139 IN EFI_STRING_ID Prompt
,
3140 IN EFI_STRING_ID Help
,
3145 EFI_IFR_SUBTITLE OpCode
;
3147 ASSERT (Scope
<= 1);
3148 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
3150 ZeroMem (&OpCode
, sizeof (OpCode
));
3151 OpCode
.Statement
.Prompt
= Prompt
;
3152 OpCode
.Statement
.Help
= Help
;
3153 OpCode
.Flags
= Flags
;
3155 return InternalHiiCreateOpCodeExtended (
3158 EFI_IFR_SUBTITLE_OP
,
3166 Create EFI_IFR_REF_OP opcode.
3168 If OpCodeHandle is NULL, then ASSERT().
3169 If any reserved bits are set in QuestionFlags, then ASSERT().
3171 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3172 @param[in] FormId Destination Form ID
3173 @param[in] Prompt String ID for Prompt
3174 @param[in] Help String ID for Help
3175 @param[in] QuestionFlags Flags in Question Header
3176 @param[in] QuestionId Question ID
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 HiiCreateGotoOpCode (
3185 IN VOID
*OpCodeHandle
,
3186 IN EFI_FORM_ID FormId
,
3187 IN EFI_STRING_ID Prompt
,
3188 IN EFI_STRING_ID Help
,
3189 IN UINT8 QuestionFlags
,
3190 IN EFI_QUESTION_ID QuestionId
3195 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3197 ZeroMem (&OpCode
, sizeof (OpCode
));
3198 OpCode
.Question
.Header
.Prompt
= Prompt
;
3199 OpCode
.Question
.Header
.Help
= Help
;
3200 OpCode
.Question
.QuestionId
= QuestionId
;
3201 OpCode
.Question
.Flags
= QuestionFlags
;
3202 OpCode
.FormId
= FormId
;
3204 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
3208 Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode.
3210 When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created.
3211 When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created.
3212 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created.
3213 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created.
3215 If OpCodeHandle is NULL, then ASSERT().
3216 If any reserved bits are set in QuestionFlags, then ASSERT().
3218 @param[in] OpCodeHandle The handle to the buffer of opcodes.
3219 @param[in] RefFormId The Destination Form ID.
3220 @param[in] Prompt The string ID for Prompt.
3221 @param[in] Help The string ID for Help.
3222 @param[in] QuestionFlags The flags in Question Header
3223 @param[in] QuestionId Question ID.
3224 @param[in] RefQuestionId The question on the form to which this link is referring.
3225 If its value is zero, then the link refers to the top of the form.
3226 @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is
3227 zero, then the link is to the current form set.
3228 @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of
3229 the device path to which the form set containing the form specified by FormId.
3230 If its value is zero, then the link refers to the current page.
3232 @retval NULL There is not enough space left in Buffer to add the opcode.
3233 @retval Other A pointer to the created opcode.
3238 HiiCreateGotoExOpCode (
3239 IN VOID
*OpCodeHandle
,
3240 IN EFI_FORM_ID RefFormId
,
3241 IN EFI_STRING_ID Prompt
,
3242 IN EFI_STRING_ID Help
,
3243 IN UINT8 QuestionFlags
,
3244 IN EFI_QUESTION_ID QuestionId
,
3245 IN EFI_QUESTION_ID RefQuestionId
,
3246 IN EFI_GUID
*RefFormSetId
, OPTIONAL
3247 IN EFI_STRING_ID RefDevicePath
3250 EFI_IFR_REF4 OpCode
;
3253 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3255 ZeroMem (&OpCode
, sizeof (OpCode
));
3256 OpCode
.Question
.Header
.Prompt
= Prompt
;
3257 OpCode
.Question
.Header
.Help
= Help
;
3258 OpCode
.Question
.QuestionId
= QuestionId
;
3259 OpCode
.Question
.Flags
= QuestionFlags
;
3260 OpCode
.FormId
= RefFormId
;
3261 OpCode
.QuestionId
= RefQuestionId
;
3262 OpCode
.DevicePath
= RefDevicePath
;
3263 if (RefFormSetId
!= NULL
) {
3264 CopyMem (&OpCode
.FormSetId
, RefFormSetId
, sizeof (OpCode
.FormSetId
));
3268 // Cacluate OpCodeSize based on the input Ref value.
3269 // Try to use the small OpCode to save size.
3271 OpCodeSize
= sizeof (EFI_IFR_REF
);
3272 if (RefDevicePath
!= 0) {
3273 OpCodeSize
= sizeof (EFI_IFR_REF4
);
3274 } else if (RefFormSetId
!= NULL
) {
3275 OpCodeSize
= sizeof (EFI_IFR_REF3
);
3276 } else if (RefQuestionId
!= 0) {
3277 OpCodeSize
= sizeof (EFI_IFR_REF2
);
3280 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, OpCodeSize
);
3284 Create EFI_IFR_CHECKBOX_OP opcode.
3286 If OpCodeHandle is NULL, then ASSERT().
3287 If any reserved bits are set in QuestionFlags, then ASSERT().
3288 If any reserved bits are set in CheckBoxFlags, then ASSERT().
3290 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3291 @param[in] QuestionId Question ID
3292 @param[in] VarStoreId Storage ID
3293 @param[in] VarOffset Offset in Storage
3294 @param[in] Prompt String ID for Prompt
3295 @param[in] Help String ID for Help
3296 @param[in] QuestionFlags Flags in Question Header
3297 @param[in] CheckBoxFlags Flags for checkbox opcode
3298 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3299 is an optional parameter that may be NULL.
3301 @retval NULL There is not enough space left in Buffer to add the opcode.
3302 @retval Other A pointer to the created opcode.
3307 HiiCreateCheckBoxOpCode (
3308 IN VOID
*OpCodeHandle
,
3309 IN EFI_QUESTION_ID QuestionId
,
3310 IN EFI_VARSTORE_ID VarStoreId
,
3311 IN UINT16 VarOffset
,
3312 IN EFI_STRING_ID Prompt
,
3313 IN EFI_STRING_ID Help
,
3314 IN UINT8 QuestionFlags
,
3315 IN UINT8 CheckBoxFlags
,
3316 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3319 EFI_IFR_CHECKBOX OpCode
;
3322 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3324 ZeroMem (&OpCode
, sizeof (OpCode
));
3325 OpCode
.Question
.QuestionId
= QuestionId
;
3326 OpCode
.Question
.VarStoreId
= VarStoreId
;
3327 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3328 OpCode
.Question
.Header
.Prompt
= Prompt
;
3329 OpCode
.Question
.Header
.Help
= Help
;
3330 OpCode
.Question
.Flags
= QuestionFlags
;
3331 OpCode
.Flags
= CheckBoxFlags
;
3333 if (DefaultsOpCodeHandle
== NULL
) {
3334 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
3337 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3338 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
3339 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3340 HiiCreateEndOpCode (OpCodeHandle
);
3341 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3345 Create EFI_IFR_NUMERIC_OP opcode.
3347 If OpCodeHandle is NULL, then ASSERT().
3348 If any reserved bits are set in QuestionFlags, then ASSERT().
3349 If any reserved bits are set in NumericFlags, then ASSERT().
3351 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3352 @param[in] QuestionId Question ID
3353 @param[in] VarStoreId Storage ID
3354 @param[in] VarOffset Offset in Storage
3355 @param[in] Prompt String ID for Prompt
3356 @param[in] Help String ID for Help
3357 @param[in] QuestionFlags Flags in Question Header
3358 @param[in] NumericFlags Flags for numeric opcode
3359 @param[in] Minimum Numeric minimum value
3360 @param[in] Maximum Numeric maximum value
3361 @param[in] Step Numeric step for edit
3362 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3363 is an optional parameter that may be NULL.
3365 @retval NULL There is not enough space left in Buffer to add the opcode.
3366 @retval Other A pointer to the created opcode.
3371 HiiCreateNumericOpCode (
3372 IN VOID
*OpCodeHandle
,
3373 IN EFI_QUESTION_ID QuestionId
,
3374 IN EFI_VARSTORE_ID VarStoreId
,
3375 IN UINT16 VarOffset
,
3376 IN EFI_STRING_ID Prompt
,
3377 IN EFI_STRING_ID Help
,
3378 IN UINT8 QuestionFlags
,
3379 IN UINT8 NumericFlags
,
3383 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3386 EFI_IFR_NUMERIC OpCode
;
3390 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3393 ZeroMem (&OpCode
, sizeof (OpCode
));
3394 OpCode
.Question
.QuestionId
= QuestionId
;
3395 OpCode
.Question
.VarStoreId
= VarStoreId
;
3396 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3397 OpCode
.Question
.Header
.Prompt
= Prompt
;
3398 OpCode
.Question
.Header
.Help
= Help
;
3399 OpCode
.Question
.Flags
= QuestionFlags
;
3400 OpCode
.Flags
= NumericFlags
;
3402 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
3403 case EFI_IFR_NUMERIC_SIZE_1
:
3404 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
3405 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3406 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3410 case EFI_IFR_NUMERIC_SIZE_2
:
3411 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3412 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3413 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3417 case EFI_IFR_NUMERIC_SIZE_4
:
3418 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3419 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3420 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3424 case EFI_IFR_NUMERIC_SIZE_8
:
3425 OpCode
.data
.u64
.MinValue
= Minimum
;
3426 OpCode
.data
.u64
.MaxValue
= Maximum
;
3427 OpCode
.data
.u64
.Step
= Step
;
3432 Length
+= OFFSET_OF (EFI_IFR_NUMERIC
, data
);
3434 if (DefaultsOpCodeHandle
== NULL
) {
3435 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, Length
);
3438 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3439 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, Length
, 0, 1);
3440 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3441 HiiCreateEndOpCode (OpCodeHandle
);
3442 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3446 Create EFI_IFR_STRING_OP opcode.
3448 If OpCodeHandle is NULL, then ASSERT().
3449 If any reserved bits are set in QuestionFlags, then ASSERT().
3450 If any reserved bits are set in StringFlags, then ASSERT().
3452 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3453 @param[in] QuestionId Question ID
3454 @param[in] VarStoreId Storage ID
3455 @param[in] VarOffset Offset in Storage
3456 @param[in] Prompt String ID for Prompt
3457 @param[in] Help String ID for Help
3458 @param[in] QuestionFlags Flags in Question Header
3459 @param[in] StringFlags Flags for string opcode
3460 @param[in] MinSize String minimum length
3461 @param[in] MaxSize String maximum length
3462 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3463 is an optional parameter that may be NULL.
3465 @retval NULL There is not enough space left in Buffer to add the opcode.
3466 @retval Other A pointer to the created opcode.
3471 HiiCreateStringOpCode (
3472 IN VOID
*OpCodeHandle
,
3473 IN EFI_QUESTION_ID QuestionId
,
3474 IN EFI_VARSTORE_ID VarStoreId
,
3475 IN UINT16 VarOffset
,
3476 IN EFI_STRING_ID Prompt
,
3477 IN EFI_STRING_ID Help
,
3478 IN UINT8 QuestionFlags
,
3479 IN UINT8 StringFlags
,
3482 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3485 EFI_IFR_STRING OpCode
;
3488 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3490 ZeroMem (&OpCode
, sizeof (OpCode
));
3491 OpCode
.Question
.Header
.Prompt
= Prompt
;
3492 OpCode
.Question
.Header
.Help
= Help
;
3493 OpCode
.Question
.QuestionId
= QuestionId
;
3494 OpCode
.Question
.VarStoreId
= VarStoreId
;
3495 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3496 OpCode
.Question
.Flags
= QuestionFlags
;
3497 OpCode
.MinSize
= MinSize
;
3498 OpCode
.MaxSize
= MaxSize
;
3499 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3501 if (DefaultsOpCodeHandle
== NULL
) {
3502 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3505 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3506 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3507 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3508 HiiCreateEndOpCode (OpCodeHandle
);
3509 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3513 Create EFI_IFR_ONE_OF_OP opcode.
3515 If OpCodeHandle is NULL, then ASSERT().
3516 If any reserved bits are set in QuestionFlags, then ASSERT().
3517 If any reserved bits are set in OneOfFlags, then ASSERT().
3519 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3520 @param[in] QuestionId Question ID
3521 @param[in] VarStoreId Storage ID
3522 @param[in] VarOffset Offset in Storage
3523 @param[in] Prompt String ID for Prompt
3524 @param[in] Help String ID for Help
3525 @param[in] QuestionFlags Flags in Question Header
3526 @param[in] OneOfFlags Flags for oneof opcode
3527 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3528 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3529 is an optional parameter that may be NULL.
3531 @retval NULL There is not enough space left in Buffer to add the opcode.
3532 @retval Other A pointer to the created opcode.
3537 HiiCreateOneOfOpCode (
3538 IN VOID
*OpCodeHandle
,
3539 IN EFI_QUESTION_ID QuestionId
,
3540 IN EFI_VARSTORE_ID VarStoreId
,
3541 IN UINT16 VarOffset
,
3542 IN EFI_STRING_ID Prompt
,
3543 IN EFI_STRING_ID Help
,
3544 IN UINT8 QuestionFlags
,
3545 IN UINT8 OneOfFlags
,
3546 IN VOID
*OptionsOpCodeHandle
,
3547 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3550 EFI_IFR_ONE_OF OpCode
;
3554 ASSERT (OptionsOpCodeHandle
!= NULL
);
3555 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3557 ZeroMem (&OpCode
, sizeof (OpCode
));
3558 OpCode
.Question
.Header
.Prompt
= Prompt
;
3559 OpCode
.Question
.Header
.Help
= Help
;
3560 OpCode
.Question
.QuestionId
= QuestionId
;
3561 OpCode
.Question
.VarStoreId
= VarStoreId
;
3562 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3563 OpCode
.Question
.Flags
= QuestionFlags
;
3564 OpCode
.Flags
= OneOfFlags
;
3566 Length
= OFFSET_OF (EFI_IFR_ONE_OF
, data
);
3567 Length
+= (1 << (OneOfFlags
& EFI_IFR_NUMERIC_SIZE
)) * 3;
3569 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3570 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, Length
, 0, 1);
3571 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3572 if (DefaultsOpCodeHandle
!= NULL
) {
3573 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3575 HiiCreateEndOpCode (OpCodeHandle
);
3576 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3580 Create EFI_IFR_ORDERED_LIST_OP opcode.
3582 If OpCodeHandle is NULL, then ASSERT().
3583 If any reserved bits are set in QuestionFlags, then ASSERT().
3584 If any reserved bits are set in OrderedListFlags, then ASSERT().
3586 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3587 @param[in] QuestionId Question ID
3588 @param[in] VarStoreId Storage ID
3589 @param[in] VarOffset Offset in Storage
3590 @param[in] Prompt String ID for Prompt
3591 @param[in] Help String ID for Help
3592 @param[in] QuestionFlags Flags in Question Header
3593 @param[in] OrderedListFlags Flags for ordered list opcode
3594 @param[in] DataType Type for option value
3595 @param[in] MaxContainers Maximum count for options in this ordered list
3596 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3597 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3598 is an optional parameter that may be NULL.
3600 @retval NULL There is not enough space left in Buffer to add the opcode.
3601 @retval Other A pointer to the created opcode.
3606 HiiCreateOrderedListOpCode (
3607 IN VOID
*OpCodeHandle
,
3608 IN EFI_QUESTION_ID QuestionId
,
3609 IN EFI_VARSTORE_ID VarStoreId
,
3610 IN UINT16 VarOffset
,
3611 IN EFI_STRING_ID Prompt
,
3612 IN EFI_STRING_ID Help
,
3613 IN UINT8 QuestionFlags
,
3614 IN UINT8 OrderedListFlags
,
3616 IN UINT8 MaxContainers
,
3617 IN VOID
*OptionsOpCodeHandle
,
3618 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3621 EFI_IFR_ORDERED_LIST OpCode
;
3624 ASSERT (OptionsOpCodeHandle
!= NULL
);
3625 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3627 ZeroMem (&OpCode
, sizeof (OpCode
));
3628 OpCode
.Question
.Header
.Prompt
= Prompt
;
3629 OpCode
.Question
.Header
.Help
= Help
;
3630 OpCode
.Question
.QuestionId
= QuestionId
;
3631 OpCode
.Question
.VarStoreId
= VarStoreId
;
3632 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3633 OpCode
.Question
.Flags
= QuestionFlags
;
3634 OpCode
.MaxContainers
= MaxContainers
;
3635 OpCode
.Flags
= OrderedListFlags
;
3637 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3638 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3639 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3640 if (DefaultsOpCodeHandle
!= NULL
) {
3641 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3643 HiiCreateEndOpCode (OpCodeHandle
);
3644 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3648 Create EFI_IFR_TEXT_OP opcode.
3650 If OpCodeHandle is NULL, then ASSERT().
3652 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3653 @param[in] Prompt String ID for Prompt.
3654 @param[in] Help String ID for Help.
3655 @param[in] TextTwo String ID for TextTwo.
3657 @retval NULL There is not enough space left in Buffer to add the opcode.
3658 @retval Other A pointer to the created opcode.
3663 HiiCreateTextOpCode (
3664 IN VOID
*OpCodeHandle
,
3665 IN EFI_STRING_ID Prompt
,
3666 IN EFI_STRING_ID Help
,
3667 IN EFI_STRING_ID TextTwo
3670 EFI_IFR_TEXT OpCode
;
3672 ZeroMem (&OpCode
, sizeof (OpCode
));
3673 OpCode
.Statement
.Prompt
= Prompt
;
3674 OpCode
.Statement
.Help
= Help
;
3675 OpCode
.TextTwo
= TextTwo
;
3677 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TEXT_OP
, sizeof (OpCode
));
3681 Create EFI_IFR_DATE_OP opcode.
3683 If OpCodeHandle is NULL, then ASSERT().
3684 If any reserved bits are set in QuestionFlags, then ASSERT().
3685 If any reserved bits are set in DateFlags, then ASSERT().
3687 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3688 @param[in] QuestionId Question ID
3689 @param[in] VarStoreId Storage ID, optional. If DateFlags is not
3690 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3691 @param[in] VarOffset Offset in Storage, optional. If DateFlags is not
3692 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3693 @param[in] Prompt String ID for Prompt
3694 @param[in] Help String ID for Help
3695 @param[in] QuestionFlags Flags in Question Header
3696 @param[in] DateFlags Flags for date opcode
3697 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3698 is an optional parameter that may be NULL.
3700 @retval NULL There is not enough space left in Buffer to add the opcode.
3701 @retval Other A pointer to the created opcode.
3706 HiiCreateDateOpCode (
3707 IN VOID
*OpCodeHandle
,
3708 IN EFI_QUESTION_ID QuestionId
,
3709 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3710 IN UINT16 VarOffset
, OPTIONAL
3711 IN EFI_STRING_ID Prompt
,
3712 IN EFI_STRING_ID Help
,
3713 IN UINT8 QuestionFlags
,
3715 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3718 EFI_IFR_DATE OpCode
;
3721 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3722 ASSERT ((DateFlags
& (~(EFI_QF_DATE_YEAR_SUPPRESS
| EFI_QF_DATE_MONTH_SUPPRESS
| EFI_QF_DATE_DAY_SUPPRESS
| EFI_QF_DATE_STORAGE
))) == 0);
3724 ZeroMem (&OpCode
, sizeof (OpCode
));
3725 OpCode
.Question
.Header
.Prompt
= Prompt
;
3726 OpCode
.Question
.Header
.Help
= Help
;
3727 OpCode
.Question
.QuestionId
= QuestionId
;
3728 OpCode
.Question
.VarStoreId
= VarStoreId
;
3729 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3730 OpCode
.Question
.Flags
= QuestionFlags
;
3731 OpCode
.Flags
= DateFlags
;
3733 if (DefaultsOpCodeHandle
== NULL
) {
3734 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
));
3737 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3738 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
), 0, 1);
3739 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3740 HiiCreateEndOpCode (OpCodeHandle
);
3741 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3745 Create EFI_IFR_TIME_OP opcode.
3747 If OpCodeHandle is NULL, then ASSERT().
3748 If any reserved bits are set in QuestionFlags, then ASSERT().
3749 If any reserved bits are set in TimeFlags, then ASSERT().
3751 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3752 @param[in] QuestionId Question ID
3753 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not
3754 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3755 @param[in] VarOffset Offset in Storage, optional. If TimeFlags is not
3756 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3757 @param[in] Prompt String ID for Prompt
3758 @param[in] Help String ID for Help
3759 @param[in] QuestionFlags Flags in Question Header
3760 @param[in] TimeFlags Flags for time opcode
3761 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3762 is an optional parameter that may be NULL.
3764 @retval NULL There is not enough space left in Buffer to add the opcode.
3765 @retval Other A pointer to the created opcode.
3770 HiiCreateTimeOpCode (
3771 IN VOID
*OpCodeHandle
,
3772 IN EFI_QUESTION_ID QuestionId
,
3773 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3774 IN UINT16 VarOffset
, OPTIONAL
3775 IN EFI_STRING_ID Prompt
,
3776 IN EFI_STRING_ID Help
,
3777 IN UINT8 QuestionFlags
,
3779 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3782 EFI_IFR_TIME OpCode
;
3785 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3786 ASSERT ((TimeFlags
& (~(QF_TIME_HOUR_SUPPRESS
| QF_TIME_MINUTE_SUPPRESS
| QF_TIME_SECOND_SUPPRESS
| QF_TIME_STORAGE
))) == 0);
3788 ZeroMem (&OpCode
, sizeof (OpCode
));
3789 OpCode
.Question
.Header
.Prompt
= Prompt
;
3790 OpCode
.Question
.Header
.Help
= Help
;
3791 OpCode
.Question
.QuestionId
= QuestionId
;
3792 OpCode
.Question
.VarStoreId
= VarStoreId
;
3793 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3794 OpCode
.Question
.Flags
= QuestionFlags
;
3795 OpCode
.Flags
= TimeFlags
;
3797 if (DefaultsOpCodeHandle
== NULL
) {
3798 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
));
3801 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3802 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
), 0, 1);
3803 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3804 HiiCreateEndOpCode (OpCodeHandle
);
3805 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3809 This is the internal worker function to update the data in
3810 a form specified by FormSetGuid, FormId and Label.
3812 @param[in] FormSetGuid The optional Formset GUID.
3813 @param[in] FormId The Form ID.
3814 @param[in] Package The package header.
3815 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR
3816 opcodes to be inserted or replaced in the form.
3817 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode
3818 that marks the end of a replace operation in the form.
3819 @param[out] TempPackage The resultant package.
3821 @retval EFI_SUCCESS The function completes successfully.
3822 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.
3827 InternalHiiUpdateFormPackageData (
3828 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3829 IN EFI_FORM_ID FormId
,
3830 IN EFI_HII_PACKAGE_HEADER
*Package
,
3831 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3832 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3833 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3838 EFI_HII_PACKAGE_HEADER PackageHeader
;
3840 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3841 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3845 UINTN UpdatePackageLength
;
3847 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3848 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3849 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3851 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3852 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3853 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3854 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3858 while (Offset
< PackageHeader
.Length
) {
3859 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3860 BufferPos
+= IfrOpHdr
->Length
;
3861 UpdatePackageLength
+= IfrOpHdr
->Length
;
3864 // Find the matched FormSet and Form
3866 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3867 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3872 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
|| IfrOpHdr
->OpCode
== EFI_IFR_FORM_MAP_OP
) {
3873 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3881 // The matched Form is found, and Update data in this form
3883 if (GetFormSet
&& GetForm
) {
3884 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3885 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3886 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3888 // Remove the original data when End OpCode buffer exist.
3890 if (OpCodeBufferEnd
!= NULL
) {
3891 Offset
+= IfrOpHdr
->Length
;
3892 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3893 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3894 while (Offset
< PackageHeader
.Length
) {
3896 // Search the matched end opcode
3898 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3899 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3903 // Go to the next Op-Code
3905 Offset
+= IfrOpHdr
->Length
;
3906 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3909 if (Offset
>= PackageHeader
.Length
) {
3911 // The end opcode is not found.
3913 return EFI_NOT_FOUND
;
3918 // Insert the updated data
3920 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3921 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3922 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3923 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3925 if (OpCodeBufferEnd
!= NULL
) {
3927 // Add the end opcode
3929 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3930 BufferPos
+= IfrOpHdr
->Length
;
3931 UpdatePackageLength
+= IfrOpHdr
->Length
;
3935 // Copy the left package data.
3937 Offset
+= IfrOpHdr
->Length
;
3938 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3939 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3950 // Go to the next Op-Code
3952 Offset
+= IfrOpHdr
->Length
;
3953 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3958 // The updated opcode buffer is not found.
3960 return EFI_NOT_FOUND
;
3963 // Update the package length.
3965 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3966 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3972 This function updates a form that has previously been registered with the HII
3973 Database. This function will perform at most one update operation.
3975 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3976 comparisons of IFR opcodes are performed from the beginning of the form being
3977 updated until an IFR opcode is found that exactly matches the first IFR opcode
3978 specified by StartOpCodeHandle. The following rules are used to determine if
3979 an insert, replace, or delete operation is performed.
3981 1) If no matches are found, then NULL is returned.
3982 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3983 from StartOpCodeHandle except the first opcode are inserted immediately after
3984 the matching IFR opcode in the form to be updated.
3985 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3986 from the matching IFR opcode until an IFR opcode exactly matches the first
3987 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3988 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3989 is found, then all of the IFR opcodes between the start match and the end
3990 match are deleted from the form being updated and all of the IFR opcodes
3991 from StartOpCodeHandle except the first opcode are inserted immediately after
3992 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3993 IFR instruction, then the result of this operation will delete all of the IFR
3994 opcodes between the start end matches.
3996 If HiiHandle is NULL, then ASSERT().
3997 If StartOpCodeHandle is NULL, then ASSERT().
3999 @param[in] HiiHandle The HII Handle of the form to update.
4000 @param[in] FormSetGuid The Formset GUID of the form to update. This
4001 is an optional parameter that may be NULL.
4002 If it is NULL, all FormSet will be updated.
4003 @param[in] FormId The ID of the form to update.
4004 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
4005 opcodes to be inserted or replaced in the form.
4006 The first IFR instruction in StartOpCodeHandle
4007 is used to find matching IFR opcode in the
4009 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
4010 that marks the end of a replace operation in
4011 the form. This is an optional parameter that
4012 may be NULL. If it is NULL, then an the IFR
4013 opcodes specified by StartOpCodeHandle are
4014 inserted into the form.
4016 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
4017 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
4018 1) The form specified by HiiHandle, FormSetGuid,
4019 and FormId could not be found in the HII Database.
4020 2) No IFR opcodes in the target form match the first
4021 IFR opcode in StartOpCodeHandle.
4022 3) EndOpCOde is not NULL, and no IFR opcodes in the
4023 target form following a matching start opcode match
4024 the first IFR opcode in EndOpCodeHandle.
4025 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
4031 IN EFI_HII_HANDLE HiiHandle
,
4032 IN EFI_GUID
*FormSetGuid
, OPTIONAL
4033 IN EFI_FORM_ID FormId
,
4034 IN VOID
*StartOpCodeHandle
,
4035 IN VOID
*EndOpCodeHandle OPTIONAL
4039 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
4040 UINT32 PackageListLength
;
4042 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
4044 UINT8
*UpdateBufferPos
;
4045 EFI_HII_PACKAGE_HEADER
*Package
;
4046 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
4047 EFI_HII_PACKAGE_HEADER PackageHeader
;
4049 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
4050 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
4053 // Input update data can't be NULL.
4055 ASSERT (HiiHandle
!= NULL
);
4056 ASSERT (StartOpCodeHandle
!= NULL
);
4057 UpdatePackageList
= NULL
;
4059 HiiPackageList
= NULL
;
4062 // Retrieve buffer data from Opcode Handle
4064 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpCodeHandle
;
4065 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpCodeHandle
;
4068 // Get the original package list
4071 HiiPackageList
= NULL
;
4072 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
4074 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
4076 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4080 HiiPackageList
= AllocatePool (BufferSize
);
4081 if (HiiPackageList
== NULL
) {
4082 Status
= EFI_OUT_OF_RESOURCES
;
4086 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
4087 if (EFI_ERROR (Status
)) {
4092 // Calculate and allocate space for retrieval of IFR data
4094 BufferSize
+= OpCodeBufferStart
->Position
;
4095 UpdatePackageList
= AllocateZeroPool (BufferSize
);
4096 if (UpdatePackageList
== NULL
) {
4097 Status
= EFI_OUT_OF_RESOURCES
;
4102 // Allocate temp buffer to store the temp updated package buffer
4104 TempPacakge
= AllocateZeroPool (BufferSize
);
4105 if (TempPacakge
== NULL
) {
4106 Status
= EFI_OUT_OF_RESOURCES
;
4110 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
4113 // Copy the package list header
4115 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
4116 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4119 // Go through each package to find the matched package and update one by one
4122 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4123 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
4124 while (Offset
< PackageListLength
) {
4125 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
4126 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4127 Offset
+= Package
->Length
;
4129 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
4131 // Check this package is the matched package.
4133 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
4135 // The matched package is found. Its package buffer will be updated by the input new data.
4137 if (!EFI_ERROR(Status
)) {
4143 // Add updated package buffer
4145 Package
= TempPacakge
;
4150 // Add pacakge buffer
4152 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4153 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
4154 UpdateBufferPos
+= PackageHeader
.Length
;
4159 // Update package list length
4161 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
4162 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
4165 // Update Package to show form
4167 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
4170 // Not matched form is found and updated.
4172 Status
= EFI_NOT_FOUND
;
4176 if (HiiPackageList
!= NULL
) {
4177 FreePool (HiiPackageList
);
4180 if (UpdatePackageList
!= NULL
) {
4181 FreePool (UpdatePackageList
);
4184 if (TempPacakge
!= NULL
) {
4185 FreePool (TempPacakge
);