2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2011, 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 // <ConfigHdr> Template
37 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
39 EFI_FORM_BROWSER2_PROTOCOL
*mUefiFormBrowser2
= NULL
;
42 // Template used to mark the end of a list of packages
44 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList
= {
45 sizeof (EFI_HII_PACKAGE_HEADER
),
50 Extract Hii package list GUID for given HII handle.
52 If HiiHandle could not be found in the HII database, then ASSERT.
53 If Guid is NULL, then ASSERT.
55 @param Handle Hii handle
56 @param Guid Package list GUID
58 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
63 InternalHiiExtractGuidFromHiiHandle (
64 IN EFI_HII_HANDLE Handle
,
70 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
72 ASSERT (Guid
!= NULL
);
73 ASSERT (Handle
!= NULL
);
76 // Get HII PackageList
79 HiiPackageList
= NULL
;
81 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
82 ASSERT (Status
!= EFI_NOT_FOUND
);
84 if (Status
== EFI_BUFFER_TOO_SMALL
) {
85 HiiPackageList
= AllocatePool (BufferSize
);
86 ASSERT (HiiPackageList
!= NULL
);
88 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
90 if (EFI_ERROR (Status
)) {
91 FreePool (HiiPackageList
);
98 CopyGuid (Guid
, &HiiPackageList
->PackageListGuid
);
100 FreePool (HiiPackageList
);
106 Registers a list of packages in the HII Database and returns the HII Handle
107 associated with that registration. If an HII Handle has already been registered
108 with the same PackageListGuid and DeviceHandle, then NULL is returned. If there
109 are not enough resources to perform the registration, then NULL is returned.
110 If an empty list of packages is passed in, then NULL is returned. If the size of
111 the list of package is 0, then NULL is returned.
113 The variable arguments are pointers which point to package header that defined
114 by UEFI VFR compiler and StringGather tool.
116 #pragma pack (push, 1)
119 EFI_HII_PACKAGE_HEADER PackageHeader;
120 } EDKII_AUTOGEN_PACKAGES_HEADER;
123 @param[in] PackageListGuid The GUID of the package list.
124 @param[in] DeviceHandle If not NULL, the Device Handle on which
125 an instance of DEVICE_PATH_PROTOCOL is installed.
126 This Device Handle uniquely defines the device that
127 the added packages are associated with.
128 @param[in] ... The variable argument list that contains pointers
129 to packages terminated by a NULL.
131 @retval NULL A HII Handle has already been registered in the HII Database with
132 the same PackageListGuid and DeviceHandle.
133 @retval NULL The HII Handle could not be created.
134 @retval NULL An empty list of packages was passed in.
135 @retval NULL All packages are empty.
136 @retval Other The HII Handle associated with the newly registered package list.
142 IN CONST EFI_GUID
*PackageListGuid
,
143 IN EFI_HANDLE DeviceHandle OPTIONAL
,
150 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
151 EFI_HII_HANDLE HiiHandle
;
155 ASSERT (PackageListGuid
!= NULL
);
158 // Calculate the length of all the packages in the variable argument list
160 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
161 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
166 // If there are no packages in the variable argument list or all the packages
167 // are empty, then return a NULL HII Handle
174 // Add the length of the Package List Header and the terminating Package Header
176 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
179 // Allocate the storage for the entire Package List
181 PackageListHeader
= AllocateZeroPool (Length
);
184 // If the Package List can not be allocated, then return a NULL HII Handle
186 if (PackageListHeader
== NULL
) {
191 // Fill in the GUID and Length of the Package List Header
193 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
194 PackageListHeader
->PackageLength
= Length
;
197 // Initialize a pointer to the beginning if the Package List data
199 Data
= (UINT8
*)(PackageListHeader
+ 1);
202 // Copy the data from each package in the variable argument list
204 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
205 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
206 CopyMem (Data
, Package
+ 1, Length
);
212 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
214 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
217 // Register the package list with the HII Database
219 Status
= gHiiDatabase
->NewPackageList (
225 if (EFI_ERROR (Status
)) {
230 // Free the allocated package list
232 FreePool (PackageListHeader
);
235 // Return the new HII Handle
241 Removes a package list from the HII database.
243 If HiiHandle is NULL, then ASSERT.
244 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
246 @param[in] HiiHandle The handle that was previously registered in the HII database
252 IN EFI_HII_HANDLE HiiHandle
257 ASSERT (HiiHandle
!= NULL
);
258 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
259 ASSERT_EFI_ERROR (Status
);
264 Retrieves the array of all the HII Handles or the HII handles of a specific
265 package list GUID in the HII Database.
266 This array is terminated with a NULL HII Handle.
267 This function allocates the returned array using AllocatePool().
268 The caller is responsible for freeing the array with FreePool().
270 @param[in] PackageListGuid An optional parameter that is used to request
271 HII Handles associated with a specific
272 Package List GUID. If this parameter is NULL,
273 then all the HII Handles in the HII Database
274 are returned. If this parameter is not NULL,
275 then zero or more HII Handles associated with
276 PackageListGuid are returned.
278 @retval NULL No HII handles were found in the HII database
279 @retval NULL The array of HII Handles could not be retrieved
280 @retval Other A pointer to the NULL terminated array of HII Handles
286 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
290 UINTN HandleBufferLength
;
291 EFI_HII_HANDLE TempHiiHandleBuffer
;
292 EFI_HII_HANDLE
*HiiHandleBuffer
;
298 // Retrieve the size required for the buffer of all HII handles.
300 HandleBufferLength
= 0;
301 Status
= gHiiDatabase
->ListPackageLists (
303 EFI_HII_PACKAGE_TYPE_ALL
,
310 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
311 // then there are no HII handles in the HII database. If ListPackageLists()
312 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
313 // handles in the HII database.
315 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
317 // Return NULL if the size can not be retrieved, or if there are no HII
318 // handles in the HII Database
324 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
326 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
327 if (HiiHandleBuffer
== NULL
) {
329 // Return NULL if allocation fails.
335 // Retrieve the array of HII Handles in the HII Database
337 Status
= gHiiDatabase
->ListPackageLists (
339 EFI_HII_PACKAGE_TYPE_ALL
,
344 if (EFI_ERROR (Status
)) {
346 // Free the buffer and return NULL if the HII handles can not be retrieved.
348 FreePool (HiiHandleBuffer
);
352 if (PackageListGuid
== NULL
) {
354 // Return the NULL terminated array of HII handles in the HII Database
356 return HiiHandleBuffer
;
358 for (Index1
= 0, Index2
= 0; HiiHandleBuffer
[Index1
] != NULL
; Index1
++) {
359 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index1
], &Guid
);
360 ASSERT_EFI_ERROR (Status
);
361 if (CompareGuid (&Guid
, PackageListGuid
)) {
362 HiiHandleBuffer
[Index2
++] = HiiHandleBuffer
[Index1
];
366 HiiHandleBuffer
[Index2
] = NULL
;
367 return HiiHandleBuffer
;
369 FreePool (HiiHandleBuffer
);
376 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
377 hex digits that appear between a '=' and a '&' in a config string.
379 If ConfigString is NULL, then ASSERT().
381 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
383 @return Pointer to the Null-terminated Unicode result string.
388 InternalHiiLowerConfigString (
389 IN EFI_STRING ConfigString
395 ASSERT (ConfigString
!= NULL
);
398 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
400 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
401 if (*String
== L
'=') {
403 } else if (*String
== L
'&') {
405 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
406 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
414 Uses the BlockToConfig() service of the Config Routing Protocol to
415 convert <ConfigRequest> and a buffer to a <ConfigResp>
417 If ConfigRequest is NULL, then ASSERT().
418 If Block is NULL, then ASSERT().
420 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
421 @param[in] Block Pointer to a block of data.
422 @param[in] BlockSize The zie, in bytes, of Block.
424 @retval NULL The <ConfigResp> string could not be generated.
425 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
430 InternalHiiBlockToConfig (
431 IN CONST EFI_STRING ConfigRequest
,
432 IN CONST UINT8
*Block
,
437 EFI_STRING ConfigResp
;
440 ASSERT (ConfigRequest
!= NULL
);
441 ASSERT (Block
!= NULL
);
444 // Convert <ConfigRequest> to <ConfigResp>
446 Status
= gHiiConfigRouting
->BlockToConfig (
454 if (EFI_ERROR (Status
)) {
461 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
462 or set uncommitted data. If sata i being retrieved, then the buffer is
463 allocated using AllocatePool(). The caller is then responsible for freeing
464 the buffer using FreePool().
466 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
467 parameter that may be NULL.
468 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
469 is an optional parameter that may be NULL.
470 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
471 of uncommited data to set. If this parameter is NULL,
472 then the caller is requesting to get the uncommited data
473 from the Form Browser.
475 @retval NULL The uncommitted data could not be retrieved.
476 @retval Other A pointer to a buffer containing the uncommitted data.
481 InternalHiiBrowserCallback (
482 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
483 IN CONST CHAR16
*VariableName
, OPTIONAL
484 IN CONST EFI_STRING SetResultsData OPTIONAL
488 UINTN ResultsDataSize
;
489 EFI_STRING ResultsData
;
490 CHAR16 TempResultsData
;
495 if (mUefiFormBrowser2
== NULL
) {
496 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
497 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
504 if (SetResultsData
!= NULL
) {
506 // Request to to set data in the uncommitted browser state information
508 ResultsData
= SetResultsData
;
511 // Retrieve the length of the buffer required ResultsData from the Browser Callback
513 Status
= mUefiFormBrowser2
->BrowserCallback (
522 if (!EFI_ERROR (Status
)) {
524 // No Resluts Data, only allocate one char for '\0'
526 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
530 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
535 // Allocate the ResultsData buffer
537 ResultsData
= AllocateZeroPool (ResultsDataSize
);
538 if (ResultsData
== NULL
) {
544 // Retrieve or set the ResultsData from the Browser Callback
546 Status
= mUefiFormBrowser2
->BrowserCallback (
550 (BOOLEAN
)(SetResultsData
== NULL
),
554 if (EFI_ERROR (Status
)) {
562 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
563 information that includes a GUID, an optional Unicode string name, and a device
564 path. The string returned is allocated with AllocatePool(). The caller is
565 responsible for freeing the allocated string with FreePool().
567 The format of a <ConfigHdr> is as follows:
569 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
571 @param[in] Guid Pointer to an EFI_GUID that is the routing information
572 GUID. Each of the 16 bytes in Guid is converted to
573 a 2 Unicode character hexidecimal string. This is
574 an optional parameter that may be NULL.
575 @param[in] Name Pointer to a Null-terminated Unicode string that is
576 the routing information NAME. This is an optional
577 parameter that may be NULL. Each 16-bit Unicode
578 character in Name is converted to a 4 character Unicode
580 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
581 that is the routing information PATH. Each byte of
582 the Device Path associated with DriverHandle is converted
583 to a 2 Unicode character hexidecimal string.
585 @retval NULL DriverHandle does not support the Device Path Protocol.
586 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
591 HiiConstructConfigHdr (
592 IN CONST EFI_GUID
*Guid
, OPTIONAL
593 IN CONST CHAR16
*Name
, OPTIONAL
594 IN EFI_HANDLE DriverHandle
598 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
599 UINTN DevicePathSize
;
601 CHAR16
*ReturnString
;
606 // Compute the length of Name in Unicode characters.
607 // If Name is NULL, then the length is 0.
611 NameLength
= StrLen (Name
);
617 // Retrieve DevicePath Protocol associated with DriverHandle
619 if (DriverHandle
!= NULL
) {
620 DevicePath
= DevicePathFromHandle (DriverHandle
);
621 if (DevicePath
== NULL
) {
625 // Compute the size of the device path in bytes
627 DevicePathSize
= GetDevicePathSize (DevicePath
);
631 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
632 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
634 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
635 if (String
== NULL
) {
640 // Start with L"GUID="
642 ReturnString
= StrCpy (String
, L
"GUID=");
643 String
+= StrLen (String
);
647 // Append Guid converted to <HexCh>32
649 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
650 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
657 StrCpy (String
, L
"&NAME=");
658 String
+= StrLen (String
);
662 // Append Name converted to <Char>NameLength
664 for (; *Name
!= L
'\0'; Name
++) {
665 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
672 StrCpy (String
, L
"&PATH=");
673 String
+= StrLen (String
);
676 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
678 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
679 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
683 // Null terminate the Unicode string
688 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
690 return InternalHiiLowerConfigString (ReturnString
);
694 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
695 to binary buffer from <ConfigHdr>.
697 This is a internal function.
699 @param String UEFI configuration string.
700 @param Flag Flag specifies what type buffer will be retrieved.
701 @param Buffer Binary of Guid, Name or Device path.
703 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
704 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
705 @retval EFI_SUCCESS The buffer data is retrieved and translated to
710 InternalHiiGetBufferFromString (
711 IN EFI_STRING String
,
717 EFI_STRING ConfigHdr
;
724 if (String
== NULL
|| Buffer
== NULL
) {
725 return EFI_INVALID_PARAMETER
;
732 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
733 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
735 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
738 case GUID_CONFIG_STRING_TYPE
:
739 case PATH_CONFIG_STRING_TYPE
:
741 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
742 // as the device path and Guid resides in RAM memory.
743 // Translate the data into binary.
745 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
746 if (DataBuffer
== NULL
) {
747 return EFI_OUT_OF_RESOURCES
;
750 // Convert binary byte one by one
752 ZeroMem (TemStr
, sizeof (TemStr
));
753 for (Index
= 0; Index
< Length
; Index
++) {
754 TemStr
[0] = ConfigHdr
[Index
];
755 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
756 if ((Index
& 1) == 0) {
757 DataBuffer
[Index
/2] = DigitUint8
;
759 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
763 *Buffer
= DataBuffer
;
766 case NAME_CONFIG_STRING_TYPE
:
768 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
772 // Add the tailling char L'\0'
774 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
775 if (DataBuffer
== NULL
) {
776 return EFI_OUT_OF_RESOURCES
;
779 // Convert character one by one
781 StringPtr
= (CHAR16
*) DataBuffer
;
782 ZeroMem (TemStr
, sizeof (TemStr
));
783 for (Index
= 0; Index
< Length
; Index
+= 4) {
784 StrnCpy (TemStr
, ConfigHdr
+ Index
, 4);
785 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
788 // Add tailing L'\0' character
790 StringPtr
[Index
/4] = L
'\0';
792 *Buffer
= DataBuffer
;
796 return EFI_INVALID_PARAMETER
;
803 This function checks VarOffset and VarWidth is in the block range.
805 @param BlockArray The block array is to be checked.
806 @param VarOffset Offset of var to the structure
807 @param VarWidth Width of var.
809 @retval TRUE This Var is in the block range.
810 @retval FALSE This Var is not in the block range.
814 IN IFR_BLOCK_DATA
*BlockArray
,
820 IFR_BLOCK_DATA
*BlockData
;
823 // No Request Block array, all vars are got.
825 if (BlockArray
== NULL
) {
830 // Check the input var is in the request block range.
832 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
833 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
834 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
843 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
845 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
847 @param ValueString String in <BlockConfig> format and points to the
848 first character of <Number>.
849 @param ValueData The output value. Caller takes the responsibility
851 @param ValueLength Length of the <Number>, in characters.
853 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
855 @retval EFI_SUCCESS Value of <Number> is outputted in Number
861 InternalHiiGetValueOfNumber (
862 IN EFI_STRING ValueString
,
863 OUT UINT8
**ValueData
,
864 OUT UINTN
*ValueLength
867 EFI_STRING StringPtr
;
874 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
875 ASSERT (*ValueString
!= L
'\0');
878 // Get the length of value string
880 StringPtr
= ValueString
;
881 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
884 Length
= StringPtr
- ValueString
;
887 // Allocate buffer to store the value
889 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
891 return EFI_OUT_OF_RESOURCES
;
895 // Convert character one by one to the value buffer
897 ZeroMem (TemStr
, sizeof (TemStr
));
898 for (Index
= 0; Index
< Length
; Index
++) {
899 TemStr
[0] = ValueString
[Length
- Index
- 1];
900 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
901 if ((Index
& 1) == 0) {
902 Buf
[Index
/2] = DigitUint8
;
904 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
909 // Set the converted value and string length.
912 *ValueLength
= Length
;
917 This internal function parses IFR data to validate current setting.
919 @param ConfigResp ConfigResp string contains the current setting.
920 @param HiiPackageList Point to Hii package list.
921 @param PackageListLength The length of the pacakge.
922 @param VarGuid Guid of the buffer storage.
923 @param VarName Name of the buffer storage.
925 @retval EFI_SUCCESS The current setting is valid.
926 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
927 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
931 InternalHiiValidateCurrentSetting (
932 IN EFI_STRING ConfigResp
,
933 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
934 IN UINTN PackageListLength
,
935 IN EFI_GUID
*VarGuid
,
939 IFR_BLOCK_DATA
*CurrentBlockArray
;
940 IFR_BLOCK_DATA
*BlockData
;
941 IFR_BLOCK_DATA
*NewBlockData
;
942 IFR_BLOCK_DATA VarBlockData
;
943 EFI_STRING StringPtr
;
953 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
954 UINT32 PackageOffset
;
957 EFI_IFR_OP_HEADER
*IfrOpHdr
;
958 EFI_IFR_VARSTORE
*IfrVarStore
;
959 EFI_IFR_ONE_OF
*IfrOneOf
;
960 EFI_IFR_NUMERIC
*IfrNumeric
;
961 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
962 EFI_IFR_CHECKBOX
*IfrCheckBox
;
963 EFI_IFR_STRING
*IfrString
;
968 // 1. Get the current setting to current block data array and Convert them into VarBuffer
972 // Skip ConfigHdr string
974 StringPtr
= ConfigResp
;
975 StringPtr
= StrStr (ConfigResp
, L
"&OFFSET");
976 if (StringPtr
== NULL
) {
978 // No ConfigBlock value is required to be validated.
979 // EFI_SUCCESS directly return.
985 // Initialize the local variables.
989 Status
= EFI_SUCCESS
;
993 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
994 VarBuffer
= AllocateZeroPool (MaxBufferSize
);
995 if (VarBuffer
== NULL
) {
996 return EFI_OUT_OF_RESOURCES
;
1000 // Init CurrentBlockArray
1002 CurrentBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1003 if (CurrentBlockArray
== NULL
) {
1004 Status
= EFI_OUT_OF_RESOURCES
;
1007 InitializeListHead (&CurrentBlockArray
->Entry
);
1010 // Parse each <RequestElement> if exists
1011 // Only <BlockName> format is supported by this help function.
1012 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1014 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1016 // Skip the &OFFSET= string
1018 StringPtr
+= StrLen (L
"&OFFSET=");
1023 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1024 if (EFI_ERROR (Status
)) {
1031 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1033 FreePool (TmpBuffer
);
1036 StringPtr
+= Length
;
1037 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1038 Status
= EFI_INVALID_PARAMETER
;
1041 StringPtr
+= StrLen (L
"&WIDTH=");
1046 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1047 if (EFI_ERROR (Status
)) {
1054 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1056 FreePool (TmpBuffer
);
1059 StringPtr
+= Length
;
1060 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1061 Status
= EFI_INVALID_PARAMETER
;
1065 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1066 Status
= EFI_INVALID_PARAMETER
;
1069 StringPtr
+= StrLen (L
"&VALUE=");
1074 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1075 if (EFI_ERROR (Status
)) {
1079 StringPtr
+= Length
;
1080 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1081 Status
= EFI_INVALID_PARAMETER
;
1086 // Check whether VarBuffer is enough
1088 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1089 VarBuffer
= ReallocatePool (
1091 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1094 if (VarBuffer
== NULL
) {
1095 Status
= EFI_OUT_OF_RESOURCES
;
1098 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1102 // Update the Block with configuration info
1104 CopyMem (VarBuffer
+ Offset
, TmpBuffer
, Width
);
1105 FreePool (TmpBuffer
);
1109 // Set new Block Data
1111 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1112 if (NewBlockData
== NULL
) {
1113 Status
= EFI_OUT_OF_RESOURCES
;
1116 NewBlockData
->Offset
= Offset
;
1117 NewBlockData
->Width
= Width
;
1120 // Insert the new block data into the block data array.
1122 for (Link
= CurrentBlockArray
->Entry
.ForwardLink
; Link
!= &CurrentBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1123 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1124 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1125 if (NewBlockData
->Width
> BlockData
->Width
) {
1126 BlockData
->Width
= NewBlockData
->Width
;
1128 FreePool (NewBlockData
);
1130 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1132 // Insert new block data as the previous one of this link.
1134 InsertTailList (Link
, &NewBlockData
->Entry
);
1140 // Insert new block data into the array tail.
1142 if (Link
== &CurrentBlockArray
->Entry
) {
1143 InsertTailList (Link
, &NewBlockData
->Entry
);
1147 // If '\0', parsing is finished.
1149 if (*StringPtr
== 0) {
1153 // Go to next ConfigBlock
1158 // Merge the aligned block data into the single block data.
1160 Link
= CurrentBlockArray
->Entry
.ForwardLink
;
1161 while ((Link
!= &CurrentBlockArray
->Entry
) && (Link
->ForwardLink
!= &CurrentBlockArray
->Entry
)) {
1162 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1163 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1164 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1165 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1166 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1168 RemoveEntryList (Link
->ForwardLink
);
1169 FreePool (NewBlockData
);
1172 Link
= Link
->ForwardLink
;
1175 if (IsListEmpty (&CurrentBlockArray
->Entry
)) {
1176 Status
= EFI_SUCCESS
;
1181 // 2. Check IFR value is in block data, then Validate Value
1183 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1186 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1187 while (PackageOffset
< PackageListLength
) {
1188 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1191 // Parse IFR opcode from the form package.
1193 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1194 IfrOffset
= sizeof (PacakgeHeader
);
1195 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1196 while (IfrOffset
< PacakgeHeader
.Length
) {
1197 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1199 // Validate current setting to the value built in IFR opcode
1201 switch (IfrOpHdr
->OpCode
) {
1202 case EFI_IFR_VARSTORE_OP
:
1204 // VarStoreId has been found. No further found.
1206 if (IfrVarStore
!= NULL
) {
1210 // Find the matched VarStoreId to the input VarGuid and VarName
1212 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1213 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1214 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1215 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1216 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1221 // The matched VarStore is found.
1223 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1230 case EFI_IFR_FORM_OP
:
1231 case EFI_IFR_FORM_MAP_OP
:
1233 // Check the matched VarStoreId is found.
1235 if (IfrVarStore
== NULL
) {
1236 Status
= EFI_SUCCESS
;
1240 case EFI_IFR_ONE_OF_OP
:
1242 // Check whether current value is the one of option.
1246 // OneOf question is not in IFR Form. This IFR form is not valid.
1248 if (IfrVarStore
== NULL
) {
1249 Status
= EFI_INVALID_PARAMETER
;
1253 // Check whether this question is for the requested varstore.
1255 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1256 if (IfrOneOf
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1261 // Get Offset by Question header and Width by DataType Flags
1263 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1264 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1266 // Check whether this question is in current block array.
1268 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1270 // This question is not in the current configuration string. Skip it.
1275 // Check this var question is in the var storage
1277 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1279 // This question exceeds the var store size.
1281 Status
= EFI_INVALID_PARAMETER
;
1286 // Get the current value for oneof opcode
1289 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1291 // Set Block Data, to be checked in the following Oneof option opcode.
1293 VarBlockData
.Offset
= Offset
;
1294 VarBlockData
.Width
= Width
;
1295 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1296 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1298 case EFI_IFR_NUMERIC_OP
:
1300 // Check the current value is in the numeric range.
1304 // Numeric question is not in IFR Form. This IFR form is not valid.
1306 if (IfrVarStore
== NULL
) {
1307 Status
= EFI_INVALID_PARAMETER
;
1311 // Check whether this question is for the requested varstore.
1313 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1314 if (IfrNumeric
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1319 // Get Offset by Question header and Width by DataType Flags
1321 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1322 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1324 // Check whether this question is in current block array.
1326 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1328 // This question is not in the current configuration string. Skip it.
1333 // Check this var question is in the var storage
1335 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1337 // This question exceeds the var store size.
1339 Status
= EFI_INVALID_PARAMETER
;
1344 // Check the current value is in the numeric range.
1347 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1348 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1349 case EFI_IFR_NUMERIC_SIZE_1
:
1350 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1352 // Not in the valid range.
1354 Status
= EFI_INVALID_PARAMETER
;
1358 case EFI_IFR_NUMERIC_SIZE_2
:
1359 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1361 // Not in the valid range.
1363 Status
= EFI_INVALID_PARAMETER
;
1367 case EFI_IFR_NUMERIC_SIZE_4
:
1368 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1370 // Not in the valid range.
1372 Status
= EFI_INVALID_PARAMETER
;
1376 case EFI_IFR_NUMERIC_SIZE_8
:
1377 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1379 // Not in the valid range.
1381 Status
= EFI_INVALID_PARAMETER
;
1388 case EFI_IFR_CHECKBOX_OP
:
1390 // Check value is BOOLEAN type, only 0 and 1 is valid.
1394 // CheckBox question is not in IFR Form. This IFR form is not valid.
1396 if (IfrVarStore
== NULL
) {
1397 Status
= EFI_INVALID_PARAMETER
;
1402 // Check whether this question is for the requested varstore.
1404 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1405 if (IfrCheckBox
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1410 // Get Offset by Question header
1412 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1413 Width
= (UINT16
) sizeof (BOOLEAN
);
1415 // Check whether this question is in current block array.
1417 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1419 // This question is not in the current configuration string. Skip it.
1424 // Check this var question is in the var storage
1426 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1428 // This question exceeds the var store size.
1430 Status
= EFI_INVALID_PARAMETER
;
1435 // Boolean type, only 1 and 0 is valid.
1437 if (*(VarBuffer
+ Offset
) > 1) {
1438 Status
= EFI_INVALID_PARAMETER
;
1443 case EFI_IFR_STRING_OP
:
1445 // Check current string length is less than maxsize
1449 // CheckBox question is not in IFR Form. This IFR form is not valid.
1451 if (IfrVarStore
== NULL
) {
1452 Status
= EFI_INVALID_PARAMETER
;
1457 // Check whether this question is for the requested varstore.
1459 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1460 if (IfrString
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1465 // Get Offset/Width by Question header and OneOf Flags
1467 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1468 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1470 // Check whether this question is in current block array.
1472 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1474 // This question is not in the current configuration string. Skip it.
1479 // Check this var question is in the var storage
1481 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1483 // This question exceeds the var store size.
1485 Status
= EFI_INVALID_PARAMETER
;
1490 // Check current string length is less than maxsize
1492 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1493 Status
= EFI_INVALID_PARAMETER
;
1497 case EFI_IFR_ONE_OF_OPTION_OP
:
1499 // Opcode Scope is zero. This one of option is not to be checked.
1501 if (VarBlockData
.Scope
== 0) {
1506 // Only check for OneOf and OrderList opcode
1508 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1509 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1511 // Check current value is the value of one of option.
1513 if (VarValue
== IfrOneOfOption
->Value
.u64
) {
1515 // The value is one of option value.
1516 // Set OpCode to Zero, don't need check again.
1518 VarBlockData
.OpCode
= 0;
1523 case EFI_IFR_END_OP
:
1525 // Decrease opcode scope for the validated opcode
1527 if (VarBlockData
.Scope
> 0) {
1528 VarBlockData
.Scope
--;
1532 // OneOf value doesn't belong to one of option value.
1534 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1535 Status
= EFI_INVALID_PARAMETER
;
1541 // Increase Scope for the validated opcode
1543 if (VarBlockData
.Scope
> 0) {
1544 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1549 // Go to the next opcode
1551 IfrOffset
+= IfrOpHdr
->Length
;
1554 // Only one form is in a package list.
1560 // Go to next package.
1562 PackageOffset
+= PacakgeHeader
.Length
;
1566 if (VarBuffer
!= NULL
) {
1567 FreePool (VarBuffer
);
1570 if (CurrentBlockArray
!= NULL
) {
1572 // Free Link Array CurrentBlockArray
1574 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1575 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1576 RemoveEntryList (&BlockData
->Entry
);
1577 FreePool (BlockData
);
1579 FreePool (CurrentBlockArray
);
1586 This function parses the input ConfigRequest string and its matched IFR code
1587 string for setting default value and validating current setting.
1589 1. For setting default action, Reset the default value specified by DefaultId
1590 to the driver configuration got by Request string.
1591 2. For validating current setting, Validate the current configuration
1592 by parsing HII form IFR opcode.
1594 NULL request string support depends on the ExportConfig interface of
1595 HiiConfigRouting protocol in UEFI specification.
1597 @param Request A null-terminated Unicode string in
1598 <MultiConfigRequest> format. It can be NULL.
1599 If it is NULL, all current configuration for the
1600 entirety of the current HII database will be validated.
1601 If it is NULL, all configuration for the
1602 entirety of the current HII database will be reset.
1603 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1604 @param ActionType Action supports setting defaults and validate current setting.
1606 @retval TURE Action runs successfully.
1607 @retval FALSE Action is not valid or Action can't be executed successfully..
1611 InternalHiiIfrValueAction (
1612 IN CONST EFI_STRING Request
, OPTIONAL
1613 IN UINT16 DefaultId
,
1617 EFI_STRING ConfigAltResp
;
1618 EFI_STRING ConfigAltHdr
;
1619 EFI_STRING ConfigResp
;
1620 EFI_STRING Progress
;
1621 EFI_STRING StringPtr
;
1622 EFI_STRING StringHdr
;
1624 EFI_HANDLE DriverHandle
;
1625 EFI_HANDLE TempDriverHandle
;
1626 EFI_HII_HANDLE
*HiiHandleBuffer
;
1627 EFI_HII_HANDLE HiiHandle
;
1632 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1633 UINTN PackageListLength
;
1634 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1635 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1637 ConfigAltResp
= NULL
;
1642 ConfigAltHdr
= NULL
;
1643 HiiHandleBuffer
= NULL
;
1645 TempDriverHandle
= NULL
;
1647 HiiPackageList
= NULL
;
1650 // Only support set default and validate setting action.
1652 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
1657 // Get the full requested value and deault value string.
1659 if (Request
!= NULL
) {
1660 Status
= gHiiConfigRouting
->ExtractConfig (
1667 Status
= gHiiConfigRouting
->ExportConfig (
1673 if (EFI_ERROR (Status
)) {
1677 StringPtr
= ConfigAltResp
;
1679 while (StringPtr
!= L
'\0') {
1681 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1683 StringHdr
= StringPtr
;
1688 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1689 Status
= EFI_INVALID_PARAMETER
;
1692 StringPtr
+= StrLen (L
"GUID=");
1693 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
1694 if (EFI_ERROR (Status
)) {
1699 // Get Name value VarName
1701 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1704 if (*StringPtr
== L
'\0') {
1705 Status
= EFI_INVALID_PARAMETER
;
1708 StringPtr
+= StrLen (L
"&NAME=");
1709 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
1710 if (EFI_ERROR (Status
)) {
1715 // Get Path value DevicePath
1717 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1720 if (*StringPtr
== L
'\0') {
1721 Status
= EFI_INVALID_PARAMETER
;
1724 StringPtr
+= StrLen (L
"&PATH=");
1725 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
1726 if (EFI_ERROR (Status
)) {
1731 // Get the Driver handle by the got device path.
1733 TempDevicePath
= DevicePath
;
1734 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
1735 if (EFI_ERROR (Status
)) {
1740 // Find the matched Hii Handle for the found Driver handle
1742 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
1743 if (HiiHandleBuffer
== NULL
) {
1744 Status
= EFI_NOT_FOUND
;
1748 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
1749 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
1750 if (TempDriverHandle
== DriverHandle
) {
1755 HiiHandle
= HiiHandleBuffer
[Index
];
1756 FreePool (HiiHandleBuffer
);
1758 if (HiiHandle
== NULL
) {
1760 // This request string has no its Hii package.
1761 // Its default value and validating can't execute by parsing IFR data.
1762 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
1764 Status
= EFI_SUCCESS
;
1765 goto NextConfigAltResp
;
1769 // 2. Get HiiPackage by HiiHandle
1771 PackageListLength
= 0;
1772 HiiPackageList
= NULL
;
1773 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1776 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1778 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1779 Status
= EFI_INVALID_PARAMETER
;
1783 HiiPackageList
= AllocatePool (PackageListLength
);
1784 if (HiiPackageList
== NULL
) {
1785 Status
= EFI_OUT_OF_RESOURCES
;
1790 // Get PackageList on HiiHandle
1792 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1793 if (EFI_ERROR (Status
)) {
1798 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
1799 // Get the default configuration string according to the default ID.
1801 Status
= gHiiConfigRouting
->GetAltConfig (
1807 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultId
:NULL
, // it can be NULL to get the current setting.
1812 // The required setting can't be found. So, it is not required to be validated and set.
1814 if (EFI_ERROR (Status
)) {
1815 Status
= EFI_SUCCESS
;
1816 goto NextConfigAltResp
;
1819 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
1821 if (StrStr (ConfigResp
, L
"&OFFSET=") == NULL
) {
1822 goto NextConfigAltResp
;
1826 // 4. Set the default configuration information or Validate current setting by parse IFR code.
1827 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1829 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1831 // Set the default configuration information.
1833 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
1836 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1838 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
);
1841 if (EFI_ERROR (Status
)) {
1847 // Free the allocated pacakge buffer and the got ConfigResp string.
1849 if (HiiPackageList
!= NULL
) {
1850 FreePool (HiiPackageList
);
1851 HiiPackageList
= NULL
;
1854 if (ConfigResp
!= NULL
) {
1855 FreePool (ConfigResp
);
1860 // Free the allocated buffer.
1868 FreePool (DevicePath
);
1872 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
1876 // Get and Skip ConfigHdr
1878 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1881 if (*StringPtr
== L
'\0') {
1886 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
1887 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
1889 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
1890 if (ConfigAltHdr
== NULL
) {
1891 Status
= EFI_OUT_OF_RESOURCES
;
1894 StrCpy (ConfigAltHdr
, L
"&");
1895 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
1896 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
1899 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
1901 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
1902 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
1903 if (*StringPtr
== L
'\0') {
1909 // Free the allocated ConfigAltHdr string
1911 FreePool (ConfigAltHdr
);
1912 if (*StringPtr
== L
'\0') {
1917 // Find &GUID as the next ConfigHdr
1919 StringPtr
= StrStr (StringPtr
, L
"&GUID");
1920 if (StringPtr
== NULL
) {
1931 if (VarGuid
!= NULL
) {
1935 if (VarName
!= NULL
) {
1939 if (DevicePath
!= NULL
) {
1940 FreePool (DevicePath
);
1943 if (ConfigResp
!= NULL
) {
1944 FreePool (ConfigResp
);
1947 if (ConfigAltResp
!= NULL
) {
1948 FreePool (ConfigAltResp
);
1951 if (HiiPackageList
!= NULL
) {
1952 FreePool (HiiPackageList
);
1955 if (EFI_ERROR (Status
)) {
1963 Validate the current configuration by parsing HII form IFR opcode.
1965 NULL request string support depends on the ExportConfig interface of
1966 HiiConfigRouting protocol in UEFI specification.
1968 @param Request A null-terminated Unicode string in
1969 <MultiConfigRequest> format. It can be NULL.
1970 If it is NULL, all current configuration for the
1971 entirety of the current HII database will be validated.
1973 @retval TRUE Current configuration is valid.
1974 @retval FALSE Current configuration is invalid.
1978 HiiValidateSettings (
1979 IN CONST EFI_STRING Request OPTIONAL
1982 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
1986 Reset the default value specified by DefaultId to the driver
1987 configuration got by Request string.
1989 NULL request string support depends on the ExportConfig interface of
1990 HiiConfigRouting protocol in UEFI specification.
1992 @param Request A null-terminated Unicode string in
1993 <MultiConfigRequest> format. It can be NULL.
1994 If it is NULL, all configuration for the
1995 entirety of the current HII database will be reset.
1996 @param DefaultId Specifies the type of defaults to retrieve.
1998 @retval TURE The default value is set successfully.
1999 @retval FALSE The default value can't be found and set.
2004 IN CONST EFI_STRING Request
, OPTIONAL
2008 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2012 Determines if two values in config strings match.
2014 Compares the substring between StartSearchString and StopSearchString in
2015 FirstString to the substring between StartSearchString and StopSearchString
2016 in SecondString. If the two substrings match, then TRUE is returned. If the
2017 two substrings do not match, then FALSE is returned.
2019 If FirstString is NULL, then ASSERT().
2020 If SecondString is NULL, then ASSERT().
2021 If StartSearchString is NULL, then ASSERT().
2022 If StopSearchString is NULL, then ASSERT().
2024 @param FirstString Pointer to the first Null-terminated Unicode string.
2025 @param SecondString Pointer to the second Null-terminated Unicode string.
2026 @param StartSearchString Pointer to the Null-terminated Unicode string that
2027 marks the start of the value string to compare.
2028 @param StopSearchString Pointer to the Null-terminated Unicode string that
2029 marks the end of the value string to compare.
2031 @retval FALSE StartSearchString is not present in FirstString.
2032 @retval FALSE StartSearchString is not present in SecondString.
2033 @retval FALSE StopSearchString is not present in FirstString.
2034 @retval FALSE StopSearchString is not present in SecondString.
2035 @retval FALSE The length of the substring in FirstString is not the
2036 same length as the substring in SecondString.
2037 @retval FALSE The value string in FirstString does not matche the
2038 value string in SecondString.
2039 @retval TRUE The value string in FirstString matches the value
2040 string in SecondString.
2045 InternalHiiCompareSubString (
2046 IN CHAR16
*FirstString
,
2047 IN CHAR16
*SecondString
,
2048 IN CHAR16
*StartSearchString
,
2049 IN CHAR16
*StopSearchString
2052 CHAR16
*EndFirstString
;
2053 CHAR16
*EndSecondString
;
2055 ASSERT (FirstString
!= NULL
);
2056 ASSERT (SecondString
!= NULL
);
2057 ASSERT (StartSearchString
!= NULL
);
2058 ASSERT (StopSearchString
!= NULL
);
2060 FirstString
= StrStr (FirstString
, StartSearchString
);
2061 if (FirstString
== NULL
) {
2065 SecondString
= StrStr (SecondString
, StartSearchString
);
2066 if (SecondString
== NULL
) {
2070 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2071 if (EndFirstString
== NULL
) {
2075 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2076 if (EndSecondString
== NULL
) {
2080 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2084 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2088 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2090 If ConfigHdr is NULL, then ASSERT().
2092 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2093 @param[in] Guid GUID of the storage.
2094 @param[in] Name NAME of the storage.
2096 @retval TRUE Routing information matches <ConfigHdr>.
2097 @retval FALSE Routing information does not match <ConfigHdr>.
2102 HiiIsConfigHdrMatch (
2103 IN CONST EFI_STRING ConfigHdr
,
2104 IN CONST EFI_GUID
*Guid
, OPTIONAL
2105 IN CONST CHAR16
*Name OPTIONAL
2108 EFI_STRING CompareConfigHdr
;
2111 ASSERT (ConfigHdr
!= NULL
);
2114 // Use Guid and Name to generate a <ConfigHdr> string
2116 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2117 if (CompareConfigHdr
== NULL
) {
2124 // Compare GUID value strings
2126 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2129 if (Result
&& Name
!= NULL
) {
2131 // Compare NAME value strings
2133 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2137 // Free the <ConfigHdr> string
2139 FreePool (CompareConfigHdr
);
2145 Retrieves uncommitted data from the Form Browser and converts it to a binary
2148 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2149 parameter that may be NULL.
2150 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2151 is an optional parameter that may be NULL.
2152 @param[in] BufferSize Length in bytes of buffer to hold retrieved data.
2153 @param[out] Buffer Buffer of data to be updated.
2155 @retval FALSE The uncommitted data could not be retrieved.
2156 @retval TRUE The uncommitted data was retrieved.
2162 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2163 IN CONST CHAR16
*VariableName
, OPTIONAL
2164 IN UINTN BufferSize
,
2168 EFI_STRING ResultsData
;
2170 EFI_STRING ConfigResp
;
2175 // Retrieve the results data from the Browser Callback
2177 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2178 if (ResultsData
== NULL
) {
2183 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2185 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2186 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2187 ConfigResp
= AllocateZeroPool (Size
);
2188 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2191 // Free the allocated buffer
2193 FreePool (ResultsData
);
2194 if (ConfigResp
== NULL
) {
2199 // Convert <ConfigResp> to a buffer
2201 Status
= gHiiConfigRouting
->ConfigToBlock (
2209 // Free the allocated buffer
2211 FreePool (ConfigResp
);
2213 if (EFI_ERROR (Status
)) {
2221 Updates uncommitted data in the Form Browser.
2223 If Buffer is NULL, then ASSERT().
2225 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2226 parameter that may be NULL.
2227 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2228 is an optional parameter that may be NULL.
2229 @param[in] BufferSize Length, in bytes, of Buffer.
2230 @param[in] Buffer Buffer of data to commit.
2231 @param[in] RequestElement An optional field to specify which part of the
2232 buffer data will be send back to Browser. If NULL,
2233 the whole buffer of data will be committed to
2235 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2237 @retval FALSE The uncommitted data could not be updated.
2238 @retval TRUE The uncommitted data was updated.
2244 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2245 IN CONST CHAR16
*VariableName
, OPTIONAL
2246 IN UINTN BufferSize
,
2247 IN CONST UINT8
*Buffer
,
2248 IN CONST CHAR16
*RequestElement OPTIONAL
2252 EFI_STRING ConfigRequest
;
2253 EFI_STRING ConfigResp
;
2254 EFI_STRING ResultsData
;
2256 ASSERT (Buffer
!= NULL
);
2259 // Construct <ConfigRequest>
2261 if (RequestElement
== NULL
) {
2263 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2264 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2266 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2267 ConfigRequest
= AllocateZeroPool (Size
);
2268 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2271 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2272 // followed by <RequestElement> followed by a Null-terminator
2274 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2275 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2276 ConfigRequest
= AllocateZeroPool (Size
);
2277 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2279 if (ConfigRequest
== NULL
) {
2284 // Convert <ConfigRequest> to <ConfigResp>
2286 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2287 FreePool (ConfigRequest
);
2288 if (ConfigResp
== NULL
) {
2293 // Set data in the uncommitted browser state information
2295 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2296 FreePool (ConfigResp
);
2298 return (BOOLEAN
)(ResultsData
!= NULL
);
2301 /////////////////////////////////////////
2302 /////////////////////////////////////////
2304 /////////////////////////////////////////
2305 /////////////////////////////////////////
2307 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2313 } HII_LIB_OPCODE_BUFFER
;
2316 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2318 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2319 1, // EFI_IFR_TYPE_NUM_SIZE_8
2320 2, // EFI_IFR_TYPE_NUM_SIZE_16
2321 4, // EFI_IFR_TYPE_NUM_SIZE_32
2322 8, // EFI_IFR_TYPE_NUM_SIZE_64
2323 1, // EFI_IFR_TYPE_BOOLEAN
2324 3, // EFI_IFR_TYPE_TIME
2325 4, // EFI_IFR_TYPE_DATE
2326 2 // EFI_IFR_TYPE_STRING
2330 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2331 HiiFreeOpCodeHandle().
2333 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2334 @retval Other A new OpCode handle.
2339 HiiAllocateOpCodeHandle (
2343 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2345 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2346 if (OpCodeBuffer
== NULL
) {
2349 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2350 if (OpCodeBuffer
->Buffer
== NULL
) {
2351 FreePool (OpCodeBuffer
);
2354 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2355 OpCodeBuffer
->Position
= 0;
2356 return (VOID
*)OpCodeBuffer
;
2360 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().
2361 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2362 Handle are also freed.
2364 If OpCodeHandle is NULL, then ASSERT().
2366 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2371 HiiFreeOpCodeHandle (
2375 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2377 ASSERT (OpCodeHandle
!= NULL
);
2379 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2380 if (OpCodeBuffer
->Buffer
!= NULL
) {
2381 FreePool (OpCodeBuffer
->Buffer
);
2383 FreePool (OpCodeBuffer
);
2387 Internal function gets the current position of opcode buffer.
2389 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2391 @return Current position of opcode buffer.
2395 InternalHiiOpCodeHandlePosition (
2396 IN VOID
*OpCodeHandle
2399 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2403 Internal function gets the start pointer of opcode buffer.
2405 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2407 @return Pointer to the opcode buffer base.
2411 InternalHiiOpCodeHandleBuffer (
2412 IN VOID
*OpCodeHandle
2415 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2419 Internal function reserves the enough buffer for current opcode.
2420 When the buffer is not enough, Opcode buffer will be extended.
2422 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2423 @param[in] Size Size of current opcode.
2425 @return Pointer to the current opcode.
2429 InternalHiiGrowOpCodeHandle (
2430 IN VOID
*OpCodeHandle
,
2434 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2437 ASSERT (OpCodeHandle
!= NULL
);
2439 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2440 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2441 Buffer
= ReallocatePool (
2442 OpCodeBuffer
->BufferSize
,
2443 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2444 OpCodeBuffer
->Buffer
2446 ASSERT (Buffer
!= NULL
);
2447 OpCodeBuffer
->Buffer
= Buffer
;
2448 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2450 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2451 OpCodeBuffer
->Position
+= Size
;
2456 Internal function creates opcode based on the template opcode.
2458 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2459 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2460 @param[in] OpCode OpCode IFR value.
2461 @param[in] OpCodeSize Size of opcode.
2462 @param[in] ExtensionSize Size of extended opcode.
2463 @param[in] Scope Scope bit of opcode.
2465 @return Pointer to the current opcode with opcode data.
2469 InternalHiiCreateOpCodeExtended (
2470 IN VOID
*OpCodeHandle
,
2471 IN VOID
*OpCodeTemplate
,
2473 IN UINTN OpCodeSize
,
2474 IN UINTN ExtensionSize
,
2478 EFI_IFR_OP_HEADER
*Header
;
2481 ASSERT (OpCodeTemplate
!= NULL
);
2482 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2484 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2485 Header
->OpCode
= OpCode
;
2486 Header
->Scope
= Scope
;
2487 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2488 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2489 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2493 Internal function creates opcode based on the template opcode for the normal opcode.
2495 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2496 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2497 @param[in] OpCode OpCode IFR value.
2498 @param[in] OpCodeSize Size of opcode.
2500 @return Pointer to the current opcode with opcode data.
2504 InternalHiiCreateOpCode (
2505 IN VOID
*OpCodeHandle
,
2506 IN VOID
*OpCodeTemplate
,
2511 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2515 Append raw opcodes to an OpCodeHandle.
2517 If OpCodeHandle is NULL, then ASSERT().
2518 If RawBuffer is NULL, then ASSERT();
2520 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2521 @param[in] RawBuffer Buffer of opcodes to append.
2522 @param[in] RawBufferSize The size, in bytes, of Buffer.
2524 @retval NULL There is not enough space left in Buffer to add the opcode.
2525 @retval Other A pointer to the appended opcodes.
2530 HiiCreateRawOpCodes (
2531 IN VOID
*OpCodeHandle
,
2532 IN UINT8
*RawBuffer
,
2533 IN UINTN RawBufferSize
2538 ASSERT (RawBuffer
!= NULL
);
2540 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2541 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2545 Append opcodes from one OpCode Handle to another OpCode handle.
2547 If OpCodeHandle is NULL, then ASSERT().
2548 If RawOpCodeHandle is NULL, then ASSERT();
2550 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2551 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2553 @retval NULL There is not enough space left in Buffer to add the opcode.
2554 @retval Other A pointer to the appended opcodes.
2559 InternalHiiAppendOpCodes (
2560 IN VOID
*OpCodeHandle
,
2561 IN VOID
*RawOpCodeHandle
2564 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2566 ASSERT (RawOpCodeHandle
!= NULL
);
2568 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2569 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2573 Create EFI_IFR_END_OP opcode.
2575 If OpCodeHandle is NULL, then ASSERT().
2577 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2579 @retval NULL There is not enough space left in Buffer to add the opcode.
2580 @retval Other A pointer to the created opcode.
2585 HiiCreateEndOpCode (
2586 IN VOID
*OpCodeHandle
2591 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2595 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2597 If OpCodeHandle is NULL, then ASSERT().
2598 If Type is invalid, then ASSERT().
2599 If Flags is invalid, then ASSERT().
2601 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2602 @param[in] StringId StringId for the option
2603 @param[in] Flags Flags for the option
2604 @param[in] Type Type for the option
2605 @param[in] Value Value for the option
2607 @retval NULL There is not enough space left in Buffer to add the opcode.
2608 @retval Other A pointer to the created opcode.
2613 HiiCreateOneOfOptionOpCode (
2614 IN VOID
*OpCodeHandle
,
2621 EFI_IFR_ONE_OF_OPTION OpCode
;
2623 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2625 ZeroMem (&OpCode
, sizeof (OpCode
));
2626 OpCode
.Option
= StringId
;
2627 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2629 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2631 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, sizeof (OpCode
));
2635 Create EFI_IFR_DEFAULT_OP opcode.
2637 If OpCodeHandle is NULL, then ASSERT().
2638 If Type is invalid, then ASSERT().
2640 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2641 @param[in] DefaultId DefaultId for the default
2642 @param[in] Type Type for the default
2643 @param[in] Value Value for the default
2645 @retval NULL There is not enough space left in Buffer to add the opcode.
2646 @retval Other A pointer to the created opcode.
2651 HiiCreateDefaultOpCode (
2652 IN VOID
*OpCodeHandle
,
2653 IN UINT16 DefaultId
,
2658 EFI_IFR_DEFAULT OpCode
;
2660 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2662 ZeroMem (&OpCode
, sizeof (OpCode
));
2664 OpCode
.DefaultId
= DefaultId
;
2665 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2667 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, sizeof (OpCode
));
2671 Create EFI_IFR_GUID opcode.
2673 If OpCodeHandle is NULL, then ASSERT().
2674 If Guid is NULL, then ASSERT().
2675 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
2677 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2678 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
2679 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
2680 optional parameter that may be NULL. If this
2681 parameter is NULL, then the GUID extension
2682 region of the created opcode is filled with zeros.
2683 If this parameter is not NULL, then the GUID
2684 extension region of GuidData will be copied to
2685 the GUID extension region of the created opcode.
2686 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
2687 must be >= sizeof(EFI_IFR_GUID).
2689 @retval NULL There is not enough space left in Buffer to add the opcode.
2690 @retval Other A pointer to the created opcode.
2695 HiiCreateGuidOpCode (
2696 IN VOID
*OpCodeHandle
,
2697 IN CONST EFI_GUID
*Guid
,
2698 IN CONST VOID
*GuidOpCode
, OPTIONAL
2702 EFI_IFR_GUID OpCode
;
2703 EFI_IFR_GUID
*OpCodePointer
;
2705 ASSERT (Guid
!= NULL
);
2706 ASSERT (OpCodeSize
>= sizeof (OpCode
));
2708 ZeroMem (&OpCode
, sizeof (OpCode
));
2709 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
2711 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
2716 OpCodeSize
- sizeof (OpCode
),
2719 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
2720 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
2722 return (UINT8
*)OpCodePointer
;
2726 Create EFI_IFR_ACTION_OP opcode.
2728 If OpCodeHandle is NULL, then ASSERT().
2729 If any reserved bits are set in QuestionFlags, then ASSERT().
2731 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2732 @param[in] QuestionId Question ID
2733 @param[in] Prompt String ID for Prompt
2734 @param[in] Help String ID for Help
2735 @param[in] QuestionFlags Flags in Question Header
2736 @param[in] QuestionConfig String ID for configuration
2738 @retval NULL There is not enough space left in Buffer to add the opcode.
2739 @retval Other A pointer to the created opcode.
2744 HiiCreateActionOpCode (
2745 IN VOID
*OpCodeHandle
,
2746 IN EFI_QUESTION_ID QuestionId
,
2747 IN EFI_STRING_ID Prompt
,
2748 IN EFI_STRING_ID Help
,
2749 IN UINT8 QuestionFlags
,
2750 IN EFI_STRING_ID QuestionConfig
2753 EFI_IFR_ACTION OpCode
;
2755 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2757 ZeroMem (&OpCode
, sizeof (OpCode
));
2758 OpCode
.Question
.QuestionId
= QuestionId
;
2759 OpCode
.Question
.Header
.Prompt
= Prompt
;
2760 OpCode
.Question
.Header
.Help
= Help
;
2761 OpCode
.Question
.Flags
= QuestionFlags
;
2762 OpCode
.QuestionConfig
= QuestionConfig
;
2764 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
2768 Create EFI_IFR_SUBTITLE_OP opcode.
2770 If OpCodeHandle is NULL, then ASSERT().
2771 If any reserved bits are set in Flags, then ASSERT().
2772 If Scope > 1, then ASSERT().
2774 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2775 @param[in] Prompt String ID for Prompt
2776 @param[in] Help String ID for Help
2777 @param[in] Flags Subtitle opcode flags
2778 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
2779 0 if this opcode is within the current scope.
2781 @retval NULL There is not enough space left in Buffer to add the opcode.
2782 @retval Other A pointer to the created opcode.
2787 HiiCreateSubTitleOpCode (
2788 IN VOID
*OpCodeHandle
,
2789 IN EFI_STRING_ID Prompt
,
2790 IN EFI_STRING_ID Help
,
2795 EFI_IFR_SUBTITLE OpCode
;
2797 ASSERT (Scope
<= 1);
2798 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
2800 ZeroMem (&OpCode
, sizeof (OpCode
));
2801 OpCode
.Statement
.Prompt
= Prompt
;
2802 OpCode
.Statement
.Help
= Help
;
2803 OpCode
.Flags
= Flags
;
2805 return InternalHiiCreateOpCodeExtended (
2808 EFI_IFR_SUBTITLE_OP
,
2816 Create EFI_IFR_REF_OP opcode.
2818 If OpCodeHandle is NULL, then ASSERT().
2819 If any reserved bits are set in QuestionFlags, then ASSERT().
2821 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2822 @param[in] FormId Destination Form ID
2823 @param[in] Prompt String ID for Prompt
2824 @param[in] Help String ID for Help
2825 @param[in] QuestionFlags Flags in Question Header
2826 @param[in] QuestionId Question ID
2828 @retval NULL There is not enough space left in Buffer to add the opcode.
2829 @retval Other A pointer to the created opcode.
2834 HiiCreateGotoOpCode (
2835 IN VOID
*OpCodeHandle
,
2836 IN EFI_FORM_ID FormId
,
2837 IN EFI_STRING_ID Prompt
,
2838 IN EFI_STRING_ID Help
,
2839 IN UINT8 QuestionFlags
,
2840 IN EFI_QUESTION_ID QuestionId
2845 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2847 ZeroMem (&OpCode
, sizeof (OpCode
));
2848 OpCode
.Question
.Header
.Prompt
= Prompt
;
2849 OpCode
.Question
.Header
.Help
= Help
;
2850 OpCode
.Question
.QuestionId
= QuestionId
;
2851 OpCode
.Question
.Flags
= QuestionFlags
;
2852 OpCode
.FormId
= FormId
;
2854 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
2858 Create EFI_IFR_CHECKBOX_OP opcode.
2860 If OpCodeHandle is NULL, then ASSERT().
2861 If any reserved bits are set in QuestionFlags, then ASSERT().
2862 If any reserved bits are set in CheckBoxFlags, then ASSERT().
2864 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2865 @param[in] QuestionId Question ID
2866 @param[in] VarStoreId Storage ID
2867 @param[in] VarOffset Offset in Storage
2868 @param[in] Prompt String ID for Prompt
2869 @param[in] Help String ID for Help
2870 @param[in] QuestionFlags Flags in Question Header
2871 @param[in] CheckBoxFlags Flags for checkbox opcode
2872 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2873 is an optional parameter that may be NULL.
2875 @retval NULL There is not enough space left in Buffer to add the opcode.
2876 @retval Other A pointer to the created opcode.
2881 HiiCreateCheckBoxOpCode (
2882 IN VOID
*OpCodeHandle
,
2883 IN EFI_QUESTION_ID QuestionId
,
2884 IN EFI_VARSTORE_ID VarStoreId
,
2885 IN UINT16 VarOffset
,
2886 IN EFI_STRING_ID Prompt
,
2887 IN EFI_STRING_ID Help
,
2888 IN UINT8 QuestionFlags
,
2889 IN UINT8 CheckBoxFlags
,
2890 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2893 EFI_IFR_CHECKBOX OpCode
;
2896 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2898 ZeroMem (&OpCode
, sizeof (OpCode
));
2899 OpCode
.Question
.QuestionId
= QuestionId
;
2900 OpCode
.Question
.VarStoreId
= VarStoreId
;
2901 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2902 OpCode
.Question
.Header
.Prompt
= Prompt
;
2903 OpCode
.Question
.Header
.Help
= Help
;
2904 OpCode
.Question
.Flags
= QuestionFlags
;
2905 OpCode
.Flags
= CheckBoxFlags
;
2907 if (DefaultsOpCodeHandle
== NULL
) {
2908 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
2911 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
2912 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
2913 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
2914 HiiCreateEndOpCode (OpCodeHandle
);
2915 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
2919 Create EFI_IFR_NUMERIC_OP opcode.
2921 If OpCodeHandle is NULL, then ASSERT().
2922 If any reserved bits are set in QuestionFlags, then ASSERT().
2923 If any reserved bits are set in NumericFlags, then ASSERT().
2925 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2926 @param[in] QuestionId Question ID
2927 @param[in] VarStoreId Storage ID
2928 @param[in] VarOffset Offset in Storage
2929 @param[in] Prompt String ID for Prompt
2930 @param[in] Help String ID for Help
2931 @param[in] QuestionFlags Flags in Question Header
2932 @param[in] NumericFlags Flags for numeric opcode
2933 @param[in] Minimum Numeric minimum value
2934 @param[in] Maximum Numeric maximum value
2935 @param[in] Step Numeric step for edit
2936 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
2937 is an optional parameter that may be NULL.
2939 @retval NULL There is not enough space left in Buffer to add the opcode.
2940 @retval Other A pointer to the created opcode.
2945 HiiCreateNumericOpCode (
2946 IN VOID
*OpCodeHandle
,
2947 IN EFI_QUESTION_ID QuestionId
,
2948 IN EFI_VARSTORE_ID VarStoreId
,
2949 IN UINT16 VarOffset
,
2950 IN EFI_STRING_ID Prompt
,
2951 IN EFI_STRING_ID Help
,
2952 IN UINT8 QuestionFlags
,
2953 IN UINT8 NumericFlags
,
2957 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2960 EFI_IFR_NUMERIC OpCode
;
2963 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2965 ZeroMem (&OpCode
, sizeof (OpCode
));
2966 OpCode
.Question
.QuestionId
= QuestionId
;
2967 OpCode
.Question
.VarStoreId
= VarStoreId
;
2968 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2969 OpCode
.Question
.Header
.Prompt
= Prompt
;
2970 OpCode
.Question
.Header
.Help
= Help
;
2971 OpCode
.Question
.Flags
= QuestionFlags
;
2972 OpCode
.Flags
= NumericFlags
;
2974 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
2975 case EFI_IFR_NUMERIC_SIZE_1
:
2976 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
2977 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
2978 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
2981 case EFI_IFR_NUMERIC_SIZE_2
:
2982 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
2983 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
2984 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
2987 case EFI_IFR_NUMERIC_SIZE_4
:
2988 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
2989 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
2990 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
2993 case EFI_IFR_NUMERIC_SIZE_8
:
2994 OpCode
.data
.u64
.MinValue
= Minimum
;
2995 OpCode
.data
.u64
.MaxValue
= Maximum
;
2996 OpCode
.data
.u64
.Step
= Step
;
3000 if (DefaultsOpCodeHandle
== NULL
) {
3001 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
));
3004 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3005 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
), 0, 1);
3006 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3007 HiiCreateEndOpCode (OpCodeHandle
);
3008 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3012 Create EFI_IFR_STRING_OP opcode.
3014 If OpCodeHandle is NULL, then ASSERT().
3015 If any reserved bits are set in QuestionFlags, then ASSERT().
3016 If any reserved bits are set in StringFlags, then ASSERT().
3018 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3019 @param[in] QuestionId Question ID
3020 @param[in] VarStoreId Storage ID
3021 @param[in] VarOffset Offset in Storage
3022 @param[in] Prompt String ID for Prompt
3023 @param[in] Help String ID for Help
3024 @param[in] QuestionFlags Flags in Question Header
3025 @param[in] StringFlags Flags for string opcode
3026 @param[in] MinSize String minimum length
3027 @param[in] MaxSize String maximum length
3028 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3029 is an optional parameter that may be NULL.
3031 @retval NULL There is not enough space left in Buffer to add the opcode.
3032 @retval Other A pointer to the created opcode.
3037 HiiCreateStringOpCode (
3038 IN VOID
*OpCodeHandle
,
3039 IN EFI_QUESTION_ID QuestionId
,
3040 IN EFI_VARSTORE_ID VarStoreId
,
3041 IN UINT16 VarOffset
,
3042 IN EFI_STRING_ID Prompt
,
3043 IN EFI_STRING_ID Help
,
3044 IN UINT8 QuestionFlags
,
3045 IN UINT8 StringFlags
,
3048 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3051 EFI_IFR_STRING OpCode
;
3054 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3056 ZeroMem (&OpCode
, sizeof (OpCode
));
3057 OpCode
.Question
.Header
.Prompt
= Prompt
;
3058 OpCode
.Question
.Header
.Help
= Help
;
3059 OpCode
.Question
.QuestionId
= QuestionId
;
3060 OpCode
.Question
.VarStoreId
= VarStoreId
;
3061 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3062 OpCode
.Question
.Flags
= QuestionFlags
;
3063 OpCode
.MinSize
= MinSize
;
3064 OpCode
.MaxSize
= MaxSize
;
3065 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3067 if (DefaultsOpCodeHandle
== NULL
) {
3068 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3071 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3072 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3073 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3074 HiiCreateEndOpCode (OpCodeHandle
);
3075 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3079 Create EFI_IFR_ONE_OF_OP opcode.
3081 If OpCodeHandle is NULL, then ASSERT().
3082 If any reserved bits are set in QuestionFlags, then ASSERT().
3083 If any reserved bits are set in OneOfFlags, then ASSERT().
3085 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3086 @param[in] QuestionId Question ID
3087 @param[in] VarStoreId Storage ID
3088 @param[in] VarOffset Offset in Storage
3089 @param[in] Prompt String ID for Prompt
3090 @param[in] Help String ID for Help
3091 @param[in] QuestionFlags Flags in Question Header
3092 @param[in] OneOfFlags Flags for oneof opcode
3093 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3094 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3095 is an optional parameter that may be NULL.
3097 @retval NULL There is not enough space left in Buffer to add the opcode.
3098 @retval Other A pointer to the created opcode.
3103 HiiCreateOneOfOpCode (
3104 IN VOID
*OpCodeHandle
,
3105 IN EFI_QUESTION_ID QuestionId
,
3106 IN EFI_VARSTORE_ID VarStoreId
,
3107 IN UINT16 VarOffset
,
3108 IN EFI_STRING_ID Prompt
,
3109 IN EFI_STRING_ID Help
,
3110 IN UINT8 QuestionFlags
,
3111 IN UINT8 OneOfFlags
,
3112 IN VOID
*OptionsOpCodeHandle
,
3113 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3116 EFI_IFR_ONE_OF OpCode
;
3119 ASSERT (OptionsOpCodeHandle
!= NULL
);
3120 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3122 ZeroMem (&OpCode
, sizeof (OpCode
));
3123 OpCode
.Question
.Header
.Prompt
= Prompt
;
3124 OpCode
.Question
.Header
.Help
= Help
;
3125 OpCode
.Question
.QuestionId
= QuestionId
;
3126 OpCode
.Question
.VarStoreId
= VarStoreId
;
3127 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3128 OpCode
.Question
.Flags
= QuestionFlags
;
3129 OpCode
.Flags
= OneOfFlags
;
3131 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3132 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, sizeof (OpCode
), 0, 1);
3133 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3134 if (DefaultsOpCodeHandle
!= NULL
) {
3135 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3137 HiiCreateEndOpCode (OpCodeHandle
);
3138 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3142 Create EFI_IFR_ORDERED_LIST_OP opcode.
3144 If OpCodeHandle is NULL, then ASSERT().
3145 If any reserved bits are set in QuestionFlags, then ASSERT().
3146 If any reserved bits are set in OrderedListFlags, then ASSERT().
3148 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3149 @param[in] QuestionId Question ID
3150 @param[in] VarStoreId Storage ID
3151 @param[in] VarOffset Offset in Storage
3152 @param[in] Prompt String ID for Prompt
3153 @param[in] Help String ID for Help
3154 @param[in] QuestionFlags Flags in Question Header
3155 @param[in] OrderedListFlags Flags for ordered list opcode
3156 @param[in] DataType Type for option value
3157 @param[in] MaxContainers Maximum count for options in this ordered list
3158 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3159 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3160 is an optional parameter that may be NULL.
3162 @retval NULL There is not enough space left in Buffer to add the opcode.
3163 @retval Other A pointer to the created opcode.
3168 HiiCreateOrderedListOpCode (
3169 IN VOID
*OpCodeHandle
,
3170 IN EFI_QUESTION_ID QuestionId
,
3171 IN EFI_VARSTORE_ID VarStoreId
,
3172 IN UINT16 VarOffset
,
3173 IN EFI_STRING_ID Prompt
,
3174 IN EFI_STRING_ID Help
,
3175 IN UINT8 QuestionFlags
,
3176 IN UINT8 OrderedListFlags
,
3178 IN UINT8 MaxContainers
,
3179 IN VOID
*OptionsOpCodeHandle
,
3180 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3183 EFI_IFR_ORDERED_LIST OpCode
;
3186 ASSERT (OptionsOpCodeHandle
!= NULL
);
3187 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3189 ZeroMem (&OpCode
, sizeof (OpCode
));
3190 OpCode
.Question
.Header
.Prompt
= Prompt
;
3191 OpCode
.Question
.Header
.Help
= Help
;
3192 OpCode
.Question
.QuestionId
= QuestionId
;
3193 OpCode
.Question
.VarStoreId
= VarStoreId
;
3194 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3195 OpCode
.Question
.Flags
= QuestionFlags
;
3196 OpCode
.MaxContainers
= MaxContainers
;
3197 OpCode
.Flags
= OrderedListFlags
;
3199 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3200 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3201 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3202 if (DefaultsOpCodeHandle
!= NULL
) {
3203 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3205 HiiCreateEndOpCode (OpCodeHandle
);
3206 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3210 Create EFI_IFR_TEXT_OP opcode.
3212 If OpCodeHandle is NULL, then ASSERT().
3214 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3215 @param[in] Prompt String ID for Prompt.
3216 @param[in] Help String ID for Help.
3217 @param[in] TextTwo String ID for TextTwo.
3219 @retval NULL There is not enough space left in Buffer to add the opcode.
3220 @retval Other A pointer to the created opcode.
3225 HiiCreateTextOpCode (
3226 IN VOID
*OpCodeHandle
,
3227 IN EFI_STRING_ID Prompt
,
3228 IN EFI_STRING_ID Help
,
3229 IN EFI_STRING_ID TextTwo
3232 EFI_IFR_TEXT OpCode
;
3234 ZeroMem (&OpCode
, sizeof (OpCode
));
3235 OpCode
.Statement
.Prompt
= Prompt
;
3236 OpCode
.Statement
.Help
= Help
;
3237 OpCode
.TextTwo
= TextTwo
;
3239 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TEXT_OP
, sizeof (OpCode
));
3243 Create EFI_IFR_DATE_OP opcode.
3245 If OpCodeHandle is NULL, then ASSERT().
3246 If any reserved bits are set in QuestionFlags, then ASSERT().
3247 If any reserved bits are set in DateFlags, then ASSERT().
3249 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3250 @param[in] QuestionId Question ID
3251 @param[in] VarStoreId Storage ID, optional. If DateFlags is not
3252 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3253 @param[in] VarOffset Offset in Storage, optional. If DateFlags is not
3254 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3255 @param[in] Prompt String ID for Prompt
3256 @param[in] Help String ID for Help
3257 @param[in] QuestionFlags Flags in Question Header
3258 @param[in] DateFlags Flags for date opcode
3259 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3260 is an optional parameter that may be NULL.
3262 @retval NULL There is not enough space left in Buffer to add the opcode.
3263 @retval Other A pointer to the created opcode.
3268 HiiCreateDateOpCode (
3269 IN VOID
*OpCodeHandle
,
3270 IN EFI_QUESTION_ID QuestionId
,
3271 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3272 IN UINT16 VarOffset
, OPTIONAL
3273 IN EFI_STRING_ID Prompt
,
3274 IN EFI_STRING_ID Help
,
3275 IN UINT8 QuestionFlags
,
3277 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3280 EFI_IFR_DATE OpCode
;
3283 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3284 ASSERT ((DateFlags
& (~(EFI_QF_DATE_YEAR_SUPPRESS
| EFI_QF_DATE_MONTH_SUPPRESS
| EFI_QF_DATE_DAY_SUPPRESS
| EFI_QF_DATE_STORAGE
))) == 0);
3286 ZeroMem (&OpCode
, sizeof (OpCode
));
3287 OpCode
.Question
.Header
.Prompt
= Prompt
;
3288 OpCode
.Question
.Header
.Help
= Help
;
3289 OpCode
.Question
.QuestionId
= QuestionId
;
3290 OpCode
.Question
.VarStoreId
= VarStoreId
;
3291 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3292 OpCode
.Question
.Flags
= QuestionFlags
;
3293 OpCode
.Flags
= DateFlags
;
3295 if (DefaultsOpCodeHandle
== NULL
) {
3296 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
));
3299 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3300 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
), 0, 1);
3301 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3302 HiiCreateEndOpCode (OpCodeHandle
);
3303 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3307 Create EFI_IFR_TIME_OP opcode.
3309 If OpCodeHandle is NULL, then ASSERT().
3310 If any reserved bits are set in QuestionFlags, then ASSERT().
3311 If any reserved bits are set in TimeFlags, then ASSERT().
3313 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3314 @param[in] QuestionId Question ID
3315 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not
3316 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3317 @param[in] VarOffset Offset in Storage, optional. If TimeFlags is not
3318 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3319 @param[in] Prompt String ID for Prompt
3320 @param[in] Help String ID for Help
3321 @param[in] QuestionFlags Flags in Question Header
3322 @param[in] TimeFlags Flags for time opcode
3323 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3324 is an optional parameter that may be NULL.
3326 @retval NULL There is not enough space left in Buffer to add the opcode.
3327 @retval Other A pointer to the created opcode.
3332 HiiCreateTimeOpCode (
3333 IN VOID
*OpCodeHandle
,
3334 IN EFI_QUESTION_ID QuestionId
,
3335 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3336 IN UINT16 VarOffset
, OPTIONAL
3337 IN EFI_STRING_ID Prompt
,
3338 IN EFI_STRING_ID Help
,
3339 IN UINT8 QuestionFlags
,
3341 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3344 EFI_IFR_TIME OpCode
;
3347 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3348 ASSERT ((TimeFlags
& (~(QF_TIME_HOUR_SUPPRESS
| QF_TIME_MINUTE_SUPPRESS
| QF_TIME_SECOND_SUPPRESS
| QF_TIME_STORAGE
))) == 0);
3350 ZeroMem (&OpCode
, sizeof (OpCode
));
3351 OpCode
.Question
.Header
.Prompt
= Prompt
;
3352 OpCode
.Question
.Header
.Help
= Help
;
3353 OpCode
.Question
.QuestionId
= QuestionId
;
3354 OpCode
.Question
.VarStoreId
= VarStoreId
;
3355 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3356 OpCode
.Question
.Flags
= QuestionFlags
;
3357 OpCode
.Flags
= TimeFlags
;
3359 if (DefaultsOpCodeHandle
== NULL
) {
3360 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
));
3363 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3364 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
), 0, 1);
3365 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3366 HiiCreateEndOpCode (OpCodeHandle
);
3367 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3371 This is the internal worker function to update the data in
3372 a form specified by FormSetGuid, FormId and Label.
3374 @param[in] FormSetGuid The optional Formset GUID.
3375 @param[in] FormId The Form ID.
3376 @param[in] Package The package header.
3377 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR
3378 opcodes to be inserted or replaced in the form.
3379 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode
3380 that marks the end of a replace operation in the form.
3381 @param[out] TempPackage The resultant package.
3383 @retval EFI_SUCCESS The function completes successfully.
3384 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.
3389 InternalHiiUpdateFormPackageData (
3390 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3391 IN EFI_FORM_ID FormId
,
3392 IN EFI_HII_PACKAGE_HEADER
*Package
,
3393 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3394 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3395 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3400 EFI_HII_PACKAGE_HEADER PackageHeader
;
3402 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3403 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3407 UINTN UpdatePackageLength
;
3409 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3410 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3411 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3413 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3414 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3415 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3416 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3420 while (Offset
< PackageHeader
.Length
) {
3421 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3422 BufferPos
+= IfrOpHdr
->Length
;
3423 UpdatePackageLength
+= IfrOpHdr
->Length
;
3426 // Find the matched FormSet and Form
3428 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3429 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3434 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
|| IfrOpHdr
->OpCode
== EFI_IFR_FORM_MAP_OP
) {
3435 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3443 // The matched Form is found, and Update data in this form
3445 if (GetFormSet
&& GetForm
) {
3446 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3447 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3448 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3450 // Remove the original data when End OpCode buffer exist.
3452 if (OpCodeBufferEnd
!= NULL
) {
3453 Offset
+= IfrOpHdr
->Length
;
3454 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3455 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3456 while (Offset
< PackageHeader
.Length
) {
3458 // Search the matched end opcode
3460 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3461 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3465 // Go to the next Op-Code
3467 Offset
+= IfrOpHdr
->Length
;
3468 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3471 if (Offset
>= PackageHeader
.Length
) {
3473 // The end opcode is not found.
3475 return EFI_NOT_FOUND
;
3480 // Insert the updated data
3482 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3483 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3484 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3485 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3487 if (OpCodeBufferEnd
!= NULL
) {
3489 // Add the end opcode
3491 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3492 BufferPos
+= IfrOpHdr
->Length
;
3493 UpdatePackageLength
+= IfrOpHdr
->Length
;
3497 // Copy the left package data.
3499 Offset
+= IfrOpHdr
->Length
;
3500 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3501 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3512 // Go to the next Op-Code
3514 Offset
+= IfrOpHdr
->Length
;
3515 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3520 // The updated opcode buffer is not found.
3522 return EFI_NOT_FOUND
;
3525 // Update the package length.
3527 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3528 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3534 This function updates a form that has previously been registered with the HII
3535 Database. This function will perform at most one update operation.
3537 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3538 comparisons of IFR opcodes are performed from the beginning of the form being
3539 updated until an IFR opcode is found that exactly matches the first IFR opcode
3540 specified by StartOpCodeHandle. The following rules are used to determine if
3541 an insert, replace, or delete operation is performed.
3543 1) If no matches are found, then NULL is returned.
3544 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3545 from StartOpCodeHandle except the first opcode are inserted immediately after
3546 the matching IFR opcode in the form to be updated.
3547 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3548 from the matching IFR opcode until an IFR opcode exactly matches the first
3549 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3550 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3551 is found, then all of the IFR opcodes between the start match and the end
3552 match are deleted from the form being updated and all of the IFR opcodes
3553 from StartOpCodeHandle except the first opcode are inserted immediately after
3554 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3555 IFR instruction, then the result of this operation will delete all of the IFR
3556 opcodes between the start end matches.
3558 If HiiHandle is NULL, then ASSERT().
3559 If StartOpCodeHandle is NULL, then ASSERT().
3561 @param[in] HiiHandle The HII Handle of the form to update.
3562 @param[in] FormSetGuid The Formset GUID of the form to update. This
3563 is an optional parameter that may be NULL.
3564 If it is NULL, all FormSet will be updated.
3565 @param[in] FormId The ID of the form to update.
3566 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
3567 opcodes to be inserted or replaced in the form.
3568 The first IFR instruction in StartOpCodeHandle
3569 is used to find matching IFR opcode in the
3571 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
3572 that marks the end of a replace operation in
3573 the form. This is an optional parameter that
3574 may be NULL. If it is NULL, then an the IFR
3575 opcodes specified by StartOpCodeHandle are
3576 inserted into the form.
3578 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
3579 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
3580 1) The form specified by HiiHandle, FormSetGuid,
3581 and FormId could not be found in the HII Database.
3582 2) No IFR opcodes in the target form match the first
3583 IFR opcode in StartOpCodeHandle.
3584 3) EndOpCOde is not NULL, and no IFR opcodes in the
3585 target form following a matching start opcode match
3586 the first IFR opcode in EndOpCodeHandle.
3587 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
3593 IN EFI_HII_HANDLE HiiHandle
,
3594 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3595 IN EFI_FORM_ID FormId
,
3596 IN VOID
*StartOpCodeHandle
,
3597 IN VOID
*EndOpCodeHandle OPTIONAL
3601 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
3602 UINT32 PackageListLength
;
3604 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
3606 UINT8
*UpdateBufferPos
;
3607 EFI_HII_PACKAGE_HEADER
*Package
;
3608 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
3609 EFI_HII_PACKAGE_HEADER PackageHeader
;
3611 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
3612 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
3615 // Input update data can't be NULL.
3617 ASSERT (HiiHandle
!= NULL
);
3618 ASSERT (StartOpCodeHandle
!= NULL
);
3619 UpdatePackageList
= NULL
;
3621 HiiPackageList
= NULL
;
3624 // Retrieve buffer data from Opcode Handle
3626 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpCodeHandle
;
3627 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpCodeHandle
;
3630 // Get the original package list
3633 HiiPackageList
= NULL
;
3634 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3636 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
3638 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3642 HiiPackageList
= AllocatePool (BufferSize
);
3643 if (HiiPackageList
== NULL
) {
3644 Status
= EFI_OUT_OF_RESOURCES
;
3648 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3649 if (EFI_ERROR (Status
)) {
3654 // Calculate and allocate space for retrieval of IFR data
3656 BufferSize
+= OpCodeBufferStart
->Position
;
3657 UpdatePackageList
= AllocateZeroPool (BufferSize
);
3658 if (UpdatePackageList
== NULL
) {
3659 Status
= EFI_OUT_OF_RESOURCES
;
3664 // Allocate temp buffer to store the temp updated package buffer
3666 TempPacakge
= AllocateZeroPool (BufferSize
);
3667 if (TempPacakge
== NULL
) {
3668 Status
= EFI_OUT_OF_RESOURCES
;
3672 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
3675 // Copy the package list header
3677 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
3678 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3681 // Go through each package to find the matched package and update one by one
3684 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3685 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
3686 while (Offset
< PackageListLength
) {
3687 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
3688 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3689 Offset
+= Package
->Length
;
3691 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
3693 // Check this package is the matched package.
3695 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
3697 // The matched package is found. Its package buffer will be updated by the input new data.
3699 if (!EFI_ERROR(Status
)) {
3705 // Add updated package buffer
3707 Package
= TempPacakge
;
3712 // Add pacakge buffer
3714 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3715 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
3716 UpdateBufferPos
+= PackageHeader
.Length
;
3721 // Update package list length
3723 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
3724 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
3727 // Update Package to show form
3729 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
3732 // Not matched form is found and updated.
3734 Status
= EFI_NOT_FOUND
;
3738 if (HiiPackageList
!= NULL
) {
3739 FreePool (HiiPackageList
);
3742 if (UpdatePackageList
!= NULL
) {
3743 FreePool (UpdatePackageList
);
3746 if (TempPacakge
!= NULL
) {
3747 FreePool (TempPacakge
);