2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalHiiLib.h"
17 #define GUID_CONFIG_STRING_TYPE 0x00
18 #define NAME_CONFIG_STRING_TYPE 0x01
19 #define PATH_CONFIG_STRING_TYPE 0x02
21 #define ACTION_SET_DEFAUTL_VALUE 0x01
22 #define ACTION_VALIDATE_SETTING 0x02
24 #define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200
27 LIST_ENTRY Entry
; // Link to Block array
35 // <ConfigHdr> Template
37 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
39 EFI_FORM_BROWSER2_PROTOCOL
*mUefiFormBrowser2
= NULL
;
42 // Template used to mark the end of a list of packages
44 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList
= {
45 sizeof (EFI_HII_PACKAGE_HEADER
),
50 Extract Hii package list GUID for given HII handle.
52 If HiiHandle could not be found in the HII database, then ASSERT.
53 If Guid is NULL, then ASSERT.
55 @param Handle Hii handle
56 @param Guid Package list GUID
58 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
63 InternalHiiExtractGuidFromHiiHandle (
64 IN EFI_HII_HANDLE Handle
,
70 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
72 ASSERT (Guid
!= NULL
);
73 ASSERT (Handle
!= NULL
);
76 // Get HII PackageList
79 HiiPackageList
= NULL
;
81 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
82 ASSERT (Status
!= EFI_NOT_FOUND
);
84 if (Status
== EFI_BUFFER_TOO_SMALL
) {
85 HiiPackageList
= AllocatePool (BufferSize
);
86 ASSERT (HiiPackageList
!= NULL
);
88 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
90 if (EFI_ERROR (Status
)) {
91 FreePool (HiiPackageList
);
98 CopyGuid (Guid
, &HiiPackageList
->PackageListGuid
);
100 FreePool (HiiPackageList
);
106 Registers a list of packages in the HII Database and returns the HII Handle
107 associated with that registration. If an HII Handle has already been registered
108 with the same PackageListGuid, then NULL is returned. If there are not enough
109 resources to perform the registration, then NULL is returned. If an empty list
110 of packages is passed in, then NULL is returned. If the size of the list of
111 package is 0, then NULL is returned.
113 The variable arguments are pointers which point to package header that defined
114 by UEFI VFR compiler and StringGather tool.
116 #pragma pack (push, 1)
119 EFI_HII_PACKAGE_HEADER PackageHeader;
120 } EDKII_AUTOGEN_PACKAGES_HEADER;
123 @param[in] PackageListGuid The GUID of the package list.
124 @param[in] DeviceHandle If not NULL, the Device Handle on which
125 an instance of DEVICE_PATH_PROTOCOL is installed.
126 This Device Handle uniquely defines the device that
127 the added packages are associated with.
128 @param[in] ... The variable argument list that contains pointers
129 to packages terminated by a NULL.
131 @retval NULL A HII Handle has already been registered in the HII Database with
132 the same PackageListGuid.
133 @retval NULL The HII Handle could not be created.
134 @retval NULL An empty list of packages was passed in.
135 @retval NULL All packages are empty.
136 @retval Other The HII Handle associated with the newly registered package list.
142 IN CONST EFI_GUID
*PackageListGuid
,
143 IN EFI_HANDLE DeviceHandle OPTIONAL
,
148 EFI_HII_HANDLE
*HiiHandleBuffer
;
151 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
152 EFI_HII_HANDLE HiiHandle
;
156 ASSERT (PackageListGuid
!= NULL
);
159 // Check to see if an HII Handle has already been registered with the same
162 HiiHandleBuffer
= HiiGetHiiHandles (PackageListGuid
);
163 if (HiiHandleBuffer
!= NULL
) {
164 FreePool (HiiHandleBuffer
);
169 // Calculate the length of all the packages in the variable argument list
171 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
172 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
177 // If there are no packages in the variable argument list or all the packages
178 // are empty, then return a NULL HII Handle
185 // Add the length of the Package List Header and the terminating Package Header
187 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
190 // Allocate the storage for the entire Package List
192 PackageListHeader
= AllocateZeroPool (Length
);
195 // If the Packahge List can not be allocated, then return a NULL HII Handle
197 if (PackageListHeader
== NULL
) {
202 // Fill in the GUID and Length of the Package List Header
204 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
205 PackageListHeader
->PackageLength
= Length
;
208 // Initialize a pointer to the beginning if the Package List data
210 Data
= (UINT8
*)(PackageListHeader
+ 1);
213 // Copy the data from each package in the variable argument list
215 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
216 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
217 CopyMem (Data
, Package
+ 1, Length
);
223 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
225 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
228 // Register the package list with the HII Database
230 Status
= gHiiDatabase
->NewPackageList (
236 if (EFI_ERROR (Status
)) {
241 // Free the allocated package list
243 FreePool (PackageListHeader
);
246 // Return the new HII Handle
252 Removes a package list from the HII database.
254 If HiiHandle is NULL, then ASSERT.
255 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
257 @param[in] HiiHandle The handle that was previously registered in the HII database
263 IN EFI_HII_HANDLE HiiHandle
268 ASSERT (HiiHandle
!= NULL
);
269 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
270 ASSERT_EFI_ERROR (Status
);
275 Retrieves the array of all the HII Handles or the HII handle of a specific
276 package list in the HII Database.
277 This array is terminated with a NULL HII Handle.
278 This function allocates the returned array using AllocatePool().
279 The caller is responsible for freeing the array with FreePool().
281 @param[in] PackageListGuid An optional parameter that is used to request
282 an HII Handle that is associatd with a specific
283 Package List GUID. If this parameter is NULL
284 then all the HII Handles in the HII Database
285 are returned. If this parameter is not NULL
286 then at most 1 HII Handle is returned.
288 @retval NULL No HII handles were found in the HII database
289 @retval NULL The array of HII Handles could not be retrieved
290 @retval Other A pointer to the NULL terminated array of HII Handles
296 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
300 UINTN HandleBufferLength
;
301 EFI_HII_HANDLE TempHiiHandleBuffer
;
302 EFI_HII_HANDLE
*HiiHandleBuffer
;
307 // Retrieve the size required for the buffer of all HII handles.
309 HandleBufferLength
= 0;
310 Status
= gHiiDatabase
->ListPackageLists (
312 EFI_HII_PACKAGE_TYPE_ALL
,
319 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
320 // then there are no HII handles in the HII database. If ListPackageLists()
321 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
322 // handles in the HII database.
324 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
326 // Return NULL if the size can not be retrieved, or if there are no HII
327 // handles in the HII Database
333 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
335 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
336 if (HiiHandleBuffer
== NULL
) {
338 // Return NULL if allocation fails.
344 // Retrieve the array of HII Handles in the HII Database
346 Status
= gHiiDatabase
->ListPackageLists (
348 EFI_HII_PACKAGE_TYPE_ALL
,
353 if (EFI_ERROR (Status
)) {
355 // Free the buffer and return NULL if the HII handles can not be retrieved.
357 FreePool (HiiHandleBuffer
);
361 if (PackageListGuid
== NULL
) {
363 // Return the NULL terminated array of HII handles in the HII Database
365 return HiiHandleBuffer
;
367 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
368 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index
], &Guid
);
369 ASSERT_EFI_ERROR (Status
);
370 if (CompareGuid (&Guid
, PackageListGuid
)) {
371 HiiHandleBuffer
[0] = HiiHandleBuffer
[Index
];
372 HiiHandleBuffer
[1] = NULL
;
373 return HiiHandleBuffer
;
376 FreePool (HiiHandleBuffer
);
382 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
383 hex digits that appear between a '=' and a '&' in a config string.
385 If String is NULL, then ASSERT().
387 @param[in] String Pointer to a Null-terminated Unicode string.
389 @return Pointer to the Null-terminated Unicode result string.
394 InternalHiiLowerConfigString (
395 IN EFI_STRING ConfigString
401 ASSERT (ConfigString
!= NULL
);
404 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
406 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
407 if (*String
== L
'=') {
409 } else if (*String
== L
'&') {
411 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
412 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
420 Uses the BlockToConfig() service of the Config Routing Protocol to
421 convert <ConfigRequest> and a buffer to a <ConfigResp>
423 If ConfigRequest is NULL, then ASSERT().
424 If Block is NULL, then ASSERT().
426 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
427 @param[in] Block Pointer to a block of data.
428 @param[in] BlockSize The zie, in bytes, of Block.
430 @retval NULL The <ConfigResp> string could not be generated.
431 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
436 InternalHiiBlockToConfig (
437 IN CONST EFI_STRING ConfigRequest
,
438 IN CONST UINT8
*Block
,
443 EFI_STRING ConfigResp
;
446 ASSERT (ConfigRequest
!= NULL
);
447 ASSERT (Block
!= NULL
);
450 // Convert <ConfigRequest> to <ConfigResp>
452 Status
= gHiiConfigRouting
->BlockToConfig (
460 if (EFI_ERROR (Status
)) {
467 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
468 or set uncommitted data. If sata i being retrieved, then the buffer is
469 allocated using AllocatePool(). The caller is then responsible for freeing
470 the buffer using FreePool().
472 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
473 is an optional parameter that may be NULL.
474 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
475 parameter that may be NULL.
476 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
477 of uncommited data to set. If this parameter is NULL,
478 then the caller is requesting to get the uncommited data
479 from the Form Browser.
481 @retval NULL The uncommitted data could not be retrieved.
482 @retval Other A pointer to a buffer containing the uncommitted data.
487 InternalHiiBrowserCallback (
488 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
489 IN CONST CHAR16
*VariableName
, OPTIONAL
490 IN CONST EFI_STRING SetResultsData OPTIONAL
494 UINTN ResultsDataSize
;
495 EFI_STRING ResultsData
;
496 CHAR16 TempResultsData
;
501 if (mUefiFormBrowser2
== NULL
) {
502 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
503 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
510 if (SetResultsData
!= NULL
) {
512 // Request to to set data in the uncommitted browser state information
514 ResultsData
= SetResultsData
;
517 // Retrieve the length of the buffer required ResultsData from the Browser Callback
519 Status
= mUefiFormBrowser2
->BrowserCallback (
528 if (!EFI_ERROR (Status
)) {
530 // No Resluts Data, only allocate one char for '\0'
532 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
536 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
541 // Allocate the ResultsData buffer
543 ResultsData
= AllocateZeroPool (ResultsDataSize
);
544 if (ResultsData
== NULL
) {
550 // Retrieve or set the ResultsData from the Browser Callback
552 Status
= mUefiFormBrowser2
->BrowserCallback (
556 (BOOLEAN
)(SetResultsData
== NULL
),
560 if (EFI_ERROR (Status
)) {
568 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
569 information that includes a GUID, an optional Unicode string name, and a device
570 path. The string returned is allocated with AllocatePool(). The caller is
571 responsible for freeing the allocated string with FreePool().
573 The format of a <ConfigHdr> is as follows:
575 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
577 @param[in] Guid Pointer to an EFI_GUID that is the routing information
578 GUID. Each of the 16 bytes in Guid is converted to
579 a 2 Unicode character hexidecimal string. This is
580 an optional parameter that may be NULL.
581 @param[in] Name Pointer to a Null-terminated Unicode string that is
582 the routing information NAME. This is an optional
583 parameter that may be NULL. Each 16-bit Unicode
584 character in Name is converted to a 4 character Unicode
586 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
587 that is the routing information PATH. Each byte of
588 the Device Path associated with DriverHandle is converted
589 to a 2 Unicode character hexidecimal string.
591 @retval NULL DriverHandle does not support the Device Path Protocol.
592 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
597 HiiConstructConfigHdr (
598 IN CONST EFI_GUID
*Guid
, OPTIONAL
599 IN CONST CHAR16
*Name
, OPTIONAL
600 IN EFI_HANDLE DriverHandle
604 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
605 UINTN DevicePathSize
;
607 CHAR16
*ReturnString
;
612 // Compute the length of Name in Unicode characters.
613 // If Name is NULL, then the length is 0.
617 NameLength
= StrLen (Name
);
623 // Retrieve DevicePath Protocol associated with DriverHandle
625 if (DriverHandle
!= NULL
) {
626 DevicePath
= DevicePathFromHandle (DriverHandle
);
627 if (DevicePath
== NULL
) {
631 // Compute the size of the device path in bytes
633 DevicePathSize
= GetDevicePathSize (DevicePath
);
637 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
638 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
640 String
= AllocateZeroPool ((5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
));
641 if (String
== NULL
) {
646 // Start with L"GUID="
648 ReturnString
= StrCpy (String
, L
"GUID=");
649 String
+= StrLen (String
);
653 // Append Guid converted to <HexCh>32
655 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
656 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
663 StrCpy (String
, L
"&NAME=");
664 String
+= StrLen (String
);
668 // Append Name converted to <Char>NameLength
670 for (; *Name
!= L
'\0'; Name
++) {
671 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *Name
, 4);
678 StrCpy (String
, L
"&PATH=");
679 String
+= StrLen (String
);
682 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
684 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
685 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(Buffer
++), 2);
689 // Null terminate the Unicode string
694 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
696 return InternalHiiLowerConfigString (ReturnString
);
700 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
701 to binary buffer from <ConfigHdr>.
703 This is a internal function.
705 @param String UEFI configuration string.
706 @param Flag Flag specifies what type buffer will be retrieved.
707 @param Buffer Binary of Guid, Name or Device path.
709 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
710 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
711 @retval EFI_SUCCESS The buffer data is retrieved and translated to
716 InternalHiiGetBufferFromString (
717 IN EFI_STRING String
,
723 EFI_STRING ConfigHdr
;
730 if (String
== NULL
|| Buffer
== NULL
) {
731 return EFI_INVALID_PARAMETER
;
738 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
739 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
741 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
744 case GUID_CONFIG_STRING_TYPE
:
745 case PATH_CONFIG_STRING_TYPE
:
747 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
748 // as the device path and Guid resides in RAM memory.
749 // Translate the data into binary.
751 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
752 if (DataBuffer
== NULL
) {
753 return EFI_OUT_OF_RESOURCES
;
756 // Convert binary byte one by one
758 ZeroMem (TemStr
, sizeof (TemStr
));
759 for (Index
= 0; Index
< Length
; Index
++) {
760 TemStr
[0] = ConfigHdr
[Index
];
761 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
762 if ((Index
& 1) == 0) {
763 DataBuffer
[Index
/2] = DigitUint8
;
765 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
769 *Buffer
= DataBuffer
;
772 case NAME_CONFIG_STRING_TYPE
:
774 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
778 // Add the tailling char L'\0'
780 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
781 if (DataBuffer
== NULL
) {
782 return EFI_OUT_OF_RESOURCES
;
785 // Convert character one by one
787 StringPtr
= (CHAR16
*) DataBuffer
;
788 ZeroMem (TemStr
, sizeof (TemStr
));
789 for (Index
= 0; Index
< Length
; Index
+= 4) {
790 StrnCpy (TemStr
, ConfigHdr
+ Index
, 4);
791 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
794 // Add tailing L'\0' character
796 StringPtr
[Index
/4] = L
'\0';
798 *Buffer
= DataBuffer
;
802 return EFI_INVALID_PARAMETER
;
810 This function checks VarOffset and VarWidth is in the block range.
812 @param BlockArray The block array is to be checked.
813 @param VarOffset Offset of var to the structure
814 @param VarWidth Width of var.
816 @retval TRUE This Var is in the block range.
817 @retval FALSE This Var is not in the block range.
821 IN IFR_BLOCK_DATA
*BlockArray
,
827 IFR_BLOCK_DATA
*BlockData
;
830 // No Request Block array, all vars are got.
832 if (BlockArray
== NULL
) {
837 // Check the input var is in the request block range.
839 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
840 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
841 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
850 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
852 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
854 @param ValueString String in <BlockConfig> format and points to the
855 first character of <Number>.
856 @param ValueData The output value. Caller takes the responsibility
858 @param ValueLength Length of the <Number>, in characters.
860 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
862 @retval EFI_SUCCESS Value of <Number> is outputted in Number
868 InternalHiiGetValueOfNumber (
869 IN EFI_STRING ValueString
,
870 OUT UINT8
**ValueData
,
871 OUT UINTN
*ValueLength
874 EFI_STRING StringPtr
;
881 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
882 ASSERT (*ValueString
!= L
'\0');
885 // Get the length of value string
887 StringPtr
= ValueString
;
888 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
891 Length
= StringPtr
- ValueString
;
894 // Allocate buffer to store the value
896 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
898 return EFI_OUT_OF_RESOURCES
;
902 // Convert character one by one to the value buffer
904 ZeroMem (TemStr
, sizeof (TemStr
));
905 for (Index
= 0; Index
< Length
; Index
++) {
906 TemStr
[0] = ValueString
[Length
- Index
- 1];
907 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
908 if ((Index
& 1) == 0) {
909 Buf
[Index
/2] = DigitUint8
;
911 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
916 // Set the converted value and string length.
919 *ValueLength
= Length
;
924 This function shares the same logic to parse ConfigAltResp string
925 for setting default value and validating current setting.
928 @param HiiPackageList
929 @param PackageListLength
937 InternalHiiValidateCurrentSetting (
938 IN EFI_STRING ConfigResp
,
939 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
940 IN UINTN PackageListLength
,
941 IN EFI_GUID
*VarGuid
,
945 IFR_BLOCK_DATA
*CurrentBlockArray
;
946 IFR_BLOCK_DATA
*BlockData
;
947 IFR_BLOCK_DATA
*NewBlockData
;
948 IFR_BLOCK_DATA VarBlockData
;
949 EFI_STRING StringPtr
;
959 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
960 UINT32 PackageOffset
;
963 EFI_IFR_OP_HEADER
*IfrOpHdr
;
964 EFI_IFR_VARSTORE
*IfrVarStore
;
965 EFI_IFR_ONE_OF
*IfrOneOf
;
966 EFI_IFR_NUMERIC
*IfrNumeric
;
967 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
968 EFI_IFR_CHECKBOX
*IfrCheckBox
;
969 EFI_IFR_STRING
*IfrString
;
974 // 1. Get the current setting to current block data array and Convert them into VarBuffer
978 // Skip ConfigHdr string
980 StringPtr
= ConfigResp
;
981 StringPtr
= StrStr (ConfigResp
, L
"&OFFSET");
982 if (StringPtr
== NULL
) {
984 // No ConfigBlock value is requied to be validated.
985 // EFI_SUCCESS directly return.
991 // Initialize the local variables.
995 Status
= EFI_SUCCESS
;
999 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
1000 VarBuffer
= AllocateZeroPool (MaxBufferSize
);
1001 if (VarBuffer
== NULL
) {
1002 return EFI_OUT_OF_RESOURCES
;
1006 // Init CurrentBlockArray
1008 CurrentBlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1009 if (CurrentBlockArray
== NULL
) {
1010 Status
= EFI_OUT_OF_RESOURCES
;
1013 InitializeListHead (&CurrentBlockArray
->Entry
);
1016 // Parse each <RequestElement> if exists
1017 // Only <BlockName> format is supported by this help function.
1018 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1020 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1022 // Skip the &OFFSET= string
1024 StringPtr
+= StrLen (L
"&OFFSET=");
1029 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1030 if (EFI_ERROR (Status
)) {
1037 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1039 FreePool (TmpBuffer
);
1042 StringPtr
+= Length
;
1043 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1044 Status
= EFI_INVALID_PARAMETER
;
1047 StringPtr
+= StrLen (L
"&WIDTH=");
1052 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1053 if (EFI_ERROR (Status
)) {
1060 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1062 FreePool (TmpBuffer
);
1065 StringPtr
+= Length
;
1066 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1067 Status
= EFI_INVALID_PARAMETER
;
1071 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1072 Status
= EFI_INVALID_PARAMETER
;
1075 StringPtr
+= StrLen (L
"&VALUE=");
1080 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1081 if (EFI_ERROR (Status
)) {
1085 StringPtr
+= Length
;
1086 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1087 Status
= EFI_INVALID_PARAMETER
;
1092 // Check whether VarBuffer is enough
1094 if ((UINTN
) (Offset
+ Width
) > MaxBufferSize
) {
1095 VarBuffer
= ReallocatePool (
1097 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1100 if (VarBuffer
== NULL
) {
1101 Status
= EFI_OUT_OF_RESOURCES
;
1104 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
1108 // Update the Block with configuration info
1110 CopyMem (VarBuffer
+ Offset
, TmpBuffer
, Width
);
1111 FreePool (TmpBuffer
);
1115 // Set new Block Data
1117 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1118 if (NewBlockData
== NULL
) {
1119 Status
= EFI_OUT_OF_RESOURCES
;
1122 NewBlockData
->Offset
= Offset
;
1123 NewBlockData
->Width
= Width
;
1126 // Insert the new block data into the block data array.
1128 for (Link
= CurrentBlockArray
->Entry
.ForwardLink
; Link
!= &CurrentBlockArray
->Entry
; Link
= Link
->ForwardLink
) {
1129 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1130 if (NewBlockData
->Offset
== BlockData
->Offset
) {
1131 if (NewBlockData
->Width
> BlockData
->Width
) {
1132 BlockData
->Width
= NewBlockData
->Width
;
1134 FreePool (NewBlockData
);
1136 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
1138 // Insert new block data as the previous one of this link.
1140 InsertTailList (Link
, &NewBlockData
->Entry
);
1146 // Insert new block data into the array tail.
1148 if (Link
== &CurrentBlockArray
->Entry
) {
1149 InsertTailList (Link
, &NewBlockData
->Entry
);
1153 // If '\0', parsing is finished.
1155 if (*StringPtr
== 0) {
1159 // Go to next ConfigBlock
1164 // Merge the aligned block data into the single block data.
1166 Link
= CurrentBlockArray
->Entry
.ForwardLink
;
1167 while ((Link
!= &CurrentBlockArray
->Entry
) && (Link
->ForwardLink
!= &CurrentBlockArray
->Entry
)) {
1168 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
1169 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1170 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
1171 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
1172 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
1174 RemoveEntryList (Link
->ForwardLink
);
1175 FreePool (NewBlockData
);
1178 Link
= Link
->ForwardLink
;
1181 if (IsListEmpty (&CurrentBlockArray
->Entry
)) {
1182 Status
= EFI_SUCCESS
;
1187 // 2. Check IFR value is in block data, then Validate Vaule
1189 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1192 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1193 while (PackageOffset
< PackageListLength
) {
1194 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1197 // Parse IFR opcode from the form package.
1199 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1200 IfrOffset
= sizeof (PacakgeHeader
);
1201 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1202 while (IfrOffset
< PacakgeHeader
.Length
) {
1203 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1205 // Validate current setting to the value built in IFR opcode
1207 switch (IfrOpHdr
->OpCode
) {
1208 case EFI_IFR_VARSTORE_OP
:
1210 // VarStoreId has been found. No further found.
1212 if (IfrVarStore
!= NULL
) {
1216 // Find the matched VarStoreId to the input VarGuid and VarName
1218 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1219 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1220 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1221 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1222 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1227 // The matched VarStore is found.
1229 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1236 case EFI_IFR_FORM_OP
:
1238 // Check the matched VarStoreId is found.
1240 if (IfrVarStore
== NULL
) {
1241 Status
= EFI_SUCCESS
;
1245 case EFI_IFR_ONE_OF_OP
:
1247 // Check whether current value is the one of option.
1251 // Check whether this question is for the requested varstore.
1253 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1254 if (IfrOneOf
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1259 // Get Offset by Question header and Width by DataType Flags
1261 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1262 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1264 // Check whether this question is in current block array.
1266 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1268 // This question is not in the current configuration string. Skip it.
1273 // Check this var question is in the var storage
1275 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1277 // This question exceeds the var store size.
1279 Status
= EFI_INVALID_PARAMETER
;
1284 // Get the current value for oneof opcode
1287 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1289 // Set Block Data, to be checked in the following Oneof option opcode.
1291 VarBlockData
.Offset
= Offset
;
1292 VarBlockData
.Width
= Width
;
1293 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1294 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1296 case EFI_IFR_NUMERIC_OP
:
1298 // Check the current value is in the numeric range.
1302 // Check whether this question is for the requested varstore.
1304 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1305 if (IfrNumeric
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1310 // Get Offset by Question header and Width by DataType Flags
1312 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1313 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1315 // Check whether this question is in current block array.
1317 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1319 // This question is not in the current configuration string. Skip it.
1324 // Check this var question is in the var storage
1326 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1328 // This question exceeds the var store size.
1330 Status
= EFI_INVALID_PARAMETER
;
1335 // Check the current value is in the numeric range.
1338 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1339 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1340 case EFI_IFR_NUMERIC_SIZE_1
:
1341 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1343 // Not in the valid range.
1345 Status
= EFI_INVALID_PARAMETER
;
1349 case EFI_IFR_NUMERIC_SIZE_2
:
1350 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1352 // Not in the valid range.
1354 Status
= EFI_INVALID_PARAMETER
;
1358 case EFI_IFR_NUMERIC_SIZE_4
:
1359 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1361 // Not in the valid range.
1363 Status
= EFI_INVALID_PARAMETER
;
1367 case EFI_IFR_NUMERIC_SIZE_8
:
1368 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1370 // Not in the valid range.
1372 Status
= EFI_INVALID_PARAMETER
;
1379 case EFI_IFR_CHECKBOX_OP
:
1381 // Check value is BOOLEAN type, only 0 and 1 is valid.
1385 // Check whether this question is for the requested varstore.
1387 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1388 if (IfrCheckBox
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1393 // Get Offset by Question header
1395 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1396 Width
= sizeof (BOOLEAN
);
1398 // Check whether this question is in current block array.
1400 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1402 // This question is not in the current configuration string. Skip it.
1407 // Check this var question is in the var storage
1409 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1411 // This question exceeds the var store size.
1413 Status
= EFI_INVALID_PARAMETER
;
1418 // Boolean type, only 1 and 0 is valid.
1420 if (*(VarBuffer
+ Offset
) > 1) {
1421 Status
= EFI_INVALID_PARAMETER
;
1426 case EFI_IFR_STRING_OP
:
1428 // Check current string length is less than maxsize
1432 // Check whether this question is for the requested varstore.
1434 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1435 if (IfrString
->Question
.VarStoreId
!= IfrVarStore
->VarStoreId
) {
1440 // Get Offset/Width by Question header and OneOf Flags
1442 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1443 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1445 // Check whether this question is in current block array.
1447 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1449 // This question is not in the current configuration string. Skip it.
1454 // Check this var question is in the var storage
1456 if ((Offset
+ Width
) > IfrVarStore
->Size
) {
1458 // This question exceeds the var store size.
1460 Status
= EFI_INVALID_PARAMETER
;
1465 // Check current string length is less than maxsize
1467 if (StrSize ((CHAR16
*) (VarBuffer
+ Offset
)) > Width
) {
1468 Status
= EFI_INVALID_PARAMETER
;
1472 case EFI_IFR_ONE_OF_OPTION_OP
:
1474 // Opcode Scope is zero. This one of option is not to be checked.
1476 if (VarBlockData
.Scope
== 0) {
1481 // Only check for OneOf and OrderList opcode
1483 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1484 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1486 // Check current value is the value of one of option.
1488 if (VarValue
== IfrOneOfOption
->Value
.u64
) {
1490 // The value is one of option value.
1491 // Set OpCode to Zero, don't need check again.
1493 VarBlockData
.OpCode
= 0;
1498 case EFI_IFR_END_OP
:
1500 // Decrease opcode scope for the validated opcode
1502 if (VarBlockData
.Scope
> 0) {
1503 VarBlockData
.Scope
--;
1507 // OneOf value doesn't belong to one of option value.
1509 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1510 Status
= EFI_INVALID_PARAMETER
;
1516 // Increase Scope for the validated opcode
1518 if (VarBlockData
.Scope
> 0) {
1519 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1524 // Go to the next opcode
1526 IfrOffset
+= IfrOpHdr
->Length
;
1529 // Only one form is in a package list.
1535 // Go to next package.
1537 PackageOffset
+= PacakgeHeader
.Length
;
1541 if (VarBuffer
!= NULL
) {
1542 FreePool (VarBuffer
);
1545 if (CurrentBlockArray
!= NULL
) {
1547 // Free Link Array CurrentBlockArray
1549 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
1550 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
1551 RemoveEntryList (&BlockData
->Entry
);
1552 FreePool (BlockData
);
1554 FreePool (CurrentBlockArray
);
1561 This function shares the same logic to parse ConfigAltResp string
1562 for setting default value and validating current setting.
1564 1. For setting default action, Reset the default value specified by DefaultId
1565 to the driver configuration got by Request string.
1566 2. For validating current setting, Validate the current configuration
1567 by parsing HII form IFR opcode.
1569 NULL request string support depends on the ExportConfig interface of
1570 HiiConfigRouting protocol in UEFI specification.
1572 @param Request A null-terminated Unicode string in
1573 <MultiConfigRequest> format. It can be NULL.
1574 If it is NULL, all current configuration for the
1575 entirety of the current HII database will be validated.
1576 If it is NULL, all configuration for the
1577 entirety of the current HII database will be reset.
1578 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
1579 @param ActionType Action supports setting defaults and validate current setting.
1581 @retval TURE Action runs successfully.
1582 @retval FALSE Action is not valid or Action can't be executed successfully..
1586 InternalHiiIfrValueAction (
1587 IN CONST EFI_STRING Request
, OPTIONAL
1588 IN UINT16 DefaultId
,
1592 EFI_STRING ConfigAltResp
;
1593 EFI_STRING ConfigAltHdr
;
1594 EFI_STRING ConfigResp
;
1595 EFI_STRING Progress
;
1596 EFI_STRING StringPtr
;
1597 EFI_STRING StringHdr
;
1599 EFI_HANDLE DriverHandle
;
1600 EFI_HANDLE TempDriverHandle
;
1601 EFI_HII_HANDLE
*HiiHandleBuffer
;
1602 EFI_HII_HANDLE HiiHandle
;
1606 EFI_STRING_ID DefaultName
;
1610 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1611 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1612 UINT32 PackageOffset
;
1613 UINTN PackageListLength
;
1614 EFI_HII_PACKAGE_HEADER PacakgeHeader
;
1615 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1616 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1618 ConfigAltResp
= NULL
;
1623 ConfigAltHdr
= NULL
;
1624 HiiHandleBuffer
= NULL
;
1626 TempDriverHandle
= NULL
;
1629 HiiPackageList
= NULL
;
1632 // Only support set default and validate setting action.
1634 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
1639 // Get the full requested value and deault value string.
1641 if (Request
!= NULL
) {
1642 Status
= gHiiConfigRouting
->ExtractConfig (
1649 Status
= gHiiConfigRouting
->ExportConfig (
1655 if (EFI_ERROR (Status
)) {
1659 StringPtr
= ConfigAltResp
;
1661 while (StringPtr
!= L
'\0') {
1663 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
1665 StringHdr
= StringPtr
;
1670 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
1671 Status
= EFI_INVALID_PARAMETER
;
1674 StringPtr
+= StrLen (L
"GUID=");
1675 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
1676 if (EFI_ERROR (Status
)) {
1681 // Get Name value VarName
1683 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
1686 if (*StringPtr
== L
'\0') {
1687 Status
= EFI_INVALID_PARAMETER
;
1690 StringPtr
+= StrLen (L
"&NAME=");
1691 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
1692 if (EFI_ERROR (Status
)) {
1697 // Get Path value DevicePath
1699 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
1702 if (*StringPtr
== L
'\0') {
1703 Status
= EFI_INVALID_PARAMETER
;
1706 StringPtr
+= StrLen (L
"&PATH=");
1707 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
1708 if (EFI_ERROR (Status
)) {
1713 // Get the Driver handle by the got device path.
1715 TempDevicePath
= DevicePath
;
1716 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
1717 if (EFI_ERROR (Status
)) {
1722 // Find the matched Hii Handle for the found Driver handle
1724 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
1725 if (HiiHandleBuffer
== NULL
) {
1726 Status
= EFI_NOT_FOUND
;
1730 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
1731 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
1732 if (TempDriverHandle
== DriverHandle
) {
1737 HiiHandle
= HiiHandleBuffer
[Index
];
1738 FreePool (HiiHandleBuffer
);
1740 if (HiiHandle
== NULL
) {
1742 // This request string has no its Hii package.
1743 // Its default value and validating can't execute by parsing IFR data.
1744 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
1746 Status
= EFI_SUCCESS
;
1747 goto NextConfigAltResp
;
1751 // 2. Get DefaultName string ID by parsing the PacakgeList
1755 // Get HiiPackage by HiiHandle
1757 PackageListLength
= 0;
1758 HiiPackageList
= NULL
;
1759 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1762 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1764 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1765 Status
= EFI_INVALID_PARAMETER
;
1769 HiiPackageList
= AllocatePool (PackageListLength
);
1770 if (HiiPackageList
== NULL
) {
1771 Status
= EFI_OUT_OF_RESOURCES
;
1776 // Get PackageList on HiiHandle
1778 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
1779 if (EFI_ERROR (Status
)) {
1784 // Parse the form package and get the default name string ID.
1786 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1787 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1788 Status
= EFI_NOT_FOUND
;
1789 while (PackageOffset
< PackageListLength
) {
1790 CopyMem (&PacakgeHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PacakgeHeader
));
1793 // Parse IFR opcode to get default store opcode
1795 if (PacakgeHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1796 IfrOffset
= sizeof (PacakgeHeader
);
1797 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1798 while (IfrOffset
< PacakgeHeader
.Length
) {
1799 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1801 // Match DefaultId to find its DefaultName
1803 if (IfrOpHdr
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
) {
1804 if (((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultId
== DefaultId
) {
1805 DefaultName
= ((EFI_IFR_DEFAULTSTORE
*) IfrOpHdr
)->DefaultName
;
1806 Status
= EFI_SUCCESS
;
1810 IfrOffset
+= IfrOpHdr
->Length
;
1813 // Only one form is in a package list.
1819 // Go to next package.
1821 PackageOffset
+= PacakgeHeader
.Length
;
1825 // Not found the matched default string ID
1827 if (EFI_ERROR (Status
)) {
1828 Status
= EFI_SUCCESS
;
1829 goto NextConfigAltResp
;
1834 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
1835 // Get the default configuration string according to the found defaultname string ID.
1837 Status
= gHiiConfigRouting
->GetAltConfig (
1843 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultName
:NULL
, // it can be NULL to get the current setting.
1847 if (EFI_ERROR (Status
)) {
1848 Status
= EFI_SUCCESS
;
1849 goto NextConfigAltResp
;
1853 // 4. Set the default configuration information or Validate current setting by parse IFR code.
1854 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1856 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
1858 // Set the default configuration information.
1860 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
1863 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
1865 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
);
1868 if (EFI_ERROR (Status
)) {
1874 // Free the allocated pacakge buffer and the got ConfigResp string.
1876 if (HiiPackageList
!= NULL
) {
1877 FreePool (HiiPackageList
);
1878 HiiPackageList
= NULL
;
1881 if (ConfigResp
!= NULL
) {
1882 FreePool (ConfigResp
);
1887 // Free the allocated buffer.
1895 FreePool (DevicePath
);
1899 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
1903 // Get and Skip ConfigHdr
1905 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1908 if (*StringPtr
== L
'\0') {
1913 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
1914 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
1916 ConfigAltHdr
= AllocateZeroPool ((1 + StringPtr
- StringHdr
+ 8 + 1) * sizeof (CHAR16
));
1917 if (ConfigAltHdr
== NULL
) {
1918 Status
= EFI_OUT_OF_RESOURCES
;
1921 StrCpy (ConfigAltHdr
, L
"&");
1922 StrnCat (ConfigAltHdr
, StringHdr
, StringPtr
- StringHdr
);
1923 StrCat (ConfigAltHdr
, L
"&ALTCFG=");
1926 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
1928 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
1929 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
1930 if (*StringPtr
== L
'\0') {
1936 // Free the allocated ConfigAltHdr string
1938 FreePool (ConfigAltHdr
);
1939 if (*StringPtr
== L
'\0') {
1944 // Find &GUID as the next ConfigHdr
1946 StringPtr
= StrStr (StringPtr
, L
"&GUID");
1947 if (StringPtr
== NULL
) {
1958 if (VarGuid
!= NULL
) {
1962 if (VarName
!= NULL
) {
1966 if (DevicePath
!= NULL
) {
1967 FreePool (DevicePath
);
1970 if (ConfigResp
!= NULL
) {
1971 FreePool (ConfigResp
);
1974 if (ConfigAltResp
!= NULL
) {
1975 FreePool (ConfigAltResp
);
1978 if (HiiPackageList
!= NULL
) {
1979 FreePool (HiiPackageList
);
1982 if (EFI_ERROR (Status
)) {
1990 Validate the current configuration by parsing HII form IFR opcode.
1992 NULL request string support depends on the ExtractConfig interface of
1993 HiiConfigRouting protocol in UEFI specification.
1995 @param Request A null-terminated Unicode string in
1996 <MultiConfigRequest> format. It can be NULL.
1997 If it is NULL, all current configuration for the
1998 entirety of the current HII database will be validated.
2000 @retval TURE Current configuration is valid.
2001 @retval FALSE Current configuration is invalid.
2005 HiiValidateSettings (
2006 IN CONST EFI_STRING Request OPTIONAL
2009 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2013 Reset the default value specified by DefaultId to the driver
2014 configuration got by Request string.
2016 NULL request string support depends on the ExportConfig interface of
2017 HiiConfigRouting protocol in UEFI specification.
2019 @param Request A null-terminated Unicode string in
2020 <MultiConfigRequest> format. It can be NULL.
2021 If it is NULL, all configuration for the
2022 entirety of the current HII database will be reset.
2023 @param DefaultId Specifies the type of defaults to retrieve.
2025 @retval TURE The default value is set successfully.
2026 @retval FALSE The default value can't be found and set.
2031 IN CONST EFI_STRING Request
, OPTIONAL
2035 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2039 Allocates and returns a Null-terminated Unicode <ConfigAltResp> string.
2041 If Guid is NULL, then ASSERT().
2042 If Name is NULL, then ASSERT().
2043 If BlockNameArray is NULL, then ASSERT().
2045 @param[in] Guid GUID of the buffer storage.
2046 @param[in] Name Name of the buffer storage.
2047 @param[in] DriverHandle The DriverHandle that support a Device Path
2049 @param[in] BufferStorage Content of the buffer storage.
2050 @param[in] BufferStorageSize Length in bytes of the buffer storage.
2051 @param[in] BlockNameArray Array generated by VFR compiler. This array
2052 contains a UINT32 value that is the length
2053 of BlockNameArray in bytes, followed by pairs
2054 of 16-bit values that are the offset and length
2055 values used to contruct a <ConfigRequest> string.
2056 @param[in] ... A variable argument list that contains pairs of 16-bit
2057 ALTCFG identifiers and pointers to DefaultValueArrays.
2058 The variable argument list is terminated by a NULL
2059 DefaultValueArray pointer. A DefaultValueArray
2060 contains a UINT32 value that is the length, in bytes,
2061 of the DefaultValueArray. The UINT32 length value
2062 is followed by a series of records that contain
2063 a 16-bit WIDTH value followed by a byte array with
2064 WIDTH entries. The records must be parsed from
2065 beginning to end until the UINT32 length limit
2068 @retval NULL There are not enough resources to process the request.
2069 @retval NULL A <ConfigResp> could not be retrieved from the Config
2071 @retval Other A pointer to the Null-terminate Unicode <ConfigAltResp>
2077 HiiConstructConfigAltResp (
2078 IN CONST EFI_GUID
*Guid
,
2079 IN CONST CHAR16
*Name
,
2080 IN EFI_HANDLE DriverHandle
,
2081 IN CONST VOID
*BufferStorage
,
2082 IN UINTN BufferStorageSize
,
2083 IN CONST VOID
*BlockNameArray
,
2092 CHAR16
*ConfigRequest
;
2093 EFI_STRING ConfigResp
;
2094 EFI_STRING ConfigAltResp
;
2101 ASSERT (Guid
!= NULL
);
2102 ASSERT (Name
!= NULL
);
2103 ASSERT (BlockNameArray
!= NULL
);
2106 // Initialize local variables
2109 ConfigRequest
= NULL
;
2113 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..."
2115 ConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, DriverHandle
);
2116 if (ConfigHdr
== NULL
) {
2121 // Compute the length of the entire request starting with <ConfigHdr> and a
2124 Length
= StrLen (ConfigHdr
) + 1;
2127 // Determine the size <BlockName> Offset/Width pairs
2129 Buffer
= (UINT8
*)BlockNameArray
;
2130 BufferEnd
= Buffer
+ ReadUnaligned32 ((UINT32
*)Buffer
);
2131 Buffer
+= sizeof (UINT32
);
2134 // Add <BlockName> length that is composed of one or more Offset/Width pairs
2136 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
2137 // | 8 | 4 | 7 | 4 |
2139 Length
+= (((BufferEnd
- Buffer
) / (sizeof (UINT16
) + sizeof (UINT16
))) * (8 + 4 + 7 + 4));
2142 // Allocate buffer for the entire <ConfigRequest>
2144 ConfigRequest
= AllocateZeroPool (Length
* sizeof (CHAR16
));
2145 if (ConfigRequest
== NULL
) {
2148 String
= ConfigRequest
;
2151 // Start with <ConfigHdr>
2153 StrCpy (String
, ConfigHdr
);
2154 String
+= StrLen (String
);
2157 // Loop through all the Offset/Width pairs and append them to ConfigRequest
2159 while (Buffer
< BufferEnd
) {
2161 // Append &OFFSET=XXXX&WIDTH=YYYY
2163 OffsetValue
= ReadUnaligned16 ((UINT16
*)Buffer
);
2164 WidthValue
= ReadUnaligned16 ((UINT16
*)(Buffer
+ sizeof (UINT16
)));
2167 (8 + 4 + 7 + 4) * sizeof (CHAR16
),
2168 L
"&OFFSET=%04X&WIDTH=%04X",
2173 String
+= StrLen (String
);
2174 Buffer
+= (sizeof (UINT16
) + sizeof (UINT16
));
2178 // Get the <ConfigResp>
2180 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, BufferStorage
, BufferStorageSize
);
2181 if (ConfigResp
== NULL
) {
2186 // Compute the length of the entire response starting with <ConfigResp> and a
2189 Length
= StrLen (ConfigResp
) + 1;
2192 // Add the length associated with each pair of variable argument parameters
2194 VA_START (Args
, BlockNameArray
);
2196 AltCfgId
= VA_ARG (Args
, UINTN
);
2197 Buffer
= VA_ARG (Args
, UINT8
*);
2198 if (Buffer
== NULL
) {
2203 // Add length for "&<ConfigHdr>&ALTCFG=XXXX"
2204 // |1| StrLen (ConfigHdr) | 8 | 4 |
2206 Length
+= (1 + StrLen (ConfigHdr
) + 8 + 4);
2208 BufferEnd
= Buffer
+ ReadUnaligned32 ((UINT32
*)Buffer
);
2209 Buffer
+= sizeof (UINT32
);
2210 while (Buffer
< BufferEnd
) {
2212 // Extract Width field
2214 Width
= ReadUnaligned16 ((UINT16
*)(Buffer
+ sizeof (UINT16
)));
2217 // Add length for "&OFFSET=XXXX&WIDTH=YYYY&VALUE=zzzzzzzzzzzz"
2218 // | 8 | 4 | 7 | 4 | 7 | Width * 2 |
2220 Length
+= (8 + 4 + 7 + 4 + 7 + Width
* 2);
2223 // Update Buffer to the next record
2225 Buffer
+= (sizeof (UINT16
) + sizeof (UINT16
) + Width
);
2231 // Allocate a buffer for the entire response
2233 ConfigAltResp
= AllocateZeroPool (Length
* sizeof (CHAR16
));
2234 if (ConfigAltResp
== NULL
) {
2237 String
= ConfigAltResp
;
2242 StrCpy (String
, ConfigResp
);
2243 String
+= StrLen (String
);
2246 // Add <AltResp> for each pair of variable argument parameters
2248 VA_START (Args
, BlockNameArray
);
2250 AltCfgId
= VA_ARG (Args
, UINTN
);
2251 Buffer
= VA_ARG (Args
, UINT8
*);
2252 if (Buffer
== NULL
) {
2257 // Add <AltConfigHdr> of the form "&<ConfigHdr>&ALTCFG=XXXX"
2258 // |1| StrLen (ConfigHdr) | 8 | 4 |
2262 (1 + StrLen (ConfigHdr
) + 8 + 4) * sizeof (CHAR16
),
2267 String
+= StrLen (String
);
2270 // Add <ConfigBody> ::= <ConfigElement>*
2272 BufferEnd
= Buffer
+ ReadUnaligned32 ((UINT32
*)Buffer
);
2273 Buffer
+= sizeof (UINT32
);
2274 while (Buffer
< BufferEnd
) {
2276 // Extract Width field
2278 Width
= ReadUnaligned16 ((UINT16
*)(Buffer
+ sizeof (UINT16
)));
2281 // Add <BlockConfig>
2285 (8 + 4 + 7 + 4 + 7 + Width
* 2) * sizeof (CHAR16
),
2286 L
"&OFFSET=%04X&WIDTH=%04X&VALUE=",
2287 ReadUnaligned16 ((UINT16
*)Buffer
),
2290 String
+= StrLen (String
);
2293 // Update Buffer to point to the value in the current record
2295 Buffer
+= (sizeof (UINT16
) + sizeof (UINT16
));
2298 // Convert Value to a hex string in "%x" format
2299 // NOTE: This is in the opposite byte that GUID and PATH use
2301 for (; Width
> 0; Width
--) {
2302 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, Buffer
[Width
- 1], 2);
2305 // Update Buffer to the next record
2313 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
2315 return InternalHiiLowerConfigString (ConfigAltResp
);
2318 if (ConfigHdr
!= NULL
) {
2319 FreePool (ConfigHdr
);
2321 if (ConfigRequest
!= NULL
) {
2322 FreePool (ConfigRequest
);
2324 if (ConfigResp
!= NULL
) {
2325 FreePool (ConfigResp
);
2332 Determines if two values in config strings match.
2334 Compares the substring between StartSearchString and StopSearchString in
2335 FirstString to the substring between StartSearchString and StopSearchString
2336 in SecondString. If the two substrings match, then TRUE is returned. If the
2337 two substrings do not match, then FALSE is returned.
2339 If FirstString is NULL, then ASSERT().
2340 If SecondString is NULL, then ASSERT().
2341 If StartSearchString is NULL, then ASSERT().
2342 If StopSearchString is NULL, then ASSERT().
2344 @param FirstString Pointer to the first Null-terminated Unicode string.
2345 @param SecondString Pointer to the second Null-terminated Unicode string.
2346 @param StartSearchString Pointer to the Null-terminated Unicode string that
2347 marks the start of the value string to compare.
2348 @param StopSearchString Pointer to the Null-terminated Unicode string that
2349 marks the end of the vakue string to compare.
2351 @retval FALSE StartSearchString is not present in FirstString.
2352 @retval FALSE StartSearchString is not present in SecondString.
2353 @retval FALSE StopSearchString is not present in FirstString.
2354 @retval FALSE StopSearchString is not present in SecondString.
2355 @retval FALSE The length of the substring in FirstString is not the
2356 same length as the substring in SecondString.
2357 @retval FALSE The value string in FirstString does not matche the
2358 value string in SecondString.
2359 @retval TRUE The value string in FirstString matches the value
2360 string in SecondString.
2365 InternalHiiCompareSubString (
2366 IN CHAR16
*FirstString
,
2367 IN CHAR16
*SecondString
,
2368 IN CHAR16
*StartSearchString
,
2369 IN CHAR16
*StopSearchString
2372 CHAR16
*EndFirstString
;
2373 CHAR16
*EndSecondString
;
2375 ASSERT (FirstString
!= NULL
);
2376 ASSERT (SecondString
!= NULL
);
2377 ASSERT (StartSearchString
!= NULL
);
2378 ASSERT (StopSearchString
!= NULL
);
2380 FirstString
= StrStr (FirstString
, StartSearchString
);
2381 if (FirstString
== NULL
) {
2385 SecondString
= StrStr (SecondString
, StartSearchString
);
2386 if (SecondString
== NULL
) {
2390 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2391 if (EndFirstString
== NULL
) {
2395 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2396 if (EndSecondString
== NULL
) {
2400 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2404 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2408 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2410 If ConfigHdr is NULL, then ASSERT().
2412 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2413 @param[in] Guid GUID of the storage.
2414 @param[in] Name NAME of the storage.
2416 @retval TRUE Routing information matches <ConfigHdr>.
2417 @retval FALSE Routing information does not match <ConfigHdr>.
2422 HiiIsConfigHdrMatch (
2423 IN CONST EFI_STRING ConfigHdr
,
2424 IN CONST EFI_GUID
*Guid
, OPTIONAL
2425 IN CONST CHAR16
*Name OPTIONAL
2428 EFI_STRING CompareConfigHdr
;
2431 ASSERT (ConfigHdr
!= NULL
);
2434 // Use Guid and Name to generate a <ConfigHdr> string
2436 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2437 if (CompareConfigHdr
== NULL
) {
2444 // Compare GUID value strings
2446 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2449 if (Result
&& Name
!= NULL
) {
2451 // Compare NAME value strings
2453 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2457 // Free the <ConfigHdr> string
2459 FreePool (CompareConfigHdr
);
2465 Retrieves uncommited data from the Form Browser and converts it to a binary
2468 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2469 is an optional parameter that may be NULL.
2470 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2471 parameter that may be NULL.
2472 @param[in] BufferSize Length in bytes of buffer to hold retrived data.
2473 @param[out] Block Buffer of data to be updated.
2475 @retval FALSE The uncommitted data could not be retrieved.
2476 @retval TRUE The uncommitted data was retrieved.
2482 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2483 IN CONST CHAR16
*VariableName
, OPTIONAL
2488 EFI_STRING ResultsData
;
2490 EFI_STRING ConfigResp
;
2495 // Retrieve the results data from the Browser Callback
2497 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2498 if (ResultsData
== NULL
) {
2503 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2505 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2506 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2507 ConfigResp
= AllocateZeroPool (Size
);
2508 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2511 // Free the allocated buffer
2513 FreePool (ResultsData
);
2514 if (ConfigResp
== NULL
) {
2519 // Convert <ConfigResp> to a buffer
2521 Status
= gHiiConfigRouting
->ConfigToBlock (
2529 // Free the allocated buffer
2531 FreePool (ConfigResp
);
2533 if (EFI_ERROR (Status
)) {
2541 Updates uncommitted data in the Form Browser.
2543 If Buffer is NULL, then ASSERT().
2545 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2546 is an optional parameter that may be NULL.
2547 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2548 parameter that may be NULL.
2549 @param[in] BufferSize Length, in bytes, of Buffer.
2550 @param[in] Buffer Buffer of data to commit.
2551 @param[in] RequestElement An optional field to specify which part of the
2552 buffer data will be send back to Browser. If NULL,
2553 the whole buffer of data will be committed to
2555 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2557 @retval FALSE The uncommitted data could not be updated.
2558 @retval TRUE The uncommitted data was updated.
2564 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2565 IN CONST CHAR16
*VariableName
, OPTIONAL
2566 IN UINTN BufferSize
,
2567 IN CONST UINT8
*Buffer
,
2568 IN CONST CHAR16
*RequestElement OPTIONAL
2572 EFI_STRING ConfigRequest
;
2573 EFI_STRING ConfigResp
;
2574 EFI_STRING ResultsData
;
2576 ASSERT (Buffer
!= NULL
);
2579 // Construct <ConfigRequest>
2581 if (RequestElement
== NULL
) {
2583 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2584 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2586 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2587 ConfigRequest
= AllocateZeroPool (Size
);
2588 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2591 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2592 // followed by <RequestElement> followed by a Null-terminator
2594 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2595 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2596 ConfigRequest
= AllocateZeroPool (Size
);
2597 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2599 if (ConfigRequest
== NULL
) {
2604 // Convert <ConfigRequest> to <ConfigResp>
2606 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2607 FreePool (ConfigRequest
);
2608 if (ConfigResp
== NULL
) {
2613 // Set data in the uncommitted browser state information
2615 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2616 FreePool (ConfigResp
);
2618 return (BOOLEAN
)(ResultsData
!= NULL
);
2621 /////////////////////////////////////////
2622 /////////////////////////////////////////
2624 /////////////////////////////////////////
2625 /////////////////////////////////////////
2627 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2633 } HII_LIB_OPCODE_BUFFER
;
2636 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2638 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2639 1, // EFI_IFR_TYPE_NUM_SIZE_8
2640 2, // EFI_IFR_TYPE_NUM_SIZE_16
2641 4, // EFI_IFR_TYPE_NUM_SIZE_32
2642 8, // EFI_IFR_TYPE_NUM_SIZE_64
2643 1, // EFI_IFR_TYPE_BOOLEAN
2644 3, // EFI_IFR_TYPE_TIME
2645 4, // EFI_IFR_TYPE_DATE
2646 2 // EFI_IFR_TYPE_STRING
2650 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2651 HiiFreeOpCodeHandle().
2653 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2654 @retval Other A new OpCode handle.
2659 HiiAllocateOpCodeHandle (
2663 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2665 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2666 if (OpCodeBuffer
== NULL
) {
2669 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2670 if (OpCodeBuffer
->Buffer
== NULL
) {
2671 FreePool (OpCodeBuffer
);
2674 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2675 OpCodeBuffer
->Position
= 0;
2676 return (VOID
*)OpCodeBuffer
;
2680 Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle().
2681 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2682 Handle are also freed.
2684 If OpCodeHandle is NULL, then ASSERT().
2689 HiiFreeOpCodeHandle (
2693 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2695 ASSERT (OpCodeHandle
!= NULL
);
2697 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2698 if (OpCodeBuffer
->Buffer
!= NULL
) {
2699 FreePool (OpCodeBuffer
->Buffer
);
2701 FreePool (OpCodeBuffer
);
2706 InternalHiiOpCodeHandlePosition (
2707 IN VOID
*OpCodeHandle
2710 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
2715 InternalHiiOpCodeHandleBuffer (
2716 IN VOID
*OpCodeHandle
2719 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
2724 InternalHiiGrowOpCodeHandle (
2729 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2732 ASSERT (OpCodeHandle
!= NULL
);
2734 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
2735 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
2736 Buffer
= ReallocatePool (
2737 OpCodeBuffer
->BufferSize
,
2738 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
2739 OpCodeBuffer
->Buffer
2741 if (Buffer
== NULL
) {
2744 OpCodeBuffer
->Buffer
= Buffer
;
2745 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
2747 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
2748 OpCodeBuffer
->Position
+= Size
;
2754 InternalHiiCreateOpCodeExtended (
2755 IN VOID
*OpCodeHandle
,
2756 IN VOID
*OpCodeTemplate
,
2758 IN UINTN OpCodeSize
,
2759 IN UINTN ExtensionSize
,
2763 EFI_IFR_OP_HEADER
*Header
;
2766 ASSERT (OpCodeTemplate
!= NULL
);
2767 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
2769 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
2770 Header
->OpCode
= OpCode
;
2771 Header
->Scope
= Scope
;
2772 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
2773 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
2774 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
2779 InternalHiiCreateOpCode (
2780 IN VOID
*OpCodeHandle
,
2781 IN VOID
*OpCodeTemplate
,
2786 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
2790 Append raw opcodes to an OpCodeHandle.
2792 If OpCodeHandle is NULL, then ASSERT().
2793 If RawBuffer is NULL, then ASSERT();
2795 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2796 @param[in] RawBuffer Buffer of opcodes to append.
2797 @param[in] RawBufferSize The size, in bytes, of Buffer.
2799 @retval NULL There is not enough space left in Buffer to add the opcode.
2800 @retval Other A pointer to the appended opcodes.
2805 HiiCreateRawOpCodes (
2806 IN VOID
*OpCodeHandle
,
2807 IN UINT8
*RawBuffer
,
2808 IN UINTN RawBufferSize
2813 ASSERT (RawBuffer
!= NULL
);
2815 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
2816 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
2820 Append opcodes from one OpCode Handle to another OpCode handle.
2822 If OpCodeHandle is NULL, then ASSERT().
2823 If RawOpCodeHandle is NULL, then ASSERT();
2825 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2826 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
2828 @retval NULL There is not enough space left in Buffer to add the opcode.
2829 @retval Other A pointer to the appended opcodes.
2834 InternalHiiAppendOpCodes (
2835 IN VOID
*OpCodeHandle
,
2836 IN VOID
*RawOpCodeHandle
2839 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
2841 ASSERT (RawOpCodeHandle
!= NULL
);
2843 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
2844 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
2848 Create EFI_IFR_END_OP opcode.
2850 If OpCodeHandle is NULL, then ASSERT().
2852 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2854 @retval NULL There is not enough space left in Buffer to add the opcode.
2855 @retval Other A pointer to the created opcode.
2860 HiiCreateEndOpCode (
2861 IN VOID
*OpCodeHandle
2866 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
2870 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
2872 If OpCodeHandle is NULL, then ASSERT().
2873 If Type is invalid, then ASSERT().
2874 If Flags is invalid, then ASSERT().
2876 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2877 @param[in] StringId StringId for the option
2878 @param[in] Flags Flags for the option
2879 @param[in] Type Type for the option
2880 @param[in] Value Value for the option
2882 @retval NULL There is not enough space left in Buffer to add the opcode.
2883 @retval Other A pointer to the created opcode.
2888 HiiCreateOneOfOptionOpCode (
2889 IN VOID
*OpCodeHandle
,
2896 EFI_IFR_ONE_OF_OPTION OpCode
;
2898 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2900 ZeroMem (&OpCode
, sizeof (OpCode
));
2901 OpCode
.Option
= StringId
;
2902 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
2904 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2906 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, sizeof (OpCode
));
2910 Create EFI_IFR_DEFAULT_OP opcode.
2912 If OpCodeHandle is NULL, then ASSERT().
2913 If Type is invalid, then ASSERT().
2915 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2916 @param[in] DefaultId DefaultId for the default
2917 @param[in] Type Type for the default
2918 @param[in] Value Value for the default
2920 @retval NULL There is not enough space left in Buffer to add the opcode.
2921 @retval Other A pointer to the created opcode.
2926 HiiCreateDefaultOpCode (
2927 IN VOID
*OpCodeHandle
,
2928 IN UINT16 DefaultId
,
2933 EFI_IFR_DEFAULT OpCode
;
2935 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
2937 ZeroMem (&OpCode
, sizeof (OpCode
));
2939 OpCode
.DefaultId
= DefaultId
;
2940 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
2942 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, sizeof (OpCode
));
2946 Create EFI_IFR_GUID opcode.
2948 If OpCodeHandle is NULL, then ASSERT().
2949 If Guid is NULL, then ASSERT().
2950 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
2952 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2953 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
2954 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
2955 optional parameter that may be NULL. If this
2956 parameter is NULL, then the GUID extension
2957 region of the created opcode is filled with zeros.
2958 If this parameter is not NULL, then the GUID
2959 extension region of GuidData will be copied to
2960 the GUID extension region of the created opcode.
2961 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
2962 must be >= sizeof(EFI_IFR_GUID).
2964 @retval NULL There is not enough space left in Buffer to add the opcode.
2965 @retval Other A pointer to the created opcode.
2970 HiiCreateGuidOpCode (
2971 IN VOID
*OpCodeHandle
,
2972 IN CONST EFI_GUID
*Guid
,
2973 IN CONST VOID
*GuidOpCode
, OPTIONAL
2977 EFI_IFR_GUID OpCode
;
2978 EFI_IFR_GUID
*OpCodePointer
;
2980 ASSERT (Guid
!= NULL
);
2981 ASSERT (OpCodeSize
>= sizeof (OpCode
));
2983 ZeroMem (&OpCode
, sizeof (OpCode
));
2984 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
2986 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
2991 OpCodeSize
- sizeof (OpCode
),
2994 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
2995 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
2997 return (UINT8
*)OpCodePointer
;
3001 Create EFI_IFR_ACTION_OP opcode.
3003 If OpCodeHandle is NULL, then ASSERT().
3004 If any reserved bits are set in QuestionFlags, then ASSERT().
3006 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3007 @param[in] QuestionId Question ID
3008 @param[in] Prompt String ID for Prompt
3009 @param[in] Help String ID for Help
3010 @param[in] QuestionFlags Flags in Question Header
3011 @param[in] QuestionConfig String ID for configuration
3013 @retval NULL There is not enough space left in Buffer to add the opcode.
3014 @retval Other A pointer to the created opcode.
3019 HiiCreateActionOpCode (
3020 IN VOID
*OpCodeHandle
,
3021 IN EFI_QUESTION_ID QuestionId
,
3022 IN EFI_STRING_ID Prompt
,
3023 IN EFI_STRING_ID Help
,
3024 IN UINT8 QuestionFlags
,
3025 IN EFI_STRING_ID QuestionConfig
3028 EFI_IFR_ACTION OpCode
;
3030 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3032 ZeroMem (&OpCode
, sizeof (OpCode
));
3033 OpCode
.Question
.QuestionId
= QuestionId
;
3034 OpCode
.Question
.Header
.Prompt
= Prompt
;
3035 OpCode
.Question
.Header
.Help
= Help
;
3036 OpCode
.Question
.Flags
= QuestionFlags
;
3037 OpCode
.QuestionConfig
= QuestionConfig
;
3039 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
3043 Create EFI_IFR_SUBTITLE_OP opcode.
3045 If OpCodeHandle is NULL, then ASSERT().
3046 If any reserved bits are set in Flags, then ASSERT().
3047 If Scope > 1, then ASSERT().
3049 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3050 @param[in] Prompt String ID for Prompt
3051 @param[in] Help String ID for Help
3052 @param[in] Flags Subtitle opcode flags
3053 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
3054 0 if this opcode is within the current scope.
3056 @retval NULL There is not enough space left in Buffer to add the opcode.
3057 @retval Other A pointer to the created opcode.
3062 HiiCreateSubTitleOpCode (
3063 IN VOID
*OpCodeHandle
,
3064 IN EFI_STRING_ID Prompt
,
3065 IN EFI_STRING_ID Help
,
3070 EFI_IFR_SUBTITLE OpCode
;
3072 ASSERT (Scope
<= 1);
3073 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
3075 ZeroMem (&OpCode
, sizeof (OpCode
));
3076 OpCode
.Statement
.Prompt
= Prompt
;
3077 OpCode
.Statement
.Help
= Help
;
3078 OpCode
.Flags
= Flags
;
3080 return InternalHiiCreateOpCodeExtended (
3083 EFI_IFR_SUBTITLE_OP
,
3091 Create EFI_IFR_REF_OP opcode.
3093 If OpCodeHandle is NULL, then ASSERT().
3094 If any reserved bits are set in QuestionFlags, then ASSERT().
3096 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3097 @param[in] FormId Destination Form ID
3098 @param[in] Prompt String ID for Prompt
3099 @param[in] Help String ID for Help
3100 @param[in] QuestionFlags Flags in Question Header
3101 @param[in] QuestionId Question ID
3103 @retval NULL There is not enough space left in Buffer to add the opcode.
3104 @retval Other A pointer to the created opcode.
3109 HiiCreateGotoOpCode (
3110 IN VOID
*OpCodeHandle
,
3111 IN EFI_FORM_ID FormId
,
3112 IN EFI_STRING_ID Prompt
,
3113 IN EFI_STRING_ID Help
,
3114 IN UINT8 QuestionFlags
,
3115 IN EFI_QUESTION_ID QuestionId
3120 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3122 ZeroMem (&OpCode
, sizeof (OpCode
));
3123 OpCode
.Question
.Header
.Prompt
= Prompt
;
3124 OpCode
.Question
.Header
.Help
= Help
;
3125 OpCode
.Question
.QuestionId
= QuestionId
;
3126 OpCode
.Question
.Flags
= QuestionFlags
;
3127 OpCode
.FormId
= FormId
;
3129 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
3133 Create EFI_IFR_CHECKBOX_OP opcode.
3135 If OpCodeHandle is NULL, then ASSERT().
3136 If any reserved bits are set in QuestionFlags, then ASSERT().
3137 If any reserved bits are set in CheckBoxFlags, then ASSERT().
3139 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3140 @param[in] QuestionId Question ID
3141 @param[in] VarStoreId Storage ID
3142 @param[in] VarOffset Offset in Storage
3143 @param[in] Prompt String ID for Prompt
3144 @param[in] Help String ID for Help
3145 @param[in] QuestionFlags Flags in Question Header
3146 @param[in] CheckBoxFlags Flags for checkbox opcode
3147 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3148 is an optional parameter that may be NULL.
3150 @retval NULL There is not enough space left in Buffer to add the opcode.
3151 @retval Other A pointer to the created opcode.
3156 HiiCreateCheckBoxOpCode (
3157 IN VOID
*OpCodeHandle
,
3158 IN EFI_QUESTION_ID QuestionId
,
3159 IN EFI_VARSTORE_ID VarStoreId
,
3160 IN UINT16 VarOffset
,
3161 IN EFI_STRING_ID Prompt
,
3162 IN EFI_STRING_ID Help
,
3163 IN UINT8 QuestionFlags
,
3164 IN UINT8 CheckBoxFlags
,
3165 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3168 EFI_IFR_CHECKBOX OpCode
;
3171 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3173 ZeroMem (&OpCode
, sizeof (OpCode
));
3174 OpCode
.Question
.QuestionId
= QuestionId
;
3175 OpCode
.Question
.VarStoreId
= VarStoreId
;
3176 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3177 OpCode
.Question
.Header
.Prompt
= Prompt
;
3178 OpCode
.Question
.Header
.Help
= Help
;
3179 OpCode
.Question
.Flags
= QuestionFlags
;
3180 OpCode
.Flags
= CheckBoxFlags
;
3182 if (DefaultsOpCodeHandle
== NULL
) {
3183 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
3186 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3187 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
3188 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3189 HiiCreateEndOpCode (OpCodeHandle
);
3190 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3194 Create EFI_IFR_NUMERIC_OP opcode.
3196 If OpCodeHandle is NULL, then ASSERT().
3197 If any reserved bits are set in QuestionFlags, then ASSERT().
3198 If any reserved bits are set in NumericFlags, then ASSERT().
3200 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3201 @param[in] QuestionId Question ID
3202 @param[in] VarStoreId Storage ID
3203 @param[in] VarOffset Offset in Storage
3204 @param[in] Prompt String ID for Prompt
3205 @param[in] Help String ID for Help
3206 @param[in] QuestionFlags Flags in Question Header
3207 @param[in] NumericFlags Flags for numeric opcode
3208 @param[in] Minimum Numeric minimum value
3209 @param[in] Maximum Numeric maximum value
3210 @param[in] Step Numeric step for edit
3211 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3212 is an optional parameter that may be NULL.
3214 @retval NULL There is not enough space left in Buffer to add the opcode.
3215 @retval Other A pointer to the created opcode.
3220 HiiCreateNumericOpCode (
3221 IN VOID
*OpCodeHandle
,
3222 IN EFI_QUESTION_ID QuestionId
,
3223 IN EFI_VARSTORE_ID VarStoreId
,
3224 IN UINT16 VarOffset
,
3225 IN EFI_STRING_ID Prompt
,
3226 IN EFI_STRING_ID Help
,
3227 IN UINT8 QuestionFlags
,
3228 IN UINT8 NumericFlags
,
3232 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3235 EFI_IFR_NUMERIC OpCode
;
3238 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3240 ZeroMem (&OpCode
, sizeof (OpCode
));
3241 OpCode
.Question
.QuestionId
= QuestionId
;
3242 OpCode
.Question
.VarStoreId
= VarStoreId
;
3243 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3244 OpCode
.Question
.Header
.Prompt
= Prompt
;
3245 OpCode
.Question
.Header
.Help
= Help
;
3246 OpCode
.Question
.Flags
= QuestionFlags
;
3247 OpCode
.Flags
= NumericFlags
;
3249 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
3250 case EFI_IFR_NUMERIC_SIZE_1
:
3251 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
3252 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3253 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3256 case EFI_IFR_NUMERIC_SIZE_2
:
3257 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3258 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3259 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3262 case EFI_IFR_NUMERIC_SIZE_4
:
3263 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3264 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3265 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3268 case EFI_IFR_NUMERIC_SIZE_8
:
3269 OpCode
.data
.u64
.MinValue
= Minimum
;
3270 OpCode
.data
.u64
.MaxValue
= Maximum
;
3271 OpCode
.data
.u64
.Step
= Step
;
3275 if (DefaultsOpCodeHandle
== NULL
) {
3276 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
));
3279 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3280 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, sizeof (OpCode
), 0, 1);
3281 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3282 HiiCreateEndOpCode (OpCodeHandle
);
3283 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3287 Create EFI_IFR_STRING_OP opcode.
3289 If OpCodeHandle is NULL, then ASSERT().
3290 If any reserved bits are set in QuestionFlags, then ASSERT().
3291 If any reserved bits are set in StringFlags, then ASSERT().
3293 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3294 @param[in] QuestionId Question ID
3295 @param[in] VarStoreId Storage ID
3296 @param[in] VarOffset Offset in Storage
3297 @param[in] Prompt String ID for Prompt
3298 @param[in] Help String ID for Help
3299 @param[in] QuestionFlags Flags in Question Header
3300 @param[in] StringFlags Flags for string opcode
3301 @param[in] MinSize String minimum length
3302 @param[in] MaxSize String maximum length
3303 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3304 is an optional parameter that may be NULL.
3306 @retval NULL There is not enough space left in Buffer to add the opcode.
3307 @retval Other A pointer to the created opcode.
3312 HiiCreateStringOpCode (
3313 IN VOID
*OpCodeHandle
,
3314 IN EFI_QUESTION_ID QuestionId
,
3315 IN EFI_VARSTORE_ID VarStoreId
,
3316 IN UINT16 VarOffset
,
3317 IN EFI_STRING_ID Prompt
,
3318 IN EFI_STRING_ID Help
,
3319 IN UINT8 QuestionFlags
,
3320 IN UINT8 StringFlags
,
3323 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3326 EFI_IFR_STRING OpCode
;
3329 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3331 ZeroMem (&OpCode
, sizeof (OpCode
));
3332 OpCode
.Question
.Header
.Prompt
= Prompt
;
3333 OpCode
.Question
.Header
.Help
= Help
;
3334 OpCode
.Question
.QuestionId
= QuestionId
;
3335 OpCode
.Question
.VarStoreId
= VarStoreId
;
3336 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3337 OpCode
.Question
.Flags
= QuestionFlags
;
3338 OpCode
.MinSize
= MinSize
;
3339 OpCode
.MaxSize
= MaxSize
;
3340 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3342 if (DefaultsOpCodeHandle
== NULL
) {
3343 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3346 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3347 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3348 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3349 HiiCreateEndOpCode (OpCodeHandle
);
3350 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3354 Create EFI_IFR_ONE_OF_OP opcode.
3356 If OpCodeHandle is NULL, then ASSERT().
3357 If any reserved bits are set in QuestionFlags, then ASSERT().
3358 If any reserved bits are set in OneOfFlags, then ASSERT().
3360 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3361 @param[in] QuestionId Question ID
3362 @param[in] VarStoreId Storage ID
3363 @param[in] VarOffset Offset in Storage
3364 @param[in] Prompt String ID for Prompt
3365 @param[in] Help String ID for Help
3366 @param[in] QuestionFlags Flags in Question Header
3367 @param[in] OneOfFlags Flags for oneof opcode
3368 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3369 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3370 is an optional parameter that may be NULL.
3372 @retval NULL There is not enough space left in Buffer to add the opcode.
3373 @retval Other A pointer to the created opcode.
3378 HiiCreateOneOfOpCode (
3379 IN VOID
*OpCodeHandle
,
3380 IN EFI_QUESTION_ID QuestionId
,
3381 IN EFI_VARSTORE_ID VarStoreId
,
3382 IN UINT16 VarOffset
,
3383 IN EFI_STRING_ID Prompt
,
3384 IN EFI_STRING_ID Help
,
3385 IN UINT8 QuestionFlags
,
3386 IN UINT8 OneOfFlags
,
3387 IN VOID
*OptionsOpCodeHandle
,
3388 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3391 EFI_IFR_ONE_OF OpCode
;
3394 ASSERT (OptionsOpCodeHandle
!= NULL
);
3395 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3397 ZeroMem (&OpCode
, sizeof (OpCode
));
3398 OpCode
.Question
.Header
.Prompt
= Prompt
;
3399 OpCode
.Question
.Header
.Help
= Help
;
3400 OpCode
.Question
.QuestionId
= QuestionId
;
3401 OpCode
.Question
.VarStoreId
= VarStoreId
;
3402 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3403 OpCode
.Question
.Flags
= QuestionFlags
;
3404 OpCode
.Flags
= OneOfFlags
;
3406 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3407 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, sizeof (OpCode
), 0, 1);
3408 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3409 if (DefaultsOpCodeHandle
!= NULL
) {
3410 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3412 HiiCreateEndOpCode (OpCodeHandle
);
3413 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3417 Create EFI_IFR_ORDERED_LIST_OP opcode.
3419 If OpCodeHandle is NULL, then ASSERT().
3420 If any reserved bits are set in QuestionFlags, then ASSERT().
3421 If any reserved bits are set in OrderedListFlags, then ASSERT().
3423 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3424 @param[in] QuestionId Question ID
3425 @param[in] VarStoreId Storage ID
3426 @param[in] VarOffset Offset in Storage
3427 @param[in] Prompt String ID for Prompt
3428 @param[in] Help String ID for Help
3429 @param[in] QuestionFlags Flags in Question Header
3430 @param[in] OrderedListFlags Flags for ordered list opcode
3431 @param[in] DataType Type for option value
3432 @param[in] MaxContainers Maximum count for options in this ordered list
3433 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3434 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3435 is an optional parameter that may be NULL.
3437 @retval NULL There is not enough space left in Buffer to add the opcode.
3438 @retval Other A pointer to the created opcode.
3443 HiiCreateOrderedListOpCode (
3444 IN VOID
*OpCodeHandle
,
3445 IN EFI_QUESTION_ID QuestionId
,
3446 IN EFI_VARSTORE_ID VarStoreId
,
3447 IN UINT16 VarOffset
,
3448 IN EFI_STRING_ID Prompt
,
3449 IN EFI_STRING_ID Help
,
3450 IN UINT8 QuestionFlags
,
3451 IN UINT8 OrderedListFlags
,
3453 IN UINT8 MaxContainers
,
3454 IN VOID
*OptionsOpCodeHandle
,
3455 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3458 EFI_IFR_ORDERED_LIST OpCode
;
3461 ASSERT (OptionsOpCodeHandle
!= NULL
);
3462 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3464 ZeroMem (&OpCode
, sizeof (OpCode
));
3465 OpCode
.Question
.Header
.Prompt
= Prompt
;
3466 OpCode
.Question
.Header
.Help
= Help
;
3467 OpCode
.Question
.QuestionId
= QuestionId
;
3468 OpCode
.Question
.VarStoreId
= VarStoreId
;
3469 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3470 OpCode
.Question
.Flags
= QuestionFlags
;
3471 OpCode
.MaxContainers
= MaxContainers
;
3472 OpCode
.Flags
= OrderedListFlags
;
3474 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3475 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3476 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3477 if (DefaultsOpCodeHandle
!= NULL
) {
3478 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3480 HiiCreateEndOpCode (OpCodeHandle
);
3481 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3485 This is the internal worker function to update the data in
3486 a form specified by FormSetGuid, FormId and Label.
3488 @param FormSetGuid The optional Formset GUID.
3489 @param FormId The Form ID.
3490 @param Package The package header.
3492 @param TempPacakge The resultant package.
3494 @retval EFI_SUCCESS The function completes successfully.
3499 InternalHiiUpdateFormPackageData (
3500 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3501 IN EFI_FORM_ID FormId
,
3502 IN EFI_HII_PACKAGE_HEADER
*Package
,
3503 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
3504 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
3505 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
3510 EFI_HII_PACKAGE_HEADER PackageHeader
;
3512 EFI_IFR_OP_HEADER
*IfrOpHdr
;
3513 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
3517 UINTN UpdatePackageLength
;
3519 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3520 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
3521 BufferPos
= (UINT8
*) (TempPackage
+ 1);
3523 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3524 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
3525 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
3526 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
3530 while (Offset
< PackageHeader
.Length
) {
3531 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3532 BufferPos
+= IfrOpHdr
->Length
;
3533 UpdatePackageLength
+= IfrOpHdr
->Length
;
3536 // Find the matched FormSet and Form
3538 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
3539 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
3544 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
) {
3545 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
3553 // The matched Form is found, and Update data in this form
3555 if (GetFormSet
&& GetForm
) {
3556 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
3557 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3558 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3560 // Remove the original data when End OpCode buffer exist.
3562 if (OpCodeBufferEnd
!= NULL
) {
3563 Offset
+= IfrOpHdr
->Length
;
3564 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3565 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
3566 while (Offset
< PackageHeader
.Length
) {
3568 // Search the matched end opcode
3570 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
3571 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
3575 // Go to the next Op-Code
3577 Offset
+= IfrOpHdr
->Length
;
3578 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3581 if (Offset
>= PackageHeader
.Length
) {
3583 // The end opcode is not found.
3585 return EFI_NOT_FOUND
;
3590 // Insert the updated data
3592 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
3593 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
3594 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
3595 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
3597 if (OpCodeBufferEnd
!= NULL
) {
3599 // Add the end opcode
3601 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
3602 BufferPos
+= IfrOpHdr
->Length
;
3603 UpdatePackageLength
+= IfrOpHdr
->Length
;
3607 // Copy the left package data.
3609 Offset
+= IfrOpHdr
->Length
;
3610 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
3611 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
3622 // Go to the next Op-Code
3624 Offset
+= IfrOpHdr
->Length
;
3625 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
3630 // The updated opcode buffer is not found.
3632 return EFI_NOT_FOUND
;
3635 // Update the package length.
3637 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
3638 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
3644 This function updates a form that has previously been registered with the HII
3645 Database. This function will perform at most one update operation.
3647 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
3648 comparisons of IFR opcodes are performed from the beginning of the form being
3649 updated until an IFR opcode is found that exactly matches the first IFR opcode
3650 specifed by StartOpCodeHandle. The following rules are used to determine if
3651 an insert, replace, or delete operation is performed.
3653 1) If no matches are found, then NULL is returned.
3654 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
3655 from StartOpcodeHandle except the first opcode are inserted immediately after
3656 the matching IFR opcode in the form beng updated.
3657 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
3658 from the matching IFR opcode until an IFR opcode exatly matches the first
3659 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
3660 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
3661 is found, then all of the IFR opcodes between the start match and the end
3662 match are deleted from the form being updated and all of the IFR opcodes
3663 from StartOpcodeHandle except the first opcode are inserted immediately after
3664 the matching start IFR opcode. If StartOpCcodeHandle only contains one
3665 IFR instruction, then the result of ths operation will delete all of the IFR
3666 opcodes between the start end matches.
3668 If HiiHandle is NULL, then ASSERT().
3669 If StartOpCodeHandle is NULL, then ASSERT().
3671 @param[in] HiiHandle The HII Handle of the form to update.
3672 @param[in] FormSetGuid The Formset GUID of the form to update. This
3673 is an optional parameter that may be NULL.
3674 If it is NULL, all FormSet will be updated.
3675 @param[in] FormId The ID of the form to update.
3676 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
3677 opcodes to be inserted or replaced in the form.
3678 The first IFR instruction in StartOpCodeHandle
3679 is used to find matching IFR opcode in the
3681 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
3682 that marks the end of a replace operation in
3683 the form. This is an optional parameter that
3684 may be NULL. If it is NULL, then an the IFR
3685 opcodes specified by StartOpCodeHandle are
3686 inserted into the form.
3688 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
3689 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
3690 1) The form specified by HiiHandle, FormSetGuid,
3691 and FormId could not be found in the HII Database.
3692 2) No IFR opcodes in the target form match the first
3693 IFR opcode in StartOpCodeHandle.
3694 3) EndOpCOde is not NULL, and no IFR opcodes in the
3695 target form following a matching start opcode match
3696 the first IFR opcode in EndOpCodeHandle.
3697 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
3703 IN EFI_HII_HANDLE HiiHandle
,
3704 IN EFI_GUID
*FormSetGuid
, OPTIONAL
3705 IN EFI_FORM_ID FormId
,
3706 IN VOID
*StartOpcodeHandle
,
3707 IN VOID
*EndOpcodeHandle OPTIONAL
3711 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
3712 UINT32 PackageListLength
;
3714 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
3716 UINT8
*UpdateBufferPos
;
3717 EFI_HII_PACKAGE_HEADER
*Package
;
3718 EFI_HII_PACKAGE_HEADER
*TempPacakge
;
3719 EFI_HII_PACKAGE_HEADER PackageHeader
;
3721 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
3722 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
3725 // Input update data can't be NULL.
3727 ASSERT (HiiHandle
!= NULL
);
3728 ASSERT (StartOpcodeHandle
!= NULL
);
3729 UpdatePackageList
= NULL
;
3731 HiiPackageList
= NULL
;
3734 // Restrive buffer data from Opcode Handle
3736 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpcodeHandle
;
3737 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpcodeHandle
;
3740 // Get the orginal package list
3743 HiiPackageList
= NULL
;
3744 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3746 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
3748 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3752 HiiPackageList
= AllocatePool (BufferSize
);
3753 if (HiiPackageList
== NULL
) {
3754 Status
= EFI_OUT_OF_RESOURCES
;
3758 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
3759 if (EFI_ERROR (Status
)) {
3764 // Calculate and allocate space for retrieval of IFR data
3766 BufferSize
+= OpCodeBufferStart
->Position
;
3767 UpdatePackageList
= AllocateZeroPool (BufferSize
);
3768 if (UpdatePackageList
== NULL
) {
3769 Status
= EFI_OUT_OF_RESOURCES
;
3774 // Allocate temp buffer to store the temp updated package buffer
3776 TempPacakge
= AllocateZeroPool (BufferSize
);
3777 if (TempPacakge
== NULL
) {
3778 Status
= EFI_OUT_OF_RESOURCES
;
3782 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
3785 // Copy the package list header
3787 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
3788 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3791 // Go through each package to find the matched pacakge and update one by one
3794 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
3795 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
3796 while (Offset
< PackageListLength
) {
3797 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
3798 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3799 Offset
+= Package
->Length
;
3801 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
3803 // Check this package is the matched package.
3805 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPacakge
);
3807 // The matched package is found. Its pacakge buffer will be updated by the input new data.
3809 if (!EFI_ERROR(Status
)) {
3815 // Add updated package buffer
3817 Package
= TempPacakge
;
3822 // Add pacakge buffer
3824 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
3825 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
3826 UpdateBufferPos
+= PackageHeader
.Length
;
3831 // Update package list length
3833 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
3834 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
3837 // Update Pacakge to show form
3839 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
3842 // Not matched form is found and updated.
3844 Status
= EFI_NOT_FOUND
;
3848 if (HiiPackageList
!= NULL
) {
3849 FreePool (HiiPackageList
);
3852 if (UpdatePackageList
!= NULL
) {
3853 FreePool (UpdatePackageList
);
3856 if (TempPacakge
!= NULL
) {
3857 FreePool (TempPacakge
);
3864 Configure the buffer accrording to ConfigBody strings in the format of
3865 <Length:4 bytes>, <Offset: 2 bytes>, <Width:2 bytes>, <Data:n bytes>.
3866 This ConfigBody strings is generated by UEFI VfrCompiler for the default
3867 values in a Form Set. The name of the ConfigBody strings is VfrMyIfrNVDataDefault0000
3868 constructed following this rule:
3869 "Vfr" + varstore.name + "Default" + defaultstore.attributes.
3870 Check the generated C file in Output for details.
3872 @param Buffer The start address of buffer.
3873 @param BufferSize The size of buffer.
3874 @param Number The number of the strings.
3875 @param ... Variable argument list for default value in <AltResp> format
3876 generated by the tool.
3878 @retval EFI_BUFFER_TOO_SMALL the BufferSize is too small to operate.
3879 @retval EFI_INVALID_PARAMETER Buffer is NULL or BufferSize is 0.
3880 @retval EFI_SUCCESS Operation successful.
3885 HiiIfrLibExtractDefault(
3887 IN UINTN
*BufferSize
,
3901 if ((Buffer
== NULL
) || (BufferSize
== NULL
)) {
3902 return EFI_INVALID_PARAMETER
;
3909 VA_START (Args
, Number
);
3910 for (Index
= 0; Index
< Number
; Index
++) {
3911 BufCfgArray
= (UINT8
*) VA_ARG (Args
, VOID
*);
3912 TotalLen
= ReadUnaligned32 ((UINT32
*)BufCfgArray
);
3913 BufferPos
= BufCfgArray
+ sizeof (UINT32
);
3915 while ((UINT32
)(BufferPos
- BufCfgArray
) < TotalLen
) {
3916 Offset
= ReadUnaligned16 ((UINT16
*)BufferPos
);
3917 BufferPos
+= sizeof (UINT16
);
3918 Width
= ReadUnaligned16 ((UINT16
*)BufferPos
);
3919 BufferPos
+= sizeof (UINT16
);
3923 if ((UINTN
)(Offset
+ Width
) > *BufferSize
) {
3924 return EFI_BUFFER_TOO_SMALL
;
3927 CopyMem ((UINT8
*)Buffer
+ Offset
, Value
, Width
);
3932 *BufferSize
= (UINTN
)Offset
;