2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalHiiLib.h"
17 #define GUID_CONFIG_STRING_TYPE 0x00
18 #define NAME_CONFIG_STRING_TYPE 0x01
19 #define PATH_CONFIG_STRING_TYPE 0x02
21 #define ACTION_SET_DEFAUTL_VALUE 0x01
22 #define ACTION_VALIDATE_SETTING 0x02
24 #define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200
27 LIST_ENTRY Entry
; // Link to Block array
35 // <ConfigHdr> Template
37 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
39 EFI_FORM_BROWSER2_PROTOCOL
*mUefiFormBrowser2
= NULL
;
42 // Template used to mark the end of a list of packages
44 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList
= {
45 sizeof (EFI_HII_PACKAGE_HEADER
),
50 Extract Hii package list GUID for given HII handle.
52 If HiiHandle could not be found in the HII database, then ASSERT.
53 If Guid is NULL, then ASSERT.
55 @param Handle Hii handle
56 @param Guid Package list GUID
58 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
63 InternalHiiExtractGuidFromHiiHandle (
64 IN EFI_HII_HANDLE Handle
,
70 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
72 ASSERT (Guid
!= NULL
);
73 ASSERT (Handle
!= NULL
);
76 // Get HII PackageList
79 HiiPackageList
= NULL
;
81 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
82 ASSERT (Status
!= EFI_NOT_FOUND
);
84 if (Status
== EFI_BUFFER_TOO_SMALL
) {
85 HiiPackageList
= AllocatePool (BufferSize
);
86 ASSERT (HiiPackageList
!= NULL
);
88 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
90 if (EFI_ERROR (Status
)) {
91 FreePool (HiiPackageList
);
98 CopyGuid (Guid
, &HiiPackageList
->PackageListGuid
);
100 FreePool (HiiPackageList
);
106 Registers a list of packages in the HII Database and returns the HII Handle
107 associated with that registration. If an HII Handle has already been registered
108 with the same PackageListGuid, then NULL is returned. If there are not enough
109 resources to perform the registration, then NULL is returned. If an empty list
110 of packages is passed in, then NULL is returned. If the size of the list of
111 package is 0, then NULL is returned.
113 The variable arguments are pointers which point to package header that defined
114 by UEFI VFR compiler and StringGather tool.
116 #pragma pack (push, 1)
119 EFI_HII_PACKAGE_HEADER PackageHeader;
120 } EDKII_AUTOGEN_PACKAGES_HEADER;
123 @param[in] PackageListGuid The GUID of the package list.
124 @param[in] DeviceHandle If not NULL, the Device Handle on which
125 an instance of DEVICE_PATH_PROTOCOL is installed.
126 This Device Handle uniquely defines the device that
127 the added packages are associated with.
128 @param[in] ... The variable argument list that contains pointers
129 to packages terminated by a NULL.
131 @retval NULL A HII Handle has already been registered in the HII Database with
132 the same PackageListGuid.
133 @retval NULL The HII Handle could not be created.
134 @retval NULL An empty list of packages was passed in.
135 @retval NULL All packages are empty.
136 @retval Other The HII Handle associated with the newly registered package list.
142 IN CONST EFI_GUID
*PackageListGuid
,
143 IN EFI_HANDLE DeviceHandle OPTIONAL
,
148 EFI_HII_HANDLE
*HiiHandleBuffer
;
151 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
152 EFI_HII_HANDLE HiiHandle
;
156 ASSERT (PackageListGuid
!= NULL
);
159 // Check to see if an HII Handle has already been registered with the same
162 HiiHandleBuffer
= HiiGetHiiHandles (PackageListGuid
);
163 if (HiiHandleBuffer
!= NULL
) {
164 FreePool (HiiHandleBuffer
);
169 // Calculate the length of all the packages in the variable argument list
171 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
172 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
177 // If there are no packages in the variable argument list or all the packages
178 // are empty, then return a NULL HII Handle
185 // Add the length of the Package List Header and the terminating Package Header
187 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
190 // Allocate the storage for the entire Package List
192 PackageListHeader
= AllocateZeroPool (Length
);
195 // If the Packahge List can not be allocated, then return a NULL HII Handle
197 if (PackageListHeader
== NULL
) {
202 // Fill in the GUID and Length of the Package List Header
204 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
205 PackageListHeader
->PackageLength
= Length
;
208 // Initialize a pointer to the beginning if the Package List data
210 Data
= (UINT8
*)(PackageListHeader
+ 1);
213 // Copy the data from each package in the variable argument list
215 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
216 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
217 CopyMem (Data
, Package
+ 1, Length
);
223 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
225 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
228 // Register the package list with the HII Database
230 Status
= gHiiDatabase
->NewPackageList (
236 if (EFI_ERROR (Status
)) {
241 // Free the allocated package list
243 FreePool (PackageListHeader
);
246 // Return the new HII Handle
252 Removes a package list from the HII database.
254 If HiiHandle is NULL, then ASSERT.
255 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
257 @param[in] HiiHandle The handle that was previously registered in the HII database
263 IN EFI_HII_HANDLE HiiHandle
268 ASSERT (HiiHandle
!= NULL
);
269 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
270 ASSERT_EFI_ERROR (Status
);
275 Retrieves the array of all the HII Handles or the HII handle of a specific
276 package list in the HII Database.
277 This array is terminated with a NULL HII Handle.
278 This function allocates the returned array using AllocatePool().
279 The caller is responsible for freeing the array with FreePool().
281 @param[in] PackageListGuid An optional parameter that is used to request
282 an HII Handle that is associatd with a specific
283 Package List GUID. If this parameter is NULL
284 then all the HII Handles in the HII Database
285 are returned. If this parameter is not NULL
286 then at most 1 HII Handle is returned.
288 @retval NULL No HII handles were found in the HII database
289 @retval NULL The array of HII Handles could not be retrieved
290 @retval Other A pointer to the NULL terminated array of HII Handles
296 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
300 UINTN HandleBufferLength
;
301 EFI_HII_HANDLE TempHiiHandleBuffer
;
302 EFI_HII_HANDLE
*HiiHandleBuffer
;
307 // Retrieve the size required for the buffer of all HII handles.
309 HandleBufferLength
= 0;
310 Status
= gHiiDatabase
->ListPackageLists (
312 EFI_HII_PACKAGE_TYPE_ALL
,
319 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
320 // then there are no HII handles in the HII database. If ListPackageLists()
321 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
322 // handles in the HII database.
324 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
326 // Return NULL if the size can not be retrieved, or if there are no HII
327 // handles in the HII Database
333 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
335 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
336 if (HiiHandleBuffer
== NULL
) {
338 // Return NULL if allocation fails.
344 // Retrieve the array of HII Handles in the HII Database
346 Status
= gHiiDatabase
->ListPackageLists (
348 EFI_HII_PACKAGE_TYPE_ALL
,
353 if (EFI_ERROR (Status
)) {
355 // Free the buffer and return NULL if the HII handles can not be retrieved.
357 FreePool (HiiHandleBuffer
);
361 if (PackageListGuid
== NULL
) {
363 // Return the NULL terminated array of HII handles in the HII Database
365 return HiiHandleBuffer
;
367 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
368 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index
], &Guid
);
369 ASSERT_EFI_ERROR (Status
);
370 if (CompareGuid (&Guid
, PackageListGuid
)) {
371 HiiHandleBuffer
[0] = HiiHandleBuffer
[Index
];
372 HiiHandleBuffer
[1] = NULL
;
373 return HiiHandleBuffer
;
376 FreePool (HiiHandleBuffer
);
382 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
383 hex digits that appear between a '=' and a '&' in a config string.
385 If String is NULL, then ASSERT().
387 @param[in] String Pointer to a Null-terminated Unicode string.
389 @return Pointer to the Null-terminated Unicode result string.
394 InternalHiiLowerConfigString (
395 IN EFI_STRING ConfigString
401 ASSERT (ConfigString
!= NULL
);
404 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
406 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
407 if (*String
== L
'=') {
409 } else if (*String
== L
'&') {
411 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
412 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
420 Uses the BlockToConfig() service of the Config Routing Protocol to
421 convert <ConfigRequest> and a buffer to a <ConfigResp>
423 If ConfigRequest is NULL, then ASSERT().
424 If Block is NULL, then ASSERT().
426 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
427 @param[in] Block Pointer to a block of data.
428 @param[in] BlockSize The zie, in bytes, of Block.
430 @retval NULL The <ConfigResp> string could not be generated.
431 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
436 InternalHiiBlockToConfig (
437 IN CONST EFI_STRING ConfigRequest
,
438 IN CONST UINT8
*Block
,
443 EFI_STRING ConfigResp
;
446 ASSERT (ConfigRequest
!= NULL
);
447 ASSERT (Block
!= NULL
);
450 // Convert <ConfigRequest> to <ConfigResp>
452 Status
= gHiiConfigRouting
->BlockToConfig (
460 if (EFI_ERROR (Status
)) {
467 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
468 or set uncommitted data. If sata i being retrieved, then the buffer is
469 allocated using AllocatePool(). The caller is then responsible for freeing
470 the buffer using FreePool().
472 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
473 is an optional parameter that may be NULL.
474 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
475 parameter that may be NULL.
476 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
477 of uncommited data to set. If this parameter is NULL,
478 then the caller is requesting to get the uncommited data
479 from the Form Browser.
481 @retval NULL The uncommitted data could not be retrieved.
482 @retval Other A pointer to a buffer containing the uncommitted data.
487 InternalHiiBrowserCallback (
488 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
489 IN CONST CHAR16
*VariableName
, OPTIONAL
490 IN CONST EFI_STRING SetResultsData OPTIONAL
494 UINTN ResultsDataSize
;
495 EFI_STRING ResultsData
;
496 CHAR16 TempResultsData
;
501 if (mUefiFormBrowser2
== NULL
) {
502 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
503 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
510 if (SetResultsData
!= NULL
) {
512 // Request to to set data in the uncommitted browser state information
514 ResultsData
= SetResultsData
;
517 // Retrieve the length of the buffer required ResultsData from the Browser Callback
519 Status
= mUefiFormBrowser2
->BrowserCallback (
528 if (!EFI_ERROR (Status
)) {
530 // No Resluts Data, only allocate one char for '\0'
532 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
536 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
541 // Allocate the ResultsData buffer
543 ResultsData
= AllocateZeroPool (ResultsDataSize
);
544 if (ResultsData
== NULL
) {
550 // Retrieve or set the ResultsData from the Browser Callback
552 Status
= mUefiFormBrowser2
->BrowserCallback (
556 (BOOLEAN
)(SetResultsData
== NULL
),
560 if (EFI_ERROR (Status
)) {
568 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
569 information that includes a GUID, an optional Unicode string name, and a device
570 path. The string returned is allocated with AllocatePool(). The caller is
571 responsible for freeing the allocated string with FreePool().
573 The format of a <ConfigHdr> is as follows:
575 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
577 @param[in] Guid Pointer to an EFI_GUID that is the routing information
578 GUID. Each of the 16 bytes in Guid is converted to
579 a 2 Unicode character hexidecimal string. This is
580 an optional parameter that may be NULL.
581 @param[in] Name Pointer to a Null-terminated Unicode string that is
582 the routing information NAME. This is an optional
583 parameter that may be NULL. Each 16-bit Unicode
584 character in Name is converted to a 4 character Unicode
586 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
587 that is the routing information PATH. Each byte of
588 the Device Path associated with DriverHandle is converted
589 to a 2 Unicode character hexidecimal string.
591 @retval NULL DriverHandle does not support the Device Path Protocol.
592 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
597 HiiConstructConfigHdr (
598 IN CONST EFI_GUID
*Guid
, OPTIONAL
599 IN CONST CHAR16
*Name
, OPTIONAL
600 IN EFI_HANDLE DriverHandle
604 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
605 UINTN DevicePathSize
;
607 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 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
641 if (String
== NULL
) {
646 // Start with L"GUID="
648 ReturnString
= StrCpy (String
, L
"GUID=");
649 String
+= StrLen (String
);
653 // Append Guid converted to <HexCh>32
655 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
656 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
663 StrCpy (String
, L
"&NAME=");
664 String
+= StrLen (String
);
668 // Append Name converted to <Char>NameLength
670 for (; *Name
!= L
'\0'; Name
++) {
671 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
678 StrCpy (String
, L
"&PATH=");
679 String
+= StrLen (String
);
682 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
684 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
685 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
689 // Null terminate the Unicode string
694 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
696 return InternalHiiLowerConfigString (ReturnString
);
700 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
701 to binary buffer from <ConfigHdr>.
703 This is a internal function.
705 @param String UEFI configuration string.
706 @param Flag Flag specifies what type buffer will be retrieved.
707 @param Buffer Binary of Guid, Name or Device path.
709 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
710 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
711 @retval EFI_SUCCESS The buffer data is retrieved and translated to
716 InternalHiiGetBufferFromString (
717 IN EFI_STRING String
,
723 EFI_STRING ConfigHdr
;
730 if (String
== NULL
|| Buffer
== NULL
) {
731 return EFI_INVALID_PARAMETER
;
738 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
739 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
741 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
744 case GUID_CONFIG_STRING_TYPE
:
745 case PATH_CONFIG_STRING_TYPE
:
747 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
748 // as the device path and Guid resides in RAM memory.
749 // Translate the data into binary.
751 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
752 if (DataBuffer
== NULL
) {
753 return EFI_OUT_OF_RESOURCES
;
756 // Convert binary byte one by one
758 ZeroMem (TemStr
, sizeof (TemStr
));
759 for (Index
= 0; Index
< Length
; Index
++) {
760 TemStr
[0] = ConfigHdr
[Index
];
761 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
762 if ((Index
& 1) == 0) {
763 DataBuffer
[Index
/2] = DigitUint8
;
765 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
769 *Buffer
= DataBuffer
;
772 case NAME_CONFIG_STRING_TYPE
:
774 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
778 // Add the tailling char L'\0'
780 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
781 if (DataBuffer
== NULL
) {
782 return EFI_OUT_OF_RESOURCES
;
785 // Convert character one by one
787 StringPtr
= (CHAR16
*) DataBuffer
;
788 ZeroMem (TemStr
, sizeof (TemStr
));
789 for (Index
= 0; Index
< Length
; Index
+= 4) {
790 StrnCpy (TemStr
, ConfigHdr
+ Index
, 4);
791 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
794 // Add tailing L'\0' character
796 StringPtr
[Index
/4] = L
'\0';
798 *Buffer
= DataBuffer
;
802 return EFI_INVALID_PARAMETER
;
810 This function checks VarOffset and VarWidth is in the block range.
812 @param BlockArray The block array is to be checked.
813 @param VarOffset Offset of var to the structure
814 @param VarWidth Width of var.
816 @retval TRUE This Var is in the block range.
817 @retval FALSE This Var is not in the block range.
821 IN IFR_BLOCK_DATA
*BlockArray
,
827 IFR_BLOCK_DATA
*BlockData
;
830 // No Request Block array, all vars are got.
832 if (BlockArray
== NULL
) {
837 // Check the input var is in the request block range.
839 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
840 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
841 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
850 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
852 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
854 @param ValueString String in <BlockConfig> format and points to the
855 first character of <Number>.
856 @param ValueData The output value. Caller takes the responsibility
858 @param ValueLength Length of the <Number>, in characters.
860 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
862 @retval EFI_SUCCESS Value of <Number> is outputted in Number
868 InternalHiiGetValueOfNumber (
869 IN EFI_STRING ValueString
,
870 OUT UINT8
**ValueData
,
871 OUT UINTN
*ValueLength
874 EFI_STRING StringPtr
;
881 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
882 ASSERT (*ValueString
!= L
'\0');
885 // Get the length of value string
887 StringPtr
= ValueString
;
888 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
891 Length
= StringPtr
- ValueString
;
894 // Allocate buffer to store the value
896 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
898 return EFI_OUT_OF_RESOURCES
;
902 // Convert character one by one to the value buffer
904 ZeroMem (TemStr
, sizeof (TemStr
));
905 for (Index
= 0; Index
< Length
; Index
++) {
906 TemStr
[0] = ValueString
[Length
- Index
- 1];
907 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
908 if ((Index
& 1) == 0) {
909 Buf
[Index
/2] = DigitUint8
;
911 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
916 // Set the converted value and string length.
919 *ValueLength
= Length
;
924 This internal function parses IFR data to validate current setting.
926 @param ConfigResp ConfigResp string contains the current setting.
927 @param HiiPackageList Point to Hii package list.
928 @param PackageListLength The length of the pacakge.
929 @param VarGuid Guid of the buffer storage.
930 @param VarName Name of the buffer storage.
932 @retval EFI_SUCCESS The current setting is valid.
933 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
934 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
938 InternalHiiValidateCurrentSetting (
939 IN EFI_STRING ConfigResp
,
940 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
941 IN UINTN PackageListLength
,
942 IN EFI_GUID
*VarGuid
,
946 IFR_BLOCK_DATA
*CurrentBlockArray
;
947 IFR_BLOCK_DATA
*BlockData
;
948 IFR_BLOCK_DATA
*NewBlockData
;
949 IFR_BLOCK_DATA VarBlockData
;
950 EFI_STRING StringPtr
;
960 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
961 UINT32 PackageOffset
;
964 EFI_IFR_OP_HEADER
*IfrOpHdr
;
965 EFI_IFR_VARSTORE
*IfrVarStore
;
966 EFI_IFR_ONE_OF
*IfrOneOf
;
967 EFI_IFR_NUMERIC
*IfrNumeric
;
968 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
969 EFI_IFR_CHECKBOX
*IfrCheckBox
;
970 EFI_IFR_STRING
*IfrString
;
975 // 1. Get the current setting to current block data array and Convert them into VarBuffer
979 // Skip ConfigHdr string
981 StringPtr
= ConfigResp
;
982 StringPtr
= StrStr (ConfigResp
, L
"&OFFSET");
983 if (StringPtr
== NULL
) {
985 // No ConfigBlock value is requied to be validated.
986 // EFI_SUCCESS directly return.
992 // Initialize the local variables.
996 Status
= EFI_SUCCESS
;
1000 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
1001 VarBuffer
= AllocateZeroPool (MaxBufferSize
);
1002 if (VarBuffer
== NULL
) {
1003 return EFI_OUT_OF_RESOURCES
;
1007 // Init CurrentBlockArray
1009 CurrentBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1010 if (CurrentBlockArray
== NULL
) {
1011 Status
= EFI_OUT_OF_RESOURCES
;
1014 InitializeListHead (&CurrentBlockArray
->Entry
);
1017 // Parse each <RequestElement> if exists
1018 // Only <BlockName> format is supported by this help function.
1019 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1021 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1023 // Skip the &OFFSET= string
1025 StringPtr
+= StrLen (L
"&OFFSET=");
1030 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1031 if (EFI_ERROR (Status
)) {
1038 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1040 FreePool (TmpBuffer
);
1043 StringPtr
+= Length
;
1044 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1045 Status
= EFI_INVALID_PARAMETER
;
1048 StringPtr
+= StrLen (L
"&WIDTH=");
1053 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1054 if (EFI_ERROR (Status
)) {
1061 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1063 FreePool (TmpBuffer
);
1066 StringPtr
+= Length
;
1067 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1068 Status
= EFI_INVALID_PARAMETER
;
1072 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1073 Status
= EFI_INVALID_PARAMETER
;
1076 StringPtr
+= StrLen (L
"&VALUE=");
1081 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1082 if (EFI_ERROR (Status
)) {
1086 StringPtr
+= Length
;
1087 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1088 Status
= EFI_INVALID_PARAMETER
;
1093 // Check whether VarBuffer is enough
1095 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1096 VarBuffer
= ReallocatePool (
1098 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1101 if (VarBuffer
== NULL
) {
1102 Status
= EFI_OUT_OF_RESOURCES
;
1105 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1109 // Update the Block with configuration info
1111 CopyMem (VarBuffer
+ Offset
, TmpBuffer
, Width
);
1112 FreePool (TmpBuffer
);
1116 // Set new Block Data
1118 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1119 if (NewBlockData
== NULL
) {
1120 Status
= EFI_OUT_OF_RESOURCES
;
1123 NewBlockData
->Offset
= Offset
;
1124 NewBlockData
->Width
= Width
;
1127 // Insert the new block data into the block data array.
1129 for (Link
= CurrentBlockArray
->Entry
.ForwardLink
; Link
!= &CurrentBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1130 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1131 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1132 if (NewBlockData
->Width
> BlockData
->Width
) {
1133 BlockData
->Width
= NewBlockData
->Width
;
1135 FreePool (NewBlockData
);
1137 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1139 // Insert new block data as the previous one of this link.
1141 InsertTailList (Link
, &NewBlockData
->Entry
);
1147 // Insert new block data into the array tail.
1149 if (Link
== &CurrentBlockArray
->Entry
) {
1150 InsertTailList (Link
, &NewBlockData
->Entry
);
1154 // If '\0', parsing is finished.
1156 if (*StringPtr
== 0) {
1160 // Go to next ConfigBlock
1165 // Merge the aligned block data into the single block data.
1167 Link
= CurrentBlockArray
->Entry
.ForwardLink
;
1168 while ((Link
!= &CurrentBlockArray
->Entry
) && (Link
->ForwardLink
!= &CurrentBlockArray
->Entry
)) {
1169 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1170 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1171 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1172 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1173 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1175 RemoveEntryList (Link
->ForwardLink
);
1176 FreePool (NewBlockData
);
1179 Link
= Link
->ForwardLink
;
1182 if (IsListEmpty (&CurrentBlockArray
->Entry
)) {
1183 Status
= EFI_SUCCESS
;
1188 // 2. Check IFR value is in block data, then Validate Vaule
1190 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1193 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1194 while (PackageOffset
< PackageListLength
) {
1195 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1198 // Parse IFR opcode from the form package.
1200 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1201 IfrOffset
= sizeof (PacakgeHeader
);
1202 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1203 while (IfrOffset
< PacakgeHeader
.Length
) {
1204 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1206 // Validate current setting to the value built in IFR opcode
1208 switch (IfrOpHdr
->OpCode
) {
1209 case EFI_IFR_VARSTORE_OP
:
1211 // VarStoreId has been found. No further found.
1213 if (IfrVarStore
!= NULL
) {
1217 // Find the matched VarStoreId to the input VarGuid and VarName
1219 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1220 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1221 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1222 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1223 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1228 // The matched VarStore is found.
1230 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1237 case EFI_IFR_FORM_OP
:
1239 // Check the matched VarStoreId is found.
1241 if (IfrVarStore
== NULL
) {
1242 Status
= EFI_SUCCESS
;
1246 case EFI_IFR_ONE_OF_OP
:
1248 // Check whether current value is the one of option.
1252 // OneOf question is not in IFR Form. This IFR form is not valid.
1254 if (IfrVarStore
== NULL
) {
1255 Status
= EFI_INVALID_PARAMETER
;
1259 // Check whether this question is for the requested varstore.
1261 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1262 if (IfrOneOf
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1267 // Get Offset by Question header and Width by DataType Flags
1269 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1270 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1272 // Check whether this question is in current block array.
1274 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1276 // This question is not in the current configuration string. Skip it.
1281 // Check this var question is in the var storage
1283 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1285 // This question exceeds the var store size.
1287 Status
= EFI_INVALID_PARAMETER
;
1292 // Get the current value for oneof opcode
1295 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1297 // Set Block Data, to be checked in the following Oneof option opcode.
1299 VarBlockData
.Offset
= Offset
;
1300 VarBlockData
.Width
= Width
;
1301 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1302 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1304 case EFI_IFR_NUMERIC_OP
:
1306 // Check the current value is in the numeric range.
1310 // Numeric question is not in IFR Form. This IFR form is not valid.
1312 if (IfrVarStore
== NULL
) {
1313 Status
= EFI_INVALID_PARAMETER
;
1317 // Check whether this question is for the requested varstore.
1319 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1320 if (IfrNumeric
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1325 // Get Offset by Question header and Width by DataType Flags
1327 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1328 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1330 // Check whether this question is in current block array.
1332 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1334 // This question is not in the current configuration string. Skip it.
1339 // Check this var question is in the var storage
1341 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1343 // This question exceeds the var store size.
1345 Status
= EFI_INVALID_PARAMETER
;
1350 // Check the current value is in the numeric range.
1353 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1354 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1355 case EFI_IFR_NUMERIC_SIZE_1
:
1356 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1358 // Not in the valid range.
1360 Status
= EFI_INVALID_PARAMETER
;
1364 case EFI_IFR_NUMERIC_SIZE_2
:
1365 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1367 // Not in the valid range.
1369 Status
= EFI_INVALID_PARAMETER
;
1373 case EFI_IFR_NUMERIC_SIZE_4
:
1374 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1376 // Not in the valid range.
1378 Status
= EFI_INVALID_PARAMETER
;
1382 case EFI_IFR_NUMERIC_SIZE_8
:
1383 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1385 // Not in the valid range.
1387 Status
= EFI_INVALID_PARAMETER
;
1394 case EFI_IFR_CHECKBOX_OP
:
1396 // Check value is BOOLEAN type, only 0 and 1 is valid.
1400 // CheckBox question is not in IFR Form. This IFR form is not valid.
1402 if (IfrVarStore
== NULL
) {
1403 Status
= EFI_INVALID_PARAMETER
;
1408 // Check whether this question is for the requested varstore.
1410 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1411 if (IfrCheckBox
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1416 // Get Offset by Question header
1418 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1419 Width
= sizeof (BOOLEAN
);
1421 // Check whether this question is in current block array.
1423 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1425 // This question is not in the current configuration string. Skip it.
1430 // Check this var question is in the var storage
1432 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1434 // This question exceeds the var store size.
1436 Status
= EFI_INVALID_PARAMETER
;
1441 // Boolean type, only 1 and 0 is valid.
1443 if (*(VarBuffer
+ Offset
) > 1) {
1444 Status
= EFI_INVALID_PARAMETER
;
1449 case EFI_IFR_STRING_OP
:
1451 // Check current string length is less than maxsize
1455 // CheckBox question is not in IFR Form. This IFR form is not valid.
1457 if (IfrVarStore
== NULL
) {
1458 Status
= EFI_INVALID_PARAMETER
;
1463 // Check whether this question is for the requested varstore.
1465 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1466 if (IfrString
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1471 // Get Offset/Width by Question header and OneOf Flags
1473 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1474 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1476 // Check whether this question is in current block array.
1478 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1480 // This question is not in the current configuration string. Skip it.
1485 // Check this var question is in the var storage
1487 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1489 // This question exceeds the var store size.
1491 Status
= EFI_INVALID_PARAMETER
;
1496 // Check current string length is less than maxsize
1498 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1499 Status
= EFI_INVALID_PARAMETER
;
1503 case EFI_IFR_ONE_OF_OPTION_OP
:
1505 // Opcode Scope is zero. This one of option is not to be checked.
1507 if (VarBlockData
.Scope
== 0) {
1512 // Only check for OneOf and OrderList opcode
1514 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1515 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1517 // Check current value is the value of one of option.
1519 if (VarValue
== IfrOneOfOption
->Value
.u64
) {
1521 // The value is one of option value.
1522 // Set OpCode to Zero, don't need check again.
1524 VarBlockData
.OpCode
= 0;
1529 case EFI_IFR_END_OP
:
1531 // Decrease opcode scope for the validated opcode
1533 if (VarBlockData
.Scope
> 0) {
1534 VarBlockData
.Scope
--;
1538 // OneOf value doesn't belong to one of option value.
1540 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1541 Status
= EFI_INVALID_PARAMETER
;
1547 // Increase Scope for the validated opcode
1549 if (VarBlockData
.Scope
> 0) {
1550 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1555 // Go to the next opcode
1557 IfrOffset
+= IfrOpHdr
->Length
;
1560 // Only one form is in a package list.
1566 // Go to next package.
1568 PackageOffset
+= PacakgeHeader
.Length
;
1572 if (VarBuffer
!= NULL
) {
1573 FreePool (VarBuffer
);
1576 if (CurrentBlockArray
!= NULL
) {
1578 // Free Link Array CurrentBlockArray
1580 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1581 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1582 RemoveEntryList (&BlockData
->Entry
);
1583 FreePool (BlockData
);
1585 FreePool (CurrentBlockArray
);
1592 This function parses the input ConfigRequest string and its matched IFR code
1593 string for setting default value and validating current setting.
1595 1. For setting default action, Reset the default value specified by DefaultId
1596 to the driver configuration got by Request string.
1597 2. For validating current setting, Validate the current configuration
1598 by parsing HII form IFR opcode.
1600 NULL request string support depends on the ExportConfig interface of
1601 HiiConfigRouting protocol in UEFI specification.
1603 @param Request A null-terminated Unicode string in
1604 <MultiConfigRequest> format. It can be NULL.
1605 If it is NULL, all current configuration for the
1606 entirety of the current HII database will be validated.
1607 If it is NULL, all configuration for the
1608 entirety of the current HII database will be reset.
1609 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1610 @param ActionType Action supports setting defaults and validate current setting.
1612 @retval TURE Action runs successfully.
1613 @retval FALSE Action is not valid or Action can't be executed successfully..
1617 InternalHiiIfrValueAction (
1618 IN CONST EFI_STRING Request
, OPTIONAL
1619 IN UINT16 DefaultId
,
1623 EFI_STRING ConfigAltResp
;
1624 EFI_STRING ConfigAltHdr
;
1625 EFI_STRING ConfigResp
;
1626 EFI_STRING Progress
;
1627 EFI_STRING StringPtr
;
1628 EFI_STRING StringHdr
;
1630 EFI_HANDLE DriverHandle
;
1631 EFI_HANDLE TempDriverHandle
;
1632 EFI_HII_HANDLE
*HiiHandleBuffer
;
1633 EFI_HII_HANDLE HiiHandle
;
1637 EFI_STRING_ID DefaultName
;
1641 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1642 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1643 UINT32 PackageOffset
;
1644 UINTN PackageListLength
;
1645 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1646 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1647 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1649 ConfigAltResp
= NULL
;
1654 ConfigAltHdr
= NULL
;
1655 HiiHandleBuffer
= NULL
;
1657 TempDriverHandle
= NULL
;
1660 HiiPackageList
= NULL
;
1663 // Only support set default and validate setting action.
1665 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
1670 // Get the full requested value and deault value string.
1672 if (Request
!= NULL
) {
1673 Status
= gHiiConfigRouting
->ExtractConfig (
1680 Status
= gHiiConfigRouting
->ExportConfig (
1686 if (EFI_ERROR (Status
)) {
1690 StringPtr
= ConfigAltResp
;
1692 while (StringPtr
!= L
'\0') {
1694 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1696 StringHdr
= StringPtr
;
1701 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1702 Status
= EFI_INVALID_PARAMETER
;
1705 StringPtr
+= StrLen (L
"GUID=");
1706 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
1707 if (EFI_ERROR (Status
)) {
1712 // Get Name value VarName
1714 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1717 if (*StringPtr
== L
'\0') {
1718 Status
= EFI_INVALID_PARAMETER
;
1721 StringPtr
+= StrLen (L
"&NAME=");
1722 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
1723 if (EFI_ERROR (Status
)) {
1728 // Get Path value DevicePath
1730 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1733 if (*StringPtr
== L
'\0') {
1734 Status
= EFI_INVALID_PARAMETER
;
1737 StringPtr
+= StrLen (L
"&PATH=");
1738 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
1739 if (EFI_ERROR (Status
)) {
1744 // Get the Driver handle by the got device path.
1746 TempDevicePath
= DevicePath
;
1747 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
1748 if (EFI_ERROR (Status
)) {
1753 // Find the matched Hii Handle for the found Driver handle
1755 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
1756 if (HiiHandleBuffer
== NULL
) {
1757 Status
= EFI_NOT_FOUND
;
1761 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
1762 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
1763 if (TempDriverHandle
== DriverHandle
) {
1768 HiiHandle
= HiiHandleBuffer
[Index
];
1769 FreePool (HiiHandleBuffer
);
1771 if (HiiHandle
== NULL
) {
1773 // This request string has no its Hii package.
1774 // Its default value and validating can't execute by parsing IFR data.
1775 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
1777 Status
= EFI_SUCCESS
;
1778 goto NextConfigAltResp
;
1782 // 2. Get DefaultName string ID by parsing the PacakgeList
1786 // Get HiiPackage by HiiHandle
1788 PackageListLength
= 0;
1789 HiiPackageList
= NULL
;
1790 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1793 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1795 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1796 Status
= EFI_INVALID_PARAMETER
;
1800 HiiPackageList
= AllocatePool (PackageListLength
);
1801 if (HiiPackageList
== NULL
) {
1802 Status
= EFI_OUT_OF_RESOURCES
;
1807 // Get PackageList on HiiHandle
1809 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1810 if (EFI_ERROR (Status
)) {
1815 // Parse the form package and get the default name string ID.
1817 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1818 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1819 Status
= EFI_NOT_FOUND
;
1820 while (PackageOffset
< PackageListLength
) {
1821 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1824 // Parse IFR opcode to get default store opcode
1826 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1827 IfrOffset
= sizeof (PacakgeHeader
);
1828 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1829 while (IfrOffset
< PacakgeHeader
.Length
) {
1830 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1832 // Match DefaultId to find its DefaultName
1834 if (IfrOpHdr
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
) {
1835 if (((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
== DefaultId
) {
1836 DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
1837 Status
= EFI_SUCCESS
;
1841 IfrOffset
+= IfrOpHdr
->Length
;
1844 // Only one form is in a package list.
1850 // Go to next package.
1852 PackageOffset
+= PacakgeHeader
.Length
;
1856 // Not found the matched default string ID
1858 if (EFI_ERROR (Status
)) {
1859 Status
= EFI_SUCCESS
;
1860 goto NextConfigAltResp
;
1865 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
1866 // Get the default configuration string according to the found defaultname string ID.
1868 Status
= gHiiConfigRouting
->GetAltConfig (
1874 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultName
:NULL
, // it can be NULL to get the current setting.
1879 // The required setting can't be found. So, it is not required to be validated and set.
1881 if (EFI_ERROR (Status
)) {
1882 Status
= EFI_SUCCESS
;
1883 goto NextConfigAltResp
;
1886 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
1888 if (StrStr (ConfigResp
, L
"&OFFSET=") == NULL
) {
1889 goto NextConfigAltResp
;
1893 // 4. Set the default configuration information or Validate current setting by parse IFR code.
1894 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1896 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1898 // Set the default configuration information.
1900 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
1903 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1905 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
);
1908 if (EFI_ERROR (Status
)) {
1914 // Free the allocated pacakge buffer and the got ConfigResp string.
1916 if (HiiPackageList
!= NULL
) {
1917 FreePool (HiiPackageList
);
1918 HiiPackageList
= NULL
;
1921 if (ConfigResp
!= NULL
) {
1922 FreePool (ConfigResp
);
1927 // Free the allocated buffer.
1935 FreePool (DevicePath
);
1939 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
1943 // Get and Skip ConfigHdr
1945 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1948 if (*StringPtr
== L
'\0') {
1953 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
1954 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
1956 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
1957 if (ConfigAltHdr
== NULL
) {
1958 Status
= EFI_OUT_OF_RESOURCES
;
1961 StrCpy (ConfigAltHdr
, L
"&");
1962 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
1963 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
1966 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
1968 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
1969 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
1970 if (*StringPtr
== L
'\0') {
1976 // Free the allocated ConfigAltHdr string
1978 FreePool (ConfigAltHdr
);
1979 if (*StringPtr
== L
'\0') {
1984 // Find &GUID as the next ConfigHdr
1986 StringPtr
= StrStr (StringPtr
, L
"&GUID");
1987 if (StringPtr
== NULL
) {
1998 if (VarGuid
!= NULL
) {
2002 if (VarName
!= NULL
) {
2006 if (DevicePath
!= NULL
) {
2007 FreePool (DevicePath
);
2010 if (ConfigResp
!= NULL
) {
2011 FreePool (ConfigResp
);
2014 if (ConfigAltResp
!= NULL
) {
2015 FreePool (ConfigAltResp
);
2018 if (HiiPackageList
!= NULL
) {
2019 FreePool (HiiPackageList
);
2022 if (EFI_ERROR (Status
)) {
2030 Validate the current configuration by parsing HII form IFR opcode.
2032 NULL request string support depends on the ExportConfig interface of
2033 HiiConfigRouting protocol in UEFI specification.
2035 @param Request A null-terminated Unicode string in
2036 <MultiConfigRequest> format. It can be NULL.
2037 If it is NULL, all current configuration for the
2038 entirety of the current HII database will be validated.
2040 @retval TURE Current configuration is valid.
2041 @retval FALSE Current configuration is invalid.
2045 HiiValidateSettings (
2046 IN CONST EFI_STRING Request OPTIONAL
2049 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2053 Reset the default value specified by DefaultId to the driver
2054 configuration got by Request string.
2056 NULL request string support depends on the ExportConfig interface of
2057 HiiConfigRouting protocol in UEFI specification.
2059 @param Request A null-terminated Unicode string in
2060 <MultiConfigRequest> format. It can be NULL.
2061 If it is NULL, all configuration for the
2062 entirety of the current HII database will be reset.
2063 @param DefaultId Specifies the type of defaults to retrieve.
2065 @retval TURE The default value is set successfully.
2066 @retval FALSE The default value can't be found and set.
2071 IN CONST EFI_STRING Request
, OPTIONAL
2075 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2079 Determines if two values in config strings match.
2081 Compares the substring between StartSearchString and StopSearchString in
2082 FirstString to the substring between StartSearchString and StopSearchString
2083 in SecondString. If the two substrings match, then TRUE is returned. If the
2084 two substrings do not match, then FALSE is returned.
2086 If FirstString is NULL, then ASSERT().
2087 If SecondString is NULL, then ASSERT().
2088 If StartSearchString is NULL, then ASSERT().
2089 If StopSearchString is NULL, then ASSERT().
2091 @param FirstString Pointer to the first Null-terminated Unicode string.
2092 @param SecondString Pointer to the second Null-terminated Unicode string.
2093 @param StartSearchString Pointer to the Null-terminated Unicode string that
2094 marks the start of the value string to compare.
2095 @param StopSearchString Pointer to the Null-terminated Unicode string that
2096 marks the end of the vakue string to compare.
2098 @retval FALSE StartSearchString is not present in FirstString.
2099 @retval FALSE StartSearchString is not present in SecondString.
2100 @retval FALSE StopSearchString is not present in FirstString.
2101 @retval FALSE StopSearchString is not present in SecondString.
2102 @retval FALSE The length of the substring in FirstString is not the
2103 same length as the substring in SecondString.
2104 @retval FALSE The value string in FirstString does not matche the
2105 value string in SecondString.
2106 @retval TRUE The value string in FirstString matches the value
2107 string in SecondString.
2112 InternalHiiCompareSubString (
2113 IN CHAR16
*FirstString
,
2114 IN CHAR16
*SecondString
,
2115 IN CHAR16
*StartSearchString
,
2116 IN CHAR16
*StopSearchString
2119 CHAR16
*EndFirstString
;
2120 CHAR16
*EndSecondString
;
2122 ASSERT (FirstString
!= NULL
);
2123 ASSERT (SecondString
!= NULL
);
2124 ASSERT (StartSearchString
!= NULL
);
2125 ASSERT (StopSearchString
!= NULL
);
2127 FirstString
= StrStr (FirstString
, StartSearchString
);
2128 if (FirstString
== NULL
) {
2132 SecondString
= StrStr (SecondString
, StartSearchString
);
2133 if (SecondString
== NULL
) {
2137 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2138 if (EndFirstString
== NULL
) {
2142 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2143 if (EndSecondString
== NULL
) {
2147 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2151 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2155 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2157 If ConfigHdr is NULL, then ASSERT().
2159 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2160 @param[in] Guid GUID of the storage.
2161 @param[in] Name NAME of the storage.
2163 @retval TRUE Routing information matches <ConfigHdr>.
2164 @retval FALSE Routing information does not match <ConfigHdr>.
2169 HiiIsConfigHdrMatch (
2170 IN CONST EFI_STRING ConfigHdr
,
2171 IN CONST EFI_GUID
*Guid
, OPTIONAL
2172 IN CONST CHAR16
*Name OPTIONAL
2175 EFI_STRING CompareConfigHdr
;
2178 ASSERT (ConfigHdr
!= NULL
);
2181 // Use Guid and Name to generate a <ConfigHdr> string
2183 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2184 if (CompareConfigHdr
== NULL
) {
2191 // Compare GUID value strings
2193 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2196 if (Result
&& Name
!= NULL
) {
2198 // Compare NAME value strings
2200 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2204 // Free the <ConfigHdr> string
2206 FreePool (CompareConfigHdr
);
2212 Retrieves uncommited data from the Form Browser and converts it to a binary
2215 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2216 is an optional parameter that may be NULL.
2217 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2218 parameter that may be NULL.
2219 @param[in] BufferSize Length in bytes of buffer to hold retrived data.
2220 @param[out] Block Buffer of data to be updated.
2222 @retval FALSE The uncommitted data could not be retrieved.
2223 @retval TRUE The uncommitted data was retrieved.
2229 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2230 IN CONST CHAR16
*VariableName
, OPTIONAL
2235 EFI_STRING ResultsData
;
2237 EFI_STRING ConfigResp
;
2242 // Retrieve the results data from the Browser Callback
2244 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2245 if (ResultsData
== NULL
) {
2250 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2252 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2253 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2254 ConfigResp
= AllocateZeroPool (Size
);
2255 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2258 // Free the allocated buffer
2260 FreePool (ResultsData
);
2261 if (ConfigResp
== NULL
) {
2266 // Convert <ConfigResp> to a buffer
2268 Status
= gHiiConfigRouting
->ConfigToBlock (
2276 // Free the allocated buffer
2278 FreePool (ConfigResp
);
2280 if (EFI_ERROR (Status
)) {
2288 Updates uncommitted data in the Form Browser.
2290 If Buffer is NULL, then ASSERT().
2292 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2293 is an optional parameter that may be NULL.
2294 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2295 parameter that may be NULL.
2296 @param[in] BufferSize Length, in bytes, of Buffer.
2297 @param[in] Buffer Buffer of data to commit.
2298 @param[in] RequestElement An optional field to specify which part of the
2299 buffer data will be send back to Browser. If NULL,
2300 the whole buffer of data will be committed to
2302 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2304 @retval FALSE The uncommitted data could not be updated.
2305 @retval TRUE The uncommitted data was updated.
2311 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2312 IN CONST CHAR16
*VariableName
, OPTIONAL
2313 IN UINTN BufferSize
,
2314 IN CONST UINT8
*Buffer
,
2315 IN CONST CHAR16
*RequestElement OPTIONAL
2319 EFI_STRING ConfigRequest
;
2320 EFI_STRING ConfigResp
;
2321 EFI_STRING ResultsData
;
2323 ASSERT (Buffer
!= NULL
);
2326 // Construct <ConfigRequest>
2328 if (RequestElement
== NULL
) {
2330 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2331 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2333 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2334 ConfigRequest
= AllocateZeroPool (Size
);
2335 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2338 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2339 // followed by <RequestElement> followed by a Null-terminator
2341 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2342 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2343 ConfigRequest
= AllocateZeroPool (Size
);
2344 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2346 if (ConfigRequest
== NULL
) {
2351 // Convert <ConfigRequest> to <ConfigResp>
2353 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2354 FreePool (ConfigRequest
);
2355 if (ConfigResp
== NULL
) {
2360 // Set data in the uncommitted browser state information
2362 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2363 FreePool (ConfigResp
);
2365 return (BOOLEAN
)(ResultsData
!= NULL
);
2368 /////////////////////////////////////////
2369 /////////////////////////////////////////
2371 /////////////////////////////////////////
2372 /////////////////////////////////////////
2374 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2380 } HII_LIB_OPCODE_BUFFER
;
2383 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2385 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2386 1, // EFI_IFR_TYPE_NUM_SIZE_8
2387 2, // EFI_IFR_TYPE_NUM_SIZE_16
2388 4, // EFI_IFR_TYPE_NUM_SIZE_32
2389 8, // EFI_IFR_TYPE_NUM_SIZE_64
2390 1, // EFI_IFR_TYPE_BOOLEAN
2391 3, // EFI_IFR_TYPE_TIME
2392 4, // EFI_IFR_TYPE_DATE
2393 2 // EFI_IFR_TYPE_STRING
2397 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2398 HiiFreeOpCodeHandle().
2400 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2401 @retval Other A new OpCode handle.
2406 HiiAllocateOpCodeHandle (
2410 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2412 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2413 if (OpCodeBuffer
== NULL
) {
2416 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2417 if (OpCodeBuffer
->Buffer
== NULL
) {
2418 FreePool (OpCodeBuffer
);
2421 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2422 OpCodeBuffer
->Position
= 0;
2423 return (VOID
*)OpCodeBuffer
;
2427 Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle().
2428 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2429 Handle are also freed.
2431 If OpCodeHandle is NULL, then ASSERT().
2436 HiiFreeOpCodeHandle (
2440 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2442 ASSERT (OpCodeHandle
!= NULL
);
2444 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2445 if (OpCodeBuffer
->Buffer
!= NULL
) {
2446 FreePool (OpCodeBuffer
->Buffer
);
2448 FreePool (OpCodeBuffer
);
2453 InternalHiiOpCodeHandlePosition (
2454 IN VOID
*OpCodeHandle
2457 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2462 InternalHiiOpCodeHandleBuffer (
2463 IN VOID
*OpCodeHandle
2466 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2471 InternalHiiGrowOpCodeHandle (
2476 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2479 ASSERT (OpCodeHandle
!= NULL
);
2481 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2482 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2483 Buffer
= ReallocatePool (
2484 OpCodeBuffer
->BufferSize
,
2485 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2486 OpCodeBuffer
->Buffer
2488 if (Buffer
== NULL
) {
2491 OpCodeBuffer
->Buffer
= Buffer
;
2492 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2494 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2495 OpCodeBuffer
->Position
+= Size
;
2501 InternalHiiCreateOpCodeExtended (
2502 IN VOID
*OpCodeHandle
,
2503 IN VOID
*OpCodeTemplate
,
2505 IN UINTN OpCodeSize
,
2506 IN UINTN ExtensionSize
,
2510 EFI_IFR_OP_HEADER
*Header
;
2513 ASSERT (OpCodeTemplate
!= NULL
);
2514 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2516 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2517 Header
->OpCode
= OpCode
;
2518 Header
->Scope
= Scope
;
2519 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2520 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2521 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2526 InternalHiiCreateOpCode (
2527 IN VOID
*OpCodeHandle
,
2528 IN VOID
*OpCodeTemplate
,
2533 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2537 Append raw opcodes to an OpCodeHandle.
2539 If OpCodeHandle is NULL, then ASSERT().
2540 If RawBuffer is NULL, then ASSERT();
2542 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2543 @param[in] RawBuffer Buffer of opcodes to append.
2544 @param[in] RawBufferSize The size, in bytes, of Buffer.
2546 @retval NULL There is not enough space left in Buffer to add the opcode.
2547 @retval Other A pointer to the appended opcodes.
2552 HiiCreateRawOpCodes (
2553 IN VOID
*OpCodeHandle
,
2554 IN UINT8
*RawBuffer
,
2555 IN UINTN RawBufferSize
2560 ASSERT (RawBuffer
!= NULL
);
2562 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2563 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2567 Append opcodes from one OpCode Handle to another OpCode handle.
2569 If OpCodeHandle is NULL, then ASSERT().
2570 If RawOpCodeHandle is NULL, then ASSERT();
2572 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2573 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2575 @retval NULL There is not enough space left in Buffer to add the opcode.
2576 @retval Other A pointer to the appended opcodes.
2581 InternalHiiAppendOpCodes (
2582 IN VOID
*OpCodeHandle
,
2583 IN VOID
*RawOpCodeHandle
2586 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2588 ASSERT (RawOpCodeHandle
!= NULL
);
2590 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2591 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2595 Create EFI_IFR_END_OP opcode.
2597 If OpCodeHandle is NULL, then ASSERT().
2599 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2601 @retval NULL There is not enough space left in Buffer to add the opcode.
2602 @retval Other A pointer to the created opcode.
2607 HiiCreateEndOpCode (
2608 IN VOID
*OpCodeHandle
2613 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2617 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2619 If OpCodeHandle is NULL, then ASSERT().
2620 If Type is invalid, then ASSERT().
2621 If Flags is invalid, then ASSERT().
2623 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2624 @param[in] StringId StringId for the option
2625 @param[in] Flags Flags for the option
2626 @param[in] Type Type for the option
2627 @param[in] Value Value for the option
2629 @retval NULL There is not enough space left in Buffer to add the opcode.
2630 @retval Other A pointer to the created opcode.
2635 HiiCreateOneOfOptionOpCode (
2636 IN VOID
*OpCodeHandle
,
2643 EFI_IFR_ONE_OF_OPTION OpCode
;
2645 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2647 ZeroMem (&OpCode
, sizeof (OpCode
));
2648 OpCode
.Option
= StringId
;
2649 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2651 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2653 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, sizeof (OpCode
));
2657 Create EFI_IFR_DEFAULT_OP opcode.
2659 If OpCodeHandle is NULL, then ASSERT().
2660 If Type is invalid, then ASSERT().
2662 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2663 @param[in] DefaultId DefaultId for the default
2664 @param[in] Type Type for the default
2665 @param[in] Value Value for the default
2667 @retval NULL There is not enough space left in Buffer to add the opcode.
2668 @retval Other A pointer to the created opcode.
2673 HiiCreateDefaultOpCode (
2674 IN VOID
*OpCodeHandle
,
2675 IN UINT16 DefaultId
,
2680 EFI_IFR_DEFAULT OpCode
;
2682 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2684 ZeroMem (&OpCode
, sizeof (OpCode
));
2686 OpCode
.DefaultId
= DefaultId
;
2687 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2689 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, sizeof (OpCode
));
2693 Create EFI_IFR_GUID opcode.
2695 If OpCodeHandle is NULL, then ASSERT().
2696 If Guid is NULL, then ASSERT().
2697 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
2699 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2700 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
2701 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
2702 optional parameter that may be NULL. If this
2703 parameter is NULL, then the GUID extension
2704 region of the created opcode is filled with zeros.
2705 If this parameter is not NULL, then the GUID
2706 extension region of GuidData will be copied to
2707 the GUID extension region of the created opcode.
2708 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
2709 must be >= sizeof(EFI_IFR_GUID).
2711 @retval NULL There is not enough space left in Buffer to add the opcode.
2712 @retval Other A pointer to the created opcode.
2717 HiiCreateGuidOpCode (
2718 IN VOID
*OpCodeHandle
,
2719 IN CONST EFI_GUID
*Guid
,
2720 IN CONST VOID
*GuidOpCode
, OPTIONAL
2724 EFI_IFR_GUID OpCode
;
2725 EFI_IFR_GUID
*OpCodePointer
;
2727 ASSERT (Guid
!= NULL
);
2728 ASSERT (OpCodeSize
>= sizeof (OpCode
));
2730 ZeroMem (&OpCode
, sizeof (OpCode
));
2731 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
2733 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
2738 OpCodeSize
- sizeof (OpCode
),
2741 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
2742 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
2744 return (UINT8
*)OpCodePointer
;
2748 Create EFI_IFR_ACTION_OP opcode.
2750 If OpCodeHandle is NULL, then ASSERT().
2751 If any reserved bits are set in QuestionFlags, then ASSERT().
2753 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2754 @param[in] QuestionId Question ID
2755 @param[in] Prompt String ID for Prompt
2756 @param[in] Help String ID for Help
2757 @param[in] QuestionFlags Flags in Question Header
2758 @param[in] QuestionConfig String ID for configuration
2760 @retval NULL There is not enough space left in Buffer to add the opcode.
2761 @retval Other A pointer to the created opcode.
2766 HiiCreateActionOpCode (
2767 IN VOID
*OpCodeHandle
,
2768 IN EFI_QUESTION_ID QuestionId
,
2769 IN EFI_STRING_ID Prompt
,
2770 IN EFI_STRING_ID Help
,
2771 IN UINT8 QuestionFlags
,
2772 IN EFI_STRING_ID QuestionConfig
2775 EFI_IFR_ACTION OpCode
;
2777 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2779 ZeroMem (&OpCode
, sizeof (OpCode
));
2780 OpCode
.Question
.QuestionId
= QuestionId
;
2781 OpCode
.Question
.Header
.Prompt
= Prompt
;
2782 OpCode
.Question
.Header
.Help
= Help
;
2783 OpCode
.Question
.Flags
= QuestionFlags
;
2784 OpCode
.QuestionConfig
= QuestionConfig
;
2786 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
2790 Create EFI_IFR_SUBTITLE_OP opcode.
2792 If OpCodeHandle is NULL, then ASSERT().
2793 If any reserved bits are set in Flags, then ASSERT().
2794 If Scope > 1, then ASSERT().
2796 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2797 @param[in] Prompt String ID for Prompt
2798 @param[in] Help String ID for Help
2799 @param[in] Flags Subtitle opcode flags
2800 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
2801 0 if this opcode is within the current scope.
2803 @retval NULL There is not enough space left in Buffer to add the opcode.
2804 @retval Other A pointer to the created opcode.
2809 HiiCreateSubTitleOpCode (
2810 IN VOID
*OpCodeHandle
,
2811 IN EFI_STRING_ID Prompt
,
2812 IN EFI_STRING_ID Help
,
2817 EFI_IFR_SUBTITLE OpCode
;
2819 ASSERT (Scope
<= 1);
2820 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
2822 ZeroMem (&OpCode
, sizeof (OpCode
));
2823 OpCode
.Statement
.Prompt
= Prompt
;
2824 OpCode
.Statement
.Help
= Help
;
2825 OpCode
.Flags
= Flags
;
2827 return InternalHiiCreateOpCodeExtended (
2830 EFI_IFR_SUBTITLE_OP
,
2838 Create EFI_IFR_REF_OP opcode.
2840 If OpCodeHandle is NULL, then ASSERT().
2841 If any reserved bits are set in QuestionFlags, then ASSERT().
2843 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2844 @param[in] FormId Destination Form ID
2845 @param[in] Prompt String ID for Prompt
2846 @param[in] Help String ID for Help
2847 @param[in] QuestionFlags Flags in Question Header
2848 @param[in] QuestionId Question ID
2850 @retval NULL There is not enough space left in Buffer to add the opcode.
2851 @retval Other A pointer to the created opcode.
2856 HiiCreateGotoOpCode (
2857 IN VOID
*OpCodeHandle
,
2858 IN EFI_FORM_ID FormId
,
2859 IN EFI_STRING_ID Prompt
,
2860 IN EFI_STRING_ID Help
,
2861 IN UINT8 QuestionFlags
,
2862 IN EFI_QUESTION_ID QuestionId
2867 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2869 ZeroMem (&OpCode
, sizeof (OpCode
));
2870 OpCode
.Question
.Header
.Prompt
= Prompt
;
2871 OpCode
.Question
.Header
.Help
= Help
;
2872 OpCode
.Question
.QuestionId
= QuestionId
;
2873 OpCode
.Question
.Flags
= QuestionFlags
;
2874 OpCode
.FormId
= FormId
;
2876 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
2880 Create EFI_IFR_CHECKBOX_OP opcode.
2882 If OpCodeHandle is NULL, then ASSERT().
2883 If any reserved bits are set in QuestionFlags, then ASSERT().
2884 If any reserved bits are set in CheckBoxFlags, then ASSERT().
2886 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2887 @param[in] QuestionId Question ID
2888 @param[in] VarStoreId Storage ID
2889 @param[in] VarOffset Offset in Storage
2890 @param[in] Prompt String ID for Prompt
2891 @param[in] Help String ID for Help
2892 @param[in] QuestionFlags Flags in Question Header
2893 @param[in] CheckBoxFlags Flags for checkbox opcode
2894 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2895 is an optional parameter that may be NULL.
2897 @retval NULL There is not enough space left in Buffer to add the opcode.
2898 @retval Other A pointer to the created opcode.
2903 HiiCreateCheckBoxOpCode (
2904 IN VOID
*OpCodeHandle
,
2905 IN EFI_QUESTION_ID QuestionId
,
2906 IN EFI_VARSTORE_ID VarStoreId
,
2907 IN UINT16 VarOffset
,
2908 IN EFI_STRING_ID Prompt
,
2909 IN EFI_STRING_ID Help
,
2910 IN UINT8 QuestionFlags
,
2911 IN UINT8 CheckBoxFlags
,
2912 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2915 EFI_IFR_CHECKBOX OpCode
;
2918 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2920 ZeroMem (&OpCode
, sizeof (OpCode
));
2921 OpCode
.Question
.QuestionId
= QuestionId
;
2922 OpCode
.Question
.VarStoreId
= VarStoreId
;
2923 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2924 OpCode
.Question
.Header
.Prompt
= Prompt
;
2925 OpCode
.Question
.Header
.Help
= Help
;
2926 OpCode
.Question
.Flags
= QuestionFlags
;
2927 OpCode
.Flags
= CheckBoxFlags
;
2929 if (DefaultsOpCodeHandle
== NULL
) {
2930 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
2933 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
2934 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
2935 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
2936 HiiCreateEndOpCode (OpCodeHandle
);
2937 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
2941 Create EFI_IFR_NUMERIC_OP opcode.
2943 If OpCodeHandle is NULL, then ASSERT().
2944 If any reserved bits are set in QuestionFlags, then ASSERT().
2945 If any reserved bits are set in NumericFlags, then ASSERT().
2947 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2948 @param[in] QuestionId Question ID
2949 @param[in] VarStoreId Storage ID
2950 @param[in] VarOffset Offset in Storage
2951 @param[in] Prompt String ID for Prompt
2952 @param[in] Help String ID for Help
2953 @param[in] QuestionFlags Flags in Question Header
2954 @param[in] NumericFlags Flags for numeric opcode
2955 @param[in] Minimum Numeric minimum value
2956 @param[in] Maximum Numeric maximum value
2957 @param[in] Step Numeric step for edit
2958 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2959 is an optional parameter that may be NULL.
2961 @retval NULL There is not enough space left in Buffer to add the opcode.
2962 @retval Other A pointer to the created opcode.
2967 HiiCreateNumericOpCode (
2968 IN VOID
*OpCodeHandle
,
2969 IN EFI_QUESTION_ID QuestionId
,
2970 IN EFI_VARSTORE_ID VarStoreId
,
2971 IN UINT16 VarOffset
,
2972 IN EFI_STRING_ID Prompt
,
2973 IN EFI_STRING_ID Help
,
2974 IN UINT8 QuestionFlags
,
2975 IN UINT8 NumericFlags
,
2979 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2982 EFI_IFR_NUMERIC OpCode
;
2985 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
2987 ZeroMem (&OpCode
, sizeof (OpCode
));
2988 OpCode
.Question
.QuestionId
= QuestionId
;
2989 OpCode
.Question
.VarStoreId
= VarStoreId
;
2990 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2991 OpCode
.Question
.Header
.Prompt
= Prompt
;
2992 OpCode
.Question
.Header
.Help
= Help
;
2993 OpCode
.Question
.Flags
= QuestionFlags
;
2994 OpCode
.Flags
= NumericFlags
;
2996 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
2997 case EFI_IFR_NUMERIC_SIZE_1
:
2998 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
2999 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3000 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3003 case EFI_IFR_NUMERIC_SIZE_2
:
3004 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3005 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3006 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3009 case EFI_IFR_NUMERIC_SIZE_4
:
3010 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3011 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3012 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3015 case EFI_IFR_NUMERIC_SIZE_8
:
3016 OpCode
.data
.u64
.MinValue
= Minimum
;
3017 OpCode
.data
.u64
.MaxValue
= Maximum
;
3018 OpCode
.data
.u64
.Step
= Step
;
3022 if (DefaultsOpCodeHandle
== NULL
) {
3023 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
));
3026 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3027 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
), 0, 1);
3028 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3029 HiiCreateEndOpCode (OpCodeHandle
);
3030 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3034 Create EFI_IFR_STRING_OP opcode.
3036 If OpCodeHandle is NULL, then ASSERT().
3037 If any reserved bits are set in QuestionFlags, then ASSERT().
3038 If any reserved bits are set in StringFlags, then ASSERT().
3040 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3041 @param[in] QuestionId Question ID
3042 @param[in] VarStoreId Storage ID
3043 @param[in] VarOffset Offset in Storage
3044 @param[in] Prompt String ID for Prompt
3045 @param[in] Help String ID for Help
3046 @param[in] QuestionFlags Flags in Question Header
3047 @param[in] StringFlags Flags for string opcode
3048 @param[in] MinSize String minimum length
3049 @param[in] MaxSize String maximum length
3050 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3051 is an optional parameter that may be NULL.
3053 @retval NULL There is not enough space left in Buffer to add the opcode.
3054 @retval Other A pointer to the created opcode.
3059 HiiCreateStringOpCode (
3060 IN VOID
*OpCodeHandle
,
3061 IN EFI_QUESTION_ID QuestionId
,
3062 IN EFI_VARSTORE_ID VarStoreId
,
3063 IN UINT16 VarOffset
,
3064 IN EFI_STRING_ID Prompt
,
3065 IN EFI_STRING_ID Help
,
3066 IN UINT8 QuestionFlags
,
3067 IN UINT8 StringFlags
,
3070 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3073 EFI_IFR_STRING OpCode
;
3076 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3078 ZeroMem (&OpCode
, sizeof (OpCode
));
3079 OpCode
.Question
.Header
.Prompt
= Prompt
;
3080 OpCode
.Question
.Header
.Help
= Help
;
3081 OpCode
.Question
.QuestionId
= QuestionId
;
3082 OpCode
.Question
.VarStoreId
= VarStoreId
;
3083 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3084 OpCode
.Question
.Flags
= QuestionFlags
;
3085 OpCode
.MinSize
= MinSize
;
3086 OpCode
.MaxSize
= MaxSize
;
3087 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3089 if (DefaultsOpCodeHandle
== NULL
) {
3090 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3093 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3094 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3095 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3096 HiiCreateEndOpCode (OpCodeHandle
);
3097 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3101 Create EFI_IFR_ONE_OF_OP opcode.
3103 If OpCodeHandle is NULL, then ASSERT().
3104 If any reserved bits are set in QuestionFlags, then ASSERT().
3105 If any reserved bits are set in OneOfFlags, then ASSERT().
3107 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3108 @param[in] QuestionId Question ID
3109 @param[in] VarStoreId Storage ID
3110 @param[in] VarOffset Offset in Storage
3111 @param[in] Prompt String ID for Prompt
3112 @param[in] Help String ID for Help
3113 @param[in] QuestionFlags Flags in Question Header
3114 @param[in] OneOfFlags Flags for oneof opcode
3115 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3116 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3117 is an optional parameter that may be NULL.
3119 @retval NULL There is not enough space left in Buffer to add the opcode.
3120 @retval Other A pointer to the created opcode.
3125 HiiCreateOneOfOpCode (
3126 IN VOID
*OpCodeHandle
,
3127 IN EFI_QUESTION_ID QuestionId
,
3128 IN EFI_VARSTORE_ID VarStoreId
,
3129 IN UINT16 VarOffset
,
3130 IN EFI_STRING_ID Prompt
,
3131 IN EFI_STRING_ID Help
,
3132 IN UINT8 QuestionFlags
,
3133 IN UINT8 OneOfFlags
,
3134 IN VOID
*OptionsOpCodeHandle
,
3135 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3138 EFI_IFR_ONE_OF OpCode
;
3141 ASSERT (OptionsOpCodeHandle
!= NULL
);
3142 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3144 ZeroMem (&OpCode
, sizeof (OpCode
));
3145 OpCode
.Question
.Header
.Prompt
= Prompt
;
3146 OpCode
.Question
.Header
.Help
= Help
;
3147 OpCode
.Question
.QuestionId
= QuestionId
;
3148 OpCode
.Question
.VarStoreId
= VarStoreId
;
3149 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3150 OpCode
.Question
.Flags
= QuestionFlags
;
3151 OpCode
.Flags
= OneOfFlags
;
3153 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3154 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, sizeof (OpCode
), 0, 1);
3155 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3156 if (DefaultsOpCodeHandle
!= NULL
) {
3157 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3159 HiiCreateEndOpCode (OpCodeHandle
);
3160 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3164 Create EFI_IFR_ORDERED_LIST_OP opcode.
3166 If OpCodeHandle is NULL, then ASSERT().
3167 If any reserved bits are set in QuestionFlags, then ASSERT().
3168 If any reserved bits are set in OrderedListFlags, then ASSERT().
3170 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3171 @param[in] QuestionId Question ID
3172 @param[in] VarStoreId Storage ID
3173 @param[in] VarOffset Offset in Storage
3174 @param[in] Prompt String ID for Prompt
3175 @param[in] Help String ID for Help
3176 @param[in] QuestionFlags Flags in Question Header
3177 @param[in] OrderedListFlags Flags for ordered list opcode
3178 @param[in] DataType Type for option value
3179 @param[in] MaxContainers Maximum count for options in this ordered list
3180 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3181 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3182 is an optional parameter that may be NULL.
3184 @retval NULL There is not enough space left in Buffer to add the opcode.
3185 @retval Other A pointer to the created opcode.
3190 HiiCreateOrderedListOpCode (
3191 IN VOID
*OpCodeHandle
,
3192 IN EFI_QUESTION_ID QuestionId
,
3193 IN EFI_VARSTORE_ID VarStoreId
,
3194 IN UINT16 VarOffset
,
3195 IN EFI_STRING_ID Prompt
,
3196 IN EFI_STRING_ID Help
,
3197 IN UINT8 QuestionFlags
,
3198 IN UINT8 OrderedListFlags
,
3200 IN UINT8 MaxContainers
,
3201 IN VOID
*OptionsOpCodeHandle
,
3202 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3205 EFI_IFR_ORDERED_LIST OpCode
;
3208 ASSERT (OptionsOpCodeHandle
!= NULL
);
3209 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3211 ZeroMem (&OpCode
, sizeof (OpCode
));
3212 OpCode
.Question
.Header
.Prompt
= Prompt
;
3213 OpCode
.Question
.Header
.Help
= Help
;
3214 OpCode
.Question
.QuestionId
= QuestionId
;
3215 OpCode
.Question
.VarStoreId
= VarStoreId
;
3216 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3217 OpCode
.Question
.Flags
= QuestionFlags
;
3218 OpCode
.MaxContainers
= MaxContainers
;
3219 OpCode
.Flags
= OrderedListFlags
;
3221 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3222 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3223 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3224 if (DefaultsOpCodeHandle
!= NULL
) {
3225 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3227 HiiCreateEndOpCode (OpCodeHandle
);
3228 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3232 This is the internal worker function to update the data in
3233 a form specified by FormSetGuid, FormId and Label.
3235 @param FormSetGuid The optional Formset GUID.
3236 @param FormId The Form ID.
3237 @param Package The package header.
3239 @param TempPacakge The resultant package.
3241 @retval EFI_SUCCESS The function completes successfully.
3246 InternalHiiUpdateFormPackageData (
3247 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3248 IN EFI_FORM_ID FormId
,
3249 IN EFI_HII_PACKAGE_HEADER
*Package
,
3250 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3251 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3252 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3257 EFI_HII_PACKAGE_HEADER PackageHeader
;
3259 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3260 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3264 UINTN UpdatePackageLength
;
3266 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3267 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3268 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3270 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3271 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3272 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3273 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3277 while (Offset
< PackageHeader
.Length
) {
3278 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3279 BufferPos
+= IfrOpHdr
->Length
;
3280 UpdatePackageLength
+= IfrOpHdr
->Length
;
3283 // Find the matched FormSet and Form
3285 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3286 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3291 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
) {
3292 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3300 // The matched Form is found, and Update data in this form
3302 if (GetFormSet
&& GetForm
) {
3303 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3304 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3305 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3307 // Remove the original data when End OpCode buffer exist.
3309 if (OpCodeBufferEnd
!= NULL
) {
3310 Offset
+= IfrOpHdr
->Length
;
3311 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3312 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3313 while (Offset
< PackageHeader
.Length
) {
3315 // Search the matched end opcode
3317 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3318 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3322 // Go to the next Op-Code
3324 Offset
+= IfrOpHdr
->Length
;
3325 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3328 if (Offset
>= PackageHeader
.Length
) {
3330 // The end opcode is not found.
3332 return EFI_NOT_FOUND
;
3337 // Insert the updated data
3339 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3340 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3341 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3342 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3344 if (OpCodeBufferEnd
!= NULL
) {
3346 // Add the end opcode
3348 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3349 BufferPos
+= IfrOpHdr
->Length
;
3350 UpdatePackageLength
+= IfrOpHdr
->Length
;
3354 // Copy the left package data.
3356 Offset
+= IfrOpHdr
->Length
;
3357 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3358 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3369 // Go to the next Op-Code
3371 Offset
+= IfrOpHdr
->Length
;
3372 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3377 // The updated opcode buffer is not found.
3379 return EFI_NOT_FOUND
;
3382 // Update the package length.
3384 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3385 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3391 This function updates a form that has previously been registered with the HII
3392 Database. This function will perform at most one update operation.
3394 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3395 comparisons of IFR opcodes are performed from the beginning of the form being
3396 updated until an IFR opcode is found that exactly matches the first IFR opcode
3397 specifed by StartOpCodeHandle. The following rules are used to determine if
3398 an insert, replace, or delete operation is performed.
3400 1) If no matches are found, then NULL is returned.
3401 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3402 from StartOpcodeHandle except the first opcode are inserted immediately after
3403 the matching IFR opcode in the form beng updated.
3404 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3405 from the matching IFR opcode until an IFR opcode exatly matches the first
3406 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3407 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3408 is found, then all of the IFR opcodes between the start match and the end
3409 match are deleted from the form being updated and all of the IFR opcodes
3410 from StartOpcodeHandle except the first opcode are inserted immediately after
3411 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3412 IFR instruction, then the result of ths operation will delete all of the IFR
3413 opcodes between the start end matches.
3415 If HiiHandle is NULL, then ASSERT().
3416 If StartOpCodeHandle is NULL, then ASSERT().
3418 @param[in] HiiHandle The HII Handle of the form to update.
3419 @param[in] FormSetGuid The Formset GUID of the form to update. This
3420 is an optional parameter that may be NULL.
3421 If it is NULL, all FormSet will be updated.
3422 @param[in] FormId The ID of the form to update.
3423 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
3424 opcodes to be inserted or replaced in the form.
3425 The first IFR instruction in StartOpCodeHandle
3426 is used to find matching IFR opcode in the
3428 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
3429 that marks the end of a replace operation in
3430 the form. This is an optional parameter that
3431 may be NULL. If it is NULL, then an the IFR
3432 opcodes specified by StartOpCodeHandle are
3433 inserted into the form.
3435 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
3436 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
3437 1) The form specified by HiiHandle, FormSetGuid,
3438 and FormId could not be found in the HII Database.
3439 2) No IFR opcodes in the target form match the first
3440 IFR opcode in StartOpCodeHandle.
3441 3) EndOpCOde is not NULL, and no IFR opcodes in the
3442 target form following a matching start opcode match
3443 the first IFR opcode in EndOpCodeHandle.
3444 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
3450 IN EFI_HII_HANDLE HiiHandle
,
3451 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3452 IN EFI_FORM_ID FormId
,
3453 IN VOID
*StartOpcodeHandle
,
3454 IN VOID
*EndOpcodeHandle OPTIONAL
3458 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
3459 UINT32 PackageListLength
;
3461 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
3463 UINT8
*UpdateBufferPos
;
3464 EFI_HII_PACKAGE_HEADER
*Package
;
3465 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
3466 EFI_HII_PACKAGE_HEADER PackageHeader
;
3468 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
3469 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
3472 // Input update data can't be NULL.
3474 ASSERT (HiiHandle
!= NULL
);
3475 ASSERT (StartOpcodeHandle
!= NULL
);
3476 UpdatePackageList
= NULL
;
3478 HiiPackageList
= NULL
;
3481 // Restrive buffer data from Opcode Handle
3483 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpcodeHandle
;
3484 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpcodeHandle
;
3487 // Get the orginal package list
3490 HiiPackageList
= NULL
;
3491 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3493 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
3495 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3499 HiiPackageList
= AllocatePool (BufferSize
);
3500 if (HiiPackageList
== NULL
) {
3501 Status
= EFI_OUT_OF_RESOURCES
;
3505 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3506 if (EFI_ERROR (Status
)) {
3511 // Calculate and allocate space for retrieval of IFR data
3513 BufferSize
+= OpCodeBufferStart
->Position
;
3514 UpdatePackageList
= AllocateZeroPool (BufferSize
);
3515 if (UpdatePackageList
== NULL
) {
3516 Status
= EFI_OUT_OF_RESOURCES
;
3521 // Allocate temp buffer to store the temp updated package buffer
3523 TempPacakge
= AllocateZeroPool (BufferSize
);
3524 if (TempPacakge
== NULL
) {
3525 Status
= EFI_OUT_OF_RESOURCES
;
3529 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
3532 // Copy the package list header
3534 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
3535 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3538 // Go through each package to find the matched pacakge and update one by one
3541 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3542 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
3543 while (Offset
< PackageListLength
) {
3544 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
3545 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3546 Offset
+= Package
->Length
;
3548 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
3550 // Check this package is the matched package.
3552 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
3554 // The matched package is found. Its pacakge buffer will be updated by the input new data.
3556 if (!EFI_ERROR(Status
)) {
3562 // Add updated package buffer
3564 Package
= TempPacakge
;
3569 // Add pacakge buffer
3571 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3572 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
3573 UpdateBufferPos
+= PackageHeader
.Length
;
3578 // Update package list length
3580 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
3581 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
3584 // Update Pacakge to show form
3586 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
3589 // Not matched form is found and updated.
3591 Status
= EFI_NOT_FOUND
;
3595 if (HiiPackageList
!= NULL
) {
3596 FreePool (HiiPackageList
);
3599 if (UpdatePackageList
!= NULL
) {
3600 FreePool (UpdatePackageList
);
3603 if (TempPacakge
!= NULL
) {
3604 FreePool (TempPacakge
);