2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2010, 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.
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
;
804 This function checks VarOffset and VarWidth is in the block range.
806 @param BlockArray The block array is to be checked.
807 @param VarOffset Offset of var to the structure
808 @param VarWidth Width of var.
810 @retval TRUE This Var is in the block range.
811 @retval FALSE This Var is not in the block range.
815 IN IFR_BLOCK_DATA
*BlockArray
,
821 IFR_BLOCK_DATA
*BlockData
;
824 // No Request Block array, all vars are got.
826 if (BlockArray
== NULL
) {
831 // Check the input var is in the request block range.
833 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
834 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
835 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
844 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
846 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
848 @param ValueString String in <BlockConfig> format and points to the
849 first character of <Number>.
850 @param ValueData The output value. Caller takes the responsibility
852 @param ValueLength Length of the <Number>, in characters.
854 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
856 @retval EFI_SUCCESS Value of <Number> is outputted in Number
862 InternalHiiGetValueOfNumber (
863 IN EFI_STRING ValueString
,
864 OUT UINT8
**ValueData
,
865 OUT UINTN
*ValueLength
868 EFI_STRING StringPtr
;
875 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
876 ASSERT (*ValueString
!= L
'\0');
879 // Get the length of value string
881 StringPtr
= ValueString
;
882 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
885 Length
= StringPtr
- ValueString
;
888 // Allocate buffer to store the value
890 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
892 return EFI_OUT_OF_RESOURCES
;
896 // Convert character one by one to the value buffer
898 ZeroMem (TemStr
, sizeof (TemStr
));
899 for (Index
= 0; Index
< Length
; Index
++) {
900 TemStr
[0] = ValueString
[Length
- Index
- 1];
901 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
902 if ((Index
& 1) == 0) {
903 Buf
[Index
/2] = DigitUint8
;
905 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
910 // Set the converted value and string length.
913 *ValueLength
= Length
;
918 This internal function parses IFR data to validate current setting.
920 @param ConfigResp ConfigResp string contains the current setting.
921 @param HiiPackageList Point to Hii package list.
922 @param PackageListLength The length of the pacakge.
923 @param VarGuid Guid of the buffer storage.
924 @param VarName Name of the buffer storage.
926 @retval EFI_SUCCESS The current setting is valid.
927 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
928 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
932 InternalHiiValidateCurrentSetting (
933 IN EFI_STRING ConfigResp
,
934 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
935 IN UINTN PackageListLength
,
936 IN EFI_GUID
*VarGuid
,
940 IFR_BLOCK_DATA
*CurrentBlockArray
;
941 IFR_BLOCK_DATA
*BlockData
;
942 IFR_BLOCK_DATA
*NewBlockData
;
943 IFR_BLOCK_DATA VarBlockData
;
944 EFI_STRING StringPtr
;
954 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
955 UINT32 PackageOffset
;
958 EFI_IFR_OP_HEADER
*IfrOpHdr
;
959 EFI_IFR_VARSTORE
*IfrVarStore
;
960 EFI_IFR_ONE_OF
*IfrOneOf
;
961 EFI_IFR_NUMERIC
*IfrNumeric
;
962 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
963 EFI_IFR_CHECKBOX
*IfrCheckBox
;
964 EFI_IFR_STRING
*IfrString
;
969 // 1. Get the current setting to current block data array and Convert them into VarBuffer
973 // Skip ConfigHdr string
975 StringPtr
= ConfigResp
;
976 StringPtr
= StrStr (ConfigResp
, L
"&OFFSET");
977 if (StringPtr
== NULL
) {
979 // No ConfigBlock value is required to be validated.
980 // EFI_SUCCESS directly return.
986 // Initialize the local variables.
990 Status
= EFI_SUCCESS
;
994 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
995 VarBuffer
= AllocateZeroPool (MaxBufferSize
);
996 if (VarBuffer
== NULL
) {
997 return EFI_OUT_OF_RESOURCES
;
1001 // Init CurrentBlockArray
1003 CurrentBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1004 if (CurrentBlockArray
== NULL
) {
1005 Status
= EFI_OUT_OF_RESOURCES
;
1008 InitializeListHead (&CurrentBlockArray
->Entry
);
1011 // Parse each <RequestElement> if exists
1012 // Only <BlockName> format is supported by this help function.
1013 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1015 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1017 // Skip the &OFFSET= string
1019 StringPtr
+= StrLen (L
"&OFFSET=");
1024 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1025 if (EFI_ERROR (Status
)) {
1032 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1034 FreePool (TmpBuffer
);
1037 StringPtr
+= Length
;
1038 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1039 Status
= EFI_INVALID_PARAMETER
;
1042 StringPtr
+= StrLen (L
"&WIDTH=");
1047 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1048 if (EFI_ERROR (Status
)) {
1055 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1057 FreePool (TmpBuffer
);
1060 StringPtr
+= Length
;
1061 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1062 Status
= EFI_INVALID_PARAMETER
;
1066 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1067 Status
= EFI_INVALID_PARAMETER
;
1070 StringPtr
+= StrLen (L
"&VALUE=");
1075 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1076 if (EFI_ERROR (Status
)) {
1080 StringPtr
+= Length
;
1081 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1082 Status
= EFI_INVALID_PARAMETER
;
1087 // Check whether VarBuffer is enough
1089 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1090 VarBuffer
= ReallocatePool (
1092 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1095 if (VarBuffer
== NULL
) {
1096 Status
= EFI_OUT_OF_RESOURCES
;
1099 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1103 // Update the Block with configuration info
1105 CopyMem (VarBuffer
+ Offset
, TmpBuffer
, Width
);
1106 FreePool (TmpBuffer
);
1110 // Set new Block Data
1112 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1113 if (NewBlockData
== NULL
) {
1114 Status
= EFI_OUT_OF_RESOURCES
;
1117 NewBlockData
->Offset
= Offset
;
1118 NewBlockData
->Width
= Width
;
1121 // Insert the new block data into the block data array.
1123 for (Link
= CurrentBlockArray
->Entry
.ForwardLink
; Link
!= &CurrentBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1124 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1125 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1126 if (NewBlockData
->Width
> BlockData
->Width
) {
1127 BlockData
->Width
= NewBlockData
->Width
;
1129 FreePool (NewBlockData
);
1131 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1133 // Insert new block data as the previous one of this link.
1135 InsertTailList (Link
, &NewBlockData
->Entry
);
1141 // Insert new block data into the array tail.
1143 if (Link
== &CurrentBlockArray
->Entry
) {
1144 InsertTailList (Link
, &NewBlockData
->Entry
);
1148 // If '\0', parsing is finished.
1150 if (*StringPtr
== 0) {
1154 // Go to next ConfigBlock
1159 // Merge the aligned block data into the single block data.
1161 Link
= CurrentBlockArray
->Entry
.ForwardLink
;
1162 while ((Link
!= &CurrentBlockArray
->Entry
) && (Link
->ForwardLink
!= &CurrentBlockArray
->Entry
)) {
1163 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1164 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1165 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1166 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1167 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1169 RemoveEntryList (Link
->ForwardLink
);
1170 FreePool (NewBlockData
);
1173 Link
= Link
->ForwardLink
;
1176 if (IsListEmpty (&CurrentBlockArray
->Entry
)) {
1177 Status
= EFI_SUCCESS
;
1182 // 2. Check IFR value is in block data, then Validate Value
1184 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1187 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1188 while (PackageOffset
< PackageListLength
) {
1189 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1192 // Parse IFR opcode from the form package.
1194 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1195 IfrOffset
= sizeof (PacakgeHeader
);
1196 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1197 while (IfrOffset
< PacakgeHeader
.Length
) {
1198 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1200 // Validate current setting to the value built in IFR opcode
1202 switch (IfrOpHdr
->OpCode
) {
1203 case EFI_IFR_VARSTORE_OP
:
1205 // VarStoreId has been found. No further found.
1207 if (IfrVarStore
!= NULL
) {
1211 // Find the matched VarStoreId to the input VarGuid and VarName
1213 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1214 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1215 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1216 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1217 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1222 // The matched VarStore is found.
1224 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1231 case EFI_IFR_FORM_OP
:
1232 case EFI_IFR_FORM_MAP_OP
:
1234 // Check the matched VarStoreId is found.
1236 if (IfrVarStore
== NULL
) {
1237 Status
= EFI_SUCCESS
;
1241 case EFI_IFR_ONE_OF_OP
:
1243 // Check whether current value is the one of option.
1247 // OneOf question is not in IFR Form. This IFR form is not valid.
1249 if (IfrVarStore
== NULL
) {
1250 Status
= EFI_INVALID_PARAMETER
;
1254 // Check whether this question is for the requested varstore.
1256 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1257 if (IfrOneOf
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1262 // Get Offset by Question header and Width by DataType Flags
1264 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1265 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1267 // Check whether this question is in current block array.
1269 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1271 // This question is not in the current configuration string. Skip it.
1276 // Check this var question is in the var storage
1278 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1280 // This question exceeds the var store size.
1282 Status
= EFI_INVALID_PARAMETER
;
1287 // Get the current value for oneof opcode
1290 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1292 // Set Block Data, to be checked in the following Oneof option opcode.
1294 VarBlockData
.Offset
= Offset
;
1295 VarBlockData
.Width
= Width
;
1296 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1297 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1299 case EFI_IFR_NUMERIC_OP
:
1301 // Check the current value is in the numeric range.
1305 // Numeric question is not in IFR Form. This IFR form is not valid.
1307 if (IfrVarStore
== NULL
) {
1308 Status
= EFI_INVALID_PARAMETER
;
1312 // Check whether this question is for the requested varstore.
1314 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1315 if (IfrNumeric
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1320 // Get Offset by Question header and Width by DataType Flags
1322 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1323 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1325 // Check whether this question is in current block array.
1327 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1329 // This question is not in the current configuration string. Skip it.
1334 // Check this var question is in the var storage
1336 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1338 // This question exceeds the var store size.
1340 Status
= EFI_INVALID_PARAMETER
;
1345 // Check the current value is in the numeric range.
1348 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1349 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1350 case EFI_IFR_NUMERIC_SIZE_1
:
1351 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1353 // Not in the valid range.
1355 Status
= EFI_INVALID_PARAMETER
;
1359 case EFI_IFR_NUMERIC_SIZE_2
:
1360 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1362 // Not in the valid range.
1364 Status
= EFI_INVALID_PARAMETER
;
1368 case EFI_IFR_NUMERIC_SIZE_4
:
1369 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1371 // Not in the valid range.
1373 Status
= EFI_INVALID_PARAMETER
;
1377 case EFI_IFR_NUMERIC_SIZE_8
:
1378 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1380 // Not in the valid range.
1382 Status
= EFI_INVALID_PARAMETER
;
1389 case EFI_IFR_CHECKBOX_OP
:
1391 // Check value is BOOLEAN type, only 0 and 1 is valid.
1395 // CheckBox question is not in IFR Form. This IFR form is not valid.
1397 if (IfrVarStore
== NULL
) {
1398 Status
= EFI_INVALID_PARAMETER
;
1403 // Check whether this question is for the requested varstore.
1405 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1406 if (IfrCheckBox
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1411 // Get Offset by Question header
1413 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1414 Width
= (UINT16
) sizeof (BOOLEAN
);
1416 // Check whether this question is in current block array.
1418 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1420 // This question is not in the current configuration string. Skip it.
1425 // Check this var question is in the var storage
1427 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1429 // This question exceeds the var store size.
1431 Status
= EFI_INVALID_PARAMETER
;
1436 // Boolean type, only 1 and 0 is valid.
1438 if (*(VarBuffer
+ Offset
) > 1) {
1439 Status
= EFI_INVALID_PARAMETER
;
1444 case EFI_IFR_STRING_OP
:
1446 // Check current string length is less than maxsize
1450 // CheckBox question is not in IFR Form. This IFR form is not valid.
1452 if (IfrVarStore
== NULL
) {
1453 Status
= EFI_INVALID_PARAMETER
;
1458 // Check whether this question is for the requested varstore.
1460 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1461 if (IfrString
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1466 // Get Offset/Width by Question header and OneOf Flags
1468 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1469 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1471 // Check whether this question is in current block array.
1473 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1475 // This question is not in the current configuration string. Skip it.
1480 // Check this var question is in the var storage
1482 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1484 // This question exceeds the var store size.
1486 Status
= EFI_INVALID_PARAMETER
;
1491 // Check current string length is less than maxsize
1493 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1494 Status
= EFI_INVALID_PARAMETER
;
1498 case EFI_IFR_ONE_OF_OPTION_OP
:
1500 // Opcode Scope is zero. This one of option is not to be checked.
1502 if (VarBlockData
.Scope
== 0) {
1507 // Only check for OneOf and OrderList opcode
1509 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1510 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1512 // Check current value is the value of one of option.
1514 if (VarValue
== IfrOneOfOption
->Value
.u64
) {
1516 // The value is one of option value.
1517 // Set OpCode to Zero, don't need check again.
1519 VarBlockData
.OpCode
= 0;
1524 case EFI_IFR_END_OP
:
1526 // Decrease opcode scope for the validated opcode
1528 if (VarBlockData
.Scope
> 0) {
1529 VarBlockData
.Scope
--;
1533 // OneOf value doesn't belong to one of option value.
1535 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1536 Status
= EFI_INVALID_PARAMETER
;
1542 // Increase Scope for the validated opcode
1544 if (VarBlockData
.Scope
> 0) {
1545 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1550 // Go to the next opcode
1552 IfrOffset
+= IfrOpHdr
->Length
;
1555 // Only one form is in a package list.
1561 // Go to next package.
1563 PackageOffset
+= PacakgeHeader
.Length
;
1567 if (VarBuffer
!= NULL
) {
1568 FreePool (VarBuffer
);
1571 if (CurrentBlockArray
!= NULL
) {
1573 // Free Link Array CurrentBlockArray
1575 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1576 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1577 RemoveEntryList (&BlockData
->Entry
);
1578 FreePool (BlockData
);
1580 FreePool (CurrentBlockArray
);
1587 This function parses the input ConfigRequest string and its matched IFR code
1588 string for setting default value and validating current setting.
1590 1. For setting default action, Reset the default value specified by DefaultId
1591 to the driver configuration got by Request string.
1592 2. For validating current setting, Validate the current configuration
1593 by parsing HII form IFR opcode.
1595 NULL request string support depends on the ExportConfig interface of
1596 HiiConfigRouting protocol in UEFI specification.
1598 @param Request A null-terminated Unicode string in
1599 <MultiConfigRequest> format. It can be NULL.
1600 If it is NULL, all current configuration for the
1601 entirety of the current HII database will be validated.
1602 If it is NULL, all configuration for the
1603 entirety of the current HII database will be reset.
1604 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1605 @param ActionType Action supports setting defaults and validate current setting.
1607 @retval TURE Action runs successfully.
1608 @retval FALSE Action is not valid or Action can't be executed successfully..
1612 InternalHiiIfrValueAction (
1613 IN CONST EFI_STRING Request
, OPTIONAL
1614 IN UINT16 DefaultId
,
1618 EFI_STRING ConfigAltResp
;
1619 EFI_STRING ConfigAltHdr
;
1620 EFI_STRING ConfigResp
;
1621 EFI_STRING Progress
;
1622 EFI_STRING StringPtr
;
1623 EFI_STRING StringHdr
;
1625 EFI_HANDLE DriverHandle
;
1626 EFI_HANDLE TempDriverHandle
;
1627 EFI_HII_HANDLE
*HiiHandleBuffer
;
1628 EFI_HII_HANDLE HiiHandle
;
1632 EFI_STRING_ID DefaultName
;
1636 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1637 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1638 UINT32 PackageOffset
;
1639 UINTN PackageListLength
;
1640 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1641 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1642 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1644 ConfigAltResp
= NULL
;
1649 ConfigAltHdr
= NULL
;
1650 HiiHandleBuffer
= NULL
;
1652 TempDriverHandle
= NULL
;
1655 HiiPackageList
= NULL
;
1658 // Only support set default and validate setting action.
1660 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
1665 // Get the full requested value and deault value string.
1667 if (Request
!= NULL
) {
1668 Status
= gHiiConfigRouting
->ExtractConfig (
1675 Status
= gHiiConfigRouting
->ExportConfig (
1681 if (EFI_ERROR (Status
)) {
1685 StringPtr
= ConfigAltResp
;
1687 while (StringPtr
!= L
'\0') {
1689 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1691 StringHdr
= StringPtr
;
1696 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1697 Status
= EFI_INVALID_PARAMETER
;
1700 StringPtr
+= StrLen (L
"GUID=");
1701 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
1702 if (EFI_ERROR (Status
)) {
1707 // Get Name value VarName
1709 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1712 if (*StringPtr
== L
'\0') {
1713 Status
= EFI_INVALID_PARAMETER
;
1716 StringPtr
+= StrLen (L
"&NAME=");
1717 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
1718 if (EFI_ERROR (Status
)) {
1723 // Get Path value DevicePath
1725 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1728 if (*StringPtr
== L
'\0') {
1729 Status
= EFI_INVALID_PARAMETER
;
1732 StringPtr
+= StrLen (L
"&PATH=");
1733 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
1734 if (EFI_ERROR (Status
)) {
1739 // Get the Driver handle by the got device path.
1741 TempDevicePath
= DevicePath
;
1742 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
1743 if (EFI_ERROR (Status
)) {
1748 // Find the matched Hii Handle for the found Driver handle
1750 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
1751 if (HiiHandleBuffer
== NULL
) {
1752 Status
= EFI_NOT_FOUND
;
1756 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
1757 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
1758 if (TempDriverHandle
== DriverHandle
) {
1763 HiiHandle
= HiiHandleBuffer
[Index
];
1764 FreePool (HiiHandleBuffer
);
1766 if (HiiHandle
== NULL
) {
1768 // This request string has no its Hii package.
1769 // Its default value and validating can't execute by parsing IFR data.
1770 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
1772 Status
= EFI_SUCCESS
;
1773 goto NextConfigAltResp
;
1777 // 2. Get DefaultName string ID by parsing the PacakgeList
1781 // Get HiiPackage by HiiHandle
1783 PackageListLength
= 0;
1784 HiiPackageList
= NULL
;
1785 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1788 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1790 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1791 Status
= EFI_INVALID_PARAMETER
;
1795 HiiPackageList
= AllocatePool (PackageListLength
);
1796 if (HiiPackageList
== NULL
) {
1797 Status
= EFI_OUT_OF_RESOURCES
;
1802 // Get PackageList on HiiHandle
1804 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1805 if (EFI_ERROR (Status
)) {
1810 // Parse the form package and get the default name string ID.
1812 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1813 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1814 Status
= EFI_NOT_FOUND
;
1815 while (PackageOffset
< PackageListLength
) {
1816 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1819 // Parse IFR opcode to get default store opcode
1821 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1822 IfrOffset
= sizeof (PacakgeHeader
);
1823 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1824 while (IfrOffset
< PacakgeHeader
.Length
) {
1825 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1827 // Match DefaultId to find its DefaultName
1829 if (IfrOpHdr
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
) {
1830 if (((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
== DefaultId
) {
1831 DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
1832 Status
= EFI_SUCCESS
;
1836 IfrOffset
+= IfrOpHdr
->Length
;
1839 // Only one form is in a package list.
1845 // Go to next package.
1847 PackageOffset
+= PacakgeHeader
.Length
;
1851 // Not found the matched default string ID
1853 if (EFI_ERROR (Status
)) {
1854 Status
= EFI_SUCCESS
;
1855 goto NextConfigAltResp
;
1860 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
1861 // Get the default configuration string according to the found default name string ID.
1863 Status
= gHiiConfigRouting
->GetAltConfig (
1869 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultName
:NULL
, // it can be NULL to get the current setting.
1874 // The required setting can't be found. So, it is not required to be validated and set.
1876 if (EFI_ERROR (Status
)) {
1877 Status
= EFI_SUCCESS
;
1878 goto NextConfigAltResp
;
1881 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
1883 if (StrStr (ConfigResp
, L
"&OFFSET=") == NULL
) {
1884 goto NextConfigAltResp
;
1888 // 4. Set the default configuration information or Validate current setting by parse IFR code.
1889 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1891 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1893 // Set the default configuration information.
1895 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
1898 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1900 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
);
1903 if (EFI_ERROR (Status
)) {
1909 // Free the allocated pacakge buffer and the got ConfigResp string.
1911 if (HiiPackageList
!= NULL
) {
1912 FreePool (HiiPackageList
);
1913 HiiPackageList
= NULL
;
1916 if (ConfigResp
!= NULL
) {
1917 FreePool (ConfigResp
);
1922 // Free the allocated buffer.
1930 FreePool (DevicePath
);
1934 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
1938 // Get and Skip ConfigHdr
1940 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1943 if (*StringPtr
== L
'\0') {
1948 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
1949 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
1951 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
1952 if (ConfigAltHdr
== NULL
) {
1953 Status
= EFI_OUT_OF_RESOURCES
;
1956 StrCpy (ConfigAltHdr
, L
"&");
1957 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
1958 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
1961 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
1963 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
1964 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
1965 if (*StringPtr
== L
'\0') {
1971 // Free the allocated ConfigAltHdr string
1973 FreePool (ConfigAltHdr
);
1974 if (*StringPtr
== L
'\0') {
1979 // Find &GUID as the next ConfigHdr
1981 StringPtr
= StrStr (StringPtr
, L
"&GUID");
1982 if (StringPtr
== NULL
) {
1993 if (VarGuid
!= NULL
) {
1997 if (VarName
!= NULL
) {
2001 if (DevicePath
!= NULL
) {
2002 FreePool (DevicePath
);
2005 if (ConfigResp
!= NULL
) {
2006 FreePool (ConfigResp
);
2009 if (ConfigAltResp
!= NULL
) {
2010 FreePool (ConfigAltResp
);
2013 if (HiiPackageList
!= NULL
) {
2014 FreePool (HiiPackageList
);
2017 if (EFI_ERROR (Status
)) {
2025 Validate the current configuration by parsing HII form IFR opcode.
2027 NULL request string support depends on the ExportConfig interface of
2028 HiiConfigRouting protocol in UEFI specification.
2030 @param Request A null-terminated Unicode string in
2031 <MultiConfigRequest> format. It can be NULL.
2032 If it is NULL, all current configuration for the
2033 entirety of the current HII database will be validated.
2035 @retval TURE Current configuration is valid.
2036 @retval FALSE Current configuration is invalid.
2040 HiiValidateSettings (
2041 IN CONST EFI_STRING Request OPTIONAL
2044 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2048 Reset the default value specified by DefaultId to the driver
2049 configuration got by Request string.
2051 NULL request string support depends on the ExportConfig interface of
2052 HiiConfigRouting protocol in UEFI specification.
2054 @param Request A null-terminated Unicode string in
2055 <MultiConfigRequest> format. It can be NULL.
2056 If it is NULL, all configuration for the
2057 entirety of the current HII database will be reset.
2058 @param DefaultId Specifies the type of defaults to retrieve.
2060 @retval TURE The default value is set successfully.
2061 @retval FALSE The default value can't be found and set.
2066 IN CONST EFI_STRING Request
, OPTIONAL
2070 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2074 Determines if two values in config strings match.
2076 Compares the substring between StartSearchString and StopSearchString in
2077 FirstString to the substring between StartSearchString and StopSearchString
2078 in SecondString. If the two substrings match, then TRUE is returned. If the
2079 two substrings do not match, then FALSE is returned.
2081 If FirstString is NULL, then ASSERT().
2082 If SecondString is NULL, then ASSERT().
2083 If StartSearchString is NULL, then ASSERT().
2084 If StopSearchString is NULL, then ASSERT().
2086 @param FirstString Pointer to the first Null-terminated Unicode string.
2087 @param SecondString Pointer to the second Null-terminated Unicode string.
2088 @param StartSearchString Pointer to the Null-terminated Unicode string that
2089 marks the start of the value string to compare.
2090 @param StopSearchString Pointer to the Null-terminated Unicode string that
2091 marks the end of the value string to compare.
2093 @retval FALSE StartSearchString is not present in FirstString.
2094 @retval FALSE StartSearchString is not present in SecondString.
2095 @retval FALSE StopSearchString is not present in FirstString.
2096 @retval FALSE StopSearchString is not present in SecondString.
2097 @retval FALSE The length of the substring in FirstString is not the
2098 same length as the substring in SecondString.
2099 @retval FALSE The value string in FirstString does not matche the
2100 value string in SecondString.
2101 @retval TRUE The value string in FirstString matches the value
2102 string in SecondString.
2107 InternalHiiCompareSubString (
2108 IN CHAR16
*FirstString
,
2109 IN CHAR16
*SecondString
,
2110 IN CHAR16
*StartSearchString
,
2111 IN CHAR16
*StopSearchString
2114 CHAR16
*EndFirstString
;
2115 CHAR16
*EndSecondString
;
2117 ASSERT (FirstString
!= NULL
);
2118 ASSERT (SecondString
!= NULL
);
2119 ASSERT (StartSearchString
!= NULL
);
2120 ASSERT (StopSearchString
!= NULL
);
2122 FirstString
= StrStr (FirstString
, StartSearchString
);
2123 if (FirstString
== NULL
) {
2127 SecondString
= StrStr (SecondString
, StartSearchString
);
2128 if (SecondString
== NULL
) {
2132 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2133 if (EndFirstString
== NULL
) {
2137 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2138 if (EndSecondString
== NULL
) {
2142 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2146 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2150 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2152 If ConfigHdr is NULL, then ASSERT().
2154 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2155 @param[in] Guid GUID of the storage.
2156 @param[in] Name NAME of the storage.
2158 @retval TRUE Routing information matches <ConfigHdr>.
2159 @retval FALSE Routing information does not match <ConfigHdr>.
2164 HiiIsConfigHdrMatch (
2165 IN CONST EFI_STRING ConfigHdr
,
2166 IN CONST EFI_GUID
*Guid
, OPTIONAL
2167 IN CONST CHAR16
*Name OPTIONAL
2170 EFI_STRING CompareConfigHdr
;
2173 ASSERT (ConfigHdr
!= NULL
);
2176 // Use Guid and Name to generate a <ConfigHdr> string
2178 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2179 if (CompareConfigHdr
== NULL
) {
2186 // Compare GUID value strings
2188 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2191 if (Result
&& Name
!= NULL
) {
2193 // Compare NAME value strings
2195 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2199 // Free the <ConfigHdr> string
2201 FreePool (CompareConfigHdr
);
2207 Retrieves uncommitted data from the Form Browser and converts it to a binary
2210 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2211 parameter that may be NULL.
2212 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2213 is an optional parameter that may be NULL.
2214 @param[in] BufferSize Length in bytes of buffer to hold retrieved data.
2215 @param[out] Buffer Buffer of data to be updated.
2217 @retval FALSE The uncommitted data could not be retrieved.
2218 @retval TRUE The uncommitted data was retrieved.
2224 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2225 IN CONST CHAR16
*VariableName
, OPTIONAL
2226 IN UINTN BufferSize
,
2230 EFI_STRING ResultsData
;
2232 EFI_STRING ConfigResp
;
2237 // Retrieve the results data from the Browser Callback
2239 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2240 if (ResultsData
== NULL
) {
2245 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2247 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2248 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2249 ConfigResp
= AllocateZeroPool (Size
);
2250 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2253 // Free the allocated buffer
2255 FreePool (ResultsData
);
2256 if (ConfigResp
== NULL
) {
2261 // Convert <ConfigResp> to a buffer
2263 Status
= gHiiConfigRouting
->ConfigToBlock (
2271 // Free the allocated buffer
2273 FreePool (ConfigResp
);
2275 if (EFI_ERROR (Status
)) {
2283 Updates uncommitted data in the Form Browser.
2285 If Buffer is NULL, then ASSERT().
2287 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2288 parameter that may be NULL.
2289 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2290 is an optional parameter that may be NULL.
2291 @param[in] BufferSize Length, in bytes, of Buffer.
2292 @param[in] Buffer Buffer of data to commit.
2293 @param[in] RequestElement An optional field to specify which part of the
2294 buffer data will be send back to Browser. If NULL,
2295 the whole buffer of data will be committed to
2297 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2299 @retval FALSE The uncommitted data could not be updated.
2300 @retval TRUE The uncommitted data was updated.
2306 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2307 IN CONST CHAR16
*VariableName
, OPTIONAL
2308 IN UINTN BufferSize
,
2309 IN CONST UINT8
*Buffer
,
2310 IN CONST CHAR16
*RequestElement OPTIONAL
2314 EFI_STRING ConfigRequest
;
2315 EFI_STRING ConfigResp
;
2316 EFI_STRING ResultsData
;
2318 ASSERT (Buffer
!= NULL
);
2321 // Construct <ConfigRequest>
2323 if (RequestElement
== NULL
) {
2325 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2326 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2328 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2329 ConfigRequest
= AllocateZeroPool (Size
);
2330 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2333 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2334 // followed by <RequestElement> followed by a Null-terminator
2336 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2337 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2338 ConfigRequest
= AllocateZeroPool (Size
);
2339 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2341 if (ConfigRequest
== NULL
) {
2346 // Convert <ConfigRequest> to <ConfigResp>
2348 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2349 FreePool (ConfigRequest
);
2350 if (ConfigResp
== NULL
) {
2355 // Set data in the uncommitted browser state information
2357 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2358 FreePool (ConfigResp
);
2360 return (BOOLEAN
)(ResultsData
!= NULL
);
2363 /////////////////////////////////////////
2364 /////////////////////////////////////////
2366 /////////////////////////////////////////
2367 /////////////////////////////////////////
2369 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2375 } HII_LIB_OPCODE_BUFFER
;
2378 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2380 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2381 1, // EFI_IFR_TYPE_NUM_SIZE_8
2382 2, // EFI_IFR_TYPE_NUM_SIZE_16
2383 4, // EFI_IFR_TYPE_NUM_SIZE_32
2384 8, // EFI_IFR_TYPE_NUM_SIZE_64
2385 1, // EFI_IFR_TYPE_BOOLEAN
2386 3, // EFI_IFR_TYPE_TIME
2387 4, // EFI_IFR_TYPE_DATE
2388 2 // EFI_IFR_TYPE_STRING
2392 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2393 HiiFreeOpCodeHandle().
2395 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2396 @retval Other A new OpCode handle.
2401 HiiAllocateOpCodeHandle (
2405 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2407 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2408 if (OpCodeBuffer
== NULL
) {
2411 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2412 if (OpCodeBuffer
->Buffer
== NULL
) {
2413 FreePool (OpCodeBuffer
);
2416 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2417 OpCodeBuffer
->Position
= 0;
2418 return (VOID
*)OpCodeBuffer
;
2422 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().
2423 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2424 Handle are also freed.
2426 If OpCodeHandle is NULL, then ASSERT().
2428 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2433 HiiFreeOpCodeHandle (
2437 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2439 ASSERT (OpCodeHandle
!= NULL
);
2441 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2442 if (OpCodeBuffer
->Buffer
!= NULL
) {
2443 FreePool (OpCodeBuffer
->Buffer
);
2445 FreePool (OpCodeBuffer
);
2449 Internal function gets the current position of opcode buffer.
2451 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2453 @return Current position of opcode buffer.
2457 InternalHiiOpCodeHandlePosition (
2458 IN VOID
*OpCodeHandle
2461 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2465 Internal function gets the start pointer of opcode buffer.
2467 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2469 @return Pointer to the opcode buffer base.
2473 InternalHiiOpCodeHandleBuffer (
2474 IN VOID
*OpCodeHandle
2477 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2481 Internal function reserves the enough buffer for current opcode.
2482 When the buffer is not enough, Opcode buffer will be extended.
2484 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2485 @param[in] Size Size of current opcode.
2487 @return Pointer to the current opcode.
2491 InternalHiiGrowOpCodeHandle (
2492 IN VOID
*OpCodeHandle
,
2496 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2499 ASSERT (OpCodeHandle
!= NULL
);
2501 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2502 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2503 Buffer
= ReallocatePool (
2504 OpCodeBuffer
->BufferSize
,
2505 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2506 OpCodeBuffer
->Buffer
2508 if (Buffer
== NULL
) {
2511 OpCodeBuffer
->Buffer
= Buffer
;
2512 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2514 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2515 OpCodeBuffer
->Position
+= Size
;
2520 Internal function creates opcode based on the template opcode.
2522 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2523 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2524 @param[in] OpCode OpCode IFR value.
2525 @param[in] OpCodeSize Size of opcode.
2526 @param[in] ExtensionSize Size of extended opcode.
2527 @param[in] Scope Scope bit of opcode.
2529 @return Pointer to the current opcode with opcode data.
2533 InternalHiiCreateOpCodeExtended (
2534 IN VOID
*OpCodeHandle
,
2535 IN VOID
*OpCodeTemplate
,
2537 IN UINTN OpCodeSize
,
2538 IN UINTN ExtensionSize
,
2542 EFI_IFR_OP_HEADER
*Header
;
2545 ASSERT (OpCodeTemplate
!= NULL
);
2546 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2548 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2549 Header
->OpCode
= OpCode
;
2550 Header
->Scope
= Scope
;
2551 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2552 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2553 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2557 Internal function creates opcode based on the template opcode for the normal opcode.
2559 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2560 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2561 @param[in] OpCode OpCode IFR value.
2562 @param[in] OpCodeSize Size of opcode.
2564 @return Pointer to the current opcode with opcode data.
2568 InternalHiiCreateOpCode (
2569 IN VOID
*OpCodeHandle
,
2570 IN VOID
*OpCodeTemplate
,
2575 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2579 Append raw opcodes to an OpCodeHandle.
2581 If OpCodeHandle is NULL, then ASSERT().
2582 If RawBuffer is NULL, then ASSERT();
2584 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2585 @param[in] RawBuffer Buffer of opcodes to append.
2586 @param[in] RawBufferSize The size, in bytes, of Buffer.
2588 @retval NULL There is not enough space left in Buffer to add the opcode.
2589 @retval Other A pointer to the appended opcodes.
2594 HiiCreateRawOpCodes (
2595 IN VOID
*OpCodeHandle
,
2596 IN UINT8
*RawBuffer
,
2597 IN UINTN RawBufferSize
2602 ASSERT (RawBuffer
!= NULL
);
2604 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2605 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2609 Append opcodes from one OpCode Handle to another OpCode handle.
2611 If OpCodeHandle is NULL, then ASSERT().
2612 If RawOpCodeHandle is NULL, then ASSERT();
2614 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2615 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2617 @retval NULL There is not enough space left in Buffer to add the opcode.
2618 @retval Other A pointer to the appended opcodes.
2623 InternalHiiAppendOpCodes (
2624 IN VOID
*OpCodeHandle
,
2625 IN VOID
*RawOpCodeHandle
2628 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2630 ASSERT (RawOpCodeHandle
!= NULL
);
2632 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2633 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2637 Create EFI_IFR_END_OP opcode.
2639 If OpCodeHandle is NULL, then ASSERT().
2641 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2643 @retval NULL There is not enough space left in Buffer to add the opcode.
2644 @retval Other A pointer to the created opcode.
2649 HiiCreateEndOpCode (
2650 IN VOID
*OpCodeHandle
2655 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2659 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2661 If OpCodeHandle is NULL, then ASSERT().
2662 If Type is invalid, then ASSERT().
2663 If Flags is invalid, then ASSERT().
2665 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2666 @param[in] StringId StringId for the option
2667 @param[in] Flags Flags for the option
2668 @param[in] Type Type for the option
2669 @param[in] Value Value for the option
2671 @retval NULL There is not enough space left in Buffer to add the opcode.
2672 @retval Other A pointer to the created opcode.
2677 HiiCreateOneOfOptionOpCode (
2678 IN VOID
*OpCodeHandle
,
2685 EFI_IFR_ONE_OF_OPTION OpCode
;
2687 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2689 ZeroMem (&OpCode
, sizeof (OpCode
));
2690 OpCode
.Option
= StringId
;
2691 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2693 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2695 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, sizeof (OpCode
));
2699 Create EFI_IFR_DEFAULT_OP opcode.
2701 If OpCodeHandle is NULL, then ASSERT().
2702 If Type is invalid, then ASSERT().
2704 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2705 @param[in] DefaultId DefaultId for the default
2706 @param[in] Type Type for the default
2707 @param[in] Value Value for the default
2709 @retval NULL There is not enough space left in Buffer to add the opcode.
2710 @retval Other A pointer to the created opcode.
2715 HiiCreateDefaultOpCode (
2716 IN VOID
*OpCodeHandle
,
2717 IN UINT16 DefaultId
,
2722 EFI_IFR_DEFAULT OpCode
;
2724 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2726 ZeroMem (&OpCode
, sizeof (OpCode
));
2728 OpCode
.DefaultId
= DefaultId
;
2729 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2731 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, sizeof (OpCode
));
2735 Create EFI_IFR_GUID opcode.
2737 If OpCodeHandle is NULL, then ASSERT().
2738 If Guid is NULL, then ASSERT().
2739 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
2741 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2742 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
2743 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
2744 optional parameter that may be NULL. If this
2745 parameter is NULL, then the GUID extension
2746 region of the created opcode is filled with zeros.
2747 If this parameter is not NULL, then the GUID
2748 extension region of GuidData will be copied to
2749 the GUID extension region of the created opcode.
2750 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
2751 must be >= sizeof(EFI_IFR_GUID).
2753 @retval NULL There is not enough space left in Buffer to add the opcode.
2754 @retval Other A pointer to the created opcode.
2759 HiiCreateGuidOpCode (
2760 IN VOID
*OpCodeHandle
,
2761 IN CONST EFI_GUID
*Guid
,
2762 IN CONST VOID
*GuidOpCode
, OPTIONAL
2766 EFI_IFR_GUID OpCode
;
2767 EFI_IFR_GUID
*OpCodePointer
;
2769 ASSERT (Guid
!= NULL
);
2770 ASSERT (OpCodeSize
>= sizeof (OpCode
));
2772 ZeroMem (&OpCode
, sizeof (OpCode
));
2773 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
2775 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
2780 OpCodeSize
- sizeof (OpCode
),
2783 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
2784 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
2786 return (UINT8
*)OpCodePointer
;
2790 Create EFI_IFR_ACTION_OP opcode.
2792 If OpCodeHandle is NULL, then ASSERT().
2793 If any reserved bits are set in QuestionFlags, then ASSERT().
2795 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2796 @param[in] QuestionId Question ID
2797 @param[in] Prompt String ID for Prompt
2798 @param[in] Help String ID for Help
2799 @param[in] QuestionFlags Flags in Question Header
2800 @param[in] QuestionConfig String ID for configuration
2802 @retval NULL There is not enough space left in Buffer to add the opcode.
2803 @retval Other A pointer to the created opcode.
2808 HiiCreateActionOpCode (
2809 IN VOID
*OpCodeHandle
,
2810 IN EFI_QUESTION_ID QuestionId
,
2811 IN EFI_STRING_ID Prompt
,
2812 IN EFI_STRING_ID Help
,
2813 IN UINT8 QuestionFlags
,
2814 IN EFI_STRING_ID QuestionConfig
2817 EFI_IFR_ACTION OpCode
;
2819 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2821 ZeroMem (&OpCode
, sizeof (OpCode
));
2822 OpCode
.Question
.QuestionId
= QuestionId
;
2823 OpCode
.Question
.Header
.Prompt
= Prompt
;
2824 OpCode
.Question
.Header
.Help
= Help
;
2825 OpCode
.Question
.Flags
= QuestionFlags
;
2826 OpCode
.QuestionConfig
= QuestionConfig
;
2828 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
2832 Create EFI_IFR_SUBTITLE_OP opcode.
2834 If OpCodeHandle is NULL, then ASSERT().
2835 If any reserved bits are set in Flags, then ASSERT().
2836 If Scope > 1, then ASSERT().
2838 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2839 @param[in] Prompt String ID for Prompt
2840 @param[in] Help String ID for Help
2841 @param[in] Flags Subtitle opcode flags
2842 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
2843 0 if this opcode is within the current scope.
2845 @retval NULL There is not enough space left in Buffer to add the opcode.
2846 @retval Other A pointer to the created opcode.
2851 HiiCreateSubTitleOpCode (
2852 IN VOID
*OpCodeHandle
,
2853 IN EFI_STRING_ID Prompt
,
2854 IN EFI_STRING_ID Help
,
2859 EFI_IFR_SUBTITLE OpCode
;
2861 ASSERT (Scope
<= 1);
2862 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
2864 ZeroMem (&OpCode
, sizeof (OpCode
));
2865 OpCode
.Statement
.Prompt
= Prompt
;
2866 OpCode
.Statement
.Help
= Help
;
2867 OpCode
.Flags
= Flags
;
2869 return InternalHiiCreateOpCodeExtended (
2872 EFI_IFR_SUBTITLE_OP
,
2880 Create EFI_IFR_REF_OP opcode.
2882 If OpCodeHandle is NULL, then ASSERT().
2883 If any reserved bits are set in QuestionFlags, then ASSERT().
2885 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2886 @param[in] FormId Destination Form ID
2887 @param[in] Prompt String ID for Prompt
2888 @param[in] Help String ID for Help
2889 @param[in] QuestionFlags Flags in Question Header
2890 @param[in] QuestionId Question ID
2892 @retval NULL There is not enough space left in Buffer to add the opcode.
2893 @retval Other A pointer to the created opcode.
2898 HiiCreateGotoOpCode (
2899 IN VOID
*OpCodeHandle
,
2900 IN EFI_FORM_ID FormId
,
2901 IN EFI_STRING_ID Prompt
,
2902 IN EFI_STRING_ID Help
,
2903 IN UINT8 QuestionFlags
,
2904 IN EFI_QUESTION_ID QuestionId
2909 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2911 ZeroMem (&OpCode
, sizeof (OpCode
));
2912 OpCode
.Question
.Header
.Prompt
= Prompt
;
2913 OpCode
.Question
.Header
.Help
= Help
;
2914 OpCode
.Question
.QuestionId
= QuestionId
;
2915 OpCode
.Question
.Flags
= QuestionFlags
;
2916 OpCode
.FormId
= FormId
;
2918 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
2922 Create EFI_IFR_CHECKBOX_OP opcode.
2924 If OpCodeHandle is NULL, then ASSERT().
2925 If any reserved bits are set in QuestionFlags, then ASSERT().
2926 If any reserved bits are set in CheckBoxFlags, then ASSERT().
2928 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2929 @param[in] QuestionId Question ID
2930 @param[in] VarStoreId Storage ID
2931 @param[in] VarOffset Offset in Storage
2932 @param[in] Prompt String ID for Prompt
2933 @param[in] Help String ID for Help
2934 @param[in] QuestionFlags Flags in Question Header
2935 @param[in] CheckBoxFlags Flags for checkbox opcode
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 HiiCreateCheckBoxOpCode (
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 CheckBoxFlags
,
2954 IN VOID
*DefaultsOpCodeHandle OPTIONAL
2957 EFI_IFR_CHECKBOX OpCode
;
2960 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
2962 ZeroMem (&OpCode
, sizeof (OpCode
));
2963 OpCode
.Question
.QuestionId
= QuestionId
;
2964 OpCode
.Question
.VarStoreId
= VarStoreId
;
2965 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
2966 OpCode
.Question
.Header
.Prompt
= Prompt
;
2967 OpCode
.Question
.Header
.Help
= Help
;
2968 OpCode
.Question
.Flags
= QuestionFlags
;
2969 OpCode
.Flags
= CheckBoxFlags
;
2971 if (DefaultsOpCodeHandle
== NULL
) {
2972 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
2975 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
2976 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
2977 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
2978 HiiCreateEndOpCode (OpCodeHandle
);
2979 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
2983 Create EFI_IFR_NUMERIC_OP opcode.
2985 If OpCodeHandle is NULL, then ASSERT().
2986 If any reserved bits are set in QuestionFlags, then ASSERT().
2987 If any reserved bits are set in NumericFlags, then ASSERT().
2989 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2990 @param[in] QuestionId Question ID
2991 @param[in] VarStoreId Storage ID
2992 @param[in] VarOffset Offset in Storage
2993 @param[in] Prompt String ID for Prompt
2994 @param[in] Help String ID for Help
2995 @param[in] QuestionFlags Flags in Question Header
2996 @param[in] NumericFlags Flags for numeric opcode
2997 @param[in] Minimum Numeric minimum value
2998 @param[in] Maximum Numeric maximum value
2999 @param[in] Step Numeric step for edit
3000 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3001 is an optional parameter that may be NULL.
3003 @retval NULL There is not enough space left in Buffer to add the opcode.
3004 @retval Other A pointer to the created opcode.
3009 HiiCreateNumericOpCode (
3010 IN VOID
*OpCodeHandle
,
3011 IN EFI_QUESTION_ID QuestionId
,
3012 IN EFI_VARSTORE_ID VarStoreId
,
3013 IN UINT16 VarOffset
,
3014 IN EFI_STRING_ID Prompt
,
3015 IN EFI_STRING_ID Help
,
3016 IN UINT8 QuestionFlags
,
3017 IN UINT8 NumericFlags
,
3021 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3024 EFI_IFR_NUMERIC OpCode
;
3027 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3029 ZeroMem (&OpCode
, sizeof (OpCode
));
3030 OpCode
.Question
.QuestionId
= QuestionId
;
3031 OpCode
.Question
.VarStoreId
= VarStoreId
;
3032 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3033 OpCode
.Question
.Header
.Prompt
= Prompt
;
3034 OpCode
.Question
.Header
.Help
= Help
;
3035 OpCode
.Question
.Flags
= QuestionFlags
;
3036 OpCode
.Flags
= NumericFlags
;
3038 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
3039 case EFI_IFR_NUMERIC_SIZE_1
:
3040 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
3041 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3042 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3045 case EFI_IFR_NUMERIC_SIZE_2
:
3046 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3047 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3048 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3051 case EFI_IFR_NUMERIC_SIZE_4
:
3052 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3053 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3054 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3057 case EFI_IFR_NUMERIC_SIZE_8
:
3058 OpCode
.data
.u64
.MinValue
= Minimum
;
3059 OpCode
.data
.u64
.MaxValue
= Maximum
;
3060 OpCode
.data
.u64
.Step
= Step
;
3064 if (DefaultsOpCodeHandle
== NULL
) {
3065 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
));
3068 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3069 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
), 0, 1);
3070 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3071 HiiCreateEndOpCode (OpCodeHandle
);
3072 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3076 Create EFI_IFR_STRING_OP opcode.
3078 If OpCodeHandle is NULL, then ASSERT().
3079 If any reserved bits are set in QuestionFlags, then ASSERT().
3080 If any reserved bits are set in StringFlags, then ASSERT().
3082 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3083 @param[in] QuestionId Question ID
3084 @param[in] VarStoreId Storage ID
3085 @param[in] VarOffset Offset in Storage
3086 @param[in] Prompt String ID for Prompt
3087 @param[in] Help String ID for Help
3088 @param[in] QuestionFlags Flags in Question Header
3089 @param[in] StringFlags Flags for string opcode
3090 @param[in] MinSize String minimum length
3091 @param[in] MaxSize String maximum length
3092 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3093 is an optional parameter that may be NULL.
3095 @retval NULL There is not enough space left in Buffer to add the opcode.
3096 @retval Other A pointer to the created opcode.
3101 HiiCreateStringOpCode (
3102 IN VOID
*OpCodeHandle
,
3103 IN EFI_QUESTION_ID QuestionId
,
3104 IN EFI_VARSTORE_ID VarStoreId
,
3105 IN UINT16 VarOffset
,
3106 IN EFI_STRING_ID Prompt
,
3107 IN EFI_STRING_ID Help
,
3108 IN UINT8 QuestionFlags
,
3109 IN UINT8 StringFlags
,
3112 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3115 EFI_IFR_STRING OpCode
;
3118 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3120 ZeroMem (&OpCode
, sizeof (OpCode
));
3121 OpCode
.Question
.Header
.Prompt
= Prompt
;
3122 OpCode
.Question
.Header
.Help
= Help
;
3123 OpCode
.Question
.QuestionId
= QuestionId
;
3124 OpCode
.Question
.VarStoreId
= VarStoreId
;
3125 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3126 OpCode
.Question
.Flags
= QuestionFlags
;
3127 OpCode
.MinSize
= MinSize
;
3128 OpCode
.MaxSize
= MaxSize
;
3129 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3131 if (DefaultsOpCodeHandle
== NULL
) {
3132 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3135 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3136 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3137 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3138 HiiCreateEndOpCode (OpCodeHandle
);
3139 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3143 Create EFI_IFR_ONE_OF_OP opcode.
3145 If OpCodeHandle is NULL, then ASSERT().
3146 If any reserved bits are set in QuestionFlags, then ASSERT().
3147 If any reserved bits are set in OneOfFlags, then ASSERT().
3149 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3150 @param[in] QuestionId Question ID
3151 @param[in] VarStoreId Storage ID
3152 @param[in] VarOffset Offset in Storage
3153 @param[in] Prompt String ID for Prompt
3154 @param[in] Help String ID for Help
3155 @param[in] QuestionFlags Flags in Question Header
3156 @param[in] OneOfFlags Flags for oneof opcode
3157 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3158 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3159 is an optional parameter that may be NULL.
3161 @retval NULL There is not enough space left in Buffer to add the opcode.
3162 @retval Other A pointer to the created opcode.
3167 HiiCreateOneOfOpCode (
3168 IN VOID
*OpCodeHandle
,
3169 IN EFI_QUESTION_ID QuestionId
,
3170 IN EFI_VARSTORE_ID VarStoreId
,
3171 IN UINT16 VarOffset
,
3172 IN EFI_STRING_ID Prompt
,
3173 IN EFI_STRING_ID Help
,
3174 IN UINT8 QuestionFlags
,
3175 IN UINT8 OneOfFlags
,
3176 IN VOID
*OptionsOpCodeHandle
,
3177 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3180 EFI_IFR_ONE_OF OpCode
;
3183 ASSERT (OptionsOpCodeHandle
!= NULL
);
3184 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3186 ZeroMem (&OpCode
, sizeof (OpCode
));
3187 OpCode
.Question
.Header
.Prompt
= Prompt
;
3188 OpCode
.Question
.Header
.Help
= Help
;
3189 OpCode
.Question
.QuestionId
= QuestionId
;
3190 OpCode
.Question
.VarStoreId
= VarStoreId
;
3191 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3192 OpCode
.Question
.Flags
= QuestionFlags
;
3193 OpCode
.Flags
= OneOfFlags
;
3195 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3196 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, sizeof (OpCode
), 0, 1);
3197 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3198 if (DefaultsOpCodeHandle
!= NULL
) {
3199 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3201 HiiCreateEndOpCode (OpCodeHandle
);
3202 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3206 Create EFI_IFR_ORDERED_LIST_OP opcode.
3208 If OpCodeHandle is NULL, then ASSERT().
3209 If any reserved bits are set in QuestionFlags, then ASSERT().
3210 If any reserved bits are set in OrderedListFlags, then ASSERT().
3212 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3213 @param[in] QuestionId Question ID
3214 @param[in] VarStoreId Storage ID
3215 @param[in] VarOffset Offset in Storage
3216 @param[in] Prompt String ID for Prompt
3217 @param[in] Help String ID for Help
3218 @param[in] QuestionFlags Flags in Question Header
3219 @param[in] OrderedListFlags Flags for ordered list opcode
3220 @param[in] DataType Type for option value
3221 @param[in] MaxContainers Maximum count for options in this ordered list
3222 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3223 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3224 is an optional parameter that may be NULL.
3226 @retval NULL There is not enough space left in Buffer to add the opcode.
3227 @retval Other A pointer to the created opcode.
3232 HiiCreateOrderedListOpCode (
3233 IN VOID
*OpCodeHandle
,
3234 IN EFI_QUESTION_ID QuestionId
,
3235 IN EFI_VARSTORE_ID VarStoreId
,
3236 IN UINT16 VarOffset
,
3237 IN EFI_STRING_ID Prompt
,
3238 IN EFI_STRING_ID Help
,
3239 IN UINT8 QuestionFlags
,
3240 IN UINT8 OrderedListFlags
,
3242 IN UINT8 MaxContainers
,
3243 IN VOID
*OptionsOpCodeHandle
,
3244 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3247 EFI_IFR_ORDERED_LIST OpCode
;
3250 ASSERT (OptionsOpCodeHandle
!= NULL
);
3251 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3253 ZeroMem (&OpCode
, sizeof (OpCode
));
3254 OpCode
.Question
.Header
.Prompt
= Prompt
;
3255 OpCode
.Question
.Header
.Help
= Help
;
3256 OpCode
.Question
.QuestionId
= QuestionId
;
3257 OpCode
.Question
.VarStoreId
= VarStoreId
;
3258 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3259 OpCode
.Question
.Flags
= QuestionFlags
;
3260 OpCode
.MaxContainers
= MaxContainers
;
3261 OpCode
.Flags
= OrderedListFlags
;
3263 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3264 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3265 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3266 if (DefaultsOpCodeHandle
!= NULL
) {
3267 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3269 HiiCreateEndOpCode (OpCodeHandle
);
3270 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3274 Create EFI_IFR_TEXT_OP opcode.
3276 If OpCodeHandle is NULL, then ASSERT().
3278 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3279 @param[in] Prompt String ID for Prompt.
3280 @param[in] Help String ID for Help.
3281 @param[in] TextTwo String ID for TextTwo.
3283 @retval NULL There is not enough space left in Buffer to add the opcode.
3284 @retval Other A pointer to the created opcode.
3289 HiiCreateTextOpCode (
3290 IN VOID
*OpCodeHandle
,
3291 IN EFI_STRING_ID Prompt
,
3292 IN EFI_STRING_ID Help
,
3293 IN EFI_STRING_ID TextTwo
3296 EFI_IFR_TEXT OpCode
;
3298 ZeroMem (&OpCode
, sizeof (OpCode
));
3299 OpCode
.Statement
.Prompt
= Prompt
;
3300 OpCode
.Statement
.Help
= Help
;
3301 OpCode
.TextTwo
= TextTwo
;
3303 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TEXT_OP
, sizeof (OpCode
));
3307 Create EFI_IFR_DATE_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 DateFlags, 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 DateFlags is not
3316 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3317 @param[in] VarOffset Offset in Storage, optional. If DateFlags is not
3318 QF_DATE_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] DateFlags Flags for date 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 HiiCreateDateOpCode (
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_DATE OpCode
;
3347 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3348 ASSERT ((DateFlags
& (~(EFI_QF_DATE_YEAR_SUPPRESS
| EFI_QF_DATE_MONTH_SUPPRESS
| EFI_QF_DATE_DAY_SUPPRESS
| EFI_QF_DATE_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
= DateFlags
;
3359 if (DefaultsOpCodeHandle
== NULL
) {
3360 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
));
3363 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3364 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
), 0, 1);
3365 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3366 HiiCreateEndOpCode (OpCodeHandle
);
3367 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3371 Create EFI_IFR_TIME_OP opcode.
3373 If OpCodeHandle is NULL, then ASSERT().
3374 If any reserved bits are set in QuestionFlags, then ASSERT().
3375 If any reserved bits are set in TimeFlags, then ASSERT().
3377 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3378 @param[in] QuestionId Question ID
3379 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not
3380 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3381 @param[in] VarOffset Offset in Storage, optional. If TimeFlags is not
3382 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3383 @param[in] Prompt String ID for Prompt
3384 @param[in] Help String ID for Help
3385 @param[in] QuestionFlags Flags in Question Header
3386 @param[in] TimeFlags Flags for time opcode
3387 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3388 is an optional parameter that may be NULL.
3390 @retval NULL There is not enough space left in Buffer to add the opcode.
3391 @retval Other A pointer to the created opcode.
3396 HiiCreateTimeOpCode (
3397 IN VOID
*OpCodeHandle
,
3398 IN EFI_QUESTION_ID QuestionId
,
3399 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
3400 IN UINT16 VarOffset
, OPTIONAL
3401 IN EFI_STRING_ID Prompt
,
3402 IN EFI_STRING_ID Help
,
3403 IN UINT8 QuestionFlags
,
3405 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3408 EFI_IFR_TIME OpCode
;
3411 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3412 ASSERT ((TimeFlags
& (~(QF_TIME_HOUR_SUPPRESS
| QF_TIME_MINUTE_SUPPRESS
| QF_TIME_SECOND_SUPPRESS
| QF_TIME_STORAGE
))) == 0);
3414 ZeroMem (&OpCode
, sizeof (OpCode
));
3415 OpCode
.Question
.Header
.Prompt
= Prompt
;
3416 OpCode
.Question
.Header
.Help
= Help
;
3417 OpCode
.Question
.QuestionId
= QuestionId
;
3418 OpCode
.Question
.VarStoreId
= VarStoreId
;
3419 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3420 OpCode
.Question
.Flags
= QuestionFlags
;
3421 OpCode
.Flags
= TimeFlags
;
3423 if (DefaultsOpCodeHandle
== NULL
) {
3424 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
));
3427 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3428 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
), 0, 1);
3429 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3430 HiiCreateEndOpCode (OpCodeHandle
);
3431 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3435 This is the internal worker function to update the data in
3436 a form specified by FormSetGuid, FormId and Label.
3438 @param[in] FormSetGuid The optional Formset GUID.
3439 @param[in] FormId The Form ID.
3440 @param[in] Package The package header.
3441 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR
3442 opcodes to be inserted or replaced in the form.
3443 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode
3444 that marks the end of a replace operation in the form.
3445 @param[out] TempPackage The resultant package.
3447 @retval EFI_SUCCESS The function completes successfully.
3448 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.
3453 InternalHiiUpdateFormPackageData (
3454 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3455 IN EFI_FORM_ID FormId
,
3456 IN EFI_HII_PACKAGE_HEADER
*Package
,
3457 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3458 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3459 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3464 EFI_HII_PACKAGE_HEADER PackageHeader
;
3466 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3467 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3471 UINTN UpdatePackageLength
;
3473 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3474 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3475 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3477 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3478 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3479 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3480 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3484 while (Offset
< PackageHeader
.Length
) {
3485 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3486 BufferPos
+= IfrOpHdr
->Length
;
3487 UpdatePackageLength
+= IfrOpHdr
->Length
;
3490 // Find the matched FormSet and Form
3492 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3493 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3498 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
|| IfrOpHdr
->OpCode
== EFI_IFR_FORM_MAP_OP
) {
3499 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3507 // The matched Form is found, and Update data in this form
3509 if (GetFormSet
&& GetForm
) {
3510 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3511 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3512 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3514 // Remove the original data when End OpCode buffer exist.
3516 if (OpCodeBufferEnd
!= NULL
) {
3517 Offset
+= IfrOpHdr
->Length
;
3518 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3519 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3520 while (Offset
< PackageHeader
.Length
) {
3522 // Search the matched end opcode
3524 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3525 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3529 // Go to the next Op-Code
3531 Offset
+= IfrOpHdr
->Length
;
3532 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3535 if (Offset
>= PackageHeader
.Length
) {
3537 // The end opcode is not found.
3539 return EFI_NOT_FOUND
;
3544 // Insert the updated data
3546 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3547 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3548 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3549 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3551 if (OpCodeBufferEnd
!= NULL
) {
3553 // Add the end opcode
3555 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3556 BufferPos
+= IfrOpHdr
->Length
;
3557 UpdatePackageLength
+= IfrOpHdr
->Length
;
3561 // Copy the left package data.
3563 Offset
+= IfrOpHdr
->Length
;
3564 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3565 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3576 // Go to the next Op-Code
3578 Offset
+= IfrOpHdr
->Length
;
3579 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3584 // The updated opcode buffer is not found.
3586 return EFI_NOT_FOUND
;
3589 // Update the package length.
3591 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3592 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3598 This function updates a form that has previously been registered with the HII
3599 Database. This function will perform at most one update operation.
3601 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3602 comparisons of IFR opcodes are performed from the beginning of the form being
3603 updated until an IFR opcode is found that exactly matches the first IFR opcode
3604 specified by StartOpCodeHandle. The following rules are used to determine if
3605 an insert, replace, or delete operation is performed.
3607 1) If no matches are found, then NULL is returned.
3608 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3609 from StartOpCodeHandle except the first opcode are inserted immediately after
3610 the matching IFR opcode in the form to be updated.
3611 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3612 from the matching IFR opcode until an IFR opcode exactly matches the first
3613 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3614 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3615 is found, then all of the IFR opcodes between the start match and the end
3616 match are deleted from the form being updated and all of the IFR opcodes
3617 from StartOpCodeHandle except the first opcode are inserted immediately after
3618 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3619 IFR instruction, then the result of this operation will delete all of the IFR
3620 opcodes between the start end matches.
3622 If HiiHandle is NULL, then ASSERT().
3623 If StartOpCodeHandle is NULL, then ASSERT().
3625 @param[in] HiiHandle The HII Handle of the form to update.
3626 @param[in] FormSetGuid The Formset GUID of the form to update. This
3627 is an optional parameter that may be NULL.
3628 If it is NULL, all FormSet will be updated.
3629 @param[in] FormId The ID of the form to update.
3630 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
3631 opcodes to be inserted or replaced in the form.
3632 The first IFR instruction in StartOpCodeHandle
3633 is used to find matching IFR opcode in the
3635 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
3636 that marks the end of a replace operation in
3637 the form. This is an optional parameter that
3638 may be NULL. If it is NULL, then an the IFR
3639 opcodes specified by StartOpCodeHandle are
3640 inserted into the form.
3642 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
3643 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
3644 1) The form specified by HiiHandle, FormSetGuid,
3645 and FormId could not be found in the HII Database.
3646 2) No IFR opcodes in the target form match the first
3647 IFR opcode in StartOpCodeHandle.
3648 3) EndOpCOde is not NULL, and no IFR opcodes in the
3649 target form following a matching start opcode match
3650 the first IFR opcode in EndOpCodeHandle.
3651 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
3657 IN EFI_HII_HANDLE HiiHandle
,
3658 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3659 IN EFI_FORM_ID FormId
,
3660 IN VOID
*StartOpCodeHandle
,
3661 IN VOID
*EndOpCodeHandle OPTIONAL
3665 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
3666 UINT32 PackageListLength
;
3668 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
3670 UINT8
*UpdateBufferPos
;
3671 EFI_HII_PACKAGE_HEADER
*Package
;
3672 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
3673 EFI_HII_PACKAGE_HEADER PackageHeader
;
3675 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
3676 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
3679 // Input update data can't be NULL.
3681 ASSERT (HiiHandle
!= NULL
);
3682 ASSERT (StartOpCodeHandle
!= NULL
);
3683 UpdatePackageList
= NULL
;
3685 HiiPackageList
= NULL
;
3688 // Retrieve buffer data from Opcode Handle
3690 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpCodeHandle
;
3691 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpCodeHandle
;
3694 // Get the original package list
3697 HiiPackageList
= NULL
;
3698 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3700 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
3702 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3706 HiiPackageList
= AllocatePool (BufferSize
);
3707 if (HiiPackageList
== NULL
) {
3708 Status
= EFI_OUT_OF_RESOURCES
;
3712 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3713 if (EFI_ERROR (Status
)) {
3718 // Calculate and allocate space for retrieval of IFR data
3720 BufferSize
+= OpCodeBufferStart
->Position
;
3721 UpdatePackageList
= AllocateZeroPool (BufferSize
);
3722 if (UpdatePackageList
== NULL
) {
3723 Status
= EFI_OUT_OF_RESOURCES
;
3728 // Allocate temp buffer to store the temp updated package buffer
3730 TempPacakge
= AllocateZeroPool (BufferSize
);
3731 if (TempPacakge
== NULL
) {
3732 Status
= EFI_OUT_OF_RESOURCES
;
3736 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
3739 // Copy the package list header
3741 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
3742 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3745 // Go through each package to find the matched package and update one by one
3748 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3749 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
3750 while (Offset
< PackageListLength
) {
3751 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
3752 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3753 Offset
+= Package
->Length
;
3755 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
3757 // Check this package is the matched package.
3759 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
3761 // The matched package is found. Its package buffer will be updated by the input new data.
3763 if (!EFI_ERROR(Status
)) {
3769 // Add updated package buffer
3771 Package
= TempPacakge
;
3776 // Add pacakge buffer
3778 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3779 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
3780 UpdateBufferPos
+= PackageHeader
.Length
;
3785 // Update package list length
3787 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
3788 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
3791 // Update Package to show form
3793 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
3796 // Not matched form is found and updated.
3798 Status
= EFI_NOT_FOUND
;
3802 if (HiiPackageList
!= NULL
) {
3803 FreePool (HiiPackageList
);
3806 if (UpdatePackageList
!= NULL
) {
3807 FreePool (UpdatePackageList
);
3810 if (TempPacakge
!= NULL
) {
3811 FreePool (TempPacakge
);