2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2015, 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
;
612 // Compute the length of Name in Unicode characters.
613 // If Name is NULL, then the length is 0.
617 NameLength
= StrLen (Name
);
623 // Retrieve DevicePath Protocol associated with DriverHandle
625 if (DriverHandle
!= NULL
) {
626 DevicePath
= DevicePathFromHandle (DriverHandle
);
627 if (DevicePath
== NULL
) {
631 // Compute the size of the device path in bytes
633 DevicePathSize
= GetDevicePathSize (DevicePath
);
637 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
638 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
640 MaxLen
= 5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1;
641 String
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
642 if (String
== NULL
) {
647 // Start with L"GUID="
649 StrCpyS (String
, MaxLen
, L
"GUID=");
650 ReturnString
= String
;
651 String
+= StrLen (String
);
655 // Append Guid converted to <HexCh>32
657 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
658 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
665 StrCpyS (String
, MaxLen
, L
"&NAME=");
666 String
+= StrLen (String
);
670 // Append Name converted to <Char>NameLength
672 for (; *Name
!= L
'\0'; Name
++) {
673 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
680 StrCpyS (String
, MaxLen
, L
"&PATH=");
681 String
+= StrLen (String
);
684 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
686 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
687 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
691 // Null terminate the Unicode string
696 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
698 return InternalHiiLowerConfigString (ReturnString
);
702 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
703 to binary buffer from <ConfigHdr>.
705 This is a internal function.
707 @param String UEFI configuration string.
708 @param Flag Flag specifies what type buffer will be retrieved.
709 @param Buffer Binary of Guid, Name or Device path.
711 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
712 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
713 @retval EFI_SUCCESS The buffer data is retrieved and translated to
718 InternalHiiGetBufferFromString (
719 IN EFI_STRING String
,
725 EFI_STRING ConfigHdr
;
732 if (String
== NULL
|| Buffer
== NULL
) {
733 return EFI_INVALID_PARAMETER
;
740 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
741 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
743 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
746 case GUID_CONFIG_STRING_TYPE
:
747 case PATH_CONFIG_STRING_TYPE
:
749 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
750 // as the device path and Guid resides in RAM memory.
751 // Translate the data into binary.
753 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
754 if (DataBuffer
== NULL
) {
755 return EFI_OUT_OF_RESOURCES
;
758 // Convert binary byte one by one
760 ZeroMem (TemStr
, sizeof (TemStr
));
761 for (Index
= 0; Index
< Length
; Index
++) {
762 TemStr
[0] = ConfigHdr
[Index
];
763 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
764 if ((Index
& 1) == 0) {
765 DataBuffer
[Index
/2] = DigitUint8
;
767 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
771 *Buffer
= DataBuffer
;
774 case NAME_CONFIG_STRING_TYPE
:
776 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
780 // Add the tailling char L'\0'
782 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
783 if (DataBuffer
== NULL
) {
784 return EFI_OUT_OF_RESOURCES
;
787 // Convert character one by one
789 StringPtr
= (CHAR16
*) DataBuffer
;
790 ZeroMem (TemStr
, sizeof (TemStr
));
791 for (Index
= 0; Index
< Length
; Index
+= 4) {
792 StrnCpyS (TemStr
, sizeof (TemStr
) / sizeof (CHAR16
), ConfigHdr
+ Index
, 4);
793 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
796 // Add tailing L'\0' character
798 StringPtr
[Index
/4] = L
'\0';
800 *Buffer
= DataBuffer
;
804 return EFI_INVALID_PARAMETER
;
811 This function checks VarOffset and VarWidth is in the block range.
813 @param BlockArray The block array is to be checked.
814 @param VarOffset Offset of var to the structure
815 @param VarWidth Width of var.
817 @retval TRUE This Var is in the block range.
818 @retval FALSE This Var is not in the block range.
822 IN IFR_BLOCK_DATA
*BlockArray
,
828 IFR_BLOCK_DATA
*BlockData
;
831 // No Request Block array, all vars are got.
833 if (BlockArray
== NULL
) {
838 // Check the input var is in the request block range.
840 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
841 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
842 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
851 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
853 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
855 @param ValueString String in <BlockConfig> format and points to the
856 first character of <Number>.
857 @param ValueData The output value. Caller takes the responsibility
859 @param ValueLength Length of the <Number>, in characters.
861 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
863 @retval EFI_SUCCESS Value of <Number> is outputted in Number
869 InternalHiiGetValueOfNumber (
870 IN EFI_STRING ValueString
,
871 OUT UINT8
**ValueData
,
872 OUT UINTN
*ValueLength
875 EFI_STRING StringPtr
;
882 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
883 ASSERT (*ValueString
!= L
'\0');
886 // Get the length of value string
888 StringPtr
= ValueString
;
889 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
892 Length
= StringPtr
- ValueString
;
895 // Allocate buffer to store the value
897 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
899 return EFI_OUT_OF_RESOURCES
;
903 // Convert character one by one to the value buffer
905 ZeroMem (TemStr
, sizeof (TemStr
));
906 for (Index
= 0; Index
< Length
; Index
++) {
907 TemStr
[0] = ValueString
[Length
- Index
- 1];
908 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
909 if ((Index
& 1) == 0) {
910 Buf
[Index
/2] = DigitUint8
;
912 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
917 // Set the converted value and string length.
920 *ValueLength
= Length
;
925 Get value from config request resp string.
927 @param ConfigElement ConfigResp string contains the current setting.
928 @param VarName The variable name which need to get value.
929 @param VarValue The return value.
931 @retval EFI_SUCCESS Get the value for the VarName
932 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
935 GetValueFromRequest (
936 IN CHAR16
*ConfigElement
,
947 // Find VarName related string.
949 StringPtr
= StrStr (ConfigElement
, VarName
);
950 ASSERT (StringPtr
!= NULL
);
953 // Skip the "VarName=" string
955 StringPtr
+= StrLen (VarName
) + 1;
960 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
961 if (EFI_ERROR (Status
)) {
966 CopyMem (VarValue
, TmpBuffer
, (((Length
+ 1) / 2) < sizeof (UINT64
)) ? ((Length
+ 1) / 2) : sizeof (UINT64
));
968 FreePool (TmpBuffer
);
974 This internal function parses IFR data to validate current setting.
976 Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid;
977 else the VarBuffer and CurrentBlockArray is valid.
979 @param HiiPackageList Point to Hii package list.
980 @param PackageListLength The length of the pacakge.
981 @param VarGuid Guid of the buffer storage.
982 @param VarName Name of the buffer storage.
983 @param VarBuffer The data buffer for the storage.
984 @param CurrentBlockArray The block array from the config Requst string.
985 @param RequestElement The config string for this storage.
986 @param HiiHandle The HiiHandle for this formset.
987 @param NameValueType Whether current storage is name/value varstore or not.
989 @retval EFI_SUCCESS The current setting is valid.
990 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
991 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
994 ValidateQuestionFromVfr (
995 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
996 IN UINTN PackageListLength
,
997 IN EFI_GUID
*VarGuid
,
1000 IN IFR_BLOCK_DATA
*CurrentBlockArray
,
1001 IN CHAR16
*RequestElement
,
1002 IN EFI_HII_HANDLE HiiHandle
,
1003 IN BOOLEAN NameValueType
1006 IFR_BLOCK_DATA VarBlockData
;
1010 EFI_IFR_TYPE_VALUE TmpValue
;
1012 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1013 UINT32 PackageOffset
;
1016 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1017 EFI_IFR_VARSTORE
*IfrVarStore
;
1018 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueStore
;
1019 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1020 IFR_VARSTORAGE_DATA VarStoreData
;
1021 EFI_IFR_ONE_OF
*IfrOneOf
;
1022 EFI_IFR_NUMERIC
*IfrNumeric
;
1023 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
1024 EFI_IFR_CHECKBOX
*IfrCheckBox
;
1025 EFI_IFR_STRING
*IfrString
;
1026 CHAR8
*VarStoreName
;
1028 CHAR16
*QuestionName
;
1032 // Initialize the local variables.
1035 VarStoreName
= NULL
;
1036 Status
= EFI_SUCCESS
;
1039 IfrNameValueStore
= NULL
;
1040 IfrEfiVarStore
= NULL
;
1041 ZeroMem (&VarStoreData
, sizeof (IFR_VARSTORAGE_DATA
));
1042 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1045 // Check IFR value is in block data, then Validate Value
1047 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1048 while (PackageOffset
< PackageListLength
) {
1049 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1052 // Parse IFR opcode from the form package.
1054 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1055 IfrOffset
= sizeof (PacakgeHeader
);
1056 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1057 while (IfrOffset
< PacakgeHeader
.Length
) {
1058 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1060 // Validate current setting to the value built in IFR opcode
1062 switch (IfrOpHdr
->OpCode
) {
1063 case EFI_IFR_VARSTORE_OP
:
1065 // VarStoreId has been found. No further found.
1067 if (VarStoreData
.VarStoreId
!= 0) {
1071 // Find the matched VarStoreId to the input VarGuid and VarName
1073 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1074 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1075 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1076 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1077 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1082 // The matched VarStore is found.
1084 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1091 if (IfrVarStore
!= NULL
) {
1092 VarStoreData
.VarStoreId
= IfrVarStore
->VarStoreId
;
1093 VarStoreData
.Size
= IfrVarStore
->Size
;
1096 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1098 // VarStoreId has been found. No further found.
1100 if (VarStoreData
.VarStoreId
!= 0) {
1104 // Find the matched VarStoreId to the input VarGuid
1106 IfrNameValueStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1107 if (!CompareGuid ((EFI_GUID
*) (VOID
*) &IfrNameValueStore
->Guid
, VarGuid
)) {
1108 IfrNameValueStore
= NULL
;
1111 if (IfrNameValueStore
!= NULL
) {
1112 VarStoreData
.VarStoreId
= IfrNameValueStore
->VarStoreId
;
1115 case EFI_IFR_VARSTORE_EFI_OP
:
1117 // VarStore is found. Don't need to search any more.
1119 if (VarStoreData
.VarStoreId
!= 0) {
1123 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1126 // If the length is small than the structure, this is from old efi
1127 // varstore definition. Old efi varstore get config directly from
1128 // GetVariable function.
1130 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1134 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrEfiVarStore
->Guid
, VarGuid
)) {
1135 VarStoreName
= (CHAR8
*) IfrEfiVarStore
->Name
;
1136 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1137 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1142 // The matched VarStore is found.
1144 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1145 IfrEfiVarStore
= NULL
;
1148 IfrEfiVarStore
= NULL
;
1151 if (IfrEfiVarStore
!= NULL
) {
1153 // Find the matched VarStore
1155 VarStoreData
.VarStoreId
= IfrEfiVarStore
->VarStoreId
;
1156 VarStoreData
.Size
= IfrEfiVarStore
->Size
;
1159 case EFI_IFR_FORM_OP
:
1160 case EFI_IFR_FORM_MAP_OP
:
1162 // Check the matched VarStoreId is found.
1164 if (VarStoreData
.VarStoreId
== 0) {
1168 case EFI_IFR_ONE_OF_OP
:
1170 // Check whether current value is the one of option.
1174 // OneOf question is not in IFR Form. This IFR form is not valid.
1176 if (VarStoreData
.VarStoreId
== 0) {
1177 return EFI_INVALID_PARAMETER
;
1180 // Check whether this question is for the requested varstore.
1182 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1183 if (IfrOneOf
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1187 if (NameValueType
) {
1188 QuestionName
= HiiGetString (HiiHandle
, IfrOneOf
->Question
.VarStoreInfo
.VarName
, NULL
);
1189 ASSERT (QuestionName
!= NULL
);
1191 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1193 // This question is not in the current configuration string. Skip it.
1198 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1199 if (EFI_ERROR (Status
)) {
1204 // Get Offset by Question header and Width by DataType Flags
1206 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1207 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1209 // Check whether this question is in current block array.
1211 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1213 // This question is not in the current configuration string. Skip it.
1218 // Check this var question is in the var storage
1220 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1222 // This question exceeds the var store size.
1224 return EFI_INVALID_PARAMETER
;
1228 // Get the current value for oneof opcode
1231 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1234 // Set Block Data, to be checked in the following Oneof option opcode.
1236 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1237 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1239 case EFI_IFR_NUMERIC_OP
:
1241 // Check the current value is in the numeric range.
1245 // Numeric question is not in IFR Form. This IFR form is not valid.
1247 if (VarStoreData
.VarStoreId
== 0) {
1248 return EFI_INVALID_PARAMETER
;
1251 // Check whether this question is for the requested varstore.
1253 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1254 if (IfrNumeric
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1258 if (NameValueType
) {
1259 QuestionName
= HiiGetString (HiiHandle
, IfrNumeric
->Question
.VarStoreInfo
.VarName
, NULL
);
1260 ASSERT (QuestionName
!= NULL
);
1262 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1264 // This question is not in the current configuration string. Skip it.
1269 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1270 if (EFI_ERROR (Status
)) {
1275 // Get Offset by Question header and Width by DataType Flags
1277 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1278 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1280 // Check whether this question is in current block array.
1282 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1284 // This question is not in the current configuration string. Skip it.
1289 // Check this var question is in the var storage
1291 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1293 // This question exceeds the var store size.
1295 return EFI_INVALID_PARAMETER
;
1299 // Check the current value is in the numeric range.
1302 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1304 if ((IfrNumeric
->Flags
& EFI_IFR_DISPLAY
) == 0) {
1305 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1306 case EFI_IFR_NUMERIC_SIZE_1
:
1307 if ((INT8
) VarValue
< (INT8
) IfrNumeric
->data
.u8
.MinValue
|| (INT8
) VarValue
> (INT8
) IfrNumeric
->data
.u8
.MaxValue
) {
1309 // Not in the valid range.
1311 return EFI_INVALID_PARAMETER
;
1314 case EFI_IFR_NUMERIC_SIZE_2
:
1315 if ((INT16
) VarValue
< (INT16
) IfrNumeric
->data
.u16
.MinValue
|| (INT16
) VarValue
> (INT16
) IfrNumeric
->data
.u16
.MaxValue
) {
1317 // Not in the valid range.
1319 return EFI_INVALID_PARAMETER
;
1322 case EFI_IFR_NUMERIC_SIZE_4
:
1323 if ((INT32
) VarValue
< (INT32
) IfrNumeric
->data
.u32
.MinValue
|| (INT32
) VarValue
> (INT32
) IfrNumeric
->data
.u32
.MaxValue
) {
1325 // Not in the valid range.
1327 return EFI_INVALID_PARAMETER
;
1330 case EFI_IFR_NUMERIC_SIZE_8
:
1331 if ((INT64
) VarValue
< (INT64
) IfrNumeric
->data
.u64
.MinValue
|| (INT64
) VarValue
> (INT64
) IfrNumeric
->data
.u64
.MaxValue
) {
1333 // Not in the valid range.
1335 return EFI_INVALID_PARAMETER
;
1340 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1341 case EFI_IFR_NUMERIC_SIZE_1
:
1342 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1344 // Not in the valid range.
1346 return EFI_INVALID_PARAMETER
;
1349 case EFI_IFR_NUMERIC_SIZE_2
:
1350 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1352 // Not in the valid range.
1354 return EFI_INVALID_PARAMETER
;
1357 case EFI_IFR_NUMERIC_SIZE_4
:
1358 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1360 // Not in the valid range.
1362 return EFI_INVALID_PARAMETER
;
1365 case EFI_IFR_NUMERIC_SIZE_8
:
1366 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1368 // Not in the valid range.
1370 return EFI_INVALID_PARAMETER
;
1376 case EFI_IFR_CHECKBOX_OP
:
1378 // Check value is BOOLEAN type, only 0 and 1 is valid.
1382 // CheckBox question is not in IFR Form. This IFR form is not valid.
1384 if (VarStoreData
.VarStoreId
== 0) {
1385 return EFI_INVALID_PARAMETER
;
1389 // Check whether this question is for the requested varstore.
1391 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1392 if (IfrCheckBox
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1396 if (NameValueType
) {
1397 QuestionName
= HiiGetString (HiiHandle
, IfrCheckBox
->Question
.VarStoreInfo
.VarName
, NULL
);
1398 ASSERT (QuestionName
!= NULL
);
1400 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1402 // This question is not in the current configuration string. Skip it.
1407 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1408 if (EFI_ERROR (Status
)) {
1413 // Get Offset by Question header
1415 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1416 Width
= (UINT16
) sizeof (BOOLEAN
);
1418 // Check whether this question is in current block array.
1420 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1422 // This question is not in the current configuration string. Skip it.
1427 // Check this var question is in the var storage
1429 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1431 // This question exceeds the var store size.
1433 return EFI_INVALID_PARAMETER
;
1436 // Check the current value is in the numeric range.
1439 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1442 // Boolean type, only 1 and 0 is valid.
1445 return EFI_INVALID_PARAMETER
;
1448 case EFI_IFR_STRING_OP
:
1450 // Check current string length is less than maxsize
1454 // CheckBox question is not in IFR Form. This IFR form is not valid.
1456 if (VarStoreData
.VarStoreId
== 0) {
1457 return EFI_INVALID_PARAMETER
;
1461 // Check whether this question is for the requested varstore.
1463 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1464 if (IfrString
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1468 // Get Width by OneOf Flags
1470 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1471 if (NameValueType
) {
1472 QuestionName
= HiiGetString (HiiHandle
, IfrString
->Question
.VarStoreInfo
.VarName
, NULL
);
1473 ASSERT (QuestionName
!= NULL
);
1475 StringPtr
= StrStr (RequestElement
, QuestionName
);
1476 if (StringPtr
== NULL
) {
1478 // This question is not in the current configuration string. Skip it.
1489 // Check current string length is less than maxsize
1491 if (StrSize (StringPtr
) > Width
) {
1492 return EFI_INVALID_PARAMETER
;
1496 // Get Offset/Width by Question header and OneOf Flags
1498 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1500 // Check whether this question is in current block array.
1502 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1504 // This question is not in the current configuration string. Skip it.
1509 // Check this var question is in the var storage
1511 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1513 // This question exceeds the var store size.
1515 return EFI_INVALID_PARAMETER
;
1519 // Check current string length is less than maxsize
1521 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1522 return EFI_INVALID_PARAMETER
;
1526 case EFI_IFR_ONE_OF_OPTION_OP
:
1528 // Opcode Scope is zero. This one of option is not to be checked.
1530 if (VarBlockData
.Scope
== 0) {
1535 // Only check for OneOf and OrderList opcode
1537 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1538 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1540 // Check current value is the value of one of option.
1542 ASSERT (IfrOneOfOption
->Type
<= EFI_IFR_TYPE_NUM_SIZE_64
);
1543 ZeroMem (&TmpValue
, sizeof (EFI_IFR_TYPE_VALUE
));
1544 CopyMem (&TmpValue
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
1545 if (VarValue
== TmpValue
.u64
) {
1547 // The value is one of option value.
1548 // Set OpCode to Zero, don't need check again.
1550 VarBlockData
.OpCode
= 0;
1554 case EFI_IFR_END_OP
:
1556 // Decrease opcode scope for the validated opcode
1558 if (VarBlockData
.Scope
> 0) {
1559 VarBlockData
.Scope
--;
1563 // OneOf value doesn't belong to one of option value.
1565 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1566 return EFI_INVALID_PARAMETER
;
1571 // Increase Scope for the validated opcode
1573 if (VarBlockData
.Scope
> 0) {
1574 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1579 // Go to the next opcode
1581 IfrOffset
+= IfrOpHdr
->Length
;
1584 // Only one form is in a package list.
1590 // Go to next package.
1592 PackageOffset
+= PacakgeHeader
.Length
;
1599 This internal function parses IFR data to validate current setting.
1601 @param ConfigElement ConfigResp element string contains the current setting.
1602 @param CurrentBlockArray Current block array.
1603 @param VarBuffer Data buffer for this varstore.
1605 @retval EFI_SUCCESS The current setting is valid.
1606 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1607 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1611 IN CHAR16
*ConfigElement
,
1612 OUT IFR_BLOCK_DATA
**CurrentBlockArray
,
1613 OUT UINT8
**VarBuffer
1616 IFR_BLOCK_DATA
*BlockData
;
1617 IFR_BLOCK_DATA
*NewBlockData
;
1618 EFI_STRING StringPtr
;
1624 UINTN MaxBufferSize
;
1626 IFR_BLOCK_DATA
*BlockArray
;
1630 // Initialize the local variables.
1632 Status
= EFI_SUCCESS
;
1634 NewBlockData
= NULL
;
1637 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
1638 DataBuffer
= AllocateZeroPool (MaxBufferSize
);
1639 if (DataBuffer
== NULL
) {
1640 return EFI_OUT_OF_RESOURCES
;
1646 BlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1647 if (BlockArray
== NULL
) {
1648 Status
= EFI_OUT_OF_RESOURCES
;
1651 InitializeListHead (&BlockArray
->Entry
);
1653 StringPtr
= StrStr (ConfigElement
, L
"&OFFSET=");
1654 ASSERT (StringPtr
!= NULL
);
1657 // Parse each <RequestElement> if exists
1658 // Only <BlockName> format is supported by this help function.
1659 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1661 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1663 // Skip the &OFFSET= string
1665 StringPtr
+= StrLen (L
"&OFFSET=");
1670 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1671 if (EFI_ERROR (Status
)) {
1678 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1680 FreePool (TmpBuffer
);
1683 StringPtr
+= Length
;
1684 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1685 Status
= EFI_INVALID_PARAMETER
;
1688 StringPtr
+= StrLen (L
"&WIDTH=");
1693 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1694 if (EFI_ERROR (Status
)) {
1701 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1703 FreePool (TmpBuffer
);
1706 StringPtr
+= Length
;
1707 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1708 Status
= EFI_INVALID_PARAMETER
;
1712 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1713 Status
= EFI_INVALID_PARAMETER
;
1716 StringPtr
+= StrLen (L
"&VALUE=");
1721 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1722 if (EFI_ERROR (Status
)) {
1726 StringPtr
+= Length
;
1727 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1728 Status
= EFI_INVALID_PARAMETER
;
1733 // Check whether VarBuffer is enough
1735 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1736 DataBuffer
= ReallocatePool (
1738 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1741 if (DataBuffer
== NULL
) {
1742 Status
= EFI_OUT_OF_RESOURCES
;
1745 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1749 // Update the Block with configuration info
1751 CopyMem (DataBuffer
+ Offset
, TmpBuffer
, Width
);
1752 FreePool (TmpBuffer
);
1756 // Set new Block Data
1758 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1759 if (NewBlockData
== NULL
) {
1760 Status
= EFI_OUT_OF_RESOURCES
;
1763 NewBlockData
->Offset
= Offset
;
1764 NewBlockData
->Width
= Width
;
1767 // Insert the new block data into the block data array.
1769 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1770 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1771 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1772 if (NewBlockData
->Width
> BlockData
->Width
) {
1773 BlockData
->Width
= NewBlockData
->Width
;
1775 FreePool (NewBlockData
);
1777 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1779 // Insert new block data as the previous one of this link.
1781 InsertTailList (Link
, &NewBlockData
->Entry
);
1787 // Insert new block data into the array tail.
1789 if (Link
== &BlockArray
->Entry
) {
1790 InsertTailList (Link
, &NewBlockData
->Entry
);
1794 // If '\0', parsing is finished.
1796 if (*StringPtr
== 0) {
1800 // Go to next ConfigBlock
1805 // Merge the aligned block data into the single block data.
1807 Link
= BlockArray
->Entry
.ForwardLink
;
1808 while ((Link
!= &BlockArray
->Entry
) && (Link
->ForwardLink
!= &BlockArray
->Entry
)) {
1809 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1810 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1811 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1812 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1813 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1815 RemoveEntryList (Link
->ForwardLink
);
1816 FreePool (NewBlockData
);
1819 Link
= Link
->ForwardLink
;
1822 *VarBuffer
= DataBuffer
;
1823 *CurrentBlockArray
= BlockArray
;
1827 if (DataBuffer
!= NULL
) {
1828 FreePool (DataBuffer
);
1831 if (BlockArray
!= NULL
) {
1833 // Free Link Array CurrentBlockArray
1835 while (!IsListEmpty (&BlockArray
->Entry
)) {
1836 BlockData
= BASE_CR (BlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1837 RemoveEntryList (&BlockData
->Entry
);
1838 FreePool (BlockData
);
1840 FreePool (BlockArray
);
1847 This internal function parses IFR data to validate current setting.
1849 @param ConfigResp ConfigResp string contains the current setting.
1850 @param HiiPackageList Point to Hii package list.
1851 @param PackageListLength The length of the pacakge.
1852 @param VarGuid Guid of the buffer storage.
1853 @param VarName Name of the buffer storage.
1854 @param HiiHandle The HiiHandle for this package.
1856 @retval EFI_SUCCESS The current setting is valid.
1857 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1858 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1862 InternalHiiValidateCurrentSetting (
1863 IN EFI_STRING ConfigResp
,
1864 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
1865 IN UINTN PackageListLength
,
1866 IN EFI_GUID
*VarGuid
,
1868 IN EFI_HII_HANDLE HiiHandle
1873 IFR_BLOCK_DATA
*CurrentBlockArray
;
1874 IFR_BLOCK_DATA
*BlockData
;
1876 BOOLEAN NameValueType
;
1878 CurrentBlockArray
= NULL
;
1881 Status
= EFI_SUCCESS
;
1884 // If StringPtr != NULL, get the request elements.
1886 if (StrStr (ConfigResp
, L
"&OFFSET=") != NULL
) {
1887 Status
= GetBlockDataInfo(ConfigResp
, &CurrentBlockArray
, &VarBuffer
);
1888 if (EFI_ERROR (Status
)) {
1891 NameValueType
= FALSE
;
1894 // Skip header part.
1896 StringPtr
= StrStr (ConfigResp
, L
"PATH=");
1897 ASSERT (StringPtr
!= NULL
);
1899 if (StrStr (StringPtr
, L
"&") != NULL
) {
1900 NameValueType
= TRUE
;
1903 // Not found Request element, return success.
1909 Status
= ValidateQuestionFromVfr(
1921 if (VarBuffer
!= NULL
) {
1922 FreePool (VarBuffer
);
1925 if (CurrentBlockArray
!= NULL
) {
1927 // Free Link Array CurrentBlockArray
1929 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1930 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1931 RemoveEntryList (&BlockData
->Entry
);
1932 FreePool (BlockData
);
1934 FreePool (CurrentBlockArray
);
1941 Check whether the ConfigRequest string has the request elements.
1942 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
1943 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
1945 @param ConfigRequest The input config request string.
1947 @retval TRUE The input include config request elements.
1948 @retval FALSE The input string not includes.
1952 GetElementsFromRequest (
1953 IN EFI_STRING ConfigRequest
1956 EFI_STRING TmpRequest
;
1958 TmpRequest
= StrStr (ConfigRequest
, L
"PATH=");
1959 ASSERT (TmpRequest
!= NULL
);
1961 if ((StrStr (TmpRequest
, L
"&OFFSET=") != NULL
) || (StrStr (TmpRequest
, L
"&") != NULL
)) {
1969 This function parses the input ConfigRequest string and its matched IFR code
1970 string for setting default value and validating current setting.
1972 1. For setting default action, Reset the default value specified by DefaultId
1973 to the driver configuration got by Request string.
1974 2. For validating current setting, Validate the current configuration
1975 by parsing HII form IFR opcode.
1977 NULL request string support depends on the ExportConfig interface of
1978 HiiConfigRouting protocol in UEFI specification.
1980 @param Request A null-terminated Unicode string in
1981 <MultiConfigRequest> format. It can be NULL.
1982 If it is NULL, all current configuration for the
1983 entirety of the current HII database will be validated.
1984 If it is NULL, all configuration for the
1985 entirety of the current HII database will be reset.
1986 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1987 @param ActionType Action supports setting defaults and validate current setting.
1989 @retval TURE Action runs successfully.
1990 @retval FALSE Action is not valid or Action can't be executed successfully..
1994 InternalHiiIfrValueAction (
1995 IN CONST EFI_STRING Request
, OPTIONAL
1996 IN UINT16 DefaultId
,
2000 EFI_STRING ConfigAltResp
;
2001 EFI_STRING ConfigAltHdr
;
2002 EFI_STRING ConfigResp
;
2003 EFI_STRING Progress
;
2004 EFI_STRING StringPtr
;
2005 EFI_STRING StringHdr
;
2007 EFI_HANDLE DriverHandle
;
2008 EFI_HANDLE TempDriverHandle
;
2009 EFI_HII_HANDLE
*HiiHandleBuffer
;
2010 EFI_HII_HANDLE HiiHandle
;
2015 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2016 UINTN PackageListLength
;
2018 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2019 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2021 ConfigAltResp
= NULL
;
2026 ConfigAltHdr
= NULL
;
2027 HiiHandleBuffer
= NULL
;
2029 TempDriverHandle
= NULL
;
2031 HiiPackageList
= NULL
;
2034 // Only support set default and validate setting action.
2036 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
2041 // Get the full requested value and deault value string.
2043 if (Request
!= NULL
) {
2044 Status
= gHiiConfigRouting
->ExtractConfig (
2051 Status
= gHiiConfigRouting
->ExportConfig (
2057 if (EFI_ERROR (Status
)) {
2061 StringPtr
= ConfigAltResp
;
2063 while (StringPtr
!= L
'\0') {
2065 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
2067 StringHdr
= StringPtr
;
2072 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2073 Status
= EFI_INVALID_PARAMETER
;
2076 StringPtr
+= StrLen (L
"GUID=");
2077 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
2078 if (EFI_ERROR (Status
)) {
2083 // Get Name value VarName
2085 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
2088 if (*StringPtr
== L
'\0') {
2089 Status
= EFI_INVALID_PARAMETER
;
2092 StringPtr
+= StrLen (L
"&NAME=");
2093 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
2094 if (EFI_ERROR (Status
)) {
2099 // Get Path value DevicePath
2101 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
2104 if (*StringPtr
== L
'\0') {
2105 Status
= EFI_INVALID_PARAMETER
;
2108 StringPtr
+= StrLen (L
"&PATH=");
2109 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
2110 if (EFI_ERROR (Status
)) {
2115 // Get the Driver handle by the got device path.
2117 TempDevicePath
= DevicePath
;
2118 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
2119 if (EFI_ERROR (Status
)) {
2124 // Find the matched Hii Handle for the found Driver handle
2126 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
2127 if (HiiHandleBuffer
== NULL
) {
2128 Status
= EFI_NOT_FOUND
;
2132 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
2133 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
2134 if (TempDriverHandle
== DriverHandle
) {
2139 HiiHandle
= HiiHandleBuffer
[Index
];
2140 FreePool (HiiHandleBuffer
);
2142 if (HiiHandle
== NULL
) {
2144 // This request string has no its Hii package.
2145 // Its default value and validating can't execute by parsing IFR data.
2146 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
2148 Status
= EFI_SUCCESS
;
2149 goto NextConfigAltResp
;
2153 // 2. Get HiiPackage by HiiHandle
2155 PackageListLength
= 0;
2156 HiiPackageList
= NULL
;
2157 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
2160 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
2162 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
2163 Status
= EFI_INVALID_PARAMETER
;
2167 HiiPackageList
= AllocatePool (PackageListLength
);
2168 if (HiiPackageList
== NULL
) {
2169 Status
= EFI_OUT_OF_RESOURCES
;
2174 // Get PackageList on HiiHandle
2176 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
2177 if (EFI_ERROR (Status
)) {
2182 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
2183 // Get the default configuration string according to the default ID.
2185 Status
= gHiiConfigRouting
->GetAltConfig (
2191 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultId
:NULL
, // it can be NULL to get the current setting.
2196 // The required setting can't be found. So, it is not required to be validated and set.
2198 if (EFI_ERROR (Status
)) {
2199 Status
= EFI_SUCCESS
;
2200 goto NextConfigAltResp
;
2203 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
2205 if (!GetElementsFromRequest (ConfigResp
)) {
2206 goto NextConfigAltResp
;
2210 // 4. Set the default configuration information or Validate current setting by parse IFR code.
2211 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2213 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
2215 // Set the default configuration information.
2217 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
2220 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2222 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
, HiiHandle
);
2225 if (EFI_ERROR (Status
)) {
2231 // Free the allocated pacakge buffer and the got ConfigResp string.
2233 if (HiiPackageList
!= NULL
) {
2234 FreePool (HiiPackageList
);
2235 HiiPackageList
= NULL
;
2238 if (ConfigResp
!= NULL
) {
2239 FreePool (ConfigResp
);
2244 // Free the allocated buffer.
2252 FreePool (DevicePath
);
2256 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
2260 // Get and Skip ConfigHdr
2262 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
2265 if (*StringPtr
== L
'\0') {
2270 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
2271 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
2273 MaxLen
= 1 + StringPtr
- StringHdr
+ 8 + 1;
2274 ConfigAltHdr
= AllocateZeroPool ( MaxLen
* sizeof (CHAR16
));
2275 if (ConfigAltHdr
== NULL
) {
2276 Status
= EFI_OUT_OF_RESOURCES
;
2279 StrCpyS (ConfigAltHdr
, MaxLen
, L
"&");
2280 StrnCatS (ConfigAltHdr
, MaxLen
, StringHdr
, StringPtr
- StringHdr
);
2281 StrCatS (ConfigAltHdr
, MaxLen
, L
"&ALTCFG=");
2284 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
2286 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
2287 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
2288 if (*StringPtr
== L
'\0') {
2294 // Free the allocated ConfigAltHdr string
2296 FreePool (ConfigAltHdr
);
2297 if (*StringPtr
== L
'\0') {
2302 // Find &GUID as the next ConfigHdr
2304 StringPtr
= StrStr (StringPtr
, L
"&GUID");
2305 if (StringPtr
== NULL
) {
2316 if (VarGuid
!= NULL
) {
2320 if (VarName
!= NULL
) {
2324 if (DevicePath
!= NULL
) {
2325 FreePool (DevicePath
);
2328 if (ConfigResp
!= NULL
) {
2329 FreePool (ConfigResp
);
2332 if (ConfigAltResp
!= NULL
) {
2333 FreePool (ConfigAltResp
);
2336 if (HiiPackageList
!= NULL
) {
2337 FreePool (HiiPackageList
);
2340 if (EFI_ERROR (Status
)) {
2348 Validate the current configuration by parsing HII form IFR opcode.
2350 NULL request string support depends on the ExportConfig interface of
2351 HiiConfigRouting protocol in UEFI specification.
2353 @param Request A null-terminated Unicode string in
2354 <MultiConfigRequest> format. It can be NULL.
2355 If it is NULL, all current configuration for the
2356 entirety of the current HII database will be validated.
2358 @retval TRUE Current configuration is valid.
2359 @retval FALSE Current configuration is invalid.
2363 HiiValidateSettings (
2364 IN CONST EFI_STRING Request OPTIONAL
2367 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2371 Reset the default value specified by DefaultId to the driver
2372 configuration got by Request string.
2374 NULL request string support depends on the ExportConfig interface of
2375 HiiConfigRouting protocol in UEFI specification.
2377 @param Request A null-terminated Unicode string in
2378 <MultiConfigRequest> format. It can be NULL.
2379 If it is NULL, all configuration for the
2380 entirety of the current HII database will be reset.
2381 @param DefaultId Specifies the type of defaults to retrieve.
2383 @retval TURE The default value is set successfully.
2384 @retval FALSE The default value can't be found and set.
2389 IN CONST EFI_STRING Request
, OPTIONAL
2393 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2397 Determines if two values in config strings match.
2399 Compares the substring between StartSearchString and StopSearchString in
2400 FirstString to the substring between StartSearchString and StopSearchString
2401 in SecondString. If the two substrings match, then TRUE is returned. If the
2402 two substrings do not match, then FALSE is returned.
2404 If FirstString is NULL, then ASSERT().
2405 If SecondString is NULL, then ASSERT().
2406 If StartSearchString is NULL, then ASSERT().
2407 If StopSearchString is NULL, then ASSERT().
2409 @param FirstString Pointer to the first Null-terminated Unicode string.
2410 @param SecondString Pointer to the second Null-terminated Unicode string.
2411 @param StartSearchString Pointer to the Null-terminated Unicode string that
2412 marks the start of the value string to compare.
2413 @param StopSearchString Pointer to the Null-terminated Unicode string that
2414 marks the end of the value string to compare.
2416 @retval FALSE StartSearchString is not present in FirstString.
2417 @retval FALSE StartSearchString is not present in SecondString.
2418 @retval FALSE StopSearchString is not present in FirstString.
2419 @retval FALSE StopSearchString is not present in SecondString.
2420 @retval FALSE The length of the substring in FirstString is not the
2421 same length as the substring in SecondString.
2422 @retval FALSE The value string in FirstString does not matche the
2423 value string in SecondString.
2424 @retval TRUE The value string in FirstString matches the value
2425 string in SecondString.
2430 InternalHiiCompareSubString (
2431 IN CHAR16
*FirstString
,
2432 IN CHAR16
*SecondString
,
2433 IN CHAR16
*StartSearchString
,
2434 IN CHAR16
*StopSearchString
2437 CHAR16
*EndFirstString
;
2438 CHAR16
*EndSecondString
;
2440 ASSERT (FirstString
!= NULL
);
2441 ASSERT (SecondString
!= NULL
);
2442 ASSERT (StartSearchString
!= NULL
);
2443 ASSERT (StopSearchString
!= NULL
);
2445 FirstString
= StrStr (FirstString
, StartSearchString
);
2446 if (FirstString
== NULL
) {
2450 SecondString
= StrStr (SecondString
, StartSearchString
);
2451 if (SecondString
== NULL
) {
2455 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2456 if (EndFirstString
== NULL
) {
2460 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2461 if (EndSecondString
== NULL
) {
2465 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2469 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2473 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2475 If ConfigHdr is NULL, then ASSERT().
2477 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2478 @param[in] Guid GUID of the storage.
2479 @param[in] Name NAME of the storage.
2481 @retval TRUE Routing information matches <ConfigHdr>.
2482 @retval FALSE Routing information does not match <ConfigHdr>.
2487 HiiIsConfigHdrMatch (
2488 IN CONST EFI_STRING ConfigHdr
,
2489 IN CONST EFI_GUID
*Guid
, OPTIONAL
2490 IN CONST CHAR16
*Name OPTIONAL
2493 EFI_STRING CompareConfigHdr
;
2496 ASSERT (ConfigHdr
!= NULL
);
2499 // Use Guid and Name to generate a <ConfigHdr> string
2501 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2502 if (CompareConfigHdr
== NULL
) {
2509 // Compare GUID value strings
2511 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2514 if (Result
&& Name
!= NULL
) {
2516 // Compare NAME value strings
2518 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2522 // Free the <ConfigHdr> string
2524 FreePool (CompareConfigHdr
);
2530 Retrieves uncommitted data from the Form Browser and converts it to a binary
2533 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2534 parameter that may be NULL.
2535 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2536 is an optional parameter that may be NULL.
2537 @param[in] BufferSize Length in bytes of buffer to hold retrieved data.
2538 @param[out] Buffer Buffer of data to be updated.
2540 @retval FALSE The uncommitted data could not be retrieved.
2541 @retval TRUE The uncommitted data was retrieved.
2547 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2548 IN CONST CHAR16
*VariableName
, OPTIONAL
2549 IN UINTN BufferSize
,
2553 EFI_STRING ResultsData
;
2555 EFI_STRING ConfigResp
;
2560 // Retrieve the results data from the Browser Callback
2562 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2563 if (ResultsData
== NULL
) {
2568 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2570 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2571 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2572 ConfigResp
= AllocateZeroPool (Size
);
2573 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2576 // Free the allocated buffer
2578 FreePool (ResultsData
);
2579 if (ConfigResp
== NULL
) {
2584 // Convert <ConfigResp> to a buffer
2586 Status
= gHiiConfigRouting
->ConfigToBlock (
2594 // Free the allocated buffer
2596 FreePool (ConfigResp
);
2598 if (EFI_ERROR (Status
)) {
2606 Updates uncommitted data in the Form Browser.
2608 If Buffer is NULL, then ASSERT().
2610 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2611 parameter that may be NULL.
2612 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2613 is an optional parameter that may be NULL.
2614 @param[in] BufferSize Length, in bytes, of Buffer.
2615 @param[in] Buffer Buffer of data to commit.
2616 @param[in] RequestElement An optional field to specify which part of the
2617 buffer data will be send back to Browser. If NULL,
2618 the whole buffer of data will be committed to
2620 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2622 @retval FALSE The uncommitted data could not be updated.
2623 @retval TRUE The uncommitted data was updated.
2629 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2630 IN CONST CHAR16
*VariableName
, OPTIONAL
2631 IN UINTN BufferSize
,
2632 IN CONST UINT8
*Buffer
,
2633 IN CONST CHAR16
*RequestElement OPTIONAL
2637 EFI_STRING ConfigRequest
;
2638 EFI_STRING ConfigResp
;
2639 EFI_STRING ResultsData
;
2641 ASSERT (Buffer
!= NULL
);
2644 // Construct <ConfigRequest>
2646 if (RequestElement
== NULL
) {
2648 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2649 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2651 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2652 ConfigRequest
= AllocateZeroPool (Size
);
2653 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2656 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2657 // followed by <RequestElement> followed by a Null-terminator
2659 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2660 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2661 ConfigRequest
= AllocateZeroPool (Size
);
2662 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2664 if (ConfigRequest
== NULL
) {
2669 // Convert <ConfigRequest> to <ConfigResp>
2671 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2672 FreePool (ConfigRequest
);
2673 if (ConfigResp
== NULL
) {
2678 // Set data in the uncommitted browser state information
2680 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2681 FreePool (ConfigResp
);
2683 return (BOOLEAN
)(ResultsData
!= NULL
);
2686 /////////////////////////////////////////
2687 /////////////////////////////////////////
2689 /////////////////////////////////////////
2690 /////////////////////////////////////////
2692 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2698 } HII_LIB_OPCODE_BUFFER
;
2701 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2703 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2704 1, // EFI_IFR_TYPE_NUM_SIZE_8
2705 2, // EFI_IFR_TYPE_NUM_SIZE_16
2706 4, // EFI_IFR_TYPE_NUM_SIZE_32
2707 8, // EFI_IFR_TYPE_NUM_SIZE_64
2708 1, // EFI_IFR_TYPE_BOOLEAN
2709 3, // EFI_IFR_TYPE_TIME
2710 4, // EFI_IFR_TYPE_DATE
2711 2 // EFI_IFR_TYPE_STRING
2715 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2716 HiiFreeOpCodeHandle().
2718 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2719 @retval Other A new OpCode handle.
2724 HiiAllocateOpCodeHandle (
2728 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2730 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2731 if (OpCodeBuffer
== NULL
) {
2734 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2735 if (OpCodeBuffer
->Buffer
== NULL
) {
2736 FreePool (OpCodeBuffer
);
2739 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2740 OpCodeBuffer
->Position
= 0;
2741 return (VOID
*)OpCodeBuffer
;
2745 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().
2746 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2747 Handle are also freed.
2749 If OpCodeHandle is NULL, then ASSERT().
2751 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2756 HiiFreeOpCodeHandle (
2760 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2762 ASSERT (OpCodeHandle
!= NULL
);
2764 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2765 if (OpCodeBuffer
->Buffer
!= NULL
) {
2766 FreePool (OpCodeBuffer
->Buffer
);
2768 FreePool (OpCodeBuffer
);
2772 Internal function gets the current position of opcode buffer.
2774 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2776 @return Current position of opcode buffer.
2780 InternalHiiOpCodeHandlePosition (
2781 IN VOID
*OpCodeHandle
2784 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2788 Internal function gets the start pointer of opcode buffer.
2790 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2792 @return Pointer to the opcode buffer base.
2796 InternalHiiOpCodeHandleBuffer (
2797 IN VOID
*OpCodeHandle
2800 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2804 Internal function reserves the enough buffer for current opcode.
2805 When the buffer is not enough, Opcode buffer will be extended.
2807 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2808 @param[in] Size Size of current opcode.
2810 @return Pointer to the current opcode.
2814 InternalHiiGrowOpCodeHandle (
2815 IN VOID
*OpCodeHandle
,
2819 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2822 ASSERT (OpCodeHandle
!= NULL
);
2824 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2825 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2826 Buffer
= ReallocatePool (
2827 OpCodeBuffer
->BufferSize
,
2828 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2829 OpCodeBuffer
->Buffer
2831 ASSERT (Buffer
!= NULL
);
2832 OpCodeBuffer
->Buffer
= Buffer
;
2833 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2835 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2836 OpCodeBuffer
->Position
+= Size
;
2841 Internal function creates opcode based on the template opcode.
2843 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2844 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2845 @param[in] OpCode OpCode IFR value.
2846 @param[in] OpCodeSize Size of opcode.
2847 @param[in] ExtensionSize Size of extended opcode.
2848 @param[in] Scope Scope bit of opcode.
2850 @return Pointer to the current opcode with opcode data.
2854 InternalHiiCreateOpCodeExtended (
2855 IN VOID
*OpCodeHandle
,
2856 IN VOID
*OpCodeTemplate
,
2858 IN UINTN OpCodeSize
,
2859 IN UINTN ExtensionSize
,
2863 EFI_IFR_OP_HEADER
*Header
;
2866 ASSERT (OpCodeTemplate
!= NULL
);
2867 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2869 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2870 Header
->OpCode
= OpCode
;
2871 Header
->Scope
= Scope
;
2872 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2873 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2874 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2878 Internal function creates opcode based on the template opcode for the normal opcode.
2880 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2881 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2882 @param[in] OpCode OpCode IFR value.
2883 @param[in] OpCodeSize Size of opcode.
2885 @return Pointer to the current opcode with opcode data.
2889 InternalHiiCreateOpCode (
2890 IN VOID
*OpCodeHandle
,
2891 IN VOID
*OpCodeTemplate
,
2896 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2900 Append raw opcodes to an OpCodeHandle.
2902 If OpCodeHandle is NULL, then ASSERT().
2903 If RawBuffer is NULL, then ASSERT();
2905 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2906 @param[in] RawBuffer Buffer of opcodes to append.
2907 @param[in] RawBufferSize The size, in bytes, of Buffer.
2909 @retval NULL There is not enough space left in Buffer to add the opcode.
2910 @retval Other A pointer to the appended opcodes.
2915 HiiCreateRawOpCodes (
2916 IN VOID
*OpCodeHandle
,
2917 IN UINT8
*RawBuffer
,
2918 IN UINTN RawBufferSize
2923 ASSERT (RawBuffer
!= NULL
);
2925 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2926 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2930 Append opcodes from one OpCode Handle to another OpCode handle.
2932 If OpCodeHandle is NULL, then ASSERT().
2933 If RawOpCodeHandle is NULL, then ASSERT();
2935 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2936 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2938 @retval NULL There is not enough space left in Buffer to add the opcode.
2939 @retval Other A pointer to the appended opcodes.
2944 InternalHiiAppendOpCodes (
2945 IN VOID
*OpCodeHandle
,
2946 IN VOID
*RawOpCodeHandle
2949 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2951 ASSERT (RawOpCodeHandle
!= NULL
);
2953 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2954 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2958 Create EFI_IFR_END_OP opcode.
2960 If OpCodeHandle is NULL, then ASSERT().
2962 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2964 @retval NULL There is not enough space left in Buffer to add the opcode.
2965 @retval Other A pointer to the created opcode.
2970 HiiCreateEndOpCode (
2971 IN VOID
*OpCodeHandle
2976 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2980 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2982 If OpCodeHandle is NULL, then ASSERT().
2983 If Type is invalid, then ASSERT().
2984 If Flags is invalid, then ASSERT().
2986 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2987 @param[in] StringId StringId for the option
2988 @param[in] Flags Flags for the option
2989 @param[in] Type Type for the option
2990 @param[in] Value Value for the option
2992 @retval NULL There is not enough space left in Buffer to add the opcode.
2993 @retval Other A pointer to the created opcode.
2998 HiiCreateOneOfOptionOpCode (
2999 IN VOID
*OpCodeHandle
,
3006 EFI_IFR_ONE_OF_OPTION OpCode
;
3008 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
3010 ZeroMem (&OpCode
, sizeof (OpCode
));
3011 OpCode
.Option
= StringId
;
3012 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
3014 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
3016 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, OFFSET_OF(EFI_IFR_ONE_OF_OPTION
, Value
) + mHiiDefaultTypeToWidth
[Type
]);
3020 Create EFI_IFR_DEFAULT_OP opcode.
3022 If OpCodeHandle is NULL, then ASSERT().
3023 If Type is invalid, then ASSERT().
3025 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3026 @param[in] DefaultId DefaultId for the default
3027 @param[in] Type Type for the default
3028 @param[in] Value Value for the default
3030 @retval NULL There is not enough space left in Buffer to add the opcode.
3031 @retval Other A pointer to the created opcode.
3036 HiiCreateDefaultOpCode (
3037 IN VOID
*OpCodeHandle
,
3038 IN UINT16 DefaultId
,
3043 EFI_IFR_DEFAULT OpCode
;
3045 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
3047 ZeroMem (&OpCode
, sizeof (OpCode
));
3049 OpCode
.DefaultId
= DefaultId
;
3050 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
3052 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, OFFSET_OF(EFI_IFR_DEFAULT
, Value
) + mHiiDefaultTypeToWidth
[Type
]);
3056 Create EFI_IFR_GUID opcode.
3058 If OpCodeHandle is NULL, then ASSERT().
3059 If Guid is NULL, then ASSERT().
3060 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
3062 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3063 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
3064 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
3065 optional parameter that may be NULL. If this
3066 parameter is NULL, then the GUID extension
3067 region of the created opcode is filled with zeros.
3068 If this parameter is not NULL, then the GUID
3069 extension region of GuidData will be copied to
3070 the GUID extension region of the created opcode.
3071 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
3072 must be >= sizeof(EFI_IFR_GUID).
3074 @retval NULL There is not enough space left in Buffer to add the opcode.
3075 @retval Other A pointer to the created opcode.
3080 HiiCreateGuidOpCode (
3081 IN VOID
*OpCodeHandle
,
3082 IN CONST EFI_GUID
*Guid
,
3083 IN CONST VOID
*GuidOpCode
, OPTIONAL
3087 EFI_IFR_GUID OpCode
;
3088 EFI_IFR_GUID
*OpCodePointer
;
3090 ASSERT (Guid
!= NULL
);
3091 ASSERT (OpCodeSize
>= sizeof (OpCode
));
3093 ZeroMem (&OpCode
, sizeof (OpCode
));
3094 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
3096 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
3101 OpCodeSize
- sizeof (OpCode
),
3104 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
3105 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
3107 return (UINT8
*)OpCodePointer
;
3111 Create EFI_IFR_ACTION_OP opcode.
3113 If OpCodeHandle is NULL, then ASSERT().
3114 If any reserved bits are set in QuestionFlags, then ASSERT().
3116 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3117 @param[in] QuestionId Question ID
3118 @param[in] Prompt String ID for Prompt
3119 @param[in] Help String ID for Help
3120 @param[in] QuestionFlags Flags in Question Header
3121 @param[in] QuestionConfig String ID for configuration
3123 @retval NULL There is not enough space left in Buffer to add the opcode.
3124 @retval Other A pointer to the created opcode.
3129 HiiCreateActionOpCode (
3130 IN VOID
*OpCodeHandle
,
3131 IN EFI_QUESTION_ID QuestionId
,
3132 IN EFI_STRING_ID Prompt
,
3133 IN EFI_STRING_ID Help
,
3134 IN UINT8 QuestionFlags
,
3135 IN EFI_STRING_ID QuestionConfig
3138 EFI_IFR_ACTION OpCode
;
3140 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3142 ZeroMem (&OpCode
, sizeof (OpCode
));
3143 OpCode
.Question
.QuestionId
= QuestionId
;
3144 OpCode
.Question
.Header
.Prompt
= Prompt
;
3145 OpCode
.Question
.Header
.Help
= Help
;
3146 OpCode
.Question
.Flags
= QuestionFlags
;
3147 OpCode
.QuestionConfig
= QuestionConfig
;
3149 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
3153 Create EFI_IFR_SUBTITLE_OP opcode.
3155 If OpCodeHandle is NULL, then ASSERT().
3156 If any reserved bits are set in Flags, then ASSERT().
3157 If Scope > 1, then ASSERT().
3159 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3160 @param[in] Prompt String ID for Prompt
3161 @param[in] Help String ID for Help
3162 @param[in] Flags Subtitle opcode flags
3163 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
3164 0 if this opcode is within the current scope.
3166 @retval NULL There is not enough space left in Buffer to add the opcode.
3167 @retval Other A pointer to the created opcode.
3172 HiiCreateSubTitleOpCode (
3173 IN VOID
*OpCodeHandle
,
3174 IN EFI_STRING_ID Prompt
,
3175 IN EFI_STRING_ID Help
,
3180 EFI_IFR_SUBTITLE OpCode
;
3182 ASSERT (Scope
<= 1);
3183 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
3185 ZeroMem (&OpCode
, sizeof (OpCode
));
3186 OpCode
.Statement
.Prompt
= Prompt
;
3187 OpCode
.Statement
.Help
= Help
;
3188 OpCode
.Flags
= Flags
;
3190 return InternalHiiCreateOpCodeExtended (
3193 EFI_IFR_SUBTITLE_OP
,
3201 Create EFI_IFR_REF_OP opcode.
3203 If OpCodeHandle is NULL, then ASSERT().
3204 If any reserved bits are set in QuestionFlags, then ASSERT().
3206 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3207 @param[in] FormId Destination Form ID
3208 @param[in] Prompt String ID for Prompt
3209 @param[in] Help String ID for Help
3210 @param[in] QuestionFlags Flags in Question Header
3211 @param[in] QuestionId Question ID
3213 @retval NULL There is not enough space left in Buffer to add the opcode.
3214 @retval Other A pointer to the created opcode.
3219 HiiCreateGotoOpCode (
3220 IN VOID
*OpCodeHandle
,
3221 IN EFI_FORM_ID FormId
,
3222 IN EFI_STRING_ID Prompt
,
3223 IN EFI_STRING_ID Help
,
3224 IN UINT8 QuestionFlags
,
3225 IN EFI_QUESTION_ID QuestionId
3230 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3232 ZeroMem (&OpCode
, sizeof (OpCode
));
3233 OpCode
.Question
.Header
.Prompt
= Prompt
;
3234 OpCode
.Question
.Header
.Help
= Help
;
3235 OpCode
.Question
.QuestionId
= QuestionId
;
3236 OpCode
.Question
.Flags
= QuestionFlags
;
3237 OpCode
.FormId
= FormId
;
3239 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
3243 Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode.
3245 When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created.
3246 When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created.
3247 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created.
3248 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created.
3250 If OpCodeHandle is NULL, then ASSERT().
3251 If any reserved bits are set in QuestionFlags, then ASSERT().
3253 @param[in] OpCodeHandle The handle to the buffer of opcodes.
3254 @param[in] RefFormId The Destination Form ID.
3255 @param[in] Prompt The string ID for Prompt.
3256 @param[in] Help The string ID for Help.
3257 @param[in] QuestionFlags The flags in Question Header
3258 @param[in] QuestionId Question ID.
3259 @param[in] RefQuestionId The question on the form to which this link is referring.
3260 If its value is zero, then the link refers to the top of the form.
3261 @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is
3262 zero, then the link is to the current form set.
3263 @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of
3264 the device path to which the form set containing the form specified by FormId.
3265 If its value is zero, then the link refers to the current page.
3267 @retval NULL There is not enough space left in Buffer to add the opcode.
3268 @retval Other A pointer to the created opcode.
3273 HiiCreateGotoExOpCode (
3274 IN VOID
*OpCodeHandle
,
3275 IN EFI_FORM_ID RefFormId
,
3276 IN EFI_STRING_ID Prompt
,
3277 IN EFI_STRING_ID Help
,
3278 IN UINT8 QuestionFlags
,
3279 IN EFI_QUESTION_ID QuestionId
,
3280 IN EFI_QUESTION_ID RefQuestionId
,
3281 IN EFI_GUID
*RefFormSetId
, OPTIONAL
3282 IN EFI_STRING_ID RefDevicePath
3285 EFI_IFR_REF4 OpCode
;
3288 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3290 ZeroMem (&OpCode
, sizeof (OpCode
));
3291 OpCode
.Question
.Header
.Prompt
= Prompt
;
3292 OpCode
.Question
.Header
.Help
= Help
;
3293 OpCode
.Question
.QuestionId
= QuestionId
;
3294 OpCode
.Question
.Flags
= QuestionFlags
;
3295 OpCode
.FormId
= RefFormId
;
3296 OpCode
.QuestionId
= RefQuestionId
;
3297 OpCode
.DevicePath
= RefDevicePath
;
3298 if (RefFormSetId
!= NULL
) {
3299 CopyMem (&OpCode
.FormSetId
, RefFormSetId
, sizeof (OpCode
.FormSetId
));
3303 // Cacluate OpCodeSize based on the input Ref value.
3304 // Try to use the small OpCode to save size.
3306 OpCodeSize
= sizeof (EFI_IFR_REF
);
3307 if (RefDevicePath
!= 0) {
3308 OpCodeSize
= sizeof (EFI_IFR_REF4
);
3309 } else if (RefFormSetId
!= NULL
) {
3310 OpCodeSize
= sizeof (EFI_IFR_REF3
);
3311 } else if (RefQuestionId
!= 0) {
3312 OpCodeSize
= sizeof (EFI_IFR_REF2
);
3315 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, OpCodeSize
);
3319 Create EFI_IFR_CHECKBOX_OP opcode.
3321 If OpCodeHandle is NULL, then ASSERT().
3322 If any reserved bits are set in QuestionFlags, then ASSERT().
3323 If any reserved bits are set in CheckBoxFlags, then ASSERT().
3325 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3326 @param[in] QuestionId Question ID
3327 @param[in] VarStoreId Storage ID
3328 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3329 for this name/value pair.
3330 @param[in] Prompt String ID for Prompt
3331 @param[in] Help String ID for Help
3332 @param[in] QuestionFlags Flags in Question Header
3333 @param[in] CheckBoxFlags Flags for checkbox opcode
3334 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3335 is an optional parameter that may be NULL.
3337 @retval NULL There is not enough space left in Buffer to add the opcode.
3338 @retval Other A pointer to the created opcode.
3343 HiiCreateCheckBoxOpCode (
3344 IN VOID
*OpCodeHandle
,
3345 IN EFI_QUESTION_ID QuestionId
,
3346 IN EFI_VARSTORE_ID VarStoreId
,
3347 IN UINT16 VarOffset
,
3348 IN EFI_STRING_ID Prompt
,
3349 IN EFI_STRING_ID Help
,
3350 IN UINT8 QuestionFlags
,
3351 IN UINT8 CheckBoxFlags
,
3352 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3355 EFI_IFR_CHECKBOX OpCode
;
3358 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3360 ZeroMem (&OpCode
, sizeof (OpCode
));
3361 OpCode
.Question
.QuestionId
= QuestionId
;
3362 OpCode
.Question
.VarStoreId
= VarStoreId
;
3363 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3364 OpCode
.Question
.Header
.Prompt
= Prompt
;
3365 OpCode
.Question
.Header
.Help
= Help
;
3366 OpCode
.Question
.Flags
= QuestionFlags
;
3367 OpCode
.Flags
= CheckBoxFlags
;
3369 if (DefaultsOpCodeHandle
== NULL
) {
3370 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
3373 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3374 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
3375 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3376 HiiCreateEndOpCode (OpCodeHandle
);
3377 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3381 Create EFI_IFR_NUMERIC_OP opcode.
3383 If OpCodeHandle is NULL, then ASSERT().
3384 If any reserved bits are set in QuestionFlags, then ASSERT().
3385 If any reserved bits are set in NumericFlags, then ASSERT().
3387 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3388 @param[in] QuestionId Question ID
3389 @param[in] VarStoreId Storage ID
3390 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3391 for this name/value pair.
3392 @param[in] Prompt String ID for Prompt
3393 @param[in] Help String ID for Help
3394 @param[in] QuestionFlags Flags in Question Header
3395 @param[in] NumericFlags Flags for numeric opcode
3396 @param[in] Minimum Numeric minimum value
3397 @param[in] Maximum Numeric maximum value
3398 @param[in] Step Numeric step for edit
3399 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3400 is an optional parameter that may be NULL.
3402 @retval NULL There is not enough space left in Buffer to add the opcode.
3403 @retval Other A pointer to the created opcode.
3408 HiiCreateNumericOpCode (
3409 IN VOID
*OpCodeHandle
,
3410 IN EFI_QUESTION_ID QuestionId
,
3411 IN EFI_VARSTORE_ID VarStoreId
,
3412 IN UINT16 VarOffset
,
3413 IN EFI_STRING_ID Prompt
,
3414 IN EFI_STRING_ID Help
,
3415 IN UINT8 QuestionFlags
,
3416 IN UINT8 NumericFlags
,
3420 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3423 EFI_IFR_NUMERIC OpCode
;
3427 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3430 ZeroMem (&OpCode
, sizeof (OpCode
));
3431 OpCode
.Question
.QuestionId
= QuestionId
;
3432 OpCode
.Question
.VarStoreId
= VarStoreId
;
3433 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3434 OpCode
.Question
.Header
.Prompt
= Prompt
;
3435 OpCode
.Question
.Header
.Help
= Help
;
3436 OpCode
.Question
.Flags
= QuestionFlags
;
3437 OpCode
.Flags
= NumericFlags
;
3439 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
3440 case EFI_IFR_NUMERIC_SIZE_1
:
3441 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
3442 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3443 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3447 case EFI_IFR_NUMERIC_SIZE_2
:
3448 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3449 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3450 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3454 case EFI_IFR_NUMERIC_SIZE_4
:
3455 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3456 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3457 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3461 case EFI_IFR_NUMERIC_SIZE_8
:
3462 OpCode
.data
.u64
.MinValue
= Minimum
;
3463 OpCode
.data
.u64
.MaxValue
= Maximum
;
3464 OpCode
.data
.u64
.Step
= Step
;
3469 Length
+= OFFSET_OF (EFI_IFR_NUMERIC
, data
);
3471 if (DefaultsOpCodeHandle
== NULL
) {
3472 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, Length
);
3475 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3476 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, Length
, 0, 1);
3477 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3478 HiiCreateEndOpCode (OpCodeHandle
);
3479 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3483 Create EFI_IFR_STRING_OP opcode.
3485 If OpCodeHandle is NULL, then ASSERT().
3486 If any reserved bits are set in QuestionFlags, then ASSERT().
3487 If any reserved bits are set in StringFlags, then ASSERT().
3489 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3490 @param[in] QuestionId Question ID
3491 @param[in] VarStoreId Storage ID
3492 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3493 for this name/value pair.
3494 @param[in] Prompt String ID for Prompt
3495 @param[in] Help String ID for Help
3496 @param[in] QuestionFlags Flags in Question Header
3497 @param[in] StringFlags Flags for string opcode
3498 @param[in] MinSize String minimum length
3499 @param[in] MaxSize String maximum length
3500 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3501 is an optional parameter that may be NULL.
3503 @retval NULL There is not enough space left in Buffer to add the opcode.
3504 @retval Other A pointer to the created opcode.
3509 HiiCreateStringOpCode (
3510 IN VOID
*OpCodeHandle
,
3511 IN EFI_QUESTION_ID QuestionId
,
3512 IN EFI_VARSTORE_ID VarStoreId
,
3513 IN UINT16 VarOffset
,
3514 IN EFI_STRING_ID Prompt
,
3515 IN EFI_STRING_ID Help
,
3516 IN UINT8 QuestionFlags
,
3517 IN UINT8 StringFlags
,
3520 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3523 EFI_IFR_STRING OpCode
;
3526 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3528 ZeroMem (&OpCode
, sizeof (OpCode
));
3529 OpCode
.Question
.Header
.Prompt
= Prompt
;
3530 OpCode
.Question
.Header
.Help
= Help
;
3531 OpCode
.Question
.QuestionId
= QuestionId
;
3532 OpCode
.Question
.VarStoreId
= VarStoreId
;
3533 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3534 OpCode
.Question
.Flags
= QuestionFlags
;
3535 OpCode
.MinSize
= MinSize
;
3536 OpCode
.MaxSize
= MaxSize
;
3537 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3539 if (DefaultsOpCodeHandle
== NULL
) {
3540 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3543 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3544 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3545 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3546 HiiCreateEndOpCode (OpCodeHandle
);
3547 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3551 Create EFI_IFR_ONE_OF_OP opcode.
3553 If OpCodeHandle is NULL, then ASSERT().
3554 If any reserved bits are set in QuestionFlags, then ASSERT().
3555 If any reserved bits are set in OneOfFlags, then ASSERT().
3557 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3558 @param[in] QuestionId Question ID
3559 @param[in] VarStoreId Storage ID
3560 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3561 for this name/value pair.
3562 @param[in] Prompt String ID for Prompt
3563 @param[in] Help String ID for Help
3564 @param[in] QuestionFlags Flags in Question Header
3565 @param[in] OneOfFlags Flags for oneof opcode
3566 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3567 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3568 is an optional parameter that may be NULL.
3570 @retval NULL There is not enough space left in Buffer to add the opcode.
3571 @retval Other A pointer to the created opcode.
3576 HiiCreateOneOfOpCode (
3577 IN VOID
*OpCodeHandle
,
3578 IN EFI_QUESTION_ID QuestionId
,
3579 IN EFI_VARSTORE_ID VarStoreId
,
3580 IN UINT16 VarOffset
,
3581 IN EFI_STRING_ID Prompt
,
3582 IN EFI_STRING_ID Help
,
3583 IN UINT8 QuestionFlags
,
3584 IN UINT8 OneOfFlags
,
3585 IN VOID
*OptionsOpCodeHandle
,
3586 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3589 EFI_IFR_ONE_OF OpCode
;
3593 ASSERT (OptionsOpCodeHandle
!= NULL
);
3594 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3596 ZeroMem (&OpCode
, sizeof (OpCode
));
3597 OpCode
.Question
.Header
.Prompt
= Prompt
;
3598 OpCode
.Question
.Header
.Help
= Help
;
3599 OpCode
.Question
.QuestionId
= QuestionId
;
3600 OpCode
.Question
.VarStoreId
= VarStoreId
;
3601 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3602 OpCode
.Question
.Flags
= QuestionFlags
;
3603 OpCode
.Flags
= OneOfFlags
;
3605 Length
= OFFSET_OF (EFI_IFR_ONE_OF
, data
);
3606 Length
+= (1 << (OneOfFlags
& EFI_IFR_NUMERIC_SIZE
)) * 3;
3608 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3609 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, Length
, 0, 1);
3610 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3611 if (DefaultsOpCodeHandle
!= NULL
) {
3612 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3614 HiiCreateEndOpCode (OpCodeHandle
);
3615 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3619 Create EFI_IFR_ORDERED_LIST_OP opcode.
3621 If OpCodeHandle is NULL, then ASSERT().
3622 If any reserved bits are set in QuestionFlags, then ASSERT().
3623 If any reserved bits are set in OrderedListFlags, then ASSERT().
3625 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3626 @param[in] QuestionId Question ID
3627 @param[in] VarStoreId Storage ID
3628 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3629 for this name/value pair.
3630 @param[in] Prompt String ID for Prompt
3631 @param[in] Help String ID for Help
3632 @param[in] QuestionFlags Flags in Question Header
3633 @param[in] OrderedListFlags Flags for ordered list opcode
3634 @param[in] DataType Type for option value
3635 @param[in] MaxContainers Maximum count for options in this ordered list
3636 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3637 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3638 is an optional parameter that may be NULL.
3640 @retval NULL There is not enough space left in Buffer to add the opcode.
3641 @retval Other A pointer to the created opcode.
3646 HiiCreateOrderedListOpCode (
3647 IN VOID
*OpCodeHandle
,
3648 IN EFI_QUESTION_ID QuestionId
,
3649 IN EFI_VARSTORE_ID VarStoreId
,
3650 IN UINT16 VarOffset
,
3651 IN EFI_STRING_ID Prompt
,
3652 IN EFI_STRING_ID Help
,
3653 IN UINT8 QuestionFlags
,
3654 IN UINT8 OrderedListFlags
,
3656 IN UINT8 MaxContainers
,
3657 IN VOID
*OptionsOpCodeHandle
,
3658 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3661 EFI_IFR_ORDERED_LIST OpCode
;
3664 ASSERT (OptionsOpCodeHandle
!= NULL
);
3665 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3667 ZeroMem (&OpCode
, sizeof (OpCode
));
3668 OpCode
.Question
.Header
.Prompt
= Prompt
;
3669 OpCode
.Question
.Header
.Help
= Help
;
3670 OpCode
.Question
.QuestionId
= QuestionId
;
3671 OpCode
.Question
.VarStoreId
= VarStoreId
;
3672 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3673 OpCode
.Question
.Flags
= QuestionFlags
;
3674 OpCode
.MaxContainers
= MaxContainers
;
3675 OpCode
.Flags
= OrderedListFlags
;
3677 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3678 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3679 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3680 if (DefaultsOpCodeHandle
!= NULL
) {
3681 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3683 HiiCreateEndOpCode (OpCodeHandle
);
3684 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3688 Create EFI_IFR_TEXT_OP opcode.
3690 If OpCodeHandle is NULL, then ASSERT().
3692 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3693 @param[in] Prompt String ID for Prompt.
3694 @param[in] Help String ID for Help.
3695 @param[in] TextTwo String ID for TextTwo.
3697 @retval NULL There is not enough space left in Buffer to add the opcode.
3698 @retval Other A pointer to the created opcode.
3703 HiiCreateTextOpCode (
3704 IN VOID
*OpCodeHandle
,
3705 IN EFI_STRING_ID Prompt
,
3706 IN EFI_STRING_ID Help
,
3707 IN EFI_STRING_ID TextTwo
3710 EFI_IFR_TEXT OpCode
;
3712 ZeroMem (&OpCode
, sizeof (OpCode
));
3713 OpCode
.Statement
.Prompt
= Prompt
;
3714 OpCode
.Statement
.Help
= Help
;
3715 OpCode
.TextTwo
= TextTwo
;
3717 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TEXT_OP
, sizeof (OpCode
));
3721 Create EFI_IFR_DATE_OP opcode.
3723 If OpCodeHandle is NULL, then ASSERT().
3724 If any reserved bits are set in QuestionFlags, then ASSERT().
3725 If any reserved bits are set in DateFlags, then ASSERT().
3727 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3728 @param[in] QuestionId Question ID
3729 @param[in] VarStoreId Storage ID, optional. If DateFlags is not
3730 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3731 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3732 for this name/value pair, optional. If DateFlags is not
3733 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3734 @param[in] Prompt String ID for Prompt
3735 @param[in] Help String ID for Help
3736 @param[in] QuestionFlags Flags in Question Header
3737 @param[in] DateFlags Flags for date opcode
3738 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3739 is an optional parameter that may be NULL.
3741 @retval NULL There is not enough space left in Buffer to add the opcode.
3742 @retval Other A pointer to the created opcode.
3747 HiiCreateDateOpCode (
3748 IN VOID
*OpCodeHandle
,
3749 IN EFI_QUESTION_ID QuestionId
,
3750 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3751 IN UINT16 VarOffset
, OPTIONAL
3752 IN EFI_STRING_ID Prompt
,
3753 IN EFI_STRING_ID Help
,
3754 IN UINT8 QuestionFlags
,
3756 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3759 EFI_IFR_DATE OpCode
;
3762 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3763 ASSERT ((DateFlags
& (~(EFI_QF_DATE_YEAR_SUPPRESS
| EFI_QF_DATE_MONTH_SUPPRESS
| EFI_QF_DATE_DAY_SUPPRESS
| EFI_QF_DATE_STORAGE
))) == 0);
3765 ZeroMem (&OpCode
, sizeof (OpCode
));
3766 OpCode
.Question
.Header
.Prompt
= Prompt
;
3767 OpCode
.Question
.Header
.Help
= Help
;
3768 OpCode
.Question
.QuestionId
= QuestionId
;
3769 OpCode
.Question
.VarStoreId
= VarStoreId
;
3770 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3771 OpCode
.Question
.Flags
= QuestionFlags
;
3772 OpCode
.Flags
= DateFlags
;
3774 if (DefaultsOpCodeHandle
== NULL
) {
3775 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
));
3778 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3779 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
), 0, 1);
3780 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3781 HiiCreateEndOpCode (OpCodeHandle
);
3782 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3786 Create EFI_IFR_TIME_OP opcode.
3788 If OpCodeHandle is NULL, then ASSERT().
3789 If any reserved bits are set in QuestionFlags, then ASSERT().
3790 If any reserved bits are set in TimeFlags, then ASSERT().
3792 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3793 @param[in] QuestionId Question ID
3794 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not
3795 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3796 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3797 for this name/value pair, optional. If TimeFlags is not
3798 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3799 @param[in] Prompt String ID for Prompt
3800 @param[in] Help String ID for Help
3801 @param[in] QuestionFlags Flags in Question Header
3802 @param[in] TimeFlags Flags for time opcode
3803 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3804 is an optional parameter that may be NULL.
3806 @retval NULL There is not enough space left in Buffer to add the opcode.
3807 @retval Other A pointer to the created opcode.
3812 HiiCreateTimeOpCode (
3813 IN VOID
*OpCodeHandle
,
3814 IN EFI_QUESTION_ID QuestionId
,
3815 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3816 IN UINT16 VarOffset
, OPTIONAL
3817 IN EFI_STRING_ID Prompt
,
3818 IN EFI_STRING_ID Help
,
3819 IN UINT8 QuestionFlags
,
3821 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3824 EFI_IFR_TIME OpCode
;
3827 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3828 ASSERT ((TimeFlags
& (~(QF_TIME_HOUR_SUPPRESS
| QF_TIME_MINUTE_SUPPRESS
| QF_TIME_SECOND_SUPPRESS
| QF_TIME_STORAGE
))) == 0);
3830 ZeroMem (&OpCode
, sizeof (OpCode
));
3831 OpCode
.Question
.Header
.Prompt
= Prompt
;
3832 OpCode
.Question
.Header
.Help
= Help
;
3833 OpCode
.Question
.QuestionId
= QuestionId
;
3834 OpCode
.Question
.VarStoreId
= VarStoreId
;
3835 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3836 OpCode
.Question
.Flags
= QuestionFlags
;
3837 OpCode
.Flags
= TimeFlags
;
3839 if (DefaultsOpCodeHandle
== NULL
) {
3840 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
));
3843 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3844 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
), 0, 1);
3845 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3846 HiiCreateEndOpCode (OpCodeHandle
);
3847 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3851 This is the internal worker function to update the data in
3852 a form specified by FormSetGuid, FormId and Label.
3854 @param[in] FormSetGuid The optional Formset GUID.
3855 @param[in] FormId The Form ID.
3856 @param[in] Package The package header.
3857 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR
3858 opcodes to be inserted or replaced in the form.
3859 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode
3860 that marks the end of a replace operation in the form.
3861 @param[out] TempPackage The resultant package.
3863 @retval EFI_SUCCESS The function completes successfully.
3864 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.
3869 InternalHiiUpdateFormPackageData (
3870 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3871 IN EFI_FORM_ID FormId
,
3872 IN EFI_HII_PACKAGE_HEADER
*Package
,
3873 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3874 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3875 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3880 EFI_HII_PACKAGE_HEADER PackageHeader
;
3882 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3883 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3887 UINTN UpdatePackageLength
;
3889 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3890 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3891 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3893 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3894 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3895 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3896 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3900 while (Offset
< PackageHeader
.Length
) {
3901 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3902 BufferPos
+= IfrOpHdr
->Length
;
3903 UpdatePackageLength
+= IfrOpHdr
->Length
;
3906 // Find the matched FormSet and Form
3908 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3909 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3914 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
|| IfrOpHdr
->OpCode
== EFI_IFR_FORM_MAP_OP
) {
3915 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3923 // The matched Form is found, and Update data in this form
3925 if (GetFormSet
&& GetForm
) {
3926 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3927 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3928 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3930 // Remove the original data when End OpCode buffer exist.
3932 if (OpCodeBufferEnd
!= NULL
) {
3933 Offset
+= IfrOpHdr
->Length
;
3934 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3935 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3936 while (Offset
< PackageHeader
.Length
) {
3938 // Search the matched end opcode
3940 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3941 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3945 // Go to the next Op-Code
3947 Offset
+= IfrOpHdr
->Length
;
3948 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3951 if (Offset
>= PackageHeader
.Length
) {
3953 // The end opcode is not found.
3955 return EFI_NOT_FOUND
;
3960 // Insert the updated data
3962 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3963 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3964 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3965 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3967 if (OpCodeBufferEnd
!= NULL
) {
3969 // Add the end opcode
3971 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3972 BufferPos
+= IfrOpHdr
->Length
;
3973 UpdatePackageLength
+= IfrOpHdr
->Length
;
3977 // Copy the left package data.
3979 Offset
+= IfrOpHdr
->Length
;
3980 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3981 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3992 // Go to the next Op-Code
3994 Offset
+= IfrOpHdr
->Length
;
3995 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
4000 // The updated opcode buffer is not found.
4002 return EFI_NOT_FOUND
;
4005 // Update the package length.
4007 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
4008 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
4014 This function updates a form that has previously been registered with the HII
4015 Database. This function will perform at most one update operation.
4017 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
4018 comparisons of IFR opcodes are performed from the beginning of the form being
4019 updated until an IFR opcode is found that exactly matches the first IFR opcode
4020 specified by StartOpCodeHandle. The following rules are used to determine if
4021 an insert, replace, or delete operation is performed.
4023 1) If no matches are found, then NULL is returned.
4024 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
4025 from StartOpCodeHandle except the first opcode are inserted immediately after
4026 the matching IFR opcode in the form to be updated.
4027 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
4028 from the matching IFR opcode until an IFR opcode exactly matches the first
4029 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
4030 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
4031 is found, then all of the IFR opcodes between the start match and the end
4032 match are deleted from the form being updated and all of the IFR opcodes
4033 from StartOpCodeHandle except the first opcode are inserted immediately after
4034 the matching start IFR opcode. If StartOpCcodeHandle only contains one
4035 IFR instruction, then the result of this operation will delete all of the IFR
4036 opcodes between the start end matches.
4038 If HiiHandle is NULL, then ASSERT().
4039 If StartOpCodeHandle is NULL, then ASSERT().
4041 @param[in] HiiHandle The HII Handle of the form to update.
4042 @param[in] FormSetGuid The Formset GUID of the form to update. This
4043 is an optional parameter that may be NULL.
4044 If it is NULL, all FormSet will be updated.
4045 @param[in] FormId The ID of the form to update.
4046 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
4047 opcodes to be inserted or replaced in the form.
4048 The first IFR instruction in StartOpCodeHandle
4049 is used to find matching IFR opcode in the
4051 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
4052 that marks the end of a replace operation in
4053 the form. This is an optional parameter that
4054 may be NULL. If it is NULL, then an the IFR
4055 opcodes specified by StartOpCodeHandle are
4056 inserted into the form.
4058 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
4059 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
4060 1) The form specified by HiiHandle, FormSetGuid,
4061 and FormId could not be found in the HII Database.
4062 2) No IFR opcodes in the target form match the first
4063 IFR opcode in StartOpCodeHandle.
4064 3) EndOpCOde is not NULL, and no IFR opcodes in the
4065 target form following a matching start opcode match
4066 the first IFR opcode in EndOpCodeHandle.
4067 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
4073 IN EFI_HII_HANDLE HiiHandle
,
4074 IN EFI_GUID
*FormSetGuid
, OPTIONAL
4075 IN EFI_FORM_ID FormId
,
4076 IN VOID
*StartOpCodeHandle
,
4077 IN VOID
*EndOpCodeHandle OPTIONAL
4081 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
4082 UINT32 PackageListLength
;
4084 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
4086 UINT8
*UpdateBufferPos
;
4087 EFI_HII_PACKAGE_HEADER
*Package
;
4088 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
4089 EFI_HII_PACKAGE_HEADER PackageHeader
;
4091 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
4092 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
4095 // Input update data can't be NULL.
4097 ASSERT (HiiHandle
!= NULL
);
4098 ASSERT (StartOpCodeHandle
!= NULL
);
4099 UpdatePackageList
= NULL
;
4101 HiiPackageList
= NULL
;
4104 // Retrieve buffer data from Opcode Handle
4106 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpCodeHandle
;
4107 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpCodeHandle
;
4110 // Get the original package list
4113 HiiPackageList
= NULL
;
4114 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
4116 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
4118 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4122 HiiPackageList
= AllocatePool (BufferSize
);
4123 if (HiiPackageList
== NULL
) {
4124 Status
= EFI_OUT_OF_RESOURCES
;
4128 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
4129 if (EFI_ERROR (Status
)) {
4134 // Calculate and allocate space for retrieval of IFR data
4136 BufferSize
+= OpCodeBufferStart
->Position
;
4137 UpdatePackageList
= AllocateZeroPool (BufferSize
);
4138 if (UpdatePackageList
== NULL
) {
4139 Status
= EFI_OUT_OF_RESOURCES
;
4144 // Allocate temp buffer to store the temp updated package buffer
4146 TempPacakge
= AllocateZeroPool (BufferSize
);
4147 if (TempPacakge
== NULL
) {
4148 Status
= EFI_OUT_OF_RESOURCES
;
4152 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
4155 // Copy the package list header
4157 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
4158 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4161 // Go through each package to find the matched package and update one by one
4164 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4165 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
4166 while (Offset
< PackageListLength
) {
4167 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
4168 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4169 Offset
+= Package
->Length
;
4171 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
4173 // Check this package is the matched package.
4175 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
4177 // The matched package is found. Its package buffer will be updated by the input new data.
4179 if (!EFI_ERROR(Status
)) {
4185 // Add updated package buffer
4187 Package
= TempPacakge
;
4192 // Add pacakge buffer
4194 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4195 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
4196 UpdateBufferPos
+= PackageHeader
.Length
;
4201 // Update package list length
4203 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
4204 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
4207 // Update Package to show form
4209 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
4212 // Not matched form is found and updated.
4214 Status
= EFI_NOT_FOUND
;
4218 if (HiiPackageList
!= NULL
) {
4219 FreePool (HiiPackageList
);
4222 if (UpdatePackageList
!= NULL
) {
4223 FreePool (UpdatePackageList
);
4226 if (TempPacakge
!= NULL
) {
4227 FreePool (TempPacakge
);